@iworkforces/tracelattice 2.0.8 → 2.1.2
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/README.md +89 -64
- package/dist/ServerConfig.d.ts +1 -1
- package/dist/ServerConfig.js.map +1 -1
- package/dist/cli.js +18 -73
- package/dist/cli.js.map +1 -1
- package/dist/config/ConfigLoader.d.ts +29 -26
- package/dist/config/ConfigLoader.d.ts.map +1 -1
- package/dist/config/ConfigLoader.js +40 -36
- package/dist/config/ConfigLoader.js.map +1 -1
- package/dist/contracts/PersistenceBackend.d.ts +7 -108
- package/dist/contracts/PersistenceBackend.d.ts.map +1 -1
- package/dist/contracts/PersistenceBackend.js +1 -6
- package/dist/contracts/calibrator.d.ts +6 -6
- package/dist/contracts/calibrator.d.ts.map +1 -1
- package/dist/contracts/ids.d.ts +1 -8
- package/dist/contracts/ids.d.ts.map +1 -1
- package/dist/contracts/ids.js +2 -3
- package/dist/contracts/ids.js.map +1 -1
- package/dist/contracts/interfaces.d.ts +4 -6
- package/dist/contracts/interfaces.d.ts.map +1 -1
- package/dist/contracts/persistence-work.d.ts +2 -3
- package/dist/contracts/persistence-work.d.ts.map +1 -1
- package/dist/core/HistoryManager.d.ts +12 -16
- package/dist/core/HistoryManager.d.ts.map +1 -1
- package/dist/core/HistoryManager.js +19 -40
- package/dist/core/HistoryManager.js.map +1 -1
- package/dist/core/IHistoryManager.d.ts +22 -30
- package/dist/core/IHistoryManager.d.ts.map +1 -1
- package/dist/core/InputNormalizer.d.ts +7 -24
- package/dist/core/InputNormalizer.d.ts.map +1 -1
- package/dist/core/InputNormalizer.js +3 -9
- package/dist/core/InputNormalizer.js.map +1 -1
- package/dist/core/PersistenceBuffer.d.ts +3 -20
- package/dist/core/PersistenceBuffer.d.ts.map +1 -1
- package/dist/core/PersistenceBuffer.js +1 -4
- package/dist/core/PersistenceBuffer.js.map +1 -1
- package/dist/core/PersistenceRestore.d.ts.map +1 -1
- package/dist/core/PersistenceRestore.js +4 -10
- package/dist/core/PersistenceRestore.js.map +1 -1
- package/dist/core/PersistenceWriter.d.ts.map +1 -1
- package/dist/core/PersistenceWriter.js +3 -12
- package/dist/core/PersistenceWriter.js.map +1 -1
- package/dist/core/SessionErrors.d.ts +0 -11
- package/dist/core/SessionErrors.d.ts.map +1 -1
- package/dist/core/SessionErrors.js +1 -14
- package/dist/core/SessionErrors.js.map +1 -1
- package/dist/core/SessionLock.d.ts +4 -5
- package/dist/core/SessionLock.d.ts.map +1 -1
- package/dist/core/SessionLock.js +5 -10
- package/dist/core/SessionLock.js.map +1 -1
- package/dist/core/SessionManager.d.ts +0 -2
- package/dist/core/SessionManager.d.ts.map +1 -1
- package/dist/core/SessionManager.js +3 -5
- package/dist/core/SessionManager.js.map +1 -1
- package/dist/core/SessionResetCoordinator.d.ts +10 -7
- package/dist/core/SessionResetCoordinator.d.ts.map +1 -1
- package/dist/core/SessionResetCoordinator.js +10 -28
- package/dist/core/SessionResetCoordinator.js.map +1 -1
- package/dist/core/ThoughtEvaluator.d.ts +5 -5
- package/dist/core/ThoughtEvaluator.d.ts.map +1 -1
- package/dist/core/ThoughtEvaluator.js +4 -40
- package/dist/core/ThoughtEvaluator.js.map +1 -1
- package/dist/core/ThoughtProcessor.d.ts +10 -3
- package/dist/core/ThoughtProcessor.d.ts.map +1 -1
- package/dist/core/ThoughtProcessor.js +34 -38
- package/dist/core/ThoughtProcessor.js.map +1 -1
- package/dist/core/VerificationOutcomeAdmission.d.ts.map +1 -1
- package/dist/core/VerificationOutcomeAdmission.js +5 -7
- package/dist/core/VerificationOutcomeAdmission.js.map +1 -1
- package/dist/core/evaluator/Calibrator.d.ts +1 -1
- package/dist/core/evaluator/Calibrator.d.ts.map +1 -1
- package/dist/core/evaluator/Calibrator.js +2 -5
- package/dist/core/evaluator/Calibrator.js.map +1 -1
- package/dist/core/evaluator/internals.d.ts +0 -4
- package/dist/core/evaluator/internals.d.ts.map +1 -1
- package/dist/core/evaluator/internals.js +1 -3
- package/dist/core/evaluator/internals.js.map +1 -1
- package/dist/core/graph/Edge.d.ts +1 -1
- package/dist/core/graph/EdgeEmitter.d.ts +2 -4
- package/dist/core/graph/EdgeEmitter.d.ts.map +1 -1
- package/dist/core/graph/EdgeEmitter.js +2 -4
- package/dist/core/graph/EdgeEmitter.js.map +1 -1
- package/dist/core/reasoning/OutcomeRecorder.d.ts +0 -1
- package/dist/core/reasoning/OutcomeRecorder.d.ts.map +1 -1
- package/dist/core/reasoning/OutcomeRecorder.js.map +1 -1
- package/dist/core/reasoning/strategies/SequentialStrategy.d.ts +3 -3
- package/dist/core/reasoning/strategies/SequentialStrategy.js.map +1 -1
- package/dist/core/thought.d.ts +2 -1
- package/dist/core/thought.d.ts.map +1 -1
- package/dist/errors.d.ts +4 -20
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +2 -28
- package/dist/errors.js.map +1 -1
- package/dist/lib.d.ts +13 -20
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +4 -7
- package/dist/lib.js.map +1 -1
- package/dist/logger/NullLogger.d.ts +9 -11
- package/dist/logger/NullLogger.d.ts.map +1 -1
- package/dist/logger/NullLogger.js.map +1 -1
- package/dist/persistence/FilePersistence.d.ts +3 -12
- package/dist/persistence/FilePersistence.d.ts.map +1 -1
- package/dist/persistence/FilePersistence.js +9 -61
- package/dist/persistence/FilePersistence.js.map +1 -1
- package/dist/persistence/FileSnapshotV2.d.ts +2 -2
- package/dist/persistence/FileSnapshotV2.js +2 -2
- package/dist/persistence/FileSnapshotV2.js.map +1 -1
- package/dist/persistence/FileWriter.d.ts +1 -0
- package/dist/persistence/FileWriter.d.ts.map +1 -1
- package/dist/persistence/FileWriter.js +3 -3
- package/dist/persistence/FileWriter.js.map +1 -1
- package/dist/persistence/MemoryPersistence.d.ts +5 -15
- package/dist/persistence/MemoryPersistence.d.ts.map +1 -1
- package/dist/persistence/MemoryPersistence.js +6 -40
- package/dist/persistence/MemoryPersistence.js.map +1 -1
- package/dist/persistence/PersistenceCodec.js +1 -3
- package/dist/persistence/PersistenceCodec.js.map +1 -1
- package/dist/persistence/PersistenceErrors.d.ts +0 -6
- package/dist/persistence/PersistenceErrors.d.ts.map +1 -1
- package/dist/persistence/PersistenceErrors.js +1 -9
- package/dist/persistence/PersistenceErrors.js.map +1 -1
- package/dist/persistence/PersistenceScope.d.ts.map +1 -1
- package/dist/persistence/PersistenceScope.js +2 -2
- package/dist/persistence/PersistenceScope.js.map +1 -1
- package/dist/persistence/SqlitePersistence.d.ts +3 -10
- package/dist/persistence/SqlitePersistence.d.ts.map +1 -1
- package/dist/persistence/SqlitePersistence.js +2 -26
- package/dist/persistence/SqlitePersistence.js.map +1 -1
- package/dist/persistence/SqliteSchemaV2.d.ts.map +1 -1
- package/dist/persistence/SqliteSchemaV2.js +3 -12
- package/dist/persistence/SqliteSchemaV2.js.map +1 -1
- package/dist/pool/ConnectionPool.d.ts +3 -12
- package/dist/pool/ConnectionPool.d.ts.map +1 -1
- package/dist/pool/ConnectionPool.js +5 -8
- package/dist/pool/ConnectionPool.js.map +1 -1
- package/dist/pool/IConnectionPool.d.ts +3 -9
- package/dist/pool/IConnectionPool.d.ts.map +1 -1
- package/dist/registry/BaseRegistry.d.ts +10 -2
- package/dist/registry/BaseRegistry.d.ts.map +1 -1
- package/dist/registry/BaseRegistry.js +128 -81
- package/dist/registry/BaseRegistry.js.map +1 -1
- package/dist/registry/SkillRegistry.d.ts +1 -7
- package/dist/registry/SkillRegistry.d.ts.map +1 -1
- package/dist/registry/SkillRegistry.js +0 -15
- package/dist/registry/SkillRegistry.js.map +1 -1
- package/dist/registry/ToolRegistry.d.ts +1 -9
- package/dist/registry/ToolRegistry.d.ts.map +1 -1
- package/dist/registry/ToolRegistry.js +0 -21
- package/dist/registry/ToolRegistry.js.map +1 -1
- package/dist/schema.d.ts +2 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +3 -3
- package/dist/schema.js.map +1 -1
- package/dist/transport/BaseTransport.d.ts +0 -9
- package/dist/transport/BaseTransport.d.ts.map +1 -1
- package/dist/transport/BaseTransport.js +0 -11
- package/dist/transport/BaseTransport.js.map +1 -1
- package/dist/watchers/SkillWatcher.d.ts.map +1 -1
- package/dist/watchers/SkillWatcher.js +1 -1
- package/dist/watchers/SkillWatcher.js.map +1 -1
- package/package.json +1 -1
- package/dist/contracts/PersistenceBackend.js.map +0 -1
- package/dist/persistence/FileLegacyImport.d.ts +0 -2
- package/dist/persistence/FileLegacyImport.d.ts.map +0 -1
- package/dist/persistence/FileLegacyImport.js +0 -183
- package/dist/persistence/FileLegacyImport.js.map +0 -1
- package/dist/persistence/SessionScopedPersistence.d.ts +0 -4
- package/dist/persistence/SessionScopedPersistence.d.ts.map +0 -1
- package/dist/persistence/SessionScopedPersistence.js +0 -9
- package/dist/persistence/SessionScopedPersistence.js.map +0 -1
- package/dist/persistence/SqliteLegacyImport.d.ts +0 -14
- package/dist/persistence/SqliteLegacyImport.d.ts.map +0 -1
- package/dist/persistence/SqliteLegacyImport.js +0 -136
- package/dist/persistence/SqliteLegacyImport.js.map +0 -1
- package/dist/persistence/SqliteLegacySchema.d.ts +0 -15
- package/dist/persistence/SqliteLegacySchema.d.ts.map +0 -1
- package/dist/persistence/SqliteLegacySchema.js +0 -72
- package/dist/persistence/SqliteLegacySchema.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core/evaluator/Calibrator.js","sources":["../../../src/core/evaluator/Calibrator.ts"],"sourcesContent":["/**\n * Confidence calibration for sequential thinking reasoning.\n *\n * Provides the {@link Calibrator} class — maps raw model confidence values\n * to calibrated probabilities using per-type Beta(2, 2) priors and\n * grid-searched temperature scaling. Reports calibration quality through\n * Brier score and 10-bin Expected Calibration Error (ECE).\n *\n * Math summary:\n * - **Per-type prior**: Beta(α=2, β=2), prior mean = 0.5. As outcomes accumulate\n * for a type, the calibrated value shrinks toward the observed mean of that\n * type with weight `priorWeight = 1 / (1 + n / 10)` where `n` is the type's\n * sample count.\n * - **Temperature scaling**: Grid search T ∈ {0.5, 0.75, 1.0, 1.25, 1.5, 2.0}\n * minimizing negative log-likelihood (NLL) over recorded outcomes. Default T=1.0.\n * Requires ≥10 outcomes; below that threshold only prior shrinkage is applied.\n * - **Brier score**: `mean((predicted - actual)^2)` over recorded outcomes.\n * - **ECE (10-bin)**: bucket predictions in 0.1 increments, compute weighted\n * absolute deviation between bin mean confidence and bin accuracy.\n *\n * @module core/evaluator/Calibrator\n */\n\nimport type {\n\tCalibrationMetrics,\n\tCalibrationResult,\n\tICalibrator,\n} from '../../contracts/calibrator.js';\nimport type { IOutcomeRecorder, VerificationOutcome } from '../../contracts/interfaces.js';\nimport type { ThoughtType } from '../../contracts/reasoning-types.js';\nimport type { SessionId } from '../../contracts/ids.js';\nimport {\n\tEPSILON,\n\tMIN_OUTCOMES_FOR_TEMPERATURE,\n\tapplyTemperature,\n\tfitTemperature,\n} from './calibration-math.js';\nimport { ALL_THOUGHT_TYPES } from './internals.js';\n\n/** Number of bins used by ECE (10-bin → 0.1 increments). */\nconst ECE_BINS = 10;\n\n/** Sentinel used in the per-session temperature map for global state. */\nconst GLOBAL_KEY: unique symbol = Symbol('global calibration temperature');\n\n/**\n * Build per-type empirical means + counts from a list of outcomes.\n *\n * @param outcomes - Outcomes to aggregate.\n * @returns Map of thought type to `{ mean, count }`. Types with no outcomes\n * are absent from the map.\n */\nfunction aggregatePerType(\n\toutcomes: readonly VerificationOutcome[]\n): Map<string, { mean: number; count: number }> {\n\tconst sums = new Map<string, { sum: number; count: number }>();\n\tfor (const o of outcomes) {\n\t\tconst prev = sums.get(o.type) ?? { sum: 0, count: 0 };\n\t\tprev.sum += o.actual;\n\t\tprev.count += 1;\n\t\tsums.set(o.type, prev);\n\t}\n\tconst result = new Map<string, { mean: number; count: number }>();\n\tfor (const [type, { sum, count }] of sums) {\n\t\tresult.set(type, { mean: sum / count, count });\n\t}\n\treturn result;\n}\n\n/**\n * Compute the Brier score over a list of outcomes.\n *\n * @param outcomes - Outcomes to score.\n * @returns Mean squared error between predicted probability and actual label,\n * or `null` if `outcomes` is empty.\n */\nfunction brierScore(outcomes: readonly VerificationOutcome[]): number | null {\n\tif (outcomes.length === 0) return null;\n\tlet sum = 0;\n\tfor (const o of outcomes) {\n\t\tconst diff = o.predicted - o.actual;\n\t\tsum += diff * diff;\n\t}\n\treturn sum / outcomes.length;\n}\n\n/**\n * Compute 10-bin Expected Calibration Error.\n *\n * Buckets predictions in 0.1-wide bins, then sums weighted absolute\n * differences between bin mean confidence and bin accuracy.\n *\n * @param outcomes - Outcomes to evaluate.\n * @returns ECE in `[0, 1]`, or `null` if `outcomes` is empty.\n */\nfunction expectedCalibrationError(outcomes: readonly VerificationOutcome[]): number | null {\n\tif (outcomes.length === 0) return null;\n\tconst binConfSum = new Array<number>(ECE_BINS).fill(0);\n\tconst binAccSum = new Array<number>(ECE_BINS).fill(0);\n\tconst binCount = new Array<number>(ECE_BINS).fill(0);\n\tfor (const o of outcomes) {\n\t\tconst p = Math.min(1 - EPSILON, Math.max(0, o.predicted));\n\t\tconst idx = Math.min(ECE_BINS - 1, Math.floor(p * ECE_BINS));\n\t\tbinConfSum[idx] = (binConfSum[idx] ?? 0) + p;\n\t\tbinAccSum[idx] = (binAccSum[idx] ?? 0) + o.actual;\n\t\tbinCount[idx] = (binCount[idx] ?? 0) + 1;\n\t}\n\tconst total = outcomes.length;\n\tlet ece = 0;\n\tfor (let i = 0; i < ECE_BINS; i++) {\n\t\tconst n = binCount[i] ?? 0;\n\t\tif (n === 0) continue;\n\t\tconst meanConf = (binConfSum[i] ?? 0) / n;\n\t\tconst meanAcc = (binAccSum[i] ?? 0) / n;\n\t\tece += (n / total) * Math.abs(meanConf - meanAcc);\n\t}\n\treturn ece;\n}\n\n/**\n * Build the per-type Brier score breakdown for {@link CalibrationMetrics}.\n *\n * @param outcomes - Outcomes to bucket by type.\n * @returns Record keyed by every {@link ThoughtType}; `null` for types with\n * no recorded outcomes.\n */\nfunction perTypeBrier(\n\toutcomes: readonly VerificationOutcome[]\n): Record<ThoughtType, number | null> {\n\tconst buckets = new Map<string, VerificationOutcome[]>();\n\tfor (const o of outcomes) {\n\t\tconst list = buckets.get(o.type) ?? [];\n\t\tlist.push(o);\n\t\tbuckets.set(o.type, list);\n\t}\n\tconst result = {} as Record<ThoughtType, number | null>;\n\tfor (const t of ALL_THOUGHT_TYPES) {\n\t\tresult[t] = brierScore(buckets.get(t) ?? []);\n\t}\n\treturn result;\n}\n\n/** Empty CalibrationMetrics returned when calibration is disabled. */\nfunction emptyMetrics(): CalibrationMetrics {\n\tconst perType = {} as Record<ThoughtType, number | null>;\n\tfor (const t of ALL_THOUGHT_TYPES) perType[t] = null;\n\treturn {\n\t\tbrierScore: null,\n\t\tece: null,\n\t\tsampleCount: 0,\n\t\tperTypeBrier: perType,\n\t};\n}\n\n/**\n * Confidence calibration service.\n *\n * Stateless w.r.t. outcome storage (delegated to {@link IOutcomeRecorder}),\n * but maintains a small per-session temperature cache that is recomputed\n * via {@link Calibrator.refit}.\n *\n * @example\n * ```typescript\n * const calibrator = new Calibrator(outcomeRecorder, true);\n * const result = calibrator.calibrate(0.9, 'hypothesis', 'session-1');\n * console.log(result.calibrated, result.temperature, result.priorWeight);\n * ```\n */\nexport class Calibrator implements ICalibrator {\n\tpublic readonly enabled: boolean;\n\tprivate readonly _recorder: IOutcomeRecorder;\n\tprivate readonly _temperatures = new Map<SessionId | typeof GLOBAL_KEY, number>();\n\n\tconstructor(outcomeRecorder: IOutcomeRecorder, enabled: boolean) {\n\t\tthis._recorder = outcomeRecorder;\n\t\tthis.enabled = enabled;\n\t}\n\n\tpublic calibrate(\n\t\trawConfidence: number,\n\t\ttype: ThoughtType,\n\t\tsessionId: SessionId\n\t): CalibrationResult {\n\t\tconst raw = Math.min(1, Math.max(0, rawConfidence));\n\t\tif (!this.enabled) {\n\t\t\treturn { raw, calibrated: raw, temperature: 1.0, priorWeight: 0 };\n\t\t}\n\t\tconst outcomes = this._recorder.getOutcomes(sessionId);\n\t\tconst perType = aggregatePerType(outcomes);\n\t\tconst typeStats = perType.get(type);\n\t\tconst n = typeStats?.count ?? 0;\n\t\tconst observedMean = typeStats?.mean ?? 0.5;\n\t\tconst priorWeight = 1 / (1 + n / 10);\n\t\tconst shrunk = priorWeight * observedMean + (1 - priorWeight) * raw;\n\t\tconst temperature =\n\t\t\tthis._temperatures.get(sessionId) ?? this._temperatures.get(GLOBAL_KEY) ?? 1.0;\n\t\tconst calibrated =\n\t\t\toutcomes.length >= MIN_OUTCOMES_FOR_TEMPERATURE\n\t\t\t\t? applyTemperature(shrunk, temperature)\n\t\t\t\t: shrunk;\n\t\treturn { raw, calibrated, temperature, priorWeight };\n\t}\n\n\tpublic metrics(sessionId?: SessionId): CalibrationMetrics {\n\t\tif (!this.enabled) return emptyMetrics();\n\t\tconst outcomes =\n\t\t\tsessionId === undefined\n\t\t\t\t? this._recorder.getAllOutcomes()\n\t\t\t\t: this._recorder.getOutcomes(sessionId);\n\t\treturn {\n\t\t\tbrierScore: brierScore(outcomes),\n\t\t\tece: expectedCalibrationError(outcomes),\n\t\t\tsampleCount: outcomes.length,\n\t\t\tperTypeBrier: perTypeBrier(outcomes),\n\t\t};\n\t}\n\n\tpublic refit(sessionId?: SessionId): void {\n\t\tif (!this.enabled) return;\n\t\tconst key = sessionId ?? GLOBAL_KEY;\n\t\tconst outcomes =\n\t\t\tsessionId === undefined\n\t\t\t\t? this._recorder.getAllOutcomes()\n\t\t\t\t: this._recorder.getOutcomes(sessionId);\n\t\tthis._temperatures.set(key, fitTemperature(outcomes));\n\t}\n\n\tpublic clearSession(sessionId: SessionId): void {\n\t\tif (!this.enabled) return;\n\t\tthis._temperatures.delete(sessionId);\n\t}\n\n\tpublic clearAll(): void {\n\t\tif (!this.enabled) return;\n\t\tthis._temperatures.clear();\n\t}\n}\n"],"names":["ECE_BINS","GLOBAL_KEY","Symbol","aggregatePerType","outcomes","sums","Map","o","prev","result","type","sum","count","brierScore","diff","expectedCalibrationError","binConfSum","Array","binAccSum","binCount","p","Math","EPSILON","idx","total","ece","i","n","meanConf","meanAcc","perTypeBrier","buckets","list","t","ALL_THOUGHT_TYPES","emptyMetrics","perType","Calibrator","outcomeRecorder","enabled","rawConfidence","sessionId","raw","typeStats","observedMean","priorWeight","shrunk","temperature","calibrated","MIN_OUTCOMES_FOR_TEMPERATURE","applyTemperature","undefined","key","fitTemperature"],"mappings":";;AAwCA,MAAMA,WAAW;AAGjB,MAAMC,aAA4BC,OAAO;AASzC,SAASC,iBACRC,QAAwC;IAExC,MAAMC,OAAO,IAAIC;IACjB,KAAK,MAAMC,KAAKH,SAAU;QACzB,MAAMI,OAAOH,KAAK,GAAG,CAACE,EAAE,IAAI,KAAK;YAAE,KAAK;YAAG,OAAO;QAAE;QACpDC,KAAK,GAAG,IAAID,EAAE,MAAM;QACpBC,KAAK,KAAK,IAAI;QACdH,KAAK,GAAG,CAACE,EAAE,IAAI,EAAEC;IAClB;IACA,MAAMC,SAAS,IAAIH;IACnB,KAAK,MAAM,CAACI,MAAM,EAAEC,GAAG,EAAEC,KAAK,EAAE,CAAC,IAAIP,KACpCI,OAAO,GAAG,CAACC,MAAM;QAAE,MAAMC,MAAMC;QAAOA;IAAM;IAE7C,OAAOH;AACR;AASA,SAASI,WAAWT,QAAwC;IAC3D,IAAIA,AAAoB,MAApBA,SAAS,MAAM,EAAQ,OAAO;IAClC,IAAIO,MAAM;IACV,KAAK,MAAMJ,KAAKH,SAAU;QACzB,MAAMU,OAAOP,EAAE,SAAS,GAAGA,EAAE,MAAM;QACnCI,OAAOG,OAAOA;IACf;IACA,OAAOH,MAAMP,SAAS,MAAM;AAC7B;AAWA,SAASW,yBAAyBX,QAAwC;IACzE,IAAIA,AAAoB,MAApBA,SAAS,MAAM,EAAQ,OAAO;IAClC,MAAMY,aAAa,IAAIC,MAAcjB,UAAU,IAAI,CAAC;IACpD,MAAMkB,YAAY,IAAID,MAAcjB,UAAU,IAAI,CAAC;IACnD,MAAMmB,WA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,OAAON;QAC1B,MAAM/B,WACLqC,AAAcU,WAAdV,YACG,IAAI,CAAC,SAAS,CAAC,cAAc,KAC7B,IAAI,CAAC,SAAS,CAAC,WAAW,CAACA;QAC/B,OAAO;YACN,YAAY5B,WAAWT;YACvB,KAAKW,yBAAyBX;YAC9B,aAAaA,SAAS,MAAM;YAC5B,cAAc0B,aAAa1B;QAC5B;IACD;IAEO,MAAMqC,SAAqB,EAAQ;QACzC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;QACnB,MAAMW,MAAMX,aAAaxC;QACzB,MAAMG,WACLqC,AAAcU,WAAdV,YACG,IAAI,CAAC,SAAS,CAAC,cAAc,KAC7B,IAAI,CAAC,SAAS,CAAC,WAAW,CAACA;QAC/B,IAAI,CAAC,aAAa,CAAC,GAAG,CAACW,KAAKC,eAAejD;IAC5C;IAEO,aAAaqC,SAAoB,EAAQ;QAC/C,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;QACnB,IAAI,CAAC,aAAa,CAAC,MAAM,CAACA;IAC3B;IAEO,WAAiB;QACvB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;QACnB,IAAI,CAAC,aAAa,CAAC,KAAK;IACzB;AACD"}
|
|
1
|
+
{"version":3,"file":"core/evaluator/Calibrator.js","sources":["../../../src/core/evaluator/Calibrator.ts"],"sourcesContent":["/**\n * Confidence calibration for sequential thinking reasoning.\n *\n * Provides the {@link Calibrator} class — maps raw model confidence values\n * to calibrated probabilities using per-type Beta(2, 2) priors and\n * grid-searched temperature scaling. Reports calibration quality through\n * Brier score and 10-bin Expected Calibration Error (ECE).\n *\n * Math summary:\n * - **Per-type prior**: Beta(α=2, β=2), prior mean = 0.5. As outcomes accumulate\n * for a type, the calibrated value shrinks toward the observed mean of that\n * type with weight `priorWeight = 1 / (1 + n / 10)` where `n` is the type's\n * sample count.\n * - **Temperature scaling**: Grid search T ∈ {0.5, 0.75, 1.0, 1.25, 1.5, 2.0}\n * minimizing negative log-likelihood (NLL) over recorded outcomes. Default T=1.0.\n * Requires ≥10 outcomes; below that threshold only prior shrinkage is applied.\n * - **Brier score**: `mean((predicted - actual)^2)` over recorded outcomes.\n * - **ECE (10-bin)**: bucket predictions in 0.1 increments, compute weighted\n * absolute deviation between bin mean confidence and bin accuracy.\n *\n * @module core/evaluator/Calibrator\n */\n\nimport type {\n\tCalibrationMetrics,\n\tCalibrationResult,\n\tICalibrator,\n} from '../../contracts/calibrator.js';\nimport type { IOutcomeRecorder, VerificationOutcome } from '../../contracts/interfaces.js';\nimport type { ThoughtType } from '../../contracts/reasoning-types.js';\nimport type { SessionId } from '../../contracts/ids.js';\nimport {\n\tEPSILON,\n\tMIN_OUTCOMES_FOR_TEMPERATURE,\n\tapplyTemperature,\n\tfitTemperature,\n} from './calibration-math.js';\nimport { ALL_THOUGHT_TYPES } from './internals.js';\n\n/** Number of bins used by ECE (10-bin → 0.1 increments). */\nconst ECE_BINS = 10;\n\n/**\n * Build per-type empirical means + counts from a list of outcomes.\n *\n * @param outcomes - Outcomes to aggregate.\n * @returns Map of thought type to `{ mean, count }`. Types with no outcomes\n * are absent from the map.\n */\nfunction aggregatePerType(\n\toutcomes: readonly VerificationOutcome[]\n): Map<string, { mean: number; count: number }> {\n\tconst sums = new Map<string, { sum: number; count: number }>();\n\tfor (const o of outcomes) {\n\t\tconst prev = sums.get(o.type) ?? { sum: 0, count: 0 };\n\t\tprev.sum += o.actual;\n\t\tprev.count += 1;\n\t\tsums.set(o.type, prev);\n\t}\n\tconst result = new Map<string, { mean: number; count: number }>();\n\tfor (const [type, { sum, count }] of sums) {\n\t\tresult.set(type, { mean: sum / count, count });\n\t}\n\treturn result;\n}\n\n/**\n * Compute the Brier score over a list of outcomes.\n *\n * @param outcomes - Outcomes to score.\n * @returns Mean squared error between predicted probability and actual label,\n * or `null` if `outcomes` is empty.\n */\nfunction brierScore(outcomes: readonly VerificationOutcome[]): number | null {\n\tif (outcomes.length === 0) return null;\n\tlet sum = 0;\n\tfor (const o of outcomes) {\n\t\tconst diff = o.predicted - o.actual;\n\t\tsum += diff * diff;\n\t}\n\treturn sum / outcomes.length;\n}\n\n/**\n * Compute 10-bin Expected Calibration Error.\n *\n * Buckets predictions in 0.1-wide bins, then sums weighted absolute\n * differences between bin mean confidence and bin accuracy.\n *\n * @param outcomes - Outcomes to evaluate.\n * @returns ECE in `[0, 1]`, or `null` if `outcomes` is empty.\n */\nfunction expectedCalibrationError(outcomes: readonly VerificationOutcome[]): number | null {\n\tif (outcomes.length === 0) return null;\n\tconst binConfSum = new Array<number>(ECE_BINS).fill(0);\n\tconst binAccSum = new Array<number>(ECE_BINS).fill(0);\n\tconst binCount = new Array<number>(ECE_BINS).fill(0);\n\tfor (const o of outcomes) {\n\t\tconst p = Math.min(1 - EPSILON, Math.max(0, o.predicted));\n\t\tconst idx = Math.min(ECE_BINS - 1, Math.floor(p * ECE_BINS));\n\t\tbinConfSum[idx] = (binConfSum[idx] ?? 0) + p;\n\t\tbinAccSum[idx] = (binAccSum[idx] ?? 0) + o.actual;\n\t\tbinCount[idx] = (binCount[idx] ?? 0) + 1;\n\t}\n\tconst total = outcomes.length;\n\tlet ece = 0;\n\tfor (let i = 0; i < ECE_BINS; i++) {\n\t\tconst n = binCount[i] ?? 0;\n\t\tif (n === 0) continue;\n\t\tconst meanConf = (binConfSum[i] ?? 0) / n;\n\t\tconst meanAcc = (binAccSum[i] ?? 0) / n;\n\t\tece += (n / total) * Math.abs(meanConf - meanAcc);\n\t}\n\treturn ece;\n}\n\n/**\n * Build the per-type Brier score breakdown for {@link CalibrationMetrics}.\n *\n * @param outcomes - Outcomes to bucket by type.\n * @returns Record keyed by every {@link ThoughtType}; `null` for types with\n * no recorded outcomes.\n */\nfunction perTypeBrier(\n\toutcomes: readonly VerificationOutcome[]\n): Record<ThoughtType, number | null> {\n\tconst buckets = new Map<string, VerificationOutcome[]>();\n\tfor (const o of outcomes) {\n\t\tconst list = buckets.get(o.type) ?? [];\n\t\tlist.push(o);\n\t\tbuckets.set(o.type, list);\n\t}\n\tconst result = {} as Record<ThoughtType, number | null>;\n\tfor (const t of ALL_THOUGHT_TYPES) {\n\t\tresult[t] = brierScore(buckets.get(t) ?? []);\n\t}\n\treturn result;\n}\n\n/** Empty CalibrationMetrics returned when calibration is disabled. */\nfunction emptyMetrics(): CalibrationMetrics {\n\tconst perType = {} as Record<ThoughtType, number | null>;\n\tfor (const t of ALL_THOUGHT_TYPES) perType[t] = null;\n\treturn {\n\t\tbrierScore: null,\n\t\tece: null,\n\t\tsampleCount: 0,\n\t\tperTypeBrier: perType,\n\t};\n}\n\n/**\n * Confidence calibration service.\n *\n * Stateless w.r.t. outcome storage (delegated to {@link IOutcomeRecorder}),\n * but maintains a small per-session temperature cache that is recomputed\n * via {@link Calibrator.refit}.\n *\n * @example\n * ```typescript\n * const calibrator = new Calibrator(outcomeRecorder, true);\n * const result = calibrator.calibrate(0.9, 'hypothesis', 'session-1');\n * console.log(result.calibrated, result.temperature, result.priorWeight);\n * ```\n */\nexport class Calibrator implements ICalibrator {\n\tpublic readonly enabled: boolean;\n\tprivate readonly _recorder: IOutcomeRecorder;\n\tprivate readonly _temperatures = new Map<SessionId, number>();\n\n\tconstructor(outcomeRecorder: IOutcomeRecorder, enabled: boolean) {\n\t\tthis._recorder = outcomeRecorder;\n\t\tthis.enabled = enabled;\n\t}\n\n\tpublic calibrate(\n\t\trawConfidence: number,\n\t\ttype: ThoughtType,\n\t\tsessionId: SessionId\n\t): CalibrationResult {\n\t\tconst raw = Math.min(1, Math.max(0, rawConfidence));\n\t\tif (!this.enabled) {\n\t\t\treturn { raw, calibrated: raw, temperature: 1.0, priorWeight: 0 };\n\t\t}\n\t\tconst outcomes = this._recorder.getOutcomes(sessionId);\n\t\tconst perType = aggregatePerType(outcomes);\n\t\tconst typeStats = perType.get(type);\n\t\tconst n = typeStats?.count ?? 0;\n\t\tconst observedMean = typeStats?.mean ?? 0.5;\n\t\tconst priorWeight = 1 / (1 + n / 10);\n\t\tconst shrunk = priorWeight * observedMean + (1 - priorWeight) * raw;\n\t\tconst temperature = this._temperatures.get(sessionId) ?? 1.0;\n\t\tconst calibrated =\n\t\t\toutcomes.length >= MIN_OUTCOMES_FOR_TEMPERATURE\n\t\t\t\t? applyTemperature(shrunk, temperature)\n\t\t\t\t: shrunk;\n\t\treturn { raw, calibrated, temperature, priorWeight };\n\t}\n\n\tpublic metrics(sessionId?: SessionId): CalibrationMetrics {\n\t\tif (!this.enabled) return emptyMetrics();\n\t\tconst outcomes =\n\t\t\tsessionId === undefined\n\t\t\t\t? this._recorder.getAllOutcomes()\n\t\t\t\t: this._recorder.getOutcomes(sessionId);\n\t\treturn {\n\t\t\tbrierScore: brierScore(outcomes),\n\t\t\tece: expectedCalibrationError(outcomes),\n\t\t\tsampleCount: outcomes.length,\n\t\t\tperTypeBrier: perTypeBrier(outcomes),\n\t\t};\n\t}\n\n\tpublic refit(sessionId: SessionId): void {\n\t\tif (!this.enabled) return;\n\t\tthis._temperatures.set(sessionId, fitTemperature(this._recorder.getOutcomes(sessionId)));\n\t}\n\n\tpublic clearSession(sessionId: SessionId): void {\n\t\tif (!this.enabled) return;\n\t\tthis._temperatures.delete(sessionId);\n\t}\n\n\tpublic clearAll(): void {\n\t\tif (!this.enabled) return;\n\t\tthis._temperatures.clear();\n\t}\n}\n"],"names":["ECE_BINS","aggregatePerType","outcomes","sums","Map","o","prev","result","type","sum","count","brierScore","diff","expectedCalibrationError","binConfSum","Array","binAccSum","binCount","p","Math","EPSILON","idx","total","ece","i","n","meanConf","meanAcc","perTypeBrier","buckets","list","t","ALL_THOUGHT_TYPES","emptyMetrics","perType","Calibrator","outcomeRecorder","enabled","rawConfidence","sessionId","raw","typeStats","observedMean","priorWeight","shrunk","temperature","calibrated","MIN_OUTCOMES_FOR_TEMPERATURE","applyTemperature","undefined","fitTemperature"],"mappings":";;AAwCA,MAAMA,WAAW;AASjB,SAASC,iBACRC,QAAwC;IAExC,MAAMC,OAAO,IAAIC;IACjB,KAAK,MAAMC,KAAKH,SA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AC/C,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;QACnB,IAAI,CAAC,aAAa,CAAC,MAAM,CAACA;IAC3B;IAEO,WAAiB;QACvB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;QACnB,IAAI,CAAC,aAAa,CAAC,KAAK;IACzB;AACD"}
|
|
@@ -20,8 +20,6 @@ export declare const ALL_THOUGHT_TYPES: ThoughtType[];
|
|
|
20
20
|
* @returns Record mapping each ThoughtType to its occurrence count
|
|
21
21
|
*/
|
|
22
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
23
|
/**
|
|
26
24
|
* Compute the longest contiguous chain depth (sequence of thoughts without branching).
|
|
27
25
|
*
|
|
@@ -31,6 +29,4 @@ export declare const countByType: typeof _countByType;
|
|
|
31
29
|
* @returns Length of the longest non-branching chain (0 for empty history)
|
|
32
30
|
*/
|
|
33
31
|
export declare function _computeChainDepth(history: ThoughtData[]): number;
|
|
34
|
-
/** Alias of {@link _computeChainDepth} without the underscore prefix. */
|
|
35
|
-
export declare const computeChainDepth: typeof _computeChainDepth;
|
|
36
32
|
//# sourceMappingURL=internals.d.ts.map
|
|
@@ -1 +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,oCAAoC,CAAC;AACtE,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
|
|
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,oCAAoC,CAAC;AACtE,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;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,WAAW,EAAE,GAAG,MAAM,CAgBjE"}
|
|
@@ -22,7 +22,6 @@ function _countByType(history) {
|
|
|
22
22
|
}
|
|
23
23
|
return counts;
|
|
24
24
|
}
|
|
25
|
-
const countByType = _countByType;
|
|
26
25
|
function _computeChainDepth(history) {
|
|
27
26
|
if (0 === history.length) return 0;
|
|
28
27
|
let maxDepth = 1;
|
|
@@ -37,7 +36,6 @@ function _computeChainDepth(history) {
|
|
|
37
36
|
}
|
|
38
37
|
return maxDepth;
|
|
39
38
|
}
|
|
40
|
-
|
|
41
|
-
export { ALL_THOUGHT_TYPES, _computeChainDepth, _countByType, computeChainDepth, countByType };
|
|
39
|
+
export { ALL_THOUGHT_TYPES, _computeChainDepth, _countByType };
|
|
42
40
|
|
|
43
41
|
//# sourceMappingURL=internals.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core/evaluator/internals.js","sources":["../../../src/core/evaluator/internals.ts"],"sourcesContent":["/**\n * Shared internal helpers for evaluator submodules.\n *\n * Pure utility functions used by SignalComputer (and future evaluator\n * components such as StatsComputer / PatternDetector). All helpers are\n * stateless and have no side effects.\n *\n * @module core/evaluator/internals\n */\n\nimport type { ThoughtType } from '../../contracts/reasoning-types.js';\nimport type { ThoughtData } from '../thought.js';\n\n/** All valid thought types for distribution counting. */\nexport const ALL_THOUGHT_TYPES: ThoughtType[] = [\n\t'regular',\n\t'hypothesis',\n\t'verification',\n\t'critique',\n\t'synthesis',\n\t'meta',\n\t'tool_call',\n\t'tool_observation',\n\t'assumption',\n\t'decomposition',\n\t'backtrack',\n];\n\n/**\n * Count thoughts in `history` grouped by {@link ThoughtType}.\n *\n * Thoughts without an explicit `thought_type` are counted as `'regular'`.\n *\n * @param history - Thoughts to count\n * @returns Record mapping each ThoughtType to its occurrence count\n */\nexport function _countByType(history: ThoughtData[]): Record<ThoughtType, number> {\n\tconst counts = Object.fromEntries(ALL_THOUGHT_TYPES.map((t) => [t, 0])) as Record<\n\t\tThoughtType,\n\t\tnumber\n\t>;\n\n\tfor (const thought of history) {\n\t\tconst type = thought.thought_type ?? 'regular';\n\t\tif (type in counts) {\n\t\t\tcounts[type]++;\n\t\t}\n\t}\n\n\treturn counts;\n}\n\n
|
|
1
|
+
{"version":3,"file":"core/evaluator/internals.js","sources":["../../../src/core/evaluator/internals.ts"],"sourcesContent":["/**\n * Shared internal helpers for evaluator submodules.\n *\n * Pure utility functions used by SignalComputer (and future evaluator\n * components such as StatsComputer / PatternDetector). All helpers are\n * stateless and have no side effects.\n *\n * @module core/evaluator/internals\n */\n\nimport type { ThoughtType } from '../../contracts/reasoning-types.js';\nimport type { ThoughtData } from '../thought.js';\n\n/** All valid thought types for distribution counting. */\nexport const ALL_THOUGHT_TYPES: ThoughtType[] = [\n\t'regular',\n\t'hypothesis',\n\t'verification',\n\t'critique',\n\t'synthesis',\n\t'meta',\n\t'tool_call',\n\t'tool_observation',\n\t'assumption',\n\t'decomposition',\n\t'backtrack',\n];\n\n/**\n * Count thoughts in `history` grouped by {@link ThoughtType}.\n *\n * Thoughts without an explicit `thought_type` are counted as `'regular'`.\n *\n * @param history - Thoughts to count\n * @returns Record mapping each ThoughtType to its occurrence count\n */\nexport function _countByType(history: ThoughtData[]): Record<ThoughtType, number> {\n\tconst counts = Object.fromEntries(ALL_THOUGHT_TYPES.map((t) => [t, 0])) as Record<\n\t\tThoughtType,\n\t\tnumber\n\t>;\n\n\tfor (const thought of history) {\n\t\tconst type = thought.thought_type ?? 'regular';\n\t\tif (type in counts) {\n\t\t\tcounts[type]++;\n\t\t}\n\t}\n\n\treturn counts;\n}\n\n/**\n * Compute the longest contiguous chain depth (sequence of thoughts without branching).\n *\n * A new chain starts whenever a thought has `branch_from_thought` set.\n *\n * @param history - Thoughts in chronological order\n * @returns Length of the longest non-branching chain (0 for empty history)\n */\nexport function _computeChainDepth(history: ThoughtData[]): number {\n\tif (history.length === 0) return 0;\n\tlet maxDepth = 1;\n\tlet currentDepth = 1;\n\n\tfor (let i = 1; i < history.length; i++) {\n\t\tconst thought = history[i]!;\n\t\tif (!thought.branch_from_thought) {\n\t\t\tcurrentDepth++;\n\t\t\tmaxDepth = Math.max(maxDepth, currentDepth);\n\t\t} else {\n\t\t\tcurrentDepth = 1;\n\t\t}\n\t}\n\n\treturn maxDepth;\n}\n"],"names":["ALL_THOUGHT_TYPES","_countByType","history","counts","Object","t","thought","type","_computeChainDepth","maxDepth","currentDepth","i","Math"],"mappings":"AAcO,MAAMA,oBAAmC;IAC/C;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACA;AAUM,SAASC,aAAaC,OAAsB;IAClD,MAAMC,SAASC,OAAO,WAAW,CAACJ,kBAAkB,GAAG,CAAC,CAACK,IAAM;YAACA;YAAG;SAAE;IAKrE,KAAK,MAAMC,WAAWJ,QAAS;QAC9B,MAAMK,OAAOD,QAAQ,YAAY,IAAI;QACrC,IAAIC,QAAQJ,QACXA,MAAM,CAACI,KAAK;IAEd;IAEA,OAAOJ;AACR;AAUO,SAASK,mBAAmBN,OAAsB;IACxD,IAAIA,AAAmB,MAAnBA,QAAQ,MAAM,EAAQ,OAAO;IACjC,IAAIO,WAAW;IACf,IAAIC,eAAe;IAEnB,IAAK,IAAIC,IAAI,GAAGA,IAAIT,QAAQ,MAAM,EAAES,IAAK;QACxC,MAAML,UAAUJ,OAAO,CAACS,EAAE;QAC1B,IAAKL,QAAQ,mBAAmB,EAI/BI,eAAe;aAJkB;YACjCA;YACAD,WAAWG,KAAK,GAAG,CAACH,UAAUC;QAC/B;IAGD;IAEA,OAAOD;AACR"}
|
|
@@ -34,7 +34,7 @@ export type EdgeKind = 'sequence' | 'branch' | 'merge' | 'verifies' | 'critiques
|
|
|
34
34
|
* from: parentThought.id,
|
|
35
35
|
* to: childThought.id,
|
|
36
36
|
* kind: 'sequence',
|
|
37
|
-
* sessionId: '
|
|
37
|
+
* sessionId: asSessionId('analysis-session'),
|
|
38
38
|
* createdAt: Date.now(),
|
|
39
39
|
* };
|
|
40
40
|
* ```
|
|
@@ -10,7 +10,7 @@ import type { IEdgeStore } from '../../contracts/interfaces.js';
|
|
|
10
10
|
import type { Logger } from '../../logger/StructuredLogger.js';
|
|
11
11
|
import type { ThoughtData } from '../thought.js';
|
|
12
12
|
import type { ThoughtAdmissionContext } from '../IHistoryManager.js';
|
|
13
|
-
import { type BranchId
|
|
13
|
+
import { type BranchId } from '../../contracts/ids.js';
|
|
14
14
|
/** Minimal session view needed for edge emission. */
|
|
15
15
|
export interface EdgeEmissionSession {
|
|
16
16
|
thought_history: ThoughtData[];
|
|
@@ -19,8 +19,7 @@ export interface EdgeEmissionSession {
|
|
|
19
19
|
/** Configuration options for EdgeEmitter. */
|
|
20
20
|
export interface EdgeEmitterConfig {
|
|
21
21
|
edgeStore?: IEdgeStore;
|
|
22
|
-
dagEdges
|
|
23
|
-
defaultSessionId: SessionId;
|
|
22
|
+
dagEdges: boolean;
|
|
24
23
|
logger?: Logger;
|
|
25
24
|
}
|
|
26
25
|
/**
|
|
@@ -30,7 +29,6 @@ export interface EdgeEmitterConfig {
|
|
|
30
29
|
export declare class EdgeEmitter {
|
|
31
30
|
private readonly _edgeStore?;
|
|
32
31
|
private readonly _dagEdges;
|
|
33
|
-
private readonly _defaultSessionId;
|
|
34
32
|
private readonly _logger;
|
|
35
33
|
constructor(config: EdgeEmitterConfig);
|
|
36
34
|
/** Returns true when edge emission is active (store + flag both set). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EdgeEmitter.d.ts","sourceRoot":"","sources":["../../../src/core/graph/EdgeEmitter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAEhE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAE/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAA6B,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAEhG,OAAO,EAEN,KAAK,QAAQ,
|
|
1
|
+
{"version":3,"file":"EdgeEmitter.d.ts","sourceRoot":"","sources":["../../../src/core/graph/EdgeEmitter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAEhE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAE/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAA6B,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAEhG,OAAO,EAEN,KAAK,QAAQ,EAGb,MAAM,wBAAwB,CAAC;AAEhC,qDAAqD;AACrD,MAAM,WAAW,mBAAmB;IACnC,eAAe,EAAE,WAAW,EAAE,CAAC;IAC/B,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,WAAW,EAAE,CAAC,CAAC;CAC1C;AAED,6CAA6C;AAC7C,MAAM,WAAW,iBAAiB;IACjC,SAAS,CAAC,EAAE,UAAU,CAAC;IACvB,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,qBAAa,WAAW;IACvB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAa;IACzC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAU;IACpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,MAAM,EAAE,iBAAiB;IAMrC,yEAAyE;IAClE,SAAS,IAAI,OAAO;IAI3B;;;;;;;;;;;;;OAaG;IACI,mBAAmB,CACzB,OAAO,EAAE,mBAAmB,EAC5B,OAAO,EAAE,WAAW,EACpB,OAAO,CAAC,EAAE,uBAAuB,GAC/B,OAAO;IA6BV,OAAO,CAAC,eAAe;IAUvB,OAAO,CAAC,eAAe;IAYvB,OAAO,CAAC,qBAAqB;IAgB7B,OAAO,CAAC,iBAAiB;IAgBzB,OAAO,CAAC,mBAAmB;IAY3B,OAAO,CAAC,iBAAiB;IAUzB,OAAO,CAAC,uBAAuB;IAsB/B,OAAO,CAAC,iBAAiB;IAczB;;;;OAIG;IACH,OAAO,CAAC,eAAe;CA2CvB"}
|
|
@@ -4,12 +4,10 @@ import { generateEdgeId } from "../../contracts/ids.js";
|
|
|
4
4
|
class EdgeEmitter {
|
|
5
5
|
_edgeStore;
|
|
6
6
|
_dagEdges;
|
|
7
|
-
_defaultSessionId;
|
|
8
7
|
_logger;
|
|
9
8
|
constructor(config){
|
|
10
9
|
this._edgeStore = config.edgeStore;
|
|
11
|
-
this._dagEdges = config.dagEdges
|
|
12
|
-
this._defaultSessionId = config.defaultSessionId;
|
|
10
|
+
this._dagEdges = config.dagEdges;
|
|
13
11
|
this._logger = config.logger ?? new NullLogger();
|
|
14
12
|
}
|
|
15
13
|
isEnabled() {
|
|
@@ -18,7 +16,7 @@ class EdgeEmitter {
|
|
|
18
16
|
emitEdgesForThought(session, thought, context) {
|
|
19
17
|
if (!this._edgeStore || !this._dagEdges) return false;
|
|
20
18
|
if (!thought.id) return false;
|
|
21
|
-
const sessionId = thought.session_id
|
|
19
|
+
const sessionId = thought.session_id;
|
|
22
20
|
const references = context?.resolvedReferences ?? {};
|
|
23
21
|
const hasRelationalIntent = void 0 !== thought.branch_from_thought && void 0 !== thought.branch_id || (thought.merge_from_thoughts?.length ?? 0) > 0 || void 0 !== thought.verification_target && ('verification' === thought.thought_type || 'critique' === thought.thought_type) || (thought.synthesis_sources?.length ?? 0) > 0 || void 0 !== thought.revises_thought || 'tool_observation' === thought.thought_type && context?.toolInvocationSourceThoughtId !== void 0;
|
|
24
22
|
const emittedRelational = [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core/graph/EdgeEmitter.js","sources":["../../../src/core/graph/EdgeEmitter.ts"],"sourcesContent":["/**\n * EdgeEmitter — emits DAG edges for thoughts based on their metadata.\n *\n * Stateless helper extracted from HistoryManager. Holds a reference to an\n * optional `IEdgeStore` and a feature flag (`dagEdges`) gating writes.\n *\n * @module EdgeEmitter\n */\n\nimport type { IEdgeStore } from '../../contracts/interfaces.js';\nimport { getErrorMessage } from '../../errors.js';\nimport type { Logger } from '../../logger/StructuredLogger.js';\nimport { NullLogger } from '../../logger/NullLogger.js';\nimport type { ThoughtData } from '../thought.js';\nimport type { ResolvedThoughtReferences, ThoughtAdmissionContext } from '../IHistoryManager.js';\nimport type { Edge, EdgeKind } from './Edge.js';\nimport {\n\tgenerateEdgeId,\n\ttype BranchId,\n\ttype SessionId,\n\ttype ThoughtId,\n} from '../../contracts/ids.js';\n\n/** Minimal session view needed for edge emission. */\nexport interface EdgeEmissionSession {\n\tthought_history: ThoughtData[];\n\tbranches: Record<BranchId, ThoughtData[]>;\n}\n\n/** Configuration options for EdgeEmitter. */\nexport interface EdgeEmitterConfig {\n\tedgeStore?: IEdgeStore;\n\tdagEdges?: boolean;\n\tdefaultSessionId: SessionId;\n\tlogger?: Logger;\n}\n\n/**\n * Emits DAG edges for thought relationships when an `IEdgeStore` is configured\n * and the `dagEdges` feature flag is enabled. No-ops otherwise.\n */\nexport class EdgeEmitter {\n\tprivate readonly _edgeStore?: IEdgeStore;\n\tprivate readonly _dagEdges: boolean;\n\tprivate readonly _defaultSessionId: SessionId;\n\tprivate readonly _logger: Logger;\n\n\tconstructor(config: EdgeEmitterConfig) {\n\t\tthis._edgeStore = config.edgeStore;\n\t\tthis._dagEdges = config.dagEdges ?? true;\n\t\tthis._defaultSessionId = config.defaultSessionId;\n\t\tthis._logger = config.logger ?? new NullLogger();\n\t}\n\n\t/** Returns true when edge emission is active (store + flag both set). */\n\tpublic isEnabled(): boolean {\n\t\treturn this._edgeStore !== undefined && this._dagEdges;\n\t}\n\n\t/**\n\t * Emits DAG edges for a thought based on its metadata fields.\n\t *\n\t * Edge kinds (in priority order):\n\t * - branch: branch_from_thought + branch_id → parent.id → current.id\n\t * - merge: merge_from_thoughts → source.id → current.id (per source)\n\t * - verifies: verification_target + thought_type=verification → current.id → target.id\n\t * - critiques: verification_target + thought_type=critique → current.id → target.id\n\t * - derives_from: synthesis_sources → source.id → current.id (per source)\n\t * - revises: revises_thought → current.id → target.id\n\t * - tool_invocation: stable admission source id → current.id\n\t * - sequence: default chronological link from previous thought (if none of the above)\n\t * @returns True only when at least one edge was added to the store\n\t */\n\tpublic emitEdgesForThought(\n\t\tsession: EdgeEmissionSession,\n\t\tthought: ThoughtData,\n\t\tcontext?: ThoughtAdmissionContext\n\t): boolean {\n\t\tif (!this._edgeStore || !this._dagEdges) return false;\n\t\tif (!thought.id) return false;\n\n\t\tconst sessionId = thought.session_id ?? this._defaultSessionId;\n\t\tconst references = context?.resolvedReferences ?? {};\n\t\tconst hasRelationalIntent =\n\t\t\t(thought.branch_from_thought !== undefined && thought.branch_id !== undefined) ||\n\t\t\t(thought.merge_from_thoughts?.length ?? 0) > 0 ||\n\t\t\t(thought.verification_target !== undefined &&\n\t\t\t\t(thought.thought_type === 'verification' || thought.thought_type === 'critique')) ||\n\t\t\t(thought.synthesis_sources?.length ?? 0) > 0 ||\n\t\t\tthought.revises_thought !== undefined ||\n\t\t\t(thought.thought_type === 'tool_observation' &&\n\t\t\t\tcontext?.toolInvocationSourceThoughtId !== undefined);\n\t\tconst emittedRelational = [\n\t\t\tthis._emitBranchEdge(thought, references, sessionId),\n\t\t\tthis._emitMergeEdges(thought, references, sessionId),\n\t\t\tthis._emitVerificationEdge(thought, references, sessionId),\n\t\t\tthis._emitCritiqueEdge(thought, references, sessionId),\n\t\t\tthis._emitSynthesisEdges(thought, references, sessionId),\n\t\t\tthis._emitRevisionEdge(thought, references, sessionId),\n\t\t\tthis._emitToolInvocationEdge(thought, sessionId, context),\n\t\t].some((emitted) => emitted);\n\n\t\tif (emittedRelational || hasRelationalIntent) return emittedRelational;\n\t\treturn this._emitSequenceEdge(session, thought, sessionId);\n\t}\n\n\tprivate _emitBranchEdge(\n\t\tthought: ThoughtData,\n\t\treferences: ResolvedThoughtReferences,\n\t\tsessionId: SessionId\n\t): boolean {\n\t\tif (thought.branch_from_thought === undefined || !thought.branch_id) return false;\n\n\t\treturn this._addEdgeIfValid(references.branchFromThoughtId, thought.id, 'branch', sessionId);\n\t}\n\n\tprivate _emitMergeEdges(\n\t\tthought: ThoughtData,\n\t\treferences: ResolvedThoughtReferences,\n\t\tsessionId: SessionId\n\t): boolean {\n\t\tlet emitted = false;\n\t\tfor (const srcId of references.mergeFromThoughtIds ?? []) {\n\t\t\temitted = this._addEdgeIfValid(srcId, thought.id, 'merge', sessionId) || emitted;\n\t\t}\n\t\treturn emitted;\n\t}\n\n\tprivate _emitVerificationEdge(\n\t\tthought: ThoughtData,\n\t\treferences: ResolvedThoughtReferences,\n\t\tsessionId: SessionId\n\t): boolean {\n\t\tif (thought.verification_target === undefined || thought.thought_type !== 'verification')\n\t\t\treturn false;\n\n\t\treturn this._addEdgeIfValid(\n\t\t\tthought.id,\n\t\t\treferences.verificationTargetThoughtId,\n\t\t\t'verifies',\n\t\t\tsessionId\n\t\t);\n\t}\n\n\tprivate _emitCritiqueEdge(\n\t\tthought: ThoughtData,\n\t\treferences: ResolvedThoughtReferences,\n\t\tsessionId: SessionId\n\t): boolean {\n\t\tif (thought.verification_target === undefined || thought.thought_type !== 'critique')\n\t\t\treturn false;\n\n\t\treturn this._addEdgeIfValid(\n\t\t\tthought.id,\n\t\t\treferences.verificationTargetThoughtId,\n\t\t\t'critiques',\n\t\t\tsessionId\n\t\t);\n\t}\n\n\tprivate _emitSynthesisEdges(\n\t\tthought: ThoughtData,\n\t\treferences: ResolvedThoughtReferences,\n\t\tsessionId: SessionId\n\t): boolean {\n\t\tlet emitted = false;\n\t\tfor (const srcId of references.synthesisSourceThoughtIds ?? []) {\n\t\t\temitted = this._addEdgeIfValid(srcId, thought.id, 'derives_from', sessionId) || emitted;\n\t\t}\n\t\treturn emitted;\n\t}\n\n\tprivate _emitRevisionEdge(\n\t\tthought: ThoughtData,\n\t\treferences: ResolvedThoughtReferences,\n\t\tsessionId: SessionId\n\t): boolean {\n\t\tif (thought.revises_thought === undefined) return false;\n\n\t\treturn this._addEdgeIfValid(thought.id, references.revisesThoughtId, 'revises', sessionId);\n\t}\n\n\tprivate _emitToolInvocationEdge(\n\t\tthought: ThoughtData,\n\t\tsessionId: SessionId,\n\t\tcontext?: ThoughtAdmissionContext\n\t): boolean {\n\t\tif (\n\t\t\tthought.thought_type !== 'tool_observation' ||\n\t\t\tcontext?.toolInvocationSourceThoughtId === undefined\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst metadata = thought.tool_name !== undefined ? { tool_name: thought.tool_name } : undefined;\n\t\treturn this._addEdgeIfValid(\n\t\t\tcontext.toolInvocationSourceThoughtId,\n\t\t\tthought.id,\n\t\t\t'tool_invocation',\n\t\t\tsessionId,\n\t\t\tmetadata\n\t\t);\n\t}\n\n\tprivate _emitSequenceEdge(\n\t\tsession: EdgeEmissionSession,\n\t\tthought: ThoughtData,\n\t\tsessionId: SessionId\n\t): boolean {\n\t\tconst history = session.thought_history;\n\t\tif (history.length < 2) return false;\n\n\t\tconst prev = history[history.length - 2];\n\t\tif (!prev?.id) return false;\n\n\t\treturn this._addEdgeIfValid(prev.id, thought.id, 'sequence', sessionId);\n\t}\n\n\t/**\n\t * Adds an edge to the edge store if both endpoints are non-empty strings.\n\t * Returns true if added, false if skipped (missing endpoint).\n\t * Failures (e.g. self-edge) are caught and logged.\n\t */\n\tprivate _addEdgeIfValid(\n\t\tfrom: ThoughtId | undefined,\n\t\tto: ThoughtId | undefined,\n\t\tkind: EdgeKind,\n\t\tsessionId: SessionId,\n\t\tmetadata?: Record<string, unknown>\n\t): boolean {\n\t\tif (!from || !to) {\n\t\t\tthis._logger.debug('Skipping edge: unresolved endpoint', {\n\t\t\t\tkind,\n\t\t\t\tfrom: from ?? null,\n\t\t\t\tto: to ?? null,\n\t\t\t});\n\t\t\treturn false;\n\t\t}\n\t\tconst edge: Edge = {\n\t\t\tid: generateEdgeId(),\n\t\t\tfrom: from as Edge['from'],\n\t\t\tto: to as Edge['to'],\n\t\t\tkind,\n\t\t\tsessionId: sessionId as Edge['sessionId'],\n\t\t\tcreatedAt: Date.now(),\n\t\t\t...(metadata !== undefined ? { metadata } : {}),\n\t\t};\n\t\tif (!this._edgeStore) {\n\t\t\tthis._logger.warn('EdgeStore not available; skipping edge', { kind });\n\t\t\treturn false;\n\t\t}\n\t\tconst duplicate = this._edgeStore\n\t\t\t.edgesForSession(sessionId)\n\t\t\t.some((existing) => existing.kind === kind && existing.from === from && existing.to === to);\n\t\tif (duplicate) return false;\n\t\ttry {\n\t\t\tthis._edgeStore.addEdge(edge);\n\t\t\treturn true;\n\t\t} catch (err) {\n\t\t\tthis._logger.info('Failed to add DAG edge', {\n\t\t\t\tkind,\n\t\t\t\terror: getErrorMessage(err),\n\t\t\t});\n\t\t\treturn false;\n\t\t}\n\t}\n}\n"],"names":["EdgeEmitter","config","NullLogger","undefined","session","thought","context","sessionId","references","hasRelationalIntent","emittedRelational","emitted","srcId","metadata","history","prev","from","to","kind","edge","generateEdgeId","Date","duplicate","existing","err","getErrorMessage"],"mappings":";;;AAyCO,MAAMA;IACK,WAAwB;IACxB,UAAmB;IACnB,kBAA6B;IAC7B,QAAgB;IAEj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AAMF,QAAQ;gBACd,IAAIC,MAAM;YACX;YACA,OAAO;QACR;QACA,MAAME,OAAa;YAClB,IAAIC;YACJ,MAAMJ;YACN,IAAIC;YACJC;YACA,WAAWX;YACX,WAAWc,KAAK,GAAG;YACnB,GAAIR,AAAaV,WAAbU,WAAyB;gBAAEA;YAAS,IAAI,CAAC,CAAC;QAC/C;QACA,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;YACrB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,0CAA0C;gBAAEK;YAAK;YACnE,OAAO;QACR;QACA,MAAMI,YAAY,IAAI,CAAC,UAAU,CAC/B,eAAe,CAACf,WAChB,IAAI,CAAC,CAACgB,WAAaA,SAAS,IAAI,KAAKL,QAAQK,SAAS,IAAI,KAAKP,QAAQO,SAAS,EAAE,KAAKN;QACzF,IAAIK,WAAW,OAAO;QACtB,IAAI;YACH,IAAI,CAAC,UAAU,CAAC,OAAO,CAACH;YACxB,OAAO;QACR,EAAE,OAAOK,KAAK;YACb,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,0BAA0B;gBAC3CN;gBACA,OAAOO,gBAAgBD;YACxB;YACA,OAAO;QACR;IACD;AACD"}
|
|
1
|
+
{"version":3,"file":"core/graph/EdgeEmitter.js","sources":["../../../src/core/graph/EdgeEmitter.ts"],"sourcesContent":["/**\n * EdgeEmitter — emits DAG edges for thoughts based on their metadata.\n *\n * Stateless helper extracted from HistoryManager. Holds a reference to an\n * optional `IEdgeStore` and a feature flag (`dagEdges`) gating writes.\n *\n * @module EdgeEmitter\n */\n\nimport type { IEdgeStore } from '../../contracts/interfaces.js';\nimport { getErrorMessage } from '../../errors.js';\nimport type { Logger } from '../../logger/StructuredLogger.js';\nimport { NullLogger } from '../../logger/NullLogger.js';\nimport type { ThoughtData } from '../thought.js';\nimport type { ResolvedThoughtReferences, ThoughtAdmissionContext } from '../IHistoryManager.js';\nimport type { Edge, EdgeKind } from './Edge.js';\nimport {\n\tgenerateEdgeId,\n\ttype BranchId,\n\ttype SessionId,\n\ttype ThoughtId,\n} from '../../contracts/ids.js';\n\n/** Minimal session view needed for edge emission. */\nexport interface EdgeEmissionSession {\n\tthought_history: ThoughtData[];\n\tbranches: Record<BranchId, ThoughtData[]>;\n}\n\n/** Configuration options for EdgeEmitter. */\nexport interface EdgeEmitterConfig {\n\tedgeStore?: IEdgeStore;\n\tdagEdges: boolean;\n\tlogger?: Logger;\n}\n\n/**\n * Emits DAG edges for thought relationships when an `IEdgeStore` is configured\n * and the `dagEdges` feature flag is enabled. No-ops otherwise.\n */\nexport class EdgeEmitter {\n\tprivate readonly _edgeStore?: IEdgeStore;\n\tprivate readonly _dagEdges: boolean;\n\tprivate readonly _logger: Logger;\n\n\tconstructor(config: EdgeEmitterConfig) {\n\t\tthis._edgeStore = config.edgeStore;\n\t\tthis._dagEdges = config.dagEdges;\n\t\tthis._logger = config.logger ?? new NullLogger();\n\t}\n\n\t/** Returns true when edge emission is active (store + flag both set). */\n\tpublic isEnabled(): boolean {\n\t\treturn this._edgeStore !== undefined && this._dagEdges;\n\t}\n\n\t/**\n\t * Emits DAG edges for a thought based on its metadata fields.\n\t *\n\t * Edge kinds (in priority order):\n\t * - branch: branch_from_thought + branch_id → parent.id → current.id\n\t * - merge: merge_from_thoughts → source.id → current.id (per source)\n\t * - verifies: verification_target + thought_type=verification → current.id → target.id\n\t * - critiques: verification_target + thought_type=critique → current.id → target.id\n\t * - derives_from: synthesis_sources → source.id → current.id (per source)\n\t * - revises: revises_thought → current.id → target.id\n\t * - tool_invocation: stable admission source id → current.id\n\t * - sequence: default chronological link from previous thought (if none of the above)\n\t * @returns True only when at least one edge was added to the store\n\t */\n\tpublic emitEdgesForThought(\n\t\tsession: EdgeEmissionSession,\n\t\tthought: ThoughtData,\n\t\tcontext?: ThoughtAdmissionContext\n\t): boolean {\n\t\tif (!this._edgeStore || !this._dagEdges) return false;\n\t\tif (!thought.id) return false;\n\n\t\tconst sessionId = thought.session_id;\n\t\tconst references = context?.resolvedReferences ?? {};\n\t\tconst hasRelationalIntent =\n\t\t\t(thought.branch_from_thought !== undefined && thought.branch_id !== undefined) ||\n\t\t\t(thought.merge_from_thoughts?.length ?? 0) > 0 ||\n\t\t\t(thought.verification_target !== undefined &&\n\t\t\t\t(thought.thought_type === 'verification' || thought.thought_type === 'critique')) ||\n\t\t\t(thought.synthesis_sources?.length ?? 0) > 0 ||\n\t\t\tthought.revises_thought !== undefined ||\n\t\t\t(thought.thought_type === 'tool_observation' &&\n\t\t\t\tcontext?.toolInvocationSourceThoughtId !== undefined);\n\t\tconst emittedRelational = [\n\t\t\tthis._emitBranchEdge(thought, references, sessionId),\n\t\t\tthis._emitMergeEdges(thought, references, sessionId),\n\t\t\tthis._emitVerificationEdge(thought, references, sessionId),\n\t\t\tthis._emitCritiqueEdge(thought, references, sessionId),\n\t\t\tthis._emitSynthesisEdges(thought, references, sessionId),\n\t\t\tthis._emitRevisionEdge(thought, references, sessionId),\n\t\t\tthis._emitToolInvocationEdge(thought, sessionId, context),\n\t\t].some((emitted) => emitted);\n\n\t\tif (emittedRelational || hasRelationalIntent) return emittedRelational;\n\t\treturn this._emitSequenceEdge(session, thought, sessionId);\n\t}\n\n\tprivate _emitBranchEdge(\n\t\tthought: ThoughtData,\n\t\treferences: ResolvedThoughtReferences,\n\t\tsessionId: SessionId\n\t): boolean {\n\t\tif (thought.branch_from_thought === undefined || !thought.branch_id) return false;\n\n\t\treturn this._addEdgeIfValid(references.branchFromThoughtId, thought.id, 'branch', sessionId);\n\t}\n\n\tprivate _emitMergeEdges(\n\t\tthought: ThoughtData,\n\t\treferences: ResolvedThoughtReferences,\n\t\tsessionId: SessionId\n\t): boolean {\n\t\tlet emitted = false;\n\t\tfor (const srcId of references.mergeFromThoughtIds ?? []) {\n\t\t\temitted = this._addEdgeIfValid(srcId, thought.id, 'merge', sessionId) || emitted;\n\t\t}\n\t\treturn emitted;\n\t}\n\n\tprivate _emitVerificationEdge(\n\t\tthought: ThoughtData,\n\t\treferences: ResolvedThoughtReferences,\n\t\tsessionId: SessionId\n\t): boolean {\n\t\tif (thought.verification_target === undefined || thought.thought_type !== 'verification')\n\t\t\treturn false;\n\n\t\treturn this._addEdgeIfValid(\n\t\t\tthought.id,\n\t\t\treferences.verificationTargetThoughtId,\n\t\t\t'verifies',\n\t\t\tsessionId\n\t\t);\n\t}\n\n\tprivate _emitCritiqueEdge(\n\t\tthought: ThoughtData,\n\t\treferences: ResolvedThoughtReferences,\n\t\tsessionId: SessionId\n\t): boolean {\n\t\tif (thought.verification_target === undefined || thought.thought_type !== 'critique')\n\t\t\treturn false;\n\n\t\treturn this._addEdgeIfValid(\n\t\t\tthought.id,\n\t\t\treferences.verificationTargetThoughtId,\n\t\t\t'critiques',\n\t\t\tsessionId\n\t\t);\n\t}\n\n\tprivate _emitSynthesisEdges(\n\t\tthought: ThoughtData,\n\t\treferences: ResolvedThoughtReferences,\n\t\tsessionId: SessionId\n\t): boolean {\n\t\tlet emitted = false;\n\t\tfor (const srcId of references.synthesisSourceThoughtIds ?? []) {\n\t\t\temitted = this._addEdgeIfValid(srcId, thought.id, 'derives_from', sessionId) || emitted;\n\t\t}\n\t\treturn emitted;\n\t}\n\n\tprivate _emitRevisionEdge(\n\t\tthought: ThoughtData,\n\t\treferences: ResolvedThoughtReferences,\n\t\tsessionId: SessionId\n\t): boolean {\n\t\tif (thought.revises_thought === undefined) return false;\n\n\t\treturn this._addEdgeIfValid(thought.id, references.revisesThoughtId, 'revises', sessionId);\n\t}\n\n\tprivate _emitToolInvocationEdge(\n\t\tthought: ThoughtData,\n\t\tsessionId: SessionId,\n\t\tcontext?: ThoughtAdmissionContext\n\t): boolean {\n\t\tif (\n\t\t\tthought.thought_type !== 'tool_observation' ||\n\t\t\tcontext?.toolInvocationSourceThoughtId === undefined\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst metadata = thought.tool_name !== undefined ? { tool_name: thought.tool_name } : undefined;\n\t\treturn this._addEdgeIfValid(\n\t\t\tcontext.toolInvocationSourceThoughtId,\n\t\t\tthought.id,\n\t\t\t'tool_invocation',\n\t\t\tsessionId,\n\t\t\tmetadata\n\t\t);\n\t}\n\n\tprivate _emitSequenceEdge(\n\t\tsession: EdgeEmissionSession,\n\t\tthought: ThoughtData,\n\t\tsessionId: SessionId\n\t): boolean {\n\t\tconst history = session.thought_history;\n\t\tif (history.length < 2) return false;\n\n\t\tconst prev = history[history.length - 2];\n\t\tif (!prev?.id) return false;\n\n\t\treturn this._addEdgeIfValid(prev.id, thought.id, 'sequence', sessionId);\n\t}\n\n\t/**\n\t * Adds an edge to the edge store if both endpoints are non-empty strings.\n\t * Returns true if added, false if skipped (missing endpoint).\n\t * Failures (e.g. self-edge) are caught and logged.\n\t */\n\tprivate _addEdgeIfValid(\n\t\tfrom: ThoughtId | undefined,\n\t\tto: ThoughtId | undefined,\n\t\tkind: EdgeKind,\n\t\tsessionId: SessionId,\n\t\tmetadata?: Record<string, unknown>\n\t): boolean {\n\t\tif (!from || !to) {\n\t\t\tthis._logger.debug('Skipping edge: unresolved endpoint', {\n\t\t\t\tkind,\n\t\t\t\tfrom: from ?? null,\n\t\t\t\tto: to ?? null,\n\t\t\t});\n\t\t\treturn false;\n\t\t}\n\t\tconst edge: Edge = {\n\t\t\tid: generateEdgeId(),\n\t\t\tfrom: from as Edge['from'],\n\t\t\tto: to as Edge['to'],\n\t\t\tkind,\n\t\t\tsessionId: sessionId as Edge['sessionId'],\n\t\t\tcreatedAt: Date.now(),\n\t\t\t...(metadata !== undefined ? { metadata } : {}),\n\t\t};\n\t\tif (!this._edgeStore) {\n\t\t\tthis._logger.warn('EdgeStore not available; skipping edge', { kind });\n\t\t\treturn false;\n\t\t}\n\t\tconst duplicate = this._edgeStore\n\t\t\t.edgesForSession(sessionId)\n\t\t\t.some((existing) => existing.kind === kind && existing.from === from && existing.to === to);\n\t\tif (duplicate) return false;\n\t\ttry {\n\t\t\tthis._edgeStore.addEdge(edge);\n\t\t\treturn true;\n\t\t} catch (err) {\n\t\t\tthis._logger.info('Failed to add DAG edge', {\n\t\t\t\tkind,\n\t\t\t\terror: getErrorMessage(err),\n\t\t\t});\n\t\t\treturn false;\n\t\t}\n\t}\n}\n"],"names":["EdgeEmitter","config","NullLogger","undefined","session","thought","context","sessionId","references","hasRelationalIntent","emittedRelational","emitted","srcId","metadata","history","prev","from","to","kind","edge","generateEdgeId","Date","duplicate","existing","err","getErrorMessage"],"mappings":";;;AAwCO,MAAMA;IACK,WAAwB;IACxB,UAAmB;IACnB,QAAgB;IAEjC,YAAYC,MAAyB,CAAE;QACtC,IAAI,CAAC,UAAU,GAAGA,OAAO,SAAS;QAClC,IAAI,CAAC,SAAS,GAAGA,OAAO,QAAQ;QAChC,IAAI,CAAC,OAAO,GAAGA,OAAO,MAAM,IAAI,IAAIC;IACrC;IAGO,YAAqB;QAC3B,OAAO,AAAoBC,WAApB,IAAI,CAAC,UAAU,IAAkB,IAAI,CAAC,SAAS;IACvD;IAgBO,oBACNC,OAA4B,EAC5BC,OAAoB,EACpBC,OAAiC,EACvB;QACV,IAAI,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO;QAChD,IAAI,CAACD,QAAQ,EAAE,EAAE,OAAO;QAExB,MAAME,YAAYF,QAAQ,UAAU;QACpC,MAAMG,aAAaF,SAAS,sBAAsB,CAAC;QACnD,MAAMG,sBACJJ,AAAgCF,WAAhCE,QAAQ,mBAAmB,IAAkBA,AAAsBF,WAAtBE,QAAQ,SAAS,IAC9DA,AAAAA,CAAAA,QAAQ,mBAAmB,EAAE,UAAU,KAAK,KAC5CA,AAAgCF,WAAhCE,QAAQ,mBAAmB,IAC1BA,CAAAA,AAAyB,mBAAzBA,QAAQ,YAAY,IAAuBA,AAAyB,eAAzBA,QAAQ,YAAY,AAAc,KAC9EA,AAAAA,CAAAA,QAAQ,iBAAiB,EAAE,UAAU,KAAK,KAC3CA,AAA4BF,WAA5BE,QAAQ,eAAe,IACtBA,AAAyB,uBA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ACA,KAAK,EAAE,EAAEV,QAAQ,EAAE,EAAE,YAAYE;IAC9D;IAOQ,gBACPS,IAA2B,EAC3BC,EAAyB,EACzBC,IAAc,EACdX,SAAoB,EACpBM,QAAkC,EACxB;QACV,IAAI,CAACG,QAAQ,CAACC,IAAI;YACjB,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,sCAAsC;gBACxDC;gBACA,MAAMF,QAAQ;gBACd,IAAIC,MAAM;YACX;YACA,OAAO;QACR;QACA,MAAME,OAAa;YAClB,IAAIC;YACJ,MAAMJ;YACN,IAAIC;YACJC;YACA,WAAWX;YACX,WAAWc,KAAK,GAAG;YACnB,GAAIR,AAAaV,WAAbU,WAAyB;gBAAEA;YAAS,IAAI,CAAC,CAAC;QAC/C;QACA,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;YACrB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,0CAA0C;gBAAEK;YAAK;YACnE,OAAO;QACR;QACA,MAAMI,YAAY,IAAI,CAAC,UAAU,CAC/B,eAAe,CAACf,WAChB,IAAI,CAAC,CAACgB,WAAaA,SAAS,IAAI,KAAKL,QAAQK,SAAS,IAAI,KAAKP,QAAQO,SAAS,EAAE,KAAKN;QACzF,IAAIK,WAAW,OAAO;QACtB,IAAI;YACH,IAAI,CAAC,UAAU,CAAC,OAAO,CAACH;YACxB,OAAO;QACR,EAAE,OAAOK,KAAK;YACb,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,0BAA0B;gBAC3CN;gBACA,OAAOO,gBAAgBD;YACxB;YACA,OAAO;QACR;IACD;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OutcomeRecorder.d.ts","sourceRoot":"","sources":["../../../src/core/reasoning/OutcomeRecorder.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAC3F,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAGnE;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACrC,4CAA4C;IAC5C,OAAO,EAAE,OAAO,CAAC;CACjB;AAED
|
|
1
|
+
{"version":3,"file":"OutcomeRecorder.d.ts","sourceRoot":"","sources":["../../../src/core/reasoning/OutcomeRecorder.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAC3F,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAGnE;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACrC,4CAA4C;IAC5C,OAAO,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,eAAgB,YAAW,gBAAgB;IACvD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAkE;IAC5F,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAU;IAEnC;;OAEG;IACH,IAAW,OAAO,IAAI,OAAO,CAE5B;IAED;;;;OAIG;gBACS,MAAM,EAAE,qBAAqB;IAIzC;;;;;;OAMG;IACH,eAAe,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,GAAG,IAAI;IAUjE;;;;;;OAMG;IACH,kBAAkB,CAAC,OAAO,EAAE,IAAI,CAAC,mBAAmB,EAAE,YAAY,CAAC,GAAG,IAAI;IAc1E;;;;;OAKG;IACH,WAAW,CAAC,SAAS,EAAE,SAAS,GAAG,mBAAmB,EAAE;IAKxD;;;;OAIG;IACH,cAAc,IAAI,mBAAmB,EAAE;IASvC;;;;OAIG;IACH,aAAa,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI;IAIzC,gBAAgB,IAAI,IAAI;CAGxB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core/reasoning/OutcomeRecorder.js","sources":["../../../src/core/reasoning/OutcomeRecorder.ts"],"sourcesContent":["/**\n * Records verification outcomes for confidence calibration.\n *\n * No-op implementation when feature flag is disabled.\n * Stores outcomes per-session in memory for later calibration use.\n *\n * @module core/reasoning/OutcomeRecorder\n */\n\nimport type { IOutcomeRecorder, VerificationOutcome } from '../../contracts/interfaces.js';\nimport type { SessionId, ThoughtId } from '../../contracts/ids.js';\nimport { ValidationError } from '../../errors.js';\n\n/**\n * Configuration for OutcomeRecorder.\n */\nexport interface OutcomeRecorderConfig {\n\t/** Whether outcome recording is enabled. */\n\tenabled: boolean;\n}\n\n/**\n * Records verification outcomes for confidence calibration.\n *\n * When disabled (default), all methods are no-ops and return empty arrays.\n * When enabled, outcomes are stored in memory per-session.\n *\n * @example\n * ```typescript\n * const recorder = new OutcomeRecorder({ enabled: true });\n * recorder.recordVerification({\n * thoughtId: 't1',\n *
|
|
1
|
+
{"version":3,"file":"core/reasoning/OutcomeRecorder.js","sources":["../../../src/core/reasoning/OutcomeRecorder.ts"],"sourcesContent":["/**\n * Records verification outcomes for confidence calibration.\n *\n * No-op implementation when feature flag is disabled.\n * Stores outcomes per-session in memory for later calibration use.\n *\n * @module core/reasoning/OutcomeRecorder\n */\n\nimport type { IOutcomeRecorder, VerificationOutcome } from '../../contracts/interfaces.js';\nimport type { SessionId, ThoughtId } from '../../contracts/ids.js';\nimport { ValidationError } from '../../errors.js';\n\n/**\n * Configuration for OutcomeRecorder.\n */\nexport interface OutcomeRecorderConfig {\n\t/** Whether outcome recording is enabled. */\n\tenabled: boolean;\n}\n\n/**\n * Records verification outcomes for confidence calibration.\n *\n * When disabled (default), all methods are no-ops and return empty arrays.\n * When enabled, outcomes are stored in memory per-session.\n *\n * @example\n * ```typescript\n * const recorder = new OutcomeRecorder({ enabled: true });\n * recorder.recordVerification({\n * thoughtId: 't1',\n * sessionId: 'session-a',\n * predicted: 0.8,\n * actual: 1,\n * type: 'verification',\n * });\n * const outcomes = recorder.getOutcomes('session-a');\n * ```\n */\nexport class OutcomeRecorder implements IOutcomeRecorder {\n\tprivate readonly _outcomes: Map<SessionId, Map<ThoughtId, VerificationOutcome>> = new Map();\n\tprivate readonly _enabled: boolean;\n\n\t/**\n\t * Whether outcome recording is currently enabled.\n\t */\n\tpublic get enabled(): boolean {\n\t\treturn this._enabled;\n\t}\n\n\t/**\n\t * Create a new OutcomeRecorder.\n\t *\n\t * @param config - Recorder configuration\n\t */\n\tconstructor(config: OutcomeRecorderConfig) {\n\t\tthis._enabled = config.enabled;\n\t}\n\n\t/**\n\t * Assert that a target is available for one outcome label.\n\t *\n\t * @param sessionId - Canonical session namespace\n\t * @param thoughtId - Stable target identity\n\t * @throws {ValidationError} When the target was already labeled\n\t */\n\tassertCanRecord(sessionId: SessionId, thoughtId: ThoughtId): void {\n\t\tif (!this._enabled) return;\n\t\tif (this._outcomes.get(sessionId)?.has(thoughtId)) {\n\t\t\tthrow new ValidationError(\n\t\t\t\t'verification_result',\n\t\t\t\t'The verification target already has a recorded result'\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Record a verification outcome.\n\t *\n\t * No-op when outcome recording is disabled.\n\t *\n\t * @param outcome - The outcome data (recordedAt is auto-set)\n\t */\n\trecordVerification(outcome: Omit<VerificationOutcome, 'recordedAt'>): void {\n\t\tif (!this._enabled) return;\n\t\tthis.assertCanRecord(outcome.sessionId, outcome.thoughtId);\n\n\t\tconst full: VerificationOutcome = {\n\t\t\t...outcome,\n\t\t\trecordedAt: Date.now(),\n\t\t};\n\n\t\tconst sessionOutcomes = this._outcomes.get(outcome.sessionId) ?? new Map();\n\t\tsessionOutcomes.set(outcome.thoughtId, full);\n\t\tthis._outcomes.set(outcome.sessionId, sessionOutcomes);\n\t}\n\n\t/**\n\t * Get all recorded outcomes for a session.\n\t *\n\t * @param sessionId - The session id to query\n\t * @returns Array of outcomes (empty when disabled or no data)\n\t */\n\tgetOutcomes(sessionId: SessionId): VerificationOutcome[] {\n\t\tif (!this._enabled) return [];\n\t\treturn [...(this._outcomes.get(sessionId)?.values() ?? [])].map((outcome) => ({ ...outcome }));\n\t}\n\n\t/**\n\t * Get outcomes across all sessions.\n\t *\n\t * @returns Flat array of all outcomes (empty when disabled)\n\t */\n\tgetAllOutcomes(): VerificationOutcome[] {\n\t\tif (!this._enabled) return [];\n\t\tconst all: VerificationOutcome[] = [];\n\t\tfor (const outcomes of this._outcomes.values()) {\n\t\t\tfor (const outcome of outcomes.values()) all.push({ ...outcome });\n\t\t}\n\t\treturn all;\n\t}\n\n\t/**\n\t * Clear outcomes for a specific session.\n\t *\n\t * @param sessionId - The session id to clear\n\t */\n\tclearOutcomes(sessionId: SessionId): void {\n\t\tthis._outcomes.delete(sessionId);\n\t}\n\n\tclearAllOutcomes(): void {\n\t\tthis._outcomes.clear();\n\t}\n}\n"],"names":["OutcomeRecorder","Map","config","sessionId","thoughtId","ValidationError","outcome","full","Date","sessionOutcomes","all","outcomes"],"mappings":";AAwCO,MAAMA;IACK,YAAiE,IAAIC,MAAM;IAC3E,SAAkB;IAKnC,IAAW,UAAmB;QAC7B,OAAO,IAAI,CAAC,QAAQ;IACrB;IAOA,YAAYC,MAA6B,CAAE;QAC1C,IAAI,CAAC,QAAQ,GAAGA,OAAO,OAAO;IAC/B;IASA,gBAAgBC,SAAoB,EAAEC,SAAoB,EAAQ;QACjE,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;QACpB,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAACD,YAAY,IAAIC,YACtC,MAAM,IAAIC,gBACT,uBACA;IAGH;IASA,mBAAmBC,OAAgD,EAAQ;QAC1E,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;QACpB,IAAI,CAAC,eAAe,CAACA,QAAQ,SAAS,EAAEA,QAAQ,SAAS;QAEzD,MAAMC,OAA4B;YACjC,GAAGD,OAAO;YACV,YAAYE,KAAK,GAAG;QACrB;QAEA,MAAMC,kBAAkB,IAAI,CAAC,SAAS,CAAC,GAAG,CAACH,QAAQ,SAAS,KAAK,IAAIL;QACrEQ,gBAAgB,GAAG,CAACH,QAAQ,SAAS,EAAEC;QACvC,IAAI,CAAC,SAAS,CAAC,GAAG,CAACD,QAAQ,SAAS,EAAEG;IACvC;IAQA,YAAYN,SAAoB,EAAyB;QACxD,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE;QAC7B,OAAO;eAAK,IAAI,CAAC,SAAS,CAAC,GAAG,CAACA,YAAY,YAAY,EAAE;SAAE,CAAC,GAAG,CAAC,CAACG,UAAa;gBAAE,GAAGA,OAAO;YAAC;IAC5F;IAOA,iBAAwC;QACvC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE;QAC7B,MAAMI,MAA6B,EAAE;QACrC,KAAK,MAAMC,YAAY,IAAI,CAAC,SAAS,CAAC,MAAM,GAC3C,KAAK,MAAML,WAAWK,SAAS,MAAM,GAAID,IAAI,IAAI,CAAC;YAAE,GAAGJ,OAAO;QAAC;QAEhE,OAAOI;IACR;IAOA,cAAcP,SAAoB,EAAQ;QACzC,IAAI,CAAC,SAAS,CAAC,MAAM,CAACA;IACvB;IAEA,mBAAyB;QACxB,IAAI,CAAC,SAAS,CAAC,KAAK;IACrB;AACD"}
|
|
@@ -10,15 +10,15 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import type { IReasoningStrategy, StrategyContext, StrategyDecision } from '../../../contracts/strategy.js';
|
|
12
12
|
/**
|
|
13
|
-
* Default sequential strategy.
|
|
13
|
+
* Default sequential strategy. Applies the linear thinking flow:
|
|
14
14
|
*
|
|
15
15
|
* - Continue while `next_thought_needed` is truthy (or unset).
|
|
16
16
|
* - Terminate as soon as `next_thought_needed === false`.
|
|
17
17
|
* - Branch when both `branch_from_thought` and `branch_id` are present.
|
|
18
18
|
*
|
|
19
19
|
* Type-agnostic: all `ThoughtType` variants (including `assumption`,
|
|
20
|
-
* `decomposition`, `backtrack`, `tool_call`, `tool_observation
|
|
21
|
-
*
|
|
20
|
+
* `decomposition`, `backtrack`, `tool_call`, and `tool_observation`) pass
|
|
21
|
+
* through unchanged. The strategy intentionally inspects
|
|
22
22
|
* only `next_thought_needed`, `branch_from_thought`, and `branch_id` —
|
|
23
23
|
* type-aware behavior lives in evaluator/scoring layers, not here.
|
|
24
24
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core/reasoning/strategies/SequentialStrategy.js","sources":["../../../../src/core/reasoning/strategies/SequentialStrategy.ts"],"sourcesContent":["/**\n * Sequential reasoning strategy — the default policy that preserves existing\n * {@link ThoughtProcessor} behavior. Continues the chain unless the current\n * thought explicitly signals termination via `next_thought_needed === false`.\n *\n * Pure policy: no mutable state, no I/O, no module-level variables. All\n * methods are deterministic functions of their inputs.\n *\n * @module core/reasoning/strategies/SequentialStrategy\n */\n\nimport type {\n\tIReasoningStrategy,\n\tStrategyContext,\n\tStrategyDecision,\n} from '../../../contracts/strategy.js';\n\n/**\n * Default sequential strategy.
|
|
1
|
+
{"version":3,"file":"core/reasoning/strategies/SequentialStrategy.js","sources":["../../../../src/core/reasoning/strategies/SequentialStrategy.ts"],"sourcesContent":["/**\n * Sequential reasoning strategy — the default policy that preserves existing\n * {@link ThoughtProcessor} behavior. Continues the chain unless the current\n * thought explicitly signals termination via `next_thought_needed === false`.\n *\n * Pure policy: no mutable state, no I/O, no module-level variables. All\n * methods are deterministic functions of their inputs.\n *\n * @module core/reasoning/strategies/SequentialStrategy\n */\n\nimport type {\n\tIReasoningStrategy,\n\tStrategyContext,\n\tStrategyDecision,\n} from '../../../contracts/strategy.js';\n\n/**\n * Default sequential strategy. Applies the linear thinking flow:\n *\n * - Continue while `next_thought_needed` is truthy (or unset).\n * - Terminate as soon as `next_thought_needed === false`.\n * - Branch when both `branch_from_thought` and `branch_id` are present.\n *\n * Type-agnostic: all `ThoughtType` variants (including `assumption`,\n * `decomposition`, `backtrack`, `tool_call`, and `tool_observation`) pass\n * through unchanged. The strategy intentionally inspects\n * only `next_thought_needed`, `branch_from_thought`, and `branch_id` —\n * type-aware behavior lives in evaluator/scoring layers, not here.\n *\n * @example\n * ```ts\n * const strategy = new SequentialStrategy();\n * const decision = strategy.decide(ctx);\n * if (decision.action === 'terminate') stop();\n * ```\n */\nexport class SequentialStrategy implements IReasoningStrategy {\n\treadonly name = 'sequential' as const;\n\n\t/**\n\t * Compute the next action for the chain.\n\t *\n\t * @param ctx - Read-only session snapshot.\n\t * @returns `{ action: 'terminate' }` when current thought signals stop,\n\t * otherwise `{ action: 'continue' }`.\n\t */\n\tdecide(ctx: StrategyContext): StrategyDecision {\n\t\tif (ctx.currentThought.next_thought_needed === false) {\n\t\t\treturn { action: 'terminate', reason: 'next_thought_needed=false' };\n\t\t}\n\t\treturn { action: 'continue' };\n\t}\n\n\t/**\n\t * Predicate: should the chain branch right now?\n\t * True iff both `branch_from_thought` and `branch_id` are set on the\n\t * current thought.\n\t */\n\tshouldBranch(ctx: StrategyContext): boolean {\n\t\tconst t = ctx.currentThought;\n\t\treturn t.branch_from_thought !== undefined && t.branch_id !== undefined;\n\t}\n\n\t/**\n\t * Predicate: should the chain terminate right now?\n\t * True iff `next_thought_needed === false`.\n\t */\n\tshouldTerminate(ctx: StrategyContext): boolean {\n\t\treturn ctx.currentThought.next_thought_needed === false;\n\t}\n}\n"],"names":["SequentialStrategy","ctx","t","undefined"],"mappings":"AAqCO,MAAMA;IACH,OAAO,aAAsB;IAStC,OAAOC,GAAoB,EAAoB;QAC9C,IAAIA,AAA2C,UAA3CA,IAAI,cAAc,CAAC,mBAAmB,EACzC,OAAO;YAAE,QAAQ;YAAa,QAAQ;QAA4B;QAEnE,OAAO;YAAE,QAAQ;QAAW;IAC7B;IAOA,aAAaA,GAAoB,EAAW;QAC3C,MAAMC,IAAID,IAAI,cAAc;QAC5B,OAAOC,AAA0BC,WAA1BD,EAAE,mBAAmB,IAAkBA,AAAgBC,WAAhBD,EAAE,SAAS;IAC1D;IAMA,gBAAgBD,GAAoB,EAAW;QAC9C,OAAOA,AAA2C,UAA3CA,IAAI,cAAc,CAAC,mBAAmB;IAC9C;AACD"}
|
package/dist/core/thought.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ import type { StepRecommendation } from './step.js';
|
|
|
27
27
|
* thought: 'I should read the package.json to understand dependencies',
|
|
28
28
|
* thought_number: 1,
|
|
29
29
|
* total_thoughts: 5,
|
|
30
|
+
* session_id: asSessionId('package-analysis'),
|
|
30
31
|
* next_thought_needed: true,
|
|
31
32
|
* current_step: {
|
|
32
33
|
* step_description: 'Read package.json',
|
|
@@ -45,7 +46,7 @@ export type ThoughtData = Omit<SchemaOutput, 'id' | 'session_id' | 'continuation
|
|
|
45
46
|
/** Unique identifier for this thought (branded ThoughtId). Auto-generated when not provided. */
|
|
46
47
|
id?: ThoughtId;
|
|
47
48
|
/** Session identifier (branded SessionId) for state isolation. */
|
|
48
|
-
session_id
|
|
49
|
+
session_id: SessionId;
|
|
49
50
|
/** Continuation token (branded SuspensionToken) linking tool_observation back to suspended tool_call. */
|
|
50
51
|
continuation_token?: SuspensionToken;
|
|
51
52
|
/** Branch identifier (branded BranchId) for branching reasoning paths. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thought.d.ts","sourceRoot":"","sources":["../../src/core/thought.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACpD
|
|
1
|
+
{"version":3,"file":"thought.d.ts","sourceRoot":"","sources":["../../src/core/thought.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cA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Q,CAAC,gBAAgB,EAAE,MAAM,CAAC;CAClC,CAAC;AAEF,sEAAsE;AACtE,MAAM,MAAM,mBAAmB,GAAG,WAAW,GAAG;IAC/C,QAAQ,CAAC,YAAY,EAAE,cAAc,CAAC;IACtC,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;CACrC,CAAC;AAEF,kEAAkE;AAClE,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG;IAC3C,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC;IAClC,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;CACrC,CAAC;AAEF,2EAA2E;AAC3E,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG;IAC5C,QAAQ,CAAC,YAAY,EAAE,WAAW,CAAC;IACnC,QAAQ,CAAC,iBAAiB,EAAE,SAAS,MAAM,EAAE,CAAC;CAC9C,CAAC;AAEF,qEAAqE;AACrE,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG;IACvC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAC7B,WAAW,EACX,WAAW,GAAG,kBAAkB,GAAG,WAAW,GAAG,cAAc,GAAG,UAAU,GAAG,WAAW,CAC1F,CAAC;CACF,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GACzB,eAAe,GACf,sBAAsB,GACtB,gBAAgB,GAChB,mBAAmB,GACnB,eAAe,GACf,gBAAgB,GAChB,WAAW,CAAC"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -63,13 +63,9 @@ export declare const ERROR_CODES: {
|
|
|
63
63
|
readonly PERSISTENCE_DRAIN: "PERSISTENCE_DRAIN";
|
|
64
64
|
readonly PERSISTENCE_SESSION_ADMISSION_CLOSED: "PERSISTENCE_SESSION_ADMISSION_CLOSED";
|
|
65
65
|
readonly PERSISTENCE_SESSION_BARRIER_REENTRANCY: "PERSISTENCE_SESSION_BARRIER_REENTRANCY";
|
|
66
|
-
readonly ASYNC_RESET_REQUIRED: "ASYNC_RESET_REQUIRED";
|
|
67
|
-
readonly PERSISTENCE_CAPABILITY_UNSUPPORTED: "PERSISTENCE_CAPABILITY_UNSUPPORTED";
|
|
68
66
|
readonly PERSISTENCE_SCOPE_MISMATCH: "PERSISTENCE_SCOPE_MISMATCH";
|
|
69
67
|
readonly PERSISTENCE_UNAVAILABLE: "PERSISTENCE_UNAVAILABLE";
|
|
70
68
|
readonly PERSISTENCE_COMPATIBILITY: "PERSISTENCE_COMPATIBILITY";
|
|
71
|
-
readonly PERSISTENCE_IMPORT_REQUIRED: "PERSISTENCE_IMPORT_REQUIRED";
|
|
72
|
-
readonly PERSISTENCE_LEGACY_AMBIGUITY: "PERSISTENCE_LEGACY_AMBIGUITY";
|
|
73
69
|
};
|
|
74
70
|
export type ErrorCode = (typeof ERROR_CODES)[keyof typeof ERROR_CODES];
|
|
75
71
|
/**
|
|
@@ -138,7 +134,7 @@ export declare class ConfigurationError extends SequentialThinkingError {
|
|
|
138
134
|
*
|
|
139
135
|
* @example
|
|
140
136
|
* ```typescript
|
|
141
|
-
* const tool = registry.
|
|
137
|
+
* const tool = registry.get('non-existent-tool');
|
|
142
138
|
* if (!tool) {
|
|
143
139
|
* throw new ToolNotFoundError('non-existent-tool');
|
|
144
140
|
* }
|
|
@@ -171,7 +167,7 @@ export declare class ToolNotFoundError extends SequentialThinkingError {
|
|
|
171
167
|
*
|
|
172
168
|
* @example
|
|
173
169
|
* ```typescript
|
|
174
|
-
* const skill = registry.
|
|
170
|
+
* const skill = registry.get('non-existent-skill');
|
|
175
171
|
* if (!skill) {
|
|
176
172
|
* throw new SkillNotFoundError('non-existent-skill');
|
|
177
173
|
* }
|
|
@@ -302,7 +298,7 @@ export declare class HistoryLimitExceededError extends SequentialThinkingError {
|
|
|
302
298
|
*
|
|
303
299
|
* @example
|
|
304
300
|
* ```typescript
|
|
305
|
-
* if (registry.
|
|
301
|
+
* if (registry.has(skill.name)) {
|
|
306
302
|
* throw new DuplicateSkillError(skill.name);
|
|
307
303
|
* }
|
|
308
304
|
* ```
|
|
@@ -358,7 +354,7 @@ export declare class InvalidSkillError extends SequentialThinkingError {
|
|
|
358
354
|
*
|
|
359
355
|
* @example
|
|
360
356
|
* ```typescript
|
|
361
|
-
* if (registry.
|
|
357
|
+
* if (registry.has(tool.name)) {
|
|
362
358
|
* throw new DuplicateToolError(tool.name);
|
|
363
359
|
* }
|
|
364
360
|
* ```
|
|
@@ -623,18 +619,6 @@ export declare class PersistenceCompatibilityError extends SequentialThinkingErr
|
|
|
623
619
|
readonly cause: unknown;
|
|
624
620
|
constructor(sourcePath: string, detail: string, cause?: unknown);
|
|
625
621
|
}
|
|
626
|
-
/** Error raised when legacy files require an explicit one-way import. */
|
|
627
|
-
export declare class PersistenceImportRequiredError extends SequentialThinkingError {
|
|
628
|
-
readonly sourcePath: string;
|
|
629
|
-
readonly legacyArtifacts: readonly string[];
|
|
630
|
-
constructor(sourcePath: string, legacyArtifacts: readonly string[]);
|
|
631
|
-
}
|
|
632
|
-
/** Error raised when legacy bytes do not identify one durable namespace. */
|
|
633
|
-
export declare class PersistenceLegacyAmbiguityError extends SequentialThinkingError {
|
|
634
|
-
readonly sourcePath: string;
|
|
635
|
-
readonly detail: string;
|
|
636
|
-
constructor(sourcePath: string, detail: string);
|
|
637
|
-
}
|
|
638
622
|
/**
|
|
639
623
|
* Type guard to check if an error has a specific error code.
|
|
640
624
|
*/
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH;;GAEG;AACH,eAAO,MAAM,WAAW
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH;;GAEG;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;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IACnD,SAAyB,KAAK,EAAE,OAAO,CAAC;gBAE5B,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,2BAA2B,EAAE,KAAK,EAAE,OAAO;CAU5E;AAED,qBAAa,sBAAuB,SAAQ,uBAAuB;IAClE,SAAgB,OAAO,EAAE,MAAM,CAAC;gBAEpB,OAAO,EAAE,MAAM;CAK3B;AAED,8EAA8E;AAC9E,qBAAa,6BAA8B,SAAQ,uBAAuB;IACzE,SAAgB,UAAU,EAAE,MAAM,CAAC;IACnC,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAyB,KAAK,EAAE,OAAO,CAAC;gBAE5B,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAU/D;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,SAAS,EAC9C,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,CAAC,GACL,GAAG,IAAI,uBAAuB,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;CAAE,CAEvD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEtD"}
|
package/dist/errors.js
CHANGED
|
@@ -33,13 +33,9 @@ const ERROR_CODES = {
|
|
|
33
33
|
PERSISTENCE_DRAIN: 'PERSISTENCE_DRAIN',
|
|
34
34
|
PERSISTENCE_SESSION_ADMISSION_CLOSED: 'PERSISTENCE_SESSION_ADMISSION_CLOSED',
|
|
35
35
|
PERSISTENCE_SESSION_BARRIER_REENTRANCY: 'PERSISTENCE_SESSION_BARRIER_REENTRANCY',
|
|
36
|
-
ASYNC_RESET_REQUIRED: 'ASYNC_RESET_REQUIRED',
|
|
37
|
-
PERSISTENCE_CAPABILITY_UNSUPPORTED: 'PERSISTENCE_CAPABILITY_UNSUPPORTED',
|
|
38
36
|
PERSISTENCE_SCOPE_MISMATCH: 'PERSISTENCE_SCOPE_MISMATCH',
|
|
39
37
|
PERSISTENCE_UNAVAILABLE: 'PERSISTENCE_UNAVAILABLE',
|
|
40
|
-
PERSISTENCE_COMPATIBILITY: 'PERSISTENCE_COMPATIBILITY'
|
|
41
|
-
PERSISTENCE_IMPORT_REQUIRED: 'PERSISTENCE_IMPORT_REQUIRED',
|
|
42
|
-
PERSISTENCE_LEGACY_AMBIGUITY: 'PERSISTENCE_LEGACY_AMBIGUITY'
|
|
38
|
+
PERSISTENCE_COMPATIBILITY: 'PERSISTENCE_COMPATIBILITY'
|
|
43
39
|
};
|
|
44
40
|
const WARNING_CODES = {
|
|
45
41
|
TOTAL_THOUGHTS_ADJUSTED: 'TOTAL_THOUGHTS_ADJUSTED'
|
|
@@ -249,34 +245,12 @@ class PersistenceCompatibilityError extends SequentialThinkingError {
|
|
|
249
245
|
this.cause = cause;
|
|
250
246
|
}
|
|
251
247
|
}
|
|
252
|
-
class PersistenceImportRequiredError extends SequentialThinkingError {
|
|
253
|
-
sourcePath;
|
|
254
|
-
legacyArtifacts;
|
|
255
|
-
constructor(sourcePath, legacyArtifacts){
|
|
256
|
-
super(`Legacy persistence at '${sourcePath}' requires explicit import`, ERROR_CODES.PERSISTENCE_IMPORT_REQUIRED);
|
|
257
|
-
this.name = 'PersistenceImportRequiredError';
|
|
258
|
-
this.sourcePath = sourcePath;
|
|
259
|
-
this.legacyArtifacts = [
|
|
260
|
-
...legacyArtifacts
|
|
261
|
-
];
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
class PersistenceLegacyAmbiguityError extends SequentialThinkingError {
|
|
265
|
-
sourcePath;
|
|
266
|
-
detail;
|
|
267
|
-
constructor(sourcePath, detail){
|
|
268
|
-
super(`Legacy persistence at '${sourcePath}' is ambiguous: ${detail}`, ERROR_CODES.PERSISTENCE_LEGACY_AMBIGUITY);
|
|
269
|
-
this.name = 'PersistenceLegacyAmbiguityError';
|
|
270
|
-
this.sourcePath = sourcePath;
|
|
271
|
-
this.detail = detail;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
248
|
function isErrorCode(err, code) {
|
|
275
249
|
return err instanceof SequentialThinkingError && err.code === code;
|
|
276
250
|
}
|
|
277
251
|
function getErrorMessage(error) {
|
|
278
252
|
return error instanceof Error ? error.message : String(error);
|
|
279
253
|
}
|
|
280
|
-
export { CliShutdownTimeoutError, ConfigurationError, CycleDetectedError, DuplicateSkillError, DuplicateToolError, ERROR_CODES, HistoryLimitExceededError, InvalidBacktrackError, InvalidEdgeError, InvalidSkillError, InvalidThoughtError, InvalidToolCallError, InvalidToolError, MaxSessionsReachedError, PersistenceClosedError, PersistenceCompatibilityError, PersistenceCorruptionError,
|
|
254
|
+
export { CliShutdownTimeoutError, ConfigurationError, CycleDetectedError, DuplicateSkillError, DuplicateToolError, ERROR_CODES, HistoryLimitExceededError, InvalidBacktrackError, InvalidEdgeError, InvalidSkillError, InvalidThoughtError, InvalidToolCallError, InvalidToolError, MaxSessionsReachedError, PersistenceClosedError, PersistenceCompatibilityError, PersistenceCorruptionError, PersistenceOwnershipError, PersistencePublicationError, PersistenceUnavailableError, PoolTerminatedError, SequentialThinkingError, SkillDiscoveryError, SkillNotFoundError, SuspensionExpiredError, SuspensionNotFoundError, ToolNotFoundError, UnknownToolError, ValidationError, WARNING_CODES, getErrorMessage, isErrorCode };
|
|
281
255
|
|
|
282
256
|
//# sourceMappingURL=errors.js.map
|