couchloop-eq-mcp 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/README.md +30 -5
  2. package/dist/clients/shrinkChatClient.d.ts +10 -0
  3. package/dist/clients/shrinkChatClient.d.ts.map +1 -1
  4. package/dist/clients/shrinkChatClient.js +4 -0
  5. package/dist/clients/shrinkChatClient.js.map +1 -1
  6. package/dist/db/client.d.ts.map +1 -1
  7. package/dist/db/client.js +5 -3
  8. package/dist/db/client.js.map +1 -1
  9. package/dist/db/schema.d.ts +363 -0
  10. package/dist/db/schema.d.ts.map +1 -1
  11. package/dist/db/schema.js +47 -0
  12. package/dist/db/schema.js.map +1 -1
  13. package/dist/governance/config.d.ts +66 -0
  14. package/dist/governance/config.d.ts.map +1 -0
  15. package/dist/governance/config.js +238 -0
  16. package/dist/governance/config.js.map +1 -0
  17. package/dist/governance/detectors/hallucination.d.ts +61 -0
  18. package/dist/governance/detectors/hallucination.d.ts.map +1 -0
  19. package/dist/governance/detectors/hallucination.js +338 -0
  20. package/dist/governance/detectors/hallucination.js.map +1 -0
  21. package/dist/governance/detectors/inconsistency.d.ts +99 -0
  22. package/dist/governance/detectors/inconsistency.d.ts.map +1 -0
  23. package/dist/governance/detectors/inconsistency.js +548 -0
  24. package/dist/governance/detectors/inconsistency.js.map +1 -0
  25. package/dist/governance/detectors/toneDrift.d.ts +63 -0
  26. package/dist/governance/detectors/toneDrift.d.ts.map +1 -0
  27. package/dist/governance/detectors/toneDrift.js +421 -0
  28. package/dist/governance/detectors/toneDrift.js.map +1 -0
  29. package/dist/governance/detectors/unsafeReasoning.d.ts +54 -0
  30. package/dist/governance/detectors/unsafeReasoning.d.ts.map +1 -0
  31. package/dist/governance/detectors/unsafeReasoning.js +473 -0
  32. package/dist/governance/detectors/unsafeReasoning.js.map +1 -0
  33. package/dist/governance/evaluationEngine.d.ts +112 -0
  34. package/dist/governance/evaluationEngine.d.ts.map +1 -0
  35. package/dist/governance/evaluationEngine.js +265 -0
  36. package/dist/governance/evaluationEngine.js.map +1 -0
  37. package/dist/governance/intervention.d.ts +81 -0
  38. package/dist/governance/intervention.d.ts.map +1 -0
  39. package/dist/governance/intervention.js +405 -0
  40. package/dist/governance/intervention.js.map +1 -0
  41. package/dist/server/chatgpt-mcp.d.ts +10 -0
  42. package/dist/server/chatgpt-mcp.d.ts.map +1 -0
  43. package/dist/server/chatgpt-mcp.js +233 -0
  44. package/dist/server/chatgpt-mcp.js.map +1 -0
  45. package/dist/server/index.d.ts.map +1 -1
  46. package/dist/server/index.js +94 -3
  47. package/dist/server/index.js.map +1 -1
  48. package/dist/server/middleware/localNetworkAccess.d.ts +16 -0
  49. package/dist/server/middleware/localNetworkAccess.d.ts.map +1 -0
  50. package/dist/server/middleware/localNetworkAccess.js +97 -0
  51. package/dist/server/middleware/localNetworkAccess.js.map +1 -0
  52. package/dist/server/sse.d.ts +16 -0
  53. package/dist/server/sse.d.ts.map +1 -0
  54. package/dist/server/sse.js +215 -0
  55. package/dist/server/sse.js.map +1 -0
  56. package/dist/tools/checkpoint.d.ts.map +1 -1
  57. package/dist/tools/index.d.ts +1 -0
  58. package/dist/tools/index.d.ts.map +1 -1
  59. package/dist/tools/index.js +4 -2
  60. package/dist/tools/index.js.map +1 -1
  61. package/dist/tools/insight.d.ts +1 -0
  62. package/dist/tools/insight.d.ts.map +1 -1
  63. package/dist/tools/sendMessage-complex-backup.d.ts +6 -0
  64. package/dist/tools/sendMessage-complex-backup.d.ts.map +1 -0
  65. package/dist/tools/sendMessage-complex-backup.js +545 -0
  66. package/dist/tools/sendMessage-complex-backup.js.map +1 -0
  67. package/dist/tools/sendMessage-revised.d.ts +11 -0
  68. package/dist/tools/sendMessage-revised.d.ts.map +1 -0
  69. package/dist/tools/sendMessage-revised.js +429 -0
  70. package/dist/tools/sendMessage-revised.js.map +1 -0
  71. package/dist/tools/sendMessage-truly-simple.d.ts +8 -0
  72. package/dist/tools/sendMessage-truly-simple.d.ts.map +1 -0
  73. package/dist/tools/sendMessage-truly-simple.js +299 -0
  74. package/dist/tools/sendMessage-truly-simple.js.map +1 -0
  75. package/dist/tools/sendMessage.d.ts +4 -2
  76. package/dist/tools/sendMessage.d.ts.map +1 -1
  77. package/dist/tools/sendMessage.js +240 -186
  78. package/dist/tools/sendMessage.js.map +1 -1
  79. package/dist/tools/session.d.ts.map +1 -1
  80. package/dist/tools/session.js +35 -29
  81. package/dist/tools/session.js.map +1 -1
  82. package/dist/types/auth.d.ts +9 -1
  83. package/dist/types/auth.d.ts.map +1 -1
  84. package/dist/types/auth.js +37 -10
  85. package/dist/types/auth.js.map +1 -1
  86. package/dist/types/insight.d.ts +10 -0
  87. package/dist/types/insight.d.ts.map +1 -1
  88. package/dist/types/session.d.ts +10 -0
  89. package/dist/types/session.d.ts.map +1 -1
  90. package/package.json +10 -5
