mcp-web-validator 1.3.51 → 1.3.53

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 (172) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +64 -4
  3. package/dist/audit-history.d.ts +9 -0
  4. package/dist/audit-history.js +27 -0
  5. package/dist/audit-history.js.map +1 -1
  6. package/dist/index.js +2508 -2
  7. package/dist/index.js.map +1 -1
  8. package/dist/modules/browser-ux/lighthouse-lab-probe.d.ts +21 -0
  9. package/dist/modules/browser-ux/lighthouse-lab-probe.js +190 -0
  10. package/dist/modules/browser-ux/lighthouse-lab-probe.js.map +1 -0
  11. package/dist/modules/browser-ux/lighthouse-lab.d.ts +61 -0
  12. package/dist/modules/browser-ux/lighthouse-lab.js +98 -0
  13. package/dist/modules/browser-ux/lighthouse-lab.js.map +1 -0
  14. package/dist/modules/browser-ux/media-diagnostics.d.ts +41 -0
  15. package/dist/modules/browser-ux/media-diagnostics.js +183 -0
  16. package/dist/modules/browser-ux/media-diagnostics.js.map +1 -0
  17. package/dist/modules/browser-ux/raw-rendered-diff.d.ts +70 -0
  18. package/dist/modules/browser-ux/raw-rendered-diff.js +262 -0
  19. package/dist/modules/browser-ux/raw-rendered-diff.js.map +1 -0
  20. package/dist/modules/browser-ux/raw-rendered-probe.d.ts +17 -0
  21. package/dist/modules/browser-ux/raw-rendered-probe.js +163 -0
  22. package/dist/modules/browser-ux/raw-rendered-probe.js.map +1 -0
  23. package/dist/modules/browser-ux/resource-failures-probe.d.ts +11 -0
  24. package/dist/modules/browser-ux/resource-failures-probe.js +231 -0
  25. package/dist/modules/browser-ux/resource-failures-probe.js.map +1 -0
  26. package/dist/modules/browser-ux/resource-failures.d.ts +79 -0
  27. package/dist/modules/browser-ux/resource-failures.js +178 -0
  28. package/dist/modules/browser-ux/resource-failures.js.map +1 -0
  29. package/dist/modules/browser-ux/viewport-parity-probe.d.ts +5 -0
  30. package/dist/modules/browser-ux/viewport-parity-probe.js +307 -0
  31. package/dist/modules/browser-ux/viewport-parity-probe.js.map +1 -0
  32. package/dist/modules/browser-ux/viewport-parity.d.ts +112 -0
  33. package/dist/modules/browser-ux/viewport-parity.js +224 -0
  34. package/dist/modules/browser-ux/viewport-parity.js.map +1 -0
  35. package/dist/modules/browser-ux/wcag-interactions.d.ts +95 -0
  36. package/dist/modules/browser-ux/wcag-interactions.js +360 -0
  37. package/dist/modules/browser-ux/wcag-interactions.js.map +1 -0
  38. package/dist/modules/change-regression/availability-history-store.d.ts +18 -0
  39. package/dist/modules/change-regression/availability-history-store.js +168 -0
  40. package/dist/modules/change-regression/availability-history-store.js.map +1 -0
  41. package/dist/modules/change-regression/crawler-log-correlation.d.ts +111 -0
  42. package/dist/modules/change-regression/crawler-log-correlation.js +374 -0
  43. package/dist/modules/change-regression/crawler-log-correlation.js.map +1 -0
  44. package/dist/modules/change-regression/google-common-crawler-ip.d.ts +15 -0
  45. package/dist/modules/change-regression/google-common-crawler-ip.js +129 -0
  46. package/dist/modules/change-regression/google-common-crawler-ip.js.map +1 -0
  47. package/dist/modules/change-regression/historical-comparisons.d.ts +120 -0
  48. package/dist/modules/change-regression/historical-comparisons.js +330 -0
  49. package/dist/modules/change-regression/historical-comparisons.js.map +1 -0
  50. package/dist/modules/change-regression/production-change-comparison.d.ts +68 -0
  51. package/dist/modules/change-regression/production-change-comparison.js +214 -0
  52. package/dist/modules/change-regression/production-change-comparison.js.map +1 -0
  53. package/dist/modules/change-regression/regression-alerts.d.ts +73 -0
  54. package/dist/modules/change-regression/regression-alerts.js +183 -0
  55. package/dist/modules/change-regression/regression-alerts.js.map +1 -0
  56. package/dist/modules/change-regression/strict-observation-time.d.ts +7 -0
  57. package/dist/modules/change-regression/strict-observation-time.js +31 -0
  58. package/dist/modules/change-regression/strict-observation-time.js.map +1 -0
  59. package/dist/modules/content-schema/citation-methodology-consistency.d.ts +108 -0
  60. package/dist/modules/content-schema/citation-methodology-consistency.js +360 -0
  61. package/dist/modules/content-schema/citation-methodology-consistency.js.map +1 -0
  62. package/dist/modules/content-schema/competitor-intent-comparison.d.ts +74 -0
  63. package/dist/modules/content-schema/competitor-intent-comparison.js +185 -0
  64. package/dist/modules/content-schema/competitor-intent-comparison.js.map +1 -0
  65. package/dist/modules/content-schema/empty-boilerplate-content.d.ts +36 -0
  66. package/dist/modules/content-schema/empty-boilerplate-content.js +225 -0
  67. package/dist/modules/content-schema/empty-boilerplate-content.js.map +1 -0
  68. package/dist/modules/content-schema/extract-citation-methodology.d.ts +6 -0
  69. package/dist/modules/content-schema/extract-citation-methodology.js +201 -0
  70. package/dist/modules/content-schema/extract-citation-methodology.js.map +1 -0
  71. package/dist/modules/content-schema/extract-competitor-intent.d.ts +2 -0
  72. package/dist/modules/content-schema/extract-competitor-intent.js +140 -0
  73. package/dist/modules/content-schema/extract-competitor-intent.js.map +1 -0
  74. package/dist/modules/content-schema/extract-main-content.d.ts +6 -0
  75. package/dist/modules/content-schema/extract-main-content.js +33 -0
  76. package/dist/modules/content-schema/extract-main-content.js.map +1 -0
  77. package/dist/modules/content-schema/extract-metadata-consistency.d.ts +3 -0
  78. package/dist/modules/content-schema/extract-metadata-consistency.js +62 -0
  79. package/dist/modules/content-schema/extract-metadata-consistency.js.map +1 -0
  80. package/dist/modules/content-schema/extract-product-claims.d.ts +3 -0
  81. package/dist/modules/content-schema/extract-product-claims.js +58 -0
  82. package/dist/modules/content-schema/extract-product-claims.js.map +1 -0
  83. package/dist/modules/content-schema/extract-structured-data.d.ts +3 -0
  84. package/dist/modules/content-schema/extract-structured-data.js +25 -0
  85. package/dist/modules/content-schema/extract-structured-data.js.map +1 -0
  86. package/dist/modules/content-schema/metadata-consistency.d.ts +66 -0
  87. package/dist/modules/content-schema/metadata-consistency.js +282 -0
  88. package/dist/modules/content-schema/metadata-consistency.js.map +1 -0
  89. package/dist/modules/content-schema/product-claims.d.ts +73 -0
  90. package/dist/modules/content-schema/product-claims.js +195 -0
  91. package/dist/modules/content-schema/product-claims.js.map +1 -0
  92. package/dist/modules/content-schema/same-language-duplicates.d.ts +52 -0
  93. package/dist/modules/content-schema/same-language-duplicates.js +158 -0
  94. package/dist/modules/content-schema/same-language-duplicates.js.map +1 -0
  95. package/dist/modules/content-schema/structured-data-validation.d.ts +37 -0
  96. package/dist/modules/content-schema/structured-data-validation.js +385 -0
  97. package/dist/modules/content-schema/structured-data-validation.js.map +1 -0
  98. package/dist/modules/external-metrics/crux-field-probe.d.ts +10 -0
  99. package/dist/modules/external-metrics/crux-field-probe.js +113 -0
  100. package/dist/modules/external-metrics/crux-field-probe.js.map +1 -0
  101. package/dist/modules/external-metrics/crux-field.d.ts +61 -0
  102. package/dist/modules/external-metrics/crux-field.js +231 -0
  103. package/dist/modules/external-metrics/crux-field.js.map +1 -0
  104. package/dist/modules/http-crawl/availability-observations.d.ts +68 -0
  105. package/dist/modules/http-crawl/availability-observations.js +206 -0
  106. package/dist/modules/http-crawl/availability-observations.js.map +1 -0
  107. package/dist/modules/http-crawl/availability-probe.d.ts +8 -0
  108. package/dist/modules/http-crawl/availability-probe.js +46 -0
  109. package/dist/modules/http-crawl/availability-probe.js.map +1 -0
  110. package/dist/modules/http-crawl/crawler-access-probe.d.ts +6 -0
  111. package/dist/modules/http-crawl/crawler-access-probe.js +79 -0
  112. package/dist/modules/http-crawl/crawler-access-probe.js.map +1 -0
  113. package/dist/modules/http-crawl/crawler-access.d.ts +75 -0
  114. package/dist/modules/http-crawl/crawler-access.js +404 -0
  115. package/dist/modules/http-crawl/crawler-access.js.map +1 -0
  116. package/dist/modules/http-crawl/http-delivery-probe.d.ts +3 -0
  117. package/dist/modules/http-crawl/http-delivery-probe.js +44 -0
  118. package/dist/modules/http-crawl/http-delivery-probe.js.map +1 -0
  119. package/dist/modules/http-crawl/http-delivery.d.ts +64 -0
  120. package/dist/modules/http-crawl/http-delivery.js +269 -0
  121. package/dist/modules/http-crawl/http-delivery.js.map +1 -0
  122. package/dist/modules/http-crawl/https-security.d.ts +84 -0
  123. package/dist/modules/http-crawl/https-security.js +441 -0
  124. package/dist/modules/http-crawl/https-security.js.map +1 -0
  125. package/dist/modules/http-crawl/non-html-directives.d.ts +74 -0
  126. package/dist/modules/http-crawl/non-html-directives.js +353 -0
  127. package/dist/modules/http-crawl/non-html-directives.js.map +1 -0
  128. package/dist/modules/http-crawl/redirect-canonical-chains.d.ts +80 -0
  129. package/dist/modules/http-crawl/redirect-canonical-chains.js +459 -0
  130. package/dist/modules/http-crawl/redirect-canonical-chains.js.map +1 -0
  131. package/dist/modules/http-crawl/redirect-canonical-probe.d.ts +6 -0
  132. package/dist/modules/http-crawl/redirect-canonical-probe.js +83 -0
  133. package/dist/modules/http-crawl/redirect-canonical-probe.js.map +1 -0
  134. package/dist/modules/http-crawl/sitemap-inventory-probe.d.ts +8 -0
  135. package/dist/modules/http-crawl/sitemap-inventory-probe.js +155 -0
  136. package/dist/modules/http-crawl/sitemap-inventory-probe.js.map +1 -0
  137. package/dist/modules/http-crawl/sitemap-inventory.d.ts +107 -0
  138. package/dist/modules/http-crawl/sitemap-inventory.js +557 -0
  139. package/dist/modules/http-crawl/sitemap-inventory.js.map +1 -0
  140. package/dist/modules/http-crawl/url-variants.d.ts +86 -0
  141. package/dist/modules/http-crawl/url-variants.js +379 -0
  142. package/dist/modules/http-crawl/url-variants.js.map +1 -0
  143. package/dist/modules/site-architecture/extract-internal-links.d.ts +3 -0
  144. package/dist/modules/site-architecture/extract-internal-links.js +88 -0
  145. package/dist/modules/site-architecture/extract-internal-links.js.map +1 -0
  146. package/dist/modules/site-architecture/extract-multilingual-page.d.ts +2 -0
  147. package/dist/modules/site-architecture/extract-multilingual-page.js +29 -0
  148. package/dist/modules/site-architecture/extract-multilingual-page.js.map +1 -0
  149. package/dist/modules/site-architecture/internal-link-graph-probe.d.ts +7 -0
  150. package/dist/modules/site-architecture/internal-link-graph-probe.js +116 -0
  151. package/dist/modules/site-architecture/internal-link-graph-probe.js.map +1 -0
  152. package/dist/modules/site-architecture/internal-link-graph.d.ts +113 -0
  153. package/dist/modules/site-architecture/internal-link-graph.js +414 -0
  154. package/dist/modules/site-architecture/internal-link-graph.js.map +1 -0
  155. package/dist/modules/site-architecture/internal-link-quality.d.ts +77 -0
  156. package/dist/modules/site-architecture/internal-link-quality.js +260 -0
  157. package/dist/modules/site-architecture/internal-link-quality.js.map +1 -0
  158. package/dist/modules/site-architecture/multilingual-clusters.d.ts +82 -0
  159. package/dist/modules/site-architecture/multilingual-clusters.js +363 -0
  160. package/dist/modules/site-architecture/multilingual-clusters.js.map +1 -0
  161. package/dist/network.d.ts +4 -0
  162. package/dist/network.js +18 -2
  163. package/dist/network.js.map +1 -1
  164. package/dist/presentation.d.ts +53 -0
  165. package/dist/presentation.js +526 -0
  166. package/dist/presentation.js.map +1 -1
  167. package/dist/screenshot.d.ts +2 -1
  168. package/dist/screenshot.js +4 -2
  169. package/dist/screenshot.js.map +1 -1
  170. package/dist/seo-auditor.js +16 -6
  171. package/dist/seo-auditor.js.map +1 -1
  172. package/package.json +7 -4
