tracelattice 1.3.0 → 1.3.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 +2 -0
- package/dist/ServerConfig.d.ts +10 -11
- package/dist/ServerConfig.d.ts.map +1 -1
- package/dist/ServerConfig.js +7 -7
- package/dist/ServerConfig.js.map +1 -1
- package/dist/__tests__/core/retraction.test.d.ts +2 -0
- package/dist/__tests__/core/retraction.test.d.ts.map +1 -0
- package/dist/__tests__/helpers/factories.d.ts +2 -0
- package/dist/__tests__/helpers/factories.d.ts.map +1 -1
- package/dist/cli.js +6 -6
- package/dist/core/HistoryManager.d.ts +45 -523
- package/dist/core/HistoryManager.d.ts.map +1 -1
- package/dist/core/HistoryManager.js +101 -249
- package/dist/core/HistoryManager.js.map +1 -1
- package/dist/core/IHistoryManager.d.ts +17 -0
- package/dist/core/IHistoryManager.d.ts.map +1 -1
- package/dist/core/PersistenceBuffer.d.ts +110 -0
- package/dist/core/PersistenceBuffer.d.ts.map +1 -0
- package/dist/core/PersistenceBuffer.js +141 -0
- package/dist/core/PersistenceBuffer.js.map +1 -0
- package/dist/core/SessionManager.d.ts +58 -0
- package/dist/core/SessionManager.d.ts.map +1 -0
- package/dist/core/SessionManager.js +65 -0
- package/dist/core/SessionManager.js.map +1 -0
- package/dist/core/ThoughtEvaluator.d.ts.map +1 -1
- package/dist/core/ThoughtEvaluator.js +16 -4
- package/dist/core/ThoughtEvaluator.js.map +1 -1
- package/dist/core/ThoughtFormatter.d.ts.map +1 -1
- package/dist/core/ThoughtFormatter.js +2 -1
- package/dist/core/ThoughtFormatter.js.map +1 -1
- package/dist/core/ThoughtProcessor.d.ts +18 -0
- package/dist/core/ThoughtProcessor.d.ts.map +1 -1
- package/dist/core/ThoughtProcessor.js +47 -16
- package/dist/core/ThoughtProcessor.js.map +1 -1
- package/dist/core/evaluator/Aggregator.d.ts.map +1 -1
- package/dist/core/evaluator/Aggregator.js +6 -2
- package/dist/core/evaluator/Aggregator.js.map +1 -1
- package/dist/core/evaluator/PatternDetector.js +2 -2
- package/dist/core/evaluator/PatternDetector.js.map +1 -1
- package/dist/core/evaluator/SignalComputer.d.ts +57 -5
- package/dist/core/evaluator/SignalComputer.d.ts.map +1 -1
- package/dist/core/evaluator/SignalComputer.js +52 -10
- package/dist/core/evaluator/SignalComputer.js.map +1 -1
- package/dist/core/graph/EdgeEmitter.d.ts +64 -0
- package/dist/core/graph/EdgeEmitter.d.ts.map +1 -0
- package/dist/core/graph/EdgeEmitter.js +99 -0
- package/dist/core/graph/EdgeEmitter.js.map +1 -0
- package/dist/core/reasoning.d.ts +17 -2
- package/dist/core/reasoning.d.ts.map +1 -1
- package/dist/core/thought.d.ts +7 -0
- package/dist/core/thought.d.ts.map +1 -1
- package/dist/core/tools/InMemorySuspensionStore.js +1 -1
- package/dist/core/tools/InMemorySuspensionStore.js.map +1 -1
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +11 -0
- package/dist/lib.js.map +1 -1
- package/dist/persistence/FilePersistence.d.ts +6 -0
- package/dist/persistence/FilePersistence.d.ts.map +1 -1
- package/dist/persistence/FilePersistence.js +8 -0
- package/dist/persistence/FilePersistence.js.map +1 -1
- package/dist/persistence/MemoryPersistence.d.ts +6 -0
- package/dist/persistence/MemoryPersistence.d.ts.map +1 -1
- package/dist/persistence/MemoryPersistence.js +3 -0
- package/dist/persistence/MemoryPersistence.js.map +1 -1
- package/dist/persistence/PersistenceBackend.d.ts +6 -0
- package/dist/persistence/PersistenceBackend.d.ts.map +1 -1
- package/dist/persistence/SqlitePersistence.d.ts +6 -0
- package/dist/persistence/SqlitePersistence.d.ts.map +1 -1
- package/dist/persistence/SqlitePersistence.js +4 -0
- package/dist/persistence/SqlitePersistence.js.map +1 -1
- package/dist/schema.d.ts +3 -2
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +8 -7
- package/dist/schema.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SignalComputer.d.ts","sourceRoot":"","sources":["../../../src/core/evaluator/SignalComputer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACtE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"SignalComputer.d.ts","sourceRoot":"","sources":["../../../src/core/evaluator/SignalComputer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACtE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAgBjD,iEAAiE;AACjE,UAAU,uBAAuB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE;QACX,cAAc,EAAE,MAAM,CAAC;QACvB,qBAAqB,EAAE,MAAM,CAAC;QAC9B,gBAAgB,EAAE,MAAM,CAAC;QACzB,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;KACpC,CAAC;IACF,cAAc,EAAE;QACf,cAAc,EAAE,MAAM,CAAC;QACvB,qBAAqB,EAAE,MAAM,CAAC;QAC9B,gBAAgB,EAAE,MAAM,CAAC;QACzB,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;KACpC,CAAC;CACF;AAED;;;;;;GAMG;AACH,qBAAa,cAAc;IAC1B;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAK5B;IAEX;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,qBAAqB,CAIlC;IAEX;;;;;;OAMG;IACI,wBAAwB,CAC9B,OAAO,EAAE,WAAW,EAAE,EACtB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC,GACrC,iBAAiB;IAiCpB;;;;;;;;;;;;;;;OAeG;IACI,wBAAwB,CAC9B,OAAO,EAAE,WAAW,EAAE,EACtB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC,EACvC,gBAAgB,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,EAC7C,WAAW,EAAE,MAAM,EAAE,GACnB,uBAAuB,GAAG,IAAI;IA+EjC;;;;;;OAMG;IACI,0BAA0B,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,IAAI;IAUvE;;;;;;OAMG;IACI,6BAA6B,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,IAAI;CAS1E"}
|
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import { ALL_THOUGHT_TYPES, _computeChainDepth, _countByType } from "./internals.js";
|
|
2
2
|
const FLOOR = 0.01;
|
|
3
|
+
function roundToPrecision(value, decimals = 10) {
|
|
4
|
+
const factor = Math.pow(10, decimals);
|
|
5
|
+
return Math.round(value * factor) / factor;
|
|
6
|
+
}
|
|
3
7
|
class SignalComputer {
|
|
8
|
+
static QUALITY_WEIGHTS = {
|
|
9
|
+
typeDiversity: 0.3,
|
|
10
|
+
verificationCoverage: 0.3,
|
|
11
|
+
depthEfficiency: 0.2,
|
|
12
|
+
confidenceStability: 0.2
|
|
13
|
+
};
|
|
14
|
+
static QUALITY_WEIGHTS_NO_CS = {
|
|
15
|
+
typeDiversity: 0.375,
|
|
16
|
+
verificationCoverage: 0.375,
|
|
17
|
+
depthEfficiency: 0.25
|
|
18
|
+
};
|
|
4
19
|
computeConfidenceSignals(history, branches) {
|
|
5
20
|
const typeDistribution = _countByType(history);
|
|
6
21
|
const allConfidences = history.map((t)=>t.confidence).filter((c)=>void 0 !== c);
|
|
@@ -12,10 +27,11 @@ class SignalComputer {
|
|
|
12
27
|
thought_type_distribution: typeDistribution,
|
|
13
28
|
has_hypothesis: history.some((t)=>'hypothesis' === t.thought_type),
|
|
14
29
|
has_verification: history.some((t)=>'verification' === t.thought_type),
|
|
15
|
-
average_confidence: allConfidences.length > 0 ? allConfidences.reduce((a, b)=>a + b, 0) / allConfidences.length : null,
|
|
30
|
+
average_confidence: allConfidences.length > 0 ? roundToPrecision(allConfidences.reduce((a, b)=>a + b, 0) / allConfidences.length) : null,
|
|
16
31
|
...null !== structuralResult && {
|
|
17
32
|
structural_quality: structuralResult.score,
|
|
18
|
-
quality_components: structuralResult.components
|
|
33
|
+
quality_components: structuralResult.components,
|
|
34
|
+
quality_components_raw: structuralResult.raw_components
|
|
19
35
|
}
|
|
20
36
|
};
|
|
21
37
|
}
|
|
@@ -30,38 +46,64 @@ class SignalComputer {
|
|
|
30
46
|
entropy -= pk * Math.log2(pk);
|
|
31
47
|
}
|
|
32
48
|
}
|
|
33
|
-
const
|
|
49
|
+
const rawTypeDiversity = entropy / Math.log2(6);
|
|
50
|
+
const typeDiversity = Math.max(rawTypeDiversity, FLOOR);
|
|
34
51
|
const hypotheses = history.filter((t)=>'hypothesis' === t.thought_type);
|
|
35
52
|
const hypothesisIds = new Set(hypotheses.map((t)=>t.hypothesis_id).filter(Boolean));
|
|
36
53
|
const verifiedIds = new Set(history.filter((t)=>'verification' === t.thought_type && t.hypothesis_id).map((t)=>t.hypothesis_id));
|
|
37
|
-
const
|
|
54
|
+
const rawVerificationCoverage = 0 === hypothesisIds.size ? 1.0 : [
|
|
38
55
|
...hypothesisIds
|
|
39
|
-
].filter((id)=>verifiedIds.has(id)).length / hypothesisIds.size
|
|
56
|
+
].filter((id)=>verifiedIds.has(id)).length / hypothesisIds.size;
|
|
57
|
+
const verificationCoverage = Math.max(rawVerificationCoverage, FLOOR);
|
|
40
58
|
const chainDepth = _computeChainDepth(history);
|
|
41
59
|
const branchCount = Object.keys(branches).length;
|
|
42
60
|
const effectiveDepth = Math.max(chainDepth, branchCount + 1);
|
|
43
|
-
const
|
|
61
|
+
const rawDepthEfficiency = Math.min(effectiveDepth / total, 1.0);
|
|
62
|
+
const depthEfficiency = Math.max(rawDepthEfficiency, FLOOR);
|
|
44
63
|
const confidenceStability = this.computeConfidenceStability(confidences);
|
|
64
|
+
const rawConfidenceStability = this.computeRawConfidenceStability(confidences);
|
|
45
65
|
const components = {
|
|
46
66
|
type_diversity: typeDiversity,
|
|
47
67
|
verification_coverage: verificationCoverage,
|
|
48
68
|
depth_efficiency: depthEfficiency,
|
|
49
69
|
confidence_stability: confidenceStability
|
|
50
70
|
};
|
|
51
|
-
const
|
|
71
|
+
const rawComponents = {
|
|
72
|
+
type_diversity: rawTypeDiversity,
|
|
73
|
+
verification_coverage: rawVerificationCoverage,
|
|
74
|
+
depth_efficiency: rawDepthEfficiency,
|
|
75
|
+
confidence_stability: rawConfidenceStability
|
|
76
|
+
};
|
|
77
|
+
let score;
|
|
78
|
+
if (null !== confidenceStability) {
|
|
79
|
+
const w = SignalComputer.QUALITY_WEIGHTS;
|
|
80
|
+
score = Math.pow(typeDiversity, w.typeDiversity) * Math.pow(verificationCoverage, w.verificationCoverage) * Math.pow(depthEfficiency, w.depthEfficiency) * Math.pow(confidenceStability, w.confidenceStability);
|
|
81
|
+
} else {
|
|
82
|
+
const w3 = SignalComputer.QUALITY_WEIGHTS_NO_CS;
|
|
83
|
+
score = Math.pow(typeDiversity, w3.typeDiversity) * Math.pow(verificationCoverage, w3.verificationCoverage) * Math.pow(depthEfficiency, w3.depthEfficiency);
|
|
84
|
+
}
|
|
52
85
|
return {
|
|
53
86
|
score,
|
|
54
|
-
components
|
|
87
|
+
components,
|
|
88
|
+
raw_components: rawComponents
|
|
55
89
|
};
|
|
56
90
|
}
|
|
57
91
|
computeConfidenceStability(confidences) {
|
|
58
|
-
if (0 === confidences.length) return
|
|
59
|
-
if (1 === confidences.length) return
|
|
92
|
+
if (0 === confidences.length) return 0.5;
|
|
93
|
+
if (1 === confidences.length) return null;
|
|
60
94
|
const mean = confidences.reduce((a, b)=>a + b, 0) / confidences.length;
|
|
61
95
|
const variance = confidences.reduce((sum, c)=>sum + (c - mean) ** 2, 0) / confidences.length;
|
|
62
96
|
const stddev = Math.sqrt(variance);
|
|
63
97
|
return Math.max(1 - stddev, FLOOR);
|
|
64
98
|
}
|
|
99
|
+
computeRawConfidenceStability(confidences) {
|
|
100
|
+
if (0 === confidences.length) return 0.5;
|
|
101
|
+
if (1 === confidences.length) return null;
|
|
102
|
+
const mean = confidences.reduce((a, b)=>a + b, 0) / confidences.length;
|
|
103
|
+
const variance = confidences.reduce((sum, c)=>sum + (c - mean) ** 2, 0) / confidences.length;
|
|
104
|
+
const stddev = Math.sqrt(variance);
|
|
105
|
+
return 1 - stddev;
|
|
106
|
+
}
|
|
65
107
|
}
|
|
66
108
|
export { SignalComputer };
|
|
67
109
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core/evaluator/SignalComputer.js","sources":["../../../src/core/evaluator/SignalComputer.ts"],"sourcesContent":["/**\n * Confidence signal computation for sequential thinking.\n *\n * Provides {@link SignalComputer} — a pure stateless service that computes\n * {@link ConfidenceSignals} (including the composite `structural_quality`\n * score and its components) from thought history and branch data.\n *\n * Extracted from `ThoughtEvaluator` as part of the evaluator decomposition.\n * All methods are pure: no side effects, no I/O, no internal state.\n *\n * @module core/evaluator/SignalComputer\n */\n\nimport type { ConfidenceSignals, ThoughtType } from '../reasoning.js';\nimport type { ThoughtData } from '../thought.js';\nimport { ALL_THOUGHT_TYPES, _computeChainDepth, _countByType } from './internals.js';\n\n/** Floor value applied to each quality component to prevent geometric mean collapse. */\nconst FLOOR = 0.01;\n\n/** Result of {@link SignalComputer.computeStructuralQuality}. */\ninterface StructuralQualityResult {\n\tscore: number;\n\tcomponents: {\n\t\ttype_diversity: number;\n\t\tverification_coverage: number;\n\t\tdepth_efficiency: number;\n\t\tconfidence_stability: number;\n\t};\n}\n\n/**\n * Stateless service that computes {@link ConfidenceSignals} from thought history.\n *\n * @remarks\n * Pure computation — no side effects, no I/O, no internal state.\n * Safe to register as singleton or transient in DI.\n */\nexport class SignalComputer {\n\t/**\n\t * Compute confidence signals from history context.\n\t *\n\t * @param history - All thoughts in the current session\n\t * @param branches - Map of branch IDs to their thought arrays\n\t * @returns Computed confidence signals reflecting reasoning quality\n\t */\n\tpublic computeConfidenceSignals(\n\t\thistory: ThoughtData[],\n\t\tbranches: Record<string, ThoughtData[]>\n\t): ConfidenceSignals {\n\t\tconst typeDistribution = _countByType(history);\n\t\tconst allConfidences = history\n\t\t\t.map((t) => t.confidence)\n\t\t\t.filter((c): c is number => c !== undefined);\n\n\t\t// Compute structural quality components\n\t\tconst structuralResult = this.computeStructuralQuality(\n\t\t\thistory,\n\t\t\tbranches,\n\t\t\ttypeDistribution,\n\t\t\tallConfidences\n\t\t);\n\n\t\treturn {\n\t\t\treasoning_depth: history.length,\n\t\t\trevision_count: history.filter((t) => t.is_revision).length,\n\t\t\tbranch_count: Object.keys(branches).length,\n\t\t\tthought_type_distribution: typeDistribution,\n\t\t\thas_hypothesis: history.some((t) => t.thought_type === 'hypothesis'),\n\t\t\thas_verification: history.some((t) => t.thought_type === 'verification'),\n\t\t\taverage_confidence:\n\t\t\t\tallConfidences.length > 0\n\t\t\t\t\t? allConfidences.reduce((a, b) => a + b, 0) / allConfidences.length\n\t\t\t\t\t: null,\n\t\t\t...(structuralResult !== null && {\n\t\t\t\tstructural_quality: structuralResult.score,\n\t\t\t\tquality_components: structuralResult.components,\n\t\t\t}),\n\t\t};\n\t}\n\n\t/**\n\t * Compute the composite structural quality score and its components.\n\t *\n\t * Algorithm (all components floored at {@link FLOOR} = 0.01):\n\t * - `type_diversity` = Shannon entropy of thought_type distribution / log2(6)\n\t * - `verification_coverage` = verified_hypotheses / max(total_hypotheses, 1) (1.0 if none)\n\t * - `depth_efficiency` = max(chain_depth, branch_count + 1) / total_thoughts, clamped to 1.0\n\t * - `confidence_stability` = 1 - stddev(confidences), default 0.5 when empty\n\t * - `structural_quality` = td^0.3 * vc^0.3 * de^0.2 * cs^0.2 (weighted geometric mean)\n\t *\n\t * @returns Score + components, or `null` when history is empty\n\t */\n\tpublic computeStructuralQuality(\n\t\thistory: ThoughtData[],\n\t\tbranches: Record<string, ThoughtData[]>,\n\t\ttypeDistribution: Record<ThoughtType, number>,\n\t\tconfidences: number[]\n\t): StructuralQualityResult | null {\n\t\tif (history.length === 0) return null;\n\n\t\t// 1. type_diversity: Shannon entropy / log2(6)\n\t\tconst total = history.length;\n\t\tlet entropy = 0;\n\t\tfor (const type of ALL_THOUGHT_TYPES) {\n\t\t\tconst count = typeDistribution[type];\n\t\t\tif (count > 0) {\n\t\t\t\tconst pk = count / total;\n\t\t\t\tentropy -= pk * Math.log2(pk);\n\t\t\t}\n\t\t}\n\t\tconst typeDiversity = Math.max(entropy / Math.log2(6), FLOOR);\n\n\t\t// 2. verification_coverage: verified / total hypotheses (1.0 if none)\n\t\tconst hypotheses = history.filter((t) => t.thought_type === 'hypothesis');\n\t\tconst hypothesisIds = new Set(hypotheses.map((t) => t.hypothesis_id).filter(Boolean));\n\t\tconst verifiedIds = new Set(\n\t\t\thistory\n\t\t\t\t.filter((t) => t.thought_type === 'verification' && t.hypothesis_id)\n\t\t\t\t.map((t) => t.hypothesis_id)\n\t\t);\n\t\tconst verificationCoverage =\n\t\t\thypothesisIds.size === 0\n\t\t\t\t? 1.0\n\t\t\t\t: Math.max(\n\t\t\t\t\t\t[...hypothesisIds].filter((id) => verifiedIds.has(id)).length / hypothesisIds.size,\n\t\t\t\t\t\tFLOOR\n\t\t\t\t\t);\n\n\t\t// 3. depth_efficiency: max(chain_depth, branch_count + 1) / total_thoughts, clamped to 1.0\n\t\t// NOTE (Metis H3): Branching is desirable — treat branches as depth-equivalent.\n\t\tconst chainDepth = _computeChainDepth(history);\n\t\tconst branchCount = Object.keys(branches).length;\n\t\tconst effectiveDepth = Math.max(chainDepth, branchCount + 1);\n\t\tconst depthEfficiency = Math.max(Math.min(effectiveDepth / total, 1.0), FLOOR);\n\n\t\t// 4. confidence_stability: 1 - stddev(confidences), default 0.5\n\t\tconst confidenceStability = this.computeConfidenceStability(confidences);\n\n\t\tconst components = {\n\t\t\ttype_diversity: typeDiversity,\n\t\t\tverification_coverage: verificationCoverage,\n\t\t\tdepth_efficiency: depthEfficiency,\n\t\t\tconfidence_stability: confidenceStability,\n\t\t};\n\n\t\t// Weighted geometric mean: td^0.3 * vc^0.3 * de^0.2 * cs^0.2\n\t\tconst score =\n\t\t\tMath.pow(typeDiversity, 0.3) *\n\t\t\tMath.pow(verificationCoverage, 0.3) *\n\t\t\tMath.pow(depthEfficiency, 0.2) *\n\t\t\tMath.pow(confidenceStability, 0.2);\n\n\t\treturn { score, components };\n\t}\n\n\t/**\n\t * Compute confidence stability: 1 - stddev(confidences).\n\t *\n\t * - Empty input → 0.5 (default neutral value, floored at {@link FLOOR})\n\t * - Single value → 1.0 (perfectly stable, floored at {@link FLOOR})\n\t * - Otherwise → max(1 - stddev, FLOOR)\n\t */\n\tpublic computeConfidenceStability(confidences: number[]): number {\n\t\tif (confidences.length === 0) return Math.max(0.5, FLOOR);\n\t\tif (confidences.length === 1) return Math.max(1.0, FLOOR);\n\n\t\tconst mean = confidences.reduce((a, b) => a + b, 0) / confidences.length;\n\t\tconst variance =\n\t\t\tconfidences.reduce((sum, c) => sum + (c - mean) ** 2, 0) / confidences.length;\n\t\tconst stddev = Math.sqrt(variance);\n\t\treturn Math.max(1 - stddev, FLOOR);\n\t}\n}\n"],"names":["FLOOR","SignalComputer","history","branches","typeDistribution","_countByType","allConfidences","t","c","undefined","structuralResult","Object","a","b","confidences","total","entropy","type","ALL_THOUGHT_TYPES","count","pk","Math","typeDiversity","hypotheses","hypothesisIds","Set","Boolean","verifiedIds","verificationCoverage","id","chainDepth","_computeChainDepth","branchCount","effectiveDepth","depthEfficiency","confidenceStability","components","score","mean","variance","sum","stddev"],"mappings":";AAkBA,MAAMA,QAAQ;AAoBP,MAAMC;IAQL,yBACNC,OAAsB,EACtBC,QAAuC,EACnB;QACpB,MAAMC,mBAAmBC,aAAaH;QACtC,MAAMI,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OAAOxB,YAAY,MAAM,CAAC,CAACF,GAAGC,IAAMD,IAAIC,GAAG,KAAKC,YAAY,MAAM;QACxE,MAAMyB,WACLzB,YAAY,MAAM,CAAC,CAAC0B,KAAKhC,IAAMgC,MAAOhC,AAAAA,CAAAA,IAAI8B,IAAG,KAAM,GAAG,KAAKxB,YAAY,MAAM;QAC9E,MAAM2B,SAASpB,KAAK,IAAI,CAACkB;QACzB,OAAOlB,KAAK,GAAG,CAAC,IAAIoB,QAAQzC;IAC7B;AACD"}
|
|
1
|
+
{"version":3,"file":"core/evaluator/SignalComputer.js","sources":["../../../src/core/evaluator/SignalComputer.ts"],"sourcesContent":["/**\n * Confidence signal computation for sequential thinking.\n *\n * Provides {@link SignalComputer} — a pure stateless service that computes\n * {@link ConfidenceSignals} (including the composite `structural_quality`\n * score and its components) from thought history and branch data.\n *\n * Extracted from `ThoughtEvaluator` as part of the evaluator decomposition.\n * All methods are pure: no side effects, no I/O, no internal state.\n *\n * @module core/evaluator/SignalComputer\n */\n\nimport type { ConfidenceSignals, ThoughtType } from '../reasoning.js';\nimport type { ThoughtData } from '../thought.js';\nimport { ALL_THOUGHT_TYPES, _computeChainDepth, _countByType } from './internals.js';\n\n/** Floor value applied to each quality component to prevent geometric mean collapse. */\nconst FLOOR = 0.01;\n\n/**\n * Round a numeric value to a fixed number of decimal places to mitigate\n * IEEE 754 floating-point accumulation errors (e.g. 0.9 + 0.8 averaging to\n * 0.8500000000000001 instead of 0.85).\n */\nfunction roundToPrecision(value: number, decimals: number = 10): number {\n\tconst factor = Math.pow(10, decimals);\n\treturn Math.round(value * factor) / factor;\n}\n\n/** Result of {@link SignalComputer.computeStructuralQuality}. */\ninterface StructuralQualityResult {\n\tscore: number;\n\tcomponents: {\n\t\ttype_diversity: number;\n\t\tverification_coverage: number;\n\t\tdepth_efficiency: number;\n\t\tconfidence_stability: number | null;\n\t};\n\traw_components: {\n\t\ttype_diversity: number;\n\t\tverification_coverage: number;\n\t\tdepth_efficiency: number;\n\t\tconfidence_stability: number | null;\n\t};\n}\n\n/**\n * Stateless service that computes {@link ConfidenceSignals} from thought history.\n *\n * @remarks\n * Pure computation — no side effects, no I/O, no internal state.\n * Safe to register as singleton or transient in DI.\n */\nexport class SignalComputer {\n\t/**\n\t * Structural quality weight configuration.\n\t *\n\t * Weights reflect the relative importance of each quality dimension:\n\t * - type_diversity (0.3): Shannon entropy of thought types — rewards reasoning that uses\n\t * multiple cognitive modes (hypothesis, verification, critique, synthesis) rather than\n\t * monotonic sequences. Based on information theory: higher entropy = more information.\n\t *\n\t * - verification_coverage (0.3): Ratio of verified to total hypotheses — rewards scientific\n\t * rigor. Hypotheses without verification are speculation; verification grounds reasoning.\n\t * Equal weight with diversity because unverified reasoning is a common failure mode.\n\t *\n\t * - depth_efficiency (0.2): Ratio of structural depth to total thoughts — rewards efficient\n\t * reasoning. Deep chains (many revisions/branches) are good; but only if proportionally\n\t * dense. Padding with low-value thoughts penalizes this metric.\n\t *\n\t * - confidence_stability (0.2): Low variance in self-assessed confidence — rewards calibrated\n\t * reasoning. Wildly fluctuating confidence suggests uncertainty about the approach.\n\t * Lower weight because confidence values are LLM self-reports (inherently noisy).\n\t *\n\t * Design rationale:\n\t * - Diversity + Verification (0.6) > Depth + Stability (0.4): Structural properties of the\n\t * reasoning DAG are more important than behavioral signals.\n\t * - All weights are positive (no dimension is penalizing).\n\t * - Weights sum to 1.0 for normalized scoring.\n\t * - When confidence_stability is unavailable (n<2), remaining weights redistribute\n\t * proportionally: td→0.375, vc→0.375, de→0.25 (preserving relative ratios).\n\t */\n\tprivate static readonly QUALITY_WEIGHTS = {\n\t\ttypeDiversity: 0.3,\n\t\tverificationCoverage: 0.3,\n\t\tdepthEfficiency: 0.2,\n\t\tconfidenceStability: 0.2,\n\t} as const;\n\n\t/**\n\t * Redistributed weights when confidence_stability is excluded (n<2).\n\t * Preserves relative ratios of remaining components (sum = 1.0).\n\t */\n\tprivate static readonly QUALITY_WEIGHTS_NO_CS = {\n\t\ttypeDiversity: 0.375,\n\t\tverificationCoverage: 0.375,\n\t\tdepthEfficiency: 0.25,\n\t} as const;\n\n\t/**\n\t * Compute confidence signals from history context.\n\t *\n\t * @param history - All thoughts in the current session\n\t * @param branches - Map of branch IDs to their thought arrays\n\t * @returns Computed confidence signals reflecting reasoning quality\n\t */\n\tpublic computeConfidenceSignals(\n\t\thistory: ThoughtData[],\n\t\tbranches: Record<string, ThoughtData[]>\n\t): ConfidenceSignals {\n\t\tconst typeDistribution = _countByType(history);\n\t\tconst allConfidences = history\n\t\t\t.map((t) => t.confidence)\n\t\t\t.filter((c): c is number => c !== undefined);\n\n\t\t// Compute structural quality components\n\t\tconst structuralResult = this.computeStructuralQuality(\n\t\t\thistory,\n\t\t\tbranches,\n\t\t\ttypeDistribution,\n\t\t\tallConfidences\n\t\t);\n\n\t\treturn {\n\t\t\treasoning_depth: history.length,\n\t\t\trevision_count: history.filter((t) => t.is_revision).length,\n\t\t\tbranch_count: Object.keys(branches).length,\n\t\t\tthought_type_distribution: typeDistribution,\n\t\t\thas_hypothesis: history.some((t) => t.thought_type === 'hypothesis'),\n\t\t\thas_verification: history.some((t) => t.thought_type === 'verification'),\n\t\t\taverage_confidence:\n\t\t\t\tallConfidences.length > 0\n\t\t\t\t\t? roundToPrecision(allConfidences.reduce((a, b) => a + b, 0) / allConfidences.length)\n\t\t\t\t\t: null,\n\t\t\t...(structuralResult !== null && {\n\t\t\t\tstructural_quality: structuralResult.score,\n\t\t\t\tquality_components: structuralResult.components,\n\t\t\t\tquality_components_raw: structuralResult.raw_components,\n\t\t\t}),\n\t\t};\n\t}\n\n\t/**\n\t * Compute the composite structural quality score and its components.\n\t *\n\t * Algorithm (all components floored at {@link FLOOR} = 0.01):\n\t * - `type_diversity` = Shannon entropy of thought_type distribution / log2(6)\n\t * - `verification_coverage` = verified_hypotheses / max(total_hypotheses, 1) (1.0 if none)\n\t * - `depth_efficiency` = max(chain_depth, branch_count + 1) / total_thoughts, clamped to 1.0\n\t * - `confidence_stability` = 1 - stddev(confidences), default 0.5 when empty, null when single value\n\t * - `structural_quality` = td^0.3 * vc^0.3 * de^0.2 * cs^0.2 (weighted geometric mean)\n\t *\n\t * Note: When confidence_stability is null (fewer than 2 confidence values), it is\n\t * excluded from the geometric mean and the remaining weights are redistributed\n\t * proportionally (td→0.375, vc→0.375, de→0.25).\n\t *\n\t * @returns Score + components, or `null` when history is empty\n\t */\n\tpublic computeStructuralQuality(\n\t\thistory: ThoughtData[],\n\t\tbranches: Record<string, ThoughtData[]>,\n\t\ttypeDistribution: Record<ThoughtType, number>,\n\t\tconfidences: number[]\n\t): StructuralQualityResult | null {\n\t\tif (history.length === 0) return null;\n\n\t\t// 1. type_diversity: Shannon entropy / log2(6)\n\t\tconst total = history.length;\n\t\tlet entropy = 0;\n\t\tfor (const type of ALL_THOUGHT_TYPES) {\n\t\t\tconst count = typeDistribution[type];\n\t\t\tif (count > 0) {\n\t\t\t\tconst pk = count / total;\n\t\t\t\tentropy -= pk * Math.log2(pk);\n\t\t\t}\n\t\t}\n\t\tconst rawTypeDiversity = entropy / Math.log2(6);\n\t\tconst typeDiversity = Math.max(rawTypeDiversity, FLOOR);\n\n\t\t// 2. verification_coverage: verified / total hypotheses (1.0 if none)\n\t\tconst hypotheses = history.filter((t) => t.thought_type === 'hypothesis');\n\t\tconst hypothesisIds = new Set(hypotheses.map((t) => t.hypothesis_id).filter(Boolean));\n\t\tconst verifiedIds = new Set(\n\t\t\thistory\n\t\t\t\t.filter((t) => t.thought_type === 'verification' && t.hypothesis_id)\n\t\t\t\t.map((t) => t.hypothesis_id)\n\t\t);\n\t\tconst rawVerificationCoverage =\n\t\t\thypothesisIds.size === 0\n\t\t\t\t? 1.0\n\t\t\t\t: [...hypothesisIds].filter((id) => verifiedIds.has(id)).length / hypothesisIds.size;\n\t\tconst verificationCoverage = Math.max(rawVerificationCoverage, FLOOR);\n\n\t\t// 3. depth_efficiency: max(chain_depth, branch_count + 1) / total_thoughts, clamped to 1.0\n\t\t// NOTE (Metis H3): Branching is desirable — treat branches as depth-equivalent.\n\t\tconst chainDepth = _computeChainDepth(history);\n\t\tconst branchCount = Object.keys(branches).length;\n\t\tconst effectiveDepth = Math.max(chainDepth, branchCount + 1);\n\t\tconst rawDepthEfficiency = Math.min(effectiveDepth / total, 1.0);\n\t\tconst depthEfficiency = Math.max(rawDepthEfficiency, FLOOR);\n\n\t\t// 4. confidence_stability: 1 - stddev(confidences), default 0.5\n\t\tconst confidenceStability = this.computeConfidenceStability(confidences);\n\t\tconst rawConfidenceStability = this.computeRawConfidenceStability(confidences);\n\n\t\tconst components: StructuralQualityResult['components'] = {\n\t\t\ttype_diversity: typeDiversity,\n\t\t\tverification_coverage: verificationCoverage,\n\t\t\tdepth_efficiency: depthEfficiency,\n\t\t\tconfidence_stability: confidenceStability,\n\t\t};\n\n\t\tconst rawComponents: StructuralQualityResult['raw_components'] = {\n\t\t\ttype_diversity: rawTypeDiversity,\n\t\t\tverification_coverage: rawVerificationCoverage,\n\t\t\tdepth_efficiency: rawDepthEfficiency,\n\t\t\tconfidence_stability: rawConfidenceStability,\n\t\t};\n\n\t\t// Weighted geometric mean: td^0.3 * vc^0.3 * de^0.2 * cs^0.2\n\t\t// When confidence_stability is null (n<2), exclude it from the geomean\n\t\t// and redistribute its weight proportionally to remaining components\n\t\t// (normalized td=0.375, vc=0.375, de=0.25)\n\t\tlet score: number;\n\t\tif (confidenceStability !== null) {\n\t\t\tconst w = SignalComputer.QUALITY_WEIGHTS;\n\t\t\tscore =\n\t\t\t\tMath.pow(typeDiversity, w.typeDiversity) *\n\t\t\t\tMath.pow(verificationCoverage, w.verificationCoverage) *\n\t\t\t\tMath.pow(depthEfficiency, w.depthEfficiency) *\n\t\t\t\tMath.pow(confidenceStability, w.confidenceStability);\n\t\t} else {\n\t\t\tconst w3 = SignalComputer.QUALITY_WEIGHTS_NO_CS;\n\t\t\tscore =\n\t\t\t\tMath.pow(typeDiversity, w3.typeDiversity) *\n\t\t\t\tMath.pow(verificationCoverage, w3.verificationCoverage) *\n\t\t\t\tMath.pow(depthEfficiency, w3.depthEfficiency);\n\t\t}\n\n\t\treturn { score, components, raw_components: rawComponents };\n\t}\n\n\t/**\n\t * Compute confidence stability: 1 - stddev(confidences).\n\t *\n\t * - Empty input → 0.5 (neutral default)\n\t * - Single value → null (insufficient data, excluded from structural quality)\n\t * - Otherwise → max(1 - stddev, FLOOR)\n\t */\n\tpublic computeConfidenceStability(confidences: number[]): number | null {\n\t\tif (confidences.length === 0) return 0.5;\n\t\tif (confidences.length === 1) return null;\n\n\t\tconst mean = confidences.reduce((a, b) => a + b, 0) / confidences.length;\n\t\tconst variance = confidences.reduce((sum, c) => sum + (c - mean) ** 2, 0) / confidences.length;\n\t\tconst stddev = Math.sqrt(variance);\n\t\treturn Math.max(1 - stddev, FLOOR);\n\t}\n\n\t/**\n\t * Compute raw (unfloored) confidence stability: 1 - stddev(confidences).\n\t *\n\t * - Empty input → 0.5 (neutral default)\n\t * - Single value → null (insufficient data)\n\t * - Otherwise → 1 - stddev (may be below FLOOR)\n\t */\n\tpublic computeRawConfidenceStability(confidences: number[]): number | null {\n\t\tif (confidences.length === 0) return 0.5;\n\t\tif (confidences.length === 1) return null;\n\n\t\tconst mean = confidences.reduce((a, b) => a + b, 0) / confidences.length;\n\t\tconst variance = confidences.reduce((sum, c) => sum + (c - mean) ** 2, 0) / confidences.length;\n\t\tconst stddev = Math.sqrt(variance);\n\t\treturn 1 - stddev;\n\t}\n}\n"],"names":["FLOOR","roundToPrecision","value","decimals","factor","Math","SignalComputer","history","branches","typeDistribution","_countByType","allConfidences","t","c","undefined","structuralResult","Object","a","b","confidences","total","entropy","type","ALL_THOUGHT_TYPES","count","pk","rawTypeDiversity","typeDiversity","hypotheses","hypothesisIds","Set","Boolean","verifiedIds","rawVerificationCoverage","id","verificationCoverage","chainDepth","_computeChainDepth","branchCount","effectiveDepth","rawDepthEfficiency","depthEfficiency","confidenceStability","rawConfidenceStability","components","rawComponents","score","w","w3","mean","variance","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AG,KAAM,GAAG,KAAK9B,YAAY,MAAM;QAC9F,MAAMiC,SAAS/C,KAAK,IAAI,CAAC6C;QACzB,OAAO7C,KAAK,GAAG,CAAC,IAAI+C,QAAQpD;IAC7B;IASO,8BAA8BmB,WAAqB,EAAiB;QAC1E,IAAIA,AAAuB,MAAvBA,YAAY,MAAM,EAAQ,OAAO;QACrC,IAAIA,AAAuB,MAAvBA,YAAY,MAAM,EAAQ,OAAO;QAErC,MAAM8B,OAAO9B,YAAY,MAAM,CAAC,CAACF,GAAGC,IAAMD,IAAIC,GAAG,KAAKC,YAAY,MAAM;QACxE,MAAM+B,WAAW/B,YAAY,MAAM,CAAC,CAACgC,KAAKtC,IAAMsC,MAAOtC,AAAAA,CAAAA,IAAIoC,IAAG,KAAM,GAAG,KAAK9B,YAAY,MAAM;QAC9F,MAAMiC,SAAS/C,KAAK,IAAI,CAAC6C;QACzB,OAAO,IAAIE;IACZ;AACD"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EdgeEmitter — emits DAG edges for thoughts based on their metadata.
|
|
3
|
+
*
|
|
4
|
+
* Stateless helper extracted from HistoryManager. Holds a reference to an
|
|
5
|
+
* optional `IEdgeStore` and a feature flag (`dagEdges`) gating writes.
|
|
6
|
+
*
|
|
7
|
+
* @module EdgeEmitter
|
|
8
|
+
*/
|
|
9
|
+
import type { IEdgeStore } from '../../contracts/interfaces.js';
|
|
10
|
+
import type { Logger } from '../../logger/StructuredLogger.js';
|
|
11
|
+
import type { ThoughtData } from '../thought.js';
|
|
12
|
+
/** Minimal session view needed for edge emission. */
|
|
13
|
+
export interface EdgeEmissionSession {
|
|
14
|
+
thought_history: ThoughtData[];
|
|
15
|
+
branches: Record<string, ThoughtData[]>;
|
|
16
|
+
}
|
|
17
|
+
/** Configuration options for EdgeEmitter. */
|
|
18
|
+
export interface EdgeEmitterConfig {
|
|
19
|
+
edgeStore?: IEdgeStore;
|
|
20
|
+
dagEdges?: boolean;
|
|
21
|
+
defaultSessionId: string;
|
|
22
|
+
logger?: Logger;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Emits DAG edges for thought relationships when an `IEdgeStore` is configured
|
|
26
|
+
* and the `dagEdges` feature flag is enabled. No-ops otherwise.
|
|
27
|
+
*/
|
|
28
|
+
export declare class EdgeEmitter {
|
|
29
|
+
private readonly _edgeStore?;
|
|
30
|
+
private readonly _dagEdges;
|
|
31
|
+
private readonly _defaultSessionId;
|
|
32
|
+
private readonly _logger;
|
|
33
|
+
constructor(config: EdgeEmitterConfig);
|
|
34
|
+
/** Returns true when edge emission is active (store + flag both set). */
|
|
35
|
+
isEnabled(): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Emits DAG edges for a thought based on its metadata fields.
|
|
38
|
+
*
|
|
39
|
+
* Edge kinds (in priority order):
|
|
40
|
+
* - branch: branch_from_thought + branch_id → parent.id → current.id
|
|
41
|
+
* - merge: merge_from_thoughts → source.id → current.id (per source)
|
|
42
|
+
* - verifies: verification_target + thought_type=verification → current.id → target.id
|
|
43
|
+
* - critiques: verification_target + thought_type=critique → current.id → target.id
|
|
44
|
+
* - derives_from: synthesis_sources → source.id → current.id (per source)
|
|
45
|
+
* - revises: revises_thought → current.id → target.id
|
|
46
|
+
* - tool_invocation: tool_observation with _resumedFrom → tool_call.id → current.id
|
|
47
|
+
* - sequence: default chronological link from previous thought (if none of the above)
|
|
48
|
+
*/
|
|
49
|
+
emitEdgesForThought(session: EdgeEmissionSession, thought: ThoughtData): void;
|
|
50
|
+
/**
|
|
51
|
+
* Resolves a thought_number to its stable id within the given session.
|
|
52
|
+
* Searches main history first, then branches.
|
|
53
|
+
*
|
|
54
|
+
* @returns The thought's id if found and non-empty, undefined otherwise
|
|
55
|
+
*/
|
|
56
|
+
resolveThoughtId(session: EdgeEmissionSession, thoughtNumber: number): string | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Adds an edge to the edge store if both endpoints are non-empty strings.
|
|
59
|
+
* Returns true if added, false if skipped (missing endpoint).
|
|
60
|
+
* Failures (e.g. self-edge) are caught and logged.
|
|
61
|
+
*/
|
|
62
|
+
private _addEdgeIfValid;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=EdgeEmitter.d.ts.map
|
|
@@ -0,0 +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;AAIjD,qDAAqD;AACrD,MAAM,WAAW,mBAAmB;IACnC,eAAe,EAAE,WAAW,EAAE,CAAC;IAC/B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC;CACxC;AAED,6CAA6C;AAC7C,MAAM,WAAW,iBAAiB;IACjC,SAAS,CAAC,EAAE,UAAU,CAAC;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,gBAAgB,EAAE,MAAM,CAAC;IACzB,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,iBAAiB,CAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,MAAM,EAAE,iBAAiB;IAOrC,yEAAyE;IAClE,SAAS,IAAI,OAAO;IAI3B;;;;;;;;;;;;OAYG;IACI,mBAAmB,CAAC,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,WAAW,GAAG,IAAI;IAoFpF;;;;;OAKG;IACI,gBAAgB,CACtB,OAAO,EAAE,mBAAmB,EAC5B,aAAa,EAAE,MAAM,GACnB,MAAM,GAAG,SAAS;IAgBrB;;;;OAIG;IACH,OAAO,CAAC,eAAe;CAmCvB"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { getErrorMessage } from "../../errors.js";
|
|
2
|
+
import { NullLogger } from "../../logger/NullLogger.js";
|
|
3
|
+
import { generateUlid } from "../ids.js";
|
|
4
|
+
class EdgeEmitter {
|
|
5
|
+
_edgeStore;
|
|
6
|
+
_dagEdges;
|
|
7
|
+
_defaultSessionId;
|
|
8
|
+
_logger;
|
|
9
|
+
constructor(config){
|
|
10
|
+
this._edgeStore = config.edgeStore;
|
|
11
|
+
this._dagEdges = config.dagEdges ?? true;
|
|
12
|
+
this._defaultSessionId = config.defaultSessionId;
|
|
13
|
+
this._logger = config.logger ?? new NullLogger();
|
|
14
|
+
}
|
|
15
|
+
isEnabled() {
|
|
16
|
+
return void 0 !== this._edgeStore && this._dagEdges;
|
|
17
|
+
}
|
|
18
|
+
emitEdgesForThought(session, thought) {
|
|
19
|
+
if (!this._edgeStore || !this._dagEdges) return;
|
|
20
|
+
if (!thought.id) return;
|
|
21
|
+
const sessionId = thought.session_id ?? this._defaultSessionId;
|
|
22
|
+
let emittedRelational = false;
|
|
23
|
+
if (void 0 !== thought.branch_from_thought && thought.branch_id) {
|
|
24
|
+
const parentId = this.resolveThoughtId(session, thought.branch_from_thought);
|
|
25
|
+
if (this._addEdgeIfValid(parentId, thought.id, 'branch', sessionId)) emittedRelational = true;
|
|
26
|
+
}
|
|
27
|
+
if (thought.merge_from_thoughts?.length) for (const src of thought.merge_from_thoughts){
|
|
28
|
+
const srcId = this.resolveThoughtId(session, src);
|
|
29
|
+
if (this._addEdgeIfValid(srcId, thought.id, 'merge', sessionId)) emittedRelational = true;
|
|
30
|
+
}
|
|
31
|
+
if (void 0 !== thought.verification_target && 'verification' === thought.thought_type) {
|
|
32
|
+
const targetId = this.resolveThoughtId(session, thought.verification_target);
|
|
33
|
+
if (this._addEdgeIfValid(thought.id, targetId, 'verifies', sessionId)) emittedRelational = true;
|
|
34
|
+
}
|
|
35
|
+
if (void 0 !== thought.verification_target && 'critique' === thought.thought_type) {
|
|
36
|
+
const targetId = this.resolveThoughtId(session, thought.verification_target);
|
|
37
|
+
if (this._addEdgeIfValid(thought.id, targetId, 'critiques', sessionId)) emittedRelational = true;
|
|
38
|
+
}
|
|
39
|
+
if (thought.synthesis_sources?.length) for (const src of thought.synthesis_sources){
|
|
40
|
+
const srcId = this.resolveThoughtId(session, src);
|
|
41
|
+
if (this._addEdgeIfValid(srcId, thought.id, 'derives_from', sessionId)) emittedRelational = true;
|
|
42
|
+
}
|
|
43
|
+
if (void 0 !== thought.revises_thought) {
|
|
44
|
+
const targetId = this.resolveThoughtId(session, thought.revises_thought);
|
|
45
|
+
if (this._addEdgeIfValid(thought.id, targetId, 'revises', sessionId)) emittedRelational = true;
|
|
46
|
+
}
|
|
47
|
+
if ('tool_observation' === thought.thought_type && void 0 !== thought._resumedFrom) {
|
|
48
|
+
const toolCallId = this.resolveThoughtId(session, thought._resumedFrom);
|
|
49
|
+
const meta = {};
|
|
50
|
+
if (void 0 !== thought.tool_name) meta.tool_name = thought.tool_name;
|
|
51
|
+
if (this._addEdgeIfValid(toolCallId, thought.id, 'tool_invocation', sessionId, Object.keys(meta).length > 0 ? meta : void 0)) emittedRelational = true;
|
|
52
|
+
}
|
|
53
|
+
if (!emittedRelational) {
|
|
54
|
+
const history = session.thought_history;
|
|
55
|
+
if (history.length >= 2) {
|
|
56
|
+
const prev = history[history.length - 2];
|
|
57
|
+
if (prev.id) this._addEdgeIfValid(prev.id, thought.id, 'sequence', sessionId);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
resolveThoughtId(session, thoughtNumber) {
|
|
62
|
+
for (const t of session.thought_history)if (t.thought_number === thoughtNumber && 'string' == typeof t.id && t.id.length > 0) return t.id;
|
|
63
|
+
for (const branchThoughts of Object.values(session.branches))for (const t of branchThoughts)if (t.thought_number === thoughtNumber && 'string' == typeof t.id && t.id.length > 0) return t.id;
|
|
64
|
+
}
|
|
65
|
+
_addEdgeIfValid(from, to, kind, sessionId, metadata) {
|
|
66
|
+
if (!from || !to) {
|
|
67
|
+
this._logger.debug('Skipping edge: unresolved endpoint', {
|
|
68
|
+
kind,
|
|
69
|
+
from: from ?? null,
|
|
70
|
+
to: to ?? null
|
|
71
|
+
});
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
const edge = {
|
|
75
|
+
id: generateUlid(),
|
|
76
|
+
from,
|
|
77
|
+
to,
|
|
78
|
+
kind,
|
|
79
|
+
sessionId,
|
|
80
|
+
createdAt: Date.now(),
|
|
81
|
+
...void 0 !== metadata ? {
|
|
82
|
+
metadata
|
|
83
|
+
} : {}
|
|
84
|
+
};
|
|
85
|
+
try {
|
|
86
|
+
this._edgeStore.addEdge(edge);
|
|
87
|
+
return true;
|
|
88
|
+
} catch (err) {
|
|
89
|
+
this._logger.info('Failed to add DAG edge', {
|
|
90
|
+
kind,
|
|
91
|
+
error: getErrorMessage(err)
|
|
92
|
+
});
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
export { EdgeEmitter };
|
|
98
|
+
|
|
99
|
+
//# sourceMappingURL=EdgeEmitter.js.map
|
|
@@ -0,0 +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 { Edge, EdgeKind } from './Edge.js';\nimport { generateUlid } from '../ids.js';\n\n/** Minimal session view needed for edge emission. */\nexport interface EdgeEmissionSession {\n\tthought_history: ThoughtData[];\n\tbranches: Record<string, ThoughtData[]>;\n}\n\n/** Configuration options for EdgeEmitter. */\nexport interface EdgeEmitterConfig {\n\tedgeStore?: IEdgeStore;\n\tdagEdges?: boolean;\n\tdefaultSessionId: string;\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: string;\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: tool_observation with _resumedFrom → tool_call.id → current.id\n\t * - sequence: default chronological link from previous thought (if none of the above)\n\t */\n\tpublic emitEdgesForThought(session: EdgeEmissionSession, thought: ThoughtData): void {\n\t\tif (!this._edgeStore || !this._dagEdges) return;\n\t\tif (!thought.id) return;\n\n\t\tconst sessionId = thought.session_id ?? this._defaultSessionId;\n\t\tlet emittedRelational = false;\n\n\t\tif (thought.branch_from_thought !== undefined && thought.branch_id) {\n\t\t\tconst parentId = this.resolveThoughtId(session, thought.branch_from_thought);\n\t\t\tif (this._addEdgeIfValid(parentId, thought.id, 'branch', sessionId)) {\n\t\t\t\temittedRelational = true;\n\t\t\t}\n\t\t}\n\n\t\tif (thought.merge_from_thoughts?.length) {\n\t\t\tfor (const src of thought.merge_from_thoughts) {\n\t\t\t\tconst srcId = this.resolveThoughtId(session, src);\n\t\t\t\tif (this._addEdgeIfValid(srcId, thought.id, 'merge', sessionId)) {\n\t\t\t\t\temittedRelational = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (thought.verification_target !== undefined && thought.thought_type === 'verification') {\n\t\t\tconst targetId = this.resolveThoughtId(session, thought.verification_target);\n\t\t\tif (this._addEdgeIfValid(thought.id, targetId, 'verifies', sessionId)) {\n\t\t\t\temittedRelational = true;\n\t\t\t}\n\t\t}\n\n\t\tif (thought.verification_target !== undefined && thought.thought_type === 'critique') {\n\t\t\tconst targetId = this.resolveThoughtId(session, thought.verification_target);\n\t\t\tif (this._addEdgeIfValid(thought.id, targetId, 'critiques', sessionId)) {\n\t\t\t\temittedRelational = true;\n\t\t\t}\n\t\t}\n\n\t\tif (thought.synthesis_sources?.length) {\n\t\t\tfor (const src of thought.synthesis_sources) {\n\t\t\t\tconst srcId = this.resolveThoughtId(session, src);\n\t\t\t\tif (this._addEdgeIfValid(srcId, thought.id, 'derives_from', sessionId)) {\n\t\t\t\t\temittedRelational = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (thought.revises_thought !== undefined) {\n\t\t\tconst targetId = this.resolveThoughtId(session, thought.revises_thought);\n\t\t\tif (this._addEdgeIfValid(thought.id, targetId, 'revises', sessionId)) {\n\t\t\t\temittedRelational = true;\n\t\t\t}\n\t\t}\n\n\t\t// tool_invocation edge: tool_call → tool_observation\n\t\tif (thought.thought_type === 'tool_observation' && thought._resumedFrom !== undefined) {\n\t\t\tconst toolCallId = this.resolveThoughtId(session, thought._resumedFrom);\n\t\t\tconst meta: Record<string, unknown> = {};\n\t\t\tif (thought.tool_name !== undefined) meta.tool_name = thought.tool_name;\n\t\t\tif (\n\t\t\t\tthis._addEdgeIfValid(\n\t\t\t\t\ttoolCallId,\n\t\t\t\t\tthought.id,\n\t\t\t\t\t'tool_invocation',\n\t\t\t\t\tsessionId,\n\t\t\t\t\tObject.keys(meta).length > 0 ? meta : undefined\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\temittedRelational = true;\n\t\t\t}\n\t\t}\n\n\t\tif (!emittedRelational) {\n\t\t\t// Default: chronological sequence from previous thought (the one before current).\n\t\t\t// current was just pushed, so prev is at length - 2.\n\t\t\tconst history = session.thought_history;\n\t\t\tif (history.length >= 2) {\n\t\t\t\tconst prev = history[history.length - 2]!;\n\t\t\t\tif (prev.id) {\n\t\t\t\t\tthis._addEdgeIfValid(prev.id, thought.id, 'sequence', sessionId);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Resolves a thought_number to its stable id within the given session.\n\t * Searches main history first, then branches.\n\t *\n\t * @returns The thought's id if found and non-empty, undefined otherwise\n\t */\n\tpublic resolveThoughtId(\n\t\tsession: EdgeEmissionSession,\n\t\tthoughtNumber: number\n\t): string | undefined {\n\t\tfor (const t of session.thought_history) {\n\t\t\tif (t.thought_number === thoughtNumber && typeof t.id === 'string' && t.id.length > 0) {\n\t\t\t\treturn t.id;\n\t\t\t}\n\t\t}\n\t\tfor (const branchThoughts of Object.values(session.branches)) {\n\t\t\tfor (const t of branchThoughts) {\n\t\t\t\tif (t.thought_number === thoughtNumber && typeof t.id === 'string' && t.id.length > 0) {\n\t\t\t\t\treturn t.id;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn undefined;\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: string | undefined,\n\t\tto: string | undefined,\n\t\tkind: EdgeKind,\n\t\tsessionId: string,\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: generateUlid(),\n\t\t\tfrom,\n\t\t\tto,\n\t\t\tkind,\n\t\t\tsessionId,\n\t\t\tcreatedAt: Date.now(),\n\t\t\t...(metadata !== undefined ? { metadata } : {}),\n\t\t};\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","sessionId","emittedRelational","parentId","src","srcId","targetId","toolCallId","meta","Object","history","prev","thoughtNumber","t","branchThoughts","from","to","kind","metadata","edge","generateUlid","Date","err","getErrorMessage"],"mappings":";;;AAmCO,MAAMA;IACK,WAAwB;IACxB,UAAmB;IACnB,kBAA0B;IAC1B,QAAgB;IAEjC,YAAYC,MAAyB,CAAE;QACtC,IAAI,CAAC,UAAU,GAAGA,OAAO,SAAS;QAClC,IAAI,CAAC,SAAS,GAAGA,OAAO,QAAQ,IAAI;QACpC,IAAI,CAAC,iBAAiB,GAAGA,OAAO,gBAAgB;QAChD,IAAI,CAAC,OAAO,GAAGA,OAAO,MAAM,IAAI,IAAIC;IACrC;IAGO,YAAqB;QAC3B,OAAO,AAAoBC,WAApB,IAAI,CAAC,UAAU,IAAkB,IAAI,CAAC,S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AAc,KAAKD,iBAAiB,AAAgB,YAAhB,OAAOC,EAAE,EAAE,IAAiBA,EAAE,EAAE,CAAC,MAAM,GAAG,GACnF,OAAOA,EAAE,EAAE;QAGb,KAAK,MAAMC,kBAAkBL,OAAO,MAAM,CAACV,QAAQ,QAAQ,EAC1D,KAAK,MAAMc,KAAKC,eACf,IAAID,EAAE,cAAc,KAAKD,iBAAiB,AAAgB,YAAhB,OAAOC,EAAE,EAAE,IAAiBA,EAAE,EAAE,CAAC,MAAM,GAAG,GACnF,OAAOA,EAAE,EAAE;IAKf;IAOQ,gBACPE,IAAwB,EACxBC,EAAsB,EACtBC,IAAc,EACdhB,SAAiB,EACjBiB,QAAkC,EACxB;QACV,IAAI,CAACH,QAAQ,CAACC,IAAI;YACjB,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,sCAAsC;gBACxDC;gBACA,MAAMF,QAAQ;gBACd,IAAIC,MAAM;YACX;YACA,OAAO;QACR;QACA,MAAMG,OAAa;YAClB,IAAIC;YACJL;YACAC;YACAC;YACAhB;YACA,WAAWoB,KAAK,GAAG;YACnB,GAAIH,AAAapB,WAAboB,WAAyB;gBAAEA;YAAS,IAAI,CAAC,CAAC;QAC/C;QACA,IAAI;YACH,IAAI,CAAC,UAAU,CAAE,OAAO,CAACC;YACzB,OAAO;QACR,EAAE,OAAOG,KAAK;YACb,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,0BAA0B;gBAC3CL;gBACA,OAAOM,gBAAgBD;YACxB;YACA,OAAO;QACR;IACD;AACD"}
|
package/dist/core/reasoning.d.ts
CHANGED
|
@@ -109,8 +109,23 @@ export interface ConfidenceSignals {
|
|
|
109
109
|
verification_coverage: number;
|
|
110
110
|
/** max(chain_depth, branch_count + 1) / total_thoughts, clamped to [0, 1]. Branching is desirable. */
|
|
111
111
|
depth_efficiency: number;
|
|
112
|
-
/** 1 - stddev(confidence values). Defaults to 0.5 if no confidence values. */
|
|
113
|
-
confidence_stability: number;
|
|
112
|
+
/** 1 - stddev(confidence values). Defaults to 0.5 if no confidence values. Null when fewer than 2 confidence values. */
|
|
113
|
+
confidence_stability: number | null;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Raw (unfloored) quality components before the 0.01 floor is applied.
|
|
117
|
+
* Only present when quality_components is present.
|
|
118
|
+
* Useful for debugging quality score calculations.
|
|
119
|
+
*/
|
|
120
|
+
quality_components_raw?: {
|
|
121
|
+
/** Shannon entropy / log2(6) — may be below 0.01 floor. */
|
|
122
|
+
type_diversity: number;
|
|
123
|
+
/** verified / total hypotheses — may be below 0.01 floor. */
|
|
124
|
+
verification_coverage: number;
|
|
125
|
+
/** depth / total — may be below 0.01 floor. */
|
|
126
|
+
depth_efficiency: number;
|
|
127
|
+
/** 1 - stddev — may be below 0.01 floor. Null when fewer than 2 confidence values. */
|
|
128
|
+
confidence_stability: number | null;
|
|
114
129
|
};
|
|
115
130
|
/** Calibrated confidence score (post temperature scaling + prior shrinkage). Only present when features.calibration=true. */
|
|
116
131
|
readonly calibrated_confidence?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reasoning.d.ts","sourceRoot":"","sources":["../../src/core/reasoning.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAErE;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,WAAW,GACpB,SAAS,GACT,YAAY,GACZ,cAAc,GACd,UAAU,GACV,WAAW,GACX,MAAM,GACN,WAAW,GACX,kBAAkB,GAClB,YAAY,GACZ,eAAe,GACf,WAAW,CAAC;AAEf;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,aAAa;IAC7B,2CAA2C;IAC3C,OAAO,EAAE,MAAM,CAAC;IAEhB,uEAAuE;IACvE,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAE7B,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAC;IAEhB,wEAAwE;IACxE,a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BAAmB,CAAC,EAAE,kBAAkB,CAAC;CAClD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,WAAW,cAAc;IAC9B,iCAAiC;IACjC,cAAc,EAAE,MAAM,CAAC;IAEvB,8BAA8B;IAC9B,cAAc,EAAE,MAAM,CAAC;IAEvB,iCAAiC;IACjC,eAAe,EAAE,MAAM,CAAC;IAExB,6CAA6C;IAC7C,YAAY,EAAE,MAAM,CAAC;IAErB,sCAAsC;IACtC,WAAW,EAAE,MAAM,CAAC;IAEpB,kCAAkC;IAClC,mBAAmB,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IAEjD,0BAA0B;IAC1B,gBAAgB,EAAE,MAAM,CAAC;IAEzB,0CAA0C;IAC1C,yBAAyB,EAAE,MAAM,CAAC;IAElC,uCAAuC;IACvC,2BAA2B,EAAE,MAAM,CAAC;IAEpC,uEAAuE;IACvE,qBAAqB,EAAE,MAAM,GAAG,IAAI,CAAC;IAErC,wEAAwE;IACxE,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC"}
|
package/dist/core/thought.d.ts
CHANGED
|
@@ -209,6 +209,13 @@ export interface ThoughtData {
|
|
|
209
209
|
decomposition_children?: string[];
|
|
210
210
|
/** Thought number being backtracked from */
|
|
211
211
|
backtrack_target?: number;
|
|
212
|
+
/**
|
|
213
|
+
* When true, this thought has been logically retracted by a subsequent
|
|
214
|
+
* `backtrack` thought. The thought remains in history (append-only,
|
|
215
|
+
* event-sourcing) but is excluded from quality calculations.
|
|
216
|
+
* Default: false.
|
|
217
|
+
*/
|
|
218
|
+
retracted?: boolean;
|
|
212
219
|
/**
|
|
213
220
|
* Internal: thought_number of the tool_call this tool_observation resumes from.
|
|
214
221
|
* Set transiently by ThoughtProcessor; not part of the public API.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thought.d.ts","sourceRoot":"","sources":["../../src/core/thought.ts"],"names":[],"mappings":"AAAA;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CAAC;IAE5B;;;;;;;OAOG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;;;;;;;OAQG;IACH,eAAe,CAAC,EAAE,SAAS,GAAG,UAAU,GAAG,MAAM,CAAC;IAElD;;;;;;;;;OASG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;;;;;OAQG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB,uCAAuC;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,wCAAwC;IACxC,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEzC,yDAAyD;IACzD,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB,8EAA8E;IAC9E,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B,oDAAoD;IACpD,sBAAsB,CAAC,EAAE,MAAM,EAAE,CAAC;IAElC,4CAA4C;IAC5C,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;;;;OAKG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core/tools/InMemorySuspensionStore.js","sources":["../../../src/core/tools/InMemorySuspensionStore.ts"],"sourcesContent":["/**\n * In-memory implementation of {@link ISuspensionStore}.\n *\n * Stores suspension records in process memory with optional background\n * sweeping of expired entries. Suitable for single-process deployments;\n * cluster setups should provide a shared backend.\n *\n * @module core/tools/InMemorySuspensionStore\n */\n\nimport type { ISuspensionStore, SuspensionRecord } from '../../contracts/suspension.js';\nimport { generateUlid } from '../ids.js';\n\n/**\n * Configuration for {@link InMemorySuspensionStore}.\n */\nexport interface InMemorySuspensionStoreConfig {\n\t/** Default TTL applied to records that omit `ttlMs`. Defaults to 60_000ms. */\n\tttlMs?: number;\n\t/** Sweep interval for the background expiry timer. Defaults to 60_000ms. */\n\tsweepIntervalMs?: number;\n\t/** Optional logger; reserved for future diagnostic output. */\n\tlogger?: unknown;\n}\n\nconst DEFAULT_TTL_MS =
|
|
1
|
+
{"version":3,"file":"core/tools/InMemorySuspensionStore.js","sources":["../../../src/core/tools/InMemorySuspensionStore.ts"],"sourcesContent":["/**\n * In-memory implementation of {@link ISuspensionStore}.\n *\n * Stores suspension records in process memory with optional background\n * sweeping of expired entries. Suitable for single-process deployments;\n * cluster setups should provide a shared backend.\n *\n * @module core/tools/InMemorySuspensionStore\n */\n\nimport type { ISuspensionStore, SuspensionRecord } from '../../contracts/suspension.js';\nimport { generateUlid } from '../ids.js';\n\n/**\n * Configuration for {@link InMemorySuspensionStore}.\n */\nexport interface InMemorySuspensionStoreConfig {\n\t/** Default TTL applied to records that omit `ttlMs`. Defaults to 60_000ms. */\n\tttlMs?: number;\n\t/** Sweep interval for the background expiry timer. Defaults to 60_000ms. */\n\tsweepIntervalMs?: number;\n\t/** Optional logger; reserved for future diagnostic output. */\n\tlogger?: unknown;\n}\n\nconst DEFAULT_TTL_MS = 300_000;\nconst DEFAULT_SWEEP_INTERVAL_MS = 60_000;\n\n/**\n * In-memory suspension store with TTL expiry and background sweep.\n *\n * @example\n * ```typescript\n * const store = new InMemorySuspensionStore({ ttlMs: 30_000 });\n * store.start();\n * const rec = store.suspend({\n * sessionId: 's1',\n * toolCallThoughtNumber: 3,\n * toolName: 'search',\n * toolArguments: { q: 'foo' },\n * expiresAt: 0,\n * });\n * const resumed = store.resume(rec.token);\n * store.stop();\n * ```\n */\nexport class InMemorySuspensionStore implements ISuspensionStore {\n\tprivate readonly _byToken: Map<string, SuspensionRecord> = new Map();\n\tprivate readonly _bySession: Map<string, Set<string>> = new Map();\n\tprivate readonly _ttlMs: number;\n\tprivate readonly _sweepIntervalMs: number;\n\tprivate _timer: ReturnType<typeof setInterval> | null = null;\n\n\tconstructor(config: InMemorySuspensionStoreConfig = {}) {\n\t\tthis._ttlMs = config.ttlMs ?? DEFAULT_TTL_MS;\n\t\tthis._sweepIntervalMs = config.sweepIntervalMs ?? DEFAULT_SWEEP_INTERVAL_MS;\n\t}\n\n\tsuspend(\n\t\trecord: Omit<SuspensionRecord, 'token' | 'createdAt'> & { ttlMs?: number },\n\t): SuspensionRecord {\n\t\tconst token = generateUlid();\n\t\tconst createdAt = Date.now();\n\t\tconst ttlMs = record.ttlMs ?? this._ttlMs;\n\t\tconst expiresAt = createdAt + ttlMs;\n\n\t\tconst full: SuspensionRecord = {\n\t\t\ttoken,\n\t\t\tsessionId: record.sessionId,\n\t\t\ttoolCallThoughtNumber: record.toolCallThoughtNumber,\n\t\t\ttoolName: record.toolName,\n\t\t\ttoolArguments: record.toolArguments,\n\t\t\tcreatedAt,\n\t\t\texpiresAt,\n\t\t};\n\n\t\tthis._byToken.set(token, full);\n\t\tlet bucket = this._bySession.get(full.sessionId);\n\t\tif (!bucket) {\n\t\t\tbucket = new Set();\n\t\t\tthis._bySession.set(full.sessionId, bucket);\n\t\t}\n\t\tbucket.add(token);\n\n\t\treturn full;\n\t}\n\n\tresume(token: string): SuspensionRecord | null {\n\t\tconst rec = this._byToken.get(token);\n\t\tif (!rec) return null;\n\t\tif (rec.expiresAt <= Date.now()) {\n\t\t\tthis._delete(token, rec.sessionId);\n\t\t\treturn null;\n\t\t}\n\t\tthis._delete(token, rec.sessionId);\n\t\treturn rec;\n\t}\n\n\tpeek(token: string): SuspensionRecord | null {\n\t\treturn this._byToken.get(token) ?? null;\n\t}\n\n\texpireOlderThan(now: number): number {\n\t\tlet removed = 0;\n\t\tfor (const [token, rec] of this._byToken) {\n\t\t\tif (rec.expiresAt <= now) {\n\t\t\t\tthis._delete(token, rec.sessionId);\n\t\t\t\tremoved++;\n\t\t\t}\n\t\t}\n\t\treturn removed;\n\t}\n\n\tclearSession(sessionId: string): void {\n\t\tconst bucket = this._bySession.get(sessionId);\n\t\tif (!bucket) return;\n\t\tfor (const token of bucket) {\n\t\t\tthis._byToken.delete(token);\n\t\t}\n\t\tthis._bySession.delete(sessionId);\n\t}\n\n\tsize(sessionId?: string): number {\n\t\tif (sessionId === undefined) return this._byToken.size;\n\t\treturn this._bySession.get(sessionId)?.size ?? 0;\n\t}\n\n\tstart(): void {\n\t\tif (this._timer !== null) return;\n\t\tthis._timer = setInterval(() => {\n\t\t\tthis.expireOlderThan(Date.now());\n\t\t}, this._sweepIntervalMs);\n\t\tthis._timer.unref?.();\n\t}\n\n\tstop(): void {\n\t\tif (this._timer === null) return;\n\t\tclearInterval(this._timer);\n\t\tthis._timer = null;\n\t}\n\n\tprivate _delete(token: string, sessionId: string): void {\n\t\tthis._byToken.delete(token);\n\t\tconst bucket = this._bySession.get(sessionId);\n\t\tif (bucket) {\n\t\t\tbucket.delete(token);\n\t\t\tif (bucket.size === 0) this._bySession.delete(sessionId);\n\t\t}\n\t}\n}\n"],"names":["DEFAULT_TTL_MS","DEFAULT_SWEEP_INTERVAL_MS","InMemorySuspensionStore","Map","config","record","token","generateUlid","createdAt","Date","ttlMs","expiresAt","full","bucket","Set","rec","now","removed","sessionId","undefined","setInterval","clearInterval"],"mappings":";AAyBA,MAAMA,iBAAiB;AACvB,MAAMC,4BAA4B;AAoB3B,MAAMC;IACK,WAA0C,IAAIC,MAAM;IACpD,aAAuC,IAAIA,MAAM;IACjD,OAAe;IACf,iBAAyB;IAClC,SAAgD,KAAK;IAE7D,YAAYC,SAAwC,CAAC,CAAC,CAAE;QACvD,IAAI,CAAC,MAAM,GAAGA,OAAO,KAAK,IAAIJ;QAC9B,IAAI,CAAC,gBAAgB,GAAGI,OAAO,eAAe,IAAIH;IACnD;IAEA,QACCI,MAA0E,EACvD;QACnB,MAAMC,QAAQC;QACd,MAAMC,YAAYC,KAAK,GAAG;QAC1B,MAAMC,QAAQL,OAAO,KAAK,IAAI,IAAI,CAAC,MAAM;QACzC,MAAMM,YAAYH,YAAYE;QAE9B,MAAME,OAAyB;YAC9BN;YACA,WAAWD,OAAO,SAAS;YAC3B,uBAAuBA,OAAO,qBAAqB;YACnD,UAAUA,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4B;IAChD,OAAO,CAAC,OAAO,CAAe;IAG9B;;;;;;;OAOG;IACH,SAAgB,OAAO,EAAE,cAAc,CAAC;IAExC;;;;;;;OAOG;IACH,SAAgB,KAAK,EAAE,YAAY,CAAC;IAEpC;;;;;;;OAOG;IACH,SAAgB,MAAM,EAAE,aAAa,CAAC;IAEtC;;;;;;OAMG;IACH,SAAgB,MAAM,EAAE,YAAY,CAAC;gBAEzB,OAAO,GAAE,aAAkB;IAmCvC;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAsKnC;;;OAGG;mBACkB,2BAA2B;IAYhD;;;OAGG;IACI,YAAY,IAAI,SAAS;IAIhC;;;;OAIG;IACU,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC;IAKnD;;;OAGG;IACI,WAAW,IAAI,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC;IAKtC,cAAc,CAAC,KAAK,EAAE,CAAC,CAAC,UAAU,CAAC,OAAO,wBAAwB,CAAC;IAuBzE,kBAAkB,IAAI,MAAM;IAInC;;;OAGG;IACU,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAyClC;;;OAGG;IACI,KAAK,IAAI,IAAI;IAKpB;;;;OAIG;IACU,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAKrC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAsB,YAAY,CACjC,OAAO,GAAE,aAAkB,GACzB,OAAO,CAAC,iCAAiC,CAAC,CAE5C;AAGD,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,iCAAiC,CAAC,CAmBnF"}
|
package/dist/lib.js
CHANGED
|
@@ -193,6 +193,17 @@ class ToolAwareSequentialThinkingServer extends EventEmitter {
|
|
|
193
193
|
async processThought(input) {
|
|
194
194
|
const startTime = Date.now();
|
|
195
195
|
const thoughtInput = input;
|
|
196
|
+
if ('string' == typeof thoughtInput.register_branch_id && thoughtInput.register_branch_id.length > 0) {
|
|
197
|
+
try {
|
|
198
|
+
this._historyManager.registerBranch(thoughtInput.session_id, thoughtInput.register_branch_id);
|
|
199
|
+
} catch (err) {
|
|
200
|
+
this._logger.warn('registerBranch skipped', {
|
|
201
|
+
branch_id: thoughtInput.register_branch_id,
|
|
202
|
+
error: err instanceof Error ? err.message : String(err)
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
delete thoughtInput.register_branch_id;
|
|
206
|
+
}
|
|
196
207
|
const result = await this._thoughtProcessor.process(thoughtInput);
|
|
197
208
|
const durationSeconds = (Date.now() - startTime) / 1000;
|
|
198
209
|
this._metrics.histogram('thought_processing_duration_seconds', durationSeconds, {});
|