@thanh01.pmt/research-kit 1.0.0 → 1.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 (78) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +213 -0
  3. package/dist/academic/index.cjs +332 -127
  4. package/dist/academic/index.cjs.map +1 -1
  5. package/dist/academic/index.d.cts +3 -3
  6. package/dist/academic/index.d.ts +3 -3
  7. package/dist/academic/index.js +2 -2
  8. package/dist/{catalogBuilder-8A-Dg_A-.d.ts → catalogBuilder-CmmQzUnf.d.ts} +11 -3
  9. package/dist/{catalogBuilder-feU79wQQ.d.cts → catalogBuilder-DgXYxL2F.d.cts} +11 -3
  10. package/dist/chunk-2JEVBCIF.js +3 -0
  11. package/dist/{chunk-KGCDYFFD.js.map → chunk-2JEVBCIF.js.map} +1 -1
  12. package/dist/chunk-2XIEWCUE.js +244 -0
  13. package/dist/chunk-2XIEWCUE.js.map +1 -0
  14. package/dist/chunk-AUGVVZTL.js +514 -0
  15. package/dist/chunk-AUGVVZTL.js.map +1 -0
  16. package/dist/chunk-DOXSPRSP.js +559 -0
  17. package/dist/chunk-DOXSPRSP.js.map +1 -0
  18. package/dist/chunk-GKF3NDEX.js +162 -0
  19. package/dist/chunk-GKF3NDEX.js.map +1 -0
  20. package/dist/chunk-J3VCGH7Z.js +3 -0
  21. package/dist/chunk-J3VCGH7Z.js.map +1 -0
  22. package/dist/{chunk-67V2GJGK.js → chunk-J7XKDMGL.js} +7 -5
  23. package/dist/chunk-J7XKDMGL.js.map +1 -0
  24. package/dist/chunk-KAFQVI2R.js +333 -0
  25. package/dist/chunk-KAFQVI2R.js.map +1 -0
  26. package/dist/chunk-XIF5YNI7.js +799 -0
  27. package/dist/chunk-XIF5YNI7.js.map +1 -0
  28. package/dist/config/index.cjs +5 -3
  29. package/dist/config/index.cjs.map +1 -1
  30. package/dist/config/index.d.cts +1 -1
  31. package/dist/config/index.d.ts +1 -1
  32. package/dist/config/index.js +1 -1
  33. package/dist/evidence/index.cjs +337 -21
  34. package/dist/evidence/index.cjs.map +1 -1
  35. package/dist/evidence/index.d.cts +44 -7
  36. package/dist/evidence/index.d.ts +44 -7
  37. package/dist/evidence/index.js +3 -2
  38. package/dist/harvester/index.cjs +805 -64
  39. package/dist/harvester/index.cjs.map +1 -1
  40. package/dist/harvester/index.d.cts +79 -8
  41. package/dist/harvester/index.d.ts +79 -8
  42. package/dist/harvester/index.js +3 -2
  43. package/dist/{index-BU5n1ip_.d.ts → index-t8pahlJ4.d.cts} +104 -15
  44. package/dist/{index-BU5n1ip_.d.cts → index-t8pahlJ4.d.ts} +104 -15
  45. package/dist/index.cjs +2001 -252
  46. package/dist/index.cjs.map +1 -1
  47. package/dist/index.d.cts +156 -8
  48. package/dist/index.d.ts +156 -8
  49. package/dist/index.js +237 -8
  50. package/dist/index.js.map +1 -1
  51. package/dist/literatureReview-BTPFe7eb.d.cts +64 -0
  52. package/dist/literatureReview-hGbfrBmw.d.ts +64 -0
  53. package/dist/pipeline/index.cjs +1570 -241
  54. package/dist/pipeline/index.cjs.map +1 -1
  55. package/dist/pipeline/index.d.cts +49 -9
  56. package/dist/pipeline/index.d.ts +49 -9
  57. package/dist/pipeline/index.js +5 -4
  58. package/dist/webScraper-BhiQ8s9x.d.ts +68 -0
  59. package/dist/webScraper-D9Ldus9p.d.cts +68 -0
  60. package/package.json +8 -9
  61. package/dist/chunk-47L7ZHMY.js +0 -316
  62. package/dist/chunk-47L7ZHMY.js.map +0 -1
  63. package/dist/chunk-63X2HPCI.js +0 -47
  64. package/dist/chunk-63X2HPCI.js.map +0 -1
  65. package/dist/chunk-67V2GJGK.js.map +0 -1
  66. package/dist/chunk-6Q2XCUG7.js +0 -40
  67. package/dist/chunk-6Q2XCUG7.js.map +0 -1
  68. package/dist/chunk-KGCDYFFD.js +0 -3
  69. package/dist/chunk-MHAYD555.js +0 -239
  70. package/dist/chunk-MHAYD555.js.map +0 -1
  71. package/dist/chunk-MPLDSHFM.js +0 -396
  72. package/dist/chunk-MPLDSHFM.js.map +0 -1
  73. package/dist/chunk-QZNLB5X4.js +0 -65
  74. package/dist/chunk-QZNLB5X4.js.map +0 -1
  75. package/dist/literatureReview-C4AgVljZ.d.ts +0 -43
  76. package/dist/literatureReview-Dlods4Aw.d.cts +0 -43
  77. package/dist/webScraper-pKzdXhfI.d.ts +0 -46
  78. package/dist/webScraper-yBcYOHoL.d.cts +0 -46
@@ -1,73 +1,388 @@
1
1
  'use strict';
2
2
 
3
+ // src/harvester/webScraper.ts
4
+ function extractSubstantiveExcerpts(markdown, maxExcerpts = 6) {
5
+ const withoutCode = markdown.replace(/```[\s\S]*?```/g, "\n");
6
+ const blocks = withoutCode.split(/\n{2,}/).map((b) => b.replace(/\s+/g, " ").trim()).filter((b) => {
7
+ if (b.length < 60 || b.length > 900) return false;
8
+ if (b.startsWith("#") || b.startsWith("|")) return false;
9
+ const linkRatio = (b.match(/\[[^\]]+\]\([^)]+\)/g) || []).join("").length / b.length;
10
+ if (linkRatio > 0.45) return false;
11
+ if (/\b(cookie policy|privacy policy|all rights reserved|terms of service|sign in|log in|subscribe to our newsletter)\b/i.test(b)) {
12
+ return false;
13
+ }
14
+ return true;
15
+ });
16
+ return blocks.slice(0, maxExcerpts);
17
+ }
18
+
3
19
  // src/evidence/evidenceScorer.ts