@@ -0,0 +1,185 @@
1
+ export const INTENTS = [
2
+ "informational", "commercial", "transactional", "navigational",
3
+ ];
4
+ export const MAX_INTENT_COMPETITORS = 6;
5
+ export const MAX_INTENT_HTML_BYTES = 150_000;
6
+ export const MAX_INTENT_TOTAL_BYTES = 800_000;
7
+ export const MAX_INTENT_FINDINGS = 10;
8
+ export const MAX_INTENT_QUERY_BYTES = 160;
9
+ const MAX_QUERY_TERMS = 12;
10
+ export const SIGNALS = {
11
+ informational: ["article_schema", "faq_schema", "howto_schema", "editorial_sections"],
12
+ commercial: ["product_schema", "review_schema", "comparison_heading", "pricing_heading"],
13
+ transactional: ["offer_schema", "checkout_link", "purchase_action", "purchase_form"],
14
+ navigational: ["contact_heading", "main_contact_link", "main_address"],
15
+ };
16
+ export function emptyIntentComparison() {
17
+ const signals = Object.fromEntries(INTENTS.map((intent) => [intent, []]));
18
+ const signal_counts = Object.fromEntries(INTENTS.map((intent) => [intent, 0]));
19
+ return {
20
+ scope: "caller_supplied_static_html_only",
21
+ query_supplied: false,
22
+ usable_query_terms: 0,
23
+ primary: {
24
+ origin: "", title_present: false, h1_present: false, main_found: false,
25
+ signals, signal_counts, extraction_limited: true,
26
+ },
27
+ competitors: [], competitors_submitted: 0, competitors_eligible: 0,
28
+ competitors_with_intent_signals: 0, coverage_limited: true,
29
+ limitations: ["Comparison could not be performed on the bounded supplied input."],
30
+ total_findings: 0, findings: [], findings_truncated: false,
31
+ };
32
+ }
33
+ export function safeIntentUrl(raw) {
34
+ if (raw.length > 512)
35
+ return undefined;
36
+ try {
37
+ const parsed = new URL(raw);
38
+ if (!["http:", "https:"].includes(parsed.protocol) || !parsed.hostname ||
39
+ parsed.username || parsed.password || parsed.search || parsed.hash ||
40
+ parsed.port || parsed.hostname.length > 180)
41
+ return undefined;
42
+ return parsed.href;
43
+ }
44
+ catch {
45
+ return undefined;
46
+ }
47
+ }
48
+ const stopWords = new Set([
49
+ "a", "an", "and", "are", "as", "at", "be", "can", "for", "from", "how", "in",
50
+ "is", "it", "of", "on", "or", "the", "to", "vs", "what", "when", "where", "which", "with",
51
+ ]);
52
+ /** Exact normalized heading tokens only; synonyms/intent are not inferred. */
53
+ function tokenize(text) {
54
+ const matches = text.normalize("NFKC").toLocaleLowerCase("en")
55
+ .match(/[\p{L}\p{N}]+/gu) ?? [];
56
+ return matches.filter((word) => word.length >= 2 && word.length <= 32);
57
+ }
58
+ export function queryKeywords(query) {
59
+ if (!query || new TextEncoder().encode(query).byteLength > MAX_INTENT_QUERY_BYTES)
60
+ return [];
61
+ return [...new Set(tokenize(query)
62
+ .filter((word) => !stopWords.has(word)))].slice(0, MAX_QUERY_TERMS);
63
+ }
64
+ function wordCoverage(heading, words) {
65
+ if (!words.length)
66
+ return undefined;
67
+ const terms = new Set(tokenize(heading));
68
+ return Math.round(100 * words.filter((word) => terms.has(word)).length / words.length);
69
+ }
70
+ function signalSnapshot(record, expected, words) {
71
+ const url = safeIntentUrl(record.url);
72
+ const signals = Object.fromEntries(INTENTS.map((intent) => [intent,
73
+ [...new Set(record.signals[intent])].filter((item) => SIGNALS[intent].includes(item)).slice(0, 5),
74
+ ]));
75
+ const counts = Object.fromEntries(INTENTS.map((intent) => [intent, signals[intent].length]));
76
+ return {
77
+ origin: url ? new URL(url).origin : "",
78
+ title_present: Boolean(record.title.trim()),
79
+ h1_present: Boolean(record.h1.trim()),
80
+ main_found: record.main_found,
81
+ signals, signal_counts: counts,
82
+ ...(expected ? { intent_signal_count: counts[expected] } : {}),
83
+ ...(words.length ? {
84
+ query_title_coverage_percent: wordCoverage(record.title, words),
85
+ query_h1_coverage_percent: wordCoverage(record.h1, words),
86
+ } : {}),
87
+ extraction_limited: record.extraction_limited,
88
+ };
89
+ }
90
+ export function compareIntentObservations(primary, competitors, options = {}) {
91
+ if (competitors.length < 1 || competitors.length > MAX_INTENT_COMPETITORS) {
92
+ throw new Error("Supply one to six competitor observations.");
93
+ }
94
+ const primaryUrl = safeIntentUrl(primary.url);
95
+ if (!primaryUrl || !primary.eligible)
96
+ throw new Error("Primary HTML observation is ineligible.");
97
+ const primaryOrigin = new URL(primaryUrl).origin;
98
+ const competitorOrigins = new Set();
99
+ for (const record of competitors) {
100
+ const competitorUrl = safeIntentUrl(record.url);
101
+ if (!competitorUrl || !record.eligible)
102
+ throw new Error("Competitor HTML observation is ineligible.");
103
+ const origin = new URL(competitorUrl).origin;
104
+ if (origin === primaryOrigin || competitorOrigins.has(origin)) {
105
+ throw new Error("Competitor observations must have distinct origins from the primary and each other.");
106
+ }
107
+ competitorOrigins.add(origin);
108
+ }
109
+ if (options.expectedIntent && !INTENTS.includes(options.expectedIntent)) {
110
+ throw new Error("Unsupported intent label.");
111
+ }
112
+ const query = options.query;
113
+ if (query && new TextEncoder().encode(query).byteLength > MAX_INTENT_QUERY_BYTES) {
114
+ throw new Error("Optional query exceeds the byte limit.");
115
+ }
116
+ const words = queryKeywords(query);
117
+ const own = signalSnapshot(primary, options.expectedIntent, words);
118
+ const others = competitors.map((record) => signalSnapshot(record, options.expectedIntent, words));
119
+ let competitorsWithSignals = 0;
120
+ const findings = [];
121
+ if (options.expectedIntent) {
122
+ competitorsWithSignals = others.filter((record) => (record.intent_signal_count ?? 0) > 0).length;
123
+ if (!own.intent_signal_count && competitorsWithSignals > 0) {
124
+ findings.push({
125
+ code: "primary_intent_signal_gap", severity: competitorsWithSignals >= 2 ? "warning" : "info",
126
+ confidence: "review",
127
+ competitors_supporting: competitorsWithSignals,
128
+ message: "The primary page lacks the selected intent's inspected static signals, while one or more supplied competitor pages display them. This is a markup review lead, not an intent or ranking verdict.",
129
+ });
130
+ }
131
+ }
132
+ if (words.length) {
133
+ const primaryCoverage = Math.max(own.query_title_coverage_percent ?? 0, own.query_h1_coverage_percent ?? 0);
134
+ const competitorCoverage = others.filter((record) => Math.max(record.query_title_coverage_percent ?? 0, record.query_h1_coverage_percent ?? 0) >= 50).length;
135
+ if (primaryCoverage === 0 && competitorCoverage >= 2) {
136
+ findings.push({
137
+ code: "primary_heading_query_gap", severity: "info", confidence: "review",
138
+ competitors_supporting: competitorCoverage,
139
+ message: "Neither primary heading contains the supplied query's normalized content words, but multiple competitor headings overlap at least half. Synonyms, other languages and page relevance were not assessed.",
140
+ });
141
+ }
142
+ }
143
+ else if (query) {
144
+ findings.push({
145
+ code: "ambiguous_query_terms", severity: "info", confidence: "review",
146
+ message: "No usable content words remain after bounded tokenization of the supplied query. No lexical heading overlap can be assessed.",
147
+ });
148
+ }
149
+ if (!own.title_present && !own.h1_present) {
150
+ findings.push({
151
+ code: "primary_missing_headings", severity: "info", confidence: "observed",
152
+ message: "The primary supplied HTML has neither a nonempty title nor a visible first main H1.",
153
+ });
154
+ }
155
+ if (!options.expectedIntent && !words.length) {
156
+ findings.push({
157
+ code: "no_explicit_intent_evidence", severity: "info", confidence: "review",
158
+ message: "No explicit target intent or usable query was supplied; only inspected static signal inventories can be compared.",
159
+ });
160
+ }
161
+ // Never declare that an incomplete user-supplied competitor set is a SERP,
162
+ // competitor ranking, market sample or result from a search engine.
163
+ return {
164
+ scope: "caller_supplied_static_html_only",
165
+ ...(options.expectedIntent ? { expected_intent: options.expectedIntent } : {}),
166
+ query_supplied: Boolean(query), usable_query_terms: words.length,
167
+ primary: own, competitors: others,
168
+ competitors_submitted: competitors.length, competitors_eligible: others.length,
169
+ competitors_with_intent_signals: competitorsWithSignals,
170
+ coverage_limited: true,
171
+ limitations: [
172
+ "Only caller-supplied static page HTML is compared; no competitors, SERP rankings, live search demand, search console data, crawl results, or index status were retrieved.",
173
+ "Intent indicators are bounded DOM/JSON-LD and heading observations, not Google's interpretation, a semantic classifier, topical authority, content usefulness or proof of relevance.",
174
+ ...(query ? ["Query-heading overlap is strictly lexical; translations, variants, synonyms and implicit intent are not evaluated."] :
175
+ ["No query was supplied; topical heading alignment cannot be checked."]),
176
+ ...(!options.expectedIntent ? ["No target search intent was supplied; markup cannot establish it automatically."] : []),
177
+ ...([primary, ...competitors].some((record) => record.extraction_limited || !record.main_found)
178
+ ? ["At least one page lacked a main region or reached a static parsing bound; evidence may be incomplete."] : []),
179
+ ],
180
+ total_findings: findings.length,
181
+ findings: findings.slice(0, MAX_INTENT_FINDINGS),
182
+ findings_truncated: findings.length > MAX_INTENT_FINDINGS,
183
+ };
184
+ }
185
+ //# sourceMappingURL=competitor-intent-comparison.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"competitor-intent-comparison.js","sourceRoot":"","sources":["../../../src/modules/content-schema/competitor-intent-comparison.ts"],"names":[],"mappings":"AASA,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,eAAe,EAAE,YAAY,EAAE,eAAe,EAAE,cAAc;CACpB,CAAC;AAC7C,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AACxC,MAAM,CAAC,MAAM,qBAAqB,GAAG,OAAO,CAAC;AAC7C,MAAM,CAAC,MAAM,sBAAsB,GAAG,OAAO,CAAC;AAC9C,MAAM,CAAC,MAAM,mBAAmB,GAAG,EA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GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9E,cAAc,EAAE,OAAO,CAAC,KAAK,CAAC,EAAE,kBAAkB,EAAE,KAAK,CAAC,MAAM;QAChE,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM;QACjC,qBAAqB,EAAE,WAAW,CAAC,MAAM,EAAE,oBAAoB,EAAE,MAAM,CAAC,MAAM;QAC9E,+BAA+B,EAAE,sBAAsB;QACvD,gBAAgB,EAAE,IAAI;QACtB,WAAW,EAAE;YACX,2KAA2K;YAC3K,sLAAsL;YACtL,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,oHAAoH,CAAC,CAAC,CAAC;gBAClI,CAAC,qEAAqE,CAAC,CAAC;YAC1E,GAAG,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,iFAAiF,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YACvH,GAAG,CAAC,CAAC,OAAO,EAAE,GAAG,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,kBAAkB,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC;gBAC7F,CAAC,CAAC,CAAC,uGAAuG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;SACpH;QACD,cAAc,EAAE,QAAQ,CAAC,MAAM;QAC/B,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,mBAAmB,CAAC;QAChD,kBAAkB,EAAE,QAAQ,CAAC,MAAM,GAAG,mBAAmB;KAC1D,CAAC;AACJ,CAAC","sourcesContent":["/**\n * P1-06: evidence-limited competitor search-intent comparison.\n *\n * This module compares only static HTML that the caller already has the right\n * to supply. It cannot discover competitor pages, query Google/analytics, or\n * determine Google's interpretation, rankings, page usefulness or relevance.\n */\nexport type SearchIntent = \"informational\" | \"commercial\" | \"transactional\" | \"navigational\";\n\nexport const INTENTS = [\n \"informational\", \"commercial\", \"transactional\", \"navigational\",\n] as const satisfies readonly SearchIntent[];\nexport const MAX_INTENT_COMPETITORS = 6;\nexport const MAX_INTENT_HTML_BYTES = 150_000;\nexport const MAX_INTENT_TOTAL_BYTES = 800_000;\nexport const MAX_INTENT_FINDINGS = 10;\nexport const MAX_INTENT_QUERY_BYTES = 160;\nconst MAX_QUERY_TERMS = 12;\n\nexport const SIGNALS = {\n informational: [\"article_schema\", \"faq_schema\", \"howto_schema\", \"editorial_sections\"],\n commercial: [\"product_schema\", \"review_schema\", \"comparison_heading\", \"pricing_heading\"],\n transactional: [\"offer_schema\", \"checkout_link\", \"purchase_action\", \"purchase_form\"],\n navigational: [\"contact_heading\", \"main_contact_link\", \"main_address\"],\n} as const;\ntype Signals = Record<SearchIntent, string[]>;\nexport type IntentCode = \"primary_intent_signal_gap\"\n | \"primary_heading_query_gap\"\n | \"primary_missing_headings\"\n | \"no_explicit_intent_evidence\"\n | \"incomplete_competitor_sample\"\n | \"ambiguous_query_terms\";\n\nexport interface IntentObservation {\n url: string;\n title: string;\n h1: string;\n signals: Signals;\n eligible: boolean;\n extraction_limited: boolean;\n main_found: boolean;\n}\nexport interface IntentPageEvidence {\n origin: string;\n title_present: boolean;\n h1_present: boolean;\n main_found: boolean;\n signals: Signals;\n signal_counts: Record<SearchIntent, number>;\n intent_signal_count?: number;\n query_title_coverage_percent?: number;\n query_h1_coverage_percent?: number;\n extraction_limited: boolean;\n}\nexport interface IntentFinding {\n code: IntentCode;\n severity: \"warning\" | \"info\";\n confidence: \"observed\" | \"review\";\n message: string;\n competitors_supporting?: number;\n}\nexport interface IntentComparison {\n scope: \"caller_supplied_static_html_only\";\n expected_intent?: SearchIntent;\n query_supplied: boolean;\n usable_query_terms: number;\n primary: IntentPageEvidence;\n competitors: IntentPageEvidence[];\n competitors_submitted: number;\n competitors_eligible: number;\n competitors_with_intent_signals: number;\n coverage_limited: boolean;\n limitations: string[];\n total_findings: number;\n findings: IntentFinding[];\n findings_truncated: boolean;\n}\n\nexport function emptyIntentComparison(): IntentComparison {\n const signals = Object.fromEntries(INTENTS.map((intent) => [intent, [] as string[]])) as\n Record<SearchIntent, string[]>;\n const signal_counts = Object.fromEntries(INTENTS.map((intent) => [intent, 0])) as\n Record<SearchIntent, number>;\n return {\n scope: \"caller_supplied_static_html_only\",\n query_supplied: false,\n usable_query_terms: 0,\n primary: {\n origin: \"\", title_present: false, h1_present: false, main_found: false,\n signals, signal_counts, extraction_limited: true,\n },\n competitors: [], competitors_submitted: 0, competitors_eligible: 0,\n competitors_with_intent_signals: 0, coverage_limited: true,\n limitations: [\"Comparison could not be performed on the bounded supplied input.\"],\n total_findings: 0, findings: [], findings_truncated: false,\n };\n}\n\nexport function safeIntentUrl(raw: string): string | undefined {\n if (raw.length > 512) return undefined;\n try {\n const parsed = new URL(raw);\n if (![\"http:\", \"https:\"].includes(parsed.protocol) || !parsed.hostname ||\n parsed.username || parsed.password || parsed.search || parsed.hash ||\n parsed.port || parsed.hostname.length > 180) return undefined;\n return parsed.href;\n } catch {\n return undefined;\n }\n}\nconst stopWords = new Set([\n \"a\", \"an\", \"and\", \"are\", \"as\", \"at\", \"be\", \"can\", \"for\", \"from\", \"how\", \"in\",\n \"is\", \"it\", \"of\", \"on\", \"or\", \"the\", \"to\", \"vs\", \"what\", \"when\", \"where\", \"which\", \"with\",\n]);\n\n/** Exact normalized heading tokens only; synonyms/intent are not inferred. */\nfunction tokenize(text: string): string[] {\n const matches = text.normalize(\"NFKC\").toLocaleLowerCase(\"en\")\n .match(/[\\p{L}\\p{N}]+/gu) ?? [];\n return matches.filter((word) => word.length >= 2 && word.length <= 32);\n}\nexport function queryKeywords(query?: string): string[] {\n if (!query || new TextEncoder().encode(query).byteLength > MAX_INTENT_QUERY_BYTES) return [];\n return [...new Set(tokenize(query)\n .filter((word) => !stopWords.has(word)))].slice(0, MAX_QUERY_TERMS);\n}\nfunction wordCoverage(heading: string, words: readonly string[]): number | undefined {\n if (!words.length) return undefined;\n const terms = new Set(tokenize(heading));\n return Math.round(100 * words.filter((word) => terms.has(word)).length / words.length);\n}\nfunction signalSnapshot(record: IntentObservation, expected: SearchIntent | undefined,\n words: readonly string[]): IntentPageEvidence {\n const url = safeIntentUrl(record.url);\n const signals = Object.fromEntries(INTENTS.map((intent) => [intent,\n [...new Set(record.signals[intent])].filter((item) =>\n (SIGNALS[intent] as readonly string[]).includes(item)).slice(0, 5),\n ])) as Signals;\n const counts = Object.fromEntries(INTENTS.map((intent) =>\n [intent, signals[intent].length])) as Record<SearchIntent, number>;\n return {\n origin: url ? new URL(url).origin : \"\",\n title_present: Boolean(record.title.trim()),\n h1_present: Boolean(record.h1.trim()),\n main_found: record.main_found,\n signals, signal_counts: counts,\n ...(expected ? { intent_signal_count: counts[expected] } : {}),\n ...(words.length ? {\n query_title_coverage_percent: wordCoverage(record.title, words),\n query_h1_coverage_percent: wordCoverage(record.h1, words),\n } : {}),\n extraction_limited: record.extraction_limited,\n };\n}\nexport function compareIntentObservations(\n primary: IntentObservation,\n competitors: readonly IntentObservation[],\n options: { expectedIntent?: SearchIntent; query?: string } = {},\n): IntentComparison {\n if (competitors.length < 1 || competitors.length > MAX_INTENT_COMPETITORS) {\n throw new Error(\"Supply one to six competitor observations.\");\n }\n const primaryUrl = safeIntentUrl(primary.url);\n if (!primaryUrl || !primary.eligible) throw new Error(\"Primary HTML observation is ineligible.\");\n const primaryOrigin = new URL(primaryUrl).origin;\n const competitorOrigins = new Set<string>();\n for (const record of competitors) {\n const competitorUrl = safeIntentUrl(record.url);\n if (!competitorUrl || !record.eligible) throw new Error(\"Competitor HTML observation is ineligible.\");\n const origin = new URL(competitorUrl).origin;\n if (origin === primaryOrigin || competitorOrigins.has(origin)) {\n throw new Error(\"Competitor observations must have distinct origins from the primary and each other.\");\n }\n competitorOrigins.add(origin);\n }\n if (options.expectedIntent && !INTENTS.includes(options.expectedIntent)) {\n throw new Error(\"Unsupported intent label.\");\n }\n const query = options.query;\n if (query && new TextEncoder().encode(query).byteLength > MAX_INTENT_QUERY_BYTES) {\n throw new Error(\"Optional query exceeds the byte limit.\");\n }\n const words = queryKeywords(query);\n const own = signalSnapshot(primary, options.expectedIntent, words);\n const others = competitors.map((record) => signalSnapshot(record, options.expectedIntent, words));\n let competitorsWithSignals = 0;\n const findings: IntentFinding[] = [];\n if (options.expectedIntent) {\n competitorsWithSignals = others.filter((record) => (record.intent_signal_count ?? 0) > 0).length;\n if (!own.intent_signal_count && competitorsWithSignals > 0) {\n findings.push({\n code: \"primary_intent_signal_gap\", severity: competitorsWithSignals >= 2 ? \"warning\" : \"info\",\n confidence: \"review\",\n competitors_supporting: competitorsWithSignals,\n message: \"The primary page lacks the selected intent's inspected static signals, while one or more supplied competitor pages display them. This is a markup review lead, not an intent or ranking verdict.\",\n });\n }\n }\n if (words.length) {\n const primaryCoverage = Math.max(own.query_title_coverage_percent ?? 0,\n own.query_h1_coverage_percent ?? 0);\n const competitorCoverage = others.filter((record) =>\n Math.max(record.query_title_coverage_percent ?? 0, record.query_h1_coverage_percent ?? 0) >= 50).length;\n if (primaryCoverage === 0 && competitorCoverage >= 2) {\n findings.push({\n code: \"primary_heading_query_gap\", severity: \"info\", confidence: \"review\",\n competitors_supporting: competitorCoverage,\n message: \"Neither primary heading contains the supplied query's normalized content words, but multiple competitor headings overlap at least half. Synonyms, other languages and page relevance were not assessed.\",\n });\n }\n } else if (query) {\n findings.push({\n code: \"ambiguous_query_terms\", severity: \"info\", confidence: \"review\",\n message: \"No usable content words remain after bounded tokenization of the supplied query. No lexical heading overlap can be assessed.\",\n });\n }\n if (!own.title_present && !own.h1_present) {\n findings.push({\n code: \"primary_missing_headings\", severity: \"info\", confidence: \"observed\",\n message: \"The primary supplied HTML has neither a nonempty title nor a visible first main H1.\",\n });\n }\n if (!options.expectedIntent && !words.length) {\n findings.push({\n code: \"no_explicit_intent_evidence\", severity: \"info\", confidence: \"review\",\n message: \"No explicit target intent or usable query was supplied; only inspected static signal inventories can be compared.\",\n });\n }\n // Never declare that an incomplete user-supplied competitor set is a SERP,\n // competitor ranking, market sample or result from a search engine.\n return {\n scope: \"caller_supplied_static_html_only\",\n ...(options.expectedIntent ? { expected_intent: options.expectedIntent } : {}),\n query_supplied: Boolean(query), usable_query_terms: words.length,\n primary: own, competitors: others,\n competitors_submitted: competitors.length, competitors_eligible: others.length,\n competitors_with_intent_signals: competitorsWithSignals,\n coverage_limited: true,\n limitations: [\n \"Only caller-supplied static page HTML is compared; no competitors, SERP rankings, live search demand, search console data, crawl results, or index status were retrieved.\",\n \"Intent indicators are bounded DOM/JSON-LD and heading observations, not Google's interpretation, a semantic classifier, topical authority, content usefulness or proof of relevance.\",\n ...(query ? [\"Query-heading overlap is strictly lexical; translations, variants, synonyms and implicit intent are not evaluated.\"] :\n [\"No query was supplied; topical heading alignment cannot be checked.\"]),\n ...(!options.expectedIntent ? [\"No target search intent was supplied; markup cannot establish it automatically.\"] : []),\n ...([primary, ...competitors].some((record) => record.extraction_limited || !record.main_found)\n ? [\"At least one page lacked a main region or reached a static parsing bound; evidence may be incomplete.\"] : []),\n ],\n total_findings: findings.length,\n findings: findings.slice(0, MAX_INTENT_FINDINGS),\n findings_truncated: findings.length > MAX_INTENT_FINDINGS,\n };\n}\n"]}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * P1-03: evidence-limited structural content-quality checks.
3
+ * Pure deterministic logic over the already extracted static main text.
4
+ * It is not a content-quality score, indexing verdict, or semantic judgment.
5
+ */
6
+ import { type MainContentObservation } from "./same-language-duplicates.js";
7
+ export declare const MAX_PAGE_QUALITY_PAGES = 8;
8
+ export declare const MAX_PAGE_QUALITY_FINDINGS = 12;
9
+ export interface ContentQualityFinding {
10
+ code: string;
11
+ severity: "warning" | "info";
12
+ confidence: "observed" | "potential";
13
+ message: string;
14
+ affected_pages: number;
15
+ example_urls: string[];
16
+ }
17
+ export interface PageContentQualityAnalysis {
18
+ scope: "sampled_pages_only";
19
+ sampled_pages: number;
20
+ eligible_pages: number;
21
+ skipped_pages: number;
22
+ families_compared: number;
23
+ empty_main_pages: number;
24
+ short_main_pages: number;
25
+ repeated_boilerplate_pages: number;
26
+ possible_low_value_pages: number;
27
+ coverage_limited: boolean;
28
+ limitations: string[];
29
+ total_findings: number;
30
+ findings: ContentQualityFinding[];
31
+ findings_truncated: boolean;
32
+ }
33
+ export declare function analyzePageContentQuality(observations: readonly MainContentObservation[], options?: {
34
+ sampledPages?: number;
35
+ coverageLimited?: boolean;
36
+ }): PageContentQualityAnalysis;
@@ -0,0 +1,225 @@
1
+ /**
2
+ * P1-03: evidence-limited structural content-quality checks.
3
+ * Pure deterministic logic over the already extracted static main text.
4
+ * It is not a content-quality score, indexing verdict, or semantic judgment.
5
+ */
6
+ import { MAX_MAIN_CONTENT_CHARS, MAX_MAIN_CONTENT_WORDS, comparisonLanguage, safeObservedUrl, tokensFromText, } from "./same-language-duplicates.js";
7
+ export const MAX_PAGE_QUALITY_PAGES = 8;
8
+ export const MAX_PAGE_QUALITY_FINDINGS = 12;
9
+ const THIN_CONTENT_WORDS = 40;
10
+ const MIN_REPEATED_WORDS = 60;
11
+ const MIN_REPEATED_SENTENCE_WORDS = 12;
12
+ const BOILERPLATE_MIN_SHARE = 0.65;
13
+ const LOW_UNIQUE_VALUE_SHARE = 0.8;
14
+ const LOW_UNIQUE_WORDS = 30;
15
+ const MAX_SENTENCES = 240;
16
+ const MAX_EXAMPLE_URLS = 2;
17
+ /** URL-based grouping is a heuristic, not proof that two pages have the same purpose. */
18
+ function familyFor(url) {
19
+ const parsed = new URL(url);
20
+ const parts = parsed.pathname.split("/").filter(Boolean);
21
+ // A site's /privacy and /contact are not a family merely because they
22
+ // share the root directory; grouping needs an actual path-category parent.
23
+ const path = parts.length < 2 ? parsed.pathname :
24
+ "/" + parts.slice(0, parts.length > 2 ? 2 : 1).join("/") + "/*";
25
+ return parsed.origin + path;
26
+ }
27
+ function prepare(input) {
28
+ const url = safeObservedUrl(input.url);
29
+ if (!url || input.text.length > MAX_MAIN_CONTENT_CHARS)
30
+ return undefined;
31
+ const language = comparisonLanguage(input.language);
32
+ const locale = language ?? "en";
33
+ const normalizedText = input.text.normalize("NFKC").replace(/\s+/gu, " ").trim().toLocaleLowerCase(locale);
34
+ if (normalizedText.length > MAX_MAIN_CONTENT_CHARS)
35
+ return undefined;
36
+ const words = tokensFromText(normalizedText, locale);
37
+ if (words.length > MAX_MAIN_CONTENT_WORDS)
38
+ return undefined;
39
+ const segmenter = new Intl.Segmenter(locale, { granularity: "sentence" });
40
+ const sentences = [];
41
+ let sentenceLimit = false;
42
+ // Preserve author-provided paragraph boundaries: a 100-word paragraph
43
+ // without punctuation is still a substantive reusable content block.
44
+ // Analyze each leaf block once; do not double-count flattened main text.
45
+ const blocks = input.blocks?.length ? input.blocks : [normalizedText];
46
+ for (const rawBlock of blocks.slice(0, MAX_SENTENCES)) {
47
+ if (sentences.length >= MAX_SENTENCES) {
48
+ sentenceLimit = true;
49
+ break;
50
+ }
51
+ const text = rawBlock.normalize("NFKC").replace(/\s+/gu, " ").trim().toLocaleLowerCase(locale);
52
+ const segmented = Array.from(segmenter.segment(text), (segment) => segment.segment);
53
+ // ICU sometimes misses punctuation after alphanumeric identifiers.
54
+ const sections = segmented.length <= 1 && /[.!?]\s+\p{L}/u.test(text)
55
+ ? text.split(/(?<=[.!?])\s+(?=\p{L})/u)
56
+ : segmented;
57
+ for (const section of sections) {
58
+ if (sentences.length >= MAX_SENTENCES) {
59
+ sentenceLimit = true;
60
+ break;
61
+ }
62
+ const value = section.trim();
63
+ if (!value)
64
+ continue;
65
+ const count = tokensFromText(value, locale).length;
66
+ if (count >= MIN_REPEATED_SENTENCE_WORDS)
67
+ sentences.push({ normalized: value, words: count });
68
+ }
69
+ }
70
+ if (input.blocksTruncated || blocks.length > MAX_SENTENCES)
71
+ sentenceLimit = true;
72
+ return {
73
+ url, source: input.source, ...(language ? { language } : {}),
74
+ family: familyFor(url), normalizedText, words: words.length, sentences, sentenceLimit,
75
+ };
76
+ }
77
+ function findingComparator(left, right) {
78
+ return (left.severity === "warning" ? 0 : 1) - (right.severity === "warning" ? 0 : 1)
79
+ || left.code.localeCompare(right.code)
80
+ || (left.example_urls[0] ?? "").localeCompare(right.example_urls[0] ?? "");
81
+ }
82
+ export function analyzePageContentQuality(observations, options = {}) {
83
+ if (observations.length > MAX_PAGE_QUALITY_PAGES) {
84
+ throw new Error("Content-quality analysis supports at most eight pages per sample.");
85
+ }
86
+ const sampledPages = options.sampledPages ?? observations.length;
87
+ if (!Number.isSafeInteger(sampledPages) || sampledPages < observations.length ||
88
+ sampledPages > MAX_PAGE_QUALITY_PAGES) {
89
+ throw new Error("sampledPages must be between the observed count and eight.");
90
+ }
91
+ const seenPages = new Set();
92
+ const prepared = observations.flatMap((item) => {
93
+ const page = prepare(item);
94
+ if (!page || seenPages.has(page.url))
95
+ return [];
96
+ seenPages.add(page.url);
97
+ return [page];
98
+ });
99
+ const empty = prepared.filter((p) => p.words <= 2 && p.source !== "body_fallback");
100
+ const noTextBody = prepared.filter((p) => p.words <= 2 && p.source === "body_fallback");
101
+ const thin = prepared.filter((p) => p.words > 2 && p.words < THIN_CONTENT_WORDS &&
102
+ (p.source === "main" || p.source === "article"));
103
+ const findings = [];
104
+ const seen = new Set();
105
+ let totalFindings = 0;
106
+ function report(code, confidence, message, pages, severity = "warning") {
107
+ if (pages.length === 0)
108
+ return;
109
+ const examples = [...new Set(pages.map((page) => page.url))].sort();
110
+ const key = JSON.stringify([code, examples]);
111
+ if (seen.has(key))
112
+ return;
113
+ seen.add(key);
114
+ totalFindings += 1;
115
+ findings.push({
116
+ code, severity, confidence, message,
117
+ affected_pages: examples.length,
118
+ example_urls: examples.slice(0, MAX_EXAMPLE_URLS),
119
+ });
120
+ }
121
+ if (empty.length)
122
+ report("content.empty_main", "observed", "Sampled page main content has little or no static text. Images, video, or script-rendered content might still provide value; inspect the rendered page.", empty);
123
+ if (noTextBody.length)
124
+ report("content.no_static_body", "potential", "Sampled HTML has almost no static body text and no main landmark. A JavaScript-rendered interface may still provide substantial content; check the rendered page.", noTextBody);
125
+ if (thin.length)
126
+ report("content.short_main", "potential", "Sampled page main text has fewer than 40 words. Short pages can be useful; review whether each meets its visitors' needs.", thin);
127
+ const byFamily = new Map();
128
+ for (const page of prepared) {
129
+ const group = byFamily.get(page.family) ?? [];
130
+ group.push(page);
131
+ byFamily.set(page.family, group);
132
+ }
133
+ const repeated = new Set();
134
+ const lowValue = new Set();
135
+ let comparableFamilies = 0;
136
+ for (const pages of byFamily.values()) {
137
+ if (pages.length < 2)
138
+ continue;
139
+ const emptyPages = pages.filter((page) => page.words <= 2);
140
+ if (emptyPages.length >= 2)
141
+ report("content.family_empty", emptyPages.some((p) => p.source === "body_fallback") ? "potential" : "observed", "Multiple pages in an approximate URL family have almost no static main text; inspect the family template and rendered output.", emptyPages);
142
+ const shortPages = pages.filter((page) => page.words < THIN_CONTENT_WORDS);
143
+ if (pages.length >= 3 && shortPages.length >= Math.ceil(pages.length * 0.75))
144
+ report("content.family_thin", "potential", "Most sampled pages in an approximate URL family have short main text; evaluate their different visitor needs rather than relying on word count alone.", shortPages);
145
+ const byLanguage = new Map();
146
+ for (const page of pages) {
147
+ if (!page.language)
148
+ continue;
149
+ const languagePages = byLanguage.get(page.language) ?? [];
150
+ languagePages.push(page);
151
+ byLanguage.set(page.language, languagePages);
152
+ }
153
+ for (const languagePages of byLanguage.values()) {
154
+ if (languagePages.length < 2)
155
+ continue;
156
+ comparableFamilies += 1;
157
+ const sentenceOwners = new Map();
158
+ const exactTextOwners = new Map();
159
+ for (const page of languagePages) {
160
+ const repeatedText = exactTextOwners.get(page.normalizedText) ?? new Set();
161
+ repeatedText.add(page.url);
162
+ exactTextOwners.set(page.normalizedText, repeatedText);
163
+ for (const sentence of page.sentences) {
164
+ const owners = sentenceOwners.get(sentence.normalized) ?? new Set();
165
+ owners.add(page.url);
166
+ sentenceOwners.set(sentence.normalized, owners);
167
+ }
168
+ }
169
+ const familyBoilerplate = [];
170
+ const familyLowValue = [];
171
+ for (const page of languagePages) {
172
+ // Identical pages are already reported by P1-01. Avoid duplicating
173
+ // that same diagnostic under a new name.
174
+ if ((exactTextOwners.get(page.normalizedText)?.size ?? 0) > 1 || page.words < MIN_REPEATED_WORDS) {
175
+ continue;
176
+ }
177
+ const repeatedWords = Math.min(page.words, page.sentences.reduce((sum, sentence) => sum +
178
+ ((sentenceOwners.get(sentence.normalized)?.size ?? 0) >= 2 ? sentence.words : 0), 0));
179
+ if (repeatedWords < MIN_REPEATED_WORDS)
180
+ continue;
181
+ const ratio = repeatedWords / page.words;
182
+ if (ratio >= BOILERPLATE_MIN_SHARE) {
183
+ familyBoilerplate.push(page);
184
+ repeated.add(page.url);
185
+ }
186
+ if (ratio >= LOW_UNIQUE_VALUE_SHARE && page.words - repeatedWords < LOW_UNIQUE_WORDS) {
187
+ familyLowValue.push(page);
188
+ lowValue.add(page.url);
189
+ }
190
+ }
191
+ if (familyBoilerplate.length >= 2)
192
+ report("content.family_repeated_boilerplate", "potential", "Substantial main-text sentences repeat across multiple nonidentical pages in one sampled URL family. Review whether the pages offer distinct information.", familyBoilerplate);
193
+ if (familyLowValue.length)
194
+ report("content.low_unique_value", "potential", "One or more sampled pages contain mostly repeated main-text sentences with little additional text. This is a review signal, not a determination of usefulness.", familyLowValue);
195
+ }
196
+ }
197
+ findings.sort(findingComparator);
198
+ const skippedPages = sampledPages - prepared.length;
199
+ const unknownLanguage = prepared.some((page) => !page.language);
200
+ const sentenceLimits = prepared.some((page) => page.sentenceLimit);
201
+ return {
202
+ scope: "sampled_pages_only",
203
+ sampled_pages: sampledPages,
204
+ eligible_pages: prepared.length,
205
+ skipped_pages: skippedPages,
206
+ families_compared: comparableFamilies,
207
+ empty_main_pages: empty.length,
208
+ short_main_pages: thin.length,
209
+ repeated_boilerplate_pages: repeated.size,
210
+ possible_low_value_pages: lowValue.size,
211
+ coverage_limited: Boolean(options.coverageLimited) || sampledPages < 2 ||
212
+ skippedPages > 0 || unknownLanguage || sentenceLimits,
213
+ limitations: [
214
+ "Static main-text heuristics cannot prove content usefulness, originality, indexing eligibility, ranking effects, or rendered-page behavior.",
215
+ "Boilerplate comparisons use only sampled pages in the same approximate URL family and language; a clean result is not site-wide coverage.",
216
+ ...(skippedPages ? [String(skippedPages) + " page(s) had unavailable or oversized observations or duplicate URL labels."] : []),
217
+ ...(unknownLanguage || sentenceLimits || options.coverageLimited
218
+ ? ["Unknown language, a bounded sentence scan, or incomplete page discovery limits cross-page conclusions."] : []),
219
+ ],
220
+ total_findings: totalFindings,
221
+ findings: findings.slice(0, MAX_PAGE_QUALITY_FINDINGS),
222
+ findings_truncated: findings.length > MAX_PAGE_QUALITY_FINDINGS,
223
+ };
224
+ }
225
+ //# sourceMappingURL=empty-boilerplate-content.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"empty-boilerplate-content.js","sourceRoot":"","sources":["../../../src/modules/content-schema/empty-boilerplate-content.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,kBAAkB,EAClB,eAAe,EACf,cAAc,GAEf,MAAM,+BAA+B,CAAC;AAEvC,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AACxC,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAC5C,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,MAAM,2BAA2B,GAAG,EAAE,CAAC;AACvC,MAAM,qBAAqB,GAAG,IAAI,CAAC;AACnC,MAAM,sBAAsB,GAAG,GAAG,CAAC;AACnC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAC5B,MAAM,aAAa,GAAG,GAAG,CAAC;AAC1B,MAAM,gBAAgB,GAAG,CAAC,CAAC;AA4C3B,yFAAyF;AACzF,SAAS,SAAS,CAAC,GAAW;IAC5B,MAAM,MAAM,GAAG,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7I,2IAA2I;YAC3I,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,6EAA6E,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAC/H,GAAG,CAAC,eAAe,IAAI,cAAc,IAAI,OAAO,CAAC,eAAe;gBAC9D,CAAC,CAAC,CAAC,wGAAwG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;SACrH;QACD,cAAc,EAAE,aAAa;QAC7B,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,yBAAyB,CAAC;QACtD,kBAAkB,EAAE,QAAQ,CAAC,MAAM,GAAG,yBAAyB;KAChE,CAAC;AACJ,CAAC","sourcesContent":["/**\n * P1-03: evidence-limited structural content-quality checks.\n * Pure deterministic logic over the already extracted static main text.\n * It is not a content-quality score, indexing verdict, or semantic judgment.\n */\nimport {\n MAX_MAIN_CONTENT_CHARS,\n MAX_MAIN_CONTENT_WORDS,\n comparisonLanguage,\n safeObservedUrl,\n tokensFromText,\n type MainContentObservation,\n} from \"./same-language-duplicates.js\";\n\nexport const MAX_PAGE_QUALITY_PAGES = 8;\nexport const MAX_PAGE_QUALITY_FINDINGS = 12;\nconst THIN_CONTENT_WORDS = 40;\nconst MIN_REPEATED_WORDS = 60;\nconst MIN_REPEATED_SENTENCE_WORDS = 12;\nconst BOILERPLATE_MIN_SHARE = 0.65;\nconst LOW_UNIQUE_VALUE_SHARE = 0.8;\nconst LOW_UNIQUE_WORDS = 30;\nconst MAX_SENTENCES = 240;\nconst MAX_EXAMPLE_URLS = 2;\n\nexport interface ContentQualityFinding {\n code: string;\n severity: \"warning\" | \"info\";\n confidence: \"observed\" | \"potential\";\n message: string;\n affected_pages: number;\n example_urls: string[];\n}\n\nexport interface PageContentQualityAnalysis {\n scope: \"sampled_pages_only\";\n sampled_pages: number;\n eligible_pages: number;\n skipped_pages: number;\n families_compared: number;\n empty_main_pages: number;\n short_main_pages: number;\n repeated_boilerplate_pages: number;\n possible_low_value_pages: number;\n coverage_limited: boolean;\n limitations: string[];\n total_findings: number;\n findings: ContentQualityFinding[];\n findings_truncated: boolean;\n}\n\ninterface AnalyzedSentence {\n normalized: string;\n words: number;\n}\n\ninterface AnalyzedPage {\n url: string;\n source: MainContentObservation[\"source\"];\n language?: string;\n family: string;\n normalizedText: string;\n words: number;\n sentences: AnalyzedSentence[];\n sentenceLimit: boolean;\n}\n\n/** URL-based grouping is a heuristic, not proof that two pages have the same purpose. */\nfunction familyFor(url: string): string {\n const parsed = new URL(url);\n const parts = parsed.pathname.split(\"/\").filter(Boolean);\n // A site's /privacy and /contact are not a family merely because they\n // share the root directory; grouping needs an actual path-category parent.\n const path = parts.length < 2 ? parsed.pathname :\n \"/\" + parts.slice(0, parts.length > 2 ? 2 : 1).join(\"/\") + \"/*\";\n return parsed.origin + path;\n}\n\nfunction prepare(input: MainContentObservation): AnalyzedPage | undefined {\n const url = safeObservedUrl(input.url);\n if (!url || input.text.length > MAX_MAIN_CONTENT_CHARS) return undefined;\n const language = comparisonLanguage(input.language);\n const locale = language ?? \"en\";\n const normalizedText = input.text.normalize(\"NFKC\").replace(/\\s+/gu, \" \").trim().toLocaleLowerCase(locale);\n if (normalizedText.length > MAX_MAIN_CONTENT_CHARS) return undefined;\n const words = tokensFromText(normalizedText, locale);\n if (words.length > MAX_MAIN_CONTENT_WORDS) return undefined;\n\n const segmenter = new Intl.Segmenter(locale, { granularity: \"sentence\" });\n const sentences: AnalyzedSentence[] = [];\n let sentenceLimit = false;\n // Preserve author-provided paragraph boundaries: a 100-word paragraph\n // without punctuation is still a substantive reusable content block.\n // Analyze each leaf block once; do not double-count flattened main text.\n const blocks = input.blocks?.length ? input.blocks : [normalizedText];\n for (const rawBlock of blocks.slice(0, MAX_SENTENCES)) {\n if (sentences.length >= MAX_SENTENCES) { sentenceLimit = true; break; }\n const text = rawBlock.normalize(\"NFKC\").replace(/\\s+/gu, \" \").trim().toLocaleLowerCase(locale);\n const segmented = Array.from(segmenter.segment(text), (segment) => segment.segment);\n // ICU sometimes misses punctuation after alphanumeric identifiers.\n const sections = segmented.length <= 1 && /[.!?]\\s+\\p{L}/u.test(text)\n ? text.split(/(?<=[.!?])\\s+(?=\\p{L})/u)\n : segmented;\n for (const section of sections) {\n if (sentences.length >= MAX_SENTENCES) { sentenceLimit = true; break; }\n const value = section.trim();\n if (!value) continue;\n const count = tokensFromText(value, locale).length;\n if (count >= MIN_REPEATED_SENTENCE_WORDS) sentences.push({ normalized: value, words: count });\n }\n }\n if (input.blocksTruncated || blocks.length > MAX_SENTENCES) sentenceLimit = true;\n return {\n url, source: input.source, ...(language ? { language } : {}),\n family: familyFor(url), normalizedText, words: words.length, sentences, sentenceLimit,\n };\n}\n\nfunction findingComparator(left: ContentQualityFinding, right: ContentQualityFinding): number {\n return (left.severity === \"warning\" ? 0 : 1) - (right.severity === \"warning\" ? 0 : 1)\n || left.code.localeCompare(right.code)\n || (left.example_urls[0] ?? \"\").localeCompare(right.example_urls[0] ?? \"\");\n}\n\nexport function analyzePageContentQuality(\n observations: readonly MainContentObservation[],\n options: { sampledPages?: number; coverageLimited?: boolean } = {},\n): PageContentQualityAnalysis {\n if (observations.length > MAX_PAGE_QUALITY_PAGES) {\n throw new Error(\"Content-quality analysis supports at most eight pages per sample.\");\n }\n const sampledPages = options.sampledPages ?? observations.length;\n if (!Number.isSafeInteger(sampledPages) || sampledPages < observations.length ||\n sampledPages > MAX_PAGE_QUALITY_PAGES) {\n throw new Error(\"sampledPages must be between the observed count and eight.\");\n }\n const seenPages = new Set<string>();\n const prepared = observations.flatMap((item) => {\n const page = prepare(item);\n if (!page || seenPages.has(page.url)) return [];\n seenPages.add(page.url);\n return [page];\n });\n const empty = prepared.filter((p) => p.words <= 2 && p.source !== \"body_fallback\");\n const noTextBody = prepared.filter((p) => p.words <= 2 && p.source === \"body_fallback\");\n const thin = prepared.filter((p) => p.words > 2 && p.words < THIN_CONTENT_WORDS &&\n (p.source === \"main\" || p.source === \"article\"));\n const findings: ContentQualityFinding[] = [];\n const seen = new Set<string>();\n let totalFindings = 0;\n\n function report(code: string, confidence: ContentQualityFinding[\"confidence\"],\n message: string, pages: readonly AnalyzedPage[], severity: ContentQualityFinding[\"severity\"] = \"warning\") {\n if (pages.length === 0) return;\n const examples = [...new Set(pages.map((page) => page.url))].sort();\n const key = JSON.stringify([code, examples]);\n if (seen.has(key)) return;\n seen.add(key);\n totalFindings += 1;\n findings.push({\n code, severity, confidence, message,\n affected_pages: examples.length,\n example_urls: examples.slice(0, MAX_EXAMPLE_URLS),\n });\n }\n\n if (empty.length) report(\n \"content.empty_main\", \"observed\",\n \"Sampled page main content has little or no static text. Images, video, or script-rendered content might still provide value; inspect the rendered page.\",\n empty,\n );\n if (noTextBody.length) report(\n \"content.no_static_body\", \"potential\",\n \"Sampled HTML has almost no static body text and no main landmark. A JavaScript-rendered interface may still provide substantial content; check the rendered page.\",\n noTextBody,\n );\n if (thin.length) report(\n \"content.short_main\", \"potential\",\n \"Sampled page main text has fewer than 40 words. Short pages can be useful; review whether each meets its visitors' needs.\",\n thin,\n );\n\n const byFamily = new Map<string, AnalyzedPage[]>();\n for (const page of prepared) {\n const group = byFamily.get(page.family) ?? [];\n group.push(page);\n byFamily.set(page.family, group);\n }\n const repeated = new Set<string>();\n const lowValue = new Set<string>();\n let comparableFamilies = 0;\n for (const pages of byFamily.values()) {\n if (pages.length < 2) continue;\n const emptyPages = pages.filter((page) => page.words <= 2);\n if (emptyPages.length >= 2) report(\n \"content.family_empty\", emptyPages.some((p) => p.source === \"body_fallback\") ? \"potential\" : \"observed\",\n \"Multiple pages in an approximate URL family have almost no static main text; inspect the family template and rendered output.\",\n emptyPages,\n );\n const shortPages = pages.filter((page) => page.words < THIN_CONTENT_WORDS);\n if (pages.length >= 3 && shortPages.length >= Math.ceil(pages.length * 0.75)) report(\n \"content.family_thin\", \"potential\",\n \"Most sampled pages in an approximate URL family have short main text; evaluate their different visitor needs rather than relying on word count alone.\",\n shortPages,\n );\n\n const byLanguage = new Map<string, AnalyzedPage[]>();\n for (const page of pages) {\n if (!page.language) continue;\n const languagePages = byLanguage.get(page.language) ?? [];\n languagePages.push(page);\n byLanguage.set(page.language, languagePages);\n }\n for (const languagePages of byLanguage.values()) {\n if (languagePages.length < 2) continue;\n comparableFamilies += 1;\n const sentenceOwners = new Map<string, Set<string>>();\n const exactTextOwners = new Map<string, Set<string>>();\n for (const page of languagePages) {\n const repeatedText = exactTextOwners.get(page.normalizedText) ?? new Set<string>();\n repeatedText.add(page.url);\n exactTextOwners.set(page.normalizedText, repeatedText);\n for (const sentence of page.sentences) {\n const owners = sentenceOwners.get(sentence.normalized) ?? new Set<string>();\n owners.add(page.url);\n sentenceOwners.set(sentence.normalized, owners);\n }\n }\n const familyBoilerplate: AnalyzedPage[] = [];\n const familyLowValue: AnalyzedPage[] = [];\n for (const page of languagePages) {\n // Identical pages are already reported by P1-01. Avoid duplicating\n // that same diagnostic under a new name.\n if ((exactTextOwners.get(page.normalizedText)?.size ?? 0) > 1 || page.words < MIN_REPEATED_WORDS) {\n continue;\n }\n const repeatedWords = Math.min(page.words, page.sentences.reduce(\n (sum, sentence) => sum +\n ((sentenceOwners.get(sentence.normalized)?.size ?? 0) >= 2 ? sentence.words : 0),\n 0,\n ));\n if (repeatedWords < MIN_REPEATED_WORDS) continue;\n const ratio = repeatedWords / page.words;\n if (ratio >= BOILERPLATE_MIN_SHARE) {\n familyBoilerplate.push(page);\n repeated.add(page.url);\n }\n if (ratio >= LOW_UNIQUE_VALUE_SHARE && page.words - repeatedWords < LOW_UNIQUE_WORDS) {\n familyLowValue.push(page);\n lowValue.add(page.url);\n }\n }\n if (familyBoilerplate.length >= 2) report(\n \"content.family_repeated_boilerplate\", \"potential\",\n \"Substantial main-text sentences repeat across multiple nonidentical pages in one sampled URL family. Review whether the pages offer distinct information.\",\n familyBoilerplate,\n );\n if (familyLowValue.length) report(\n \"content.low_unique_value\", \"potential\",\n \"One or more sampled pages contain mostly repeated main-text sentences with little additional text. This is a review signal, not a determination of usefulness.\",\n familyLowValue,\n );\n }\n }\n\n findings.sort(findingComparator);\n const skippedPages = sampledPages - prepared.length;\n const unknownLanguage = prepared.some((page) => !page.language);\n const sentenceLimits = prepared.some((page) => page.sentenceLimit);\n return {\n scope: \"sampled_pages_only\",\n sampled_pages: sampledPages,\n eligible_pages: prepared.length,\n skipped_pages: skippedPages,\n families_compared: comparableFamilies,\n empty_main_pages: empty.length,\n short_main_pages: thin.length,\n repeated_boilerplate_pages: repeated.size,\n possible_low_value_pages: lowValue.size,\n coverage_limited: Boolean(options.coverageLimited) || sampledPages < 2 ||\n skippedPages > 0 || unknownLanguage || sentenceLimits,\n limitations: [\n \"Static main-text heuristics cannot prove content usefulness, originality, indexing eligibility, ranking effects, or rendered-page behavior.\",\n \"Boilerplate comparisons use only sampled pages in the same approximate URL family and language; a clean result is not site-wide coverage.\",\n ...(skippedPages ? [String(skippedPages) + \" page(s) had unavailable or oversized observations or duplicate URL labels.\"] : []),\n ...(unknownLanguage || sentenceLimits || options.coverageLimited\n ? [\"Unknown language, a bounded sentence scan, or incomplete page discovery limits cross-page conclusions.\"] : []),\n ],\n total_findings: totalFindings,\n findings: findings.slice(0, MAX_PAGE_QUALITY_FINDINGS),\n findings_truncated: findings.length > MAX_PAGE_QUALITY_FINDINGS,\n };\n}\n"]}
@@ -0,0 +1,6 @@
1
+ import { type ProvenanceObservation } from "./citation-methodology-consistency.js";
2
+ /**
3
+ * Static-only HTML adapter. Source links and declared dates are observed but
4
+ * never dereferenced. Each runtime imports its own Cheerio installation.
5
+ */
6
+ export declare function observeProvenancePage(html: string, rawUrl: string): ProvenanceObservation;