truthguard-ai 0.1.5 → 0.3.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 (54) hide show
  1. package/README.md +13 -13
  2. package/dist-npm/Claims/index.d.ts +73 -0
  3. package/dist-npm/Claims/index.d.ts.map +1 -0
  4. package/dist-npm/Claims/index.js +1669 -0
  5. package/dist-npm/Claims/index.js.map +1 -0
  6. package/dist-npm/Config/index.d.ts +41 -0
  7. package/dist-npm/Config/index.d.ts.map +1 -0
  8. package/dist-npm/Config/index.js +129 -0
  9. package/dist-npm/Config/index.js.map +1 -0
  10. package/dist-npm/Grounding/index.d.ts +40 -0
  11. package/dist-npm/Grounding/index.d.ts.map +1 -0
  12. package/dist-npm/Grounding/index.js +1433 -0
  13. package/dist-npm/Grounding/index.js.map +1 -0
  14. package/dist-npm/L2/index.d.ts +93 -0
  15. package/dist-npm/L2/index.d.ts.map +1 -0
  16. package/dist-npm/L2/index.js +1773 -0
  17. package/dist-npm/L2/index.js.map +1 -0
  18. package/dist-npm/Matchers/index.d.ts +101 -0
  19. package/dist-npm/Matchers/index.d.ts.map +1 -0
  20. package/dist-npm/Matchers/index.js +690 -0
  21. package/dist-npm/Matchers/index.js.map +1 -0
  22. package/dist-npm/Mode/index.d.ts +87 -0
  23. package/dist-npm/Mode/index.d.ts.map +1 -0
  24. package/dist-npm/Mode/index.js +117 -0
  25. package/dist-npm/Mode/index.js.map +1 -0
  26. package/dist-npm/Policy/index.d.ts +89 -0
  27. package/dist-npm/Policy/index.d.ts.map +1 -0
  28. package/dist-npm/Policy/index.js +143 -0
  29. package/dist-npm/Policy/index.js.map +1 -0
  30. package/dist-npm/Registry/index.d.ts +93 -0
  31. package/dist-npm/Registry/index.d.ts.map +1 -0
  32. package/dist-npm/Registry/index.js +818 -0
  33. package/dist-npm/Registry/index.js.map +1 -0
  34. package/dist-npm/Rules/index.d.ts +587 -0
  35. package/dist-npm/Rules/index.d.ts.map +1 -0
  36. package/dist-npm/Rules/index.js +6236 -0
  37. package/dist-npm/Rules/index.js.map +1 -0
  38. package/dist-npm/Rules/intents.d.ts +22 -0
  39. package/dist-npm/Rules/intents.d.ts.map +1 -0
  40. package/dist-npm/Rules/intents.js +242 -0
  41. package/dist-npm/Rules/intents.js.map +1 -0
  42. package/dist-npm/TraceReadiness/index.d.ts +42 -0
  43. package/dist-npm/TraceReadiness/index.d.ts.map +1 -0
  44. package/dist-npm/TraceReadiness/index.js +169 -0
  45. package/dist-npm/TraceReadiness/index.js.map +1 -0
  46. package/dist-npm/i18n/index.d.ts +44 -0
  47. package/dist-npm/i18n/index.d.ts.map +1 -0
  48. package/dist-npm/i18n/index.js +124 -0
  49. package/dist-npm/i18n/index.js.map +1 -0
  50. package/package.json +8 -22
  51. package/dist/cli/index.d.ts +0 -15
  52. package/dist/cli/index.d.ts.map +0 -1
  53. package/dist/cli/index.js +0 -807
  54. package/dist/cli/index.js.map +0 -1
package/README.md CHANGED
@@ -18,7 +18,7 @@ Most "hallucinations" in tool-calling agents are **grounding failures** — the
18
18
  TruthGuard extracts factual claims from the agent's response, cross-references them against tool outputs, and reports grounding failures with standardized codes — like OBD diagnostic codes for AI.
19
19
 
20
20
  ```
21
- npm install truthguard
21
+ npm install truthguard-ai
22
22
  ```
23
23
 
24
24
  **Zero LLM calls.** 30+ deterministic failure detectors. Runs in <50ms.
@@ -30,7 +30,7 @@ npm install truthguard
30
30
  ### 1. Evaluate a trace