20
+ function tokenizeBilingualKeywords(text) {
21
+ return text.normalize("NFC").toLowerCase().replace(/[.,;:!?()[\]{}"“”‘’/\\|`*_~#-]+/g, " ").split(/\s+/).filter((w) => w.length >= 2 && !/^(and|the|for|with|from|into|của|trong|được|những|các|cho|với|khi|và|hoặc|để|từ|đến|về)$/.test(w));
22
+ }
23
+ function extractTopSentences(markdown, targetTopic, maxSentences = 3) {
24
+ const keywords = tokenizeBilingualKeywords(targetTopic);
25
+ const withoutCode = markdown.replace(/```[\s\S]*?```/g, " ");
26
+ const rawSentences = withoutCode.split(/(?<=[.!?。\n])\s+/).map((s) => s.replace(/^[-*•#>\s]+/, "").replace(/\s+/g, " ").trim()).filter((s) => {
27
+ if (s.length < 45 || s.length > 320) return false;
28
+ if (s.startsWith("|") || s.startsWith("http")) return false;
29
+ if (/\b(cookie|privacy policy|sign in|subscribe|all rights reserved)\b/i.test(s)) return false;
30
+ return true;
31
+ });
32
+ if (rawSentences.length === 0) return [];
33
+ const scored = rawSentences.map((sentence, idx) => {
34
+ const lower = sentence.normalize("NFC").toLowerCase();
35
+ const matchedCount = keywords.filter((k) => lower.includes(k)).length;
36
+ const positionBonus = idx < 8 ? 1.5 : idx < 20 ? 0.5 : 0;
37
+ const technicalBonus = /(`[^`]+`|\b(?:api|function|class|actor|async|sensor|pin|loop|state|biến|hàm|cảm biến|vòng lặp|mạch)\b)/i.test(
38
+ sentence
39
+ ) ? 1.5 : 0;
40
+ return {
41
+ sentence,
42
+ idx,
43
+ score: matchedCount * 2 + positionBonus + technicalBonus
44
+ };
45
+ });
46
+ return scored.sort((a, b) => b.score - a.score || a.idx - b.idx).slice(0, maxSentences).sort((a, b) => a.idx - b.idx).map((s) => s.sentence);
47
+ }
4
48
  var EvidenceScorer = class {
5
49
  scoreDocument(doc, domain, targetTopic) {
6
50
  let depthScore = 5;
7
- let codeScore = doc.extractedCodeSnippets.length > 0 ? 8 : 4;
51
+ const hasCode = doc.extractedCodeSnippets.length > 0;
52
+ let codeScore = hasCode ? Math.min(10, 7 + Math.min(3, doc.extractedCodeSnippets.length)) : 5;
8
53
  let noiseScore = 2;
9
- const lowerContent = doc.markdownContent.toLowerCase();
10
- const targetKeywords = targetTopic.toLowerCase().split(/\s+/).filter((w) => w.length > 3);
54
+ const lowerContent = doc.markdownContent.normalize("NFC").toLowerCase();
55
+ const targetKeywords = tokenizeBilingualKeywords(targetTopic);
11
56
  const keywordMatches = targetKeywords.filter((k) => lowerContent.includes(k)).length;
12
- if (keywordMatches >= targetKeywords.length) depthScore += 3;
57
+ const matchRatio = targetKeywords.length > 0 ? keywordMatches / targetKeywords.length : 1;
58
+ if (matchRatio >= 0.75) depthScore += 3;
59
+ else if (matchRatio >= 0.4) depthScore += 2;
60
+ else if (keywordMatches >= 1) depthScore += 1;
13
61
  if (doc.tablesCount > 0) depthScore += 1;
14
- if (doc.byteSize > 2e3) depthScore += 1;
62
+ if (doc.byteSize > 1500) depthScore += 1;
63
+ if ((doc.extractedHeadings?.length || 0) >= 2) depthScore += 1;
64
+ depthScore = Math.min(10, depthScore);
65
+ if (!hasCode && doc.byteSize > 1200 && matchRatio >= 0.5) {
66
+ codeScore = 6;
67
+ }
15
68
  if (lowerContent.includes("subscribe") && lowerContent.includes("advertisement")) {
16
69
  noiseScore += 3;
17
70
  }
18
- const rawTotal = depthScore * 0.5 + codeScore * 0.4 - noiseScore * 0.1;
71
+ const rawTotal = depthScore * 0.55 + codeScore * 0.35 - noiseScore * 0.1 + 0.5;
19
72
  const score = Math.max(1, Math.min(10, Math.round(rawTotal)));
20
73
  const isApproved = score >= 6;
21
- const summary = `Evidence scored ${score}/10 (${isApproved ? "APPROVED" : "REJECTED"}). Contains ${doc.extractedCodeSnippets.length} code snippets and ${doc.tablesCount} reference tables for domain ${domain}.`;
74
+ const topSentences = extractTopSentences(doc.markdownContent, targetTopic, 3);
75
+ const excerpts = doc.keyExcerpts?.length ? doc.keyExcerpts : extractSubstantiveExcerpts(doc.markdownContent, 3);
76
+ const keyTakeaways = topSentences.length > 0 ? topSentences : excerpts.slice(0, 2);
77
+ const summary = keyTakeaways.length > 0 ? `${keyTakeaways[0]} [Evidence ${score}/10 \xB7 ${doc.extractedCodeSnippets.length} code blocks \xB7 ${doc.tablesCount} tables]` : `Evidence scored ${score}/10 (${isApproved ? "APPROVED" : "REJECTED"}) for ${domain} (${doc.byteSize} bytes).`;
22
78
  return {
23
79
  doc,
24
80
  score,
25
81
  isApproved,
82
+ isLlmEvaluated: false,
26
83
  breakdown: {
27
84
  technicalDepth: depthScore,
85
+ structuralRichness: depthScore,
28
86
  codeSnippetQuality: codeScore,
29
87
  noiseFactor: noiseScore
30
88
  },
31
- summary
89
+ summary,
90
+ keyTakeaways
32
91
  };
33
92
  }
93
+ /**
94
+ * Evaluates evidence with host LLM for genuine pedagogical relevance, conceptual depth,
95
+ * and accuracy for the target learner age band.
96
+ */
97
+ async scoreDocumentWithLlm(doc, domain, targetTopic, options = {}) {
98
+ const baseline = this.scoreDocument(doc, domain, targetTopic);
99
+ if (!options.llm) {
100
+ return baseline;
101
+ }
102
+ try {
103
+ const prompt = [
104
+ `You are a Senior Curriculum Researcher. Evaluate this harvested web document for the course topic "${targetTopic}" (Domain: ${domain}).`,
105
+ options.context?.ageBand ? `Target Learner Age Band: ${options.context.ageBand[0]}-${options.context.ageBand[1]}` : "",
106
+ options.context?.hardwarePlatform ? `Hardware Platform: ${options.context.hardwarePlatform}` : "",
107
+ options.context?.softwareEnv ? `Software / Tools: ${options.context.softwareEnv}` : "",
108
+ `
109
+ Document Title: ${doc.title}`,
110
+ `Document URL: ${doc.url}`,
111
+ `Sample Excerpts:
112
+ ${(doc.keyExcerpts || []).slice(0, 3).join("\n")}`,
113
+ `Code Blocks Found: ${doc.extractedCodeSnippets.length}`,
114
+ `
115
+ Return ONLY a JSON object:`,
116
+ `{"score": 8, "isApproved": true, "pedagogicalRelevance": 9, "summary": "1-sentence evaluative summary", "keyTakeaways": ["Takeaway 1 grounded in text", "Takeaway 2"]}`
117
+ ].filter(Boolean).join("\n");
118
+ const raw = await options.llm(prompt, {
119
+ system: "You are an educational curriculum auditor. Output strictly valid JSON.",
120
+ temperature: 0.2,
121
+ jsonMode: true
122
+ });
123
+ const match = raw.match(/\{[\s\S]*\}/);
124
+ if (match) {
125
+ const parsed = JSON.parse(match[0]);
126
+ const score = Math.max(1, Math.min(10, Number(parsed.score) || baseline.score));
127
+ return {
128
+ doc,
129
+ score,
130
+ isApproved: score >= 6,
131
+ isLlmEvaluated: true,
132
+ breakdown: {
133
+ ...baseline.breakdown,
134
+ pedagogicalRelevance: Number(parsed.pedagogicalRelevance) || score
135
+ },
136
+ summary: String(parsed.summary || baseline.summary),
137
+ keyTakeaways: Array.isArray(parsed.keyTakeaways) && parsed.keyTakeaways.length > 0 ? parsed.keyTakeaways.map(String) : baseline.keyTakeaways
138
+ };
139
+ }
140
+ } catch (e) {
141
+ console.warn("[EvidenceScorer] LLM evidence evaluation failed, using structural baseline:", e?.message || e);
142
+ }
143
+ return baseline;
144
+ }
34
145
  };
35
146
 
36
147
  // src/evidence/claimVerifier.ts
148
+ var CLAIM_STOPWORDS = /* @__PURE__ */ new Set([
149
+ "the",
150
+ "and",
151
+ "for",
152
+ "with",
153
+ "that",
154
+ "this",
155
+ "from",
156
+ "into",
157
+ "are",
158
+ "was",
159
+ "were",
160
+ "have",
161
+ "has",
162
+ "will",
163
+ "would",
164
+ "through",
165
+ "their",
166
+ "these",
167
+ "those",
168
+ "which",
169
+ "while",
170
+ "c\u1EE7a",
171
+ "trong",
172
+ "\u0111\u01B0\u1EE3c",
173
+ "nh\u1EEFng",
174
+ "c\xE1c",
175
+ "cho",
176
+ "v\u1EDBi",
177
+ "v\xE0",
178
+ "ho\u1EB7c",
179
+ "\u0111\u1EC3",
180
+ "t\u1EEB",
181
+ "\u0111\u1EBFn",
182
+ "v\u1EC1",
183
+ "n\xE0y",
184
+ "\u0111\xF3",
185
+ "m\u1ED9t",
186
+ "nh\u01B0",
187
+ "s\u1EBD",
188
+ "\u0111ang",
189
+ "\u0111\xE3",
190
+ "ra",
191
+ "v\xE0o",
192
+ "l\xE0"
193
+ ]);
194
+ function extractSignificantTokens(text) {
195
+ return text.normalize("NFC").toLowerCase().replace(/[.,;:!?()[\]{}"“”‘’/\\|`*_~#-]+/g, " ").split(/\s+/).filter((w) => w.length >= 3 && !CLAIM_STOPWORDS.has(w));
196
+ }
197
+ function tokenMatchesCorpus(token, lowerCorpus) {
198
+ if (lowerCorpus.includes(token)) return true;
199
+ if (token.length >= 6) {
200
+ const stem = token.replace(/(?:ing|tion|ions|ment|ments|ed|es|s)$/, "");
201
+ if (stem.length >= 4 && lowerCorpus.includes(stem)) return true;
202
+ }
203
+ return false;
204
+ }
37
205
  var ClaimVerifier = class {
38
- verifyClaims(claims, sourceCorpus) {
206
+ /**
207
+ * Deterministic lexical match baseline.
208
+ * Explicitly marks verdict as 'lexical_match_only' to prevent false sense of semantic verification.
209
+ */
210
+ verifyClaimsDeterministic(claims, sourceCorpus) {
39
211
  const verifiedList = [];
40
- const lowerCorpus = sourceCorpus.toLowerCase();
212
+ const normCorpus = sourceCorpus.normalize("NFC");
213
+ const lowerCorpus = normCorpus.toLowerCase();
214
+ const corpusSentences = normCorpus.split(/(?<=[.!?。\n])\s+/).map((s) => s.replace(/^[-*•#>\s]+/, "").replace(/\s+/g, " ").trim()).filter((s) => {
215
+ if (s.length < 25) return false;
216
+ if (/^(title:|url source:|final url:|http|!\[)/i.test(s)) return false;
217
+ return true;
218
+ });
41
219
  for (const claim of claims) {
42
- const claimKeywords = claim.toLowerCase().split(/\s+/).filter((w) => w.length > 4);
43
- const matchCount = claimKeywords.filter((k) => lowerCorpus.includes(k)).length;
44
- const matchRatio = claimKeywords.length > 0 ? matchCount / claimKeywords.length : 0;
45
- const isSupported = matchRatio >= 0.6;
220
+ const claimTokens = extractSignificantTokens(claim);
221
+ const matchCount = claimTokens.filter((t) => tokenMatchesCorpus(t, lowerCorpus)).length;
222
+ const matchRatio = claimTokens.length > 0 ? matchCount / claimTokens.length : 0;
223
+ let bestQuote;
224
+ let bestSentenceRatio = 0;
225
+ for (const sent of corpusSentences) {
226
+ const lowerSent = sent.toLowerCase();
227
+ const sentMatches = claimTokens.filter((t) => tokenMatchesCorpus(t, lowerSent)).length;
228
+ const sentRatio = claimTokens.length > 0 ? sentMatches / claimTokens.length : 0;
229
+ if (sentRatio > bestSentenceRatio) {
230
+ bestSentenceRatio = sentRatio;
231
+ bestQuote = sent.slice(0, 240);
232
+ }
233
+ }
234
+ const effectiveRatio = Math.max(matchRatio, bestSentenceRatio);
235
+ const hasLexicalEvidence = effectiveRatio >= 0.55;
46
236
  verifiedList.push({
47
237
  claimText: claim,
48
- isSupported,
49
- confidenceScore: Math.round(matchRatio * 100)
238
+ verdict: "lexical_match_only",
239
+ isSupported: hasLexicalEvidence,
240
+ isLlmVerified: false,
241
+ confidenceScore: Math.round(effectiveRatio * 100),
242
+ extractedQuote: hasLexicalEvidence ? bestQuote : void 0,
243
+ explanation: hasLexicalEvidence ? `Lexical token match found (${Math.round(effectiveRatio * 100)}% token overlap). Semantic entailment requires LLM verification.` : `Insufficient lexical overlap in harvest corpus (${Math.round(effectiveRatio * 100)}%).`
50
244
  });
51
245
  }
52
246
  const supportedCount = verifiedList.filter((c) => c.isSupported).length;
53
247
  const supportPct = claims.length > 0 ? supportedCount / claims.length * 100 : 100;
54
248
  const hallucinationRisk = supportPct >= 80 ? "low" : supportPct >= 50 ? "medium" : "high";
55
249
  const mdLines = [
56
- `# \u{1F50D} Claim-Support Sweep & Verification Report`,
57
- `> **Verification Rate:** \`${supportPct.toFixed(1)}%\` (${supportedCount}/${claims.length} claims supported) | **Hallucination Risk:** \`${hallucinationRisk.toUpperCase()}\``,
250
+ `# \u{1F50D} Claim-Support Sweep & Verification Report (Lexical Scan Mode)`,
251
+ `> **Notice:** *Scored via deterministic lexical token matching. True semantic entailment requires an LLM call.*`,
252
+ `> **Lexical Coverage:** \`${supportPct.toFixed(1)}%\` (${supportedCount}/${claims.length} claims with token matches) | **Hallucination Risk (Lexical):** \`${hallucinationRisk.toUpperCase()}\``,
58
253
  `
59
- | Pedagogical / Technical Claim | Evidence Status | Confidence Match |`,
60
- `|---|---|---|`,
61
- ...verifiedList.map((c) => `| ${c.claimText} | ${c.isSupported ? "\u2705 **SUPPORTED**" : "\u26A0\uFE0F *UNVERIFIED / GAP*"} | \`${c.confidenceScore}%\` |`)
254
+ | Pedagogical / Technical Claim | Evidence Status | Token Match | Supporting Quote | Semantic Status |`,
255
+ `|---|---|---|---|---|`,
256
+ ...verifiedList.map(
257
+ (c) => `| ${c.claimText.replace(/\|/g, "/")} | ${c.isSupported ? "\u{1F7E1} **LEXICAL MATCH**" : "\u26A0\uFE0F *UNVERIFIED / GAP*"} | \`${c.confidenceScore}%\` | ${(c.extractedQuote || "\u2014").replace(/\|/g, "/")} | *Awaiting LLM Entailment* |`
258
+ )
62
259
  ];
63
260
  return {
64
261
  totalClaimsChecked: claims.length,
65
262
  supportedClaimsCount: supportedCount,
263
+ refutedClaimsCount: 0,
264
+ unverifiedClaimsCount: claims.length - supportedCount,
66
265
  hallucinationRisk,
266
+ isLlmVerified: false,
67
267
  claims: verifiedList,
68
268
  reportMd: mdLines.join("\n")
69
269
  };
70
270
  }
271
+ /**
272
+ * Primary verification interface.
273
+ * If an LLM callback is provided, performs genuine Semantic Entailment (NLI).
274
+ * Otherwise falls back to deterministic lexical retrieval with honest labeling.
275
+ */
276
+ async verifyClaims(claims, sourceCorpus, options = {}) {
277
+ const detReport = this.verifyClaimsDeterministic(claims, sourceCorpus);
278
+ if (!options.llm || claims.length === 0) {
279
+ return detReport;
280
+ }
281
+ try {
282
+ const normCorpus = sourceCorpus.normalize("NFC");
283
+ const cleanSubstantiveText = normCorpus.replace(/```[\s\S]*?```/g, "\n").split("\n").filter((l) => !/^(title:|url source:|final url:|http|!\[|#)/i.test(l.trim())).join("\n").trim();
284
+ const corpusSentences = cleanSubstantiveText.split(/(?<=[.!?。\n])\s+/).map((s) => s.replace(/^[-*•#>\s]+/, "").replace(/\s+/g, " ").trim()).filter((s) => s.length >= 25 && !/^(cookie|privacy|sign in|all rights reserved)/i.test(s));
285
+ const fallbackExcerpts = corpusSentences.slice(0, 8).join("\n");
286
+ const claimContexts = claims.map((claim, idx) => {
287
+ const tokens = extractSignificantTokens(claim);
288
+ const topSentences = corpusSentences.map((sent) => ({
289
+ sent,
290
+ overlap: tokens.filter((t) => tokenMatchesCorpus(t, sent.toLowerCase())).length
291
+ })).filter((item) => item.overlap > 0).sort((a, b) => b.overlap - a.overlap).slice(0, 5).map((item) => item.sent);
292
+ const candidates = topSentences.length > 0 ? `${topSentences.join("\n")}
293
+
294
+ [General Reference Excerpts]:
295
+ ${fallbackExcerpts}` : fallbackExcerpts || "No substantive text found.";
296
+ return {
297
+ idx,
298
+ claim,
299
+ candidatePassages: candidates
300
+ };
301
+ });
302
+ const prompt = [
303
+ `You are a Rigorous Scientific & Pedagogical Fact-Checking System (Natural Language Inference).`,
304
+ `Evaluate whether each technical/pedagogical claim is strictly SUPPORTED, directly REFUTED, or has NOT_ENOUGH_EVIDENCE in the harvested technical reference text.`,
305
+ `Pay careful attention to NEGATION words ("kh\xF4ng", "never", "tr\xE1nh", "do not"), causal relationships, hardware pin constraints, and edge cases. Do not assume truth without textual evidence.`,
306
+ `
307
+ Harvested Reference Excerpts for Claims:
308
+ `,
309
+ claimContexts.map((c) => `[Claim ${c.idx + 1}]: "${c.claim}"
310
+ [Passage Candidates]: ${c.candidatePassages}`).join("\n\n"),
311
+ `
312
+ Return ONLY a valid JSON array of objects with the exact structure:`,
313
+ `[{"claimIndex": 1, "verdict": "supported"|"refuted"|"not_enough_evidence", "confidenceScore": 95, "extractedQuote": "exact quote from passage", "explanation": "1-sentence semantic reason"}]`
314
+ ].join("\n");
315
+ const raw = await options.llm(prompt, {
316
+ system: "You are an exacting academic fact-checker. Output strictly valid JSON array without commentary.",
317
+ temperature: 0.1,
318
+ jsonMode: true
319
+ });
320
+ let parsed = [];
321
+ const arrayMatch = raw.match(/\[[\s\S]*\]/);
322
+ if (arrayMatch) {
323
+ try {
324
+ const res = JSON.parse(arrayMatch[0]);
325
+ if (Array.isArray(res)) parsed = res;
326
+ } catch {
327
+ }
328
+ }
329
+ if (parsed.length === 0) {
330
+ const objMatch = raw.match(/\{[\s\S]*\}/);
331
+ if (objMatch) {
332
+ try {
333
+ const obj = JSON.parse(objMatch[0]);
334
+ const candidateList = obj.claims || obj.results || obj.verifications || Object.values(obj).find(Array.isArray);
335
+ if (Array.isArray(candidateList)) parsed = candidateList;
336
+ } catch {
337
+ }
338
+ }
339
+ }
340
+ if (parsed.length > 0) {
341
+ const verifiedList = claims.map((claim, idx) => {
342
+ const item = parsed.find((p) => p.claimIndex === idx + 1) || parsed[idx];
343
+ const verdict = item && ["supported", "refuted", "not_enough_evidence"].includes(item.verdict) ? item.verdict : detReport.claims[idx]?.isSupported ? "supported" : "not_enough_evidence";
344
+ const isSupported = verdict === "supported";
345
+ return {
346
+ claimText: claim,
347
+ verdict,
348
+ isSupported,
349
+ isLlmVerified: true,
350
+ confidenceScore: Number(item?.confidenceScore) || (isSupported ? 90 : 30),
351
+ extractedQuote: item?.extractedQuote || detReport.claims[idx]?.extractedQuote,
352
+ explanation: item?.explanation || (isSupported ? "Semantically entailed by reference corpus." : "Not verified.")
353
+ };
354
+ });
355
+ const supportedCount = verifiedList.filter((c) => c.verdict === "supported").length;
356
+ const refutedCount = verifiedList.filter((c) => c.verdict === "refuted").length;
357
+ const unverifiedCount = claims.length - supportedCount;
358
+ const supportPct = claims.length > 0 ? supportedCount / claims.length * 100 : 100;
359
+ const hallucinationRisk = refutedCount > 0 ? "high" : supportPct >= 75 ? "low" : "medium";
360
+ const mdLines = [
361
+ `# \u{1F50D} Claim-Support Sweep & Semantic Verification Report (LLM NLI Evaluated)`,
362
+ `> **Semantic Verification Rate:** \`${supportPct.toFixed(1)}%\` (${supportedCount}/${claims.length} claims supported) | **Refuted / Contradictions:** \`${refutedCount}\` | **Hallucination Risk:** \`${hallucinationRisk.toUpperCase()}\``,
363
+ `
364
+ | Pedagogical / Technical Claim | Semantic Verdict | Confidence | Supporting Quote / Evidence | Explanation |`,
365
+ `|---|---|---|---|---|`,
366
+ ...verifiedList.map(
367
+ (c) => `| ${c.claimText.replace(/\|/g, "/")} | ${c.verdict === "supported" ? "\u2705 **SUPPORTED**" : c.verdict === "refuted" ? "\u274C **REFUTED**" : "\u26A0\uFE0F *NOT ENOUGH EVIDENCE*"} | \`${c.confidenceScore}%\` | ${(c.extractedQuote || "\u2014").replace(/\|/g, "/")} | ${(c.explanation || "").replace(/\|/g, "/")} |`
368
+ )
369
+ ];
370
+ return {
371
+ totalClaimsChecked: claims.length,
372
+ supportedClaimsCount: supportedCount,
373
+ refutedClaimsCount: refutedCount,
374
+ unverifiedClaimsCount: unverifiedCount,
375
+ hallucinationRisk,
376
+ isLlmVerified: true,
377
+ claims: verifiedList,
378
+ reportMd: mdLines.join("\n")
379
+ };
380
+ }
381
+ } catch (e) {
382
+ console.warn("[ClaimVerifier] LLM semantic verification failed, falling back to deterministic lexical report:", e?.message || e);
383
+ }
384
+ return detReport;
385
+ }
71
386
  };
72
387
 
73
388
  // src/evidence/provenanceTracker.ts
@@ -102,5 +417,6 @@ var ProvenanceTracker = class {
102
417
  exports.ClaimVerifier = ClaimVerifier;
103
418
  exports.EvidenceScorer = EvidenceScorer;
104
419
  exports.ProvenanceTracker = ProvenanceTracker;
420
+ exports.extractTopSentences = extractTopSentences;
105
421
  //# sourceMappingURL=index.cjs.map
106
422
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/evidence/evidenceScorer.ts","../../src/evidence/claimVerifier.ts","../../src/evidence/provenanceTracker.ts"],"names":[],"mappings":";;;AAkBO,IAAM,iBAAN,MAAqB;AAAA,EAC1B,aAAA,CAAc,GAAA,EAAsB,MAAA,EAAyB,WAAA,EAAqC;AAChG,IAAA,IAAI,UAAA,GAAa,CAAA;AACjB,IAAA,IAAI,SAAA,GAAY,GAAA,CAAI,qBAAA,CAAsB,MAAA,GAAS,IAAI,CAAA,GAAI,CAAA;AAC3D,IAAA,IAAI,UAAA,GAAa,CAAA;AAEjB,IAAA,MAAM,YAAA,GAAe,GAAA,CAAI,eAAA,CAAgB,WAAA,EAAY;AACrD,IAAA,MAAM,cAAA,GAAiB,WAAA,CAAY,WAAA,EAAY,CAAE,KAAA,CAAM,KAAK,CAAA,CAAE,MAAA,CAAO,CAAA,CAAA,KAAK,CAAA,CAAE,MAAA,GAAS,CAAC,CAAA;AACtF,IAAA,MAAM,cAAA,GAAiB,eAAe,MAAA,CAAO,CAAA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CAAE,MAAM,CAAA,cAAA,EAAY,CAAA,CAAE,cAAc,aAAa,CAAA,CAAE,QAAQ,CAAA,qBAAA,EAAwB,CAAA,CAAE,SAAS,CAAA,MAAA,EAAS,CAAA,CAAE,UAAA,CAAW,KAAA,CAAM,CAAA,EAAG,EAAE,CAAC,CAAA,IAAA,CAAM,CAAA;AAAA,MACvL;AAAA,sBAAA,CAAA;AAAA,MACA,CAAA,mHAAA,CAAA;AAAA,MACA,CAAA,sGAAA;AAAA,KACF;AAEA,IAAA,OAAO;AAAA,MACL,KAAA;AAAA,MACA,UAAA;AAAA,MACA,WAAA;AAAA,MACA,cAAc,OAAA,CAAQ,MAAA;AAAA,MACtB,OAAA;AAAA,MACA,YAAA,EAAc,OAAA,CAAQ,IAAA,CAAK,IAAI;AAAA,KACjC;AAAA,EACF;AACF","file":"index.cjs","sourcesContent":["import { ScrapedDocument } from '../harvester/webScraper';\nimport { TechnicalDomain } from '../harvester/domainClassifier';\n\nexport interface ScoredEvidence {\n doc: ScrapedDocument;\n score: number; // 1 to 10\n isApproved: boolean; // >= 6 is approved\n breakdown: {\n technicalDepth: number; // 1-10\n codeSnippetQuality: number; // 1-10\n noiseFactor: number; // 1-10 (lower is better)\n };\n summary: string;\n}\n\n/**\n * Evaluates and scores evidence on a 1-10 scale as mandated by Harvest 1-4 & course_research.md (English Canonical)\n */\nexport class EvidenceScorer {\n scoreDocument(doc: ScrapedDocument, domain: TechnicalDomain, targetTopic: string): ScoredEvidence {\n let depthScore = 5;\n let codeScore = doc.extractedCodeSnippets.length > 0 ? 8 : 4;\n let noiseScore = 2;\n\n const lowerContent = doc.markdownContent.toLowerCase();\n const targetKeywords = targetTopic.toLowerCase().split(/\\s+/).filter(w => w.length > 3);\n const keywordMatches = targetKeywords.filter(k => lowerContent.includes(k)).length;\n\n if (keywordMatches >= targetKeywords.length) depthScore += 3;\n if (doc.tablesCount > 0) depthScore += 1;\n if (doc.byteSize > 2000) depthScore += 1;\n\n if (lowerContent.includes('subscribe') && lowerContent.includes('advertisement')) {\n noiseScore += 3;\n }\n\n const rawTotal = (depthScore * 0.5 + codeScore * 0.4 - noiseScore * 0.1);\n const score = Math.max(1, Math.min(10, Math.round(rawTotal)));\n const isApproved = score >= 6;\n\n const summary = `Evidence scored ${score}/10 (${isApproved ? 'APPROVED' : 'REJECTED'}). Contains ${doc.extractedCodeSnippets.length} code snippets and ${doc.tablesCount} reference tables for domain ${domain}.`;\n\n return {\n doc,\n score,\n isApproved,\n breakdown: {\n technicalDepth: depthScore,\n codeSnippetQuality: codeScore,\n noiseFactor: noiseScore,\n },\n summary,\n };\n }\n}\n","export interface VerifiedClaim {\n claimText: string;\n sourceUrl?: string;\n isSupported: boolean;\n confidenceScore: number;\n extractedQuote?: string;\n}\n\nexport interface ClaimSweepReport {\n totalClaimsChecked: number;\n supportedClaimsCount: number;\n hallucinationRisk: 'low' | 'medium' | 'high';\n claims: VerifiedClaim[];\n reportMd: string;\n}\n\n/**\n * Claim-Support Sweep & Fact Checker (Anti-Hallucination Gate - English Canonical)\n */\nexport class ClaimVerifier {\n verifyClaims(claims: string[], sourceCorpus: string): ClaimSweepReport {\n const verifiedList: VerifiedClaim[] = [];\n const lowerCorpus = sourceCorpus.toLowerCase();\n\n for (const claim of claims) {\n const claimKeywords = claim.toLowerCase().split(/\\s+/).filter(w => w.length > 4);\n const matchCount = claimKeywords.filter(k => lowerCorpus.includes(k)).length;\n const matchRatio = claimKeywords.length > 0 ? matchCount / claimKeywords.length : 0;\n\n const isSupported = matchRatio >= 0.6;\n verifiedList.push({\n claimText: claim,\n isSupported,\n confidenceScore: Math.round(matchRatio * 100),\n });\n }\n\n const supportedCount = verifiedList.filter(c => c.isSupported).length;\n const supportPct = claims.length > 0 ? (supportedCount / claims.length) * 100 : 100;\n const hallucinationRisk = supportPct >= 80 ? 'low' : supportPct >= 50 ? 'medium' : 'high';\n\n const mdLines = [\n `# 🔍 Claim-Support Sweep & Verification Report`,\n `> **Verification Rate:** \\`${supportPct.toFixed(1)}%\\` (${supportedCount}/${claims.length} claims supported) | **Hallucination Risk:** \\`${hallucinationRisk.toUpperCase()}\\``,\n `\\n| Pedagogical / Technical Claim | Evidence Status | Confidence Match |`,\n `|---|---|---|`,\n ...verifiedList.map(c => `| ${c.claimText} | ${c.isSupported ? '✅ **SUPPORTED**' : '⚠️ *UNVERIFIED / GAP*'} | \\`${c.confidenceScore}%\\` |`)\n ];\n\n return {\n totalClaimsChecked: claims.length,\n supportedClaimsCount: supportedCount,\n hallucinationRisk,\n claims: verifiedList,\n reportMd: mdLines.join('\\n'),\n };\n }\n}\n","export interface ProvenanceRecord {\n resourceId: string;\n sourceUrl: string;\n accessedAt: string;\n domain: string;\n relevanceScore: number;\n byteSize: number;\n}\n\nexport interface ProvenanceSidecar {\n topic: string;\n campaignId: string;\n generatedAt: string;\n totalRecords: number;\n records: ProvenanceRecord[];\n provenanceMd: string;\n}\n\n/**\n * Generates the mandatory *.provenance.md sidecar document (English Canonical)\n */\nexport class ProvenanceTracker {\n generateSidecar(topic: string, records: ProvenanceRecord[]): ProvenanceSidecar {\n const campaignId = `CAMP-${Math.random().toString(36).substring(2, 9).toUpperCase()}`;\n const generatedAt = new Date().toISOString();\n\n const mdLines = [\n `# 📜 Provenance & Audit Trail: ${topic}`,\n `> **Campaign ID:** \\`${campaignId}\\` | **Generated At:** \\`${generatedAt}\\` | **Total Verified Sources:** \\`${records.length}\\``,\n `\\n## Audit Trail Table`,\n `| Resource ID | Domain | Relevancy | Size (Bytes) | Source URL | Timestamp |`,\n `|---|---|---|---|---|---|`,\n ...records.map(r => `| **${r.resourceId}** | \\`${r.domain}\\` | ⭐ \\`${r.relevanceScore}/10\\` | \\`${r.byteSize}\\` | [Access Source](${r.sourceUrl}) | \\`${r.accessedAt.slice(0, 19)}\\` |`),\n `\\n## Integrity Guarantee`,\n `- Every pedagogical claim and technical snippet in the curriculum maps 1-to-1 to the physical sources listed above.`,\n `- Unverified citations or hallucinated sources are strictly prohibited under Curriculum OS Rule §5.`\n ];\n\n return {\n topic,\n campaignId,\n generatedAt,\n totalRecords: records.length,\n records,\n provenanceMd: mdLines.join('\\n'),\n };\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/harvester/webScraper.ts","../../src/evidence/evidenceScorer.ts","../../src/evidence/claimVerifier.ts","../../src/evidence/provenanceTracker.ts"],"names":[],"mappings":";;;AAgCO,SAAS,0BAAA,CAA2B,QAAA,EAAkB,WAAA,GAAc,CAAA,EAAa;AACtF,EAAA,MAAM,WAAA,GAAc,QAAA,CAAS,OAAA,CAAQ,iBAAA,EAAmB,IAAI,CAAA;AAC5D,EAAA,MAAM,SAAS,WAAA,CACZ,KAAA,CAAM,QAAQ,CAAA,CACd,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,CAAE,OAAA,CAAQ,MAAA,EAAQ,GAAG,CAAA,CAAE,IAAA,EAAM,CAAA,CACxC,MAAA,CAAO,CAAC,CAAA,KAAM;AACb,IAAA,IAAI,EAAE,MAAA,GAAS,EAAA,IAAM,CAAA,CAAE,MAAA,GAAS,KAAK,OAAO,KAAA;AAC5C,IAAA,IAAI,CAAA,CAAE,WAAW,GAAG,CAAA,IAAK,EAAE,UAAA,CAAW,GAAG,GAAG,OAAO,KAAA;AACnD,IAAA,MAAM,SAAA,GAAA,CAAa,CAAA,CAAE,KAAA,CAAM,sBAAsB,CAAA,IAAK,EAAC,EAAG,IAAA,CAAK,EAAE,CAAA,CAAE,MAAA,GAAS,CAAA,CAAE,MAAA;AAC9E,IAAA,IAAI,SAAA,GAAY,MAAM,OAAO,KAAA;AAC7B,IAAA,IAAI,qHAAA,CAAsH,IAAA,CAAK,CAAC,CAAA,EAAG;AACjI,MAAA,OAAO,KAAA;AAAA,IACT;AACA,IAAA,OAAO,IAAA;AAAA,EACT,CAAC,CAAA;AAEH,EAAA,OAAO,MAAA,CAAO,KAAA,CAAM,CAAA,EAAG,WAAW,CAAA;AACpC;;;AC7BA,SAAS,0BAA0B,IAAA,EAAwB;AACzD,EAAA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AEA,IAAA,OAAO;AAAA,MACL,KAAA;AAAA,MACA,UAAA;AAAA,MACA,WAAA;AAAA,MACA,cAAc,OAAA,CAAQ,MAAA;AAAA,MACtB,OAAA;AAAA,MACA,YAAA,EAAc,OAAA,CAAQ,IAAA,CAAK,IAAI;AAAA,KACjC;AAAA,EACF;AACF","file":"index.cjs","sourcesContent":["import { CustomCrawlerAdapter } from '../config/researchConfig';\nimport { isYouTubeUrl, YouTubeIngestionService } from './youtubeTranscript';\n\nexport interface ExtractedCodeBlock {\n language: string;\n code: string;\n}\n\nexport interface ScrapedDocument {\n url: string;\n title: string;\n markdownContent: string;\n byteSize: number;\n extractedCodeSnippets: string[];\n extractedCodeBlocks?: ExtractedCodeBlock[];\n extractedTables?: string[];\n extractedHeadings?: string[];\n keyExcerpts?: string[];\n tablesCount: number;\n fetchProvider: 'jina' | 'crawl4ai' | 'youtube' | 'direct' | 'custom';\n}\n\nexport interface WebScraperOptions {\n crawl4aiHost?: string;\n jinaKey?: string;\n allowEnvFallback?: boolean;\n customAdapter?: CustomCrawlerAdapter;\n}\n\n/**\n * Extracts top substantive paragraphs from Markdown (stripping navigation, links-only lines, and cookie banners).\n */\nexport function extractSubstantiveExcerpts(markdown: string, maxExcerpts = 6): string[] {\n const withoutCode = markdown.replace(/```[\\s\\S]*?```/g, '\\n');\n const blocks = withoutCode\n .split(/\\n{2,}/)\n .map((b) => b.replace(/\\s+/g, ' ').trim())\n .filter((b) => {\n if (b.length < 60 || b.length > 900) return false;\n if (b.startsWith('#') || b.startsWith('|')) return false;\n const linkRatio = (b.match(/\\[[^\\]]+\\]\\([^)]+\\)/g) || []).join('').length / b.length;\n if (linkRatio > 0.45) return false;\n if (/\\b(cookie policy|privacy policy|all rights reserved|terms of service|sign in|log in|subscribe to our newsletter)\\b/i.test(b)) {\n return false;\n }\n return true;\n });\n\n return blocks.slice(0, maxExcerpts);\n}\n\n/**\n * High-fidelity web content & YouTube transcript extractor with Custom Crawler & Jina Auth support\n */\nexport class WebScraper {\n private crawl4aiHost?: string;\n private jinaKey?: string;\n private allowEnvFallback: boolean;\n private customAdapter?: CustomCrawlerAdapter;\n private youtubeService: YouTubeIngestionService;\n\n constructor(options: WebScraperOptions = {}) {\n this.allowEnvFallback = options.allowEnvFallback ?? true;\n this.crawl4aiHost =\n options.crawl4aiHost || (this.allowEnvFallback ? process.env.CRAWL4AI_HOST : undefined) || 'http://localhost:11235';\n this.jinaKey = options.jinaKey || (this.allowEnvFallback ? process.env.JINA_API_KEY : undefined);\n this.customAdapter = options.customAdapter;\n this.youtubeService = new YouTubeIngestionService();\n }\n\n setCustomAdapter(adapter: CustomCrawlerAdapter) {\n this.customAdapter = adapter;\n }\n\n setJinaKey(key?: string) {\n this.jinaKey = key;\n }\n\n async scrapeUrl(\n targetUrl: string,\n options: { customAdapter?: CustomCrawlerAdapter; jinaKey?: string; preferredLanguages?: string[] } = {}\n ): Promise<ScrapedDocument> {\n const adapter = options.customAdapter || this.customAdapter;\n\n // 0. Custom Crawler Adapter (e.g. MCP bridge, Playwright, Headless Chrome)\n if (adapter) {\n try {\n const result = await adapter.crawl(targetUrl);\n if (result && result.markdownContent) {\n return this.packageDocument(targetUrl, result.markdownContent, 'custom', result.title);\n }\n } catch (e: any) {\n console.warn(`[WebScraper] Custom crawler adapter failed for ${targetUrl}:`, e?.message || e);\n }\n }\n\n // 0.5. YouTube Video URL -> Route to YouTubeIngestionService (Idea §3.1)\n if (isYouTubeUrl(targetUrl)) {\n try {\n const yt = await this.youtubeService.fetchTranscript(targetUrl, options.preferredLanguages);\n if (yt.stitchedMarkdown && yt.stitchedMarkdown.length > 80) {\n return this.packageDocument(yt.url, yt.stitchedMarkdown, 'youtube', yt.title);\n }\n } catch (e: any) {\n console.warn(`[WebScraper] YouTube transcript extraction failed for ${targetUrl}:`, e?.message || e);\n }\n }\n\n // 1. Try Jina Reader API (with optional Bearer auth from host app or env)\n try {\n const jinaUrl = `https://r.jina.ai/${targetUrl}`;\n const jinaKey = options.jinaKey || this.jinaKey;\n const headers: Record<string, string> = {\n 'User-Agent': 'OrchableComposer/1.0',\n 'X-Return-Format': 'markdown',\n };\n if (jinaKey) {\n headers['Authorization'] = `Bearer ${jinaKey}`;\n }\n\n const res = await fetch(jinaUrl, {\n headers,\n signal: AbortSignal.timeout(15000),\n });\n\n if (res.ok) {\n const markdown = await res.text();\n if (markdown && markdown.length > 100) {\n return this.packageDocument(targetUrl, markdown, 'jina');\n }\n }\n } catch (e: any) {\n console.warn(`[WebScraper] Jina Reader failed for ${targetUrl}:`, e?.message || e);\n }\n\n // 2. Try Crawl4AI Local Server if reachable\n if (this.crawl4aiHost) {\n try {\n const res = await fetch(`${this.crawl4aiHost}/crawl`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n urls: targetUrl,\n priority: 10,\n }),\n signal: AbortSignal.timeout(15000),\n });\n\n if (res.ok) {\n const data = await res.json();\n const markdown = data?.results?.[0]?.markdown || data?.markdown;\n if (markdown) {\n return this.packageDocument(targetUrl, markdown, 'crawl4ai');\n }\n }\n } catch {\n // ignore if local crawl4ai is not running\n }\n }\n\n // 3. Fallback: Direct Fetch & Structured HTML-to-Markdown Conversion\n try {\n const res = await fetch(targetUrl, {\n headers: { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)' },\n signal: AbortSignal.timeout(10000),\n });\n if (res.ok) {\n const rawHtml = await res.text();\n const titleTag = rawHtml.match(/<title[^>]*>([\\s\\S]*?)<\\/title>/i)?.[1]?.trim();\n const clean = rawHtml\n .replace(/<script\\b[^<]*(?:(?!<\\/script>)<[^<]*)*<\\/script>/gi, '')\n .replace(/<style\\b[^<]*(?:(?!<\\/style>)<[^<]*)*<\\/style>/gi, '')\n .replace(/<nav\\b[^<]*(?:(?!<\\/nav>)<[^<]*)*<\\/nav>/gi, '')\n .replace(/<footer\\b[^<]*(?:(?!<\\/footer>)<[^<]*)*<\\/footer>/gi, '')\n .replace(/<h([1-3])[^>]*>([\\s\\S]*?)<\\/h\\1>/gi, (_, lvl, txt) => `\\n${'#'.repeat(Number(lvl))} ${txt.replace(/<[^>]+>/g, '').trim()}\\n`)\n .replace(/<pre[^>]*><code[^>]*>([\\s\\S]*?)<\\/code><\\/pre>/gi, (_, code) => `\\n\\`\\`\\`\\n${code.replace(/<[^>]+>/g, '').trim()}\\n\\`\\`\\`\\n`)\n .replace(/<p[^>]*>([\\s\\S]*?)<\\/p>/gi, (_, p) => `\\n${p.replace(/<[^>]+>/g, ' ').trim()}\\n`)\n .replace(/<[^>]+>/g, ' ')\n .replace(/[ \\t]+/g, ' ')\n .replace(/\\n{3,}/g, '\\n\\n')\n .trim();\n\n return this.packageDocument(targetUrl, clean, 'direct', titleTag);\n }\n } catch (e: any) {\n console.warn(`[WebScraper] Direct fetch failed for ${targetUrl}:`, e?.message || e);\n }\n\n throw new Error(`Unable to fetch content from URL: ${targetUrl}`);\n }\n\n private packageDocument(\n url: string,\n markdown: string,\n provider: 'jina' | 'crawl4ai' | 'youtube' | 'direct' | 'custom',\n explicitTitle?: string\n ): ScrapedDocument {\n const titleMatch = markdown.match(/^#\\s+(.+)$/m) || markdown.match(/^Title:\\s*(.+)$/im);\n const title = (explicitTitle || (titleMatch ? titleMatch[1]!.trim() : url.split('/').filter(Boolean).pop() || 'Document')).slice(0, 180);\n\n // Extract code blocks with language tags\n const codeBlockMatches = [...markdown.matchAll(/```([a-zA-Z0-9_+-]*)\\n([\\s\\S]*?)```/g)];\n const extractedCodeBlocks: ExtractedCodeBlock[] = codeBlockMatches\n .map((m) => ({\n language: (m[1] || '').trim().toLowerCase(),\n code: (m[2] || '').trim(),\n }))\n .filter((b) => b.code.length > 0);\n const extractedCodeSnippets = extractedCodeBlocks.map((b) => b.code);\n\n // Extract markdown tables (contiguous pipe lines with separator row)\n const tableBlocks =\n markdown.match(/(?:^\\|.+\\|\\s*\\n)+^\\|[-:| ]+\\|\\s*\\n(?:^\\|.+\\|\\s*\\n?)+/gm) ||\n markdown.match(/\\|[\\s\\S]*?\\|[\\s\\S]*?\\|/g) ||\n [];\n const extractedTables = tableBlocks.map((t) => t.trim()).filter((t) => t.length > 15);\n\n // Extract section headings\n const extractedHeadings = [...markdown.matchAll(/^#{1,3}\\s+(.+)$/gm)]\n .map((m) => m[1]!.trim())\n .filter((h) => h.length > 2 && h.length < 120);\n\n const keyExcerpts = extractSubstantiveExcerpts(markdown, 6);\n\n return {\n url,\n title,\n markdownContent: markdown,\n byteSize: Buffer.byteLength(markdown, 'utf-8'),\n extractedCodeSnippets,\n extractedCodeBlocks,\n extractedTables,\n extractedHeadings,\n keyExcerpts,\n tablesCount: extractedTables.length,\n fetchProvider: provider,\n };\n }\n}\n","import { ScrapedDocument, extractSubstantiveExcerpts } from '../harvester/webScraper';\nimport { TechnicalDomain } from '../harvester/domainClassifier';\nimport { CourseResearchContext, LlmTextFn } from '../config/researchConfig';\n\nexport interface ScoredEvidence {\n doc: ScrapedDocument;\n score: number; // 1 to 10\n isApproved: boolean; // >= 6 is approved\n isLlmEvaluated?: boolean;\n breakdown: {\n technicalDepth?: number; // legacy alias for backwards compatibility\n structuralRichness: number; // 1-10: format hygiene, byte size, headings, tables\n codeSnippetQuality: number; // 1-10\n noiseFactor: number; // 1-10 (lower is better)\n pedagogicalRelevance?: number; // 1-10 (when evaluated by LLM)\n };\n summary: string;\n keyTakeaways: string[];\n}\n\nfunction tokenizeBilingualKeywords(text: string): string[] {\n return text\n .normalize('NFC')\n .toLowerCase()\n .replace(/[.,;:!?()[\\]{}\"“”‘’/\\\\|`*_~#-]+/g, ' ')\n .split(/\\s+/)\n .filter((w) => w.length >= 2 && !/^(and|the|for|with|from|into|của|trong|được|những|các|cho|với|khi|và|hoặc|để|từ|đến|về)$/.test(w));\n}\n\n/**\n * Extracts top key sentences from a document ranked by keyword overlap and structural salience (TextRank-inspired).\n */\nexport function extractTopSentences(markdown: string, targetTopic: string, maxSentences = 3): string[] {\n const keywords = tokenizeBilingualKeywords(targetTopic);\n const withoutCode = markdown.replace(/```[\\s\\S]*?```/g, ' ');\n const rawSentences = withoutCode\n .split(/(?<=[.!?。\\n])\\s+/)\n .map((s) => s.replace(/^[-*•#>\\s]+/, '').replace(/\\s+/g, ' ').trim())\n .filter((s) => {\n if (s.length < 45 || s.length > 320) return false;\n if (s.startsWith('|') || s.startsWith('http')) return false;\n if (/\\b(cookie|privacy policy|sign in|subscribe|all rights reserved)\\b/i.test(s)) return false;\n return true;\n });\n\n if (rawSentences.length === 0) return [];\n\n const scored = rawSentences.map((sentence, idx) => {\n const lower = sentence.normalize('NFC').toLowerCase();\n const matchedCount = keywords.filter((k) => lower.includes(k)).length;\n const positionBonus = idx < 8 ? 1.5 : idx < 20 ? 0.5 : 0;\n const technicalBonus = /(`[^`]+`|\\b(?:api|function|class|actor|async|sensor|pin|loop|state|biến|hàm|cảm biến|vòng lặp|mạch)\\b)/i.test(\n sentence\n )\n ? 1.5\n : 0;\n return {\n sentence,\n idx,\n score: matchedCount * 2 + positionBonus + technicalBonus,\n };\n });\n\n return scored\n .sort((a, b) => b.score - a.score || a.idx - b.idx)\n .slice(0, maxSentences)\n .sort((a, b) => a.idx - b.idx)\n .map((s) => s.sentence);\n}\n\n/**\n * Evaluates and scores evidence on a 1-10 scale and extracts real substantive takeaways\n */\nexport class EvidenceScorer {\n scoreDocument(doc: ScrapedDocument, domain: TechnicalDomain, targetTopic: string): ScoredEvidence {\n let depthScore = 5;\n const hasCode = doc.extractedCodeSnippets.length > 0;\n let codeScore = hasCode ? Math.min(10, 7 + Math.min(3, doc.extractedCodeSnippets.length)) : 5;\n let noiseScore = 2;\n\n const lowerContent = doc.markdownContent.normalize('NFC').toLowerCase();\n const targetKeywords = tokenizeBilingualKeywords(targetTopic);\n const keywordMatches = targetKeywords.filter((k) => lowerContent.includes(k)).length;\n const matchRatio = targetKeywords.length > 0 ? keywordMatches / targetKeywords.length : 1;\n\n if (matchRatio >= 0.75) depthScore += 3;\n else if (matchRatio >= 0.4) depthScore += 2;\n else if (keywordMatches >= 1) depthScore += 1;\n\n if (doc.tablesCount > 0) depthScore += 1;\n if (doc.byteSize > 1500) depthScore += 1;\n if ((doc.extractedHeadings?.length || 0) >= 2) depthScore += 1;\n depthScore = Math.min(10, depthScore);\n\n // Conceptual, academic, or official overview pages without code fences shouldn't be rejected if rich in structure\n if (!hasCode && doc.byteSize > 1200 && matchRatio >= 0.5) {\n codeScore = 6;\n }\n\n if (lowerContent.includes('subscribe') && lowerContent.includes('advertisement')) {\n noiseScore += 3;\n }\n\n const rawTotal = depthScore * 0.55 + codeScore * 0.35 - noiseScore * 0.1 + 0.5;\n const score = Math.max(1, Math.min(10, Math.round(rawTotal)));\n const isApproved = score >= 6;\n\n const topSentences = extractTopSentences(doc.markdownContent, targetTopic, 3);\n const excerpts = doc.keyExcerpts?.length ? doc.keyExcerpts : extractSubstantiveExcerpts(doc.markdownContent, 3);\n const keyTakeaways = topSentences.length > 0 ? topSentences : excerpts.slice(0, 2);\n\n const summary =\n keyTakeaways.length > 0\n ? `${keyTakeaways[0]} [Evidence ${score}/10 · ${doc.extractedCodeSnippets.length} code blocks · ${doc.tablesCount} tables]`\n : `Evidence scored ${score}/10 (${isApproved ? 'APPROVED' : 'REJECTED'}) for ${domain} (${doc.byteSize} bytes).`;\n\n return {\n doc,\n score,\n isApproved,\n isLlmEvaluated: false,\n breakdown: {\n technicalDepth: depthScore,\n structuralRichness: depthScore,\n codeSnippetQuality: codeScore,\n noiseFactor: noiseScore,\n },\n summary,\n keyTakeaways,\n };\n }\n\n /**\n * Evaluates evidence with host LLM for genuine pedagogical relevance, conceptual depth,\n * and accuracy for the target learner age band.\n */\n async scoreDocumentWithLlm(\n doc: ScrapedDocument,\n domain: TechnicalDomain,\n targetTopic: string,\n options: { llm?: LlmTextFn; context?: CourseResearchContext } = {}\n ): Promise<ScoredEvidence> {\n const baseline = this.scoreDocument(doc, domain, targetTopic);\n if (!options.llm) {\n return baseline;\n }\n\n try {\n const prompt = [\n `You are a Senior Curriculum Researcher. Evaluate this harvested web document for the course topic \"${targetTopic}\" (Domain: ${domain}).`,\n options.context?.ageBand ? `Target Learner Age Band: ${options.context.ageBand[0]}-${options.context.ageBand[1]}` : '',\n options.context?.hardwarePlatform ? `Hardware Platform: ${options.context.hardwarePlatform}` : '',\n options.context?.softwareEnv ? `Software / Tools: ${options.context.softwareEnv}` : '',\n `\\nDocument Title: ${doc.title}`,\n `Document URL: ${doc.url}`,\n `Sample Excerpts:\\n${(doc.keyExcerpts || []).slice(0, 3).join('\\n')}`,\n `Code Blocks Found: ${doc.extractedCodeSnippets.length}`,\n `\\nReturn ONLY a JSON object:`,\n `{\"score\": 8, \"isApproved\": true, \"pedagogicalRelevance\": 9, \"summary\": \"1-sentence evaluative summary\", \"keyTakeaways\": [\"Takeaway 1 grounded in text\", \"Takeaway 2\"]}`,\n ]\n .filter(Boolean)\n .join('\\n');\n\n const raw = await options.llm(prompt, {\n system: 'You are an educational curriculum auditor. Output strictly valid JSON.',\n temperature: 0.2,\n jsonMode: true,\n });\n\n const match = raw.match(/\\{[\\s\\S]*\\}/);\n if (match) {\n const parsed = JSON.parse(match[0]);\n const score = Math.max(1, Math.min(10, Number(parsed.score) || baseline.score));\n return {\n doc,\n score,\n isApproved: score >= 6,\n isLlmEvaluated: true,\n breakdown: {\n ...baseline.breakdown,\n pedagogicalRelevance: Number(parsed.pedagogicalRelevance) || score,\n },\n summary: String(parsed.summary || baseline.summary),\n keyTakeaways: Array.isArray(parsed.keyTakeaways) && parsed.keyTakeaways.length > 0\n ? parsed.keyTakeaways.map(String)\n : baseline.keyTakeaways,\n };\n }\n } catch (e: any) {\n console.warn('[EvidenceScorer] LLM evidence evaluation failed, using structural baseline:', e?.message || e);\n }\n\n return baseline;\n }\n}\n","import { LlmTextFn } from '../config/researchConfig';\n\nexport type ClaimVerdict = 'supported' | 'refuted' | 'not_enough_evidence' | 'lexical_match_only';\n\nexport interface VerifiedClaim {\n claimText: string;\n sourceUrl?: string;\n verdict: ClaimVerdict;\n isSupported: boolean;\n isLlmVerified: boolean;\n confidenceScore: number;\n extractedQuote?: string;\n explanation?: string;\n}\n\nexport interface ClaimSweepReport {\n totalClaimsChecked: number;\n supportedClaimsCount: number;\n refutedClaimsCount: number;\n unverifiedClaimsCount: number;\n hallucinationRisk: 'low' | 'medium' | 'high';\n isLlmVerified: boolean;\n claims: VerifiedClaim[];\n reportMd: string;\n}\n\n/**\n * Non-semantic grammatical fillers ONLY.\n * NEVER include negation words ('không', 'chưa', 'not', 'never') or causal markers ('khi', 'nếu', 'thì', 'if', 'then')\n * because stripping them inverts semantic polarity and destroys conditional assertions.\n */\nconst CLAIM_STOPWORDS = new Set([\n 'the', 'and', 'for', 'with', 'that', 'this', 'from', 'into', 'are', 'was', 'were', 'have', 'has',\n 'will', 'would', 'through', 'their', 'these', 'those', 'which', 'while',\n 'của', 'trong', 'được', 'những', 'các', 'cho', 'với', 'và', 'hoặc', 'để',\n 'từ', 'đến', 'về', 'này', 'đó', 'một', 'như', 'sẽ', 'đang', 'đã', 'ra', 'vào', 'là',\n]);\n\nfunction extractSignificantTokens(text: string): string[] {\n return text\n .normalize('NFC')\n .toLowerCase()\n .replace(/[.,;:!?()[\\]{}\"“”‘’/\\\\|`*_~#-]+/g, ' ')\n .split(/\\s+/)\n .filter((w) => w.length >= 3 && !CLAIM_STOPWORDS.has(w));\n}\n\nfunction tokenMatchesCorpus(token: string, lowerCorpus: string): boolean {\n if (lowerCorpus.includes(token)) return true;\n // Basic morphological stem check (e.g., eliminate -> eliminat, isolation -> isolat, races -> race)\n if (token.length >= 6) {\n const stem = token.replace(/(?:ing|tion|ions|ment|ments|ed|es|s)$/, '');\n if (stem.length >= 4 && lowerCorpus.includes(stem)) return true;\n }\n return false;\n}\n\n/**\n * Claim-Support Sweep & Fact Checker\n * Combines Deterministic Passage Retrieval (Passage Candidate Slicing)\n * with LLM Semantic Entailment (Natural Language Inference).\n */\nexport class ClaimVerifier {\n /**\n * Deterministic lexical match baseline.\n * Explicitly marks verdict as 'lexical_match_only' to prevent false sense of semantic verification.\n */\n verifyClaimsDeterministic(claims: string[], sourceCorpus: string): ClaimSweepReport {\n const verifiedList: VerifiedClaim[] = [];\n const normCorpus = sourceCorpus.normalize('NFC');\n const lowerCorpus = normCorpus.toLowerCase();\n const corpusSentences = normCorpus\n .split(/(?<=[.!?。\\n])\\s+/)\n .map((s) => s.replace(/^[-*•#>\\s]+/, '').replace(/\\s+/g, ' ').trim())\n .filter((s) => {\n if (s.length < 25) return false;\n if (/^(title:|url source:|final url:|http|!\\[)/i.test(s)) return false;\n return true;\n });\n\n for (const claim of claims) {\n const claimTokens = extractSignificantTokens(claim);\n const matchCount = claimTokens.filter((t) => tokenMatchesCorpus(t, lowerCorpus)).length;\n const matchRatio = claimTokens.length > 0 ? matchCount / claimTokens.length : 0;\n\n // Find best candidate supporting quote from corpus sentences via lexical overlap\n let bestQuote: string | undefined;\n let bestSentenceRatio = 0;\n for (const sent of corpusSentences) {\n const lowerSent = sent.toLowerCase();\n const sentMatches = claimTokens.filter((t) => tokenMatchesCorpus(t, lowerSent)).length;\n const sentRatio = claimTokens.length > 0 ? sentMatches / claimTokens.length : 0;\n if (sentRatio > bestSentenceRatio) {\n bestSentenceRatio = sentRatio;\n bestQuote = sent.slice(0, 240);\n }\n }\n\n const effectiveRatio = Math.max(matchRatio, bestSentenceRatio);\n const hasLexicalEvidence = effectiveRatio >= 0.55;\n\n verifiedList.push({\n claimText: claim,\n verdict: 'lexical_match_only',\n isSupported: hasLexicalEvidence,\n isLlmVerified: false,\n confidenceScore: Math.round(effectiveRatio * 100),\n extractedQuote: hasLexicalEvidence ? bestQuote : undefined,\n explanation: hasLexicalEvidence\n ? `Lexical token match found (${Math.round(effectiveRatio * 100)}% token overlap). Semantic entailment requires LLM verification.`\n : `Insufficient lexical overlap in harvest corpus (${Math.round(effectiveRatio * 100)}%).`,\n });\n }\n\n const supportedCount = verifiedList.filter((c) => c.isSupported).length;\n const supportPct = claims.length > 0 ? (supportedCount / claims.length) * 100 : 100;\n const hallucinationRisk = supportPct >= 80 ? 'low' : supportPct >= 50 ? 'medium' : 'high';\n\n const mdLines = [\n `# 🔍 Claim-Support Sweep & Verification Report (Lexical Scan Mode)`,\n `> **Notice:** *Scored via deterministic lexical token matching. True semantic entailment requires an LLM call.*`,\n `> **Lexical Coverage:** \\`${supportPct.toFixed(1)}%\\` (${supportedCount}/${claims.length} claims with token matches) | **Hallucination Risk (Lexical):** \\`${hallucinationRisk.toUpperCase()}\\``,\n `\\n| Pedagogical / Technical Claim | Evidence Status | Token Match | Supporting Quote | Semantic Status |`,\n `|---|---|---|---|---|`,\n ...verifiedList.map(\n (c) =>\n `| ${c.claimText.replace(/\\|/g, '/')} | ${c.isSupported ? '🟡 **LEXICAL MATCH**' : '⚠️ *UNVERIFIED / GAP*'} | \\`${c.confidenceScore}%\\` | ${(c.extractedQuote || '—').replace(/\\|/g, '/')} | *Awaiting LLM Entailment* |`\n ),\n ];\n\n return {\n totalClaimsChecked: claims.length,\n supportedClaimsCount: supportedCount,\n refutedClaimsCount: 0,\n unverifiedClaimsCount: claims.length - supportedCount,\n hallucinationRisk,\n isLlmVerified: false,\n claims: verifiedList,\n reportMd: mdLines.join('\\n'),\n };\n }\n\n /**\n * Primary verification interface.\n * If an LLM callback is provided, performs genuine Semantic Entailment (NLI).\n * Otherwise falls back to deterministic lexical retrieval with honest labeling.\n */\n async verifyClaims(\n claims: string[],\n sourceCorpus: string,\n options: { llm?: LlmTextFn } = {}\n ): Promise<ClaimSweepReport> {\n const detReport = this.verifyClaimsDeterministic(claims, sourceCorpus);\n if (!options.llm || claims.length === 0) {\n return detReport;\n }\n\n try {\n const normCorpus = sourceCorpus.normalize('NFC');\n const cleanSubstantiveText = normCorpus\n .replace(/```[\\s\\S]*?```/g, '\\n')\n .split('\\n')\n .filter((l) => !/^(title:|url source:|final url:|http|!\\[|#)/i.test(l.trim()))\n .join('\\n')\n .trim();\n\n const corpusSentences = cleanSubstantiveText\n .split(/(?<=[.!?。\\n])\\s+/)\n .map((s) => s.replace(/^[-*•#>\\s]+/, '').replace(/\\s+/g, ' ').trim())\n .filter((s) => s.length >= 25 && !/^(cookie|privacy|sign in|all rights reserved)/i.test(s));\n\n // Collect candidate passages for each claim.\n // If cross-lingual (e.g. Vietnamese claim vs English corpus), lexical overlap alone might miss translated synonyms,\n // so we include top lexical matches AND the first substantive paragraphs of the reference document.\n const fallbackExcerpts = corpusSentences.slice(0, 8).join('\\n');\n\n const claimContexts = claims.map((claim, idx) => {\n const tokens = extractSignificantTokens(claim);\n const topSentences = corpusSentences\n .map((sent) => ({\n sent,\n overlap: tokens.filter((t) => tokenMatchesCorpus(t, sent.toLowerCase())).length,\n }))\n .filter((item) => item.overlap > 0)\n .sort((a, b) => b.overlap - a.overlap)\n .slice(0, 5)\n .map((item) => item.sent);\n\n const candidates = topSentences.length > 0\n ? `${topSentences.join('\\n')}\\n\\n[General Reference Excerpts]:\\n${fallbackExcerpts}`\n : fallbackExcerpts || 'No substantive text found.';\n\n return {\n idx,\n claim,\n candidatePassages: candidates,\n };\n });\n\n const prompt = [\n `You are a Rigorous Scientific & Pedagogical Fact-Checking System (Natural Language Inference).`,\n `Evaluate whether each technical/pedagogical claim is strictly SUPPORTED, directly REFUTED, or has NOT_ENOUGH_EVIDENCE in the harvested technical reference text.`,\n `Pay careful attention to NEGATION words (\"không\", \"never\", \"tránh\", \"do not\"), causal relationships, hardware pin constraints, and edge cases. Do not assume truth without textual evidence.`,\n `\\nHarvested Reference Excerpts for Claims:\\n`,\n claimContexts.map((c) => `[Claim ${c.idx + 1}]: \"${c.claim}\"\\n[Passage Candidates]: ${c.candidatePassages}`).join('\\n\\n'),\n `\\nReturn ONLY a valid JSON array of objects with the exact structure:`,\n `[{\"claimIndex\": 1, \"verdict\": \"supported\"|\"refuted\"|\"not_enough_evidence\", \"confidenceScore\": 95, \"extractedQuote\": \"exact quote from passage\", \"explanation\": \"1-sentence semantic reason\"}]`,\n ].join('\\n');\n\n const raw = await options.llm(prompt, {\n system: 'You are an exacting academic fact-checker. Output strictly valid JSON array without commentary.',\n temperature: 0.1,\n jsonMode: true,\n });\n\n let parsed: any[] = [];\n const arrayMatch = raw.match(/\\[[\\s\\S]*\\]/);\n if (arrayMatch) {\n try {\n const res = JSON.parse(arrayMatch[0]);\n if (Array.isArray(res)) parsed = res;\n } catch {}\n }\n if (parsed.length === 0) {\n const objMatch = raw.match(/\\{[\\s\\S]*\\}/);\n if (objMatch) {\n try {\n const obj = JSON.parse(objMatch[0]);\n const candidateList = obj.claims || obj.results || obj.verifications || Object.values(obj).find(Array.isArray);\n if (Array.isArray(candidateList)) parsed = candidateList;\n } catch {}\n }\n }\n\n if (parsed.length > 0) {\n const verifiedList: VerifiedClaim[] = claims.map((claim, idx) => {\n const item = parsed.find((p: any) => p.claimIndex === idx + 1) || parsed[idx];\n const verdict: ClaimVerdict =\n item && ['supported', 'refuted', 'not_enough_evidence'].includes(item.verdict)\n ? item.verdict\n : detReport.claims[idx]?.isSupported\n ? 'supported'\n : 'not_enough_evidence';\n\n const isSupported = verdict === 'supported';\n return {\n claimText: claim,\n verdict,\n isSupported,\n isLlmVerified: true,\n confidenceScore: Number(item?.confidenceScore) || (isSupported ? 90 : 30),\n extractedQuote: item?.extractedQuote || detReport.claims[idx]?.extractedQuote,\n explanation: item?.explanation || (isSupported ? 'Semantically entailed by reference corpus.' : 'Not verified.'),\n };\n });\n\n const supportedCount = verifiedList.filter((c) => c.verdict === 'supported').length;\n const refutedCount = verifiedList.filter((c) => c.verdict === 'refuted').length;\n const unverifiedCount = claims.length - supportedCount;\n const supportPct = claims.length > 0 ? (supportedCount / claims.length) * 100 : 100;\n const hallucinationRisk = refutedCount > 0 ? 'high' : supportPct >= 75 ? 'low' : 'medium';\n\n const mdLines = [\n `# 🔍 Claim-Support Sweep & Semantic Verification Report (LLM NLI Evaluated)`,\n `> **Semantic Verification Rate:** \\`${supportPct.toFixed(1)}%\\` (${supportedCount}/${claims.length} claims supported) | **Refuted / Contradictions:** \\`${refutedCount}\\` | **Hallucination Risk:** \\`${hallucinationRisk.toUpperCase()}\\``,\n `\\n| Pedagogical / Technical Claim | Semantic Verdict | Confidence | Supporting Quote / Evidence | Explanation |`,\n `|---|---|---|---|---|`,\n ...verifiedList.map(\n (c) =>\n `| ${c.claimText.replace(/\\|/g, '/')} | ${\n c.verdict === 'supported'\n ? '✅ **SUPPORTED**'\n : c.verdict === 'refuted'\n ? '❌ **REFUTED**'\n : '⚠️ *NOT ENOUGH EVIDENCE*'\n } | \\`${c.confidenceScore}%\\` | ${(c.extractedQuote || '—').replace(/\\|/g, '/')} | ${(c.explanation || '').replace(/\\|/g, '/')} |`\n ),\n ];\n\n return {\n totalClaimsChecked: claims.length,\n supportedClaimsCount: supportedCount,\n refutedClaimsCount: refutedCount,\n unverifiedClaimsCount: unverifiedCount,\n hallucinationRisk,\n isLlmVerified: true,\n claims: verifiedList,\n reportMd: mdLines.join('\\n'),\n };\n }\n } catch (e: any) {\n console.warn('[ClaimVerifier] LLM semantic verification failed, falling back to deterministic lexical report:', e?.message || e);\n }\n\n return detReport;\n }\n}\n","export interface ProvenanceRecord {\n resourceId: string;\n sourceUrl: string;\n accessedAt: string;\n domain: string;\n relevanceScore: number;\n byteSize: number;\n}\n\nexport interface ProvenanceSidecar {\n topic: string;\n campaignId: string;\n generatedAt: string;\n totalRecords: number;\n records: ProvenanceRecord[];\n provenanceMd: string;\n}\n\n/**\n * Generates the mandatory *.provenance.md sidecar document (English Canonical)\n */\nexport class ProvenanceTracker {\n generateSidecar(topic: string, records: ProvenanceRecord[]): ProvenanceSidecar {\n const campaignId = `CAMP-${Math.random().toString(36).substring(2, 9).toUpperCase()}`;\n const generatedAt = new Date().toISOString();\n\n const mdLines = [\n `# 📜 Provenance & Audit Trail: ${topic}`,\n `> **Campaign ID:** \\`${campaignId}\\` | **Generated At:** \\`${generatedAt}\\` | **Total Verified Sources:** \\`${records.length}\\``,\n `\\n## Audit Trail Table`,\n `| Resource ID | Domain | Relevancy | Size (Bytes) | Source URL | Timestamp |`,\n `|---|---|---|---|---|---|`,\n ...records.map(r => `| **${r.resourceId}** | \\`${r.domain}\\` | ⭐ \\`${r.relevanceScore}/10\\` | \\`${r.byteSize}\\` | [Access Source](${r.sourceUrl}) | \\`${r.accessedAt.slice(0, 19)}\\` |`),\n `\\n## Integrity Guarantee`,\n `- Every pedagogical claim and technical snippet in the curriculum maps 1-to-1 to the physical sources listed above.`,\n `- Unverified citations or hallucinated sources are strictly prohibited under Curriculum OS Rule §5.`\n ];\n\n return {\n topic,\n campaignId,\n generatedAt,\n totalRecords: records.length,\n records,\n provenanceMd: mdLines.join('\\n'),\n };\n }\n}\n"]}