@vorionsys/a3i 0.1.0

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 (166) hide show
  1. package/LICENSE +190 -0
  2. package/dist/api/handlers.d.ts +231 -0
  3. package/dist/api/handlers.d.ts.map +1 -0
  4. package/dist/api/handlers.js +279 -0
  5. package/dist/api/handlers.js.map +1 -0
  6. package/dist/api/index.d.ts +24 -0
  7. package/dist/api/index.d.ts.map +1 -0
  8. package/dist/api/index.js +27 -0
  9. package/dist/api/index.js.map +1 -0
  10. package/dist/api/middleware.d.ts +106 -0
  11. package/dist/api/middleware.d.ts.map +1 -0
  12. package/dist/api/middleware.js +186 -0
  13. package/dist/api/middleware.js.map +1 -0
  14. package/dist/api/routes.d.ts +41 -0
  15. package/dist/api/routes.d.ts.map +1 -0
  16. package/dist/api/routes.js +91 -0
  17. package/dist/api/routes.js.map +1 -0
  18. package/dist/authorization/constraints.d.ts +75 -0
  19. package/dist/authorization/constraints.d.ts.map +1 -0
  20. package/dist/authorization/constraints.js +302 -0
  21. package/dist/authorization/constraints.js.map +1 -0
  22. package/dist/authorization/decision.d.ts +98 -0
  23. package/dist/authorization/decision.d.ts.map +1 -0
  24. package/dist/authorization/decision.js +202 -0
  25. package/dist/authorization/decision.js.map +1 -0
  26. package/dist/authorization/engine.d.ts +141 -0
  27. package/dist/authorization/engine.d.ts.map +1 -0
  28. package/dist/authorization/engine.js +339 -0
  29. package/dist/authorization/engine.js.map +1 -0
  30. package/dist/authorization/index.d.ts +10 -0
  31. package/dist/authorization/index.d.ts.map +1 -0
  32. package/dist/authorization/index.js +13 -0
  33. package/dist/authorization/index.js.map +1 -0
  34. package/dist/banding/band-calculator.d.ts +137 -0
  35. package/dist/banding/band-calculator.d.ts.map +1 -0
  36. package/dist/banding/band-calculator.js +252 -0
  37. package/dist/banding/band-calculator.js.map +1 -0
  38. package/dist/banding/bands.d.ts +56 -0
  39. package/dist/banding/bands.d.ts.map +1 -0
  40. package/dist/banding/bands.js +200 -0
  41. package/dist/banding/bands.js.map +1 -0
  42. package/dist/banding/hysteresis.d.ts +64 -0
  43. package/dist/banding/hysteresis.d.ts.map +1 -0
  44. package/dist/banding/hysteresis.js +143 -0
  45. package/dist/banding/hysteresis.js.map +1 -0
  46. package/dist/banding/index.d.ts +10 -0
  47. package/dist/banding/index.d.ts.map +1 -0
  48. package/dist/banding/index.js +10 -0
  49. package/dist/banding/index.js.map +1 -0
  50. package/dist/canary/canary-service.d.ts +123 -0
  51. package/dist/canary/canary-service.d.ts.map +1 -0
  52. package/dist/canary/canary-service.js +353 -0
  53. package/dist/canary/canary-service.js.map +1 -0
  54. package/dist/canary/index.d.ts +12 -0
  55. package/dist/canary/index.d.ts.map +1 -0
  56. package/dist/canary/index.js +14 -0
  57. package/dist/canary/index.js.map +1 -0
  58. package/dist/canary/probe-library.d.ts +43 -0
  59. package/dist/canary/probe-library.d.ts.map +1 -0
  60. package/dist/canary/probe-library.js +655 -0
  61. package/dist/canary/probe-library.js.map +1 -0
  62. package/dist/execution/engine.d.ts +120 -0
  63. package/dist/execution/engine.d.ts.map +1 -0
  64. package/dist/execution/engine.js +220 -0
  65. package/dist/execution/engine.js.map +1 -0
  66. package/dist/execution/index.d.ts +7 -0
  67. package/dist/execution/index.d.ts.map +1 -0
  68. package/dist/execution/index.js +7 -0
  69. package/dist/execution/index.js.map +1 -0
  70. package/dist/gate/index.d.ts +12 -0
  71. package/dist/gate/index.d.ts.map +1 -0
  72. package/dist/gate/index.js +14 -0
  73. package/dist/gate/index.js.map +1 -0
  74. package/dist/gate/pre-action-gate.d.ts +87 -0
  75. package/dist/gate/pre-action-gate.d.ts.map +1 -0
  76. package/dist/gate/pre-action-gate.js +286 -0
  77. package/dist/gate/pre-action-gate.js.map +1 -0
  78. package/dist/gate/risk-classifier.d.ts +43 -0
  79. package/dist/gate/risk-classifier.d.ts.map +1 -0
  80. package/dist/gate/risk-classifier.js +157 -0
  81. package/dist/gate/risk-classifier.js.map +1 -0
  82. package/dist/hooks/executor.d.ts +56 -0
  83. package/dist/hooks/executor.d.ts.map +1 -0
  84. package/dist/hooks/executor.js +217 -0
  85. package/dist/hooks/executor.js.map +1 -0
  86. package/dist/hooks/index.d.ts +45 -0
  87. package/dist/hooks/index.d.ts.map +1 -0
  88. package/dist/hooks/index.js +49 -0
  89. package/dist/hooks/index.js.map +1 -0
  90. package/dist/hooks/manager.d.ts +156 -0
  91. package/dist/hooks/manager.d.ts.map +1 -0
  92. package/dist/hooks/manager.js +267 -0
  93. package/dist/hooks/manager.js.map +1 -0
  94. package/dist/hooks/registry.d.ts +130 -0
  95. package/dist/hooks/registry.d.ts.map +1 -0
  96. package/dist/hooks/registry.js +238 -0
  97. package/dist/hooks/registry.js.map +1 -0
  98. package/dist/hooks/types.d.ts +226 -0
  99. package/dist/hooks/types.d.ts.map +1 -0
  100. package/dist/hooks/types.js +41 -0
  101. package/dist/hooks/types.js.map +1 -0
  102. package/dist/index.d.ts +20 -0
  103. package/dist/index.d.ts.map +1 -0
  104. package/dist/index.js +31 -0
  105. package/dist/index.js.map +1 -0
  106. package/dist/observation/attestation.d.ts +102 -0
  107. package/dist/observation/attestation.d.ts.map +1 -0
  108. package/dist/observation/attestation.js +127 -0
  109. package/dist/observation/attestation.js.map +1 -0
  110. package/dist/observation/ceilings.d.ts +60 -0
  111. package/dist/observation/ceilings.d.ts.map +1 -0
  112. package/dist/observation/ceilings.js +110 -0
  113. package/dist/observation/ceilings.js.map +1 -0
  114. package/dist/observation/index.d.ts +11 -0
  115. package/dist/observation/index.d.ts.map +1 -0
  116. package/dist/observation/index.js +14 -0
  117. package/dist/observation/index.js.map +1 -0
  118. package/dist/observation/tiers.d.ts +96 -0
  119. package/dist/observation/tiers.d.ts.map +1 -0
  120. package/dist/observation/tiers.js +225 -0
  121. package/dist/observation/tiers.js.map +1 -0
  122. package/dist/orchestrator/index.d.ts +8 -0
  123. package/dist/orchestrator/index.d.ts.map +1 -0
  124. package/dist/orchestrator/index.js +8 -0
  125. package/dist/orchestrator/index.js.map +1 -0
  126. package/dist/orchestrator/orchestrator.d.ts +225 -0
  127. package/dist/orchestrator/orchestrator.d.ts.map +1 -0
  128. package/dist/orchestrator/orchestrator.js +302 -0
  129. package/dist/orchestrator/orchestrator.js.map +1 -0
  130. package/dist/orchestrator/proof-plane-adapter.d.ts +80 -0
  131. package/dist/orchestrator/proof-plane-adapter.d.ts.map +1 -0
  132. package/dist/orchestrator/proof-plane-adapter.js +78 -0
  133. package/dist/orchestrator/proof-plane-adapter.js.map +1 -0
  134. package/dist/trust/calculator.d.ts +60 -0
  135. package/dist/trust/calculator.d.ts.map +1 -0
  136. package/dist/trust/calculator.js +163 -0
  137. package/dist/trust/calculator.js.map +1 -0
  138. package/dist/trust/dimensions.d.ts +133 -0
  139. package/dist/trust/dimensions.d.ts.map +1 -0
  140. package/dist/trust/dimensions.js +257 -0
  141. package/dist/trust/dimensions.js.map +1 -0
  142. package/dist/trust/index.d.ts +14 -0
  143. package/dist/trust/index.d.ts.map +1 -0
  144. package/dist/trust/index.js +25 -0
  145. package/dist/trust/index.js.map +1 -0
  146. package/dist/trust/profile-service.d.ts +179 -0
  147. package/dist/trust/profile-service.d.ts.map +1 -0
  148. package/dist/trust/profile-service.js +378 -0
  149. package/dist/trust/profile-service.js.map +1 -0
  150. package/dist/trust/profile-store.d.ts +122 -0
  151. package/dist/trust/profile-store.d.ts.map +1 -0
  152. package/dist/trust/profile-store.js +132 -0
  153. package/dist/trust/profile-store.js.map +1 -0
  154. package/dist/trust/trust-calculator.d.ts +111 -0
  155. package/dist/trust/trust-calculator.d.ts.map +1 -0
  156. package/dist/trust/trust-calculator.js +271 -0
  157. package/dist/trust/trust-calculator.js.map +1 -0
  158. package/dist/trust/trust-dynamics.d.ts +152 -0
  159. package/dist/trust/trust-dynamics.d.ts.map +1 -0
  160. package/dist/trust/trust-dynamics.js +302 -0
  161. package/dist/trust/trust-dynamics.js.map +1 -0
  162. package/dist/trust/weights.d.ts +57 -0
  163. package/dist/trust/weights.d.ts.map +1 -0
  164. package/dist/trust/weights.js +75 -0
  165. package/dist/trust/weights.js.map +1 -0
  166. package/package.json +81 -0
