@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 @@
|
|
|
1
|
+
{"version":3,"file":"core/ThoughtReferenceIndex.js","sources":["../../src/core/ThoughtReferenceIndex.ts"],"sourcesContent":["import type { SessionId, ThoughtId } from '../contracts/ids.js';\nimport type { ThoughtData } from './thought.js';\n\nexport type ThoughtReferenceResolution =\n\t| { readonly kind: 'missing' }\n\t| { readonly kind: 'unique'; readonly thoughtId: ThoughtId }\n\t| { readonly kind: 'ambiguous'; readonly thoughtIds: readonly ThoughtId[] };\n\nconst MISSING: ThoughtReferenceResolution = Object.freeze({ kind: 'missing' });\n\n/** Ref-counted stable-ID lookup for retained thoughts in each session. */\nexport class ThoughtReferenceIndex {\n\tprivate readonly _sessions = new Map<SessionId, Map<number, Map<ThoughtId, number>>>();\n\n\tpublic add(sessionId: SessionId, thought: ThoughtData): void {\n\t\tif (thought.id === undefined) return;\n\t\tlet session = this._sessions.get(sessionId);\n\t\tif (session === undefined) {\n\t\t\tsession = new Map();\n\t\t\tthis._sessions.set(sessionId, session);\n\t\t}\n\t\tthis._addToSession(session, thought);\n\t}\n\n\tpublic remove(sessionId: SessionId, thought: ThoughtData): void {\n\t\tif (thought.id === undefined) return;\n\t\tconst session = this._sessions.get(sessionId);\n\t\tconst bucket = session?.get(thought.thought_number);\n\t\tconst count = bucket?.get(thought.id);\n\t\tif (session === undefined || bucket === undefined || count === undefined) return;\n\t\tif (count > 1) {\n\t\t\tbucket.set(thought.id, count - 1);\n\t\t} else {\n\t\t\tbucket.delete(thought.id);\n\t\t}\n\t\tif (bucket.size === 0) session.delete(thought.thought_number);\n\t\tif (session.size === 0) this._sessions.delete(sessionId);\n\t}\n\n\tpublic resolve(sessionId: SessionId, thoughtNumber: number): ThoughtReferenceResolution {\n\t\tconst bucket = this._sessions.get(sessionId)?.get(thoughtNumber);\n\t\tif (bucket === undefined || bucket.size === 0) return MISSING;\n\t\tif (bucket.size === 1) {\n\t\t\tconst thoughtId = bucket.keys().next().value;\n\t\t\treturn thoughtId === undefined ? MISSING : { kind: 'unique', thoughtId };\n\t\t}\n\t\tconst thoughtIds = Object.freeze(Array.from(bucket.keys()).sort());\n\t\treturn Object.freeze({ kind: 'ambiguous', thoughtIds });\n\t}\n\n\tpublic replaceSession(sessionId: SessionId, thoughts: Iterable<ThoughtData>): void {\n\t\tconst replacement = new Map<number, Map<ThoughtId, number>>();\n\t\tfor (const thought of thoughts) this._addToSession(replacement, thought);\n\t\tif (replacement.size === 0) {\n\t\t\tthis._sessions.delete(sessionId);\n\t\t} else {\n\t\t\tthis._sessions.set(sessionId, replacement);\n\t\t}\n\t}\n\n\tpublic clearSession(sessionId: SessionId): void {\n\t\tthis._sessions.delete(sessionId);\n\t}\n\n\tpublic clearAll(): void {\n\t\tthis._sessions.clear();\n\t}\n\n\tprivate _addToSession(session: Map<number, Map<ThoughtId, number>>, thought: ThoughtData): void {\n\t\tif (thought.id === undefined) return;\n\t\tlet bucket = session.get(thought.thought_number);\n\t\tif (bucket === undefined) {\n\t\t\tbucket = new Map();\n\t\t\tsession.set(thought.thought_number, bucket);\n\t\t}\n\t\tbucket.set(thought.id, (bucket.get(thought.id) ?? 0) + 1);\n\t}\n}\n"],"names":["MISSING","Object","ThoughtReferenceIndex","Map","sessionId","thought","undefined","session","bucket","count","thoughtNumber","thoughtId","thoughtIds","Array","thoughts","replacement"],"mappings":"AAQA,MAAMA,UAAsCC,OAAO,MAAM,CAAC;IAAE,MAAM;AAAU;AAGrE,MAAMC;IACK,YAAY,IAAIC,MAAsD;IAEhF,IAAIC,SAAoB,EAAEC,OAAoB,EAAQ;QAC5D,IAAIA,AAAeC,WAAfD,QAAQ,EAAE,EAAgB;QAC9B,IAAIE,UAAU,IAAI,CAAC,SAAS,CAAC,GAAG,CAACH;QACjC,IAAIG,AAAYD,WAAZC,SAAuB;YAC1BA,UAAU,IAAIJ;YACd,IAAI,CAAC,SAAS,CAAC,GAAG,CAACC,WAAWG;QAC/B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AAIZ;QACxB,KAAK,MAAME,WAAWS,SAAU,IAAI,CAAC,aAAa,CAACC,aAAaV;QAChE,IAAIU,AAAqB,MAArBA,YAAY,IAAI,EACnB,IAAI,CAAC,SAAS,CAAC,MAAM,CAACX;aAEtB,IAAI,CAAC,SAAS,CAAC,GAAG,CAACA,WAAWW;IAEhC;IAEO,aAAaX,SAAoB,EAAQ;QAC/C,IAAI,CAAC,SAAS,CAAC,MAAM,CAACA;IACvB;IAEO,WAAiB;QACvB,IAAI,CAAC,SAAS,CAAC,KAAK;IACrB;IAEQ,cAAcG,OAA4C,EAAEF,OAAoB,EAAQ;QAC/F,IAAIA,AAAeC,WAAfD,QAAQ,EAAE,EAAgB;QAC9B,IAAIG,SAASD,QAAQ,GAAG,CAACF,QAAQ,cAAc;QAC/C,IAAIG,AAAWF,WAAXE,QAAsB;YACzBA,SAAS,IAAIL;YACbI,QAAQ,GAAG,CAACF,QAAQ,cAAc,EAAEG;QACrC;QACAA,OAAO,GAAG,CAACH,QAAQ,EAAE,EAAGG,AAAAA,CAAAA,OAAO,GAAG,CAACH,QAAQ,EAAE,KAAK,KAAK;IACxD;AACD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SessionId } from '../contracts/ids.js';
|
|
2
|
+
import type { IOutcomeRecorder, VerificationOutcome } from '../contracts/interfaces.js';
|
|
3
|
+
import type { HistorySessionSnapshot, ResolvedThoughtReferences } from './IHistoryManager.js';
|
|
4
|
+
import type { ThoughtData } from './thought.js';
|
|
5
|
+
interface VerificationOutcomeAdmissionContext {
|
|
6
|
+
readonly input: ThoughtData;
|
|
7
|
+
readonly snapshot: HistorySessionSnapshot;
|
|
8
|
+
readonly resolvedReferences: ResolvedThoughtReferences;
|
|
9
|
+
readonly sessionId: SessionId;
|
|
10
|
+
readonly recorder?: IOutcomeRecorder;
|
|
11
|
+
}
|
|
12
|
+
/** Builds one immutable calibration sample from the retained pre-admission target. */
|
|
13
|
+
export declare function prepareVerificationOutcome(context: VerificationOutcomeAdmissionContext): Omit<VerificationOutcome, 'recordedAt'> | undefined;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=VerificationOutcomeAdmission.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VerificationOutcomeAdmission.d.ts","sourceRoot":"","sources":["../../src/core/VerificationOutcomeAdmission.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAExF,OAAO,KAAK,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAC9F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,UAAU,mCAAmC;IAC5C,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,sBAAsB,CAAC;IAC1C,QAAQ,CAAC,kBAAkB,EAAE,yBAAyB,CAAC;IACvD,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,QAAQ,CAAC,EAAE,gBAAgB,CAAC;CACrC;AAED,sFAAsF;AACtF,wBAAgB,0BAA0B,CACzC,OAAO,EAAE,mCAAmC,GAC1C,IAAI,CAAC,mBAAmB,EAAE,YAAY,CAAC,GAAG,SAAS,CA6BrD"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ValidationError } from "../errors.js";
|
|
2
|
+
function prepareVerificationOutcome(context) {
|
|
3
|
+
const { input, resolvedReferences, sessionId, snapshot, recorder } = context;
|
|
4
|
+
if ('verification' !== input.thought_type || void 0 === input.verification_result) return;
|
|
5
|
+
const thoughtId = resolvedReferences.verificationTargetThoughtId;
|
|
6
|
+
const thoughtNumber = input.verification_target;
|
|
7
|
+
if (void 0 === thoughtId || void 0 === thoughtNumber) throw new ValidationError('verification_result', 'requires a retained verification_target');
|
|
8
|
+
const target = findTarget(snapshot, thoughtId, thoughtNumber);
|
|
9
|
+
if (void 0 === target) throw new ValidationError('verification_result', 'verification_target is no longer retained');
|
|
10
|
+
if (true === target.retracted) throw new ValidationError('verification_result', 'verification_target must not be retracted');
|
|
11
|
+
if (void 0 === target.confidence) throw new ValidationError('verification_result', 'verification_target must have confidence');
|
|
12
|
+
recorder?.assertCanRecord(sessionId, thoughtId);
|
|
13
|
+
return Object.freeze({
|
|
14
|
+
thoughtId,
|
|
15
|
+
thoughtNumber: target.thought_number,
|
|
16
|
+
sessionId,
|
|
17
|
+
predicted: target.confidence,
|
|
18
|
+
actual: input.verification_result,
|
|
19
|
+
type: target.thought_type ?? 'regular'
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function findTarget(snapshot, thoughtId, thoughtNumber) {
|
|
23
|
+
for (const thought of snapshot.history)if (thought.id === thoughtId && thought.thought_number === thoughtNumber) return thought;
|
|
24
|
+
for (const branch of Object.values(snapshot.branches))for (const thought of branch)if (thought.id === thoughtId && thought.thought_number === thoughtNumber) return thought;
|
|
25
|
+
}
|
|
26
|
+
export { prepareVerificationOutcome };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=VerificationOutcomeAdmission.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core/VerificationOutcomeAdmission.js","sources":["../../src/core/VerificationOutcomeAdmission.ts"],"sourcesContent":["import type { SessionId } from '../contracts/ids.js';\nimport type { IOutcomeRecorder, VerificationOutcome } from '../contracts/interfaces.js';\nimport { ValidationError } from '../errors.js';\nimport type { HistorySessionSnapshot, ResolvedThoughtReferences } from './IHistoryManager.js';\nimport type { ThoughtData } from './thought.js';\n\ninterface VerificationOutcomeAdmissionContext {\n\treadonly input: ThoughtData;\n\treadonly snapshot: HistorySessionSnapshot;\n\treadonly resolvedReferences: ResolvedThoughtReferences;\n\treadonly sessionId: SessionId;\n\treadonly recorder?: IOutcomeRecorder;\n}\n\n/** Builds one immutable calibration sample from the retained pre-admission target. */\nexport function prepareVerificationOutcome(\n\tcontext: VerificationOutcomeAdmissionContext\n): Omit<VerificationOutcome, 'recordedAt'> | undefined {\n\tconst { input, resolvedReferences, sessionId, snapshot, recorder } = context;\n\tif (input.thought_type !== 'verification' || input.verification_result === undefined) {\n\t\treturn undefined;\n\t}\n\tconst thoughtId = resolvedReferences.verificationTargetThoughtId;\n\tconst thoughtNumber = input.verification_target;\n\tif (thoughtId === undefined || thoughtNumber === undefined) {\n\t\tthrow new ValidationError('verification_result', 'requires a retained verification_target');\n\t}\n\tconst target = findTarget(snapshot, thoughtId, thoughtNumber);\n\tif (target === undefined) {\n\t\tthrow new ValidationError('verification_result', 'verification_target is no longer retained');\n\t}\n\tif (target.retracted === true) {\n\t\tthrow new ValidationError('verification_result', 'verification_target must not be retracted');\n\t}\n\tif (target.confidence === undefined) {\n\t\tthrow new ValidationError('verification_result', 'verification_target must have confidence');\n\t}\n\trecorder?.assertCanRecord(sessionId, thoughtId);\n\treturn Object.freeze({\n\t\tthoughtId,\n\t\tthoughtNumber: target.thought_number,\n\t\tsessionId,\n\t\tpredicted: target.confidence,\n\t\tactual: input.verification_result,\n\t\ttype: target.thought_type ?? 'regular',\n\t});\n}\n\nfunction findTarget(\n\tsnapshot: HistorySessionSnapshot,\n\tthoughtId: VerificationOutcome['thoughtId'],\n\tthoughtNumber: number\n): ThoughtData | undefined {\n\tfor (const thought of snapshot.history) {\n\t\tif (thought.id === thoughtId && thought.thought_number === thoughtNumber) return thought;\n\t}\n\tfor (const branch of Object.values(snapshot.branches)) {\n\t\tfor (const thought of branch) {\n\t\t\tif (thought.id === thoughtId && thought.thought_number === thoughtNumber) return thought;\n\t\t}\n\t}\n\treturn undefined;\n}\n"],"names":["prepareVerificationOutcome","context","input","resolvedReferences","sessionId","snapshot","recorder","undefined","thoughtId","thoughtNumber","ValidationError","target","findTarget","Object","thought","branch"],"mappings":";AAeO,SAASA,2BACfC,OAA4C;IAE5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
|
+
* Compresses a terminated branch (or any subtree rooted at a thought) into a
|
|
5
|
+
* single {@link Summary} record. Pure offline computation: no LLM, no I/O.
|
|
6
|
+
*
|
|
7
|
+
* Topic extraction is unigram frequency with stopword filtering; aggregate
|
|
8
|
+
* confidence is the arithmetic mean of per-thought calibrated (or raw)
|
|
9
|
+
* confidence values. The covered set is identified via
|
|
10
|
+
* {@link GraphView.descendants}. Compression is **additive**: original
|
|
11
|
+
* thoughts are never mutated or deleted.
|
|
12
|
+
*
|
|
13
|
+
* @module core/compression/CompressionService
|
|
14
|
+
*/
|
|
15
|
+
import type { ISummaryStore, Summary } from '../../contracts/summary.js';
|
|
16
|
+
import type { IEdgeStore } from '../../contracts/interfaces.js';
|
|
17
|
+
import type { Logger } from '../../logger/StructuredLogger.js';
|
|
18
|
+
import type { IHistoryManager } from '../IHistoryManager.js';
|
|
19
|
+
import type { BranchId, SessionId, ThoughtId } from '../../contracts/ids.js';
|
|
20
|
+
/** Dependencies required by {@link CompressionService}. */
|
|
21
|
+
export interface CompressionDeps {
|
|
22
|
+
readonly historyManager: IHistoryManager;
|
|
23
|
+
readonly edgeStore: IEdgeStore;
|
|
24
|
+
readonly summaryStore: ISummaryStore;
|
|
25
|
+
readonly onSummaryCreated?: (summary: Summary) => void;
|
|
26
|
+
readonly logger?: Logger;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Deterministic, offline compression of branch subtrees into {@link Summary}.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const svc = new CompressionService({ historyManager, edgeStore, summaryStore });
|
|
34
|
+
* const summary = svc.compressBranch('s1', 'alt-1', 'thought-root');
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare class CompressionService {
|
|
38
|
+
private readonly _deps;
|
|
39
|
+
private readonly _graph;
|
|
40
|
+
constructor(deps: CompressionDeps);
|
|
41
|
+
/**
|
|
42
|
+
* Compress the subtree rooted at `rootThoughtId` into a {@link Summary}.
|
|
43
|
+
*
|
|
44
|
+
* Idempotency: if a summary for the same `(branchId, rootThoughtId)` already
|
|
45
|
+
* exists in the store, the existing summary is returned unchanged — same
|
|
46
|
+
* inputs always yield the same Summary identity.
|
|
47
|
+
*/
|
|
48
|
+
compressBranch(sessionId: SessionId, branchId: BranchId, rootThoughtId: ThoughtId): Summary;
|
|
49
|
+
/** Look up an existing summary on this branch with a matching root. */
|
|
50
|
+
private _findExistingForRoot;
|
|
51
|
+
/** Collect the root and all of its descendants (chronological BFS). */
|
|
52
|
+
private _collectCovered;
|
|
53
|
+
/**
|
|
54
|
+
* Resolve covered ids to {@link ThoughtData}, dropping any not found in
|
|
55
|
+
* the history (defensive — graph may reference evicted thoughts).
|
|
56
|
+
*/
|
|
57
|
+
private _lookupThoughts;
|
|
58
|
+
/**
|
|
59
|
+
* Mean of (`calibrated_confidence` ?? `confidence` ?? 0) across covered.
|
|
60
|
+
* Returns 0 when no thoughts are covered.
|
|
61
|
+
*/
|
|
62
|
+
private _meanConfidence;
|
|
63
|
+
/**
|
|
64
|
+
* Inclusive `[min, max]` of `thought_number` across covered thoughts.
|
|
65
|
+
* Returns `[0, 0]` when no thoughts are covered.
|
|
66
|
+
*/
|
|
67
|
+
private _coveredRange;
|
|
68
|
+
/**
|
|
69
|
+
* Extract top-3 unigrams by frequency from concatenated thought text.
|
|
70
|
+
* Ties broken by first-occurrence order (stable).
|
|
71
|
+
*/
|
|
72
|
+
private _extractTopics;
|
|
73
|
+
/** Lowercase + strip non-alphanumerics; reject if too short or a stopword. */
|
|
74
|
+
private _normalizeToken;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=CompressionService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CompressionService.d.ts","sourceRoot":"","sources":["../../../src/core/compression/CompressionService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE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} from "../ids.js";
|
|
3
|
+
const STOPWORDS = new Set([
|
|
4
|
+
'the',
|
|
5
|
+
'this',
|
|
6
|
+
'that',
|
|
7
|
+
'then',
|
|
8
|
+
'than',
|
|
9
|
+
'with',
|
|
10
|
+
'from',
|
|
11
|
+
'have',
|
|
12
|
+
'will',
|
|
13
|
+
'been',
|
|
14
|
+
'they',
|
|
15
|
+
'them',
|
|
16
|
+
'their',
|
|
17
|
+
'there',
|
|
18
|
+
'about',
|
|
19
|
+
'would',
|
|
20
|
+
'could',
|
|
21
|
+
'should',
|
|
22
|
+
'which',
|
|
23
|
+
'where',
|
|
24
|
+
'when',
|
|
25
|
+
'what',
|
|
26
|
+
'some',
|
|
27
|
+
'into',
|
|
28
|
+
'also',
|
|
29
|
+
'just',
|
|
30
|
+
'like',
|
|
31
|
+
'over',
|
|
32
|
+
'such',
|
|
33
|
+
'after',
|
|
34
|
+
'only',
|
|
35
|
+
'most',
|
|
36
|
+
'very',
|
|
37
|
+
'much',
|
|
38
|
+
'well',
|
|
39
|
+
'even',
|
|
40
|
+
'still',
|
|
41
|
+
'since',
|
|
42
|
+
'being',
|
|
43
|
+
'doing',
|
|
44
|
+
'going',
|
|
45
|
+
'using'
|
|
46
|
+
]);
|
|
47
|
+
const MIN_TOKEN_LENGTH = 4;
|
|
48
|
+
const TOP_TOPICS = 3;
|
|
49
|
+
class CompressionService {
|
|
50
|
+
_deps;
|
|
51
|
+
_graph;
|
|
52
|
+
constructor(deps){
|
|
53
|
+
this._deps = deps;
|
|
54
|
+
this._graph = new GraphView(deps.edgeStore);
|
|
55
|
+
}
|
|
56
|
+
compressBranch(sessionId, branchId, rootThoughtId) {
|
|
57
|
+
const existing = this._findExistingForRoot(sessionId, branchId, rootThoughtId);
|
|
58
|
+
if (existing) return existing;
|
|
59
|
+
const coveredIds = this._collectCovered(sessionId, rootThoughtId);
|
|
60
|
+
const thoughts = this._lookupThoughts(sessionId, coveredIds);
|
|
61
|
+
const summary = {
|
|
62
|
+
id: generateUlid(),
|
|
63
|
+
sessionId,
|
|
64
|
+
branchId,
|
|
65
|
+
rootThoughtId,
|
|
66
|
+
coveredIds,
|
|
67
|
+
coveredRange: this._coveredRange(thoughts),
|
|
68
|
+
topics: this._extractTopics(thoughts),
|
|
69
|
+
aggregateConfidence: this._meanConfidence(thoughts),
|
|
70
|
+
createdAt: Date.now()
|
|
71
|
+
};
|
|
72
|
+
this._deps.summaryStore.add(summary);
|
|
73
|
+
this._deps.onSummaryCreated?.(summary);
|
|
74
|
+
this._deps.logger?.debug('compression.branch.compressed', {
|
|
75
|
+
sessionId,
|
|
76
|
+
branchId,
|
|
77
|
+
rootThoughtId,
|
|
78
|
+
covered: coveredIds.length,
|
|
79
|
+
topics: summary.topics
|
|
80
|
+
});
|
|
81
|
+
return summary;
|
|
82
|
+
}
|
|
83
|
+
_findExistingForRoot(sessionId, branchId, rootThoughtId) {
|
|
84
|
+
for (const s of this._deps.summaryStore.forBranch(sessionId, branchId))if (s.rootThoughtId === rootThoughtId) return s;
|
|
85
|
+
}
|
|
86
|
+
_collectCovered(sessionId, rootThoughtId) {
|
|
87
|
+
const descendants = this._graph.descendants(sessionId, rootThoughtId);
|
|
88
|
+
return [
|
|
89
|
+
rootThoughtId,
|
|
90
|
+
...descendants
|
|
91
|
+
];
|
|
92
|
+
}
|
|
93
|
+
_lookupThoughts(sessionId, coveredIds) {
|
|
94
|
+
const history = this._deps.historyManager.getHistory(sessionId);
|
|
95
|
+
const byId = new Map();
|
|
96
|
+
for (const t of history)if (void 0 !== t.id) byId.set(t.id, t);
|
|
97
|
+
const out = [];
|
|
98
|
+
for (const id of coveredIds){
|
|
99
|
+
const t = byId.get(id);
|
|
100
|
+
if (t) out.push(t);
|
|
101
|
+
}
|
|
102
|
+
return out;
|
|
103
|
+
}
|
|
104
|
+
_meanConfidence(thoughts) {
|
|
105
|
+
if (0 === thoughts.length) return 0;
|
|
106
|
+
let sum = 0;
|
|
107
|
+
for (const t of thoughts){
|
|
108
|
+
const withSignals = t;
|
|
109
|
+
const calibrated = withSignals.confidence_signals?.calibrated_confidence;
|
|
110
|
+
sum += calibrated ?? t.confidence ?? 0;
|
|
111
|
+
}
|
|
112
|
+
return sum / thoughts.length;
|
|
113
|
+
}
|
|
114
|
+
_coveredRange(thoughts) {
|
|
115
|
+
if (0 === thoughts.length) return [
|
|
116
|
+
0,
|
|
117
|
+
0
|
|
118
|
+
];
|
|
119
|
+
let min = 1 / 0;
|
|
120
|
+
let max = -1 / 0;
|
|
121
|
+
for (const t of thoughts){
|
|
122
|
+
const n = t.thought_number;
|
|
123
|
+
if (n < min) min = n;
|
|
124
|
+
if (n > max) max = n;
|
|
125
|
+
}
|
|
126
|
+
return [
|
|
127
|
+
min,
|
|
128
|
+
max
|
|
129
|
+
];
|
|
130
|
+
}
|
|
131
|
+
_extractTopics(thoughts) {
|
|
132
|
+
if (0 === thoughts.length) return [];
|
|
133
|
+
const counts = new Map();
|
|
134
|
+
const order = new Map();
|
|
135
|
+
let position = 0;
|
|
136
|
+
for (const t of thoughts)for (const raw of (t.thought ?? '').split(/\s+/)){
|
|
137
|
+
const token = this._normalizeToken(raw);
|
|
138
|
+
if (null !== token) {
|
|
139
|
+
if (!counts.has(token)) order.set(token, position++);
|
|
140
|
+
counts.set(token, (counts.get(token) ?? 0) + 1);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (0 === counts.size) return [];
|
|
144
|
+
const entries = Array.from(counts.entries());
|
|
145
|
+
entries.sort((a, b)=>{
|
|
146
|
+
if (b[1] !== a[1]) return b[1] - a[1];
|
|
147
|
+
return (order.get(a[0]) ?? 0) - (order.get(b[0]) ?? 0);
|
|
148
|
+
});
|
|
149
|
+
return entries.slice(0, TOP_TOPICS).map(([word])=>word);
|
|
150
|
+
}
|
|
151
|
+
_normalizeToken(raw) {
|
|
152
|
+
const cleaned = raw.toLowerCase().replace(/[^a-z0-9]+/g, '');
|
|
153
|
+
if (cleaned.length < MIN_TOKEN_LENGTH) return null;
|
|
154
|
+
if (STOPWORDS.has(cleaned)) return null;
|
|
155
|
+
return cleaned;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
export { CompressionService };
|
|
159
|
+
|
|
160
|
+
//# sourceMappingURL=CompressionService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core/compression/CompressionService.js","sources":["../../../src/core/compression/CompressionService.ts"],"sourcesContent":["/**\n * CompressionService — deterministic branch summarization.\n *\n * Compresses a terminated branch (or any subtree rooted at a thought) into a\n * single {@link Summary} record. Pure offline computation: no LLM, no I/O.\n *\n * Topic extraction is unigram frequency with stopword filtering; aggregate\n * confidence is the arithmetic mean of per-thought calibrated (or raw)\n * confidence values. The covered set is identified via\n * {@link GraphView.descendants}. Compression is **additive**: original\n * thoughts are never mutated or deleted.\n *\n * @module core/compression/CompressionService\n */\n\nimport type { ISummaryStore, Summary } from '../../contracts/summary.js';\nimport type { IEdgeStore } from '../../contracts/interfaces.js';\nimport type { Logger } from '../../logger/StructuredLogger.js';\nimport type { IHistoryManager } from '../IHistoryManager.js';\nimport type { ThoughtData } from '../thought.js';\nimport type { ConfidenceSignals } from '../reasoning.js';\nimport { GraphView } from '../graph/GraphView.js';\nimport { generateUlid } from '../ids.js';\nimport type { BranchId, SessionId, ThoughtId } from '../../contracts/ids.js';\n\n/** Stopwords excluded from topic extraction (lowercase). */\nconst STOPWORDS: ReadonlySet<string> = new Set([\n\t'the', 'this', 'that', 'then', 'than', 'with', 'from', 'have', 'will', 'been',\n\t'they', 'them', 'their', 'there', 'about', 'would', 'could', 'should', 'which',\n\t'where', 'when', 'what', 'some', 'into', 'also', 'just', 'like', 'over', 'such',\n\t'after', 'only', 'most', 'very', 'much', 'well', 'even', 'still', 'since',\n\t'being', 'doing', 'going', 'using',\n]);\n\nconst MIN_TOKEN_LENGTH = 4;\nconst TOP_TOPICS = 3;\n\n/** Local view of {@link ThoughtData} that exposes optional confidence signals. */\ntype ThoughtWithSignals = ThoughtData & { readonly confidence_signals?: ConfidenceSignals };\n\n/** Dependencies required by {@link CompressionService}. */\nexport interface CompressionDeps {\n\treadonly historyManager: IHistoryManager;\n\treadonly edgeStore: IEdgeStore;\n\treadonly summaryStore: ISummaryStore;\n\treadonly onSummaryCreated?: (summary: Summary) => void;\n\treadonly logger?: Logger;\n}\n\n/**\n * Deterministic, offline compression of branch subtrees into {@link Summary}.\n *\n * @example\n * ```typescript\n * const svc = new CompressionService({ historyManager, edgeStore, summaryStore });\n * const summary = svc.compressBranch('s1', 'alt-1', 'thought-root');\n * ```\n */\nexport class CompressionService {\n\tprivate readonly _deps: CompressionDeps;\n\tprivate readonly _graph: GraphView;\n\n\tconstructor(deps: CompressionDeps) {\n\t\tthis._deps = deps;\n\t\tthis._graph = new GraphView(deps.edgeStore);\n\t}\n\n\t/**\n\t * Compress the subtree rooted at `rootThoughtId` into a {@link Summary}.\n\t *\n\t * Idempotency: if a summary for the same `(branchId, rootThoughtId)` already\n\t * exists in the store, the existing summary is returned unchanged — same\n\t * inputs always yield the same Summary identity.\n\t */\n\tcompressBranch(sessionId: SessionId, branchId: BranchId, rootThoughtId: ThoughtId): Summary {\n\t\tconst existing = this._findExistingForRoot(sessionId, branchId, rootThoughtId);\n\t\tif (existing) return existing;\n\n\t\tconst coveredIds = this._collectCovered(sessionId, rootThoughtId);\n\t\tconst thoughts = this._lookupThoughts(sessionId, coveredIds);\n\t\tconst summary: Summary = {\n\t\t\tid: generateUlid(),\n\t\t\tsessionId,\n\t\t\tbranchId,\n\t\t\trootThoughtId,\n\t\t\tcoveredIds,\n\t\t\tcoveredRange: this._coveredRange(thoughts),\n\t\t\ttopics: this._extractTopics(thoughts),\n\t\t\taggregateConfidence: this._meanConfidence(thoughts),\n\t\t\tcreatedAt: Date.now(),\n\t\t};\n\n\t\tthis._deps.summaryStore.add(summary);\n\t\tthis._deps.onSummaryCreated?.(summary);\n\t\tthis._deps.logger?.debug('compression.branch.compressed', {\n\t\t\tsessionId,\n\t\t\tbranchId,\n\t\t\trootThoughtId,\n\t\t\tcovered: coveredIds.length,\n\t\t\ttopics: summary.topics,\n\t\t});\n\t\treturn summary;\n\t}\n\n\t/** Look up an existing summary on this branch with a matching root. */\n\tprivate _findExistingForRoot(\n\t\tsessionId: SessionId,\n\t\tbranchId: BranchId,\n\t\trootThoughtId: ThoughtId\n\t): Summary | undefined {\n\t\tfor (const s of this._deps.summaryStore.forBranch(sessionId, branchId)) {\n\t\t\tif (s.rootThoughtId === rootThoughtId) return s;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/** Collect the root and all of its descendants (chronological BFS). */\n\tprivate _collectCovered(sessionId: SessionId, rootThoughtId: ThoughtId): readonly ThoughtId[] {\n\t\tconst descendants = this._graph.descendants(sessionId, rootThoughtId);\n\t\treturn [rootThoughtId, ...descendants];\n\t}\n\n\t/**\n\t * Resolve covered ids to {@link ThoughtData}, dropping any not found in\n\t * the history (defensive — graph may reference evicted thoughts).\n\t */\n\tprivate _lookupThoughts(sessionId: SessionId, coveredIds: readonly ThoughtId[]): ThoughtData[] {\n\t\tconst history = this._deps.historyManager.getHistory(sessionId);\n\t\tconst byId = new Map<string, ThoughtData>();\n\t\tfor (const t of history) {\n\t\t\tif (t.id !== undefined) byId.set(t.id, t);\n\t\t}\n\t\tconst out: ThoughtData[] = [];\n\t\tfor (const id of coveredIds) {\n\t\t\tconst t = byId.get(id);\n\t\t\tif (t) out.push(t);\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t * Mean of (`calibrated_confidence` ?? `confidence` ?? 0) across covered.\n\t * Returns 0 when no thoughts are covered.\n\t */\n\tprivate _meanConfidence(thoughts: readonly ThoughtData[]): number {\n\t\tif (thoughts.length === 0) return 0;\n\t\tlet sum = 0;\n\t\tfor (const t of thoughts) {\n\t\t\tconst withSignals = t as ThoughtWithSignals;\n\t\t\tconst calibrated = withSignals.confidence_signals?.calibrated_confidence;\n\t\t\tsum += calibrated ?? t.confidence ?? 0;\n\t\t}\n\t\treturn sum / thoughts.length;\n\t}\n\n\t/**\n\t * Inclusive `[min, max]` of `thought_number` across covered thoughts.\n\t * Returns `[0, 0]` when no thoughts are covered.\n\t */\n\tprivate _coveredRange(thoughts: readonly ThoughtData[]): readonly [number, number] {\n\t\tif (thoughts.length === 0) return [0, 0];\n\t\tlet min = Number.POSITIVE_INFINITY;\n\t\tlet max = Number.NEGATIVE_INFINITY;\n\t\tfor (const t of thoughts) {\n\t\t\tconst n = t.thought_number;\n\t\t\tif (n < min) min = n;\n\t\t\tif (n > max) max = n;\n\t\t}\n\t\treturn [min, max];\n\t}\n\n\t/**\n\t * Extract top-3 unigrams by frequency from concatenated thought text.\n\t * Ties broken by first-occurrence order (stable).\n\t */\n\tprivate _extractTopics(thoughts: readonly ThoughtData[]): readonly string[] {\n\t\tif (thoughts.length === 0) return [];\n\t\tconst counts = new Map<string, number>();\n\t\tconst order = new Map<string, number>();\n\t\tlet position = 0;\n\t\tfor (const t of thoughts) {\n\t\t\tfor (const raw of (t.thought ?? '').split(/\\s+/)) {\n\t\t\t\tconst token = this._normalizeToken(raw);\n\t\t\t\tif (token === null) continue;\n\t\t\t\tif (!counts.has(token)) order.set(token, position++);\n\t\t\t\tcounts.set(token, (counts.get(token) ?? 0) + 1);\n\t\t\t}\n\t\t}\n\t\tif (counts.size === 0) return [];\n\t\tconst entries = Array.from(counts.entries());\n\t\tentries.sort((a, b) => {\n\t\t\tif (b[1] !== a[1]) return b[1] - a[1];\n\t\t\treturn (order.get(a[0]) ?? 0) - (order.get(b[0]) ?? 0);\n\t\t});\n\t\treturn entries.slice(0, TOP_TOPICS).map(([word]) => word);\n\t}\n\n\t/** Lowercase + strip non-alphanumerics; reject if too short or a stopword. */\n\tprivate _normalizeToken(raw: string): string | null {\n\t\tconst cleaned = raw.toLowerCase().replace(/[^a-z0-9]+/g, '');\n\t\tif (cleaned.length < MIN_TOKEN_LENGTH) return null;\n\t\tif (STOPWORDS.has(cleaned)) return null;\n\t\treturn cleaned;\n\t}\n}\n"],"names":["STOPWORDS","Set","MIN_TOKEN_LENGTH","TOP_TOPICS","CompressionService","deps","GraphView","sessionId","branchId","rootThoughtId","existing","coveredIds","thoughts","summary","generateUlid","Date","s","descendants","history","byId","Map","t","undefined","out","id","sum","withSignals","calibrated","min","Number","max","n","counts","order","position","raw","token","entries","Array","a","b","word","cleaned"],"mappings":";;AA0BA,MAAMA,YAAiC,IAAIC,IAAI;IAC9C;IAAO;IAAQ;IAAQ;IAAQ;IAAQ;IAAQ;IAAQ;IAAQ;IAAQ;IACvE;IAAQ;IAAQ;IAAS;IAAS;IAAS;IAAS;IAAS;IAAU;IACvE;IAAS;IAAQ;IAAQ;IAAQ;IAAQ;IAAQ;IAAQ;IAAQ;IAAQ;IACzE;IAAS;IAAQ;IAAQ;IAAQ;IAAQ;IAAQ;IAAQ;IAAS;IAClE;IAAS;IAAS;IAAS;CAC3B;AAED,MAAMC,mBAAmB;AACzB,MAAMC,aAAa;AAuBZ,MAAMC;IACK,MAAuB;IACvB,OAAkB;IAEnC,YAAYC,IAAqB,CAAE;QAClC,IAAI,CAAC,KAAK,GAAGA;QACb,IAAI,CAAC,MAAM,GAAG,IAAIC,UAAUD,KAAK,SAAS;IAC3C;IASA,eAAeE,SAAoB,EAAEC,QAAkB,EAAEC,aAAwB,EAAW;QAC3F,MAAMC,WAAW,IAAI,CAAC,oBAAoB,CAACH,WAAWC,UAAUC;QAChE,IAAIC,UAAU,OAAOA;QAErB,MAAMC,aAAa,IAAI,CAAC,eAAe,CAACJ,WAAWE;QACnD,MAAMG,WAAW,IAAI,CAAC,eAAe,CAACL,WAAWI;QACjD,MAAME,UAAmB;YACxB,IAAIC;YACJP;YACAC;YACAC;YACAE;YACA,cAAc,IAAI,CAAC,aAAa,CAACC;YACjC,QAAQ,IAAI,CAAC,cAAc,CAACA;YAC5B,qBAAqB,IAAI,CAAC,eAAe,CAACA;YAC1C,WAAWG,KAAK,GAAG;QACpB;QAEA,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC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;QACrD;QACA,OAAOH,QAAQ,KAAK,CAAC,GAAGlC,YAAY,GAAG,CAAC,CAAC,CAACsC,KAAK,GAAKA;IACrD;IAGQ,gBAAgBN,GAAW,EAAiB;QACnD,MAAMO,UAAUP,IAAI,WAAW,GAAG,OAAO,CAAC,eAAe;QACzD,IAAIO,QAAQ,MAAM,GAAGxC,kBAAkB,OAAO;QAC9C,IAAIF,UAAU,GAAG,CAAC0C,UAAU,OAAO;QACnC,OAAOA;IACR;AACD"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DehydrationPolicy — sliding-window history compaction.
|
|
3
|
+
*
|
|
4
|
+
* Replaces older thoughts (the "cold" prefix beyond the most recent K) with
|
|
5
|
+
* lightweight {@link SummaryRef} placeholders that point to existing
|
|
6
|
+
* {@link Summary} records in an {@link ISummaryStore}. Recent thoughts (the
|
|
7
|
+
* "hot" suffix of length K) are preserved verbatim.
|
|
8
|
+
*
|
|
9
|
+
* Pure and **non-mutating**: the input history array is never modified, and
|
|
10
|
+
* neither the summary store nor any thought record is altered. When a cold
|
|
11
|
+
* thought has no matching summary, the original {@link ThoughtData} is emitted
|
|
12
|
+
* unchanged. Consecutive cold thoughts that fall within the same summary's
|
|
13
|
+
* `coveredRange` are deduplicated to a single `SummaryRef`.
|
|
14
|
+
*
|
|
15
|
+
* @module core/compression/DehydrationPolicy
|
|
16
|
+
*/
|
|
17
|
+
import type { ISummaryStore } from '../../contracts/summary.js';
|
|
18
|
+
import type { ThoughtData } from '../thought.js';
|
|
19
|
+
import type { SessionId } from '../../contracts/ids.js';
|
|
20
|
+
/** Options controlling sliding-window dehydration. */
|
|
21
|
+
export interface DehydrationOptions {
|
|
22
|
+
/**
|
|
23
|
+
* Number of most-recent thoughts to keep verbatim ("hot" window).
|
|
24
|
+
* Older thoughts (the "cold" prefix) are eligible for replacement by
|
|
25
|
+
* summary references.
|
|
26
|
+
* @default 50
|
|
27
|
+
*/
|
|
28
|
+
readonly keepLastK?: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Lightweight reference replacing one or more cold thoughts covered by a
|
|
32
|
+
* {@link Summary}. Carries only the summary id and the inclusive
|
|
33
|
+
* `thought_number` range it covers.
|
|
34
|
+
*/
|
|
35
|
+
export interface SummaryRef {
|
|
36
|
+
readonly kind: 'summary';
|
|
37
|
+
readonly summaryId: string;
|
|
38
|
+
readonly coveredRange: readonly [number, number];
|
|
39
|
+
}
|
|
40
|
+
/** Output entry in a dehydrated history: either a verbatim thought or a ref. */
|
|
41
|
+
export type HydratedEntry = ThoughtData | SummaryRef;
|
|
42
|
+
/**
|
|
43
|
+
* Sliding-window dehydration policy.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const policy = new DehydrationPolicy(summaryStore);
|
|
48
|
+
* const hydrated = policy.apply(history, sessionId, { keepLastK: 50 });
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare class DehydrationPolicy {
|
|
52
|
+
private readonly _summaryStore;
|
|
53
|
+
constructor(_summaryStore: ISummaryStore);
|
|
54
|
+
/**
|
|
55
|
+
* Apply sliding-window dehydration to a history array.
|
|
56
|
+
*
|
|
57
|
+
* Returns a new array of `(ThoughtData | SummaryRef)` where:
|
|
58
|
+
* - The last `keepLastK` thoughts are preserved verbatim.
|
|
59
|
+
* - Older thoughts whose `thought_number` falls within an existing
|
|
60
|
+
* summary's `coveredRange` are replaced by a single {@link SummaryRef}.
|
|
61
|
+
* - Consecutive cold thoughts covered by the same summary collapse to one
|
|
62
|
+
* `SummaryRef`.
|
|
63
|
+
* - Cold thoughts with no matching summary are emitted verbatim.
|
|
64
|
+
*
|
|
65
|
+
* Non-mutating: the input array is not modified and original thoughts are
|
|
66
|
+
* never altered.
|
|
67
|
+
*
|
|
68
|
+
* @param history - Input history (chronological)
|
|
69
|
+
* @param sessionId - Session whose summaries should be considered
|
|
70
|
+
* @param opts - Optional dehydration options
|
|
71
|
+
* @returns A new array of hydrated entries
|
|
72
|
+
*/
|
|
73
|
+
apply(history: readonly ThoughtData[], sessionId: SessionId, opts?: DehydrationOptions): HydratedEntry[];
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=DehydrationPolicy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DehydrationPolicy.d.ts","sourceRoot":"","sources":["../../../src/core/compression/DehydrationPolicy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAW,MAAM,4BAA4B,CAAC;AACzE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAMxD,sDAAsD;AACtD,MAAM,WAAW,kBAAkB;IAClC;;;;;OAKG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;;;GAIG;AACH,MAAM,WAAW,UAAU;IAC1B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,YAAY,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjD;AAED,gFAAgF;AAChF,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,UAAU,CAAC;AAErD;;;;;;;;GAQG;AACH,qBAAa,iBAAiB;IACjB,OAAO,CAAC,QAAQ,CAAC,aAAa;gBAAb,aAAa,EAAE,aAAa;IAEzD;;;;;;;;;;;;;;;;;;OAkBG;IACH,KAAK,CACJ,OAAO,EAAE,SAAS,WAAW,EAAE,EAC/B,SAAS,EAAE,SAAS,EACpB,IAAI,CAAC,EAAE,kBAAkB,GACvB,aAAa,EAAE;CAgClB"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const DEFAULT_KEEP_LAST_K = 50;
|
|
2
|
+
class DehydrationPolicy {
|
|
3
|
+
_summaryStore;
|
|
4
|
+
constructor(_summaryStore){
|
|
5
|
+
this._summaryStore = _summaryStore;
|
|
6
|
+
}
|
|
7
|
+
apply(history, sessionId, opts) {
|
|
8
|
+
const k = opts?.keepLastK ?? DEFAULT_KEEP_LAST_K;
|
|
9
|
+
if (0 === history.length) return [];
|
|
10
|
+
if (history.length <= k) return history.slice();
|
|
11
|
+
const splitAt = history.length - k;
|
|
12
|
+
const cold = history.slice(0, splitAt);
|
|
13
|
+
const hot = history.slice(splitAt);
|
|
14
|
+
const summaries = this._summaryStore.forSession(sessionId);
|
|
15
|
+
const out = [];
|
|
16
|
+
let lastEmittedSummaryId;
|
|
17
|
+
for (const thought of cold){
|
|
18
|
+
const match = findCoveringSummary(summaries, thought.thought_number);
|
|
19
|
+
if (void 0 === match) {
|
|
20
|
+
out.push(thought);
|
|
21
|
+
lastEmittedSummaryId = void 0;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (match.id !== lastEmittedSummaryId) {
|
|
25
|
+
out.push({
|
|
26
|
+
kind: 'summary',
|
|
27
|
+
summaryId: match.id,
|
|
28
|
+
coveredRange: match.coveredRange
|
|
29
|
+
});
|
|
30
|
+
lastEmittedSummaryId = match.id;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
for (const t of hot)out.push(t);
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function findCoveringSummary(summaries, thoughtNumber) {
|
|
38
|
+
for (const s of summaries){
|
|
39
|
+
const [lo, hi] = s.coveredRange;
|
|
40
|
+
if (thoughtNumber >= lo && thoughtNumber <= hi) return s;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export { DehydrationPolicy };
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=DehydrationPolicy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core/compression/DehydrationPolicy.js","sources":["../../../src/core/compression/DehydrationPolicy.ts"],"sourcesContent":["/**\n * DehydrationPolicy — sliding-window history compaction.\n *\n * Replaces older thoughts (the \"cold\" prefix beyond the most recent K) with\n * lightweight {@link SummaryRef} placeholders that point to existing\n * {@link Summary} records in an {@link ISummaryStore}. Recent thoughts (the\n * \"hot\" suffix of length K) are preserved verbatim.\n *\n * Pure and **non-mutating**: the input history array is never modified, and\n * neither the summary store nor any thought record is altered. When a cold\n * thought has no matching summary, the original {@link ThoughtData} is emitted\n * unchanged. Consecutive cold thoughts that fall within the same summary's\n * `coveredRange` are deduplicated to a single `SummaryRef`.\n *\n * @module core/compression/DehydrationPolicy\n */\n\nimport type { ISummaryStore, Summary } from '../../contracts/summary.js';\nimport type { ThoughtData } from '../thought.js';\nimport type { SessionId } from '../../contracts/ids.js';\n\n\n/** Default value for {@link DehydrationOptions.keepLastK}. */\nconst DEFAULT_KEEP_LAST_K = 50;\n\n/** Options controlling sliding-window dehydration. */\nexport interface DehydrationOptions {\n\t/**\n\t * Number of most-recent thoughts to keep verbatim (\"hot\" window).\n\t * Older thoughts (the \"cold\" prefix) are eligible for replacement by\n\t * summary references.\n\t * @default 50\n\t */\n\treadonly keepLastK?: number;\n}\n\n/**\n * Lightweight reference replacing one or more cold thoughts covered by a\n * {@link Summary}. Carries only the summary id and the inclusive\n * `thought_number` range it covers.\n */\nexport interface SummaryRef {\n\treadonly kind: 'summary';\n\treadonly summaryId: string;\n\treadonly coveredRange: readonly [number, number];\n}\n\n/** Output entry in a dehydrated history: either a verbatim thought or a ref. */\nexport type HydratedEntry = ThoughtData | SummaryRef;\n\n/**\n * Sliding-window dehydration policy.\n *\n * @example\n * ```typescript\n * const policy = new DehydrationPolicy(summaryStore);\n * const hydrated = policy.apply(history, sessionId, { keepLastK: 50 });\n * ```\n */\nexport class DehydrationPolicy {\n\tconstructor(private readonly _summaryStore: ISummaryStore) {}\n\n\t/**\n\t * Apply sliding-window dehydration to a history array.\n\t *\n\t * Returns a new array of `(ThoughtData | SummaryRef)` where:\n\t * - The last `keepLastK` thoughts are preserved verbatim.\n\t * - Older thoughts whose `thought_number` falls within an existing\n\t * summary's `coveredRange` are replaced by a single {@link SummaryRef}.\n\t * - Consecutive cold thoughts covered by the same summary collapse to one\n\t * `SummaryRef`.\n\t * - Cold thoughts with no matching summary are emitted verbatim.\n\t *\n\t * Non-mutating: the input array is not modified and original thoughts are\n\t * never altered.\n\t *\n\t * @param history - Input history (chronological)\n\t * @param sessionId - Session whose summaries should be considered\n\t * @param opts - Optional dehydration options\n\t * @returns A new array of hydrated entries\n\t */\n\tapply(\n\t\thistory: readonly ThoughtData[],\n\t\tsessionId: SessionId,\n\t\topts?: DehydrationOptions\n\t): HydratedEntry[] {\n\t\tconst k = opts?.keepLastK ?? DEFAULT_KEEP_LAST_K;\n\t\tif (history.length === 0) return [];\n\t\tif (history.length <= k) return history.slice();\n\n\t\tconst splitAt = history.length - k;\n\t\tconst cold = history.slice(0, splitAt);\n\t\tconst hot = history.slice(splitAt);\n\n\t\tconst summaries = this._summaryStore.forSession(sessionId);\n\t\tconst out: HydratedEntry[] = [];\n\t\tlet lastEmittedSummaryId: string | undefined;\n\n\t\tfor (const thought of cold) {\n\t\t\tconst match = findCoveringSummary(summaries, thought.thought_number);\n\t\t\tif (match === undefined) {\n\t\t\t\tout.push(thought);\n\t\t\t\tlastEmittedSummaryId = undefined;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (match.id === lastEmittedSummaryId) continue;\n\t\t\tout.push({\n\t\t\t\tkind: 'summary',\n\t\t\t\tsummaryId: match.id,\n\t\t\t\tcoveredRange: match.coveredRange,\n\t\t\t});\n\t\t\tlastEmittedSummaryId = match.id;\n\t\t}\n\n\t\tfor (const t of hot) out.push(t);\n\t\treturn out;\n\t}\n}\n\n/**\n * Find the first summary whose `coveredRange` includes the given thought\n * number (inclusive on both ends). Returns `undefined` when none match.\n */\nfunction findCoveringSummary(\n\tsummaries: readonly Summary[],\n\tthoughtNumber: number\n): Summary | undefined {\n\tfor (const s of summaries) {\n\t\tconst [lo, hi] = s.coveredRange;\n\t\tif (thoughtNumber >= lo && thoughtNumber <= hi) return s;\n\t}\n\treturn undefined;\n}\n"],"names":["DEFAULT_KEEP_LAST_K","DehydrationPolicy","_summaryStore","history","sessionId","opts","k","splitAt","cold","hot","summaries","out","lastEmittedSummaryId","thought","match","findCoveringSummary","undefined","t","thoughtNumber","s","lo","hi"],"mappings":"AAuBA,MAAMA,sBAAsB;AAoCrB,MAAMC;;IACZ,YAA6BC,aAA4B,CAAE;aAA9BA,aAAa,GAAbA;IAA+B;IAqB5D,MACCC,OAA+B,EAC/BC,SAAoB,EACpBC,IAAyB,EACP;QAClB,MAAMC,IAAID,MAAM,aAAaL;QAC7B,IAAIG,AAAmB,MAAnBA,QAAQ,MAAM,EAAQ,OAAO,EAAE;QACnC,IAAIA,QAAQ,MAAM,IAAIG,GAAG,OAAOH,QAAQ,KAAK;QAE7C,MAAMI,UAAUJ,QAAQ,MAAM,GAAGG;QACjC,MAAME,OAAOL,QAAQ,KAAK,CAAC,GAAGI;QAC9B,MAAME,MAAMN,QAAQ,KAAK,CAACI;QAE1B,MAAMG,YAAY,IAAI,CAAC,aAAa,CAAC,UAAU,CAACN;QAChD,MAAMO,MAAuB,EAAE;QAC/B,IAAIC;QAEJ,KAAK,MAAMC,WAAWL,KAAM;YAC3B,MAAMM,QAAQC,oBAAoBL,WAAWG,QAAQ,cAAc;YACnE,IAAIC,AAAUE,WAAVF,OAAqB;gBACxBH,IAAI,IAAI,CAACE;gBACTD,uBAAuBI;gBACvB;YACD;YACA,IAAIF,MAAM,EAAE,KAAKF;gBACjBD,IAAI,IAAI,CAAC;oBACR,MAAM;oBACN,WAAWG,MAAM,EAAE;oBACnB,cAAcA,MAAM,YAAY;gBACjC;gBACAF,uBAAuBE,MAAM,EAAE;;QAChC;QAEA,KAAK,MAAMG,KAAKR,IAAKE,IAAI,IAAI,CAACM;QAC9B,OAAON;IACR;AACD;AAMA,SAASI,oBACRL,SAA6B,EAC7BQ,aAAqB;IAErB,KAAK,MAAMC,KAAKT,UAAW;QAC1B,MAAM,CAACU,IAAIC,GAAG,GAAGF,EAAE,YAAY;QAC/B,IAAID,iBAAiBE,MAAMF,iBAAiBG,IAAI,OAAOF;IACxD;AAED"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* InMemorySummaryStore — in-memory implementation of {@link ISummaryStore}.
|
|
3
|
+
*
|
|
4
|
+
* Stores compressed thought summaries in three indexes for O(1) point lookups
|
|
5
|
+
* and O(n) bucket reads (n = result size). Per-session and per-branch isolation
|
|
6
|
+
* is enforced by maintaining independent buckets keyed by session and
|
|
7
|
+
* `${sessionId}:${branchId}`.
|
|
8
|
+
*
|
|
9
|
+
* The store is intentionally synchronous and pure in-memory — no I/O. Persistence
|
|
10
|
+
* adapters may wrap this implementation if durability is required.
|
|
11
|
+
*
|
|
12
|
+
* @module core/compression/InMemorySummaryStore
|
|
13
|
+
*/
|
|
14
|
+
import type { ISummaryStore, Summary } from '../../contracts/summary.js';
|
|
15
|
+
import { type BranchId } from '../../contracts/ids.js';
|
|
16
|
+
/**
|
|
17
|
+
* In-memory implementation of {@link ISummaryStore}.
|
|
18
|
+
*
|
|
19
|
+
* Maintains three indexes:
|
|
20
|
+
* - `_byId`: id → summary (global lookup)
|
|
21
|
+
* - `_bySession`: sessionId → summaries[] (sorted by `createdAt` ascending)
|
|
22
|
+
* - `_byBranch`: `${sessionId}:${branchId}` → summaries[] (sorted by `createdAt`)
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const store = new InMemorySummaryStore();
|
|
27
|
+
* store.add({
|
|
28
|
+
* id: '01HX...',
|
|
29
|
+
* sessionId: 's1',
|
|
30
|
+
* rootThoughtId: 't5',
|
|
31
|
+
* coveredIds: ['t5', 't6'],
|
|
32
|
+
* coveredRange: [5, 6],
|
|
33
|
+
* topics: ['cache', 'lookup'],
|
|
34
|
+
* aggregateConfidence: 0.8,
|
|
35
|
+
* createdAt: Date.now(),
|
|
36
|
+
* });
|
|
37
|
+
* const all = store.forSession('s1');
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare class InMemorySummaryStore implements ISummaryStore {
|
|
41
|
+
private readonly _byId;
|
|
42
|
+
private readonly _bySession;
|
|
43
|
+
private readonly _byBranch;
|
|
44
|
+
/**
|
|
45
|
+
* Add a summary to the store.
|
|
46
|
+
*
|
|
47
|
+
* Inserts the summary into all three indexes, maintaining ascending
|
|
48
|
+
* `createdAt` order in the per-session and per-branch buckets via binary
|
|
49
|
+
* search insertion (O(log n)).
|
|
50
|
+
*
|
|
51
|
+
* @param summary - The summary record to add
|
|
52
|
+
* @throws {SequentialThinkingError} When a summary with the same id already exists
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* store.add(summary);
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
add(summary: Summary): void;
|
|
60
|
+
/**
|
|
61
|
+
* Retrieve a summary by its unique id.
|
|
62
|
+
*
|
|
63
|
+
* @param id - The summary's unique identifier
|
|
64
|
+
* @returns The summary, or `undefined` if not found
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const s = store.get('01HX...');
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
get(id: string): Summary | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Get all summaries for a session, sorted by `createdAt` ascending.
|
|
74
|
+
*
|
|
75
|
+
* @param sessionId - Session to query
|
|
76
|
+
* @returns Read-only array of summaries (empty if none)
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* for (const s of store.forSession('s1')) console.log(s.topics);
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
forSession(sessionId: string): readonly Summary[];
|
|
84
|
+
/**
|
|
85
|
+
* Get all summaries on a specific branch within a session.
|
|
86
|
+
*
|
|
87
|
+
* @param sessionId - Session to query
|
|
88
|
+
* @param branchId - Branch identifier
|
|
89
|
+
* @returns Read-only array of summaries (empty if none)
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* const branch = store.forBranch('s1', 'alt-1');
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
forBranch(sessionId: string, branchId: BranchId): readonly Summary[];
|
|
97
|
+
/**
|
|
98
|
+
* Remove all summaries for a session. Other sessions are unaffected.
|
|
99
|
+
*
|
|
100
|
+
* Removes entries from all three indexes in a single pass over the
|
|
101
|
+
* session's summary list.
|
|
102
|
+
*
|
|
103
|
+
* @param sessionId - Session to clear
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* store.clearSession('s1');
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
clearSession(sessionId: string): void;
|
|
111
|
+
clearAll(): void;
|
|
112
|
+
/**
|
|
113
|
+
* Count summaries.
|
|
114
|
+
*
|
|
115
|
+
* @param sessionId - If provided, count for that session only;
|
|
116
|
+
* otherwise return the total across all sessions
|
|
117
|
+
* @returns The number of summaries
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* const total = store.size();
|
|
122
|
+
* const perSession = store.size('s1');
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
size(sessionId?: string): number;
|
|
126
|
+
/**
|
|
127
|
+
* Insert a summary into a bucket maintaining ascending `createdAt` order
|
|
128
|
+
* via binary search (O(log n) search, O(n) splice).
|
|
129
|
+
*/
|
|
130
|
+
private _insertSorted;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=InMemorySummaryStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InMemorySummaryStore.d.ts","sourceRoot":"","sources":["../../../src/core/compression/InMemorySummaryStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAIN,KAAK,QAAQ,EAGb,MAAM,wBAAwB,CAAC;AAahC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,oBAAqB,YAAW,aAAa;IACzD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAsD;IAC5E,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAwC;IACnE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAuC;IAEjE;;;;;;;;;;;;;;OAcG;IACH,GAAG,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAqB3B;;;;;;;;;;OAUG;IACH,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS;IAQpC;;;;;;;;;;OAUG;IACH,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,OAAO,EAAE;IAIjD;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,SAAS,OAAO,EAAE;IAIpE;;;;;;;;;;;;OAYG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAerC,QAAQ,IAAI,IAAI;IAMhB;;;;;;;;;;;;OAYG;IACH,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM;IAShC;;;OAGG;IACH,OAAO,CAAC,aAAa;CAmBrB"}
|