@lucern/graph-primitives 0.1.0-alpha.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.
Files changed (224) hide show
  1. package/README.md +29 -0
  2. package/dist/beliefDecay-Q_26RTc-.d.ts +72 -0
  3. package/dist/beliefDecay.d.ts +2 -0
  4. package/dist/beliefDecay.js +1628 -0
  5. package/dist/beliefDecay.js.map +1 -0
  6. package/dist/beliefEvidenceLinks-42FlR48t.d.ts +77 -0
  7. package/dist/beliefEvidenceLinks.d.ts +1 -0
  8. package/dist/beliefEvidenceLinks.js +1978 -0
  9. package/dist/beliefEvidenceLinks.js.map +1 -0
  10. package/dist/beliefLifecycle-C-AehZgF.d.ts +43 -0
  11. package/dist/beliefLifecycle.d.ts +1 -0
  12. package/dist/beliefLifecycle.js +98 -0
  13. package/dist/beliefLifecycle.js.map +1 -0
  14. package/dist/confidencePropagationDispatch.d.ts +46 -0
  15. package/dist/confidencePropagationDispatch.js +744 -0
  16. package/dist/confidencePropagationDispatch.js.map +1 -0
  17. package/dist/contradictions-Hdwl7zid.d.ts +71 -0
  18. package/dist/contradictions.d.ts +1 -0
  19. package/dist/contradictions.js +1557 -0
  20. package/dist/contradictions.js.map +1 -0
  21. package/dist/convex.d.ts +23 -0
  22. package/dist/convex.js +17 -0
  23. package/dist/convex.js.map +1 -0
  24. package/dist/edgeValidation-CeI0wc0r.d.ts +35 -0
  25. package/dist/edgeValidation.d.ts +2 -0
  26. package/dist/edgeValidation.js +307 -0
  27. package/dist/edgeValidation.js.map +1 -0
  28. package/dist/edges/contains.d.ts +6 -0
  29. package/dist/edges/contains.js +14 -0
  30. package/dist/edges/contains.js.map +1 -0
  31. package/dist/edges/contradicts.d.ts +6 -0
  32. package/dist/edges/contradicts.js +183 -0
  33. package/dist/edges/contradicts.js.map +1 -0
  34. package/dist/edges/dependsOn.d.ts +6 -0
  35. package/dist/edges/dependsOn.js +240 -0
  36. package/dist/edges/dependsOn.js.map +1 -0
  37. package/dist/edges/derivedFrom.d.ts +6 -0
  38. package/dist/edges/derivedFrom.js +14 -0
  39. package/dist/edges/derivedFrom.js.map +1 -0
  40. package/dist/edges/elaborates.d.ts +6 -0
  41. package/dist/edges/elaborates.js +100 -0
  42. package/dist/edges/elaborates.js.map +1 -0
  43. package/dist/edges/index.d.ts +3 -0
  44. package/dist/edges/index.js +556 -0
  45. package/dist/edges/index.js.map +1 -0
  46. package/dist/edges/informs.d.ts +6 -0
  47. package/dist/edges/informs.js +112 -0
  48. package/dist/edges/informs.js.map +1 -0
  49. package/dist/edges/propagationTypes.d.ts +39 -0
  50. package/dist/edges/propagationTypes.js +17 -0
  51. package/dist/edges/propagationTypes.js.map +1 -0
  52. package/dist/edges/refutes.d.ts +6 -0
  53. package/dist/edges/refutes.js +108 -0
  54. package/dist/edges/refutes.js.map +1 -0
  55. package/dist/edges/supports.d.ts +6 -0
  56. package/dist/edges/supports.js +193 -0
  57. package/dist/edges/supports.js.map +1 -0
  58. package/dist/edges/tests.d.ts +6 -0
  59. package/dist/edges/tests.js +14 -0
  60. package/dist/edges/tests.js.map +1 -0
  61. package/dist/edges/utils.d.ts +12 -0
  62. package/dist/edges/utils.js +188 -0
  63. package/dist/edges/utils.js.map +1 -0
  64. package/dist/embeddingTrigger.d.ts +24 -0
  65. package/dist/embeddingTrigger.js +24 -0
  66. package/dist/embeddingTrigger.js.map +1 -0
  67. package/dist/entityBridge-DMaKooYn.d.ts +59 -0
  68. package/dist/entityBridge.d.ts +1 -0
  69. package/dist/entityBridge.js +663 -0
  70. package/dist/entityBridge.js.map +1 -0
  71. package/dist/entityLifecycle-BkhRJ-XI.d.ts +69 -0
  72. package/dist/entityLifecycle.d.ts +1 -0
  73. package/dist/entityLifecycle.js +2083 -0
  74. package/dist/entityLifecycle.js.map +1 -0
  75. package/dist/entityValidation-KLZ_Xl2D.d.ts +50 -0
  76. package/dist/entityValidation.d.ts +3 -0
  77. package/dist/entityValidation.js +71 -0
  78. package/dist/entityValidation.js.map +1 -0
  79. package/dist/epistemicAnswers-DSP1slZ9.d.ts +67 -0
  80. package/dist/epistemicAnswers.d.ts +1 -0
  81. package/dist/epistemicAnswers.js +1650 -0
  82. package/dist/epistemicAnswers.js.map +1 -0
  83. package/dist/epistemicBeliefs-DtFVTp-k.d.ts +377 -0
  84. package/dist/epistemicBeliefs.d.ts +5 -0
  85. package/dist/epistemicBeliefs.js +6386 -0
  86. package/dist/epistemicBeliefs.js.map +1 -0
  87. package/dist/epistemicContractHelpers.d.ts +1 -0
  88. package/dist/epistemicContractHelpers.js +320 -0
  89. package/dist/epistemicContractHelpers.js.map +1 -0
  90. package/dist/epistemicContracts.d.ts +77 -0
  91. package/dist/epistemicContracts.js +8436 -0
  92. package/dist/epistemicContracts.js.map +1 -0
  93. package/dist/epistemicEdges-DcA8ErUG.d.ts +191 -0
  94. package/dist/epistemicEdges.d.ts +2 -0
  95. package/dist/epistemicEdges.js +2749 -0
  96. package/dist/epistemicEdges.js.map +1 -0
  97. package/dist/epistemicEvidence-Bo638XDP.d.ts +128 -0
  98. package/dist/epistemicEvidence.d.ts +3 -0
  99. package/dist/epistemicEvidence.js +3282 -0
  100. package/dist/epistemicEvidence.js.map +1 -0
  101. package/dist/epistemicHelpers-Bd9xbaib.d.ts +329 -0
  102. package/dist/epistemicHelpers.d.ts +4 -0
  103. package/dist/epistemicHelpers.js +999 -0
  104. package/dist/epistemicHelpers.js.map +1 -0
  105. package/dist/epistemicLinking-CyeLOIzN.d.ts +35 -0
  106. package/dist/epistemicLinking.d.ts +1 -0
  107. package/dist/epistemicLinking.js +1391 -0
  108. package/dist/epistemicLinking.js.map +1 -0
  109. package/dist/epistemicNodes-BpD6Koud.d.ts +167 -0
  110. package/dist/epistemicNodes.d.ts +2 -0
  111. package/dist/epistemicNodes.js +2942 -0
  112. package/dist/epistemicNodes.js.map +1 -0
  113. package/dist/epistemicQuestions-CmEeY6zQ.d.ts +214 -0
  114. package/dist/epistemicQuestions.d.ts +3 -0
  115. package/dist/epistemicQuestions.js +4993 -0
  116. package/dist/epistemicQuestions.js.map +1 -0
  117. package/dist/epistemicSources-ZazxHOK1.d.ts +25 -0
  118. package/dist/epistemicSources.d.ts +1 -0
  119. package/dist/epistemicSources.js +2025 -0
  120. package/dist/epistemicSources.js.map +1 -0
  121. package/dist/evaluators/index.d.ts +9 -0
  122. package/dist/evaluators/index.js +8440 -0
  123. package/dist/evaluators/index.js.map +1 -0
  124. package/dist/evaluators/lintCheckerEvaluator.d.ts +11 -0
  125. package/dist/evaluators/lintCheckerEvaluator.js +155 -0
  126. package/dist/evaluators/lintCheckerEvaluator.js.map +1 -0
  127. package/dist/evaluators/sentryCheckerEvaluator.d.ts +11 -0
  128. package/dist/evaluators/sentryCheckerEvaluator.js +126 -0
  129. package/dist/evaluators/sentryCheckerEvaluator.js.map +1 -0
  130. package/dist/evaluators/shared.d.ts +27 -0
  131. package/dist/evaluators/shared.js +92 -0
  132. package/dist/evaluators/shared.js.map +1 -0
  133. package/dist/evaluators/testRunnerEvaluator.d.ts +17 -0
  134. package/dist/evaluators/testRunnerEvaluator.js +232 -0
  135. package/dist/evaluators/testRunnerEvaluator.js.map +1 -0
  136. package/dist/evaluators/tscCheckerEvaluator.d.ts +11 -0
  137. package/dist/evaluators/tscCheckerEvaluator.js +189 -0
  138. package/dist/evaluators/tscCheckerEvaluator.js.map +1 -0
  139. package/dist/globalId-DKh9d_uD.d.ts +20 -0
  140. package/dist/globalId.d.ts +1 -0
  141. package/dist/globalId.js +15 -0
  142. package/dist/globalId.js.map +1 -0
  143. package/dist/graphTypes-CpgIuCdo.d.ts +52 -0
  144. package/dist/graphTypes.d.ts +1 -0
  145. package/dist/graphTypes.js +120 -0
  146. package/dist/graphTypes.js.map +1 -0
  147. package/dist/helpers-BYHIk5vU.d.ts +27 -0
  148. package/dist/helpers.d.ts +4 -0
  149. package/dist/helpers.js +313 -0
  150. package/dist/helpers.js.map +1 -0
  151. package/dist/index-Dct1T70K.d.ts +25 -0
  152. package/dist/index-Dq-7R-gi.d.ts +31 -0
  153. package/dist/index.d.ts +45 -0
  154. package/dist/index.js +22294 -0
  155. package/dist/index.js.map +1 -0
  156. package/dist/invariantEnforcement.d.ts +52 -0
  157. package/dist/invariantEnforcement.js +231 -0
  158. package/dist/invariantEnforcement.js.map +1 -0
  159. package/dist/logicalRoleInference-CJxqWi3u.d.ts +16 -0
  160. package/dist/logicalRoleInference.d.ts +3 -0
  161. package/dist/logicalRoleInference.js +64 -0
  162. package/dist/logicalRoleInference.js.map +1 -0
  163. package/dist/matcherFeedbackUtils.d.ts +33 -0
  164. package/dist/matcherFeedbackUtils.js +95 -0
  165. package/dist/matcherFeedbackUtils.js.map +1 -0
  166. package/dist/ontology-matching-Buhu23ss.d.ts +48 -0
  167. package/dist/ontology-matching.d.ts +2 -0
  168. package/dist/ontology-matching.js +346 -0
  169. package/dist/ontology-matching.js.map +1 -0
  170. package/dist/ontologyApproval-Ba0Jjk1k.d.ts +26 -0
  171. package/dist/ontologyApproval.d.ts +1 -0
  172. package/dist/ontologyApproval.js +78 -0
  173. package/dist/ontologyApproval.js.map +1 -0
  174. package/dist/ontologyDefinitions.d.ts +72 -0
  175. package/dist/ontologyDefinitions.js +635 -0
  176. package/dist/ontologyDefinitions.js.map +1 -0
  177. package/dist/ontologyHelpers.d.ts +79 -0
  178. package/dist/ontologyHelpers.js +81 -0
  179. package/dist/ontologyHelpers.js.map +1 -0
  180. package/dist/ontologyRegistry-B67rPJ16.d.ts +31 -0
  181. package/dist/ontologyRegistry.d.ts +1 -0
  182. package/dist/ontologyRegistry.js +296 -0
  183. package/dist/ontologyRegistry.js.map +1 -0
  184. package/dist/projectionReconciliation-CxrXYGaB.d.ts +20 -0
  185. package/dist/projectionReconciliation.d.ts +1 -0
  186. package/dist/projectionReconciliation.js +261 -0
  187. package/dist/projectionReconciliation.js.map +1 -0
  188. package/dist/projectionStaleness-CAdpIsaW.d.ts +51 -0
  189. package/dist/projectionStaleness.d.ts +1 -0
  190. package/dist/projectionStaleness.js +57 -0
  191. package/dist/projectionStaleness.js.map +1 -0
  192. package/dist/questionEvidenceLinks-BdQD0TkM.d.ts +34 -0
  193. package/dist/questionEvidenceLinks.d.ts +1 -0
  194. package/dist/questionEvidenceLinks.js +1690 -0
  195. package/dist/questionEvidenceLinks.js.map +1 -0
  196. package/dist/resolverTypes-CC8Ea2E2.d.ts +20 -0
  197. package/dist/resolverTypes.d.ts +4 -0
  198. package/dist/resolverTypes.js +3 -0
  199. package/dist/resolverTypes.js.map +1 -0
  200. package/dist/resolvers-Br1a6eLV.d.ts +14 -0
  201. package/dist/resolvers.d.ts +5 -0
  202. package/dist/resolvers.js +308 -0
  203. package/dist/resolvers.js.map +1 -0
  204. package/dist/scopeResolverCompat.d.ts +26 -0
  205. package/dist/scopeResolverCompat.js +242 -0
  206. package/dist/scopeResolverCompat.js.map +1 -0
  207. package/dist/text-matching-CMn2WnVD.d.ts +40 -0
  208. package/dist/text-matching.d.ts +2 -0
  209. package/dist/text-matching.js +246 -0
  210. package/dist/text-matching.js.map +1 -0
  211. package/dist/topicOntologyResolver.d.ts +80 -0
  212. package/dist/topicOntologyResolver.js +67 -0
  213. package/dist/topicOntologyResolver.js.map +1 -0
  214. package/dist/topicProjectOverlay.d.ts +92 -0
  215. package/dist/topicProjectOverlay.js +249 -0
  216. package/dist/topicProjectOverlay.js.map +1 -0
  217. package/dist/topicScope-By_zp4tt.d.ts +34 -0
  218. package/dist/topicScope.d.ts +3 -0
  219. package/dist/topicScope.js +206 -0
  220. package/dist/topicScope.js.map +1 -0
  221. package/dist/workspaceIsolation.d.ts +44 -0
  222. package/dist/workspaceIsolation.js +950 -0
  223. package/dist/workspaceIsolation.js.map +1 -0
  224. package/package.json +46 -0
