@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,192 @@
|
|
|
1
|
+
class PatternDetector {
|
|
2
|
+
computePatternSignals(history, branches) {
|
|
3
|
+
if (0 === history.length) return [];
|
|
4
|
+
const signals = [];
|
|
5
|
+
signals.push(...this._detectConsecutiveWithoutVerification(history));
|
|
6
|
+
signals.push(...this._detectUnverifiedHypothesis(history));
|
|
7
|
+
signals.push(...this._detectNoAlternativesExplored(history, branches));
|
|
8
|
+
signals.push(...this._detectMonotonicType(history));
|
|
9
|
+
signals.push(...this._detectConfidenceDrift(history));
|
|
10
|
+
signals.push(...this._detectHealthyVerification(history));
|
|
11
|
+
return signals;
|
|
12
|
+
}
|
|
13
|
+
_detectConsecutiveWithoutVerification(history) {
|
|
14
|
+
const signals = [];
|
|
15
|
+
let runStart = 0;
|
|
16
|
+
for(let i = 0; i < history.length; i++){
|
|
17
|
+
const type = history[i].thought_type ?? 'regular';
|
|
18
|
+
if ('verification' === type) {
|
|
19
|
+
runStart = i + 1;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (i - runStart + 1 >= 3) {
|
|
23
|
+
const start = history[runStart].thought_number ?? runStart + 1;
|
|
24
|
+
const end = history[i].thought_number ?? i + 1;
|
|
25
|
+
signals.push({
|
|
26
|
+
pattern: 'consecutive_without_verification',
|
|
27
|
+
severity: 'warning',
|
|
28
|
+
message: `3+ consecutive thoughts (${start}-${end}) without verification`,
|
|
29
|
+
thought_range: [
|
|
30
|
+
start,
|
|
31
|
+
end
|
|
32
|
+
]
|
|
33
|
+
});
|
|
34
|
+
runStart = i + 1;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return signals;
|
|
38
|
+
}
|
|
39
|
+
_detectUnverifiedHypothesis(history) {
|
|
40
|
+
const signals = [];
|
|
41
|
+
for(let i = 0; i < history.length; i++){
|
|
42
|
+
if ('hypothesis' !== history[i].thought_type) continue;
|
|
43
|
+
const remaining = history.length - i - 1;
|
|
44
|
+
if (remaining < 3) continue;
|
|
45
|
+
const lookahead = history.slice(i + 1, i + 4);
|
|
46
|
+
const hasVerification = lookahead.some((t)=>'verification' === t.thought_type);
|
|
47
|
+
if (!hasVerification) {
|
|
48
|
+
const n = history[i].thought_number ?? i + 1;
|
|
49
|
+
signals.push({
|
|
50
|
+
pattern: 'unverified_hypothesis',
|
|
51
|
+
severity: 'warning',
|
|
52
|
+
message: `Hypothesis at thought ${n} has not been verified within 3 thoughts`,
|
|
53
|
+
thought_range: [
|
|
54
|
+
n,
|
|
55
|
+
n
|
|
56
|
+
]
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return signals;
|
|
61
|
+
}
|
|
62
|
+
_detectNoAlternativesExplored(history, branches) {
|
|
63
|
+
if (history.length < 5) return [];
|
|
64
|
+
if (history.some((t)=>'critique' === t.thought_type)) return [];
|
|
65
|
+
if (Object.keys(branches).length > 0) return [];
|
|
66
|
+
const start = history[0].thought_number ?? 1;
|
|
67
|
+
const end = history[history.length - 1].thought_number ?? history.length;
|
|
68
|
+
return [
|
|
69
|
+
{
|
|
70
|
+
pattern: 'no_alternatives_explored',
|
|
71
|
+
severity: 'warning',
|
|
72
|
+
message: '5+ thoughts with no critique or branching — consider exploring alternatives',
|
|
73
|
+
thought_range: [
|
|
74
|
+
start,
|
|
75
|
+
end
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
];
|
|
79
|
+
}
|
|
80
|
+
_detectMonotonicType(history) {
|
|
81
|
+
if (history.length < 5) return [];
|
|
82
|
+
const hasExplicitType = history.some((t)=>void 0 !== t.thought_type);
|
|
83
|
+
if (!hasExplicitType) return [];
|
|
84
|
+
const signals = [];
|
|
85
|
+
let runType = history[0].thought_type ?? 'regular';
|
|
86
|
+
let runStart = 0;
|
|
87
|
+
let runLength = 1;
|
|
88
|
+
for(let i = 1; i < history.length; i++){
|
|
89
|
+
const type = history[i].thought_type ?? 'regular';
|
|
90
|
+
if (type === runType) runLength++;
|
|
91
|
+
else {
|
|
92
|
+
this._flushMonotonicRun(history, runStart, runLength, runType, signals);
|
|
93
|
+
runType = type;
|
|
94
|
+
runStart = i;
|
|
95
|
+
runLength = 1;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
this._flushMonotonicRun(history, runStart, runLength, runType, signals);
|
|
99
|
+
return signals;
|
|
100
|
+
}
|
|
101
|
+
_flushMonotonicRun(history, runStart, runLength, runType, signals) {
|
|
102
|
+
if (runLength < 4) return;
|
|
103
|
+
const start = history[runStart].thought_number ?? runStart + 1;
|
|
104
|
+
const end = history[runStart + runLength - 1].thought_number ?? runStart + runLength;
|
|
105
|
+
signals.push({
|
|
106
|
+
pattern: 'monotonic_type',
|
|
107
|
+
severity: 'warning',
|
|
108
|
+
message: `4+ consecutive '${runType}' thoughts (${start}-${end}) — consider varying approach`,
|
|
109
|
+
thought_range: [
|
|
110
|
+
start,
|
|
111
|
+
end
|
|
112
|
+
]
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
_detectConfidenceDrift(history) {
|
|
116
|
+
const signals = [];
|
|
117
|
+
let runStart = -1;
|
|
118
|
+
let runLength = 0;
|
|
119
|
+
let prevConf = -1;
|
|
120
|
+
for(let i = 0; i < history.length; i++){
|
|
121
|
+
const conf = history[i].confidence;
|
|
122
|
+
if (void 0 === conf) {
|
|
123
|
+
this._flushDriftRun(history, runStart, runLength, signals);
|
|
124
|
+
runStart = -1;
|
|
125
|
+
runLength = 0;
|
|
126
|
+
prevConf = -1;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (0 === runLength) {
|
|
130
|
+
runStart = i;
|
|
131
|
+
runLength = 1;
|
|
132
|
+
prevConf = conf;
|
|
133
|
+
} else if (conf < prevConf) {
|
|
134
|
+
runLength++;
|
|
135
|
+
prevConf = conf;
|
|
136
|
+
} else {
|
|
137
|
+
this._flushDriftRun(history, runStart, runLength, signals);
|
|
138
|
+
runStart = i;
|
|
139
|
+
runLength = 1;
|
|
140
|
+
prevConf = conf;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
this._flushDriftRun(history, runStart, runLength, signals);
|
|
144
|
+
return signals;
|
|
145
|
+
}
|
|
146
|
+
_flushDriftRun(history, runStart, runLength, signals) {
|
|
147
|
+
if (runLength < 3) return;
|
|
148
|
+
const first = history[runStart];
|
|
149
|
+
const last = history[runStart + runLength - 1];
|
|
150
|
+
if (!first || !last) return;
|
|
151
|
+
if (void 0 === first.confidence || void 0 === last.confidence) return;
|
|
152
|
+
const start = first.thought_number ?? runStart + 1;
|
|
153
|
+
const end = last.thought_number ?? runStart + runLength;
|
|
154
|
+
const firstConf = first.confidence;
|
|
155
|
+
const lastConf = last.confidence;
|
|
156
|
+
signals.push({
|
|
157
|
+
pattern: 'confidence_drift',
|
|
158
|
+
severity: 'warning',
|
|
159
|
+
message: `Confidence decreasing across thoughts ${start}-${end} (${firstConf} → ${lastConf})`,
|
|
160
|
+
thought_range: [
|
|
161
|
+
start,
|
|
162
|
+
end
|
|
163
|
+
]
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
_detectHealthyVerification(history) {
|
|
167
|
+
const signals = [];
|
|
168
|
+
for(let i = 0; i < history.length; i++){
|
|
169
|
+
if ('hypothesis' !== history[i].thought_type) continue;
|
|
170
|
+
const hypId = history[i].hypothesis_id;
|
|
171
|
+
const lookahead = history.slice(i + 1, i + 4);
|
|
172
|
+
const verifier = lookahead.find((t)=>'verification' === t.thought_type && (t.hypothesis_id === hypId || t.verification_target === (history[i].thought_number ?? i + 1)));
|
|
173
|
+
if (verifier) {
|
|
174
|
+
const n = history[i].thought_number ?? i + 1;
|
|
175
|
+
const m = verifier.thought_number ?? history.indexOf(verifier) + 1;
|
|
176
|
+
signals.push({
|
|
177
|
+
pattern: 'healthy_verification',
|
|
178
|
+
severity: 'info',
|
|
179
|
+
message: `Hypothesis at thought ${n} verified at thought ${m} — good practice`,
|
|
180
|
+
thought_range: [
|
|
181
|
+
n,
|
|
182
|
+
m
|
|
183
|
+
]
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return signals;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
export { PatternDetector };
|
|
191
|
+
|
|
192
|
+
//# sourceMappingURL=PatternDetector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core/evaluator/PatternDetector.js","sources":["../../../src/core/evaluator/PatternDetector.ts"],"sourcesContent":["/**\n * Pattern detection for sequential thinking reasoning analytics.\n *\n * Provides the {@link PatternDetector} class — a stateless service that detects\n * reasoning patterns (anti-patterns and positive signals) from thought history.\n * Extracted from {@link ThoughtEvaluator} to keep concerns isolated and reduce\n * cyclomatic complexity per function.\n *\n * Detected patterns:\n * - `consecutive_without_verification` (warning) — 3+ consecutive regular thoughts\n * without a verification step\n * - `unverified_hypothesis` (warning) — hypothesis not verified within 3 subsequent\n * thoughts\n * - `no_alternatives_explored` (info) — 5+ thoughts with no critique and no branches\n * - `monotonic_type` (info) — 4+ consecutive thoughts with the same thought_type\n * (requires ≥1 explicit type and ≥5 thoughts)\n * - `confidence_drift` (warning) — 3+ consecutive thoughts with strictly decreasing\n * confidence\n * - `healthy_verification` (info) — hypothesis verified within 3 subsequent thoughts\n *\n * @module core/evaluator/PatternDetector\n */\n\nimport type { PatternSignal } from '../reasoning.js';\nimport type { ThoughtData } from '../thought.js';\n\n/**\n * Stateless service that detects reasoning patterns from thought history.\n *\n * @remarks\n * All methods are pure computations — no side effects, no I/O, no internal state.\n * Designed to be registered as transient in the DI container or composed directly\n * into {@link ThoughtEvaluator}.\n *\n * @example\n * ```typescript\n * const detector = new PatternDetector();\n * const signals = detector.computePatternSignals(history, branches);\n * const warnings = signals.filter((s) => s.severity === 'warning');\n * ```\n */\nexport class PatternDetector {\n\t/**\n\t * Detect all reasoning patterns from history and 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 Array of detected pattern signals (possibly empty)\n\t */\n\tpublic computePatternSignals(\n\t\thistory: ThoughtData[],\n\t\tbranches: Record<string, ThoughtData[]>\n\t): PatternSignal[] {\n\t\tif (history.length === 0) return [];\n\n\t\tconst signals: PatternSignal[] = [];\n\t\tsignals.push(...this._detectConsecutiveWithoutVerification(history));\n\t\tsignals.push(...this._detectUnverifiedHypothesis(history));\n\t\tsignals.push(...this._detectNoAlternativesExplored(history, branches));\n\t\tsignals.push(...this._detectMonotonicType(history));\n\t\tsignals.push(...this._detectConfidenceDrift(history));\n\t\tsignals.push(...this._detectHealthyVerification(history));\n\t\treturn signals;\n\t}\n\n\t/** Detect runs of 3+ consecutive thoughts without verification. */\n\tprivate _detectConsecutiveWithoutVerification(history: ThoughtData[]): PatternSignal[] {\n\t\tconst signals: PatternSignal[] = [];\n\t\tlet runStart = 0;\n\t\tfor (let i = 0; i < history.length; i++) {\n\t\t\tconst type = history[i]!.thought_type ?? 'regular';\n\t\t\tif (type === 'verification') {\n\t\t\t\trunStart = i + 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (i - runStart + 1 >= 3) {\n\t\t\t\tconst start = history[runStart]!.thought_number ?? runStart + 1;\n\t\t\t\tconst end = history[i]!.thought_number ?? i + 1;\n\t\t\t\tsignals.push({\n\t\t\t\t\tpattern: 'consecutive_without_verification',\n\t\t\t\t\tseverity: 'warning',\n\t\t\t\t\tmessage: `3+ consecutive thoughts (${start}-${end}) without verification`,\n\t\t\t\t\tthought_range: [start, end],\n\t\t\t\t});\n\t\t\t\trunStart = i + 1;\n\t\t\t}\n\t\t}\n\t\treturn signals;\n\t}\n\n\t/** Detect hypothesis thoughts not verified within 3 subsequent thoughts. */\n\tprivate _detectUnverifiedHypothesis(history: ThoughtData[]): PatternSignal[] {\n\t\tconst signals: PatternSignal[] = [];\n\t\tfor (let i = 0; i < history.length; i++) {\n\t\t\tif (history[i]!.thought_type !== 'hypothesis') continue;\n\t\t\tconst remaining = history.length - i - 1;\n\t\t\tif (remaining < 3) continue;\n\t\t\tconst lookahead = history.slice(i + 1, i + 4);\n\t\t\tconst hasVerification = lookahead.some((t) => t.thought_type === 'verification');\n\t\t\tif (!hasVerification) {\n\t\t\t\tconst n = history[i]!.thought_number ?? i + 1;\n\t\t\t\tsignals.push({\n\t\t\t\t\tpattern: 'unverified_hypothesis',\n\t\t\t\t\tseverity: 'warning',\n\t\t\t\t\tmessage: `Hypothesis at thought ${n} has not been verified within 3 thoughts`,\n\t\t\t\t\tthought_range: [n, n],\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\treturn signals;\n\t}\n\n\t/** Detect 5+ thoughts with no critique and no branches. */\n\tprivate _detectNoAlternativesExplored(\n\t\thistory: ThoughtData[],\n\t\tbranches: Record<string, ThoughtData[]>\n\t): PatternSignal[] {\n\t\tif (history.length < 5) return [];\n\t\tif (history.some((t) => t.thought_type === 'critique')) return [];\n\t\tif (Object.keys(branches).length > 0) return [];\n\t\tconst start = history[0]!.thought_number ?? 1;\n\t\tconst end = history[history.length - 1]!.thought_number ?? history.length;\n\t\treturn [\n\t\t\t{\n\t\t\t\tpattern: 'no_alternatives_explored',\n\t\t\t\tseverity: 'warning',\n\t\t\t\tmessage: '5+ thoughts with no critique or branching — consider exploring alternatives',\n\t\t\t\tthought_range: [start, end],\n\t\t\t},\n\t\t];\n\t}\n\n\t/**\n\t * Detect runs of 4+ consecutive thoughts with the same thought_type.\n\t * Only fires when history has ≥5 thoughts and at least one explicitly set thought_type.\n\t */\n\tprivate _detectMonotonicType(history: ThoughtData[]): PatternSignal[] {\n\t\tif (history.length < 5) return [];\n\t\tconst hasExplicitType = history.some((t) => t.thought_type !== undefined);\n\t\tif (!hasExplicitType) return [];\n\n\t\tconst signals: PatternSignal[] = [];\n\t\tlet runType = history[0]!.thought_type ?? 'regular';\n\t\tlet runStart = 0;\n\t\tlet runLength = 1;\n\n\t\tfor (let i = 1; i < history.length; i++) {\n\t\t\tconst type = history[i]!.thought_type ?? 'regular';\n\t\t\tif (type === runType) {\n\t\t\t\trunLength++;\n\t\t\t} else {\n\t\t\t\tthis._flushMonotonicRun(history, runStart, runLength, runType, signals);\n\t\t\t\trunType = type;\n\t\t\t\trunStart = i;\n\t\t\t\trunLength = 1;\n\t\t\t}\n\t\t}\n\t\tthis._flushMonotonicRun(history, runStart, runLength, runType, signals);\n\t\treturn signals;\n\t}\n\n\t/** Emit a monotonic_type signal if the run length qualifies. */\n\tprivate _flushMonotonicRun(\n\t\thistory: ThoughtData[],\n\t\trunStart: number,\n\t\trunLength: number,\n\t\trunType: string,\n\t\tsignals: PatternSignal[]\n\t): void {\n\t\tif (runLength < 4) return;\n\t\tconst start = history[runStart]!.thought_number ?? runStart + 1;\n\t\tconst end = history[runStart + runLength - 1]!.thought_number ?? runStart + runLength;\n\t\tsignals.push({\n\t\t\tpattern: 'monotonic_type',\n\t\t\tseverity: 'warning',\n\t\t\tmessage: `4+ consecutive '${runType}' thoughts (${start}-${end}) — consider varying approach`,\n\t\t\tthought_range: [start, end],\n\t\t});\n\t}\n\n\t/** Detect runs of 3+ consecutive thoughts with strictly decreasing confidence. */\n\tprivate _detectConfidenceDrift(history: ThoughtData[]): PatternSignal[] {\n\t\tconst signals: PatternSignal[] = [];\n\t\tlet runStart = -1;\n\t\tlet runLength = 0;\n\t\tlet prevConf = -1;\n\n\t\tfor (let i = 0; i < history.length; i++) {\n\t\t\tconst conf = history[i]!.confidence;\n\t\t\tif (conf === undefined) {\n\t\t\t\tthis._flushDriftRun(history, runStart, runLength, signals);\n\t\t\t\trunStart = -1;\n\t\t\t\trunLength = 0;\n\t\t\t\tprevConf = -1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (runLength === 0) {\n\t\t\t\trunStart = i;\n\t\t\t\trunLength = 1;\n\t\t\t\tprevConf = conf;\n\t\t\t} else if (conf < prevConf) {\n\t\t\t\trunLength++;\n\t\t\t\tprevConf = conf;\n\t\t\t} else {\n\t\t\t\tthis._flushDriftRun(history, runStart, runLength, signals);\n\t\t\t\trunStart = i;\n\t\t\t\trunLength = 1;\n\t\t\t\tprevConf = conf;\n\t\t\t}\n\t\t}\n\t\tthis._flushDriftRun(history, runStart, runLength, signals);\n\t\treturn signals;\n\t}\n\n\t/** Emit a confidence_drift signal if the run length qualifies. */\n\tprivate _flushDriftRun(\n\t\thistory: ThoughtData[],\n\t\trunStart: number,\n\t\trunLength: number,\n\t\tsignals: PatternSignal[]\n\t): void {\n\t\tif (runLength < 3) return;\n\t\tconst first = history[runStart];\n\t\tconst last = history[runStart + runLength - 1];\n\t\tif (!first || !last) return;\n\t\tif (first.confidence === undefined || last.confidence === undefined) return;\n\t\tconst start = first.thought_number ?? runStart + 1;\n\t\tconst end = last.thought_number ?? runStart + runLength;\n\t\tconst firstConf = first.confidence;\n\t\tconst lastConf = last.confidence;\n\t\tsignals.push({\n\t\t\tpattern: 'confidence_drift',\n\t\t\tseverity: 'warning',\n\t\t\tmessage: `Confidence decreasing across thoughts ${start}-${end} (${firstConf} → ${lastConf})`,\n\t\t\tthought_range: [start, end],\n\t\t});\n\t}\n\n\t/** Detect hypothesis verified within 3 subsequent thoughts — positive signal. */\n\tprivate _detectHealthyVerification(history: ThoughtData[]): PatternSignal[] {\n\t\tconst signals: PatternSignal[] = [];\n\t\tfor (let i = 0; i < history.length; i++) {\n\t\t\tif (history[i]!.thought_type !== 'hypothesis') continue;\n\t\t\tconst hypId = history[i]!.hypothesis_id;\n\t\t\tconst lookahead = history.slice(i + 1, i + 4);\n\t\t\tconst verifier = lookahead.find(\n\t\t\t\t(t) =>\n\t\t\t\t\tt.thought_type === 'verification' &&\n\t\t\t\t\t(t.hypothesis_id === hypId ||\n\t\t\t\t\t\tt.verification_target === (history[i]!.thought_number ?? i + 1))\n\t\t\t);\n\t\t\tif (verifier) {\n\t\t\t\tconst n = history[i]!.thought_number ?? i + 1;\n\t\t\t\tconst m = verifier.thought_number ?? history.indexOf(verifier) + 1;\n\t\t\t\tsignals.push({\n\t\t\t\t\tpattern: 'healthy_verification',\n\t\t\t\t\tseverity: 'info',\n\t\t\t\t\tmessage: `Hypothesis at thought ${n} verified at thought ${m} — good practice`,\n\t\t\t\t\tthought_range: [n, m],\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\treturn signals;\n\t}\n}\n"],"names":["PatternDetector","history","branches","signals","runStart","i","type","start","end","remaining","lookahead","hasVerification","t","n","Object","hasExplicitType","undefined","runType","runLength","prevConf","conf","first","last","firstConf","lastConf","hypId","verifier","m"],"mappings":"AAyCO,MAAMA;IAQL,sBACNC,OAAsB,EACtBC,QAAuC,EACrB;QAClB,IAAID,AAAmB,MAAnBA,QAAQ,MAAM,EAAQ,OAAO,EAAE;QAEnC,MAAME,UAA2B,EAAE;QACnCA,QAAQ,IAAI,IAAI,IAAI,CAAC,qCAAqC,CAACF;QAC3DE,QAAQ,IAAI,IAAI,IAAI,CAAC,2BAA2B,CAACF;QACjDE,QAAQ,IAAI,IAAI,IAAI,CAAC,6BAA6B,CAACF,SAASC;QAC5DC,QAAQ,IAAI,IAAI,IAAI,CAAC,oBAAoB,CAACF;QAC1CE,QAAQ,IAAI,IAAI,IAAI,CAAC,sBAAsB,CAACF;QAC5CE,QAAQ,IAAI,IAAI,IAAI,CAAC,0BAA0B,CAACF;QAChD,OAAOE;IACR;IAGQ,sCAAsCF,OAAsB,EAAmB;QACtF,MAAME,UAA2B,EAAE;QACnC,IAAIC,WAAW;QACf,IAAK,IAAIC,IAAI,GAAGA,IAAIJ,QAAQ,MAAM,EAAEI,IAAK;YACxC,MAAMC,OAAOL,OAAO,CAACI,EAAE,CAAE,YAAY,IAAI;YACzC,IAAIC,AAAS,mBAATA,MAAyB;gBAC5BF,WAAWC,IAAI;gBACf;YACD;YACA,IAAIA,IAAID,WAAW,KAAK,GAAG;gBAC1B,MAAMG,QAAQN,OAAO,CAACG,SAAS,CAAE,cAAc,IAAIA,WAAW;gBAC9D,MAAMI,MAAMP,OAAO,CAACI,EAAE,CAAE,cAAc,IA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AU;QAChCnB,QAAQ,IAAI,CAAC;YACZ,SAAS;YACT,UAAU;YACV,SAAS,CAAC,sCAAsC,EAAEI,MAAM,CAAC,EAAEC,IAAI,EAAE,EAAEe,UAAU,GAAG,EAAEC,SAAS,CAAC,CAAC;YAC7F,eAAe;gBAACjB;gBAAOC;aAAI;QAC5B;IACD;IAGQ,2BAA2BP,OAAsB,EAAmB;QAC3E,MAAME,UAA2B,EAAE;QACnC,IAAK,IAAIE,IAAI,GAAGA,IAAIJ,QAAQ,MAAM,EAAEI,IAAK;YACxC,IAAIJ,AAA6B,iBAA7BA,OAAO,CAACI,EAAE,CAAE,YAAY,EAAmB;YAC/C,MAAMoB,QAAQxB,OAAO,CAACI,EAAE,CAAE,aAAa;YACvC,MAAMK,YAAYT,QAAQ,KAAK,CAACI,IAAI,GAAGA,IAAI;YAC3C,MAAMqB,WAAWhB,UAAU,IAAI,CAC9B,CAACE,IACAA,AAAmB,mBAAnBA,EAAE,YAAY,IACbA,CAAAA,EAAE,aAAa,KAAKa,SACpBb,EAAE,mBAAmB,KAAMX,CAAAA,OAAO,CAACI,EAAE,CAAE,cAAc,IAAIA,IAAI,EAAC;YAEjE,IAAIqB,UAAU;gBACb,MAAMb,IAAIZ,OAAO,CAACI,EAAE,CAAE,cAAc,IAAIA,IAAI;gBAC5C,MAAMsB,IAAID,SAAS,cAAc,IAAIzB,QAAQ,OAAO,CAACyB,YAAY;gBACjEvB,QAAQ,IAAI,CAAC;oBACZ,SAAS;oBACT,UAAU;oBACV,SAAS,CAAC,sBAAsB,EAAEU,EAAE,qBAAqB,EAAEc,EAAE,gBAAgB,CAAC;oBAC9E,eAAe;wBAACd;wBAAGc;qBAAE;gBACtB;YACD;QACD;QACA,OAAOxB;IACR;AACD"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Confidence signal computation for sequential thinking.
|
|
3
|
+
*
|
|
4
|
+
* Provides {@link SignalComputer} — a pure stateless service that computes
|
|
5
|
+
* {@link ConfidenceSignals} (including the composite `structural_quality`
|
|
6
|
+
* score and its components) from thought history and branch data.
|
|
7
|
+
*
|
|
8
|
+
* Extracted from `ThoughtEvaluator` as part of the evaluator decomposition.
|
|
9
|
+
* All methods are pure: no side effects, no I/O, no internal state.
|
|
10
|
+
*
|
|
11
|
+
* @module core/evaluator/SignalComputer
|
|
12
|
+
*/
|
|
13
|
+
import type { ConfidenceSignals, ThoughtType } from '../reasoning.js';
|
|
14
|
+
import type { ThoughtData } from '../thought.js';
|
|
15
|
+
/** Result of {@link SignalComputer.computeStructuralQuality}. */
|
|
16
|
+
interface StructuralQualityResult {
|
|
17
|
+
score: number;
|
|
18
|
+
components: {
|
|
19
|
+
type_diversity: number;
|
|
20
|
+
verification_coverage: number;
|
|
21
|
+
depth_efficiency: number;
|
|
22
|
+
confidence_stability: number | null;
|
|
23
|
+
};
|
|
24
|
+
raw_components: {
|
|
25
|
+
type_diversity: number;
|
|
26
|
+
verification_coverage: number;
|
|
27
|
+
depth_efficiency: number;
|
|
28
|
+
confidence_stability: number | null;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Stateless service that computes {@link ConfidenceSignals} from thought history.
|
|
33
|
+
*
|
|
34
|
+
* @remarks
|
|
35
|
+
* Pure computation — no side effects, no I/O, no internal state.
|
|
36
|
+
* Safe to register as singleton or transient in DI.
|
|
37
|
+
*/
|
|
38
|
+
export declare class SignalComputer {
|
|
39
|
+
/**
|
|
40
|
+
* Structural quality weight configuration.
|
|
41
|
+
*
|
|
42
|
+
* Weights reflect the relative importance of each quality dimension:
|
|
43
|
+
* - type_diversity (0.3): Shannon entropy of thought types — rewards reasoning that uses
|
|
44
|
+
* multiple cognitive modes (hypothesis, verification, critique, synthesis) rather than
|
|
45
|
+
* monotonic sequences. Based on information theory: higher entropy = more information.
|
|
46
|
+
*
|
|
47
|
+
* - verification_coverage (0.3): Ratio of verified to total hypotheses — rewards scientific
|
|
48
|
+
* rigor. Hypotheses without verification are speculation; verification grounds reasoning.
|
|
49
|
+
* Equal weight with diversity because unverified reasoning is a common failure mode.
|
|
50
|
+
*
|
|
51
|
+
* - depth_efficiency (0.2): Ratio of structural depth to total thoughts — rewards efficient
|
|
52
|
+
* reasoning. Deep chains (many revisions/branches) are good; but only if proportionally
|
|
53
|
+
* dense. Padding with low-value thoughts penalizes this metric.
|
|
54
|
+
*
|
|
55
|
+
* - confidence_stability (0.2): Low variance in self-assessed confidence — rewards calibrated
|
|
56
|
+
* reasoning. Wildly fluctuating confidence suggests uncertainty about the approach.
|
|
57
|
+
* Lower weight because confidence values are LLM self-reports (inherently noisy).
|
|
58
|
+
*
|
|
59
|
+
* Design rationale:
|
|
60
|
+
* - Diversity + Verification (0.6) > Depth + Stability (0.4): Structural properties of the
|
|
61
|
+
* reasoning DAG are more important than behavioral signals.
|
|
62
|
+
* - All weights are positive (no dimension is penalizing).
|
|
63
|
+
* - Weights sum to 1.0 for normalized scoring.
|
|
64
|
+
* - When confidence_stability is unavailable (n<2), remaining weights redistribute
|
|
65
|
+
* proportionally: td→0.375, vc→0.375, de→0.25 (preserving relative ratios).
|
|
66
|
+
*/
|
|
67
|
+
private static readonly QUALITY_WEIGHTS;
|
|
68
|
+
/**
|
|
69
|
+
* Redistributed weights when confidence_stability is excluded (n<2).
|
|
70
|
+
* Preserves relative ratios of remaining components (sum = 1.0).
|
|
71
|
+
*/
|
|
72
|
+
private static readonly QUALITY_WEIGHTS_NO_CS;
|
|
73
|
+
/**
|
|
74
|
+
* Compute confidence signals from history context.
|
|
75
|
+
*
|
|
76
|
+
* @param history - All thoughts in the current session
|
|
77
|
+
* @param branches - Map of branch IDs to their thought arrays
|
|
78
|
+
* @returns Computed confidence signals reflecting reasoning quality
|
|
79
|
+
*/
|
|
80
|
+
computeConfidenceSignals(history: ThoughtData[], branches: Record<string, ThoughtData[]>): ConfidenceSignals;
|
|
81
|
+
/**
|
|
82
|
+
* Compute the composite structural quality score and its components.
|
|
83
|
+
*
|
|
84
|
+
* Algorithm (all components floored at {@link FLOOR} = 0.01):
|
|
85
|
+
* - `type_diversity` = Shannon entropy of thought_type distribution / log2(6)
|
|
86
|
+
* - `verification_coverage` = verified_hypotheses / max(total_hypotheses, 1) (1.0 if none)
|
|
87
|
+
* - `depth_efficiency` = max(chain_depth, branch_count + 1) / total_thoughts, clamped to 1.0
|
|
88
|
+
* - `confidence_stability` = 1 - stddev(confidences), default 0.5 when empty, null when single value
|
|
89
|
+
* - `structural_quality` = td^0.3 * vc^0.3 * de^0.2 * cs^0.2 (weighted geometric mean)
|
|
90
|
+
*
|
|
91
|
+
* Note: When confidence_stability is null (fewer than 2 confidence values), it is
|
|
92
|
+
* excluded from the geometric mean and the remaining weights are redistributed
|
|
93
|
+
* proportionally (td→0.375, vc→0.375, de→0.25).
|
|
94
|
+
*
|
|
95
|
+
* @returns Score + components, or `null` when history is empty
|
|
96
|
+
*/
|
|
97
|
+
computeStructuralQuality(history: ThoughtData[], branches: Record<string, ThoughtData[]>, typeDistribution: Record<ThoughtType, number>, confidences: number[]): StructuralQualityResult | null;
|
|
98
|
+
/**
|
|
99
|
+
* Compute confidence stability: 1 - stddev(confidences).
|
|
100
|
+
*
|
|
101
|
+
* - Empty input → 0.5 (neutral default)
|
|
102
|
+
* - Single value → null (insufficient data, excluded from structural quality)
|
|
103
|
+
* - Otherwise → max(1 - stddev, FLOOR)
|
|
104
|
+
*/
|
|
105
|
+
computeConfidenceStability(confidences: number[]): number | null;
|
|
106
|
+
/**
|
|
107
|
+
* Compute raw (unfloored) confidence stability: 1 - stddev(confidences).
|
|
108
|
+
*
|
|
109
|
+
* - Empty input → 0.5 (neutral default)
|
|
110
|
+
* - Single value → null (insufficient data)
|
|
111
|
+
* - Otherwise → 1 - stddev (may be below FLOOR)
|
|
112
|
+
*/
|
|
113
|
+
computeRawConfidenceStability(confidences: number[]): number | null;
|
|
114
|
+
}
|
|
115
|
+
export {};
|
|
116
|
+
//# sourceMappingURL=SignalComputer.d.ts.map
|
|
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MAAM,EAAE,GACnB,uBAAuB,GAAG,IAAI;IA+EjC;;;;;;OAMG;IACI,0BAA0B,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,IAAI;IAUvE;;;;;;OAMG;IACI,6BAA6B,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,IAAI;CAS1E"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { ALL_THOUGHT_TYPES, _computeChainDepth, _countByType } from "./internals.js";
|
|
2
|
+
const FLOOR = 0.01;
|
|
3
|
+
function roundToPrecision(value, decimals = 10) {
|
|
4
|
+
const factor = Math.pow(10, decimals);
|
|
5
|
+
return Math.round(value * factor) / factor;
|
|
6
|
+
}
|
|
7
|
+
class SignalComputer {
|
|
8
|
+
static QUALITY_WEIGHTS = {
|
|
9
|
+
typeDiversity: 0.3,
|
|
10
|
+
verificationCoverage: 0.3,
|
|
11
|
+
depthEfficiency: 0.2,
|
|
12
|
+
confidenceStability: 0.2
|
|
13
|
+
};
|
|
14
|
+
static QUALITY_WEIGHTS_NO_CS = {
|
|
15
|
+
typeDiversity: 0.375,
|
|
16
|
+
verificationCoverage: 0.375,
|
|
17
|
+
depthEfficiency: 0.25
|
|
18
|
+
};
|
|
19
|
+
computeConfidenceSignals(history, branches) {
|
|
20
|
+
const typeDistribution = _countByType(history);
|
|
21
|
+
const allConfidences = history.map((t)=>t.confidence).filter((c)=>void 0 !== c);
|
|
22
|
+
const structuralResult = this.computeStructuralQuality(history, branches, typeDistribution, allConfidences);
|
|
23
|
+
return {
|
|
24
|
+
reasoning_depth: history.length,
|
|
25
|
+
revision_count: history.filter((t)=>t.is_revision).length,
|
|
26
|
+
branch_count: Object.keys(branches).length,
|
|
27
|
+
thought_type_distribution: typeDistribution,
|
|
28
|
+
has_hypothesis: history.some((t)=>'hypothesis' === t.thought_type),
|
|
29
|
+
has_verification: history.some((t)=>'verification' === t.thought_type),
|
|
30
|
+
average_confidence: allConfidences.length > 0 ? roundToPrecision(allConfidences.reduce((a, b)=>a + b, 0) / allConfidences.length) : null,
|
|
31
|
+
...null !== structuralResult && {
|
|
32
|
+
structural_quality: structuralResult.score,
|
|
33
|
+
quality_components: structuralResult.components,
|
|
34
|
+
quality_components_raw: structuralResult.raw_components
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
computeStructuralQuality(history, branches, typeDistribution, confidences) {
|
|
39
|
+
if (0 === history.length) return null;
|
|
40
|
+
const total = history.length;
|
|
41
|
+
let entropy = 0;
|
|
42
|
+
for (const type of ALL_THOUGHT_TYPES){
|
|
43
|
+
const count = typeDistribution[type];
|
|
44
|
+
if (count > 0) {
|
|
45
|
+
const pk = count / total;
|
|
46
|
+
entropy -= pk * Math.log2(pk);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const rawTypeDiversity = entropy / Math.log2(6);
|
|
50
|
+
const typeDiversity = Math.max(rawTypeDiversity, FLOOR);
|
|
51
|
+
const hypotheses = history.filter((t)=>'hypothesis' === t.thought_type);
|
|
52
|
+
const hypothesisIds = new Set(hypotheses.map((t)=>t.hypothesis_id).filter(Boolean));
|
|
53
|
+
const verifiedIds = new Set(history.filter((t)=>'verification' === t.thought_type && t.hypothesis_id).map((t)=>t.hypothesis_id));
|
|
54
|
+
const rawVerificationCoverage = 0 === hypothesisIds.size ? 1.0 : [
|
|
55
|
+
...hypothesisIds
|
|
56
|
+
].filter((id)=>verifiedIds.has(id)).length / hypothesisIds.size;
|
|
57
|
+
const verificationCoverage = Math.max(rawVerificationCoverage, FLOOR);
|
|
58
|
+
const chainDepth = _computeChainDepth(history);
|
|
59
|
+
const branchCount = Object.keys(branches).length;
|
|
60
|
+
const effectiveDepth = Math.max(chainDepth, branchCount + 1);
|
|
61
|
+
const rawDepthEfficiency = Math.min(effectiveDepth / total, 1.0);
|
|
62
|
+
const depthEfficiency = Math.max(rawDepthEfficiency, FLOOR);
|
|
63
|
+
const confidenceStability = this.computeConfidenceStability(confidences);
|
|
64
|
+
const rawConfidenceStability = this.computeRawConfidenceStability(confidences);
|
|
65
|
+
const components = {
|
|
66
|
+
type_diversity: typeDiversity,
|
|
67
|
+
verification_coverage: verificationCoverage,
|
|
68
|
+
depth_efficiency: depthEfficiency,
|
|
69
|
+
confidence_stability: confidenceStability
|
|
70
|
+
};
|
|
71
|
+
const rawComponents = {
|
|
72
|
+
type_diversity: rawTypeDiversity,
|
|
73
|
+
verification_coverage: rawVerificationCoverage,
|
|
74
|
+
depth_efficiency: rawDepthEfficiency,
|
|
75
|
+
confidence_stability: rawConfidenceStability
|
|
76
|
+
};
|
|
77
|
+
let score;
|
|
78
|
+
if (null !== confidenceStability) {
|
|
79
|
+
const w = SignalComputer.QUALITY_WEIGHTS;
|
|
80
|
+
score = Math.pow(typeDiversity, w.typeDiversity) * Math.pow(verificationCoverage, w.verificationCoverage) * Math.pow(depthEfficiency, w.depthEfficiency) * Math.pow(confidenceStability, w.confidenceStability);
|
|
81
|
+
} else {
|
|
82
|
+
const w3 = SignalComputer.QUALITY_WEIGHTS_NO_CS;
|
|
83
|
+
score = Math.pow(typeDiversity, w3.typeDiversity) * Math.pow(verificationCoverage, w3.verificationCoverage) * Math.pow(depthEfficiency, w3.depthEfficiency);
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
score,
|
|
87
|
+
components,
|
|
88
|
+
raw_components: rawComponents
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
computeConfidenceStability(confidences) {
|
|
92
|
+
if (0 === confidences.length) return 0.5;
|
|
93
|
+
if (1 === confidences.length) return null;
|
|
94
|
+
const mean = confidences.reduce((a, b)=>a + b, 0) / confidences.length;
|
|
95
|
+
const variance = confidences.reduce((sum, c)=>sum + (c - mean) ** 2, 0) / confidences.length;
|
|
96
|
+
const stddev = Math.sqrt(variance);
|
|
97
|
+
return Math.max(1 - stddev, FLOOR);
|
|
98
|
+
}
|
|
99
|
+
computeRawConfidenceStability(confidences) {
|
|
100
|
+
if (0 === confidences.length) return 0.5;
|
|
101
|
+
if (1 === confidences.length) return null;
|
|
102
|
+
const mean = confidences.reduce((a, b)=>a + b, 0) / confidences.length;
|
|
103
|
+
const variance = confidences.reduce((sum, c)=>sum + (c - mean) ** 2, 0) / confidences.length;
|
|
104
|
+
const stddev = Math.sqrt(variance);
|
|
105
|
+
return 1 - stddev;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
export { SignalComputer };
|
|
109
|
+
|
|
110
|
+
//# sourceMappingURL=SignalComputer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core/evaluator/SignalComputer.js","sources":["../../../src/core/evaluator/SignalComputer.ts"],"sourcesContent":["/**\n * Confidence signal computation for sequential thinking.\n *\n * Provides {@link SignalComputer} — a pure stateless service that computes\n * {@link ConfidenceSignals} (including the composite `structural_quality`\n * score and its components) from thought history and branch data.\n *\n * Extracted from `ThoughtEvaluator` as part of the evaluator decomposition.\n * All methods are pure: no side effects, no I/O, no internal state.\n *\n * @module core/evaluator/SignalComputer\n */\n\nimport type { ConfidenceSignals, ThoughtType } from '../reasoning.js';\nimport type { ThoughtData } from '../thought.js';\nimport { ALL_THOUGHT_TYPES, _computeChainDepth, _countByType } from './internals.js';\n\n/** Floor value applied to each quality component to prevent geometric mean collapse. */\nconst FLOOR = 0.01;\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/** Result of {@link SignalComputer.computeStructuralQuality}. */\ninterface StructuralQualityResult {\n\tscore: number;\n\tcomponents: {\n\t\ttype_diversity: number;\n\t\tverification_coverage: number;\n\t\tdepth_efficiency: number;\n\t\tconfidence_stability: number | null;\n\t};\n\traw_components: {\n\t\ttype_diversity: number;\n\t\tverification_coverage: number;\n\t\tdepth_efficiency: number;\n\t\tconfidence_stability: number | null;\n\t};\n}\n\n/**\n * Stateless service that computes {@link ConfidenceSignals} from thought history.\n *\n * @remarks\n * Pure computation — no side effects, no I/O, no internal state.\n * Safe to register as singleton or transient in DI.\n */\nexport class SignalComputer {\n\t/**\n\t * Structural quality weight configuration.\n\t *\n\t * Weights reflect the relative importance of each quality dimension:\n\t * - type_diversity (0.3): Shannon entropy of thought types — rewards reasoning that uses\n\t * multiple cognitive modes (hypothesis, verification, critique, synthesis) rather than\n\t * monotonic sequences. Based on information theory: higher entropy = more information.\n\t *\n\t * - verification_coverage (0.3): Ratio of verified to total hypotheses — rewards scientific\n\t * rigor. Hypotheses without verification are speculation; verification grounds reasoning.\n\t * Equal weight with diversity because unverified reasoning is a common failure mode.\n\t *\n\t * - depth_efficiency (0.2): Ratio of structural depth to total thoughts — rewards efficient\n\t * reasoning. Deep chains (many revisions/branches) are good; but only if proportionally\n\t * dense. Padding with low-value thoughts penalizes this metric.\n\t *\n\t * - confidence_stability (0.2): Low variance in self-assessed confidence — rewards calibrated\n\t * reasoning. Wildly fluctuating confidence suggests uncertainty about the approach.\n\t * Lower weight because confidence values are LLM self-reports (inherently noisy).\n\t *\n\t * Design rationale:\n\t * - Diversity + Verification (0.6) > Depth + Stability (0.4): Structural properties of the\n\t * reasoning DAG are more important than behavioral signals.\n\t * - All weights are positive (no dimension is penalizing).\n\t * - Weights sum to 1.0 for normalized scoring.\n\t * - When confidence_stability is unavailable (n<2), remaining weights redistribute\n\t * proportionally: td→0.375, vc→0.375, de→0.25 (preserving relative ratios).\n\t */\n\tprivate static readonly QUALITY_WEIGHTS = {\n\t\ttypeDiversity: 0.3,\n\t\tverificationCoverage: 0.3,\n\t\tdepthEfficiency: 0.2,\n\t\tconfidenceStability: 0.2,\n\t} as const;\n\n\t/**\n\t * Redistributed weights when confidence_stability is excluded (n<2).\n\t * Preserves relative ratios of remaining components (sum = 1.0).\n\t */\n\tprivate static readonly QUALITY_WEIGHTS_NO_CS = {\n\t\ttypeDiversity: 0.375,\n\t\tverificationCoverage: 0.375,\n\t\tdepthEfficiency: 0.25,\n\t} as const;\n\n\t/**\n\t * Compute confidence signals from history context.\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 Computed confidence signals reflecting reasoning quality\n\t */\n\tpublic computeConfidenceSignals(\n\t\thistory: ThoughtData[],\n\t\tbranches: Record<string, ThoughtData[]>\n\t): ConfidenceSignals {\n\t\tconst typeDistribution = _countByType(history);\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\t// Compute structural quality components\n\t\tconst structuralResult = this.computeStructuralQuality(\n\t\t\thistory,\n\t\t\tbranches,\n\t\t\ttypeDistribution,\n\t\t\tallConfidences\n\t\t);\n\n\t\treturn {\n\t\t\treasoning_depth: history.length,\n\t\t\trevision_count: history.filter((t) => t.is_revision).length,\n\t\t\tbranch_count: Object.keys(branches).length,\n\t\t\tthought_type_distribution: typeDistribution,\n\t\t\thas_hypothesis: history.some((t) => t.thought_type === 'hypothesis'),\n\t\t\thas_verification: history.some((t) => t.thought_type === 'verification'),\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\t...(structuralResult !== null && {\n\t\t\t\tstructural_quality: structuralResult.score,\n\t\t\t\tquality_components: structuralResult.components,\n\t\t\t\tquality_components_raw: structuralResult.raw_components,\n\t\t\t}),\n\t\t};\n\t}\n\n\t/**\n\t * Compute the composite structural quality score and its components.\n\t *\n\t * Algorithm (all components floored at {@link FLOOR} = 0.01):\n\t * - `type_diversity` = Shannon entropy of thought_type distribution / log2(6)\n\t * - `verification_coverage` = verified_hypotheses / max(total_hypotheses, 1) (1.0 if none)\n\t * - `depth_efficiency` = max(chain_depth, branch_count + 1) / total_thoughts, clamped to 1.0\n\t * - `confidence_stability` = 1 - stddev(confidences), default 0.5 when empty, null when single value\n\t * - `structural_quality` = td^0.3 * vc^0.3 * de^0.2 * cs^0.2 (weighted geometric mean)\n\t *\n\t * Note: When confidence_stability is null (fewer than 2 confidence values), it is\n\t * excluded from the geometric mean and the remaining weights are redistributed\n\t * proportionally (td→0.375, vc→0.375, de→0.25).\n\t *\n\t * @returns Score + components, or `null` when history is empty\n\t */\n\tpublic computeStructuralQuality(\n\t\thistory: ThoughtData[],\n\t\tbranches: Record<string, ThoughtData[]>,\n\t\ttypeDistribution: Record<ThoughtType, number>,\n\t\tconfidences: number[]\n\t): StructuralQualityResult | null {\n\t\tif (history.length === 0) return null;\n\n\t\t// 1. type_diversity: Shannon entropy / log2(6)\n\t\tconst total = history.length;\n\t\tlet entropy = 0;\n\t\tfor (const type of ALL_THOUGHT_TYPES) {\n\t\t\tconst count = typeDistribution[type];\n\t\t\tif (count > 0) {\n\t\t\t\tconst pk = count / total;\n\t\t\t\tentropy -= pk * Math.log2(pk);\n\t\t\t}\n\t\t}\n\t\tconst rawTypeDiversity = entropy / Math.log2(6);\n\t\tconst typeDiversity = Math.max(rawTypeDiversity, FLOOR);\n\n\t\t// 2. verification_coverage: verified / total hypotheses (1.0 if none)\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 rawVerificationCoverage =\n\t\t\thypothesisIds.size === 0\n\t\t\t\t? 1.0\n\t\t\t\t: [...hypothesisIds].filter((id) => verifiedIds.has(id)).length / hypothesisIds.size;\n\t\tconst verificationCoverage = Math.max(rawVerificationCoverage, FLOOR);\n\n\t\t// 3. depth_efficiency: max(chain_depth, branch_count + 1) / total_thoughts, clamped to 1.0\n\t\t// NOTE (Metis H3): Branching is desirable — treat branches as depth-equivalent.\n\t\tconst chainDepth = _computeChainDepth(history);\n\t\tconst branchCount = Object.keys(branches).length;\n\t\tconst effectiveDepth = Math.max(chainDepth, branchCount + 1);\n\t\tconst rawDepthEfficiency = Math.min(effectiveDepth / total, 1.0);\n\t\tconst depthEfficiency = Math.max(rawDepthEfficiency, FLOOR);\n\n\t\t// 4. confidence_stability: 1 - stddev(confidences), default 0.5\n\t\tconst confidenceStability = this.computeConfidenceStability(confidences);\n\t\tconst rawConfidenceStability = this.computeRawConfidenceStability(confidences);\n\n\t\tconst components: StructuralQualityResult['components'] = {\n\t\t\ttype_diversity: typeDiversity,\n\t\t\tverification_coverage: verificationCoverage,\n\t\t\tdepth_efficiency: depthEfficiency,\n\t\t\tconfidence_stability: confidenceStability,\n\t\t};\n\n\t\tconst rawComponents: StructuralQualityResult['raw_components'] = {\n\t\t\ttype_diversity: rawTypeDiversity,\n\t\t\tverification_coverage: rawVerificationCoverage,\n\t\t\tdepth_efficiency: rawDepthEfficiency,\n\t\t\tconfidence_stability: rawConfidenceStability,\n\t\t};\n\n\t\t// Weighted geometric mean: td^0.3 * vc^0.3 * de^0.2 * cs^0.2\n\t\t// When confidence_stability is null (n<2), exclude it from the geomean\n\t\t// and redistribute its weight proportionally to remaining components\n\t\t// (normalized td=0.375, vc=0.375, de=0.25)\n\t\tlet score: number;\n\t\tif (confidenceStability !== null) {\n\t\t\tconst w = SignalComputer.QUALITY_WEIGHTS;\n\t\t\tscore =\n\t\t\t\tMath.pow(typeDiversity, w.typeDiversity) *\n\t\t\t\tMath.pow(verificationCoverage, w.verificationCoverage) *\n\t\t\t\tMath.pow(depthEfficiency, w.depthEfficiency) *\n\t\t\t\tMath.pow(confidenceStability, w.confidenceStability);\n\t\t} else {\n\t\t\tconst w3 = SignalComputer.QUALITY_WEIGHTS_NO_CS;\n\t\t\tscore =\n\t\t\t\tMath.pow(typeDiversity, w3.typeDiversity) *\n\t\t\t\tMath.pow(verificationCoverage, w3.verificationCoverage) *\n\t\t\t\tMath.pow(depthEfficiency, w3.depthEfficiency);\n\t\t}\n\n\t\treturn { score, components, raw_components: rawComponents };\n\t}\n\n\t/**\n\t * Compute confidence stability: 1 - stddev(confidences).\n\t *\n\t * - Empty input → 0.5 (neutral default)\n\t * - Single value → null (insufficient data, excluded from structural quality)\n\t * - Otherwise → max(1 - stddev, FLOOR)\n\t */\n\tpublic computeConfidenceStability(confidences: number[]): number | null {\n\t\tif (confidences.length === 0) return 0.5;\n\t\tif (confidences.length === 1) return null;\n\n\t\tconst mean = confidences.reduce((a, b) => a + b, 0) / confidences.length;\n\t\tconst variance = confidences.reduce((sum, c) => sum + (c - mean) ** 2, 0) / confidences.length;\n\t\tconst stddev = Math.sqrt(variance);\n\t\treturn Math.max(1 - stddev, FLOOR);\n\t}\n\n\t/**\n\t * Compute raw (unfloored) confidence stability: 1 - stddev(confidences).\n\t *\n\t * - Empty input → 0.5 (neutral default)\n\t * - Single value → null (insufficient data)\n\t * - Otherwise → 1 - stddev (may be below FLOOR)\n\t */\n\tpublic computeRawConfidenceStability(confidences: number[]): number | null {\n\t\tif (confidences.length === 0) return 0.5;\n\t\tif (confidences.length === 1) return null;\n\n\t\tconst mean = confidences.reduce((a, b) => a + b, 0) / confidences.length;\n\t\tconst variance = confidences.reduce((sum, c) => sum + (c - mean) ** 2, 0) / confidences.length;\n\t\tconst stddev = Math.sqrt(variance);\n\t\treturn 1 - stddev;\n\t}\n}\n"],"names":["FLOOR","roundToPrecision","value","decimals","factor","Math","SignalComputer","history","branches","typeDistribution","_countByType","allConfidences","t","c","undefined","structuralResult","Object","a","b","confidences","total","entropy","type","ALL_THOUGHT_TYPES","count","pk","rawTypeDiversity","typeDiversity","hypotheses","hypothesisIds","Set","Boolean","verifiedIds","rawVerificationCoverage","id","verificationCoverage","chainDepth","_computeChainDepth","branchCount","effectiveDepth","rawDepthEfficiency","depthEfficiency","confidenceStability","rawConfidenceStability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,AAAAA,CAAAA,IAAIoC,IAAG,KAAM,GAAG,KAAK9B,YAAY,MAAM;QAC9F,MAAMiC,SAAS/C,KAAK,IAAI,CAAC6C;QACzB,OAAO7C,KAAK,GAAG,CAAC,IAAI+C,QAAQpD;IAC7B;IASO,8BAA8BmB,WAAqB,EAAiB;QAC1E,IAAIA,AAAuB,MAAvBA,YAAY,MAAM,EAAQ,OAAO;QACrC,IAAIA,AAAuB,MAAvBA,YAAY,MAAM,EAAQ,OAAO;QAErC,MAAM8B,OAAO9B,YAAY,MAAM,CAAC,CAACF,GAAGC,IAAMD,IAAIC,GAAG,KAAKC,YAAY,MAAM;QACxE,MAAM+B,WAAW/B,YAAY,MAAM,CAAC,CAACgC,KAAKtC,IAAMsC,MAAOtC,AAAAA,CAAAA,IAAIoC,IAAG,KAAM,GAAG,KAAK9B,YAAY,MAAM;QAC9F,MAAMiC,SAAS/C,KAAK,IAAI,CAAC6C;QACzB,OAAO,IAAIE;IACZ;AACD"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { VerificationOutcome } from '../../contracts/interfaces.js';
|
|
2
|
+
/** Candidate temperatures evaluated during grid search refit. */
|
|
3
|
+
export declare const TEMPERATURE_GRID: readonly number[];
|
|
4
|
+
/** Minimum outcomes required before temperature scaling is applied. */
|
|
5
|
+
export declare const MIN_OUTCOMES_FOR_TEMPERATURE = 10;
|
|
6
|
+
/** Small epsilon to keep log() finite when probabilities approach 0 or 1. */
|
|
7
|
+
export declare const EPSILON = 1e-9;
|
|
8
|
+
/**
|
|
9
|
+
* Apply temperature scaling to a probability `p`.
|
|
10
|
+
*
|
|
11
|
+
* Uses the standard logit re-scaling:
|
|
12
|
+
* `sigmoid(logit(p) / T)`. T=1 is the identity.
|
|
13
|
+
*
|
|
14
|
+
* @param p - Probability in `[0, 1]`.
|
|
15
|
+
* @param temperature - Temperature scalar (must be > 0).
|
|
16
|
+
* @returns Scaled probability in `[0, 1]`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function applyTemperature(p: number, temperature: number): number;
|
|
19
|
+
/**
|
|
20
|
+
* Compute negative log-likelihood for a candidate temperature.
|
|
21
|
+
*
|
|
22
|
+
* @param outcomes - Outcomes whose `predicted` is the raw confidence and
|
|
23
|
+
* `actual` is the observed 0/1 label.
|
|
24
|
+
* @param temperature - Temperature to evaluate.
|
|
25
|
+
* @returns Mean NLL across outcomes (lower is better). Returns `Infinity` if
|
|
26
|
+
* `outcomes` is empty.
|
|
27
|
+
*/
|
|
28
|
+
export declare function negativeLogLikelihood(outcomes: readonly VerificationOutcome[], temperature: number): number;
|
|
29
|
+
/**
|
|
30
|
+
* Grid-search the temperature minimizing NLL.
|
|
31
|
+
*
|
|
32
|
+
* Falls back to T=1.0 when there are fewer than {@link MIN_OUTCOMES_FOR_TEMPERATURE}
|
|
33
|
+
* outcomes available.
|
|
34
|
+
*
|
|
35
|
+
* @param outcomes - Outcomes to fit against.
|
|
36
|
+
* @returns Best temperature from {@link TEMPERATURE_GRID}.
|
|
37
|
+
*/
|
|
38
|
+
export declare function fitTemperature(outcomes: readonly VerificationOutcome[]): number;
|
|
39
|
+
//# sourceMappingURL=calibration-math.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calibration-math.d.ts","sourceRoot":"","sources":["../../../src/core/evaluator/calibration-math.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,iEAAiE;AACjE,eAAO,MAAM,gBAAgB,EAAE,SAAS,MAAM,EAAqC,CAAC;AAEpF,uEAAuE;AACvE,eAAO,MAAM,4BAA4B,KAAK,CAAC;AAE/C,6EAA6E;AAC7E,eAAO,MAAM,OAAO,OAAO,CAAC;AAE5B;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAKvE;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACpC,QAAQ,EAAE,SAAS,mBAAmB,EAAE,EACxC,WAAW,EAAE,MAAM,GACjB,MAAM,CASR;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,SAAS,mBAAmB,EAAE,GAAG,MAAM,CAY/E"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const TEMPERATURE_GRID = [
|
|
2
|
+
0.5,
|
|
3
|
+
0.75,
|
|
4
|
+
1.0,
|
|
5
|
+
1.25,
|
|
6
|
+
1.5,
|
|
7
|
+
2.0
|
|
8
|
+
];
|
|
9
|
+
const MIN_OUTCOMES_FOR_TEMPERATURE = 10;
|
|
10
|
+
const EPSILON = 1e-9;
|
|
11
|
+
function applyTemperature(p, temperature) {
|
|
12
|
+
const clamped = Math.min(1 - EPSILON, Math.max(EPSILON, p));
|
|
13
|
+
const logit = Math.log(clamped / (1 - clamped));
|
|
14
|
+
const scaled = logit / temperature;
|
|
15
|
+
return 1 / (1 + Math.exp(-scaled));
|
|
16
|
+
}
|
|
17
|
+
function negativeLogLikelihood(outcomes, temperature) {
|
|
18
|
+
if (0 === outcomes.length) return 1 / 0;
|
|
19
|
+
let total = 0;
|
|
20
|
+
for (const o of outcomes){
|
|
21
|
+
const p = applyTemperature(o.predicted, temperature);
|
|
22
|
+
const clamped = Math.min(1 - EPSILON, Math.max(EPSILON, p));
|
|
23
|
+
total += -(o.actual * Math.log(clamped) + (1 - o.actual) * Math.log(1 - clamped));
|
|
24
|
+
}
|
|
25
|
+
return total / outcomes.length;
|
|
26
|
+
}
|
|
27
|
+
function fitTemperature(outcomes) {
|
|
28
|
+
if (outcomes.length < MIN_OUTCOMES_FOR_TEMPERATURE) return 1.0;
|
|
29
|
+
let best = 1.0;
|
|
30
|
+
let bestLoss = 1 / 0;
|
|
31
|
+
for (const t of TEMPERATURE_GRID){
|
|
32
|
+
const loss = negativeLogLikelihood(outcomes, t);
|
|
33
|
+
if (loss < bestLoss) {
|
|
34
|
+
bestLoss = loss;
|
|
35
|
+
best = t;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return best;
|
|
39
|
+
}
|
|
40
|
+
export { EPSILON, MIN_OUTCOMES_FOR_TEMPERATURE, TEMPERATURE_GRID, applyTemperature, fitTemperature, negativeLogLikelihood };
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=calibration-math.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core/evaluator/calibration-math.js","sources":["../../../src/core/evaluator/calibration-math.ts"],"sourcesContent":["import type { VerificationOutcome } from '../../contracts/interfaces.js';\n\n/** Candidate temperatures evaluated during grid search refit. */\nexport const TEMPERATURE_GRID: readonly number[] = [0.5, 0.75, 1.0, 1.25, 1.5, 2.0];\n\n/** Minimum outcomes required before temperature scaling is applied. */\nexport const MIN_OUTCOMES_FOR_TEMPERATURE = 10;\n\n/** Small epsilon to keep log() finite when probabilities approach 0 or 1. */\nexport const EPSILON = 1e-9;\n\n/**\n * Apply temperature scaling to a probability `p`.\n *\n * Uses the standard logit re-scaling:\n * `sigmoid(logit(p) / T)`. T=1 is the identity.\n *\n * @param p - Probability in `[0, 1]`.\n * @param temperature - Temperature scalar (must be > 0).\n * @returns Scaled probability in `[0, 1]`.\n */\nexport function applyTemperature(p: number, temperature: number): number {\n\tconst clamped = Math.min(1 - EPSILON, Math.max(EPSILON, p));\n\tconst logit = Math.log(clamped / (1 - clamped));\n\tconst scaled = logit / temperature;\n\treturn 1 / (1 + Math.exp(-scaled));\n}\n\n/**\n * Compute negative log-likelihood for a candidate temperature.\n *\n * @param outcomes - Outcomes whose `predicted` is the raw confidence and\n * `actual` is the observed 0/1 label.\n * @param temperature - Temperature to evaluate.\n * @returns Mean NLL across outcomes (lower is better). Returns `Infinity` if\n * `outcomes` is empty.\n */\nexport function negativeLogLikelihood(\n\toutcomes: readonly VerificationOutcome[],\n\ttemperature: number,\n): number {\n\tif (outcomes.length === 0) return Number.POSITIVE_INFINITY;\n\tlet total = 0;\n\tfor (const o of outcomes) {\n\t\tconst p = applyTemperature(o.predicted, temperature);\n\t\tconst clamped = Math.min(1 - EPSILON, Math.max(EPSILON, p));\n\t\ttotal += -(o.actual * Math.log(clamped) + (1 - o.actual) * Math.log(1 - clamped));\n\t}\n\treturn total / outcomes.length;\n}\n\n/**\n * Grid-search the temperature minimizing NLL.\n *\n * Falls back to T=1.0 when there are fewer than {@link MIN_OUTCOMES_FOR_TEMPERATURE}\n * outcomes available.\n *\n * @param outcomes - Outcomes to fit against.\n * @returns Best temperature from {@link TEMPERATURE_GRID}.\n */\nexport function fitTemperature(outcomes: readonly VerificationOutcome[]): number {\n\tif (outcomes.length < MIN_OUTCOMES_FOR_TEMPERATURE) return 1.0;\n\tlet best = 1.0;\n\tlet bestLoss = Number.POSITIVE_INFINITY;\n\tfor (const t of TEMPERATURE_GRID) {\n\t\tconst loss = negativeLogLikelihood(outcomes, t);\n\t\tif (loss < bestLoss) {\n\t\t\tbestLoss = loss;\n\t\t\tbest = t;\n\t\t}\n\t}\n\treturn best;\n}\n"],"names":["TEMPERATURE_GRID","MIN_OUTCOMES_FOR_TEMPERATURE","EPSILON","applyTemperature","p","temperature","clamped","Math","logit","scaled","negativeLogLikelihood","outcomes","Number","total","o","fitTemperature","best","bestLoss","t","loss"],"mappings":"AAGO,MAAMA,mBAAsC;IAAC;IAAK;IAAM;IAAK;IAAM;IAAK;CAAI;AAG5E,MAAMC,+BAA+B;AAGrC,MAAMC,UAAU;AAYhB,SAASC,iBAAiBC,CAAS,EAAEC,WAAmB;IAC9D,MAAMC,UAAUC,KAAK,GAAG,CAAC,IAAIL,SAASK,KAAK,GAAG,CAACL,SAASE;IACxD,MAAMI,QAAQD,KAAK,GAAG,CAACD,UAAW,KAAIA,OAAM;IAC5C,MAAMG,SAASD,QAAQH;IACvB,OAAO,IAAK,KAAIE,KAAK,GAAG,CAAC,CAACE,OAAM;AACjC;AAWO,SAASC,sBACfC,QAAwC,EACxCN,WAAmB;IAEnB,IAAIM,AAAoB,MAApBA,SAAS,MAAM,EAAQ,OAAOC,KAAwB;IAC1D,IAAIC,QAAQ;IACZ,KAAK,MAAMC,KAAKH,SAAU;QACzB,MAAMP,IAAID,iBAAiBW,EAAE,SAAS,EAAET;QACxC,MAAMC,UAAUC,KAAK,GAAG,CAAC,IAAIL,SAASK,KAAK,GAAG,CAACL,SAASE;QACxDS,SAAS,CAAEC,CAAAA,EAAE,MAAM,GAAGP,KAAK,GAAG,CAACD,WAAY,KAAIQ,EAAE,MAAK,IAAKP,KAAK,GAAG,CAAC,IAAID,QAAO;IAChF;IACA,OAAOO,QAAQF,SAAS,MAAM;AAC/B;AAWO,SAASI,eAAeJ,QAAwC;IACtE,IAAIA,SAAS,MAAM,GAAGV,8BAA8B,OAAO;IAC3D,IAAIe,OAAO;IACX,IAAIC,WAAWL,KAAwB;IACvC,KAAK,MAAMM,KAAKlB,iBAAkB;QACjC,MAAMmB,OAAOT,sBAAsBC,UAAUO;QAC7C,IAAIC,OAAOF,UAAU;YACpBA,WAAWE;YACXH,OAAOE;QACR;IACD;IACA,OAAOF;AACR"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared internal helpers for evaluator submodules.
|
|
3
|
+
*
|
|
4
|
+
* Pure utility functions used by SignalComputer (and future evaluator
|
|
5
|
+
* components such as StatsComputer / PatternDetector). All helpers are
|
|
6
|
+
* stateless and have no side effects.
|
|
7
|
+
*
|
|
8
|
+
* @module core/evaluator/internals
|
|
9
|
+
*/
|
|
10
|
+
import type { ThoughtType } from '../reasoning.js';
|
|
11
|
+
import type { ThoughtData } from '../thought.js';
|
|
12
|
+
/** All valid thought types for distribution counting. */
|
|
13
|
+
export declare const ALL_THOUGHT_TYPES: ThoughtType[];
|
|
14
|
+
/**
|
|
15
|
+
* Count thoughts in `history` grouped by {@link ThoughtType}.
|
|
16
|
+
*
|
|
17
|
+
* Thoughts without an explicit `thought_type` are counted as `'regular'`.
|
|
18
|
+
*
|
|
19
|
+
* @param history - Thoughts to count
|
|
20
|
+
* @returns Record mapping each ThoughtType to its occurrence count
|
|
21
|
+
*/
|
|
22
|
+
export declare function _countByType(history: ThoughtData[]): Record<ThoughtType, number>;
|
|
23
|
+
/** Alias of {@link _countByType} without the underscore prefix. */
|
|
24
|
+
export declare const countByType: typeof _countByType;
|
|
25
|
+
/**
|
|
26
|
+
* Compute the longest contiguous chain depth (sequence of thoughts without branching).
|
|
27
|
+
*
|
|
28
|
+
* A new chain starts whenever a thought has `branch_from_thought` set.
|
|
29
|
+
*
|
|
30
|
+
* @param history - Thoughts in chronological order
|
|
31
|
+
* @returns Length of the longest non-branching chain (0 for empty history)
|
|
32
|
+
*/
|
|
33
|
+
export declare function _computeChainDepth(history: ThoughtData[]): number;
|
|
34
|
+
/** Alias of {@link _computeChainDepth} without the underscore prefix. */
|
|
35
|
+
export declare const computeChainDepth: typeof _computeChainDepth;
|
|
36
|
+
//# sourceMappingURL=internals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internals.d.ts","sourceRoot":"","sources":["../../../src/core/evaluator/internals.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,yDAAyD;AACzD,eAAO,MAAM,iBAAiB,EAAE,WAAW,EAY1C,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAchF;AAED,mEAAmE;AACnE,eAAO,MAAM,WAAW,qBAAe,CAAC;AAExC;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,WAAW,EAAE,GAAG,MAAM,CAgBjE;AAED,yEAAyE;AACzE,eAAO,MAAM,iBAAiB,2BAAqB,CAAC"}
|