@@ -0,0 +1,338 @@
1
+ /**
2
+ * CouchLoop Behavioral Governance Layer - Hallucination Detector
3
+ *
4
+ * Detects fabricated facts, false certainty, and unsupported claims in LLM responses
5
+ */
6
+ export class HallucinationDetector {
7
+ config;
8
+ certaintyPatterns;
9
+ statisticalPatterns;
10
+ authorityPatterns;
11
+ absolutePatterns;
12
+ constructor(config) {
13
+ this.config = config;
14
+ // Compile regex patterns for performance
15
+ this.certaintyPatterns = [
16
+ /I have (direct|personal|firsthand) experience/i,
17
+ /I (personally|directly) (know|experienced|saw|witnessed)/i,
18
+ /In my (experience|life|years)/i,
19
+ /I can (personally|directly) attest/i,
20
+ /I've (seen|witnessed|observed) this (many times|often|frequently)/i
21
+ ];
22
+ this.statisticalPatterns = [
23
+ /(\d+)% of (people|individuals|studies|research|cases|patients)/i,
24
+ /(\d+) out of (\d+) (people|studies|cases)/i,
25
+ /(studies|research) (consistently |always |invariably )?show/i,
26
+ /according to (recent|latest|new) (research|studies|data)/i,
27
+ /statistically proven/i,
28
+ /data (clearly |definitively |conclusively )?shows/i,
29
+ /peer-reviewed (research|studies) (confirm|prove|demonstrate)/i
30
+ ];
31
+ this.authorityPatterns = [
32
+ /experts (agree|confirm|say|believe) that/i,
33
+ /(all|most) (therapists|doctors|psychologists|psychiatrists) (recommend|agree|say)/i,
34
+ /medical consensus is/i,
35
+ /scientifically proven/i,
36
+ /universally accepted/i,
37
+ /leading authorities (confirm|state|agree)/i,
38
+ /Nobel Prize winning/i,
39
+ /Harvard study/i
40
+ ];
41
+ this.absolutePatterns = [
42
+ /it['']s a (proven|established|known|undeniable) fact that/i,
43
+ /(everyone|nobody) knows that/i,
44
+ /absolutely (certain|guaranteed|proven)/i,
45
+ /(always|never) (works|fails|happens)/i,
46
+ /100% (effective|safe|certain|guaranteed)/i,
47
+ /impossible to/i,
48
+ /definitely will/i,
49
+ /guaranteed to/i,
50
+ /undoubtedly/i,
51
+ /unquestionably/i
52
+ ];
53
+ // Add custom patterns from config
54
+ if (config.patterns) {
55
+ const customPatterns = config.patterns.map(p => new RegExp(p, 'i'));
56
+ this.certaintyPatterns.push(...customPatterns);
57
+ }
58
+ }
59
+ /**
60
+ * Main detection method
61
+ */
62
+ async detect(response, context) {
63
+ const detectedPatterns = [];
64
+ let confidenceScore = 0;
65
+ let detectionCount = 0;
66
+ // Check for false personal experience claims
67
+ const personalClaims = this.detectPersonalClaims(response);
68
+ if (personalClaims.length > 0) {
69
+ detectedPatterns.push(...personalClaims);
70
+ confidenceScore += 0.3;
71
+ detectionCount++;
72
+ }
73
+ // Check for unsupported statistical claims
74
+ const statsClaims = this.detectStatisticalClaims(response);
75
+ if (statsClaims.length > 0) {
76
+ detectedPatterns.push(...statsClaims);
77
+ confidenceScore += 0.25;
78
+ detectionCount++;
79
+ }
80
+ // Check for false authority claims
81
+ const authorityClaims = this.detectAuthorityClaims(response);
82
+ if (authorityClaims.length > 0) {
83
+ detectedPatterns.push(...authorityClaims);
84
+ confidenceScore += 0.2;
85
+ detectionCount++;
86
+ }
87
+ // Check for absolute statements
88
+ const absoluteClaims = this.detectAbsoluteClaims(response);
89
+ if (absoluteClaims.length > 0) {
90
+ detectedPatterns.push(...absoluteClaims);
91
+ confidenceScore += 0.25;
92
+ detectionCount++;
93
+ }
94
+ // Check for fabricated technical terms
95
+ const technicalTerms = this.detectFabricatedTerms(response);
96
+ if (technicalTerms.length > 0) {
97
+ detectedPatterns.push(...technicalTerms);
98
+ confidenceScore += 0.2;
99
+ detectionCount++;
100
+ }
101
+ // Contextual verification if context is provided
102
+ if (context?.conversationHistory) {
103
+ const contextualIssues = await this.verifyAgainstContext(response, context);
104
+ if (contextualIssues.length > 0) {
105
+ detectedPatterns.push(...contextualIssues);
106
+ confidenceScore += 0.3;
107
+ detectionCount++;
108
+ }
109
+ }
110
+ // Normalize confidence score (cap at 1.0)
111
+ confidenceScore = Math.min(confidenceScore, 1.0);
112
+ // Apply threshold
113
+ const detected = confidenceScore >= this.config.threshold;
114
+ return {
115
+ detected,
116
+ confidence: confidenceScore,
117
+ patterns: detectedPatterns,
118
+ details: {
119
+ detectionCount,
120
+ personalClaims: personalClaims.length,
121
+ statisticalClaims: statsClaims.length,
122
+ authorityClaims: authorityClaims.length,
123
+ absoluteClaims: absoluteClaims.length,
124
+ threshold: this.config.threshold
125
+ }
126
+ };
127
+ }
128
+ /**
129
+ * Detect false personal experience claims
130
+ */
131
+ detectPersonalClaims(response) {
132
+ const detected = [];
133
+ for (const pattern of this.certaintyPatterns) {
134
+ const matches = response.match(pattern);
135
+ if (matches) {
136
+ detected.push(`Personal claim: "${matches[0]}"`);
137
+ }
138
+ }
139
+ return detected;
140
+ }
141
+ /**
142
+ * Detect unsupported statistical claims
143
+ */
144
+ detectStatisticalClaims(response) {
145
+ const detected = [];
146
+ for (const pattern of this.statisticalPatterns) {
147
+ const matches = response.match(pattern);
148
+ if (matches) {
149
+ // Special check for specific percentages that seem fabricated
150
+ if (matches[0].includes('%')) {
151
+ const percentMatch = matches[0].match(/(\d+)%/);
152
+ if (percentMatch && percentMatch[1]) {
153
+ const percent = parseInt(percentMatch[1]);
154
+ // Suspicious percentages (very specific or round numbers without context)
155
+ if ((percent > 70 && percent < 100 && percent % 5 !== 0) ||
156
+ (percent === 73 || percent === 87 || percent === 92)) {
157
+ detected.push(`Suspicious statistic: "${matches[0]}"`);
158
+ continue;
159
+ }
160
+ }
161
+ }
162
+ detected.push(`Statistical claim: "${matches[0]}"`);
163
+ }
164
+ }
165
+ return detected;
166
+ }
167
+ /**
168
+ * Detect false authority claims
169
+ */
170
+ detectAuthorityClaims(response) {
171
+ const detected = [];
172
+ for (const pattern of this.authorityPatterns) {
173
+ const matches = response.match(pattern);
174
+ if (matches) {
175
+ detected.push(`Authority claim: "${matches[0]}"`);
176
+ }
177
+ }
178
+ return detected;
179
+ }
180
+ /**
181
+ * Detect absolute statements
182
+ */
183
+ detectAbsoluteClaims(response) {
184
+ const detected = [];
185
+ for (const pattern of this.absolutePatterns) {
186
+ const matches = response.match(pattern);
187
+ if (matches) {
188
+ detected.push(`Absolute claim: "${matches[0]}"`);
189
+ }
190
+ }
191
+ return detected;
192
+ }
193
+ /**
194
+ * Detect potentially fabricated technical or medical terms
195
+ */
196
+ detectFabricatedTerms(response) {
197
+ const detected = [];
198
+ // Look for made-up sounding technical terms
199
+ const suspiciousTermPatterns = [
200
+ /neuro-?[a-z]+ive/i, // Neuro-something-ive
201
+ /psycho-?[a-z]+osis/i, // Psycho-something-osis
202
+ /[a-z]+pathic [a-z]+syndrome/i, // X-pathic Y syndrome
203
+ /cognitive [a-z]+ disorder/i, // Cognitive X disorder (when X is unusual)
204
+ /therapeutic [a-z]+ protocol/i, // Therapeutic X protocol
205
+ ];
206
+ // Known legitimate terms to exclude
207
+ const legitimateTerms = new Set([
208
+ 'cognitive behavioral therapy',
209
+ 'psychosis',
210
+ 'neurosis',
211
+ 'neuropathic',
212
+ 'psychopathic',
213
+ 'therapeutic intervention protocol'
214
+ ]);
215
+ for (const pattern of suspiciousTermPatterns) {
216
+ const matches = response.match(pattern);
217
+ if (matches) {
218
+ const term = matches[0].toLowerCase();
219
+ if (!legitimateTerms.has(term)) {
220
+ detected.push(`Suspicious term: "${matches[0]}"`);
221
+ }
222
+ }
223
+ }
224
+ return detected;
225
+ }
226
+ /**
227
+ * Verify claims against conversation context
228
+ */
229
+ async verifyAgainstContext(response, context) {
230
+ const issues = [];
231
+ if (!context.conversationHistory || context.conversationHistory.length === 0) {
232
+ return issues;
233
+ }
234
+ // Check if the AI is claiming knowledge about the user that wasn't provided
235
+ const userInfoClaims = [
236
+ /you (said|mentioned|told me) (earlier |before |previously )?that/i,
237
+ /as you (mentioned|said|explained)/i,
238
+ /based on what you('ve)? (shared|told me|said)/i,
239
+ /you have (a |an )?[a-z]+ (condition|disorder|issue)/i,
240
+ /your [a-z]+ (problem|issue|condition)/i
241
+ ];
242
+ for (const pattern of userInfoClaims) {
243
+ const matches = response.match(pattern);
244
+ if (matches) {
245
+ // Try to verify if this was actually mentioned
246
+ const claimedInfo = matches[0];
247
+ let foundInHistory = false;
248
+ for (const msg of context.conversationHistory) {
249
+ if (msg.role === 'user' && this.fuzzyMatch(claimedInfo, msg.content)) {
250
+ foundInHistory = true;
251
+ break;
252
+ }
253
+ }
254
+ if (!foundInHistory) {
255
+ issues.push(`Unverified claim about user: "${claimedInfo}"`);
256
+ }
257
+ }
258
+ }
259
+ // Check for contradictions with earlier messages
260
+ const currentClaims = this.extractClaims(response);
261
+ const historicalClaims = context.conversationHistory
262
+ .filter(msg => msg.role === 'assistant')
263
+ .flatMap(msg => this.extractClaims(msg.content));
264
+ for (const currentClaim of currentClaims) {
265
+ for (const historicalClaim of historicalClaims) {
266
+ if (this.areContradictory(currentClaim, historicalClaim)) {
267
+ issues.push(`Contradiction detected: Current: "${currentClaim}" vs Earlier: "${historicalClaim}"`);
268
+ }
269
+ }
270
+ }
271
+ return issues;
272
+ }
273
+ /**
274
+ * Extract factual claims from text
275
+ */
276
+ extractClaims(text) {
277
+ const claims = [];
278
+ // Patterns that indicate factual claims
279
+ const claimPatterns = [
280
+ /[A-Z][^.!?]+ is [^.!?]+[.!?]/g,
281
+ /[A-Z][^.!?]+ are [^.!?]+[.!?]/g,
282
+ /[A-Z][^.!?]+ causes [^.!?]+[.!?]/g,
283
+ /[A-Z][^.!?]+ leads to [^.!?]+[.!?]/g,
284
+ /[A-Z][^.!?]+ results in [^.!?]+[.!?]/g
285
+ ];
286
+ for (const pattern of claimPatterns) {
287
+ const matches = text.match(pattern);
288
+ if (matches) {
289
+ claims.push(...matches);
290
+ }
291
+ }
292
+ return claims;
293
+ }
294
+ /**
295
+ * Check if two claims are contradictory
296
+ */
297
+ areContradictory(claim1, claim2) {
298
+ // Simple contradiction detection - can be enhanced
299
+ const normalized1 = claim1.toLowerCase();
300
+ const normalized2 = claim2.toLowerCase();
301
+ // Check for opposite modals
302
+ if ((normalized1.includes(' is ') && normalized2.includes(' is not ')) ||
303
+ (normalized1.includes(' is not ') && normalized2.includes(' is ')) ||
304
+ (normalized1.includes(' will ') && normalized2.includes(' will not ')) ||
305
+ (normalized1.includes(' can ') && normalized2.includes(' cannot '))) {
306
+ // Check if they're about the same subject
307
+ const subject1 = normalized1.split(' is ')[0] || normalized1.split(' will ')[0] || normalized1;
308
+ const subject2 = normalized2.split(' is ')[0] || normalized2.split(' will ')[0] || normalized2;
309
+ return this.fuzzyMatch(subject1, subject2);
310
+ }
311
+ return false;
312
+ }
313
+ /**
314
+ * Fuzzy string matching for similarity
315
+ */
316
+ fuzzyMatch(str1, str2) {
317
+ const normalized1 = str1.toLowerCase().trim();
318
+ const normalized2 = str2.toLowerCase().trim();
319
+ // Check for substring match
320
+ if (normalized1.includes(normalized2) || normalized2.includes(normalized1)) {
321
+ return true;
322
+ }
323
+ // Check for high word overlap
324
+ const words1 = new Set(normalized1.split(/\s+/));
325
+ const words2 = new Set(normalized2.split(/\s+/));
326
+ const intersection = new Set([...words1].filter(x => words2.has(x)));
327
+ const overlapRatio = intersection.size / Math.min(words1.size, words2.size);
328
+ return overlapRatio > 0.6;
329
+ }
330
+ /**
331
+ * Update configuration
332
+ */
333
+ updateConfig(config) {
334
+ this.config = config;
335
+ }
336
+ }
337
+ export default HallucinationDetector;
338
+ //# sourceMappingURL=hallucination.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hallucination.js","sourceRoot":"","sources":["../../../src/governance/detectors/hallucination.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,MAAM,OAAO,qBAAqB;IACxB,MAAM,CAAkB;IACxB,iBAAiB,CAAW;IAC5B,mBAAmB,CAAW;IAC9B,iBAAiB,CAAW;IAC5B,gBAAgB,CAAW;IAEnC,YAAY,MAAuB;QACjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,yCAAyC;QACzC,IAAI,CAAC,iBAAiB,GAAG;YACvB,gDAAgD;YAChD,2DAA2D;YAC3D,gCAAgC;YAChC,qCAAqC;YACrC,oEAAoE;SACrE,CAAC;QAEF,IAAI,CAAC,mBAAmB,GAAG;YACzB,iEAAiE;YACjE,4CAA4C;YAC5C,8DAA8D;YAC9D,2DAA2D;YAC3D,uBAAuB;YACvB,oDAAoD;YACpD,+DAA+D;SAChE,CAAC;QAEF,IAAI,CAAC,iBAAiB,GAAG;YACvB,2CAA2C;YAC3C,oFAAoF;YACpF,uBAAuB;YACvB,wBAAwB;YACxB,uBAAuB;YACvB,4CAA4C;YAC5C,sBAAsB;YACtB,gBAAgB;SACjB,CAAC;QAEF,IAAI,CAAC,gBAAgB,GAAG;YACtB,4DAA4D;YAC5D,+BAA+B;YAC/B,yCAAyC;YACzC,uCAAuC;YACvC,2CAA2C;YAC3C,gBAAgB;YAChB,kBAAkB;YAClB,gBAAgB;YAChB,cAAc;YACd,iBAAiB;SAClB,CAAC;QAEF,kCAAkC;QAClC,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;YACpB,MAAM,cAAc,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CA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7C,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACK,UAAU,CAAC,IAAY,EAAE,IAAY;QAC3C,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,CAAC;QAC9C,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,CAAC;QAE9C,4BAA4B;QAC5B,IAAI,WAAW,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,WAAW,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;YAC3E,OAAO,IAAI,CAAC;QACd,CAAC;QAED,8BAA8B;QAC9B,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QACjD,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QAEjD,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACrE,MAAM,YAAY,GAAG,YAAY,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;QAE5E,OAAO,YAAY,GAAG,GAAG,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,YAAY,CAAC,MAAuB;QAClC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED,eAAe,qBAAqB,CAAC"}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * CouchLoop Behavioral Governance Layer - Inconsistency Checker
3
+ *
4
+ * Detects contradictions with earlier turns, sudden reversals in advice,
5
+ * and logical incoherence across conversation history
6
+ */
7
+ import type { DetectionResult, SessionContext } from '../evaluationEngine.js';
8
+ import type { CriterionConfig } from '../config.js';
9
+ export declare class InconsistencyChecker {
10
+ private config;
11
+ private lookbackLimit;
12
+ constructor(config: CriterionConfig);
13
+ /**
14
+ * Main check method - detects inconsistencies with conversation history
15
+ */
16
+ check(response: string, context?: SessionContext): Promise<DetectionResult>;
17
+ /**
18
+ * Load conversation history from database
19
+ */
20
+ private loadConversationHistory;
21
+ /**
22
+ * Extract claims from text
23
+ */
24
+ private extractClaims;
25
+ /**
26
+ * Extract claims from historical messages
27
+ */
28
+ private extractHistoricalClaims;
29
+ /**
30
+ * Find contradictions between current and historical claims
31
+ */
32
+ private findContradictions;
33
+ /**
34
+ * Check if two claims are contradictory
35
+ */
36
+ private areContradictory;
37
+ /**
38
+ * Check if advice has been reversed
39
+ */
40
+ private isReversal;
41
+ /**
42
+ * Extract action from advice statement
43
+ */
44
+ private extractAction;
45
+ /**
46
+ * Check for logical coherence issues
47
+ */
48
+ private checkLogicalCoherence;
49
+ /**
50
+ * Check if two sentences within the same response are contradictory
51
+ */
52
+ private areSentencesContradictory;
53
+ /**
54
+ * Extract subject from sentence
55
+ */
56
+ private extractSubject;
57
+ /**
58
+ * Detect circular reasoning patterns
59
+ */
60
+ private detectCircularReasoning;
61
+ /**
62
+ * Check for sudden reversals in approach or tone
63
+ */
64
+ private checkReversals;
65
+ /**
66
+ * Identify the therapeutic approach being used
67
+ */
68
+ private identifyApproach;
69
+ /**
70
+ * Check if two approaches are opposite
71
+ */
72
+ private areApproachesOpposite;
73
+ /**
74
+ * Extract stances on various topics
75
+ */
76
+ private extractStances;
77
+ /**
78
+ * Assess severity of contradiction
79
+ */
80
+ private assessSeverity;
81
+ /**
82
+ * Calculate overall confidence score
83
+ */
84
+ private calculateConfidence;
85
+ /**
86
+ * Format contradiction for output
87
+ */
88
+ private formatContradiction;
89
+ /**
90
+ * Fuzzy string matching
91
+ */
92
+ private fuzzyMatch;
93
+ /**
94
+ * Update configuration
95
+ */
96
+ updateConfig(config: CriterionConfig): void;
97
+ }
98
+ export default InconsistencyChecker;
99
+ //# sourceMappingURL=inconsistency.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inconsistency.d.ts","sourceRoot":"","sources":["../../../src/governance/detectors/inconsistency.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAqBpD,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,aAAa,CAAS;gBAElB,MAAM,EAAE,eAAe;IAKnC;;OAEG;IACG,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC;IAuDjF;;OAEG;YACW,uBAAuB;IAgCrC;;OAEG;IACH,OAAO,CAAC,aAAa;IA8DrB;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAgB/B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAgC1B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IA6DxB;;OAEG;IACH,OAAO,CAAC,UAAU;IAqClB;;OAEG;IACH,OAAO,CAAC,aAAa;IAWrB;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAyC7B;;OAEG;IACH,OAAO,CAAC,yBAAyB;IAoBjC;;OAEG;IACH,OAAO,CAAC,cAAc;IAgBtB;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAU/B;;OAEG;IACH,OAAO,CAAC,cAAc;IAmCtB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAmBxB;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAW7B;;OAEG;IACH,OAAO,CAAC,cAAc;IA2BtB;;OAEG;IACH,OAAO,CAAC,cAAc;IAmBtB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAgC3B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAO3B;;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