@@ -0,0 +1,744 @@
1
+ // ../confidence/src/v1/operations/subjectiveLogic/index.ts
2
+ function opinion(belief, disbelief, uncertainty, baseRate = 0.5) {
3
+ const b = Math.max(0, Math.min(1, belief));
4
+ const d = Math.max(0, Math.min(1, disbelief));
5
+ const u = Math.max(0, Math.min(1, uncertainty));
6
+ const a = Math.max(0, Math.min(1, baseRate));
7
+ const sum = b + d + u;
8
+ if (sum === 0) {
9
+ return { b: 0, d: 0, u: 1, a };
10
+ }
11
+ return {
12
+ b: b / sum,
13
+ d: d / sum,
14
+ u: u / sum,
15
+ a
16
+ };
17
+ }
18
+ function vacuous(baseRate = 0.5) {
19
+ return { b: 0, d: 0, u: 1, a: baseRate };
20
+ }
21
+ function project(o) {
22
+ return o.b + o.a * o.u;
23
+ }
24
+ function cumulativeFusion(left, right) {
25
+ if (left.u === 0 && right.u === 0) {
26
+ return opinion(
27
+ (left.b + right.b) / 2,
28
+ (left.d + right.d) / 2,
29
+ 0,
30
+ (left.a + right.a) / 2
31
+ );
32
+ }
33
+ const k = left.u + right.u - left.u * right.u;
34
+ if (k === 0) {
35
+ return vacuous((left.a + right.a) / 2);
36
+ }
37
+ return opinion(
38
+ (left.b * right.u + right.b * left.u) / k,
39
+ (left.d * right.u + right.d * left.u) / k,
40
+ left.u * right.u / k,
41
+ (left.a + right.a) / 2
42
+ );
43
+ }
44
+ function trustDiscount(sourceOpinion, trust) {
45
+ const weight = Math.max(0, Math.min(1, Math.abs(trust)));
46
+ return opinion(
47
+ weight * sourceOpinion.b,
48
+ weight * sourceOpinion.d,
49
+ 1 - weight * (sourceOpinion.b + sourceOpinion.d),
50
+ sourceOpinion.a
51
+ );
52
+ }
53
+ var EPSILON = 1e-9;
54
+ function childBaseRateFallback(ifTrue, ifFalse, fallbackBaseRate) {
55
+ if (fallbackBaseRate !== void 0) {
56
+ return Math.max(0, Math.min(1, fallbackBaseRate));
57
+ }
58
+ if (Math.abs(ifTrue.a - ifFalse.a) <= EPSILON) {
59
+ return ifTrue.a;
60
+ }
61
+ return (ifTrue.a + ifFalse.a) / 2;
62
+ }
63
+ function computeConditionalDeductionBaseRate(opinionA, ifTrue, ifFalse, fallbackBaseRate) {
64
+ const denominator = 1 - opinionA.a * ifTrue.u - (1 - opinionA.a) * ifFalse.u;
65
+ if (ifTrue.u + ifFalse.u < 2 - EPSILON && Math.abs(denominator) > EPSILON) {
66
+ const baseRate = (opinionA.a * ifTrue.b + (1 - opinionA.a) * ifFalse.b) / denominator;
67
+ if (baseRate >= -EPSILON && baseRate <= 1 + EPSILON) {
68
+ return Math.max(0, Math.min(1, baseRate));
69
+ }
70
+ }
71
+ return fallbackBaseRate;
72
+ }
73
+ function safeCorrectionTerm(numerator, denominator) {
74
+ if (Math.abs(denominator) <= EPSILON) {
75
+ return void 0;
76
+ }
77
+ const value = numerator / denominator;
78
+ if (!Number.isFinite(value)) {
79
+ return void 0;
80
+ }
81
+ return Math.max(0, value);
82
+ }
83
+ function conditionalDeduction(opinionA, ifTrue, ifFalse, fallbackBaseRate) {
84
+ const fallbackChildBaseRate = childBaseRateFallback(
85
+ ifTrue,
86
+ ifFalse,
87
+ fallbackBaseRate
88
+ );
89
+ const childBaseRate = computeConditionalDeductionBaseRate(
90
+ opinionA,
91
+ ifTrue,
92
+ ifFalse,
93
+ fallbackChildBaseRate
94
+ );
95
+ const projectedAntecedent = project(opinionA);
96
+ const projectedAntecedentComplement = 1 - projectedAntecedent;
97
+ const intermediateBelief = opinionA.b * ifTrue.b + opinionA.d * ifFalse.b + opinionA.u * (ifTrue.b * opinionA.a + ifFalse.b * (1 - opinionA.a));
98
+ const intermediateDisbelief = opinionA.b * ifTrue.d + opinionA.d * ifFalse.d + opinionA.u * (ifTrue.d * opinionA.a + ifFalse.d * (1 - opinionA.a));
99
+ const intermediateUncertainty = opinionA.b * ifTrue.u + opinionA.d * ifFalse.u + opinionA.u * (ifTrue.u * opinionA.a + ifFalse.u * (1 - opinionA.a));
100
+ const projectedVacuousDeduction = ifTrue.b * opinionA.a + ifFalse.b * (1 - opinionA.a) + childBaseRate * (ifTrue.u * opinionA.a + ifFalse.u * (1 - opinionA.a));
101
+ const projectedConditionalA = ifTrue.b + childBaseRate * (1 - ifTrue.b - ifTrue.d);
102
+ let correction = 0;
103
+ if (ifTrue.b > ifFalse.b && ifTrue.d > ifFalse.d || ifTrue.b <= ifFalse.b && ifTrue.d <= ifFalse.d) {
104
+ correction = 0;
105
+ } else if (ifTrue.b > ifFalse.b && ifTrue.d <= ifFalse.d) {
106
+ const beliefGap = ifTrue.b - ifFalse.b;
107
+ const disbeliefGap = ifFalse.d - ifTrue.d;
108
+ if (projectedVacuousDeduction <= projectedConditionalA && projectedAntecedent <= opinionA.a) {
109
+ correction = safeCorrectionTerm(
110
+ opinionA.a * opinionA.u * (intermediateBelief - ifTrue.b),
111
+ projectedAntecedent * childBaseRate
112
+ ) ?? 0;
113
+ } else if (projectedVacuousDeduction <= projectedConditionalA && projectedAntecedent > opinionA.a) {
114
+ correction = safeCorrectionTerm(
115
+ opinionA.a * opinionA.u * (intermediateDisbelief - ifTrue.d) * beliefGap,
116
+ projectedAntecedentComplement * childBaseRate * disbeliefGap
117
+ ) ?? 0;
118
+ } else if (projectedVacuousDeduction > projectedConditionalA && projectedAntecedent <= opinionA.a) {
119
+ correction = safeCorrectionTerm(
120
+ (1 - opinionA.a) * opinionA.u * (intermediateBelief - ifTrue.b) * disbeliefGap,
121
+ projectedAntecedent * (1 - childBaseRate) * beliefGap
122
+ ) ?? 0;
123
+ } else {
124
+ correction = safeCorrectionTerm(
125
+ (1 - opinionA.a) * opinionA.u * (intermediateDisbelief - ifTrue.d),
126
+ projectedAntecedentComplement * (1 - childBaseRate)
127
+ ) ?? 0;
128
+ }
129
+ } else {
130
+ const beliefGap = ifFalse.b - ifTrue.b;
131
+ const disbeliefGap = ifTrue.d - ifFalse.d;
132
+ if (projectedVacuousDeduction <= projectedConditionalA && projectedAntecedent <= opinionA.a) {
133
+ correction = safeCorrectionTerm(
134
+ (1 - opinionA.a) * opinionA.u * (intermediateDisbelief - ifTrue.d) * beliefGap,
135
+ projectedAntecedent * childBaseRate * disbeliefGap
136
+ ) ?? 0;
137
+ } else if (projectedVacuousDeduction <= projectedConditionalA && projectedAntecedent > opinionA.a) {
138
+ correction = safeCorrectionTerm(
139
+ (1 - opinionA.a) * opinionA.u * (intermediateBelief - ifTrue.b),
140
+ projectedAntecedentComplement * childBaseRate
141
+ ) ?? 0;
142
+ } else if (projectedVacuousDeduction > projectedConditionalA && projectedAntecedent <= opinionA.a) {
143
+ correction = safeCorrectionTerm(
144
+ opinionA.a * opinionA.u * (intermediateDisbelief - ifTrue.d),
145
+ projectedAntecedent * (1 - childBaseRate)
146
+ ) ?? 0;
147
+ } else {
148
+ correction = safeCorrectionTerm(
149
+ opinionA.a * opinionA.u * (intermediateBelief - ifTrue.b) * disbeliefGap,
150
+ projectedAntecedentComplement * (1 - childBaseRate) * beliefGap
151
+ ) ?? 0;
152
+ }
153
+ }
154
+ return opinion(
155
+ intermediateBelief - childBaseRate * correction,
156
+ intermediateDisbelief - (1 - childBaseRate) * correction,
157
+ intermediateUncertainty + correction,
158
+ childBaseRate
159
+ );
160
+ }
161
+ function negate(o) {
162
+ return { b: o.d, d: o.b, u: o.u, a: 1 - o.a };
163
+ }
164
+ function constraintFusion(left, right, mode = "pressure") {
165
+ if (mode === "redistribute") {
166
+ const leftProjected = project(left);
167
+ const rightProjected = project(right);
168
+ const total = leftProjected + rightProjected;
169
+ if (total <= 1) {
170
+ return { o1: left, o2: right };
171
+ }
172
+ const scale = 1 / total;
173
+ return {
174
+ o1: opinion(
175
+ left.b * scale,
176
+ left.d + left.b * (1 - scale),
177
+ left.u,
178
+ left.a
179
+ ),
180
+ o2: opinion(
181
+ right.b * scale,
182
+ right.d + right.b * (1 - scale),
183
+ right.u,
184
+ right.a
185
+ )
186
+ };
187
+ }
188
+ const pressureLeft = right.b * 0.5;
189
+ const pressureRight = left.b * 0.5;
190
+ return {
191
+ o1: opinion(
192
+ left.b - pressureLeft * 0.3,
193
+ left.d + pressureLeft * 0.3,
194
+ left.u,
195
+ left.a
196
+ ),
197
+ o2: opinion(
198
+ right.b - pressureRight * 0.3,
199
+ right.d + pressureRight * 0.3,
200
+ right.u,
201
+ right.a
202
+ )
203
+ };
204
+ }
205
+
206
+ // ../confidence/src/v1/operations/scoring.ts
207
+ function finiteNumber(value) {
208
+ return typeof value === "number" && Number.isFinite(value) ? value : void 0;
209
+ }
210
+ function clamp01(value) {
211
+ return Math.max(0, Math.min(1, value));
212
+ }
213
+ function confidenceFromOpinion(opinion2) {
214
+ return clamp01(opinion2.b + opinion2.a * opinion2.u);
215
+ }
216
+ function readOpinionFromRecord(source, fallback = {}) {
217
+ const record = source && typeof source === "object" ? source : {};
218
+ return {
219
+ b: finiteNumber(record.b) ?? finiteNumber(record.belief) ?? finiteNumber(record.slBelief) ?? finiteNumber(record.opinion_b) ?? fallback.b ?? 0,
220
+ d: finiteNumber(record.d) ?? finiteNumber(record.disbelief) ?? finiteNumber(record.slDisbelief) ?? finiteNumber(record.opinion_d) ?? fallback.d ?? 0,
221
+ u: finiteNumber(record.u) ?? finiteNumber(record.uncertainty) ?? finiteNumber(record.slUncertainty) ?? finiteNumber(record.opinion_u) ?? fallback.u ?? 1,
222
+ a: finiteNumber(record.a) ?? finiteNumber(record.baseRate) ?? finiteNumber(record.slBaseRate) ?? finiteNumber(record.opinion_a) ?? fallback.a ?? 0.5
223
+ };
224
+ }
225
+ function hasProjectedOpinionChanged(current, next, tolerance = 0.01) {
226
+ return Math.abs(confidenceFromOpinion(next) - confidenceFromOpinion(current)) >= tolerance;
227
+ }
228
+
229
+ // ../confidence/src/v1/operations/dynamics/cascade.ts
230
+ function dampedDependencyOpinion(dependencyOpinion, beliefOpinion, mode = "continuous", threshold = 0.3) {
231
+ const dependencyProjection = project(dependencyOpinion);
232
+ if (mode === "threshold") {
233
+ if (dependencyProjection < threshold) {
234
+ return opinion(
235
+ 0,
236
+ beliefOpinion.d + beliefOpinion.b * 0.5,
237
+ 0.5,
238
+ beliefOpinion.a
239
+ );
240
+ }
241
+ return beliefOpinion;
242
+ }
243
+ const dampingFactor = Math.pow(dependencyProjection, 0.5);
244
+ return opinion(
245
+ beliefOpinion.b * dampingFactor,
246
+ beliefOpinion.d + beliefOpinion.b * (1 - dampingFactor) * 0.3,
247
+ beliefOpinion.u + beliefOpinion.b * (1 - dampingFactor) * 0.7,
248
+ beliefOpinion.a
249
+ );
250
+ }
251
+ function dampedDependencyCascade(dependencyOpinion, beliefOpinion, mode = "continuous") {
252
+ return {
253
+ opinion: dampedDependencyOpinion(dependencyOpinion, beliefOpinion, mode),
254
+ operator: "dependency_cascade",
255
+ rationale: `Damped dependency cascade (${mode}): prerequisite at ${project(
256
+ dependencyOpinion
257
+ ).toFixed(2)}`
258
+ };
259
+ }
260
+
261
+ // ../confidence/src/v1/operations/dynamics/defeat.ts
262
+ function applyNegativeSupport(source, target, weight, metadata = {}) {
263
+ if (metadata.constraint === "xor") {
264
+ const result = constraintFusion(
265
+ source,
266
+ target,
267
+ metadata.normalization ?? "pressure"
268
+ );
269
+ return {
270
+ opinion: result.o2,
271
+ operator: "constraint_fusion",
272
+ rationale: `XOR constraint: source belief at ${project(source).toFixed(
273
+ 2
274
+ )} pressures target`
275
+ };
276
+ }
277
+ const discounted = trustDiscount(negate(source), Math.abs(weight));
278
+ return {
279
+ opinion: cumulativeFusion(target, discounted),
280
+ operator: "cumulative_fusion",
281
+ rationale: `Contradicting evidence (weight=${weight.toFixed(
282
+ 2
283
+ )}) from source at ${project(source).toFixed(2)}`
284
+ };
285
+ }
286
+ function applyNegativeEvidence(source, target, weight) {
287
+ const discounted = trustDiscount(negate(source), Math.abs(weight));
288
+ return {
289
+ opinion: cumulativeFusion(target, discounted),
290
+ operator: "cumulative_fusion",
291
+ rationale: `Contradicting evidence (weight=${weight.toFixed(2)})`
292
+ };
293
+ }
294
+
295
+ // src/edges/contains.ts
296
+ var containsPropagationSpec = {
297
+ edgeType: "contains",
298
+ direction: "outgoing",
299
+ transitivity: "none",
300
+ damping: 1,
301
+ maxHops: 1,
302
+ operator: () => null,
303
+ description: "Structural containment only. Traversed for explicit semantics, but it never propagates opinions."
304
+ };
305
+
306
+ // src/edges/utils.ts
307
+ function readEdgeMetadata(edge) {
308
+ return {
309
+ constraint: edge.constraint ?? void 0,
310
+ normalization: edge.normalization ?? void 0,
311
+ propagation: edge.propagation ?? void 0,
312
+ conditionalA: edge.conditionalA ?? void 0,
313
+ conditionalNotA: edge.conditionalNotA ?? void 0
314
+ };
315
+ }
316
+ function applyPerHopDamping(sourceOpinion, damping) {
317
+ if (damping >= 1) {
318
+ return sourceOpinion;
319
+ }
320
+ return trustDiscount(sourceOpinion, Math.max(0, damping));
321
+ }
322
+ function annotateRationale(result, spec, hop) {
323
+ return {
324
+ ...result,
325
+ rationale: `hop=${hop} edge=${spec.edgeType} damping=${spec.damping.toFixed(
326
+ 2
327
+ )} :: ${result.rationale}`
328
+ };
329
+ }
330
+ function propagatePositiveSupport(sourceOpinion, targetOpinion, edgeWeight) {
331
+ const discounted = trustDiscount(sourceOpinion, Math.abs(edgeWeight));
332
+ return {
333
+ opinion: cumulativeFusion(targetOpinion, discounted),
334
+ operator: "cumulative_fusion",
335
+ rationale: `Supporting evidence (weight=${edgeWeight.toFixed(
336
+ 2
337
+ )}) from source at ${project(sourceOpinion).toFixed(2)}`
338
+ };
339
+ }
340
+ function propagatePositiveInform(sourceOpinion, targetOpinion, edgeWeight) {
341
+ const discounted = trustDiscount(sourceOpinion, Math.abs(edgeWeight));
342
+ return {
343
+ opinion: cumulativeFusion(targetOpinion, discounted),
344
+ operator: "cumulative_fusion",
345
+ rationale: `Supporting evidence (weight=${edgeWeight.toFixed(2)})`
346
+ };
347
+ }
348
+ function propagateNegativeSupportWithMetadata(sourceOpinion, targetOpinion, edgeWeight, edge) {
349
+ return applyNegativeSupport(
350
+ sourceOpinion,
351
+ targetOpinion,
352
+ edgeWeight,
353
+ readEdgeMetadata(edge)
354
+ );
355
+ }
356
+ function propagateNegativeInform(sourceOpinion, targetOpinion, edgeWeight) {
357
+ return applyNegativeEvidence(sourceOpinion, targetOpinion, edgeWeight);
358
+ }
359
+
360
+ // src/edges/contradicts.ts
361
+ var contradictsPropagationSpec = {
362
+ edgeType: "contradicts",
363
+ direction: "bidirectional",
364
+ transitivity: "none",
365
+ damping: 0.85,
366
+ maxHops: 1,
367
+ operator: (sourceOpinion, targetOpinion, edge, context) => {
368
+ const dampedSource = applyPerHopDamping(
369
+ sourceOpinion,
370
+ context.spec.damping
371
+ );
372
+ const negativeWeight = -Math.abs(edge.weight ?? 1);
373
+ const result = propagateNegativeSupportWithMetadata(
374
+ dampedSource,
375
+ targetOpinion,
376
+ negativeWeight,
377
+ edge
378
+ );
379
+ return annotateRationale(result, context.spec, context.hop);
380
+ },
381
+ description: "Legacy contradiction edges move negative pressure in either direction, but never beyond one hop."
382
+ };
383
+
384
+ // src/edges/dependsOn.ts
385
+ var dependsOnPropagationSpec = {
386
+ edgeType: "depends_on",
387
+ direction: "incoming",
388
+ transitivity: "damped",
389
+ damping: 0.8,
390
+ maxHops: "unbounded",
391
+ operator: (sourceOpinion, targetOpinion, edge, context) => {
392
+ const dampedSource = applyPerHopDamping(
393
+ sourceOpinion,
394
+ context.spec.damping
395
+ );
396
+ const metadata = readEdgeMetadata(edge);
397
+ if (metadata.conditionalA && metadata.conditionalNotA) {
398
+ const deducedOpinion = conditionalDeduction(
399
+ dampedSource,
400
+ metadata.conditionalA,
401
+ metadata.conditionalNotA,
402
+ targetOpinion.a
403
+ );
404
+ return annotateRationale(
405
+ {
406
+ opinion: deducedOpinion,
407
+ operator: "conditional_deduction",
408
+ rationale: `Conditional deduction: prerequisite at ${project(
409
+ dampedSource
410
+ ).toFixed(2)}`
411
+ },
412
+ context.spec,
413
+ context.hop
414
+ );
415
+ }
416
+ const result = dampedDependencyCascade(
417
+ dampedSource,
418
+ targetOpinion,
419
+ metadata.propagation ?? "continuous"
420
+ );
421
+ return annotateRationale(result, context.spec, context.hop);
422
+ },
423
+ description: "Structural gating. Textbook conditional deduction when edge conditionals exist, otherwise damped dependency cascade through downstream chains."
424
+ };
425
+
426
+ // src/edges/derivedFrom.ts
427
+ var derivedFromPropagationSpec = {
428
+ edgeType: "derived_from",
429
+ direction: "incoming",
430
+ transitivity: "none",
431
+ damping: 1,
432
+ maxHops: 1,
433
+ operator: () => null,
434
+ description: "Provenance only. The traversal surface stays explicit, but confidence does not move across derived_from edges."
435
+ };
436
+
437
+ // src/edges/elaborates.ts
438
+ var elaboratesPropagationSpec = {
439
+ edgeType: "elaborates",
440
+ direction: "outgoing",
441
+ transitivity: "damped",
442
+ damping: 0.7,
443
+ maxHops: 2,
444
+ operator: (sourceOpinion, targetOpinion, edge, context) => {
445
+ const dampedSource = applyPerHopDamping(
446
+ sourceOpinion,
447
+ context.spec.damping
448
+ );
449
+ const contextualWeight = Math.min(Math.abs(edge.weight ?? 0.35), 0.35);
450
+ const result = propagatePositiveInform(
451
+ dampedSource,
452
+ targetOpinion,
453
+ contextualWeight
454
+ );
455
+ return annotateRationale(result, context.spec, context.hop);
456
+ },
457
+ description: "Context-rich supporting detail. Elaborates carries a small positive effect with short, damped chaining."
458
+ };
459
+
460
+ // src/edges/informs.ts
461
+ var informsPropagationSpec = {
462
+ edgeType: "informs",
463
+ direction: "outgoing",
464
+ transitivity: "full",
465
+ damping: 0.92,
466
+ maxHops: "unbounded",
467
+ operator: (sourceOpinion, targetOpinion, edge, context) => {
468
+ const dampedSource = applyPerHopDamping(
469
+ sourceOpinion,
470
+ context.spec.damping
471
+ );
472
+ const weight = edge.weight ?? 1;
473
+ const result = weight < 0 ? propagateNegativeInform(dampedSource, targetOpinion, weight) : propagatePositiveInform(dampedSource, targetOpinion, weight);
474
+ return annotateRationale(result, context.spec, context.hop);
475
+ },
476
+ description: "Evidence-bearing influence. Informs can chain through the graph with light per-hop damping."
477
+ };
478
+
479
+ // src/edges/propagationTypes.ts
480
+ function isPropagationTraversalDirection(direction) {
481
+ return direction === "outgoing" || direction === "incoming";
482
+ }
483
+ function canTraverseHop(spec, nextHop) {
484
+ return spec.maxHops === "unbounded" || nextHop <= spec.maxHops;
485
+ }
486
+ function canContinueTransitively(spec, currentHop) {
487
+ if (spec.transitivity === "none") {
488
+ return false;
489
+ }
490
+ return spec.maxHops === "unbounded" || currentHop < spec.maxHops;
491
+ }
492
+
493
+ // src/edges/refutes.ts
494
+ var refutesPropagationSpec = {
495
+ edgeType: "refutes",
496
+ direction: "outgoing",
497
+ transitivity: "none",
498
+ damping: 0.9,
499
+ maxHops: 1,
500
+ operator: (sourceOpinion, targetOpinion, edge, context) => {
501
+ const dampedSource = applyPerHopDamping(
502
+ sourceOpinion,
503
+ context.spec.damping
504
+ );
505
+ const negativeWeight = -Math.abs(edge.weight ?? 1);
506
+ const result = propagateNegativeInform(
507
+ dampedSource,
508
+ targetOpinion,
509
+ negativeWeight
510
+ );
511
+ return annotateRationale(result, context.spec, context.hop);
512
+ },
513
+ description: "Explicit negative evidence semantics. Refutes is treated as strong one-hop counter-evidence."
514
+ };
515
+
516
+ // src/edges/supports.ts
517
+ var supportsPropagationSpec = {
518
+ edgeType: "supports",
519
+ direction: "outgoing",
520
+ transitivity: "full",
521
+ damping: 0.85,
522
+ maxHops: "unbounded",
523
+ operator: (sourceOpinion, targetOpinion, edge, context) => {
524
+ const dampedSource = applyPerHopDamping(
525
+ sourceOpinion,
526
+ context.spec.damping
527
+ );
528
+ const weight = edge.weight ?? 1;
529
+ const result = weight < 0 ? propagateNegativeSupportWithMetadata(
530
+ dampedSource,
531
+ targetOpinion,
532
+ weight,
533
+ edge
534
+ ) : propagatePositiveSupport(dampedSource, targetOpinion, weight);
535
+ return annotateRationale(result, context.spec, context.hop);
536
+ },
537
+ description: "Belief-to-belief influence. Supports chains transitively with moderate per-hop damping."
538
+ };
539
+
540
+ // src/edges/tests.ts
541
+ var testsPropagationSpec = {
542
+ edgeType: "tests",
543
+ direction: "outgoing",
544
+ transitivity: "none",
545
+ damping: 1,
546
+ maxHops: 1,
547
+ operator: () => null,
548
+ description: "Interrogation linkage only. Tests edges do not directly move confidence."
549
+ };
550
+
551
+ // src/edges/index.ts
552
+ var EDGE_PROPAGATION_SPECS = [
553
+ supportsPropagationSpec,
554
+ informsPropagationSpec,
555
+ dependsOnPropagationSpec,
556
+ derivedFromPropagationSpec,
557
+ containsPropagationSpec,
558
+ testsPropagationSpec,
559
+ contradictsPropagationSpec,
560
+ refutesPropagationSpec,
561
+ elaboratesPropagationSpec
562
+ ];
563
+ new Map(EDGE_PROPAGATION_SPECS.map((spec) => [spec.edgeType, spec]));
564
+ function getEdgePropagationSpecs() {
565
+ return EDGE_PROPAGATION_SPECS;
566
+ }
567
+ function getTraversalDirections(direction) {
568
+ if (isPropagationTraversalDirection(direction)) {
569
+ return [direction];
570
+ }
571
+ return ["outgoing", "incoming"];
572
+ }
573
+
574
+ // src/workspaceIsolation.ts
575
+ function normalizeScopeValue(value) {
576
+ if (typeof value !== "string") {
577
+ return;
578
+ }
579
+ const normalized = value.trim();
580
+ return normalized.length > 0 ? normalized : void 0;
581
+ }
582
+ function nodeMatchesWorkspaceReasoningScope(node, scope) {
583
+ if (!node) {
584
+ return false;
585
+ }
586
+ const scopeTenantId = normalizeScopeValue(scope.tenantId);
587
+ const scopeWorkspaceId = normalizeScopeValue(scope.workspaceId);
588
+ const nodeTenantId = normalizeScopeValue(node.tenantId);
589
+ const nodeWorkspaceId = normalizeScopeValue(node.workspaceId);
590
+ const epistemicLayer = typeof node.epistemicLayer === "string" ? node.epistemicLayer : void 0;
591
+ if (scopeTenantId && nodeTenantId && scopeTenantId !== nodeTenantId) {
592
+ return false;
593
+ }
594
+ if (epistemicLayer === "ontological" && nodeWorkspaceId === void 0) {
595
+ return true;
596
+ }
597
+ if (!scopeWorkspaceId && node.publicationStatus === "published") {
598
+ return true;
599
+ }
600
+ if (!scopeWorkspaceId) {
601
+ return nodeWorkspaceId === void 0;
602
+ }
603
+ return scopeWorkspaceId === nodeWorkspaceId;
604
+ }
605
+ function edgeMatchesWorkspaceReasoningScope(edge, scope) {
606
+ if (!edge) {
607
+ return false;
608
+ }
609
+ const scopeTenantId = normalizeScopeValue(scope.tenantId);
610
+ const scopeWorkspaceId = normalizeScopeValue(scope.workspaceId);
611
+ const edgeTenantId = normalizeScopeValue(edge.tenantId);
612
+ const edgeWorkspaceId = normalizeScopeValue(edge.workspaceId);
613
+ if (scopeTenantId && edgeTenantId && scopeTenantId !== edgeTenantId) {
614
+ return false;
615
+ }
616
+ if (!scopeWorkspaceId) {
617
+ return edgeWorkspaceId === void 0;
618
+ }
619
+ return scopeWorkspaceId === edgeWorkspaceId;
620
+ }
621
+
622
+ // src/confidencePropagationDispatch.ts
623
+ function resolveTraversalTargetNodeId(edge, direction) {
624
+ const targetNodeId = direction === "outgoing" ? edge.toNodeId : edge.fromNodeId;
625
+ return targetNodeId ?? void 0;
626
+ }
627
+ function readNodeOpinion(node) {
628
+ const metadata = node.metadata ?? {};
629
+ return readOpinionFromRecord(
630
+ {
631
+ ...metadata,
632
+ opinion_b: node.opinion_b,
633
+ opinion_d: node.opinion_d,
634
+ opinion_u: node.opinion_u,
635
+ opinion_a: node.opinion_a
636
+ },
637
+ { b: 0, d: 0, u: 1, a: 0.5 }
638
+ );
639
+ }
640
+ async function collectConfidencePropagationDispatches(args) {
641
+ const dispatchesByTargetId = /* @__PURE__ */ new Map();
642
+ const opinionCache = /* @__PURE__ */ new Map();
643
+ const nodeCache = /* @__PURE__ */ new Map();
644
+ const traversalSpecs = args.traversalSpecs ?? getEdgePropagationSpecs();
645
+ const queue = [
646
+ {
647
+ nodeId: args.sourceNodeId,
648
+ opinion: args.sourceOpinion,
649
+ hop: 0,
650
+ visitedNodeIds: /* @__PURE__ */ new Set([String(args.sourceNodeId)])
651
+ }
652
+ ];
653
+ const loadNode = async (nodeId) => {
654
+ const cacheKey = String(nodeId);
655
+ if (!nodeCache.has(cacheKey)) {
656
+ nodeCache.set(cacheKey, await args.getNode(nodeId));
657
+ }
658
+ return nodeCache.get(cacheKey) ?? null;
659
+ };
660
+ while (queue.length > 0) {
661
+ const state = queue.shift();
662
+ if (!state) {
663
+ continue;
664
+ }
665
+ for (const spec of traversalSpecs) {
666
+ const nextHop = state.hop + 1;
667
+ if (!canTraverseHop(spec, nextHop)) {
668
+ continue;
669
+ }
670
+ for (const direction of getTraversalDirections(spec.direction)) {
671
+ const edges = await args.queryEdges({
672
+ nodeId: state.nodeId,
673
+ spec,
674
+ direction,
675
+ hop: nextHop
676
+ });
677
+ for (const edge of edges) {
678
+ if (args.sourceScope && !edgeMatchesWorkspaceReasoningScope(edge, args.sourceScope)) {
679
+ continue;
680
+ }
681
+ const targetNodeId = resolveTraversalTargetNodeId(edge, direction);
682
+ if (!targetNodeId) {
683
+ continue;
684
+ }
685
+ if (state.visitedNodeIds.has(String(targetNodeId))) {
686
+ continue;
687
+ }
688
+ const targetNode = await loadNode(targetNodeId);
689
+ if (!targetNode || targetNode.nodeType !== "belief") {
690
+ continue;
691
+ }
692
+ if (args.sourceScope && !nodeMatchesWorkspaceReasoningScope(targetNode, args.sourceScope)) {
693
+ continue;
694
+ }
695
+ const cacheKey = String(targetNodeId);
696
+ const targetOpinion = opinionCache.get(cacheKey) ?? readNodeOpinion(targetNode);
697
+ const result = spec.operator(state.opinion, targetOpinion, edge, {
698
+ hop: nextHop,
699
+ sourceNodeId: state.nodeId,
700
+ targetNodeId,
701
+ traversedDirection: direction,
702
+ spec
703
+ });
704
+ if (!result || !hasProjectedOpinionChanged(targetOpinion, result.opinion)) {
705
+ continue;
706
+ }
707
+ opinionCache.set(cacheKey, result.opinion);
708
+ const existingDispatch = dispatchesByTargetId.get(cacheKey);
709
+ dispatchesByTargetId.set(cacheKey, {
710
+ targetNodeId,
711
+ edgeType: spec.edgeType,
712
+ traversedDirection: direction,
713
+ weight: edge.weight ?? 1,
714
+ opinion: result.opinion,
715
+ operator: result.operator,
716
+ rationale: existingDispatch ? `${existingDispatch.rationale}; ${result.rationale}` : result.rationale,
717
+ hop: nextHop
718
+ });
719
+ if (canContinueTransitively(spec, nextHop)) {
720
+ queue.push({
721
+ nodeId: targetNodeId,
722
+ opinion: result.opinion,
723
+ hop: nextHop,
724
+ visitedNodeIds: /* @__PURE__ */ new Set([
725
+ ...state.visitedNodeIds,
726
+ String(targetNodeId)
727
+ ])
728
+ });
729
+ }
730
+ }
731
+ }
732
+ }
733
+ }
734
+ return Array.from(dispatchesByTargetId.values()).sort((left, right) => {
735
+ if (left.hop !== right.hop) {
736
+ return left.hop - right.hop;
737
+ }
738
+ return String(left.targetNodeId).localeCompare(String(right.targetNodeId));
739
+ });
740
+ }
741
+
742
+ export { collectConfidencePropagationDispatches };
743
+ //# sourceMappingURL=confidencePropagationDispatch.js.map
744
+ //# sourceMappingURL=confidencePropagationDispatch.js.map