31
31
 
32
32
  ```typescript
33
- import { TraceBuilder, GroundingEngine, generateReport } from 'truthguard';
33
+ import { TraceBuilder, GroundingEngine, generateReport } from 'truthguard-ai';
34
34
 
35
35
  const trace = new TraceBuilder({ traceId: 'run-001' })
36
36
  .addUserInput('How many employees are on leave today?')
@@ -55,7 +55,7 @@ console.log(text);
55
55
  ### 2. Add a CI quality gate
56
56
 
57
57
  ```typescript
58
- import { loadDataset, runDataset, evaluateGate, loadGateConfig } from 'truthguard';
58
+ import { loadDataset, runDataset, evaluateGate, loadGateConfig } from 'truthguard-ai';
59
59
 
60
60
  const entries = loadDataset('./test-cases.jsonl');
61
61
  const result = runDataset(entries);
@@ -73,7 +73,7 @@ if (!verdict.pass) {
73
73
  Works with **any language** — PHP, Python, Go, Java, Ruby, C#:
74
74
 
75
75
  ```bash
76
- npx truthguard observe --port 3001
76
+ npx truthguard-ai observe --port 3001
77
77
  ```
78
78
 
79
79
  Change your AI base URL:
@@ -112,7 +112,7 @@ Every detected failure includes actionable diagnostics — root cause identifica
112
112
  Configure per-failure actions — block, warn, or observe:
113
113
 
114
114
  ```typescript
115
- import { wrapOpenAI, GroundingError } from 'truthguard';
115
+ import { wrapOpenAI, GroundingError } from 'truthguard-ai';
116
116
  import OpenAI from 'openai';
117
117
 
118
118
  const openai = wrapOpenAI(new OpenAI(), {
@@ -131,7 +131,7 @@ const openai = wrapOpenAI(new OpenAI(), {
131
131
  ### Baseline Regression Detection
132
132
 
133
133
  ```typescript
134
- import { createSnapshot, saveBaseline, loadBaseline, compareToBaseline } from 'truthguard';
134
+ import { createSnapshot, saveBaseline, loadBaseline, compareToBaseline } from 'truthguard-ai';
135
135
 
136
136
  // Save after a known-good run
137
137
  const snapshot = createSnapshot(result, 'v1.2-main');
@@ -158,7 +158,7 @@ Use TruthGuard directly from your IDE — no terminal needed.
158
158
  "truthguard": {
159
159
  "type": "stdio",
160
160
  "command": "npx",
161
- "args": ["-y", "truthguard", "mcp"]
161
+ "args": ["-y", "truthguard-ai", "mcp"]
162
162
  }
163
163
  }
164
164
  }