@@ -0,0 +1,111 @@
1
+ /**
2
+ * TrustCalculator Class - Core trust scoring engine
3
+ *
4
+ * Provides a stateful calculator for computing and managing
5
+ * trust scores with proper evidence handling and decay.
6
+ *
7
+ * Uses the 16-factor trust model where each factor is scored 0.0-1.0
8
+ * and the composite score is the average of all factor scores x 1000.
9
+ */
10
+ import type { TrustProfile, TrustFactorScores, TrustEvidence, ObservationTier, BandingConfig, EvidenceType } from '@vorionsys/contracts';
11
+ import { HysteresisCalculator } from '../banding/hysteresis.js';
12
+ /**
13
+ * Configuration for the TrustCalculator
14
+ */
15
+ export interface TrustCalculatorConfig {
16
+ /** Banding configuration */
17
+ bandingConfig?: Partial<BandingConfig>;
18
+ /** Enable time decay */
19
+ enableDecay?: boolean;
20
+ /** Decay rate per day (0.0 to 1.0) */
21
+ decayRate?: number;
22
+ /** Maximum age of evidence in days before it's ignored */
23
+ maxEvidenceAgeDays?: number;
24
+ /**
25
+ * Enable evidence type weighting
26
+ * HITL approvals weighted 5x, examinations 3x, etc.
27
+ * @default true
28
+ */
29
+ enableEvidenceTypeWeighting?: boolean;
30
+ /**
31
+ * Custom evidence type multipliers
32
+ * Override default EVIDENCE_TYPE_MULTIPLIERS
33
+ */
34
+ evidenceTypeMultipliers?: Partial<Record<EvidenceType, number>>;
35
+ }
36
+ /**
37
+ * Options for a single calculation
38
+ */
39
+ export interface CalculateOptions {
40
+ /** Override decay setting for this calculation */
41
+ applyDecay?: boolean;
42
+ /** Current time (for testing) */
43
+ now?: Date;
44
+ }
45
+ /**
46
+ * Result of evidence aggregation
47
+ */
48
+ export interface AggregationResult {
49
+ factorScores: TrustFactorScores;
50
+ validEvidenceCount: number;
51
+ expiredEvidenceCount: number;
52
+ oldestEvidence: Date | null;
53
+ newestEvidence: Date | null;
54
+ }
55
+ /**
56
+ * TrustCalculator - Main trust scoring engine
57
+ */
58
+ export declare class TrustCalculator {
59
+ private readonly config;
60
+ private readonly hysteresisCalculator;
61
+ private readonly evidenceMultipliers;
62
+ constructor(config?: TrustCalculatorConfig);
63
+ /**
64
+ * Calculate a new trust profile from evidence
65
+ */
66
+ calculate(agentId: string, observationTier: ObservationTier, evidence: TrustEvidence[], options?: CalculateOptions): TrustProfile;
67
+ /**
68
+ * Recalculate an existing profile with new evidence
69
+ */
70
+ recalculate(existingProfile: TrustProfile, newEvidence: TrustEvidence[], options?: CalculateOptions): TrustProfile;
71
+ /**
72
+ * Apply time decay to a profile without new evidence
73
+ */
74
+ applyDecay(profile: TrustProfile, options?: {
75
+ now?: Date;
76
+ }): TrustProfile;
77
+ /**
78
+ * Compute the composite score from factor scores.
79
+ * Composite = average of all factor scores x 1000.
80
+ */
81
+ computeCompositeScore(factorScores: TrustFactorScores): number;
82
+ /**
83
+ * Apply observation tier ceiling to a score
84
+ */
85
+ applyCeiling(score: number, tier: ObservationTier): number;
86
+ /**
87
+ * Aggregate evidence into factor scores
88
+ */
89
+ aggregateEvidence(evidence: TrustEvidence[], now?: Date, applyDecay?: boolean): AggregationResult;
90
+ /**
91
+ * Compute factor scores from impact arrays
92
+ */
93
+ private computeFactorScoresFromImpacts;
94
+ /**
95
+ * Validate factor score values
96
+ */
97
+ private validateFactorScores;
98
+ /**
99
+ * Get the calculator configuration
100
+ */
101
+ getConfig(): Readonly<Required<TrustCalculatorConfig>>;
102
+ /**
103
+ * Get the hysteresis calculator
104
+ */
105
+ getHysteresisCalculator(): HysteresisCalculator;
106
+ }
107
+ /**
108
+ * Create a TrustCalculator with default configuration
109
+ */
110
+ export declare function createTrustCalculator(config?: TrustCalculatorConfig): TrustCalculator;
111
+ //# sourceMappingURL=trust-calculator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trust-calculator.d.ts","sourceRoot":"","sources":["../../src/trust/trust-calculator.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH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Ae,EAChC,QAAQ,EAAE,aAAa,EAAE,EACzB,OAAO,GAAE,gBAAqB,GAC7B,YAAY;IA+Bf;;OAEG;IACH,WAAW,CACT,eAAe,EAAE,YAAY,EAC7B,WAAW,EAAE,aAAa,EAAE,EAC5B,OAAO,GAAE,gBAAqB,GAC7B,YAAY;IAoCf;;OAEG;IACH,UAAU,CACR,OAAO,EAAE,YAAY,EACrB,OAAO,GAAE;QAAE,GAAG,CAAC,EAAE,IAAI,CAAA;KAAO,GAC3B,YAAY;IA4Bf;;;OAGG;IACH,qBAAqB,CACnB,YAAY,EAAE,iBAAiB,GAC9B,MAAM;IAaT;;OAEG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,GAAG,MAAM;IAK1D;;OAEG;IACH,iBAAiB,CACf,QAAQ,EAAE,aAAa,EAAE,EACzB,GAAG,GAAE,IAAiB,EACtB,UAAU,GAAE,OAAc,GACzB,iBAAiB;IAoEpB;;OAEG;IACH,OAAO,CAAC,8BAA8B;IAmBtC;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAW5B;;OAEG;IACH,SAAS,IAAI,QAAQ,CAAC,QAAQ,CAAC,qBAAqB,CAAC,CAAC;IAItD;;OAEG;IACH,uBAAuB,IAAI,oBAAoB;CAGhD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,CAAC,EAAE,qBAAqB,GAC7B,eAAe,CAEjB"}
@@ -0,0 +1,271 @@
1
+ /**
2
+ * TrustCalculator Class - Core trust scoring engine
3
+ *
4
+ * Provides a stateful calculator for computing and managing
5
+ * trust scores with proper evidence handling and decay.
6
+ *
7
+ * Uses the 16-factor trust model where each factor is scored 0.0-1.0
8
+ * and the composite score is the average of all factor scores x 1000.
9
+ */
10
+ import { v4 as uuidv4 } from 'uuid';
11
+ import { DEFAULT_BANDING_CONFIG, OBSERVATION_CEILINGS, EVIDENCE_TYPE_MULTIPLIERS, } from '@vorionsys/contracts';
12
+ import { getBand } from '../banding/bands.js';
13
+ import { HysteresisCalculator } from '../banding/hysteresis.js';
14
+ /** Default initial factor score for factors with no evidence (baseline) */
15
+ const INITIAL_FACTOR_SCORE = 0.5;
16
+ /** The 16 core trust factor codes */
17
+ const TRUST_FACTOR_CODES = [
18
+ 'CT-COMP', 'CT-REL', 'CT-OBS', 'CT-TRANS', 'CT-ACCT', 'CT-SAFE',
19
+ 'CT-SEC', 'CT-PRIV', 'CT-ID', 'OP-HUMAN', 'OP-ALIGN', 'OP-CONTEXT',
20
+ 'OP-STEW', 'SF-HUM', 'SF-ADAPT', 'SF-LEARN',
21
+ ];
22
+ /**
23
+ * Create initial factor scores with baseline values for all 16 factors
24
+ */
25
+ function createInitialFactorScores() {
26
+ const scores = {};
27
+ for (const code of TRUST_FACTOR_CODES) {
28
+ scores[code] = INITIAL_FACTOR_SCORE;
29
+ }
30
+ return scores;
31
+ }
32
+ /**
33
+ * Clamp a factor score to valid range [0.0, 1.0]
34
+ */
35
+ function clampFactorScore(score) {
36
+ return Math.max(0.0, Math.min(1.0, score));
37
+ }
38
+ /**
39
+ * TrustCalculator - Main trust scoring engine
40
+ */
41
+ export class TrustCalculator {
42
+ config;
43
+ hysteresisCalculator;
44
+ evidenceMultipliers;
45
+ constructor(config = {}) {
46
+ this.config = {
47
+ bandingConfig: { ...DEFAULT_BANDING_CONFIG, ...config.bandingConfig },
48
+ enableDecay: config.enableDecay ?? true,
49
+ decayRate: config.decayRate ?? DEFAULT_BANDING_CONFIG.decayRate,
50
+ maxEvidenceAgeDays: config.maxEvidenceAgeDays ?? 365,
51
+ enableEvidenceTypeWeighting: config.enableEvidenceTypeWeighting ?? true,
52
+ evidenceTypeMultipliers: config.evidenceTypeMultipliers ?? {},
53
+ };
54
+ // Merge custom multipliers with defaults
55
+ this.evidenceMultipliers = {
56
+ ...EVIDENCE_TYPE_MULTIPLIERS,
57
+ ...this.config.evidenceTypeMultipliers,
58
+ };
59
+ this.hysteresisCalculator = new HysteresisCalculator(this.config.bandingConfig);
60
+ }
61
+ /**
62
+ * Calculate a new trust profile from evidence
63
+ */
64
+ calculate(agentId, observationTier, evidence, options = {}) {
65
+ const now = options.now ?? new Date();
66
+ const applyDecay = options.applyDecay ?? this.config.enableDecay;
67
+ // Aggregate evidence into factor scores
68
+ const aggregation = this.aggregateEvidence(evidence, now, applyDecay);
69
+ const factorScores = aggregation.factorScores;
70
+ // Calculate composite score (average of factor scores x 1000)
71
+ const compositeScore = this.computeCompositeScore(factorScores);
72
+ // Apply observation ceiling
73
+ const adjustedScore = this.applyCeiling(compositeScore, observationTier);
74
+ // Determine trust band
75
+ const band = getBand(adjustedScore, this.config.bandingConfig.thresholds);
76
+ return {
77
+ profileId: uuidv4(),
78
+ agentId,
79
+ factorScores,
80
+ compositeScore,
81
+ observationTier,
82
+ adjustedScore,
83
+ band,
84
+ calculatedAt: now,
85
+ evidence,
86
+ version: 1,
87
+ };
88
+ }
89
+ /**
90
+ * Recalculate an existing profile with new evidence
91
+ */
92
+ recalculate(existingProfile, newEvidence, options = {}) {
93
+ const now = options.now ?? new Date();
94
+ const applyDecay = options.applyDecay ?? this.config.enableDecay;
95
+ // Combine all evidence
96
+ const allEvidence = [...existingProfile.evidence, ...newEvidence];
97
+ // Aggregate with decay
98
+ const aggregation = this.aggregateEvidence(allEvidence, now, applyDecay);
99
+ // Calculate new composite score
100
+ const compositeScore = this.computeCompositeScore(aggregation.factorScores);
101
+ // Apply observation ceiling
102
+ const adjustedScore = this.applyCeiling(compositeScore, existingProfile.observationTier);
103
+ // Calculate new band with hysteresis
104
+ const band = this.hysteresisCalculator.calculateBandWithHysteresis(existingProfile.band, adjustedScore);
105
+ return {
106
+ profileId: uuidv4(),
107
+ agentId: existingProfile.agentId,
108
+ factorScores: aggregation.factorScores,
109
+ compositeScore,
110
+ observationTier: existingProfile.observationTier,
111
+ adjustedScore,
112
+ band,
113
+ calculatedAt: now,
114
+ evidence: allEvidence,
115
+ version: existingProfile.version + 1,
116
+ };
117
+ }
118
+ /**
119
+ * Apply time decay to a profile without new evidence
120
+ */
121
+ applyDecay(profile, options = {}) {
122
+ const now = options.now ?? new Date();
123
+ // Re-aggregate with decay
124
+ const aggregation = this.aggregateEvidence(profile.evidence, now, true);
125
+ // Recalculate scores
126
+ const compositeScore = this.computeCompositeScore(aggregation.factorScores);
127
+ const adjustedScore = this.applyCeiling(compositeScore, profile.observationTier);
128
+ // Apply hysteresis for band changes
129
+ const band = this.hysteresisCalculator.calculateBandWithHysteresis(profile.band, adjustedScore);
130
+ return {
131
+ ...profile,
132
+ profileId: uuidv4(),
133
+ factorScores: aggregation.factorScores,
134
+ compositeScore,
135
+ adjustedScore,
136
+ band,
137
+ calculatedAt: now,
138
+ version: profile.version + 1,
139
+ };
140
+ }
141
+ /**
142
+ * Compute the composite score from factor scores.
143
+ * Composite = average of all factor scores x 1000.
144
+ */
145
+ computeCompositeScore(factorScores) {
146
+ // Validate factor scores
147
+ this.validateFactorScores(factorScores);
148
+ const values = Object.values(factorScores);
149
+ if (values.length === 0)
150
+ return 0;
151
+ const average = values.reduce((a, b) => a + b, 0) / values.length;
152
+ // Round to 2 decimal places
153
+ return Math.round(average * 1000 * 100) / 100;
154
+ }
155
+ /**
156
+ * Apply observation tier ceiling to a score
157
+ */
158
+ applyCeiling(score, tier) {
159
+ const ceiling = OBSERVATION_CEILINGS[tier];
160
+ return Math.min(score, ceiling);
161
+ }
162
+ /**
163
+ * Aggregate evidence into factor scores
164
+ */
165
+ aggregateEvidence(evidence, now = new Date(), applyDecay = true) {
166
+ // Collect impacts per factor code
167
+ const factorImpacts = {};
168
+ let validCount = 0;
169
+ let expiredCount = 0;
170
+ let oldestEvidence = null;
171
+ let newestEvidence = null;
172
+ const maxAge = this.config.maxEvidenceAgeDays * 24 * 60 * 60 * 1000;
173
+ for (const ev of evidence) {
174
+ // Skip expired evidence
175
+ if (ev.expiresAt && ev.expiresAt < now) {
176
+ expiredCount++;
177
+ continue;
178
+ }
179
+ // Skip evidence older than max age
180
+ const age = now.getTime() - ev.collectedAt.getTime();
181
+ if (age > maxAge) {
182
+ expiredCount++;
183
+ continue;
184
+ }
185
+ // Calculate impact with optional decay
186
+ let impact = ev.impact;
187
+ if (applyDecay) {
188
+ const daysSinceCollection = age / (1000 * 60 * 60 * 24);
189
+ const decayFactor = Math.pow(1 - this.config.decayRate, daysSinceCollection);
190
+ impact = ev.impact * decayFactor;
191
+ }
192
+ // Apply evidence type multiplier if enabled
193
+ // HITL approvals are weighted 5x to solve cold-start problem
194
+ if (this.config.enableEvidenceTypeWeighting) {
195
+ const evidenceType = ev.evidenceType ?? 'automated';
196
+ const multiplier = this.evidenceMultipliers[evidenceType] ?? 1.0;
197
+ impact = impact * multiplier;
198
+ }
199
+ if (!factorImpacts[ev.factorCode]) {
200
+ factorImpacts[ev.factorCode] = [];
201
+ }
202
+ factorImpacts[ev.factorCode].push(impact);
203
+ validCount++;
204
+ // Track date range
205
+ if (!oldestEvidence || ev.collectedAt < oldestEvidence) {
206
+ oldestEvidence = ev.collectedAt;
207
+ }
208
+ if (!newestEvidence || ev.collectedAt > newestEvidence) {
209
+ newestEvidence = ev.collectedAt;
210
+ }
211
+ }
212
+ // Calculate final factor scores from impacts
213
+ const factorScores = this.computeFactorScoresFromImpacts(factorImpacts);
214
+ return {
215
+ factorScores,
216
+ validEvidenceCount: validCount,
217
+ expiredEvidenceCount: expiredCount,
218
+ oldestEvidence,
219
+ newestEvidence,
220
+ };
221
+ }
222
+ /**
223
+ * Compute factor scores from impact arrays
224
+ */
225
+ computeFactorScoresFromImpacts(impacts) {
226
+ const factorScores = createInitialFactorScores();
227
+ for (const [factorCode, factorImpacts] of Object.entries(impacts)) {
228
+ if (factorImpacts.length > 0) {
229
+ // Use average of impacts
230
+ const avgImpact = factorImpacts.reduce((a, b) => a + b, 0) / factorImpacts.length;
231
+ // Impacts are on -1000 to +1000 scale; factor scores are 0.0-1.0
232
+ // Convert impact to factor score delta: impact / 1000
233
+ const baseline = factorScores[factorCode] ?? INITIAL_FACTOR_SCORE;
234
+ factorScores[factorCode] = clampFactorScore(baseline + avgImpact / 1000);
235
+ }
236
+ }
237
+ return factorScores;
238
+ }
239
+ /**
240
+ * Validate factor score values
241
+ */
242
+ validateFactorScores(factorScores) {
243
+ for (const [key, value] of Object.entries(factorScores)) {
244
+ if (typeof value !== 'number' || isNaN(value)) {
245
+ throw new Error(`Invalid factor score value for ${key}: ${value}`);
246
+ }
247
+ if (value < 0.0 || value > 1.0) {
248
+ throw new Error(`Factor score ${key} out of range [0.0, 1.0]: ${value}`);
249
+ }
250
+ }
251
+ }
252
+ /**
253
+ * Get the calculator configuration
254
+ */
255
+ getConfig() {
256
+ return { ...this.config };
257
+ }
258
+ /**
259
+ * Get the hysteresis calculator
260
+ */
261
+ getHysteresisCalculator() {
262
+ return this.hysteresisCalculator;
263
+ }
264
+ }
265
+ /**
266
+ * Create a TrustCalculator with default configuration
267
+ */
268
+ export function createTrustCalculator(config) {
269
+ return new TrustCalculator(config);
270
+ }
271
+ //# sourceMappingURL=trust-calculator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trust-calculator.js","sourceRoot":"","sources":["../../src/trust/trust-calculator.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AASpC,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,yBAAyB,GAC1B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEhE,2EAA2E;AAC3E,MAAM,oBAAoB,GAAG,GAAG,CAAC;AAEjC,qCAAqC;AACrC,MAAM,kBAAkB,GAAG;IACzB,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS;IAC/D,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EA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GAAG,SAAS,GAAG,IAAI,CAAC,CAAC;YAC3E,CAAC;QACH,CAAC;QAED,OAAO,YAAY,CAAC;IACtB,CAAC;IAED;;OAEG;IACK,oBAAoB,CAAC,YAA+B;QAC1D,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;YACxD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC9C,MAAM,IAAI,KAAK,CAAC,kCAAkC,GAAG,KAAK,KAAK,EAAE,CAAC,CAAC;YACrE,CAAC;YACD,IAAI,KAAK,GAAG,GAAG,IAAI,KAAK,GAAG,GAAG,EAAE,CAAC;gBAC/B,MAAM,IAAI,KAAK,CAAC,gBAAgB,GAAG,6BAA6B,KAAK,EAAE,CAAC,CAAC;YAC3E,CAAC;QACH,CAAC;IACH,CAAC;IAED;;OAEG;IACH,SAAS;QACP,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,uBAAuB;QACrB,OAAO,IAAI,CAAC,oBAAoB,CAAC;IACnC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CACnC,MAA8B;IAE9B,OAAO,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC;AACrC,CAAC"}
@@ -0,0 +1,152 @@
1
+ /**
2
+ * Trust Dynamics - Asymmetric trust updates per ATSF v2.0
3
+ *
4
+ * Implements:
5
+ * - Logarithmic gain (slow trust building)
6
+ * - Exponential loss (fast trust loss, 10:1 ratio)
7
+ * - Cooldown periods (7 days after any trust drop)
8
+ * - Oscillation detection (circuit breaker trigger)
9
+ *
10
+ * Key principle: "Trust is hard to gain, easy to lose"
11
+ */
12
+ import { type TrustDynamicsConfig, type TrustDynamicsState, type CooldownState } from '@vorionsys/contracts';
13
+ /**
14
+ * Result of a trust update operation
15
+ */
16
+ export interface TrustUpdateResult {
17
+ /** New trust score after update */
18
+ newScore: number;
19
+ /** Delta applied (can be 0 if blocked by cooldown) */
20
+ delta: number;
21
+ /** Whether the update was blocked by cooldown */
22
+ blockedByCooldown: boolean;
23
+ /** Whether this triggered a circuit breaker */
24
+ circuitBreakerTripped: boolean;
25
+ /** Reason for circuit breaker if tripped */
26
+ circuitBreakerReason?: string;
27
+ /** Whether oscillation was detected */
28
+ oscillationDetected: boolean;
29
+ /** Updated dynamics state */
30
+ state: TrustDynamicsState;
31
+ }
32
+ /**
33
+ * Options for trust update
34
+ */
35
+ export interface TrustUpdateOptions {
36
+ /** Current trust score (0-100) */
37
+ currentScore: number;
38
+ /** Whether the observation was successful */
39
+ success: boolean;
40
+ /** Trust ceiling based on observation tier (0-100) */
41
+ ceiling: number;
42
+ /** Magnitude of the outcome (for weighted updates) */
43
+ magnitude?: number;
44
+ /** Whether this is an outcome reversal (provisional success → final failure) */
45
+ isReversal?: boolean;
46
+ /** Current time (for testing) */
47
+ now?: Date;
48
+ }
49
+ /**
50
+ * TrustDynamicsEngine - Implements asymmetric trust scoring
51
+ */
52
+ export declare class TrustDynamicsEngine {
53
+ private readonly config;
54
+ private readonly states;
55
+ constructor(config?: Partial<TrustDynamicsConfig>);
56
+ /**
57
+ * Get or create dynamics state for an agent
58
+ */
59
+ getState(agentId: string): TrustDynamicsState;
60
+ /**
61
+ * Create initial dynamics state for a new agent
62
+ */
63
+ private createInitialState;
64
+ /**
65
+ * Update trust score with asymmetric dynamics
66
+ *
67
+ * Gain: delta = gainRate * log(1 + (ceiling - current))
68
+ * Loss: delta = -lossRate * current
69
+ *
70
+ * Gain is blocked during cooldown period.
71
+ * Circuit breaker trips on oscillation or low trust.
72
+ */
73
+ updateTrust(agentId: string, options: TrustUpdateOptions): TrustUpdateResult;
74
+ /**
75
+ * Calculate trust gain using logarithmic formula
76
+ * delta = gainRate * log(1 + (ceiling - current))
77
+ *
78
+ * This creates diminishing returns as trust approaches ceiling
79
+ */
80
+ private calculateGain;
81
+ /**
82
+ * Calculate trust loss using exponential formula
83
+ * delta = -lossRate * current
84
+ *
85
+ * This creates proportional loss - higher trust means bigger absolute drop
86
+ */
87
+ private calculateLoss;
88
+ /**
89
+ * Update cooldown state based on current time
90
+ */
91
+ private updateCooldownState;
92
+ /**
93
+ * Start a cooldown period
94
+ */
95
+ private startCooldown;
96
+ /**
97
+ * Track direction changes for oscillation detection
98
+ * Returns true if oscillation threshold is exceeded
99
+ */
100
+ private trackDirectionChange;
101
+ /**
102
+ * Trip the circuit breaker
103
+ */
104
+ private tripCircuitBreaker;
105
+ /**
106
+ * Reset circuit breaker (requires admin action)
107
+ */
108
+ resetCircuitBreaker(agentId: string, adminOverride?: boolean): boolean;
109
+ /**
110
+ * Check if agent is in cooldown
111
+ */
112
+ isInCooldown(agentId: string, now?: Date): boolean;
113
+ /**
114
+ * Check if circuit breaker is tripped
115
+ */
116
+ isCircuitBreakerTripped(agentId: string): boolean;
117
+ /**
118
+ * Get cooldown info for an agent
119
+ */
120
+ getCooldownInfo(agentId: string, now?: Date): CooldownState;
121
+ /**
122
+ * Get time remaining in cooldown (in hours)
123
+ */
124
+ getCooldownRemainingHours(agentId: string, now?: Date): number;
125
+ /**
126
+ * Apply time-based decay to a trust score
127
+ *
128
+ * Decay formula: score * (1 - decayRate)^days
129
+ */
130
+ applyDecay(currentScore: number, daysSinceUpdate: number, decayRate?: number): number;
131
+ /**
132
+ * Calculate asymmetry ratio (loss rate / gain rate)
133
+ */
134
+ getAsymmetryRatio(): number;
135
+ /**
136
+ * Get the current configuration
137
+ */
138
+ getConfig(): Readonly<TrustDynamicsConfig>;
139
+ /**
140
+ * Clamp a score within bounds
141
+ */
142
+ private clampScore;
143
+ /**
144
+ * Clear all state (for testing)
145
+ */
146
+ clearAllState(): void;
147
+ }
148
+ /**
149
+ * Create a trust dynamics engine with default configuration
150
+ */
151
+ export declare function createTrustDynamicsEngine(config?: Partial<TrustDynamicsConfig>): TrustDynamicsEngine;
152
+ //# sourceMappingURL=trust-dynamics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trust-dynamics.d.ts","sourceRoot":"","sources":["../../src/trust/trust-dynamics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAEnB,MAAM,sBAAsB,CAAC;AAE9B;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,mCAAmC;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,sDAAsD;IACtD,KAAK,EAAE,MAAM,CAAC;IACd,iDAAiD;IACjD,iBAAiB,EAAE,OAAO,CAAC;IAC3B,+CAA+C;IAC/C,qBAAqB,EAAE,OAAO,CAAC;IAC/B,4CAA4C;IAC5C,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,uCAAuC;IACvC,mBAAmB,EAAE,OAAO,CAAC;IAC7B,6BAA6B;IAC7B,KAAK,EAAE,kBAAkB,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,kCAAkC;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,6CAA6C;IAC7C,OAAO,EAAE,OAAO,CAAC;IACjB,sDAAsD;IACtD,OAAO,EAAE,MAAM,CAAC;IAChB,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gFAAgF;IAChF,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,iCAAiC;IACjC,GAAG,CAAC,EAAE,IAAI,CAAC;CACZ;AAED;;GAEG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsB;IAC7C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA8C;gBAEzD,MAAM,GAAE,OAAO,CAAC,mBAAmB,CAAM;IAIrD;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,kBAAkB;IAS7C;;OAEG;IACH,OAAO,CAAC,k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