@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.
- package/LICENSE +24 -0
- package/README.md +260 -0
- package/dist/CliLifecycle.d.ts +31 -0
- package/dist/CliLifecycle.d.ts.map +1 -0
- package/dist/CliLifecycle.js +90 -0
- package/dist/CliLifecycle.js.map +1 -0
- package/dist/ServerConfig.d.ts +290 -0
- package/dist/ServerConfig.d.ts.map +1 -0
- package/dist/ServerConfig.js +175 -0
- package/dist/ServerConfig.js.map +1 -0
- package/dist/cache/DiscoveryCache.d.ts +269 -0
- package/dist/cache/DiscoveryCache.d.ts.map +1 -0
- package/dist/cache/DiscoveryCache.js +104 -0
- package/dist/cache/DiscoveryCache.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +5177 -0
- package/dist/cli.js.map +1 -0
- package/dist/config/ConfigLoader.d.ts +270 -0
- package/dist/config/ConfigLoader.d.ts.map +1 -0
- package/dist/config/ConfigLoader.js +186 -0
- package/dist/config/ConfigLoader.js.map +1 -0
- package/dist/context/RequestContext.d.ts +43 -0
- package/dist/context/RequestContext.d.ts.map +1 -0
- package/dist/context/RequestContext.js +14 -0
- package/dist/context/RequestContext.js.map +1 -0
- package/dist/contracts/PersistenceBackend.d.ts +134 -0
- package/dist/contracts/PersistenceBackend.d.ts.map +1 -0
- package/dist/contracts/PersistenceBackend.js +6 -0
- package/dist/contracts/PersistenceBackend.js.map +1 -0
- package/dist/contracts/calibrator.d.ts +97 -0
- package/dist/contracts/calibrator.d.ts.map +1 -0
- package/dist/contracts/calibrator.js +1 -0
- package/dist/contracts/features.d.ts +35 -0
- package/dist/contracts/features.d.ts.map +1 -0
- package/dist/contracts/features.js +12 -0
- package/dist/contracts/features.js.map +1 -0
- package/dist/contracts/ids.d.ts +68 -0
- package/dist/contracts/ids.d.ts.map +1 -0
- package/dist/contracts/ids.js +40 -0
- package/dist/contracts/ids.js.map +1 -0
- package/dist/contracts/interfaces.d.ts +254 -0
- package/dist/contracts/interfaces.d.ts.map +1 -0
- package/dist/contracts/interfaces.js +1 -0
- package/dist/contracts/persistence-work.d.ts +96 -0
- package/dist/contracts/persistence-work.d.ts.map +1 -0
- package/dist/contracts/persistence-work.js +1 -0
- package/dist/contracts/reasoning-types.d.ts +21 -0
- package/dist/contracts/reasoning-types.d.ts.map +1 -0
- package/dist/contracts/reasoning-types.js +1 -0
- package/dist/contracts/strategy.d.ts +107 -0
- package/dist/contracts/strategy.d.ts.map +1 -0
- package/dist/contracts/strategy.js +1 -0
- package/dist/contracts/summary.d.ts +110 -0
- package/dist/contracts/summary.d.ts.map +1 -0
- package/dist/contracts/summary.js +1 -0
- package/dist/contracts/suspension.d.ts +215 -0
- package/dist/contracts/suspension.d.ts.map +1 -0
- package/dist/contracts/suspension.js +1 -0
- package/dist/contracts/transport.d.ts +26 -0
- package/dist/contracts/transport.d.ts.map +1 -0
- package/dist/contracts/transport.js +1 -0
- package/dist/core/CrossReferenceValidator.d.ts +18 -0
- package/dist/core/CrossReferenceValidator.d.ts.map +1 -0
- package/dist/core/CrossReferenceValidator.js +125 -0
- package/dist/core/CrossReferenceValidator.js.map +1 -0
- package/dist/core/HistoryManager.d.ts +215 -0
- package/dist/core/HistoryManager.d.ts.map +1 -0
- package/dist/core/HistoryManager.js +594 -0
- package/dist/core/HistoryManager.js.map +1 -0
- package/dist/core/IHistoryManager.d.ts +163 -0
- package/dist/core/IHistoryManager.d.ts.map +1 -0
- package/dist/core/IHistoryManager.js +1 -0
- package/dist/core/IThoughtFormatter.d.ts +51 -0
- package/dist/core/IThoughtFormatter.d.ts.map +1 -0
- package/dist/core/IThoughtFormatter.js +1 -0
- package/dist/core/InputNormalizer.d.ts +140 -0
- package/dist/core/InputNormalizer.d.ts.map +1 -0
- package/dist/core/InputNormalizer.js +95 -0
- package/dist/core/InputNormalizer.js.map +1 -0
- package/dist/core/PersistenceBuffer.d.ts +204 -0
- package/dist/core/PersistenceBuffer.d.ts.map +1 -0
- package/dist/core/PersistenceBuffer.js +382 -0
- package/dist/core/PersistenceBuffer.js.map +1 -0
- package/dist/core/PersistenceBufferErrors.d.ts +22 -0
- package/dist/core/PersistenceBufferErrors.d.ts.map +1 -0
- package/dist/core/PersistenceBufferErrors.js +30 -0
- package/dist/core/PersistenceBufferErrors.js.map +1 -0
- package/dist/core/PersistenceRestore.d.ts +21 -0
- package/dist/core/PersistenceRestore.d.ts.map +1 -0
- package/dist/core/PersistenceRestore.js +87 -0
- package/dist/core/PersistenceRestore.js.map +1 -0
- package/dist/core/PersistenceWorkQueue.d.ts +155 -0
- package/dist/core/PersistenceWorkQueue.d.ts.map +1 -0
- package/dist/core/PersistenceWorkQueue.js +298 -0
- package/dist/core/PersistenceWorkQueue.js.map +1 -0
- package/dist/core/PersistenceWriter.d.ts +55 -0
- package/dist/core/PersistenceWriter.d.ts.map +1 -0
- package/dist/core/PersistenceWriter.js +112 -0
- package/dist/core/PersistenceWriter.js.map +1 -0
- package/dist/core/SessionErrors.d.ts +37 -0
- package/dist/core/SessionErrors.d.ts.map +1 -0
- package/dist/core/SessionErrors.js +50 -0
- package/dist/core/SessionErrors.js.map +1 -0
- package/dist/core/SessionLifecycleCoordinator.d.ts +74 -0
- package/dist/core/SessionLifecycleCoordinator.d.ts.map +1 -0
- package/dist/core/SessionLifecycleCoordinator.js +222 -0
- package/dist/core/SessionLifecycleCoordinator.js.map +1 -0
- package/dist/core/SessionLock.d.ts +59 -0
- package/dist/core/SessionLock.d.ts.map +1 -0
- package/dist/core/SessionLock.js +39 -0
- package/dist/core/SessionLock.js.map +1 -0
- package/dist/core/SessionManager.d.ts +62 -0
- package/dist/core/SessionManager.d.ts.map +1 -0
- package/dist/core/SessionManager.js +75 -0
- package/dist/core/SessionManager.js.map +1 -0
- package/dist/core/SessionResetCoordinator.d.ts +37 -0
- package/dist/core/SessionResetCoordinator.d.ts.map +1 -0
- package/dist/core/SessionResetCoordinator.js +80 -0
- package/dist/core/SessionResetCoordinator.js.map +1 -0
- package/dist/core/ThoughtEvaluator.d.ts +48 -0
- package/dist/core/ThoughtEvaluator.d.ts.map +1 -0
- package/dist/core/ThoughtEvaluator.js +85 -0
- package/dist/core/ThoughtEvaluator.js.map +1 -0
- package/dist/core/ThoughtFormatter.d.ts +134 -0
- package/dist/core/ThoughtFormatter.d.ts.map +1 -0
- package/dist/core/ThoughtFormatter.js +118 -0
- package/dist/core/ThoughtFormatter.js.map +1 -0
- package/dist/core/ThoughtProcessor.d.ts +259 -0
- package/dist/core/ThoughtProcessor.d.ts.map +1 -0
- package/dist/core/ThoughtProcessor.js +451 -0
- package/dist/core/ThoughtProcessor.js.map +1 -0
- package/dist/core/ThoughtReferenceIndex.d.ts +23 -0
- package/dist/core/ThoughtReferenceIndex.d.ts.map +1 -0
- package/dist/core/ThoughtReferenceIndex.js +66 -0
- package/dist/core/ThoughtReferenceIndex.js.map +1 -0
- package/dist/core/VerificationOutcomeAdmission.d.ts +15 -0
- package/dist/core/VerificationOutcomeAdmission.d.ts.map +1 -0
- package/dist/core/VerificationOutcomeAdmission.js +28 -0
- package/dist/core/VerificationOutcomeAdmission.js.map +1 -0
- package/dist/core/compression/CompressionService.d.ts +76 -0
- package/dist/core/compression/CompressionService.d.ts.map +1 -0
- package/dist/core/compression/CompressionService.js +160 -0
- package/dist/core/compression/CompressionService.js.map +1 -0
- package/dist/core/compression/DehydrationPolicy.d.ts +75 -0
- package/dist/core/compression/DehydrationPolicy.d.ts.map +1 -0
- package/dist/core/compression/DehydrationPolicy.js +45 -0
- package/dist/core/compression/DehydrationPolicy.js.map +1 -0
- package/dist/core/compression/InMemorySummaryStore.d.ts +132 -0
- package/dist/core/compression/InMemorySummaryStore.d.ts.map +1 -0
- package/dist/core/compression/InMemorySummaryStore.js +69 -0
- package/dist/core/compression/InMemorySummaryStore.js.map +1 -0
- package/dist/core/compression/Summary.d.ts +74 -0
- package/dist/core/compression/Summary.d.ts.map +1 -0
- package/dist/core/compression/Summary.js +16 -0
- package/dist/core/compression/Summary.js.map +1 -0
- package/dist/core/evaluator/Aggregator.d.ts +40 -0
- package/dist/core/evaluator/Aggregator.d.ts.map +1 -0
- package/dist/core/evaluator/Aggregator.js +36 -0
- package/dist/core/evaluator/Aggregator.js.map +1 -0
- package/dist/core/evaluator/Calibrator.d.ts +52 -0
- package/dist/core/evaluator/Calibrator.d.ts.map +1 -0
- package/dist/core/evaluator/Calibrator.js +135 -0
- package/dist/core/evaluator/Calibrator.js.map +1 -0
- package/dist/core/evaluator/PatternDetector.d.ts +69 -0
- package/dist/core/evaluator/PatternDetector.d.ts.map +1 -0
- package/dist/core/evaluator/PatternDetector.js +192 -0
- package/dist/core/evaluator/PatternDetector.js.map +1 -0
- package/dist/core/evaluator/SignalComputer.d.ts +116 -0
- package/dist/core/evaluator/SignalComputer.d.ts.map +1 -0
- package/dist/core/evaluator/SignalComputer.js +110 -0
- package/dist/core/evaluator/SignalComputer.js.map +1 -0
- package/dist/core/evaluator/calibration-math.d.ts +39 -0
- package/dist/core/evaluator/calibration-math.d.ts.map +1 -0
- package/dist/core/evaluator/calibration-math.js +42 -0
- package/dist/core/evaluator/calibration-math.js.map +1 -0
- package/dist/core/evaluator/internals.d.ts +36 -0
- package/dist/core/evaluator/internals.d.ts.map +1 -0
- package/dist/core/evaluator/internals.js +43 -0
- package/dist/core/evaluator/internals.js.map +1 -0
- package/dist/core/graph/Edge.d.ts +58 -0
- package/dist/core/graph/Edge.d.ts.map +1 -0
- package/dist/core/graph/Edge.js +1 -0
- package/dist/core/graph/EdgeEmitter.d.ts +68 -0
- package/dist/core/graph/EdgeEmitter.d.ts.map +1 -0
- package/dist/core/graph/EdgeEmitter.js +118 -0
- package/dist/core/graph/EdgeEmitter.js.map +1 -0
- package/dist/core/graph/EdgeStore.d.ts +116 -0
- package/dist/core/graph/EdgeStore.d.ts.map +1 -0
- package/dist/core/graph/EdgeStore.js +107 -0
- package/dist/core/graph/EdgeStore.js.map +1 -0
- package/dist/core/graph/GraphView.d.ts +157 -0
- package/dist/core/graph/GraphView.d.ts.map +1 -0
- package/dist/core/graph/GraphView.js +149 -0
- package/dist/core/graph/GraphView.js.map +1 -0
- package/dist/core/ids.d.ts +33 -0
- package/dist/core/ids.d.ts.map +1 -0
- package/dist/core/ids.js +11 -0
- package/dist/core/ids.js.map +1 -0
- package/dist/core/reasoning/OutcomeRecorder.d.ts +88 -0
- package/dist/core/reasoning/OutcomeRecorder.d.ts.map +1 -0
- package/dist/core/reasoning/OutcomeRecorder.js +51 -0
- package/dist/core/reasoning/OutcomeRecorder.js.map +1 -0
- package/dist/core/reasoning/strategies/SequentialStrategy.d.ts +54 -0
- package/dist/core/reasoning/strategies/SequentialStrategy.d.ts.map +1 -0
- package/dist/core/reasoning/strategies/SequentialStrategy.js +22 -0
- package/dist/core/reasoning/strategies/SequentialStrategy.js.map +1 -0
- package/dist/core/reasoning/strategies/StrategyFactory.d.ts +25 -0
- package/dist/core/reasoning/strategies/StrategyFactory.d.ts.map +1 -0
- package/dist/core/reasoning/strategies/StrategyFactory.js +16 -0
- package/dist/core/reasoning/strategies/StrategyFactory.js.map +1 -0
- package/dist/core/reasoning/strategies/TreeOfThoughtStrategy.d.ts +58 -0
- package/dist/core/reasoning/strategies/TreeOfThoughtStrategy.d.ts.map +1 -0
- package/dist/core/reasoning/strategies/TreeOfThoughtStrategy.js +103 -0
- package/dist/core/reasoning/strategies/TreeOfThoughtStrategy.js.map +1 -0
- package/dist/core/reasoning/strategies/plateau.d.ts +18 -0
- package/dist/core/reasoning/strategies/plateau.d.ts.map +1 -0
- package/dist/core/reasoning/strategies/plateau.js +12 -0
- package/dist/core/reasoning/strategies/plateau.js.map +1 -0
- package/dist/core/reasoning/strategies/totScoring.d.ts +91 -0
- package/dist/core/reasoning/strategies/totScoring.d.ts.map +1 -0
- package/dist/core/reasoning/strategies/totScoring.js +88 -0
- package/dist/core/reasoning/strategies/totScoring.js.map +1 -0
- package/dist/core/reasoning.d.ts +179 -0
- package/dist/core/reasoning.d.ts.map +1 -0
- package/dist/core/reasoning.js +1 -0
- package/dist/core/step.d.ts +50 -0
- package/dist/core/step.d.ts.map +1 -0
- package/dist/core/step.js +1 -0
- package/dist/core/thought.d.ts +113 -0
- package/dist/core/thought.d.ts.map +1 -0
- package/dist/core/thought.js +1 -0
- package/dist/core/tools/InMemorySuspensionStore.d.ts +66 -0
- package/dist/core/tools/InMemorySuspensionStore.d.ts.map +1 -0
- package/dist/core/tools/InMemorySuspensionStore.js +121 -0
- package/dist/core/tools/InMemorySuspensionStore.js.map +1 -0
- package/dist/di/Container.d.ts +253 -0
- package/dist/di/Container.d.ts.map +1 -0
- package/dist/di/Container.js +111 -0
- package/dist/di/Container.js.map +1 -0
- package/dist/di/ServiceRegistry.d.ts +50 -0
- package/dist/di/ServiceRegistry.d.ts.map +1 -0
- package/dist/di/ServiceRegistry.js +1 -0
- package/dist/errors.d.ts +663 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +282 -0
- package/dist/errors.js.map +1 -0
- package/dist/health/HealthChecker.d.ts +73 -0
- package/dist/health/HealthChecker.d.ts.map +1 -0
- package/dist/health/HealthChecker.js +70 -0
- package/dist/health/HealthChecker.js.map +1 -0
- package/dist/lib.d.ts +273 -0
- package/dist/lib.d.ts.map +1 -0
- package/dist/lib.js +409 -0
- package/dist/lib.js.map +1 -0
- package/dist/logger/NullLogger.d.ts +154 -0
- package/dist/logger/NullLogger.d.ts.map +1 -0
- package/dist/logger/NullLogger.js +24 -0
- package/dist/logger/NullLogger.js.map +1 -0
- package/dist/logger/StructuredLogger.d.ts +327 -0
- package/dist/logger/StructuredLogger.d.ts.map +1 -0
- package/dist/logger/StructuredLogger.js +72 -0
- package/dist/logger/StructuredLogger.js.map +1 -0
- package/dist/metrics/metrics.impl.d.ts +252 -0
- package/dist/metrics/metrics.impl.d.ts.map +1 -0
- package/dist/metrics/metrics.impl.js +197 -0
- package/dist/metrics/metrics.impl.js.map +1 -0
- package/dist/persistence/FileLegacyImport.d.ts +2 -0
- package/dist/persistence/FileLegacyImport.d.ts.map +1 -0
- package/dist/persistence/FileLegacyImport.js +183 -0
- package/dist/persistence/FileLegacyImport.js.map +1 -0
- package/dist/persistence/FilePersistence.d.ts +53 -0
- package/dist/persistence/FilePersistence.d.ts.map +1 -0
- package/dist/persistence/FilePersistence.js +312 -0
- package/dist/persistence/FilePersistence.js.map +1 -0
- package/dist/persistence/FileSnapshotTypes.d.ts +29 -0
- package/dist/persistence/FileSnapshotTypes.d.ts.map +1 -0
- package/dist/persistence/FileSnapshotTypes.js +1 -0
- package/dist/persistence/FileSnapshotV2.d.ts +377 -0
- package/dist/persistence/FileSnapshotV2.d.ts.map +1 -0
- package/dist/persistence/FileSnapshotV2.js +124 -0
- package/dist/persistence/FileSnapshotV2.js.map +1 -0
- package/dist/persistence/FileSnapshotValidation.d.ts +15 -0
- package/dist/persistence/FileSnapshotValidation.d.ts.map +1 -0
- package/dist/persistence/FileSnapshotValidation.js +64 -0
- package/dist/persistence/FileSnapshotValidation.js.map +1 -0
- package/dist/persistence/FileWriter.d.ts +30 -0
- package/dist/persistence/FileWriter.d.ts.map +1 -0
- package/dist/persistence/FileWriter.js +155 -0
- package/dist/persistence/FileWriter.js.map +1 -0
- package/dist/persistence/MemoryPersistence.d.ts +45 -0
- package/dist/persistence/MemoryPersistence.d.ts.map +1 -0
- package/dist/persistence/MemoryPersistence.js +180 -0
- package/dist/persistence/MemoryPersistence.js.map +1 -0
- package/dist/persistence/PersistenceCodec.d.ts +7 -0
- package/dist/persistence/PersistenceCodec.d.ts.map +1 -0
- package/dist/persistence/PersistenceCodec.js +97 -0
- package/dist/persistence/PersistenceCodec.js.map +1 -0
- package/dist/persistence/PersistenceErrors.d.ts +23 -0
- package/dist/persistence/PersistenceErrors.d.ts.map +1 -0
- package/dist/persistence/PersistenceErrors.js +26 -0
- package/dist/persistence/PersistenceErrors.js.map +1 -0
- package/dist/persistence/PersistenceFactory.d.ts +21 -0
- package/dist/persistence/PersistenceFactory.d.ts.map +1 -0
- package/dist/persistence/PersistenceFactory.js +28 -0
- package/dist/persistence/PersistenceFactory.js.map +1 -0
- package/dist/persistence/PersistenceScope.d.ts +42 -0
- package/dist/persistence/PersistenceScope.d.ts.map +1 -0
- package/dist/persistence/PersistenceScope.js +93 -0
- package/dist/persistence/PersistenceScope.js.map +1 -0
- package/dist/persistence/SessionScopedPersistence.d.ts +4 -0
- package/dist/persistence/SessionScopedPersistence.d.ts.map +1 -0
- package/dist/persistence/SessionScopedPersistence.js +9 -0
- package/dist/persistence/SessionScopedPersistence.js.map +1 -0
- package/dist/persistence/SqliteDriver.d.ts +22 -0
- package/dist/persistence/SqliteDriver.d.ts.map +1 -0
- package/dist/persistence/SqliteDriver.js +29 -0
- package/dist/persistence/SqliteDriver.js.map +1 -0
- package/dist/persistence/SqliteLegacyImport.d.ts +14 -0
- package/dist/persistence/SqliteLegacyImport.d.ts.map +1 -0
- package/dist/persistence/SqliteLegacyImport.js +136 -0
- package/dist/persistence/SqliteLegacyImport.js.map +1 -0
- package/dist/persistence/SqliteLegacySchema.d.ts +15 -0
- package/dist/persistence/SqliteLegacySchema.d.ts.map +1 -0
- package/dist/persistence/SqliteLegacySchema.js +72 -0
- package/dist/persistence/SqliteLegacySchema.js.map +1 -0
- package/dist/persistence/SqlitePayload.d.ts +11 -0
- package/dist/persistence/SqlitePayload.d.ts.map +1 -0
- package/dist/persistence/SqlitePayload.js +86 -0
- package/dist/persistence/SqlitePayload.js.map +1 -0
- package/dist/persistence/SqlitePersistence.d.ts +49 -0
- package/dist/persistence/SqlitePersistence.d.ts.map +1 -0
- package/dist/persistence/SqlitePersistence.js +248 -0
- package/dist/persistence/SqlitePersistence.js.map +1 -0
- package/dist/persistence/SqliteSchemaV2.d.ts +14 -0
- package/dist/persistence/SqliteSchemaV2.d.ts.map +1 -0
- package/dist/persistence/SqliteSchemaV2.js +129 -0
- package/dist/persistence/SqliteSchemaV2.js.map +1 -0
- package/dist/persistence/SqliteSnapshotWriter.d.ts +17 -0
- package/dist/persistence/SqliteSnapshotWriter.d.ts.map +1 -0
- package/dist/persistence/SqliteSnapshotWriter.js +30 -0
- package/dist/persistence/SqliteSnapshotWriter.js.map +1 -0
- package/dist/pool/ConnectionPool.d.ts +203 -0
- package/dist/pool/ConnectionPool.d.ts.map +1 -0
- package/dist/pool/ConnectionPool.js +303 -0
- package/dist/pool/ConnectionPool.js.map +1 -0
- package/dist/pool/IConnectionPool.d.ts +143 -0
- package/dist/pool/IConnectionPool.d.ts.map +1 -0
- package/dist/pool/IConnectionPool.js +1 -0
- package/dist/pool/PoolErrors.d.ts +11 -0
- package/dist/pool/PoolErrors.d.ts.map +1 -0
- package/dist/pool/PoolErrors.js +16 -0
- package/dist/pool/PoolErrors.js.map +1 -0
- package/dist/registry/BaseRegistry.d.ts +219 -0
- package/dist/registry/BaseRegistry.d.ts.map +1 -0
- package/dist/registry/BaseRegistry.js +215 -0
- package/dist/registry/BaseRegistry.js.map +1 -0
- package/dist/registry/SkillRegistry.d.ts +67 -0
- package/dist/registry/SkillRegistry.d.ts.map +1 -0
- package/dist/registry/SkillRegistry.js +87 -0
- package/dist/registry/SkillRegistry.js.map +1 -0
- package/dist/registry/ToolRegistry.d.ts +70 -0
- package/dist/registry/ToolRegistry.d.ts.map +1 -0
- package/dist/registry/ToolRegistry.js +96 -0
- package/dist/registry/ToolRegistry.js.map +1 -0
- package/dist/sanitize.d.ts +164 -0
- package/dist/sanitize.d.ts.map +1 -0
- package/dist/sanitize.js +100 -0
- package/dist/sanitize.js.map +1 -0
- package/dist/schema.d.ts +562 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +251 -0
- package/dist/schema.js.map +1 -0
- package/dist/transport/BaseTransport.d.ts +166 -0
- package/dist/transport/BaseTransport.d.ts.map +1 -0
- package/dist/transport/BaseTransport.js +199 -0
- package/dist/transport/BaseTransport.js.map +1 -0
- package/dist/transport/HttpHelpers.d.ts +53 -0
- package/dist/transport/HttpHelpers.d.ts.map +1 -0
- package/dist/transport/HttpHelpers.js +44 -0
- package/dist/transport/HttpHelpers.js.map +1 -0
- package/dist/transport/HttpRequestLifecycle.d.ts +37 -0
- package/dist/transport/HttpRequestLifecycle.d.ts.map +1 -0
- package/dist/transport/HttpRequestLifecycle.js +87 -0
- package/dist/transport/HttpRequestLifecycle.js.map +1 -0
- package/dist/transport/HttpTransport.d.ts +140 -0
- package/dist/transport/HttpTransport.d.ts.map +1 -0
- package/dist/transport/HttpTransport.js +245 -0
- package/dist/transport/HttpTransport.js.map +1 -0
- package/dist/transport/SseTransport.d.ts +149 -0
- package/dist/transport/SseTransport.d.ts.map +1 -0
- package/dist/transport/SseTransport.js +470 -0
- package/dist/transport/SseTransport.js.map +1 -0
- package/dist/transport/StreamableHttpTransport.d.ts +225 -0
- package/dist/transport/StreamableHttpTransport.d.ts.map +1 -0
- package/dist/transport/StreamableHttpTransport.js +449 -0
- package/dist/transport/StreamableHttpTransport.js.map +1 -0
- package/dist/types/disposable.d.ts +22 -0
- package/dist/types/disposable.d.ts.map +1 -0
- package/dist/types/disposable.js +1 -0
- package/dist/types/server-config.d.ts +32 -0
- package/dist/types/server-config.d.ts.map +1 -0
- package/dist/types/server-config.js +1 -0
- package/dist/types/skill.d.ts +74 -0
- package/dist/types/skill.d.ts.map +1 -0
- package/dist/types/skill.js +1 -0
- package/dist/types/tool.d.ts +78 -0
- package/dist/types/tool.d.ts.map +1 -0
- package/dist/types/tool.js +1 -0
- package/dist/utils.d.ts +27 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +6 -0
- package/dist/utils.js.map +1 -0
- package/dist/watchers/SkillWatcher.d.ts +25 -0
- package/dist/watchers/SkillWatcher.d.ts.map +1 -0
- package/dist/watchers/SkillWatcher.js +96 -0
- package/dist/watchers/SkillWatcher.js.map +1 -0
- package/dist/watchers/ToolWatcher.d.ts +24 -0
- package/dist/watchers/ToolWatcher.d.ts.map +1 -0
- package/dist/watchers/ToolWatcher.js +92 -0
- package/dist/watchers/ToolWatcher.js.map +1 -0
- package/package.json +106 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { SequentialThinkingError } from "../../errors.js";
|
|
2
|
+
import { asBranchId, asSessionId, asSummaryId } from "../../contracts/ids.js";
|
|
3
|
+
function branchKey(sessionId, branchId) {
|
|
4
|
+
return asBranchId(`${sessionId}:${branchId}`);
|
|
5
|
+
}
|
|
6
|
+
class InMemorySummaryStore {
|
|
7
|
+
_byId = new Map();
|
|
8
|
+
_bySession = new Map();
|
|
9
|
+
_byBranch = new Map();
|
|
10
|
+
add(summary) {
|
|
11
|
+
let sessionIds = this._byId.get(summary.sessionId);
|
|
12
|
+
if (void 0 === sessionIds) {
|
|
13
|
+
sessionIds = new Map();
|
|
14
|
+
this._byId.set(summary.sessionId, sessionIds);
|
|
15
|
+
}
|
|
16
|
+
if (sessionIds.has(asSummaryId(summary.id))) throw new SequentialThinkingError(`Duplicate summary id: ${summary.id}`, 'DUPLICATE_SUMMARY');
|
|
17
|
+
sessionIds.set(asSummaryId(summary.id), summary);
|
|
18
|
+
this._insertSorted(this._bySession, summary.sessionId, summary);
|
|
19
|
+
if (void 0 !== summary.branchId) this._insertSorted(this._byBranch, branchKey(asSessionId(summary.sessionId), summary.branchId), summary);
|
|
20
|
+
}
|
|
21
|
+
get(id) {
|
|
22
|
+
for (const sessionIds of this._byId.values()){
|
|
23
|
+
const summary = sessionIds.get(asSummaryId(id));
|
|
24
|
+
if (void 0 !== summary) return summary;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
forSession(sessionId) {
|
|
28
|
+
return this._bySession.get(asSessionId(sessionId)) ?? [];
|
|
29
|
+
}
|
|
30
|
+
forBranch(sessionId, branchId) {
|
|
31
|
+
return this._byBranch.get(branchKey(asSessionId(sessionId), branchId)) ?? [];
|
|
32
|
+
}
|
|
33
|
+
clearSession(sessionId) {
|
|
34
|
+
const summaries = this._bySession.get(asSessionId(sessionId));
|
|
35
|
+
if (!summaries) return;
|
|
36
|
+
for (const summary of summaries)if (void 0 !== summary.branchId) this._byBranch.delete(branchKey(asSessionId(sessionId), summary.branchId));
|
|
37
|
+
this._byId.delete(asSessionId(sessionId));
|
|
38
|
+
this._bySession.delete(asSessionId(sessionId));
|
|
39
|
+
}
|
|
40
|
+
clearAll() {
|
|
41
|
+
this._byId.clear();
|
|
42
|
+
this._bySession.clear();
|
|
43
|
+
this._byBranch.clear();
|
|
44
|
+
}
|
|
45
|
+
size(sessionId) {
|
|
46
|
+
if (void 0 !== sessionId) return this._bySession.get(asSessionId(sessionId))?.length ?? 0;
|
|
47
|
+
let total = 0;
|
|
48
|
+
for (const sessionIds of this._byId.values())total += sessionIds.size;
|
|
49
|
+
return total;
|
|
50
|
+
}
|
|
51
|
+
_insertSorted(index, key, summary) {
|
|
52
|
+
let bucket = index.get(key);
|
|
53
|
+
if (!bucket) {
|
|
54
|
+
bucket = [];
|
|
55
|
+
index.set(key, bucket);
|
|
56
|
+
}
|
|
57
|
+
let lo = 0;
|
|
58
|
+
let hi = bucket.length;
|
|
59
|
+
while(lo < hi){
|
|
60
|
+
const mid = lo + hi >>> 1;
|
|
61
|
+
if (bucket[mid].createdAt <= summary.createdAt) lo = mid + 1;
|
|
62
|
+
else hi = mid;
|
|
63
|
+
}
|
|
64
|
+
bucket.splice(lo, 0, summary);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export { InMemorySummaryStore };
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=InMemorySummaryStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core/compression/InMemorySummaryStore.js","sources":["../../../src/core/compression/InMemorySummaryStore.ts"],"sourcesContent":["/**\n * InMemorySummaryStore — in-memory implementation of {@link ISummaryStore}.\n *\n * Stores compressed thought summaries in three indexes for O(1) point lookups\n * and O(n) bucket reads (n = result size). Per-session and per-branch isolation\n * is enforced by maintaining independent buckets keyed by session and\n * `${sessionId}:${branchId}`.\n *\n * The store is intentionally synchronous and pure in-memory — no I/O. Persistence\n * adapters may wrap this implementation if durability is required.\n *\n * @module core/compression/InMemorySummaryStore\n */\n\nimport { SequentialThinkingError } from '../../errors.js';\nimport type { ISummaryStore, Summary } from '../../contracts/summary.js';\nimport {\n\tasBranchId,\n\tasSessionId,\n\tasSummaryId,\n\ttype BranchId,\n\ttype SessionId,\n\ttype SummaryId,\n} from '../../contracts/ids.js';\n\n/**\n * Compose the composite branch key used by the per-branch index.\n *\n * The colon separator mirrors namespace conventions in the rest of the codebase\n * and is safe because session/branch ids are constrained to alphanumeric,\n * hyphen and underscore characters.\n */\nfunction branchKey(sessionId: SessionId, branchId: BranchId): BranchId {\n\treturn asBranchId(`${sessionId}:${branchId}`);\n}\n\n/**\n * In-memory implementation of {@link ISummaryStore}.\n *\n * Maintains three indexes:\n * - `_byId`: id → summary (global lookup)\n * - `_bySession`: sessionId → summaries[] (sorted by `createdAt` ascending)\n * - `_byBranch`: `${sessionId}:${branchId}` → summaries[] (sorted by `createdAt`)\n *\n * @example\n * ```typescript\n * const store = new InMemorySummaryStore();\n * store.add({\n * id: '01HX...',\n * sessionId: 's1',\n * rootThoughtId: 't5',\n * coveredIds: ['t5', 't6'],\n * coveredRange: [5, 6],\n * topics: ['cache', 'lookup'],\n * aggregateConfidence: 0.8,\n * createdAt: Date.now(),\n * });\n * const all = store.forSession('s1');\n * ```\n */\nexport class InMemorySummaryStore implements ISummaryStore {\n\tprivate readonly _byId: Map<SessionId, Map<SummaryId, Summary>> = new Map();\n\tprivate readonly _bySession: Map<SessionId, Summary[]> = new Map();\n\tprivate readonly _byBranch: Map<BranchId, Summary[]> = new Map();\n\n\t/**\n\t * Add a summary to the store.\n\t *\n\t * Inserts the summary into all three indexes, maintaining ascending\n\t * `createdAt` order in the per-session and per-branch buckets via binary\n\t * search insertion (O(log n)).\n\t *\n\t * @param summary - The summary record to add\n\t * @throws {SequentialThinkingError} When a summary with the same id already exists\n\t *\n\t * @example\n\t * ```typescript\n\t * store.add(summary);\n\t * ```\n\t */\n\tadd(summary: Summary): void {\n\t\tlet sessionIds = this._byId.get(summary.sessionId);\n\t\tif (sessionIds === undefined) {\n\t\t\tsessionIds = new Map<SummaryId, Summary>();\n\t\t\tthis._byId.set(summary.sessionId, sessionIds);\n\t\t}\n\t\tif (sessionIds.has(asSummaryId(summary.id))) {\n\t\t\tthrow new SequentialThinkingError(`Duplicate summary id: ${summary.id}`, 'DUPLICATE_SUMMARY');\n\t\t}\n\n\t\tsessionIds.set(asSummaryId(summary.id), summary);\n\t\tthis._insertSorted(this._bySession, summary.sessionId, summary);\n\t\tif (summary.branchId !== undefined) {\n\t\t\tthis._insertSorted(\n\t\t\t\tthis._byBranch,\n\t\t\t\tbranchKey(asSessionId(summary.sessionId), summary.branchId),\n\t\t\t\tsummary\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Retrieve a summary by its unique id.\n\t *\n\t * @param id - The summary's unique identifier\n\t * @returns The summary, or `undefined` if not found\n\t *\n\t * @example\n\t * ```typescript\n\t * const s = store.get('01HX...');\n\t * ```\n\t */\n\tget(id: string): Summary | undefined {\n\t\tfor (const sessionIds of this._byId.values()) {\n\t\t\tconst summary = sessionIds.get(asSummaryId(id));\n\t\t\tif (summary !== undefined) return summary;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Get all summaries for a session, sorted by `createdAt` ascending.\n\t *\n\t * @param sessionId - Session to query\n\t * @returns Read-only array of summaries (empty if none)\n\t *\n\t * @example\n\t * ```typescript\n\t * for (const s of store.forSession('s1')) console.log(s.topics);\n\t * ```\n\t */\n\tforSession(sessionId: string): readonly Summary[] {\n\t\treturn this._bySession.get(asSessionId(sessionId)) ?? [];\n\t}\n\n\t/**\n\t * Get all summaries on a specific branch within a session.\n\t *\n\t * @param sessionId - Session to query\n\t * @param branchId - Branch identifier\n\t * @returns Read-only array of summaries (empty if none)\n\t *\n\t * @example\n\t * ```typescript\n\t * const branch = store.forBranch('s1', 'alt-1');\n\t * ```\n\t */\n\tforBranch(sessionId: string, branchId: BranchId): readonly Summary[] {\n\t\treturn this._byBranch.get(branchKey(asSessionId(sessionId), branchId)) ?? [];\n\t}\n\n\t/**\n\t * Remove all summaries for a session. Other sessions are unaffected.\n\t *\n\t * Removes entries from all three indexes in a single pass over the\n\t * session's summary list.\n\t *\n\t * @param sessionId - Session to clear\n\t *\n\t * @example\n\t * ```typescript\n\t * store.clearSession('s1');\n\t * ```\n\t */\n\tclearSession(sessionId: string): void {\n\t\tconst summaries = this._bySession.get(asSessionId(sessionId));\n\t\tif (!summaries) {\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const summary of summaries) {\n\t\t\tif (summary.branchId !== undefined) {\n\t\t\t\tthis._byBranch.delete(branchKey(asSessionId(sessionId), summary.branchId));\n\t\t\t}\n\t\t}\n\t\tthis._byId.delete(asSessionId(sessionId));\n\t\tthis._bySession.delete(asSessionId(sessionId));\n\t}\n\n\tclearAll(): void {\n\t\tthis._byId.clear();\n\t\tthis._bySession.clear();\n\t\tthis._byBranch.clear();\n\t}\n\n\t/**\n\t * Count summaries.\n\t *\n\t * @param sessionId - If provided, count for that session only;\n\t * otherwise return the total across all sessions\n\t * @returns The number of summaries\n\t *\n\t * @example\n\t * ```typescript\n\t * const total = store.size();\n\t * const perSession = store.size('s1');\n\t * ```\n\t */\n\tsize(sessionId?: string): number {\n\t\tif (sessionId !== undefined) {\n\t\t\treturn this._bySession.get(asSessionId(sessionId))?.length ?? 0;\n\t\t}\n\t\tlet total = 0;\n\t\tfor (const sessionIds of this._byId.values()) total += sessionIds.size;\n\t\treturn total;\n\t}\n\n\t/**\n\t * Insert a summary into a bucket maintaining ascending `createdAt` order\n\t * via binary search (O(log n) search, O(n) splice).\n\t */\n\tprivate _insertSorted<K>(index: Map<K, Summary[]>, key: K, summary: Summary): void {\n\t\tlet bucket = index.get(key);\n\t\tif (!bucket) {\n\t\t\tbucket = [];\n\t\t\tindex.set(key, bucket);\n\t\t}\n\n\t\tlet lo = 0;\n\t\tlet hi = bucket.length;\n\t\twhile (lo < hi) {\n\t\t\tconst mid = (lo + hi) >>> 1;\n\t\t\tif (bucket[mid]!.createdAt <= summary.createdAt) {\n\t\t\t\tlo = mid + 1;\n\t\t\t} else {\n\t\t\t\thi = mid;\n\t\t\t}\n\t\t}\n\t\tbucket.splice(lo, 0, summary);\n\t}\n}\n"],"names":["branchKey","sessionId","branchId","asBranchId","InMemorySummaryStore","Map","summary","sessionIds","undefined","asSummaryId","SequentialThinkingError","asSessionId","id","summaries","total","index","key","bucket","lo","hi","mid"],"mappings":"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"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Summary type — compressed representation of a contiguous subtree of thoughts.
|
|
3
|
+
*
|
|
4
|
+
* Summaries collapse a range of thoughts (typically an entire branch or an
|
|
5
|
+
* older portion of the main chain) into a single record holding the union of
|
|
6
|
+
* their identifiers, an extracted topic vector, and an aggregate confidence.
|
|
7
|
+
* They are produced by the compression subsystem and consumed by reasoning
|
|
8
|
+
* strategies that need bounded-context views over long sessions.
|
|
9
|
+
*
|
|
10
|
+
* @module core/compression/Summary
|
|
11
|
+
*/
|
|
12
|
+
import * as v from 'valibot';
|
|
13
|
+
import type { BranchId, SessionId, ThoughtId } from '../../contracts/ids.js';
|
|
14
|
+
/**
|
|
15
|
+
* Immutable record describing a compressed group of thoughts.
|
|
16
|
+
*
|
|
17
|
+
* All fields are `readonly` to prevent post-creation mutation. Consumers
|
|
18
|
+
* should treat instances as value objects.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const summary: Summary = {
|
|
23
|
+
* id: '01HX...ulid',
|
|
24
|
+
* sessionId: 'sess_42',
|
|
25
|
+
* branchId: 'alt-1',
|
|
26
|
+
* rootThoughtId: 'thought-5',
|
|
27
|
+
* coveredIds: ['thought-5', 'thought-6', 'thought-7'],
|
|
28
|
+
* coveredRange: [5, 7],
|
|
29
|
+
* topics: ['cache', 'lookup', 'latency'],
|
|
30
|
+
* aggregateConfidence: 0.78,
|
|
31
|
+
* createdAt: Date.now(),
|
|
32
|
+
* };
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export interface Summary {
|
|
36
|
+
/** Unique identifier (ulid). */
|
|
37
|
+
readonly id: string;
|
|
38
|
+
/** Session this summary belongs to. */
|
|
39
|
+
readonly sessionId: SessionId;
|
|
40
|
+
/** Optional branch id; `undefined` indicates main-chain compression. */
|
|
41
|
+
readonly branchId?: BranchId;
|
|
42
|
+
/** `id` of the thought that anchors the compressed subtree. */
|
|
43
|
+
readonly rootThoughtId: ThoughtId;
|
|
44
|
+
/** Thought ids included in this summary, in chronological order. */
|
|
45
|
+
readonly coveredIds: readonly ThoughtId[];
|
|
46
|
+
/** Inclusive `[min, max]` of `thought_number` values covered. */
|
|
47
|
+
readonly coveredRange: readonly [number, number];
|
|
48
|
+
/** Top-3 unigrams extracted from the covered thought texts. */
|
|
49
|
+
readonly topics: readonly string[];
|
|
50
|
+
/** Weighted-mean confidence of the covered thoughts (0-1). */
|
|
51
|
+
readonly aggregateConfidence: number;
|
|
52
|
+
/** Creation timestamp (`Date.now()`). */
|
|
53
|
+
readonly createdAt: number;
|
|
54
|
+
/** Free-form metadata for strategy-specific extensions. */
|
|
55
|
+
readonly meta?: Record<string, unknown>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Valibot schema for runtime validation of {@link Summary} records loaded
|
|
59
|
+
* from persistence. IDs are validated as bounded strings; the brand is
|
|
60
|
+
* applied implicitly when consumers narrow the parsed value to `Summary`.
|
|
61
|
+
*/
|
|
62
|
+
export declare const SummarySchema: v.ObjectSchema<{
|
|
63
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 64, undefined>]>;
|
|
64
|
+
readonly sessionId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 100, undefined>]>;
|
|
65
|
+
readonly branchId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 64, undefined>]>, undefined>;
|
|
66
|
+
readonly rootThoughtId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 64, undefined>]>;
|
|
67
|
+
readonly coveredIds: v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 64, undefined>]>, undefined>;
|
|
68
|
+
readonly coveredRange: v.SchemaWithPipe<readonly [v.ArraySchema<v.NumberSchema<undefined>, undefined>, v.LengthAction<number[], 2, undefined>]>;
|
|
69
|
+
readonly topics: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
70
|
+
readonly aggregateConfidence: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 1, undefined>]>;
|
|
71
|
+
readonly createdAt: v.NumberSchema<undefined>;
|
|
72
|
+
readonly meta: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.UnknownSchema, undefined>, undefined>;
|
|
73
|
+
}, undefined>;
|
|
74
|
+
//# sourceMappingURL=Summary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Summary.d.ts","sourceRoot":"","sources":["../../../src/core/compression/Summary.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAC7B,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAE7E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,OAAO;IACvB,gCAAgC;IAChC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,uCAAuC;IACvC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,wEAAwE;IACxE,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAC7B,+DAA+D;IAC/D,QAAQ,CAAC,aAAa,EAAE,SAAS,CAAC;IAClC,oEAAoE;IACpE,QAAQ,CAAC,UAAU,EAAE,SAAS,SAAS,EAAE,CAAC;IAC1C,iEAAiE;IACjE,QAAQ,CAAC,YAAY,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjD,+DAA+D;IAC/D,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,8DAA8D;IAC9D,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;IACrC,yCAAyC;IACzC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,2DAA2D;IAC3D,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACxC;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;aAyBxB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as __rspack_external_valibot from "valibot";
|
|
2
|
+
const SummarySchema = __rspack_external_valibot.object({
|
|
3
|
+
id: __rspack_external_valibot.pipe(__rspack_external_valibot.string(), __rspack_external_valibot.minLength(1), __rspack_external_valibot.maxLength(64)),
|
|
4
|
+
sessionId: __rspack_external_valibot.pipe(__rspack_external_valibot.string(), __rspack_external_valibot.minLength(1), __rspack_external_valibot.maxLength(100)),
|
|
5
|
+
branchId: __rspack_external_valibot.optional(__rspack_external_valibot.pipe(__rspack_external_valibot.string(), __rspack_external_valibot.minLength(1), __rspack_external_valibot.maxLength(64))),
|
|
6
|
+
rootThoughtId: __rspack_external_valibot.pipe(__rspack_external_valibot.string(), __rspack_external_valibot.minLength(1), __rspack_external_valibot.maxLength(64)),
|
|
7
|
+
coveredIds: __rspack_external_valibot.array(__rspack_external_valibot.pipe(__rspack_external_valibot.string(), __rspack_external_valibot.minLength(1), __rspack_external_valibot.maxLength(64))),
|
|
8
|
+
coveredRange: __rspack_external_valibot.pipe(__rspack_external_valibot.array(__rspack_external_valibot.number()), __rspack_external_valibot.length(2)),
|
|
9
|
+
topics: __rspack_external_valibot.array(__rspack_external_valibot.string()),
|
|
10
|
+
aggregateConfidence: __rspack_external_valibot.pipe(__rspack_external_valibot.number(), __rspack_external_valibot.minValue(0), __rspack_external_valibot.maxValue(1)),
|
|
11
|
+
createdAt: __rspack_external_valibot.number(),
|
|
12
|
+
meta: __rspack_external_valibot.optional(__rspack_external_valibot.record(__rspack_external_valibot.string(), __rspack_external_valibot.unknown()))
|
|
13
|
+
});
|
|
14
|
+
export { SummarySchema };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=Summary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core/compression/Summary.js","sources":["../../../src/core/compression/Summary.ts"],"sourcesContent":["/**\n * Summary type — compressed representation of a contiguous subtree of thoughts.\n *\n * Summaries collapse a range of thoughts (typically an entire branch or an\n * older portion of the main chain) into a single record holding the union of\n * their identifiers, an extracted topic vector, and an aggregate confidence.\n * They are produced by the compression subsystem and consumed by reasoning\n * strategies that need bounded-context views over long sessions.\n *\n * @module core/compression/Summary\n */\nimport * as v from 'valibot';\nimport type { BranchId, SessionId, ThoughtId } from '../../contracts/ids.js';\n\n/**\n * Immutable record describing a compressed group of thoughts.\n *\n * All fields are `readonly` to prevent post-creation mutation. Consumers\n * should treat instances as value objects.\n *\n * @example\n * ```ts\n * const summary: Summary = {\n * id: '01HX...ulid',\n * sessionId: 'sess_42',\n * branchId: 'alt-1',\n * rootThoughtId: 'thought-5',\n * coveredIds: ['thought-5', 'thought-6', 'thought-7'],\n * coveredRange: [5, 7],\n * topics: ['cache', 'lookup', 'latency'],\n * aggregateConfidence: 0.78,\n * createdAt: Date.now(),\n * };\n * ```\n */\nexport interface Summary {\n\t/** Unique identifier (ulid). */\n\treadonly id: string;\n\t/** Session this summary belongs to. */\n\treadonly sessionId: SessionId;\n\t/** Optional branch id; `undefined` indicates main-chain compression. */\n\treadonly branchId?: BranchId;\n\t/** `id` of the thought that anchors the compressed subtree. */\n\treadonly rootThoughtId: ThoughtId;\n\t/** Thought ids included in this summary, in chronological order. */\n\treadonly coveredIds: readonly ThoughtId[];\n\t/** Inclusive `[min, max]` of `thought_number` values covered. */\n\treadonly coveredRange: readonly [number, number];\n\t/** Top-3 unigrams extracted from the covered thought texts. */\n\treadonly topics: readonly string[];\n\t/** Weighted-mean confidence of the covered thoughts (0-1). */\n\treadonly aggregateConfidence: number;\n\t/** Creation timestamp (`Date.now()`). */\n\treadonly createdAt: number;\n\t/** Free-form metadata for strategy-specific extensions. */\n\treadonly meta?: Record<string, unknown>;\n}\n\n/**\n * Valibot schema for runtime validation of {@link Summary} records loaded\n * from persistence. IDs are validated as bounded strings; the brand is\n * applied implicitly when consumers narrow the parsed value to `Summary`.\n */\nexport const SummarySchema = v.object({\n\tid: v.pipe(v.string(), v.minLength(1), v.maxLength(64)),\n\tsessionId: v.pipe(v.string(), v.minLength(1), v.maxLength(100)),\n\tbranchId: v.optional(v.pipe(v.string(), v.minLength(1), v.maxLength(64))),\n\trootThoughtId: v.pipe(v.string(), v.minLength(1), v.maxLength(64)),\n\tcoveredIds: v.array(v.pipe(v.string(), v.minLength(1), v.maxLength(64))),\n\tcoveredRange: v.pipe(\n\t\tv.array(v.number()),\n\t\tv.length(2),\n\t),\n\ttopics: v.array(v.string()),\n\taggregateConfidence: v.pipe(v.number(), v.minValue(0), v.maxValue(1)),\n\tcreatedAt: v.number(),\n\tmeta: v.optional(v.record(v.string(), v.unknown())),\n}) satisfies v.GenericSchema<{\n\tid: string;\n\tsessionId: string;\n\tbranchId?: string;\n\trootThoughtId: string;\n\tcoveredIds: string[];\n\tcoveredRange: number[];\n\ttopics: string[];\n\taggregateConfidence: number;\n\tcreatedAt: number;\n\tmeta?: Record<string, unknown>;\n}>;\n"],"names":["SummarySchema","v"],"mappings":";AA+DO,MAAMA,gBAAgBC,0BAAAA,MAAQ,CAAC;IACrC,IAAIA,0BAAAA,IAAM,CAACA,0BAAAA,MAAQ,IAAIA,0BAAAA,SAAW,CAAC,IAAIA,0BAAAA,SAAW,CAAC;IACnD,WAAWA,0BAAAA,IAAM,CAACA,0BAAAA,MAAQ,IAAIA,0BAAAA,SAAW,CAAC,IAAIA,0BAAAA,SAAW,CAAC;IAC1D,UAAUA,0BAAAA,QAAU,CAACA,0BAAAA,IAAM,CAACA,0BAAAA,MAAQ,IAAIA,0BAAAA,SAAW,CAAC,IAAIA,0BAAAA,SAAW,CAAC;IACpE,eAAeA,0BAAAA,IAAM,CAACA,0BAAAA,MAAQ,IAAIA,0BAAAA,SAAW,CAAC,IAAIA,0BAAAA,SAAW,CAAC;IAC9D,YAAYA,0BAAAA,KAAO,CAACA,0BAAAA,IAAM,CAACA,0BAAAA,MAAQ,IAAIA,0BAAAA,SAAW,CAAC,IAAIA,0BAAAA,SAAW,CAAC;IACnE,cAAcA,0BAAAA,IAAM,CACnBA,0BAAAA,KAAO,CAACA,0BAAAA,MAAQ,KAChBA,0BAAAA,MAAQ,CAAC;IAEV,QAAQA,0BAAAA,KAAO,CAACA,0BAAAA,MAAQ;IACxB,qBAAqBA,0BAAAA,IAAM,CAACA,0BAAAA,MAAQ,IAAIA,0BAAAA,QAAU,CAAC,IAAIA,0BAAAA,QAAU,CAAC;IAClE,WAAWA,0BAAAA,MAAQ;IACnB,MAAMA,0BAAAA,QAAU,CAACA,0BAAAA,MAAQ,CAACA,0BAAAA,MAAQ,IAAIA,0BAAAA,OAAS;AAChD"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reasoning analytics aggregation.
|
|
3
|
+
*
|
|
4
|
+
* Provides the {@link Aggregator} class — a stateless service that computes
|
|
5
|
+
* aggregated {@link ReasoningStats} from thought history and branch data.
|
|
6
|
+
* Extracted from {@link ThoughtEvaluator} to isolate the stats-aggregation
|
|
7
|
+
* concern.
|
|
8
|
+
*
|
|
9
|
+
* @module core/evaluator/Aggregator
|
|
10
|
+
*/
|
|
11
|
+
import type { ReasoningStats } from '../reasoning.js';
|
|
12
|
+
import type { ThoughtData } from '../thought.js';
|
|
13
|
+
/**
|
|
14
|
+
* Stateless service that aggregates reasoning analytics from thought
|
|
15
|
+
* history and branch data.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* All methods are pure computations — no side effects, no I/O, no
|
|
19
|
+
* internal state. Designed to be registered as transient in the DI
|
|
20
|
+
* container.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const aggregator = new Aggregator();
|
|
25
|
+
* const stats = aggregator.computeReasoningStats(history, branches);
|
|
26
|
+
* console.log(stats.total_thoughts); // 12
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare class Aggregator {
|
|
30
|
+
/**
|
|
31
|
+
* Compute aggregated reasoning analytics.
|
|
32
|
+
* Pure computation from history + branches.
|
|
33
|
+
*
|
|
34
|
+
* @param history - All thoughts in the current session
|
|
35
|
+
* @param branches - Map of branch IDs to their thought arrays
|
|
36
|
+
* @returns Aggregated reasoning statistics for the session
|
|
37
|
+
*/
|
|
38
|
+
computeReasoningStats(history: ThoughtData[], branches: Record<string, ThoughtData[]>): ReasoningStats;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=Aggregator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Aggregator.d.ts","sourceRoot":"","sources":["../../../src/core/evaluator/Aggregator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAajD;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,UAAU;IACtB;;;;;;;OAOG;IACI,qBAAqB,CAC3B,OAAO,EAAE,WAAW,EAAE,EACtB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC,GACrC,cAAc;CAwCjB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { _computeChainDepth, _countByType } from "./internals.js";
|
|
2
|
+
function roundToPrecision(value, decimals = 10) {
|
|
3
|
+
const factor = Math.pow(10, decimals);
|
|
4
|
+
return Math.round(value * factor) / factor;
|
|
5
|
+
}
|
|
6
|
+
class Aggregator {
|
|
7
|
+
computeReasoningStats(history, branches) {
|
|
8
|
+
const typeCounts = _countByType(history);
|
|
9
|
+
const allScores = history.map((t)=>t.quality_score).filter((s)=>void 0 !== s);
|
|
10
|
+
const allConfidences = history.map((t)=>t.confidence).filter((c)=>void 0 !== c);
|
|
11
|
+
const hypotheses = history.filter((t)=>'hypothesis' === t.thought_type);
|
|
12
|
+
const hypothesisIds = new Set(hypotheses.map((t)=>t.hypothesis_id).filter(Boolean));
|
|
13
|
+
const verifiedIds = new Set(history.filter((t)=>'verification' === t.thought_type && t.hypothesis_id).map((t)=>t.hypothesis_id));
|
|
14
|
+
const unresolvedCount = [
|
|
15
|
+
...hypothesisIds
|
|
16
|
+
].filter((id)=>!verifiedIds.has(id)).length;
|
|
17
|
+
return {
|
|
18
|
+
total_thoughts: history.length,
|
|
19
|
+
total_branches: Object.keys(branches).length,
|
|
20
|
+
total_revisions: history.filter((t)=>t.is_revision).length,
|
|
21
|
+
total_merges: history.filter((t)=>(t.merge_from_thoughts?.length ?? 0) > 0 || (t.merge_branch_ids?.length ?? 0) > 0).length,
|
|
22
|
+
chain_depth: _computeChainDepth(history),
|
|
23
|
+
thought_type_counts: typeCounts,
|
|
24
|
+
hypothesis_count: hypothesisIds.size,
|
|
25
|
+
verified_hypothesis_count: [
|
|
26
|
+
...hypothesisIds
|
|
27
|
+
].filter((id)=>verifiedIds.has(id)).length,
|
|
28
|
+
unresolved_hypothesis_count: unresolvedCount,
|
|
29
|
+
average_quality_score: allScores.length > 0 ? roundToPrecision(allScores.reduce((a, b)=>a + b, 0) / allScores.length) : null,
|
|
30
|
+
average_confidence: allConfidences.length > 0 ? roundToPrecision(allConfidences.reduce((a, b)=>a + b, 0) / allConfidences.length) : null
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export { Aggregator };
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=Aggregator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core/evaluator/Aggregator.js","sources":["../../../src/core/evaluator/Aggregator.ts"],"sourcesContent":["/**\n * Reasoning analytics aggregation.\n *\n * Provides the {@link Aggregator} class — a stateless service that computes\n * aggregated {@link ReasoningStats} from thought history and branch data.\n * Extracted from {@link ThoughtEvaluator} to isolate the stats-aggregation\n * concern.\n *\n * @module core/evaluator/Aggregator\n */\n\nimport type { ReasoningStats } from '../reasoning.js';\nimport type { ThoughtData } from '../thought.js';\nimport { _computeChainDepth, _countByType } from './internals.js';\n\n/**\n * Round a numeric value to a fixed number of decimal places to mitigate\n * IEEE 754 floating-point accumulation errors (e.g. 0.9 + 0.8 averaging to\n * 0.8500000000000001 instead of 0.85).\n */\nfunction roundToPrecision(value: number, decimals: number = 10): number {\n\tconst factor = Math.pow(10, decimals);\n\treturn Math.round(value * factor) / factor;\n}\n\n/**\n * Stateless service that aggregates reasoning analytics from thought\n * history and branch data.\n *\n * @remarks\n * All methods are pure computations — no side effects, no I/O, no\n * internal state. Designed to be registered as transient in the DI\n * container.\n *\n * @example\n * ```typescript\n * const aggregator = new Aggregator();\n * const stats = aggregator.computeReasoningStats(history, branches);\n * console.log(stats.total_thoughts); // 12\n * ```\n */\nexport class Aggregator {\n\t/**\n\t * Compute aggregated reasoning analytics.\n\t * Pure computation from history + branches.\n\t *\n\t * @param history - All thoughts in the current session\n\t * @param branches - Map of branch IDs to their thought arrays\n\t * @returns Aggregated reasoning statistics for the session\n\t */\n\tpublic computeReasoningStats(\n\t\thistory: ThoughtData[],\n\t\tbranches: Record<string, ThoughtData[]>\n\t): ReasoningStats {\n\t\tconst typeCounts = _countByType(history);\n\t\tconst allScores = history\n\t\t\t.map((t) => t.quality_score)\n\t\t\t.filter((s): s is number => s !== undefined);\n\t\tconst allConfidences = history\n\t\t\t.map((t) => t.confidence)\n\t\t\t.filter((c): c is number => c !== undefined);\n\n\t\tconst hypotheses = history.filter((t) => t.thought_type === 'hypothesis');\n\t\tconst hypothesisIds = new Set(hypotheses.map((t) => t.hypothesis_id).filter(Boolean));\n\t\tconst verifiedIds = new Set(\n\t\t\thistory\n\t\t\t\t.filter((t) => t.thought_type === 'verification' && t.hypothesis_id)\n\t\t\t\t.map((t) => t.hypothesis_id)\n\t\t);\n\t\tconst unresolvedCount = [...hypothesisIds].filter((id) => !verifiedIds.has(id)).length;\n\n\t\treturn {\n\t\t\ttotal_thoughts: history.length,\n\t\t\ttotal_branches: Object.keys(branches).length,\n\t\t\ttotal_revisions: history.filter((t) => t.is_revision).length,\n\t\t\ttotal_merges: history.filter(\n\t\t\t\t(t) => (t.merge_from_thoughts?.length ?? 0) > 0 || (t.merge_branch_ids?.length ?? 0) > 0\n\t\t\t).length,\n\t\t\tchain_depth: _computeChainDepth(history),\n\t\t\tthought_type_counts: typeCounts,\n\t\t\thypothesis_count: hypothesisIds.size,\n\t\t\tverified_hypothesis_count: [...hypothesisIds].filter((id) => verifiedIds.has(id)).length,\n\t\t\tunresolved_hypothesis_count: unresolvedCount,\n\t\t\taverage_quality_score:\n\t\t\t\tallScores.length > 0\n\t\t\t\t\t? roundToPrecision(allScores.reduce((a, b) => a + b, 0) / allScores.length)\n\t\t\t\t\t: null,\n\t\t\taverage_confidence:\n\t\t\t\tallConfidences.length > 0\n\t\t\t\t\t? roundToPrecision(allConfidences.reduce((a, b) => a + b, 0) / allConfidences.length)\n\t\t\t\t\t: null,\n\t\t};\n\t}\n}\n"],"names":["roundToPrecision","value","decimals","factor","Math","Aggregator","history","branches","typeCounts","_countByType","allScores","t","s","undefined","allConfidences","c","hypotheses","hypothesisIds","Set","Boolean","verifiedIds","unresolvedCount","id","Object","_computeChainDepth","a","b"],"mappings":";AAoBA,SAASA,iBAAiBC,KAAa,EAAEC,WAAmB,EAAE;IAC7D,MAAMC,SAASC,KAAK,GAAG,CAAC,IAAIF;IAC5B,OAAOE,KAAK,KAAK,CAACH,QAAQE,UAAUA;AACrC;AAkBO,MAAME;IASL,sBACNC,OAAsB,EACtBC,QAAuC,EACtB;QACjB,MAAMC,aAAaC,aAAaH;QAChC,MAAMI,YAAYJ,QAChB,GAAG,CAAC,CAACK,IAAMA,EAAE,aAAa,EAC1B,MAAM,CAAC,CAACC,IAAmBA,AAAMC,WAAND;QAC7B,MAAME,iBAAiBR,QACrB,GAAG,CAAC,CAACK,IAAMA,EAAE,UAAU,EACvB,MAAM,CAAC,CAACI,IAAmBA,AAAMF,WAANE;QAE7B,MAAMC,aAAaV,QAAQ,MAAM,CAAC,CAACK,IAAMA,AAAmB,iBAAnBA,EAAE,YAAY;QACvD,MAAMM,gBAAgB,IAAIC,IAAIF,WAAW,GAAG,CAAC,CAACL,IAAMA,EAAE,aAAa,EAAE,MAAM,CAACQ;QAC5E,MAAMC,cAAc,IAAIF,IACvBZ,QACE,MAAM,CAAC,CAACK,IAAMA,AAAmB,mBAAnBA,EAAE,YAAY,IAAuBA,EAAE,aAAa,EAClE,GAAG,CAAC,CAACA,IAAMA,EAAE,aAAa;QAE7B,MAAMU,kBAAkB;eAAIJ;SAAc,CAAC,MAAM,CAAC,CAACK,KAAO,CAACF,YAAY,GAAG,CAACE,KAAK,MAAM;QAEtF,OAAO;YACN,gBAAgBhB,QAAQ,MAAM;YAC9B,gBAAgBiB,OAAO,IAAI,CAAChB,UAAU,MAAM;YAC5C,iBAAiBD,QAAQ,MAAM,CAAC,CAACK,IAAMA,EAAE,WAAW,EAAE,MAAM;YAC5D,cAAcL,QAAQ,MAAM,CAC3B,CAACK,IAAOA,AAAAA,CAAAA,EAAE,mBAAmB,EAAE,UAAU,KAAK,KAAMA,AAAAA,CAAAA,EAAE,gBAAgB,EAAE,UAAU,KAAK,GACtF,MAAM;YACR,aAAaa,mBAAmBlB;YAChC,qBAAqBE;YACrB,kBAAkBS,cAAc,IAAI;YACpC,2BAA2B;mBAAIA;aAAc,CAAC,MAAM,CAAC,CAACK,KAAOF,YAAY,GAAG,CAACE,KAAK,MAAM;YACxF,6BAA6BD;YAC7B,uBACCX,UAAU,MAAM,GAAG,IAChBV,iBAAiBU,UAAU,MAAM,CAAC,CAACe,GAAGC,IAAMD,IAAIC,GAAG,KAAKhB,UAAU,MAAM,IACxE;YACJ,oBACCI,eAAe,MAAM,GAAG,IACrBd,iBAAiBc,eAAe,MAAM,CAAC,CAACW,GAAGC,IAAMD,IAAIC,GAAG,KAAKZ,eAAe,MAAM,IAClF;QACL;IACD;AACD"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Confidence calibration for sequential thinking reasoning.
|
|
3
|
+
*
|
|
4
|
+
* Provides the {@link Calibrator} class — maps raw model confidence values
|
|
5
|
+
* to calibrated probabilities using per-type Beta(2, 2) priors and
|
|
6
|
+
* grid-searched temperature scaling. Reports calibration quality through
|
|
7
|
+
* Brier score and 10-bin Expected Calibration Error (ECE).
|
|
8
|
+
*
|
|
9
|
+
* Math summary:
|
|
10
|
+
* - **Per-type prior**: Beta(α=2, β=2), prior mean = 0.5. As outcomes accumulate
|
|
11
|
+
* for a type, the calibrated value shrinks toward the observed mean of that
|
|
12
|
+
* type with weight `priorWeight = 1 / (1 + n / 10)` where `n` is the type's
|
|
13
|
+
* sample count.
|
|
14
|
+
* - **Temperature scaling**: Grid search T ∈ {0.5, 0.75, 1.0, 1.25, 1.5, 2.0}
|
|
15
|
+
* minimizing negative log-likelihood (NLL) over recorded outcomes. Default T=1.0.
|
|
16
|
+
* Requires ≥10 outcomes; below that threshold only prior shrinkage is applied.
|
|
17
|
+
* - **Brier score**: `mean((predicted - actual)^2)` over recorded outcomes.
|
|
18
|
+
* - **ECE (10-bin)**: bucket predictions in 0.1 increments, compute weighted
|
|
19
|
+
* absolute deviation between bin mean confidence and bin accuracy.
|
|
20
|
+
*
|
|
21
|
+
* @module core/evaluator/Calibrator
|
|
22
|
+
*/
|
|
23
|
+
import type { CalibrationMetrics, CalibrationResult, ICalibrator } from '../../contracts/calibrator.js';
|
|
24
|
+
import type { IOutcomeRecorder } from '../../contracts/interfaces.js';
|
|
25
|
+
import type { ThoughtType } from '../reasoning.js';
|
|
26
|
+
import type { SessionId } from '../../contracts/ids.js';
|
|
27
|
+
/**
|
|
28
|
+
* Confidence calibration service.
|
|
29
|
+
*
|
|
30
|
+
* Stateless w.r.t. outcome storage (delegated to {@link IOutcomeRecorder}),
|
|
31
|
+
* but maintains a small per-session temperature cache that is recomputed
|
|
32
|
+
* via {@link Calibrator.refit}.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const calibrator = new Calibrator(outcomeRecorder, true);
|
|
37
|
+
* const result = calibrator.calibrate(0.9, 'hypothesis', 'session-1');
|
|
38
|
+
* console.log(result.calibrated, result.temperature, result.priorWeight);
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare class Calibrator implements ICalibrator {
|
|
42
|
+
readonly enabled: boolean;
|
|
43
|
+
private readonly _recorder;
|
|
44
|
+
private readonly _temperatures;
|
|
45
|
+
constructor(outcomeRecorder: IOutcomeRecorder, enabled: boolean);
|
|
46
|
+
calibrate(rawConfidence: number, type: ThoughtType, sessionId: SessionId): CalibrationResult;
|
|
47
|
+
metrics(sessionId?: SessionId): CalibrationMetrics;
|
|
48
|
+
refit(sessionId?: SessionId): void;
|
|
49
|
+
clearSession(sessionId: SessionId): void;
|
|
50
|
+
clearAll(): void;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=Calibrator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Calibrator.d.ts","sourceRoot":"","sources":["../../../src/core/evaluator/Calibrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EACX,kBAAkB,EAClB,iBAAiB,EACjB,WAAW,EACX,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,gBAAgB,EAAuB,MAAM,+BAA+B,CAAC;AAC3F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AA4HxD;;;;;;;;;;;;;GAaG;AACH,qBAAa,UAAW,YAAW,WAAW;IAC7C,SAAgB,OAAO,EAAE,OAAO,CAAC;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAmB;IAC7C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAoD;gBAEtE,eAAe,EAAE,gBAAgB,EAAE,OAAO,EAAE,OAAO;IAKxD,SAAS,CACf,aAAa,EAAE,MAAM,EACrB,IAAI,EAAE,WAAW,EACjB,SAAS,EAAE,SAAS,GAClB,iBAAiB;IAqBb,OAAO,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,kBAAkB;IAclD,KAAK,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,IAAI;IAUlC,YAAY,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI;IAKxC,QAAQ,IAAI,IAAI;CAIvB"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { EPSILON, MIN_OUTCOMES_FOR_TEMPERATURE, applyTemperature, fitTemperature } from "./calibration-math.js";
|
|
2
|
+
import { ALL_THOUGHT_TYPES } from "./internals.js";
|
|
3
|
+
const ECE_BINS = 10;
|
|
4
|
+
const GLOBAL_KEY = Symbol('global calibration temperature');
|
|
5
|
+
function aggregatePerType(outcomes) {
|
|
6
|
+
const sums = new Map();
|
|
7
|
+
for (const o of outcomes){
|
|
8
|
+
const prev = sums.get(o.type) ?? {
|
|
9
|
+
sum: 0,
|
|
10
|
+
count: 0
|
|
11
|
+
};
|
|
12
|
+
prev.sum += o.actual;
|
|
13
|
+
prev.count += 1;
|
|
14
|
+
sums.set(o.type, prev);
|
|
15
|
+
}
|
|
16
|
+
const result = new Map();
|
|
17
|
+
for (const [type, { sum, count }] of sums)result.set(type, {
|
|
18
|
+
mean: sum / count,
|
|
19
|
+
count
|
|
20
|
+
});
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
function brierScore(outcomes) {
|
|
24
|
+
if (0 === outcomes.length) return null;
|
|
25
|
+
let sum = 0;
|
|
26
|
+
for (const o of outcomes){
|
|
27
|
+
const diff = o.predicted - o.actual;
|
|
28
|
+
sum += diff * diff;
|
|
29
|
+
}
|
|
30
|
+
return sum / outcomes.length;
|
|
31
|
+
}
|
|
32
|
+
function expectedCalibrationError(outcomes) {
|
|
33
|
+
if (0 === outcomes.length) return null;
|
|
34
|
+
const binConfSum = new Array(ECE_BINS).fill(0);
|
|
35
|
+
const binAccSum = new Array(ECE_BINS).fill(0);
|
|
36
|
+
const binCount = new Array(ECE_BINS).fill(0);
|
|
37
|
+
for (const o of outcomes){
|
|
38
|
+
const p = Math.min(1 - EPSILON, Math.max(0, o.predicted));
|
|
39
|
+
const idx = Math.min(ECE_BINS - 1, Math.floor(p * ECE_BINS));
|
|
40
|
+
binConfSum[idx] = (binConfSum[idx] ?? 0) + p;
|
|
41
|
+
binAccSum[idx] = (binAccSum[idx] ?? 0) + o.actual;
|
|
42
|
+
binCount[idx] = (binCount[idx] ?? 0) + 1;
|
|
43
|
+
}
|
|
44
|
+
const total = outcomes.length;
|
|
45
|
+
let ece = 0;
|
|
46
|
+
for(let i = 0; i < ECE_BINS; i++){
|
|
47
|
+
const n = binCount[i] ?? 0;
|
|
48
|
+
if (0 === n) continue;
|
|
49
|
+
const meanConf = (binConfSum[i] ?? 0) / n;
|
|
50
|
+
const meanAcc = (binAccSum[i] ?? 0) / n;
|
|
51
|
+
ece += n / total * Math.abs(meanConf - meanAcc);
|
|
52
|
+
}
|
|
53
|
+
return ece;
|
|
54
|
+
}
|
|
55
|
+
function perTypeBrier(outcomes) {
|
|
56
|
+
const buckets = new Map();
|
|
57
|
+
for (const o of outcomes){
|
|
58
|
+
const list = buckets.get(o.type) ?? [];
|
|
59
|
+
list.push(o);
|
|
60
|
+
buckets.set(o.type, list);
|
|
61
|
+
}
|
|
62
|
+
const result = {};
|
|
63
|
+
for (const t of ALL_THOUGHT_TYPES)result[t] = brierScore(buckets.get(t) ?? []);
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
function emptyMetrics() {
|
|
67
|
+
const perType = {};
|
|
68
|
+
for (const t of ALL_THOUGHT_TYPES)perType[t] = null;
|
|
69
|
+
return {
|
|
70
|
+
brierScore: null,
|
|
71
|
+
ece: null,
|
|
72
|
+
sampleCount: 0,
|
|
73
|
+
perTypeBrier: perType
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
class Calibrator {
|
|
77
|
+
enabled;
|
|
78
|
+
_recorder;
|
|
79
|
+
_temperatures = new Map();
|
|
80
|
+
constructor(outcomeRecorder, enabled){
|
|
81
|
+
this._recorder = outcomeRecorder;
|
|
82
|
+
this.enabled = enabled;
|
|
83
|
+
}
|
|
84
|
+
calibrate(rawConfidence, type, sessionId) {
|
|
85
|
+
const raw = Math.min(1, Math.max(0, rawConfidence));
|
|
86
|
+
if (!this.enabled) return {
|
|
87
|
+
raw,
|
|
88
|
+
calibrated: raw,
|
|
89
|
+
temperature: 1.0,
|
|
90
|
+
priorWeight: 0
|
|
91
|
+
};
|
|
92
|
+
const outcomes = this._recorder.getOutcomes(sessionId);
|
|
93
|
+
const perType = aggregatePerType(outcomes);
|
|
94
|
+
const typeStats = perType.get(type);
|
|
95
|
+
const n = typeStats?.count ?? 0;
|
|
96
|
+
const observedMean = typeStats?.mean ?? 0.5;
|
|
97
|
+
const priorWeight = 1 / (1 + n / 10);
|
|
98
|
+
const shrunk = priorWeight * observedMean + (1 - priorWeight) * raw;
|
|
99
|
+
const temperature = this._temperatures.get(sessionId) ?? this._temperatures.get(GLOBAL_KEY) ?? 1.0;
|
|
100
|
+
const calibrated = outcomes.length >= MIN_OUTCOMES_FOR_TEMPERATURE ? applyTemperature(shrunk, temperature) : shrunk;
|
|
101
|
+
return {
|
|
102
|
+
raw,
|
|
103
|
+
calibrated,
|
|
104
|
+
temperature,
|
|
105
|
+
priorWeight
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
metrics(sessionId) {
|
|
109
|
+
if (!this.enabled) return emptyMetrics();
|
|
110
|
+
const outcomes = void 0 === sessionId ? this._recorder.getAllOutcomes() : this._recorder.getOutcomes(sessionId);
|
|
111
|
+
return {
|
|
112
|
+
brierScore: brierScore(outcomes),
|
|
113
|
+
ece: expectedCalibrationError(outcomes),
|
|
114
|
+
sampleCount: outcomes.length,
|
|
115
|
+
perTypeBrier: perTypeBrier(outcomes)
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
refit(sessionId) {
|
|
119
|
+
if (!this.enabled) return;
|
|
120
|
+
const key = sessionId ?? GLOBAL_KEY;
|
|
121
|
+
const outcomes = void 0 === sessionId ? this._recorder.getAllOutcomes() : this._recorder.getOutcomes(sessionId);
|
|
122
|
+
this._temperatures.set(key, fitTemperature(outcomes));
|
|
123
|
+
}
|
|
124
|
+
clearSession(sessionId) {
|
|
125
|
+
if (!this.enabled) return;
|
|
126
|
+
this._temperatures.delete(sessionId);
|
|
127
|
+
}
|
|
128
|
+
clearAll() {
|
|
129
|
+
if (!this.enabled) return;
|
|
130
|
+
this._temperatures.clear();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
export { Calibrator };
|
|
134
|
+
|
|
135
|
+
//# sourceMappingURL=Calibrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core/evaluator/Calibrator.js","sources":["../../../src/core/evaluator/Calibrator.ts"],"sourcesContent":["/**\n * Confidence calibration for sequential thinking reasoning.\n *\n * Provides the {@link Calibrator} class — maps raw model confidence values\n * to calibrated probabilities using per-type Beta(2, 2) priors and\n * grid-searched temperature scaling. Reports calibration quality through\n * Brier score and 10-bin Expected Calibration Error (ECE).\n *\n * Math summary:\n * - **Per-type prior**: Beta(α=2, β=2), prior mean = 0.5. As outcomes accumulate\n * for a type, the calibrated value shrinks toward the observed mean of that\n * type with weight `priorWeight = 1 / (1 + n / 10)` where `n` is the type's\n * sample count.\n * - **Temperature scaling**: Grid search T ∈ {0.5, 0.75, 1.0, 1.25, 1.5, 2.0}\n * minimizing negative log-likelihood (NLL) over recorded outcomes. Default T=1.0.\n * Requires ≥10 outcomes; below that threshold only prior shrinkage is applied.\n * - **Brier score**: `mean((predicted - actual)^2)` over recorded outcomes.\n * - **ECE (10-bin)**: bucket predictions in 0.1 increments, compute weighted\n * absolute deviation between bin mean confidence and bin accuracy.\n *\n * @module core/evaluator/Calibrator\n */\n\nimport type {\n\tCalibrationMetrics,\n\tCalibrationResult,\n\tICalibrator,\n} from '../../contracts/calibrator.js';\nimport type { IOutcomeRecorder, VerificationOutcome } from '../../contracts/interfaces.js';\nimport type { ThoughtType } from '../reasoning.js';\nimport type { SessionId } from '../../contracts/ids.js';\nimport {\n\tEPSILON,\n\tMIN_OUTCOMES_FOR_TEMPERATURE,\n\tapplyTemperature,\n\tfitTemperature,\n} from './calibration-math.js';\nimport { ALL_THOUGHT_TYPES } from './internals.js';\n\n/** Number of bins used by ECE (10-bin → 0.1 increments). */\nconst ECE_BINS = 10;\n\n/** Sentinel used in the per-session temperature map for global state. */\nconst GLOBAL_KEY: unique symbol = Symbol('global calibration temperature');\n\n/**\n * Build per-type empirical means + counts from a list of outcomes.\n *\n * @param outcomes - Outcomes to aggregate.\n * @returns Map of thought type to `{ mean, count }`. Types with no outcomes\n * are absent from the map.\n */\nfunction aggregatePerType(\n\toutcomes: readonly VerificationOutcome[]\n): Map<string, { mean: number; count: number }> {\n\tconst sums = new Map<string, { sum: number; count: number }>();\n\tfor (const o of outcomes) {\n\t\tconst prev = sums.get(o.type) ?? { sum: 0, count: 0 };\n\t\tprev.sum += o.actual;\n\t\tprev.count += 1;\n\t\tsums.set(o.type, prev);\n\t}\n\tconst result = new Map<string, { mean: number; count: number }>();\n\tfor (const [type, { sum, count }] of sums) {\n\t\tresult.set(type, { mean: sum / count, count });\n\t}\n\treturn result;\n}\n\n/**\n * Compute the Brier score over a list of outcomes.\n *\n * @param outcomes - Outcomes to score.\n * @returns Mean squared error between predicted probability and actual label,\n * or `null` if `outcomes` is empty.\n */\nfunction brierScore(outcomes: readonly VerificationOutcome[]): number | null {\n\tif (outcomes.length === 0) return null;\n\tlet sum = 0;\n\tfor (const o of outcomes) {\n\t\tconst diff = o.predicted - o.actual;\n\t\tsum += diff * diff;\n\t}\n\treturn sum / outcomes.length;\n}\n\n/**\n * Compute 10-bin Expected Calibration Error.\n *\n * Buckets predictions in 0.1-wide bins, then sums weighted absolute\n * differences between bin mean confidence and bin accuracy.\n *\n * @param outcomes - Outcomes to evaluate.\n * @returns ECE in `[0, 1]`, or `null` if `outcomes` is empty.\n */\nfunction expectedCalibrationError(outcomes: readonly VerificationOutcome[]): number | null {\n\tif (outcomes.length === 0) return null;\n\tconst binConfSum = new Array<number>(ECE_BINS).fill(0);\n\tconst binAccSum = new Array<number>(ECE_BINS).fill(0);\n\tconst binCount = new Array<number>(ECE_BINS).fill(0);\n\tfor (const o of outcomes) {\n\t\tconst p = Math.min(1 - EPSILON, Math.max(0, o.predicted));\n\t\tconst idx = Math.min(ECE_BINS - 1, Math.floor(p * ECE_BINS));\n\t\tbinConfSum[idx] = (binConfSum[idx] ?? 0) + p;\n\t\tbinAccSum[idx] = (binAccSum[idx] ?? 0) + o.actual;\n\t\tbinCount[idx] = (binCount[idx] ?? 0) + 1;\n\t}\n\tconst total = outcomes.length;\n\tlet ece = 0;\n\tfor (let i = 0; i < ECE_BINS; i++) {\n\t\tconst n = binCount[i] ?? 0;\n\t\tif (n === 0) continue;\n\t\tconst meanConf = (binConfSum[i] ?? 0) / n;\n\t\tconst meanAcc = (binAccSum[i] ?? 0) / n;\n\t\tece += (n / total) * Math.abs(meanConf - meanAcc);\n\t}\n\treturn ece;\n}\n\n/**\n * Build the per-type Brier score breakdown for {@link CalibrationMetrics}.\n *\n * @param outcomes - Outcomes to bucket by type.\n * @returns Record keyed by every {@link ThoughtType}; `null` for types with\n * no recorded outcomes.\n */\nfunction perTypeBrier(\n\toutcomes: readonly VerificationOutcome[]\n): Record<ThoughtType, number | null> {\n\tconst buckets = new Map<string, VerificationOutcome[]>();\n\tfor (const o of outcomes) {\n\t\tconst list = buckets.get(o.type) ?? [];\n\t\tlist.push(o);\n\t\tbuckets.set(o.type, list);\n\t}\n\tconst result = {} as Record<ThoughtType, number | null>;\n\tfor (const t of ALL_THOUGHT_TYPES) {\n\t\tresult[t] = brierScore(buckets.get(t) ?? []);\n\t}\n\treturn result;\n}\n\n/** Empty CalibrationMetrics returned when calibration is disabled. */\nfunction emptyMetrics(): CalibrationMetrics {\n\tconst perType = {} as Record<ThoughtType, number | null>;\n\tfor (const t of ALL_THOUGHT_TYPES) perType[t] = null;\n\treturn {\n\t\tbrierScore: null,\n\t\tece: null,\n\t\tsampleCount: 0,\n\t\tperTypeBrier: perType,\n\t};\n}\n\n/**\n * Confidence calibration service.\n *\n * Stateless w.r.t. outcome storage (delegated to {@link IOutcomeRecorder}),\n * but maintains a small per-session temperature cache that is recomputed\n * via {@link Calibrator.refit}.\n *\n * @example\n * ```typescript\n * const calibrator = new Calibrator(outcomeRecorder, true);\n * const result = calibrator.calibrate(0.9, 'hypothesis', 'session-1');\n * console.log(result.calibrated, result.temperature, result.priorWeight);\n * ```\n */\nexport class Calibrator implements ICalibrator {\n\tpublic readonly enabled: boolean;\n\tprivate readonly _recorder: IOutcomeRecorder;\n\tprivate readonly _temperatures = new Map<SessionId | typeof GLOBAL_KEY, number>();\n\n\tconstructor(outcomeRecorder: IOutcomeRecorder, enabled: boolean) {\n\t\tthis._recorder = outcomeRecorder;\n\t\tthis.enabled = enabled;\n\t}\n\n\tpublic calibrate(\n\t\trawConfidence: number,\n\t\ttype: ThoughtType,\n\t\tsessionId: SessionId\n\t): CalibrationResult {\n\t\tconst raw = Math.min(1, Math.max(0, rawConfidence));\n\t\tif (!this.enabled) {\n\t\t\treturn { raw, calibrated: raw, temperature: 1.0, priorWeight: 0 };\n\t\t}\n\t\tconst outcomes = this._recorder.getOutcomes(sessionId);\n\t\tconst perType = aggregatePerType(outcomes);\n\t\tconst typeStats = perType.get(type);\n\t\tconst n = typeStats?.count ?? 0;\n\t\tconst observedMean = typeStats?.mean ?? 0.5;\n\t\tconst priorWeight = 1 / (1 + n / 10);\n\t\tconst shrunk = priorWeight * observedMean + (1 - priorWeight) * raw;\n\t\tconst temperature =\n\t\t\tthis._temperatures.get(sessionId) ?? this._temperatures.get(GLOBAL_KEY) ?? 1.0;\n\t\tconst calibrated =\n\t\t\toutcomes.length >= MIN_OUTCOMES_FOR_TEMPERATURE\n\t\t\t\t? applyTemperature(shrunk, temperature)\n\t\t\t\t: shrunk;\n\t\treturn { raw, calibrated, temperature, priorWeight };\n\t}\n\n\tpublic metrics(sessionId?: SessionId): CalibrationMetrics {\n\t\tif (!this.enabled) return emptyMetrics();\n\t\tconst outcomes =\n\t\t\tsessionId === undefined\n\t\t\t\t? this._recorder.getAllOutcomes()\n\t\t\t\t: this._recorder.getOutcomes(sessionId);\n\t\treturn {\n\t\t\tbrierScore: brierScore(outcomes),\n\t\t\tece: expectedCalibrationError(outcomes),\n\t\t\tsampleCount: outcomes.length,\n\t\t\tperTypeBrier: perTypeBrier(outcomes),\n\t\t};\n\t}\n\n\tpublic refit(sessionId?: SessionId): void {\n\t\tif (!this.enabled) return;\n\t\tconst key = sessionId ?? GLOBAL_KEY;\n\t\tconst outcomes =\n\t\t\tsessionId === undefined\n\t\t\t\t? this._recorder.getAllOutcomes()\n\t\t\t\t: this._recorder.getOutcomes(sessionId);\n\t\tthis._temperatures.set(key, fitTemperature(outcomes));\n\t}\n\n\tpublic clearSession(sessionId: SessionId): void {\n\t\tif (!this.enabled) return;\n\t\tthis._temperatures.delete(sessionId);\n\t}\n\n\tpublic clearAll(): void {\n\t\tif (!this.enabled) return;\n\t\tthis._temperatures.clear();\n\t}\n}\n"],"names":["ECE_BINS","GLOBAL_KEY","Symbol","aggregatePerType","outcomes","sums","Map","o","prev","result","type","sum","count","brierScore","diff","expectedCalibrationError","binConfSum","Array","binAccSum","binCount","p","Math","EPSILON","idx","total","ece","i","n","meanConf","meanAcc","perTypeBrier","buckets","list","t","ALL_THOUGHT_TYPES","emptyMetrics","perType","Calibrator","outcomeRecorder","enabled","rawConfidence","sessionId","raw","typeStats","observedMean","priorWeight","shrunk","temperature","calibrated","MIN_OUTCOMES_FOR_TEMPERATURE","applyTemperature","undefined","key","fitTemperature"],"mappings":"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"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pattern detection for sequential thinking reasoning analytics.
|
|
3
|
+
*
|
|
4
|
+
* Provides the {@link PatternDetector} class — a stateless service that detects
|
|
5
|
+
* reasoning patterns (anti-patterns and positive signals) from thought history.
|
|
6
|
+
* Extracted from {@link ThoughtEvaluator} to keep concerns isolated and reduce
|
|
7
|
+
* cyclomatic complexity per function.
|
|
8
|
+
*
|
|
9
|
+
* Detected patterns:
|
|
10
|
+
* - `consecutive_without_verification` (warning) — 3+ consecutive regular thoughts
|
|
11
|
+
* without a verification step
|
|
12
|
+
* - `unverified_hypothesis` (warning) — hypothesis not verified within 3 subsequent
|
|
13
|
+
* thoughts
|
|
14
|
+
* - `no_alternatives_explored` (info) — 5+ thoughts with no critique and no branches
|
|
15
|
+
* - `monotonic_type` (info) — 4+ consecutive thoughts with the same thought_type
|
|
16
|
+
* (requires ≥1 explicit type and ≥5 thoughts)
|
|
17
|
+
* - `confidence_drift` (warning) — 3+ consecutive thoughts with strictly decreasing
|
|
18
|
+
* confidence
|
|
19
|
+
* - `healthy_verification` (info) — hypothesis verified within 3 subsequent thoughts
|
|
20
|
+
*
|
|
21
|
+
* @module core/evaluator/PatternDetector
|
|
22
|
+
*/
|
|
23
|
+
import type { PatternSignal } from '../reasoning.js';
|
|
24
|
+
import type { ThoughtData } from '../thought.js';
|
|
25
|
+
/**
|
|
26
|
+
* Stateless service that detects reasoning patterns from thought history.
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* All methods are pure computations — no side effects, no I/O, no internal state.
|
|
30
|
+
* Designed to be registered as transient in the DI container or composed directly
|
|
31
|
+
* into {@link ThoughtEvaluator}.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const detector = new PatternDetector();
|
|
36
|
+
* const signals = detector.computePatternSignals(history, branches);
|
|
37
|
+
* const warnings = signals.filter((s) => s.severity === 'warning');
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare class PatternDetector {
|
|
41
|
+
/**
|
|
42
|
+
* Detect all reasoning patterns from history and branches.
|
|
43
|
+
*
|
|
44
|
+
* @param history - All thoughts in the current session
|
|
45
|
+
* @param branches - Map of branch IDs to their thought arrays
|
|
46
|
+
* @returns Array of detected pattern signals (possibly empty)
|
|
47
|
+
*/
|
|
48
|
+
computePatternSignals(history: ThoughtData[], branches: Record<string, ThoughtData[]>): PatternSignal[];
|
|
49
|
+
/** Detect runs of 3+ consecutive thoughts without verification. */
|
|
50
|
+
private _detectConsecutiveWithoutVerification;
|
|
51
|
+
/** Detect hypothesis thoughts not verified within 3 subsequent thoughts. */
|
|
52
|
+
private _detectUnverifiedHypothesis;
|
|
53
|
+
/** Detect 5+ thoughts with no critique and no branches. */
|
|
54
|
+
private _detectNoAlternativesExplored;
|
|
55
|
+
/**
|
|
56
|
+
* Detect runs of 4+ consecutive thoughts with the same thought_type.
|
|
57
|
+
* Only fires when history has ≥5 thoughts and at least one explicitly set thought_type.
|
|
58
|
+
*/
|
|
59
|
+
private _detectMonotonicType;
|
|
60
|
+
/** Emit a monotonic_type signal if the run length qualifies. */
|
|
61
|
+
private _flushMonotonicRun;
|
|
62
|
+
/** Detect runs of 3+ consecutive thoughts with strictly decreasing confidence. */
|
|
63
|
+
private _detectConfidenceDrift;
|
|
64
|
+
/** Emit a confidence_drift signal if the run length qualifies. */
|
|
65
|
+
private _flushDriftRun;
|
|
66
|
+
/** Detect hypothesis verified within 3 subsequent thoughts — positive signal. */
|
|
67
|
+
private _detectHealthyVerification;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=PatternDetector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PatternDetector.d.ts","sourceRoot":"","sources":["../../../src/core/evaluator/PatternDetector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD;;;;;;;;;;;;;;GAcG;AACH,qBAAa,eAAe;IAC3B;;;;;;OAMG;IACI,qBAAqB,CAC3B,OAAO,EAAE,WAAW,EAAE,EACtB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC,GACrC,aAAa,EAAE;IAalB,mEAAmE;IACnE,OAAO,CAAC,qCAAqC;IAwB7C,4EAA4E;IAC5E,OAAO,CAAC,2BAA2B;IAqBnC,2DAA2D;IAC3D,OAAO,CAAC,6BAA6B;IAmBrC;;;OAGG;IACH,OAAO,CAAC,oBAAoB;IAyB5B,gEAAgE;IAChE,OAAO,CAAC,kBAAkB;IAkB1B,kFAAkF;IAClF,OAAO,CAAC,sBAAsB;IAiC9B,kEAAkE;IAClE,OAAO,CAAC,cAAc;IAuBtB,iFAAiF;IACjF,OAAO,CAAC,0BAA0B;CAyBlC"}
|