@@ -178,7 +178,7 @@ Full setup guide: [docs/getting-started.md](docs/getting-started.md#ide--mcp-ser
178
178
 
179
179
  ```typescript
180
180
  import express from 'express';
181
- import { groundingMiddleware, FileStore } from 'truthguard';
181
+ import { groundingMiddleware, FileStore } from 'truthguard-ai';
182
182
 
183
183
  const app = express();
184
184
  app.post('/api/chat', groundingMiddleware({
@@ -193,10 +193,10 @@ app.post('/api/chat', groundingMiddleware({
193
193
  ## CLI
194
194
 
195
195
  ```bash
196
- npx truthguard debug trace.json # Evaluate one trace
197
- npx truthguard run dataset.jsonl # Batch dataset evaluation
198
- npx truthguard run dataset.jsonl --gate gate.yml # CI quality gate
199
- npx truthguard observe --port 3001 # Start observe server + proxy
196
+ npx truthguard-ai debug trace.json # Evaluate one trace
197
+ npx truthguard-ai run dataset.jsonl # Batch dataset evaluation
198
+ npx truthguard-ai run dataset.jsonl --gate gate.yml # CI quality gate
199
+ npx truthguard-ai observe --port 3001 # Start observe server + proxy
200
200
  ```
201
201
 
202
202
  ---
@@ -219,7 +219,7 @@ jobs:
219
219
  with:
220
220
  node-version: '20'
221
221
  - run: npm ci
222
- - run: npx truthguard run test-cases.jsonl --gate .ai-rcp-gate.yml
222
+ - run: npx truthguard-ai run test-cases.jsonl --gate .ai-rcp-gate.yml
223
223
  ```
224
224
 
225
225
  ### Gate config (`.ai-rcp-gate.yml`)
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Claim Extractor
3
+ *
4
+ * Extracts factual claims from free-form LLM text.
5
+ *
6
+ * V1 supports:
7
+ * - numbers (integer and decimal)
8
+ * - dates (common formats → ISO-8601)
9
+ * - names (capitalised multi-word proper nouns)
10
+ * - counts (explicit "N [items]" patterns)
11
+ *
12
+ * V1 explicitly skips vague qualitative claims ("most", "significant", "many").
13
+ */
14
+ import type { Claim, TraceStepRole } from '../types';
15
+ /**
16
+ * Attempt to parse a date-like string into an ISO-8601 date (YYYY-MM-DD).
17
+ * Returns null if parsing fails.
18
+ */
19
+ export declare function tryParseDate(raw: string, _referenceDate?: Date): string | null;
20
+ /**
21
+ * A date range representing a period (inclusive start, inclusive end).
22
+ */
23
+ export interface PeriodBounds {
24
+ start: string;
25
+ end: string;
26
+ label: string;
27
+ }
28
+ /**
29
+ * Parse a period expression into start/end bounds.
30
+ * Supports: Q1-Q4, H1/H2, FY, YTD, MTD, "last quarter", "this quarter",
31
+ * "last month", "this month", "MonthName YYYY", "YYYY", rolling periods.
32
+ *
33
+ * Returns null if the expression is not a recognized period.
34
+ */
35
+ export declare function parsePeriodBounds(raw: string, referenceDate?: Date): PeriodBounds | null;
36
+ /**
37
+ * Strip diacritics (č→c, ć→c, š→s, ž→z, đ→d, etc.) and lowercase.
38
+ * Allows entity matching across diacritic and case variants.
39
+ */
40
+ export declare function normalizeEntityName(name: string): string;
41
+ /**
42
+ * Check if two entity names refer to the same person/thing.
43
+ * Handles: case, diacritics, partial name matching (first/last name subset).
44
+ */
45
+ export declare function entitiesMatch(a: string, b: string): boolean;
46
+ /**
47
+ * Strips combining diacritical marks for matching purposes.
48
+ * "Tasić" → "Tasic", "Čačak" → "Cacak", "Новосибирск" → "Новосибирск" (Cyrillic unchanged).
49
+ * Uses Unicode NFD decomposition + strip combining marks (U+0300–U+036F).
50
+ */
51
+ export declare function normalizeDiacritics(str: string): string;
52
+ /** Options for claim extraction. */
53
+ export interface ExtractorOptions {
54
+ /** Step ID of the source (defaults to 'unknown'). */
55
+ sourceStepId?: string;
56
+ /** Role of the source step. */
57
+ sourceRole?: TraceStepRole;
58
+ /** Reference date for resolving relative dates ("yesterday", "pre 3 dana"). Defaults to now. */
59
+ referenceDate?: Date;
60
+ }
61
+ /**
62
+ * Extracts factual claims from a text string.
63
+ *
64
+ * Extraction order:
65
+ * 1. Dates — before numbers so date digits are not re-extracted as numbers
66
+ * 2. Counts — before numbers so count numerals are not re-extracted as plain numbers
67
+ * 3. Numbers
68
+ * 4. Names
69
+ *
70
+ * Vague qualitative claims are skipped.
71
+ */
72
+ export declare function extractClaims(text: string, options?: ExtractorOptions): Claim[];
73
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Claims/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EAAE,KAAK,EAA0B,aAAa,EAAY,MAAM,UAAU,CAAC;AAyGvF;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CA6J9E;AAcD;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACf;AAYD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,IAAI,GAAG,YAAY,GAAG,IAAI,CAyLxF;AAkXD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQxD;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAoB3D;AAqSD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEvD;AA4CD,oCAAoC;AACpC,MAAM,WAAW,gBAAgB;IAC/B,qDAAqD;IACrD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,+BAA+B;IAC/B,UAAU,CAAC,EAAE,aAAa,CAAC;IAC3B,gGAAgG;IAChG,aAAa,CAAC,EAAE,IAAI,CAAC;CACtB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB,GAAG,KAAK,EAAE,CA4jBnF"}