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.
- package/CHANGELOG.md +41 -0
- package/README.md +64 -4
- package/dist/audit-history.d.ts +9 -0
- package/dist/audit-history.js +27 -0
- package/dist/audit-history.js.map +1 -1
- package/dist/index.js +2508 -2
- package/dist/index.js.map +1 -1
- package/dist/modules/browser-ux/lighthouse-lab-probe.d.ts +21 -0
- package/dist/modules/browser-ux/lighthouse-lab-probe.js +190 -0
- package/dist/modules/browser-ux/lighthouse-lab-probe.js.map +1 -0
- package/dist/modules/browser-ux/lighthouse-lab.d.ts +61 -0
- package/dist/modules/browser-ux/lighthouse-lab.js +98 -0
- package/dist/modules/browser-ux/lighthouse-lab.js.map +1 -0
- package/dist/modules/browser-ux/media-diagnostics.d.ts +41 -0
- package/dist/modules/browser-ux/media-diagnostics.js +183 -0
- package/dist/modules/browser-ux/media-diagnostics.js.map +1 -0
- package/dist/modules/browser-ux/raw-rendered-diff.d.ts +70 -0
- package/dist/modules/browser-ux/raw-rendered-diff.js +262 -0
- package/dist/modules/browser-ux/raw-rendered-diff.js.map +1 -0
- package/dist/modules/browser-ux/raw-rendered-probe.d.ts +17 -0
- package/dist/modules/browser-ux/raw-rendered-probe.js +163 -0
- package/dist/modules/browser-ux/raw-rendered-probe.js.map +1 -0
- package/dist/modules/browser-ux/resource-failures-probe.d.ts +11 -0
- package/dist/modules/browser-ux/resource-failures-probe.js +231 -0
- package/dist/modules/browser-ux/resource-failures-probe.js.map +1 -0
- package/dist/modules/browser-ux/resource-failures.d.ts +79 -0
- package/dist/modules/browser-ux/resource-failures.js +178 -0
- package/dist/modules/browser-ux/resource-failures.js.map +1 -0
- package/dist/modules/browser-ux/viewport-parity-probe.d.ts +5 -0
- package/dist/modules/browser-ux/viewport-parity-probe.js +307 -0
- package/dist/modules/browser-ux/viewport-parity-probe.js.map +1 -0
- package/dist/modules/browser-ux/viewport-parity.d.ts +112 -0
- package/dist/modules/browser-ux/viewport-parity.js +224 -0
- package/dist/modules/browser-ux/viewport-parity.js.map +1 -0
- package/dist/modules/browser-ux/wcag-interactions.d.ts +95 -0
- package/dist/modules/browser-ux/wcag-interactions.js +360 -0
- package/dist/modules/browser-ux/wcag-interactions.js.map +1 -0
- package/dist/modules/change-regression/availability-history-store.d.ts +18 -0
- package/dist/modules/change-regression/availability-history-store.js +168 -0
- package/dist/modules/change-regression/availability-history-store.js.map +1 -0
- package/dist/modules/change-regression/crawler-log-correlation.d.ts +111 -0
- package/dist/modules/change-regression/crawler-log-correlation.js +374 -0
- package/dist/modules/change-regression/crawler-log-correlation.js.map +1 -0
- package/dist/modules/change-regression/google-common-crawler-ip.d.ts +15 -0
- package/dist/modules/change-regression/google-common-crawler-ip.js +129 -0
- package/dist/modules/change-regression/google-common-crawler-ip.js.map +1 -0
- package/dist/modules/change-regression/historical-comparisons.d.ts +120 -0
- package/dist/modules/change-regression/historical-comparisons.js +330 -0
- package/dist/modules/change-regression/historical-comparisons.js.map +1 -0
- package/dist/modules/change-regression/production-change-comparison.d.ts +68 -0
- package/dist/modules/change-regression/production-change-comparison.js +214 -0
- package/dist/modules/change-regression/production-change-comparison.js.map +1 -0
- package/dist/modules/change-regression/regression-alerts.d.ts +73 -0
- package/dist/modules/change-regression/regression-alerts.js +183 -0
- package/dist/modules/change-regression/regression-alerts.js.map +1 -0
- package/dist/modules/change-regression/strict-observation-time.d.ts +7 -0
- package/dist/modules/change-regression/strict-observation-time.js +31 -0
- package/dist/modules/change-regression/strict-observation-time.js.map +1 -0
- package/dist/modules/content-schema/citation-methodology-consistency.d.ts +108 -0
- package/dist/modules/content-schema/citation-methodology-consistency.js +360 -0
- package/dist/modules/content-schema/citation-methodology-consistency.js.map +1 -0
- package/dist/modules/content-schema/competitor-intent-comparison.d.ts +74 -0
- package/dist/modules/content-schema/competitor-intent-comparison.js +185 -0
- package/dist/modules/content-schema/competitor-intent-comparison.js.map +1 -0
- package/dist/modules/content-schema/empty-boilerplate-content.d.ts +36 -0
- package/dist/modules/content-schema/empty-boilerplate-content.js +225 -0
- package/dist/modules/content-schema/empty-boilerplate-content.js.map +1 -0
- package/dist/modules/content-schema/extract-citation-methodology.d.ts +6 -0
- package/dist/modules/content-schema/extract-citation-methodology.js +201 -0
- package/dist/modules/content-schema/extract-citation-methodology.js.map +1 -0
- package/dist/modules/content-schema/extract-competitor-intent.d.ts +2 -0
- package/dist/modules/content-schema/extract-competitor-intent.js +140 -0
- package/dist/modules/content-schema/extract-competitor-intent.js.map +1 -0
- package/dist/modules/content-schema/extract-main-content.d.ts +6 -0
- package/dist/modules/content-schema/extract-main-content.js +33 -0
- package/dist/modules/content-schema/extract-main-content.js.map +1 -0
- package/dist/modules/content-schema/extract-metadata-consistency.d.ts +3 -0
- package/dist/modules/content-schema/extract-metadata-consistency.js +62 -0
- package/dist/modules/content-schema/extract-metadata-consistency.js.map +1 -0
- package/dist/modules/content-schema/extract-product-claims.d.ts +3 -0
- package/dist/modules/content-schema/extract-product-claims.js +58 -0
- package/dist/modules/content-schema/extract-product-claims.js.map +1 -0
- package/dist/modules/content-schema/extract-structured-data.d.ts +3 -0
- package/dist/modules/content-schema/extract-structured-data.js +25 -0
- package/dist/modules/content-schema/extract-structured-data.js.map +1 -0
- package/dist/modules/content-schema/metadata-consistency.d.ts +66 -0
- package/dist/modules/content-schema/metadata-consistency.js +282 -0
- package/dist/modules/content-schema/metadata-consistency.js.map +1 -0
- package/dist/modules/content-schema/product-claims.d.ts +73 -0
- package/dist/modules/content-schema/product-claims.js +195 -0
- package/dist/modules/content-schema/product-claims.js.map +1 -0
- package/dist/modules/content-schema/same-language-duplicates.d.ts +52 -0
- package/dist/modules/content-schema/same-language-duplicates.js +158 -0
- package/dist/modules/content-schema/same-language-duplicates.js.map +1 -0
- package/dist/modules/content-schema/structured-data-validation.d.ts +37 -0
- package/dist/modules/content-schema/structured-data-validation.js +385 -0
- package/dist/modules/content-schema/structured-data-validation.js.map +1 -0
- package/dist/modules/external-metrics/crux-field-probe.d.ts +10 -0
- package/dist/modules/external-metrics/crux-field-probe.js +113 -0
- package/dist/modules/external-metrics/crux-field-probe.js.map +1 -0
- package/dist/modules/external-metrics/crux-field.d.ts +61 -0
- package/dist/modules/external-metrics/crux-field.js +231 -0
- package/dist/modules/external-metrics/crux-field.js.map +1 -0
- package/dist/modules/http-crawl/availability-observations.d.ts +68 -0
- package/dist/modules/http-crawl/availability-observations.js +206 -0
- package/dist/modules/http-crawl/availability-observations.js.map +1 -0
- package/dist/modules/http-crawl/availability-probe.d.ts +8 -0
- package/dist/modules/http-crawl/availability-probe.js +46 -0
- package/dist/modules/http-crawl/availability-probe.js.map +1 -0
- package/dist/modules/http-crawl/crawler-access-probe.d.ts +6 -0
- package/dist/modules/http-crawl/crawler-access-probe.js +79 -0
- package/dist/modules/http-crawl/crawler-access-probe.js.map +1 -0
- package/dist/modules/http-crawl/crawler-access.d.ts +75 -0
- package/dist/modules/http-crawl/crawler-access.js +404 -0
- package/dist/modules/http-crawl/crawler-access.js.map +1 -0
- package/dist/modules/http-crawl/http-delivery-probe.d.ts +3 -0
- package/dist/modules/http-crawl/http-delivery-probe.js +44 -0
- package/dist/modules/http-crawl/http-delivery-probe.js.map +1 -0
- package/dist/modules/http-crawl/http-delivery.d.ts +64 -0
- package/dist/modules/http-crawl/http-delivery.js +269 -0
- package/dist/modules/http-crawl/http-delivery.js.map +1 -0
- package/dist/modules/http-crawl/https-security.d.ts +84 -0
- package/dist/modules/http-crawl/https-security.js +441 -0
- package/dist/modules/http-crawl/https-security.js.map +1 -0
- package/dist/modules/http-crawl/non-html-directives.d.ts +74 -0
- package/dist/modules/http-crawl/non-html-directives.js +353 -0
- package/dist/modules/http-crawl/non-html-directives.js.map +1 -0
- package/dist/modules/http-crawl/redirect-canonical-chains.d.ts +80 -0
- package/dist/modules/http-crawl/redirect-canonical-chains.js +459 -0
- package/dist/modules/http-crawl/redirect-canonical-chains.js.map +1 -0
- package/dist/modules/http-crawl/redirect-canonical-probe.d.ts +6 -0
- package/dist/modules/http-crawl/redirect-canonical-probe.js +83 -0
- package/dist/modules/http-crawl/redirect-canonical-probe.js.map +1 -0
- package/dist/modules/http-crawl/sitemap-inventory-probe.d.ts +8 -0
- package/dist/modules/http-crawl/sitemap-inventory-probe.js +155 -0
- package/dist/modules/http-crawl/sitemap-inventory-probe.js.map +1 -0
- package/dist/modules/http-crawl/sitemap-inventory.d.ts +107 -0
- package/dist/modules/http-crawl/sitemap-inventory.js +557 -0
- package/dist/modules/http-crawl/sitemap-inventory.js.map +1 -0
- package/dist/modules/http-crawl/url-variants.d.ts +86 -0
- package/dist/modules/http-crawl/url-variants.js +379 -0
- package/dist/modules/http-crawl/url-variants.js.map +1 -0
- package/dist/modules/site-architecture/extract-internal-links.d.ts +3 -0
- package/dist/modules/site-architecture/extract-internal-links.js +88 -0
- package/dist/modules/site-architecture/extract-internal-links.js.map +1 -0
- package/dist/modules/site-architecture/extract-multilingual-page.d.ts +2 -0
- package/dist/modules/site-architecture/extract-multilingual-page.js +29 -0
- package/dist/modules/site-architecture/extract-multilingual-page.js.map +1 -0
- package/dist/modules/site-architecture/internal-link-graph-probe.d.ts +7 -0
- package/dist/modules/site-architecture/internal-link-graph-probe.js +116 -0
- package/dist/modules/site-architecture/internal-link-graph-probe.js.map +1 -0
- package/dist/modules/site-architecture/internal-link-graph.d.ts +113 -0
- package/dist/modules/site-architecture/internal-link-graph.js +414 -0
- package/dist/modules/site-architecture/internal-link-graph.js.map +1 -0
- package/dist/modules/site-architecture/internal-link-quality.d.ts +77 -0
- package/dist/modules/site-architecture/internal-link-quality.js +260 -0
- package/dist/modules/site-architecture/internal-link-quality.js.map +1 -0
- package/dist/modules/site-architecture/multilingual-clusters.d.ts +82 -0
- package/dist/modules/site-architecture/multilingual-clusters.js +363 -0
- package/dist/modules/site-architecture/multilingual-clusters.js.map +1 -0
- package/dist/network.d.ts +4 -0
- package/dist/network.js +18 -2
- package/dist/network.js.map +1 -1
- package/dist/presentation.d.ts +53 -0
- package/dist/presentation.js +526 -0
- package/dist/presentation.js.map +1 -1
- package/dist/screenshot.d.ts +2 -1
- package/dist/screenshot.js +4 -2
- package/dist/screenshot.js.map +1 -1
- package/dist/seo-auditor.js +16 -6
- package/dist/seo-auditor.js.map +1 -1
- package/package.json +7 -4
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* P1-05 citation / dataset / freshness / methodology consistency.
|
|
3
|
+
*
|
|
4
|
+
* Pure comparisons of supplied static HTML observations and caller-supplied
|
|
5
|
+
* evidence. Nothing here fetches a citation, validates scientific claims,
|
|
6
|
+
* measures search ranking or treats an incomplete manifest as exhaustive.
|
|
7
|
+
*/
|
|
8
|
+
export const MAX_PROVENANCE_PAGES = 8;
|
|
9
|
+
export const MAX_PROVENANCE_SOURCES = 24;
|
|
10
|
+
export const MAX_PROVENANCE_DATASETS = 16;
|
|
11
|
+
export const MAX_PROVENANCE_METHODS = 16;
|
|
12
|
+
export const MAX_PROVENANCE_FINDINGS = 12;
|
|
13
|
+
export const MAX_PROVENANCE_HTML_BYTES = 200_000;
|
|
14
|
+
export const MAX_PROVENANCE_INPUT_BYTES = 1_000_000;
|
|
15
|
+
export const MAX_PROVENANCE_DECLARATIONS = 48;
|
|
16
|
+
/** Strict safe labels for references, no query, fragment or credential leakage. */
|
|
17
|
+
export function safeProvenanceUrl(raw) {
|
|
18
|
+
if (!raw || raw.length > 512)
|
|
19
|
+
return undefined;
|
|
20
|
+
try {
|
|
21
|
+
const url = new URL(raw);
|
|
22
|
+
if ((url.protocol !== "https:" && url.protocol !== "http:") || url.username ||
|
|
23
|
+
url.password || url.search || url.hash || url.port || !url.hostname)
|
|
24
|
+
return undefined;
|
|
25
|
+
return url.href;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export function safeProvenanceId(raw) {
|
|
32
|
+
return raw.length <= 64 && /^[a-zA-Z][a-zA-Z0-9._:-]*$/.test(raw) ? raw : undefined;
|
|
33
|
+
}
|
|
34
|
+
export function safeDatasetVersion(raw) {
|
|
35
|
+
return raw.length <= 64 && /^[a-zA-Z0-9][a-zA-Z0-9 ._+-]*$/.test(raw) ? raw : undefined;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Calendar-valid YYYY-MM-DD or a timezone-qualified ISO timestamp. Dates from
|
|
39
|
+
* timestamps are compared by UTC day to avoid local machine timezone drift.
|
|
40
|
+
*/
|
|
41
|
+
export function normalizedEvidenceDate(raw) {
|
|
42
|
+
if (raw.length > 48)
|
|
43
|
+
return undefined;
|
|
44
|
+
const day = /^(\d{4})-(\d{2})-(\d{2})$/.exec(raw);
|
|
45
|
+
if (day) {
|
|
46
|
+
const year = Number(day[1]);
|
|
47
|
+
const month = Number(day[2]);
|
|
48
|
+
const date = Number(day[3]);
|
|
49
|
+
const timestamp = new Date(Date.UTC(year, month - 1, date));
|
|
50
|
+
// Date.UTC treats years 00-99 specially. Use explicit full UTC year.
|
|
51
|
+
timestamp.setUTCFullYear(year);
|
|
52
|
+
if (timestamp.getUTCFullYear() !== year ||
|
|
53
|
+
timestamp.getUTCMonth() + 1 !== month || timestamp.getUTCDate() !== date)
|
|
54
|
+
return undefined;
|
|
55
|
+
return day[0];
|
|
56
|
+
}
|
|
57
|
+
if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?(?:Z|[+-]\d{2}:\d{2})$/.test(raw)) {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
// Reject impossible calendar days and time/offset fields, not Date.parse's
|
|
61
|
+
// permissive overflow normalization.
|
|
62
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})/.exec(raw);
|
|
63
|
+
if (!normalizedEvidenceDate(match.slice(1, 4).join("-")) ||
|
|
64
|
+
Number(match[4]) > 23 || Number(match[5]) > 59 || Number(match[6]) > 59)
|
|
65
|
+
return undefined;
|
|
66
|
+
const zone = raw.endsWith("Z") ? undefined : /([+-])(\d{2}):(\d{2})$/.exec(raw);
|
|
67
|
+
if (zone && (Number(zone[2]) > 23 || Number(zone[3]) > 59))
|
|
68
|
+
return undefined;
|
|
69
|
+
const parsed = Date.parse(raw);
|
|
70
|
+
return Number.isFinite(parsed) ? new Date(parsed).toISOString().slice(0, 10) : undefined;
|
|
71
|
+
}
|
|
72
|
+
function uniqueDateValues(values) {
|
|
73
|
+
return [...new Set(values.filter((value) => normalizedEvidenceDate(value) !== undefined)
|
|
74
|
+
.map((value) => normalizedEvidenceDate(value)))].sort();
|
|
75
|
+
}
|
|
76
|
+
function daysBetween(from, to) {
|
|
77
|
+
return Math.round((Date.parse(to + "T00:00:00Z") -
|
|
78
|
+
Date.parse(from + "T00:00:00Z")) / 86_400_000);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Supports incomplete evidence. An unknown identifier remains unverified;
|
|
82
|
+
* disagreement against an explicitly supplied entry is a disagreement with
|
|
83
|
+
* that entry, not proof that the underlying publication is untruthful.
|
|
84
|
+
*/
|
|
85
|
+
export function analyzeProvenance(observations, manifest = {}, options = {}) {
|
|
86
|
+
if (observations.length > MAX_PROVENANCE_PAGES) {
|
|
87
|
+
throw new Error("Provenance comparison accepts at most eight page observations.");
|
|
88
|
+
}
|
|
89
|
+
const pagesSampled = options.sampledPages ?? observations.length;
|
|
90
|
+
if (!Number.isSafeInteger(pagesSampled) ||
|
|
91
|
+
pagesSampled < observations.length || pagesSampled > MAX_PROVENANCE_PAGES) {
|
|
92
|
+
throw new Error("sampledPages must be between observed pages and eight.");
|
|
93
|
+
}
|
|
94
|
+
if ((manifest.sources?.length ?? 0) > MAX_PROVENANCE_SOURCES ||
|
|
95
|
+
(manifest.datasets?.length ?? 0) > MAX_PROVENANCE_DATASETS ||
|
|
96
|
+
(manifest.methodologies?.length ?? 0) > MAX_PROVENANCE_METHODS) {
|
|
97
|
+
throw new Error("Supplied evidence exceeds the bounded manifest limits.");
|
|
98
|
+
}
|
|
99
|
+
for (const [kind, entries] of [
|
|
100
|
+
["sources", manifest.sources ?? []],
|
|
101
|
+
["datasets", manifest.datasets ?? []],
|
|
102
|
+
["methodologies", manifest.methodologies ?? []],
|
|
103
|
+
]) {
|
|
104
|
+
const ids = entries.map((entry) => entry.id);
|
|
105
|
+
if (new Set(ids).size !== ids.length) {
|
|
106
|
+
throw new Error("Duplicate " + kind + " IDs make the supplied evidence ambiguous.");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const referenceDate = manifest.as_of ? normalizedEvidenceDate(manifest.as_of) : undefined;
|
|
110
|
+
if (manifest.as_of && !referenceDate)
|
|
111
|
+
throw new Error("Manifest as_of must be a valid date.");
|
|
112
|
+
for (const ds of manifest.datasets ?? []) {
|
|
113
|
+
if (ds.as_of && !normalizedEvidenceDate(ds.as_of)) {
|
|
114
|
+
throw new Error("Dataset evidence as_of must be a valid date.");
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const sources = new Map((manifest.sources ?? []).map((value) => [value.id, value]));
|
|
118
|
+
const datasets = new Map((manifest.datasets ?? []).map((value) => [value.id, value]));
|
|
119
|
+
const methods = new Map((manifest.methodologies ?? []).map((value) => [value.id, value]));
|
|
120
|
+
const provided = sources.size + datasets.size + methods.size > 0;
|
|
121
|
+
const findings = [];
|
|
122
|
+
let seenCount = 0;
|
|
123
|
+
let checked = 0;
|
|
124
|
+
let consistent = 0;
|
|
125
|
+
let conflicts = 0;
|
|
126
|
+
let unverified = 0;
|
|
127
|
+
let citationTotal = 0;
|
|
128
|
+
let datasetTotal = 0;
|
|
129
|
+
let methodTotal = 0;
|
|
130
|
+
let badDates = 0;
|
|
131
|
+
const eligible = new Map();
|
|
132
|
+
for (const item of observations) {
|
|
133
|
+
const url = safeProvenanceUrl(item.url);
|
|
134
|
+
if (url && item.eligible && !eligible.has(url))
|
|
135
|
+
eligible.set(url, item);
|
|
136
|
+
}
|
|
137
|
+
function report(code, severity, evidence, page, message, ref) {
|
|
138
|
+
const finding = {
|
|
139
|
+
code, severity, evidence, page_url: page,
|
|
140
|
+
...(ref && safeProvenanceId(ref) ? { reference_id: ref } : {}),
|
|
141
|
+
message,
|
|
142
|
+
};
|
|
143
|
+
findings.push(finding);
|
|
144
|
+
}
|
|
145
|
+
// One id intentionally pointing to two sanitized URLs is directly
|
|
146
|
+
// inconsistent even when the optional manifest is absent.
|
|
147
|
+
const observedSourceTargets = new Map();
|
|
148
|
+
for (const [pageUrl, page] of eligible) {
|
|
149
|
+
seenCount += 1;
|
|
150
|
+
citationTotal += page.citations.length;
|
|
151
|
+
datasetTotal += page.datasets.length;
|
|
152
|
+
methodTotal += page.methodologies.length;
|
|
153
|
+
badDates += page.invalid_dates;
|
|
154
|
+
if (page.invalid_dates) {
|
|
155
|
+
checked += page.invalid_dates;
|
|
156
|
+
conflicts += page.invalid_dates;
|
|
157
|
+
report("invalid_date_declarations", "warning", "observed_html", pageUrl, "One or more explicit publication, modification or dataset date declarations are not valid ISO calendar dates.");
|
|
158
|
+
}
|
|
159
|
+
if (page.declarations_truncated) {
|
|
160
|
+
unverified += 1;
|
|
161
|
+
}
|
|
162
|
+
const published = uniqueDateValues(page.published_dates);
|
|
163
|
+
const modified = uniqueDateValues(page.modified_dates);
|
|
164
|
+
if (published.length > 1) {
|
|
165
|
+
checked += 1;
|
|
166
|
+
conflicts += 1;
|
|
167
|
+
report("published_dates_inconsistent", "warning", "observed_html", pageUrl, "This page declares different publication dates in its explicit structured signals.");
|
|
168
|
+
}
|
|
169
|
+
if (modified.length > 1) {
|
|
170
|
+
checked += 1;
|
|
171
|
+
conflicts += 1;
|
|
172
|
+
report("modified_dates_inconsistent", "warning", "observed_html", pageUrl, "This page declares different modification dates in its explicit structured signals.");
|
|
173
|
+
}
|
|
174
|
+
if (published.length === 1 && modified.length === 1) {
|
|
175
|
+
checked += 1;
|
|
176
|
+
if (modified[0] < published[0]) {
|
|
177
|
+
conflicts += 1;
|
|
178
|
+
report("modified_before_published", "warning", "observed_html", pageUrl, "The declared modification date precedes the publication date.");
|
|
179
|
+
}
|
|
180
|
+
else
|
|
181
|
+
consistent += 1;
|
|
182
|
+
}
|
|
183
|
+
if (referenceDate) {
|
|
184
|
+
for (const date of [...published, ...modified]) {
|
|
185
|
+
checked += 1;
|
|
186
|
+
if (date > referenceDate) {
|
|
187
|
+
conflicts += 1;
|
|
188
|
+
report("publication_after_reference_date", "warning", "reference_date", pageUrl, "An explicit publication or modification date is later than the caller-supplied reference day.");
|
|
189
|
+
}
|
|
190
|
+
else
|
|
191
|
+
consistent += 1;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
for (const cite of page.citations) {
|
|
195
|
+
const id = cite.id && safeProvenanceId(cite.id);
|
|
196
|
+
const target = cite.url && safeProvenanceUrl(cite.url);
|
|
197
|
+
const source = id && sources.get(id);
|
|
198
|
+
if (id && target) {
|
|
199
|
+
const previous = observedSourceTargets.get(id);
|
|
200
|
+
if (previous && previous !== target) {
|
|
201
|
+
checked += 1;
|
|
202
|
+
conflicts += 1;
|
|
203
|
+
report("citation_id_target_conflict", "warning", "observed_html", pageUrl, "The same citation ID is assigned different safe target URLs in the compared page sample.", id);
|
|
204
|
+
}
|
|
205
|
+
else if (!previous)
|
|
206
|
+
observedSourceTargets.set(id, target);
|
|
207
|
+
}
|
|
208
|
+
checked += 1;
|
|
209
|
+
if (source && target) {
|
|
210
|
+
const declared = safeProvenanceUrl(source.url);
|
|
211
|
+
if (declared && target === declared)
|
|
212
|
+
consistent += 1;
|
|
213
|
+
else if (declared) {
|
|
214
|
+
conflicts += 1;
|
|
215
|
+
report("citation_target_differs_from_supplied_evidence", "warning", "supplied_manifest", pageUrl, "The citation target differs from the URL for this ID in the supplied evidence.", id);
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
unverified += 1;
|
|
219
|
+
report("citation_reference_unverified", "info", "supplied_manifest", pageUrl, "The supplied source URL cannot be compared safely.", id);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
else if (target && !id && [...sources.values()].some((item) => safeProvenanceUrl(item.url) === target)) {
|
|
223
|
+
consistent += 1;
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
unverified += 1;
|
|
227
|
+
report("citation_reference_unverified", "info", "supplied_manifest", pageUrl, "This citation has no matching safe target or entry in the optional supplied source evidence.", id || undefined);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
for (const claim of page.datasets) {
|
|
231
|
+
const id = claim.id && safeProvenanceId(claim.id);
|
|
232
|
+
const evidence = id ? datasets.get(id) : undefined;
|
|
233
|
+
if (!id || !evidence) {
|
|
234
|
+
checked += 1;
|
|
235
|
+
unverified += 1;
|
|
236
|
+
report("dataset_reference_unverified", "info", "supplied_manifest", pageUrl, "This dataset claim has no matching identifier in the optional supplied dataset evidence.", id || undefined);
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
if (claim.version) {
|
|
240
|
+
checked += 1;
|
|
241
|
+
if (!evidence.version)
|
|
242
|
+
unverified += 1;
|
|
243
|
+
else if (evidence.version === claim.version)
|
|
244
|
+
consistent += 1;
|
|
245
|
+
else {
|
|
246
|
+
conflicts += 1;
|
|
247
|
+
report("dataset_version_conflict", "warning", "supplied_manifest", pageUrl, "The claimed dataset version differs from the version supplied for the same dataset ID.", id);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
if (claim.as_of) {
|
|
251
|
+
checked += 1;
|
|
252
|
+
const observed = normalizedEvidenceDate(claim.as_of);
|
|
253
|
+
const declared = evidence.as_of && normalizedEvidenceDate(evidence.as_of);
|
|
254
|
+
if (!observed) {
|
|
255
|
+
// Already counted as an invalid date by the extractor.
|
|
256
|
+
unverified += 1;
|
|
257
|
+
}
|
|
258
|
+
else if (declared) {
|
|
259
|
+
if (observed === declared)
|
|
260
|
+
consistent += 1;
|
|
261
|
+
else {
|
|
262
|
+
conflicts += 1;
|
|
263
|
+
report("dataset_as_of_conflict", "warning", "supplied_manifest", pageUrl, "The claimed dataset snapshot day differs from the supplied snapshot day for that ID.", id);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
else
|
|
267
|
+
unverified += 1;
|
|
268
|
+
if (observed && referenceDate) {
|
|
269
|
+
checked += 1;
|
|
270
|
+
if (observed > referenceDate) {
|
|
271
|
+
conflicts += 1;
|
|
272
|
+
report("dataset_snapshot_in_future", "warning", "reference_date", pageUrl, "The claimed snapshot date is later than the caller-supplied reference day.", id);
|
|
273
|
+
}
|
|
274
|
+
else
|
|
275
|
+
consistent += 1;
|
|
276
|
+
if (evidence.max_age_days !== undefined && observed <= referenceDate) {
|
|
277
|
+
checked += 1;
|
|
278
|
+
if (daysBetween(observed, referenceDate) > evidence.max_age_days) {
|
|
279
|
+
conflicts += 1;
|
|
280
|
+
report("dataset_freshness_window_exceeded", "warning", "supplied_manifest", pageUrl, "The snapshot age exceeds the explicitly supplied freshness window; review whether a newer release exists.", id);
|
|
281
|
+
}
|
|
282
|
+
else
|
|
283
|
+
consistent += 1;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
if (claim.methodology_id) {
|
|
288
|
+
checked += 1;
|
|
289
|
+
if (!evidence.methodology_id)
|
|
290
|
+
unverified += 1;
|
|
291
|
+
else if (evidence.methodology_id === claim.methodology_id)
|
|
292
|
+
consistent += 1;
|
|
293
|
+
else {
|
|
294
|
+
conflicts += 1;
|
|
295
|
+
report("methodology_id_conflict", "warning", "supplied_manifest", pageUrl, "The claimed methodology ID differs from the methodology ID supplied for this dataset.", id);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
if (!claim.version && !claim.as_of && !claim.methodology_id) {
|
|
299
|
+
checked += 1;
|
|
300
|
+
unverified += 1;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
for (const method of page.methodologies) {
|
|
304
|
+
const id = method.id && safeProvenanceId(method.id);
|
|
305
|
+
const supplied = id ? methods.get(id) : undefined;
|
|
306
|
+
checked += 1;
|
|
307
|
+
if (supplied && method.url) {
|
|
308
|
+
const actual = safeProvenanceUrl(method.url);
|
|
309
|
+
const expected = safeProvenanceUrl(supplied.url);
|
|
310
|
+
if (actual && expected) {
|
|
311
|
+
if (actual === expected)
|
|
312
|
+
consistent += 1;
|
|
313
|
+
else {
|
|
314
|
+
conflicts += 1;
|
|
315
|
+
report("methodology_link_conflict", "warning", "supplied_manifest", pageUrl, "The methodology URL differs from the URL supplied for this methodology ID.", id);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
else
|
|
319
|
+
unverified += 1;
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
unverified += 1;
|
|
323
|
+
report("methodology_reference_unverified", "info", "supplied_manifest", pageUrl, "No comparable methodology URL was supplied for this explicit methodology reference.", id || undefined);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
// Prefer observed contradictions over the potentially numerous informative
|
|
328
|
+
// unresolved references. Keep deterministic ordering and true total counts.
|
|
329
|
+
findings.sort((a, b) => (a.severity === "warning" ? 0 : 1) - (b.severity === "warning" ? 0 : 1) ||
|
|
330
|
+
a.code.localeCompare(b.code) || a.page_url.localeCompare(b.page_url) ||
|
|
331
|
+
(a.reference_id ?? "").localeCompare(b.reference_id ?? ""));
|
|
332
|
+
const extractionLimited = [...eligible.values()].some((page) => page.declarations_truncated);
|
|
333
|
+
const incomplete = pagesSampled !== eligible.size || extractionLimited ||
|
|
334
|
+
Boolean(options.coverageLimited) || !provided || unverified > 0;
|
|
335
|
+
return {
|
|
336
|
+
scope: "supplied_static_html_and_evidence",
|
|
337
|
+
pages_sampled: pagesSampled, pages_eligible: eligible.size,
|
|
338
|
+
citations_observed: citationTotal,
|
|
339
|
+
datasets_observed: datasetTotal,
|
|
340
|
+
methodologies_observed: methodTotal,
|
|
341
|
+
checked_declarations: checked,
|
|
342
|
+
consistent_declarations: consistent,
|
|
343
|
+
conflicting_declarations: conflicts,
|
|
344
|
+
unverified_declarations: unverified,
|
|
345
|
+
invalid_date_declarations: badDates,
|
|
346
|
+
evidence_supplied: provided,
|
|
347
|
+
coverage_limited: incomplete,
|
|
348
|
+
limitations: [
|
|
349
|
+
"Only supplied static HTML and optional caller-supplied evidence are compared; source URLs, DOI resolution, factual accuracy and current datasets are not independently fetched or verified.",
|
|
350
|
+
"A matched reference ID/URL verifies agreement with the supplied manifest, not authenticity, licensing, scientific correctness, freshness in the real world or Google search decisions.",
|
|
351
|
+
...(!provided ? ["No source/dataset/methodology manifest was supplied; unsupported references remain unverified."] : []),
|
|
352
|
+
...(extractionLimited || pagesSampled !== eligible.size || options.coverageLimited
|
|
353
|
+
? ["The input or extraction sample is incomplete; findings must not be interpreted as site-wide coverage."] : []),
|
|
354
|
+
],
|
|
355
|
+
total_findings: findings.length,
|
|
356
|
+
findings: findings.slice(0, MAX_PROVENANCE_FINDINGS),
|
|
357
|
+
findings_truncated: findings.length > MAX_PROVENANCE_FINDINGS,
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
//# sourceMappingURL=citation-methodology-consistency.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"citation-methodology-consistency.js","sourceRoot":"","sources":["../../../src/modules/content-schema/citation-methodology-consistency.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC;AACtC,MAAM,CAAC,MAAM,sBAAsB,GAAG,EAAE,CAAC;AACzC,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAC1C,MAAM,CAAC,MAAM,sBAAsB,GAAG,EAAE,CAAC;AACzC,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAC1C,MAAM,CAAC,MAAM,yBAAyB,GAAG,OAAO,CAAC;AACjD,MAAM,CAAC,MAAM,0BAA0B,GAAG,SAAS,CAAC;AACpD,MAAM,CAAC,MAA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;QACnC,iBAAiB,EAAE,QAAQ;QAC3B,gBAAgB,EAAE,UAAU;QAC5B,WAAW,EAAE;YACX,6LAA6L;YAC7L,wLAAwL;YACxL,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,gGAAgG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YACxH,GAAG,CAAC,iBAAiB,IAAI,YAAY,KAAK,QAAQ,CAAC,IAAI,IAAI,OAAO,CAAC,eAAe;gBAChF,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,uBAAuB,CAAC;QACpD,kBAAkB,EAAE,QAAQ,CAAC,MAAM,GAAG,uBAAuB;KAC9D,CAAC;AACJ,CAAC","sourcesContent":["/**\n * P1-05 citation / dataset / freshness / methodology consistency.\n *\n * Pure comparisons of supplied static HTML observations and caller-supplied\n * evidence. Nothing here fetches a citation, validates scientific claims,\n * measures search ranking or treats an incomplete manifest as exhaustive.\n */\nexport const MAX_PROVENANCE_PAGES = 8;\nexport const MAX_PROVENANCE_SOURCES = 24;\nexport const MAX_PROVENANCE_DATASETS = 16;\nexport const MAX_PROVENANCE_METHODS = 16;\nexport const MAX_PROVENANCE_FINDINGS = 12;\nexport const MAX_PROVENANCE_HTML_BYTES = 200_000;\nexport const MAX_PROVENANCE_INPUT_BYTES = 1_000_000;\nexport const MAX_PROVENANCE_DECLARATIONS = 48;\n\nexport interface ReferenceEvidence {\n id: string;\n url: string;\n}\nexport interface DatasetEvidence {\n id: string;\n version?: string;\n as_of?: string;\n max_age_days?: number;\n methodology_id?: string;\n}\nexport interface MethodologyEvidence {\n id: string;\n url: string;\n}\nexport interface ProvenanceManifest {\n /** The caller's reference date, not an independently checked wall clock. */\n as_of?: string;\n sources?: ReferenceEvidence[];\n datasets?: DatasetEvidence[];\n methodologies?: MethodologyEvidence[];\n}\nexport interface CitationDeclaration {\n id?: string;\n url?: string;\n}\nexport interface DatasetDeclaration {\n id?: string;\n version?: string;\n as_of?: string;\n methodology_id?: string;\n}\nexport interface MethodologyDeclaration {\n id?: string;\n url?: string;\n}\nexport interface ProvenanceObservation {\n url: string;\n citations: CitationDeclaration[];\n datasets: DatasetDeclaration[];\n methodologies: MethodologyDeclaration[];\n published_dates: string[];\n modified_dates: string[];\n invalid_dates: number;\n declarations_truncated: boolean;\n eligible: boolean;\n}\n\nexport type ProvenanceCode =\n | \"citation_id_target_conflict\"\n | \"citation_target_differs_from_supplied_evidence\"\n | \"citation_reference_unverified\"\n | \"dataset_version_conflict\"\n | \"dataset_as_of_conflict\"\n | \"dataset_reference_unverified\"\n | \"dataset_snapshot_in_future\"\n | \"dataset_freshness_window_exceeded\"\n | \"methodology_link_conflict\"\n | \"methodology_id_conflict\"\n | \"methodology_reference_unverified\"\n | \"invalid_date_declarations\"\n | \"published_dates_inconsistent\"\n | \"modified_dates_inconsistent\"\n | \"modified_before_published\"\n | \"publication_after_reference_date\";\n\nexport interface ProvenanceFinding {\n code: ProvenanceCode;\n severity: \"warning\" | \"info\";\n evidence: \"observed_html\" | \"supplied_manifest\" | \"reference_date\";\n page_url: string;\n reference_id?: string;\n message: string;\n}\nexport interface ProvenanceResult {\n scope: \"supplied_static_html_and_evidence\";\n pages_sampled: number;\n pages_eligible: number;\n citations_observed: number;\n datasets_observed: number;\n methodologies_observed: number;\n checked_declarations: number;\n consistent_declarations: number;\n conflicting_declarations: number;\n unverified_declarations: number;\n invalid_date_declarations: number;\n evidence_supplied: boolean;\n coverage_limited: boolean;\n limitations: string[];\n total_findings: number;\n findings: ProvenanceFinding[];\n findings_truncated: boolean;\n}\n\n/** Strict safe labels for references, no query, fragment or credential leakage. */\nexport function safeProvenanceUrl(raw: string): string | undefined {\n if (!raw || raw.length > 512) return undefined;\n try {\n const url = new URL(raw);\n if ((url.protocol !== \"https:\" && url.protocol !== \"http:\") || url.username ||\n url.password || url.search || url.hash || url.port || !url.hostname) return undefined;\n return url.href;\n } catch {\n return undefined;\n }\n}\nexport function safeProvenanceId(raw: string): string | undefined {\n return raw.length <= 64 && /^[a-zA-Z][a-zA-Z0-9._:-]*$/.test(raw) ? raw : undefined;\n}\nexport function safeDatasetVersion(raw: string): string | undefined {\n return raw.length <= 64 && /^[a-zA-Z0-9][a-zA-Z0-9 ._+-]*$/.test(raw) ? raw : undefined;\n}\n\n/**\n * Calendar-valid YYYY-MM-DD or a timezone-qualified ISO timestamp. Dates from\n * timestamps are compared by UTC day to avoid local machine timezone drift.\n */\nexport function normalizedEvidenceDate(raw: string): string | undefined {\n if (raw.length > 48) return undefined;\n const day = /^(\\d{4})-(\\d{2})-(\\d{2})$/.exec(raw);\n if (day) {\n const year = Number(day[1]);\n const month = Number(day[2]);\n const date = Number(day[3]);\n const timestamp = new Date(Date.UTC(year, month - 1, date));\n // Date.UTC treats years 00-99 specially. Use explicit full UTC year.\n timestamp.setUTCFullYear(year);\n if (timestamp.getUTCFullYear() !== year ||\n timestamp.getUTCMonth() + 1 !== month || timestamp.getUTCDate() !== date) return undefined;\n return day[0];\n }\n if (!/^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d{1,3})?(?:Z|[+-]\\d{2}:\\d{2})$/.test(raw)) {\n return undefined;\n }\n // Reject impossible calendar days and time/offset fields, not Date.parse's\n // permissive overflow normalization.\n const match = /^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})/.exec(raw)!;\n if (!normalizedEvidenceDate(match.slice(1, 4).join(\"-\")) ||\n Number(match[4]) > 23 || Number(match[5]) > 59 || Number(match[6]) > 59) return undefined;\n const zone = raw.endsWith(\"Z\") ? undefined : /([+-])(\\d{2}):(\\d{2})$/.exec(raw);\n if (zone && (Number(zone[2]) > 23 || Number(zone[3]) > 59)) return undefined;\n const parsed = Date.parse(raw);\n return Number.isFinite(parsed) ? new Date(parsed).toISOString().slice(0, 10) : undefined;\n}\n\nfunction uniqueDateValues(values: readonly string[]): string[] {\n return [...new Set(values.filter((value) => normalizedEvidenceDate(value) !== undefined)\n .map((value) => normalizedEvidenceDate(value)!))].sort();\n}\nfunction daysBetween(from: string, to: string): number {\n return Math.round((Date.parse(to + \"T00:00:00Z\") -\n Date.parse(from + \"T00:00:00Z\")) / 86_400_000);\n}\n\n/**\n * Supports incomplete evidence. An unknown identifier remains unverified;\n * disagreement against an explicitly supplied entry is a disagreement with\n * that entry, not proof that the underlying publication is untruthful.\n */\nexport function analyzeProvenance(\n observations: readonly ProvenanceObservation[],\n manifest: ProvenanceManifest = {},\n options: { sampledPages?: number; coverageLimited?: boolean } = {},\n): ProvenanceResult {\n if (observations.length > MAX_PROVENANCE_PAGES) {\n throw new Error(\"Provenance comparison accepts at most eight page observations.\");\n }\n const pagesSampled = options.sampledPages ?? observations.length;\n if (!Number.isSafeInteger(pagesSampled) ||\n pagesSampled < observations.length || pagesSampled > MAX_PROVENANCE_PAGES) {\n throw new Error(\"sampledPages must be between observed pages and eight.\");\n }\n if ((manifest.sources?.length ?? 0) > MAX_PROVENANCE_SOURCES ||\n (manifest.datasets?.length ?? 0) > MAX_PROVENANCE_DATASETS ||\n (manifest.methodologies?.length ?? 0) > MAX_PROVENANCE_METHODS) {\n throw new Error(\"Supplied evidence exceeds the bounded manifest limits.\");\n }\n for (const [kind, entries] of [\n [\"sources\", manifest.sources ?? []],\n [\"datasets\", manifest.datasets ?? []],\n [\"methodologies\", manifest.methodologies ?? []],\n ] as const) {\n const ids = entries.map((entry) => entry.id);\n if (new Set(ids).size !== ids.length) {\n throw new Error(\"Duplicate \" + kind + \" IDs make the supplied evidence ambiguous.\");\n }\n }\n const referenceDate = manifest.as_of ? normalizedEvidenceDate(manifest.as_of) : undefined;\n if (manifest.as_of && !referenceDate) throw new Error(\"Manifest as_of must be a valid date.\");\n for (const ds of manifest.datasets ?? []) {\n if (ds.as_of && !normalizedEvidenceDate(ds.as_of)) {\n throw new Error(\"Dataset evidence as_of must be a valid date.\");\n }\n }\n const sources = new Map((manifest.sources ?? []).map((value) => [value.id, value]));\n const datasets = new Map((manifest.datasets ?? []).map((value) => [value.id, value]));\n const methods = new Map((manifest.methodologies ?? []).map((value) => [value.id, value]));\n const provided = sources.size + datasets.size + methods.size > 0;\n const findings: ProvenanceFinding[] = [];\n let seenCount = 0;\n let checked = 0;\n let consistent = 0;\n let conflicts = 0;\n let unverified = 0;\n let citationTotal = 0;\n let datasetTotal = 0;\n let methodTotal = 0;\n let badDates = 0;\n const eligible = new Map<string, ProvenanceObservation>();\n for (const item of observations) {\n const url = safeProvenanceUrl(item.url);\n if (url && item.eligible && !eligible.has(url)) eligible.set(url, item);\n }\n function report(code: ProvenanceCode, severity: ProvenanceFinding[\"severity\"],\n evidence: ProvenanceFinding[\"evidence\"], page: string, message: string,\n ref?: string) {\n const finding: ProvenanceFinding = {\n code, severity, evidence, page_url: page,\n ...(ref && safeProvenanceId(ref) ? { reference_id: ref } : {}),\n message,\n };\n findings.push(finding);\n }\n // One id intentionally pointing to two sanitized URLs is directly\n // inconsistent even when the optional manifest is absent.\n const observedSourceTargets = new Map<string, string>();\n for (const [pageUrl, page] of eligible) {\n seenCount += 1;\n citationTotal += page.citations.length;\n datasetTotal += page.datasets.length;\n methodTotal += page.methodologies.length;\n badDates += page.invalid_dates;\n if (page.invalid_dates) {\n checked += page.invalid_dates;\n conflicts += page.invalid_dates;\n report(\"invalid_date_declarations\", \"warning\", \"observed_html\", pageUrl,\n \"One or more explicit publication, modification or dataset date declarations are not valid ISO calendar dates.\");\n }\n if (page.declarations_truncated) {\n unverified += 1;\n }\n const published = uniqueDateValues(page.published_dates);\n const modified = uniqueDateValues(page.modified_dates);\n if (published.length > 1) {\n checked += 1;\n conflicts += 1;\n report(\"published_dates_inconsistent\", \"warning\", \"observed_html\", pageUrl,\n \"This page declares different publication dates in its explicit structured signals.\");\n }\n if (modified.length > 1) {\n checked += 1;\n conflicts += 1;\n report(\"modified_dates_inconsistent\", \"warning\", \"observed_html\", pageUrl,\n \"This page declares different modification dates in its explicit structured signals.\");\n }\n if (published.length === 1 && modified.length === 1) {\n checked += 1;\n if (modified[0] < published[0]) {\n conflicts += 1;\n report(\"modified_before_published\", \"warning\", \"observed_html\", pageUrl,\n \"The declared modification date precedes the publication date.\");\n } else consistent += 1;\n }\n if (referenceDate) {\n for (const date of [...published, ...modified]) {\n checked += 1;\n if (date > referenceDate) {\n conflicts += 1;\n report(\"publication_after_reference_date\", \"warning\", \"reference_date\", pageUrl,\n \"An explicit publication or modification date is later than the caller-supplied reference day.\");\n } else consistent += 1;\n }\n }\n for (const cite of page.citations) {\n const id = cite.id && safeProvenanceId(cite.id);\n const target = cite.url && safeProvenanceUrl(cite.url);\n const source = id && sources.get(id);\n if (id && target) {\n const previous = observedSourceTargets.get(id);\n if (previous && previous !== target) {\n checked += 1;\n conflicts += 1;\n report(\"citation_id_target_conflict\", \"warning\", \"observed_html\", pageUrl,\n \"The same citation ID is assigned different safe target URLs in the compared page sample.\", id);\n } else if (!previous) observedSourceTargets.set(id, target);\n }\n checked += 1;\n if (source && target) {\n const declared = safeProvenanceUrl(source.url);\n if (declared && target === declared) consistent += 1;\n else if (declared) {\n conflicts += 1;\n report(\"citation_target_differs_from_supplied_evidence\", \"warning\",\n \"supplied_manifest\", pageUrl, \"The citation target differs from the URL for this ID in the supplied evidence.\", id);\n } else {\n unverified += 1;\n report(\"citation_reference_unverified\", \"info\", \"supplied_manifest\", pageUrl,\n \"The supplied source URL cannot be compared safely.\", id);\n }\n } else if (target && !id && [...sources.values()].some((item) => safeProvenanceUrl(item.url) === target)) {\n consistent += 1;\n } else {\n unverified += 1;\n report(\"citation_reference_unverified\", \"info\", \"supplied_manifest\", pageUrl,\n \"This citation has no matching safe target or entry in the optional supplied source evidence.\", id || undefined);\n }\n }\n for (const claim of page.datasets) {\n const id = claim.id && safeProvenanceId(claim.id);\n const evidence = id ? datasets.get(id) : undefined;\n if (!id || !evidence) {\n checked += 1;\n unverified += 1;\n report(\"dataset_reference_unverified\", \"info\", \"supplied_manifest\", pageUrl,\n \"This dataset claim has no matching identifier in the optional supplied dataset evidence.\", id || undefined);\n continue;\n }\n if (claim.version) {\n checked += 1;\n if (!evidence.version) unverified += 1;\n else if (evidence.version === claim.version) consistent += 1;\n else {\n conflicts += 1;\n report(\"dataset_version_conflict\", \"warning\", \"supplied_manifest\", pageUrl,\n \"The claimed dataset version differs from the version supplied for the same dataset ID.\", id);\n }\n }\n if (claim.as_of) {\n checked += 1;\n const observed = normalizedEvidenceDate(claim.as_of);\n const declared = evidence.as_of && normalizedEvidenceDate(evidence.as_of);\n if (!observed) {\n // Already counted as an invalid date by the extractor.\n unverified += 1;\n } else if (declared) {\n if (observed === declared) consistent += 1;\n else {\n conflicts += 1;\n report(\"dataset_as_of_conflict\", \"warning\", \"supplied_manifest\", pageUrl,\n \"The claimed dataset snapshot day differs from the supplied snapshot day for that ID.\", id);\n }\n } else unverified += 1;\n if (observed && referenceDate) {\n checked += 1;\n if (observed > referenceDate) {\n conflicts += 1;\n report(\"dataset_snapshot_in_future\", \"warning\", \"reference_date\", pageUrl,\n \"The claimed snapshot date is later than the caller-supplied reference day.\", id);\n } else consistent += 1;\n if (evidence.max_age_days !== undefined && observed <= referenceDate) {\n checked += 1;\n if (daysBetween(observed, referenceDate) > evidence.max_age_days) {\n conflicts += 1;\n report(\"dataset_freshness_window_exceeded\", \"warning\", \"supplied_manifest\", pageUrl,\n \"The snapshot age exceeds the explicitly supplied freshness window; review whether a newer release exists.\", id);\n } else consistent += 1;\n }\n }\n }\n if (claim.methodology_id) {\n checked += 1;\n if (!evidence.methodology_id) unverified += 1;\n else if (evidence.methodology_id === claim.methodology_id) consistent += 1;\n else {\n conflicts += 1;\n report(\"methodology_id_conflict\", \"warning\", \"supplied_manifest\", pageUrl,\n \"The claimed methodology ID differs from the methodology ID supplied for this dataset.\", id);\n }\n }\n if (!claim.version && !claim.as_of && !claim.methodology_id) {\n checked += 1;\n unverified += 1;\n }\n }\n for (const method of page.methodologies) {\n const id = method.id && safeProvenanceId(method.id);\n const supplied = id ? methods.get(id) : undefined;\n checked += 1;\n if (supplied && method.url) {\n const actual = safeProvenanceUrl(method.url);\n const expected = safeProvenanceUrl(supplied.url);\n if (actual && expected) {\n if (actual === expected) consistent += 1;\n else {\n conflicts += 1;\n report(\"methodology_link_conflict\", \"warning\", \"supplied_manifest\", pageUrl,\n \"The methodology URL differs from the URL supplied for this methodology ID.\", id);\n }\n } else unverified += 1;\n } else {\n unverified += 1;\n report(\"methodology_reference_unverified\", \"info\", \"supplied_manifest\", pageUrl,\n \"No comparable methodology URL was supplied for this explicit methodology reference.\", id || undefined);\n }\n }\n }\n // Prefer observed contradictions over the potentially numerous informative\n // unresolved references. Keep deterministic ordering and true total counts.\n findings.sort((a, b) =>\n (a.severity === \"warning\" ? 0 : 1) - (b.severity === \"warning\" ? 0 : 1) ||\n a.code.localeCompare(b.code) || a.page_url.localeCompare(b.page_url) ||\n (a.reference_id ?? \"\").localeCompare(b.reference_id ?? \"\"));\n const extractionLimited = [...eligible.values()].some((page) => page.declarations_truncated);\n const incomplete = pagesSampled !== eligible.size || extractionLimited ||\n Boolean(options.coverageLimited) || !provided || unverified > 0;\n return {\n scope: \"supplied_static_html_and_evidence\",\n pages_sampled: pagesSampled, pages_eligible: eligible.size,\n citations_observed: citationTotal,\n datasets_observed: datasetTotal,\n methodologies_observed: methodTotal,\n checked_declarations: checked,\n consistent_declarations: consistent,\n conflicting_declarations: conflicts,\n unverified_declarations: unverified,\n invalid_date_declarations: badDates,\n evidence_supplied: provided,\n coverage_limited: incomplete,\n limitations: [\n \"Only supplied static HTML and optional caller-supplied evidence are compared; source URLs, DOI resolution, factual accuracy and current datasets are not independently fetched or verified.\",\n \"A matched reference ID/URL verifies agreement with the supplied manifest, not authenticity, licensing, scientific correctness, freshness in the real world or Google search decisions.\",\n ...(!provided ? [\"No source/dataset/methodology manifest was supplied; unsupported references remain unverified.\"] : []),\n ...(extractionLimited || pagesSampled !== eligible.size || options.coverageLimited\n ? [\"The input or extraction sample is incomplete; findings must not be interpreted as site-wide coverage.\"] : []),\n ],\n total_findings: findings.length,\n findings: findings.slice(0, MAX_PROVENANCE_FINDINGS),\n findings_truncated: findings.length > MAX_PROVENANCE_FINDINGS,\n };\n}\n"]}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* P1-06: evidence-limited competitor search-intent comparison.
|
|
3
|
+
*
|
|
4
|
+
* This module compares only static HTML that the caller already has the right
|
|
5
|
+
* to supply. It cannot discover competitor pages, query Google/analytics, or
|
|
6
|
+
* determine Google's interpretation, rankings, page usefulness or relevance.
|
|
7
|
+
*/
|
|
8
|
+
export type SearchIntent = "informational" | "commercial" | "transactional" | "navigational";
|
|
9
|
+
export declare const INTENTS: readonly ["informational", "commercial", "transactional", "navigational"];
|
|
10
|
+
export declare const MAX_INTENT_COMPETITORS = 6;
|
|
11
|
+
export declare const MAX_INTENT_HTML_BYTES = 150000;
|
|
12
|
+
export declare const MAX_INTENT_TOTAL_BYTES = 800000;
|
|
13
|
+
export declare const MAX_INTENT_FINDINGS = 10;
|
|
14
|
+
export declare const MAX_INTENT_QUERY_BYTES = 160;
|
|
15
|
+
export declare const SIGNALS: {
|
|
16
|
+
readonly informational: readonly ["article_schema", "faq_schema", "howto_schema", "editorial_sections"];
|
|
17
|
+
readonly commercial: readonly ["product_schema", "review_schema", "comparison_heading", "pricing_heading"];
|
|
18
|
+
readonly transactional: readonly ["offer_schema", "checkout_link", "purchase_action", "purchase_form"];
|
|
19
|
+
readonly navigational: readonly ["contact_heading", "main_contact_link", "main_address"];
|
|
20
|
+
};
|
|
21
|
+
type Signals = Record<SearchIntent, string[]>;
|
|
22
|
+
export type IntentCode = "primary_intent_signal_gap" | "primary_heading_query_gap" | "primary_missing_headings" | "no_explicit_intent_evidence" | "incomplete_competitor_sample" | "ambiguous_query_terms";
|
|
23
|
+
export interface IntentObservation {
|
|
24
|
+
url: string;
|
|
25
|
+
title: string;
|
|
26
|
+
h1: string;
|
|
27
|
+
signals: Signals;
|
|
28
|
+
eligible: boolean;
|
|
29
|
+
extraction_limited: boolean;
|
|
30
|
+
main_found: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface IntentPageEvidence {
|
|
33
|
+
origin: string;
|
|
34
|
+
title_present: boolean;
|
|
35
|
+
h1_present: boolean;
|
|
36
|
+
main_found: boolean;
|
|
37
|
+
signals: Signals;
|
|
38
|
+
signal_counts: Record<SearchIntent, number>;
|
|
39
|
+
intent_signal_count?: number;
|
|
40
|
+
query_title_coverage_percent?: number;
|
|
41
|
+
query_h1_coverage_percent?: number;
|
|
42
|
+
extraction_limited: boolean;
|
|
43
|
+
}
|
|
44
|
+
export interface IntentFinding {
|
|
45
|
+
code: IntentCode;
|
|
46
|
+
severity: "warning" | "info";
|
|
47
|
+
confidence: "observed" | "review";
|
|
48
|
+
message: string;
|
|
49
|
+
competitors_supporting?: number;
|
|
50
|
+
}
|
|
51
|
+
export interface IntentComparison {
|
|
52
|
+
scope: "caller_supplied_static_html_only";
|
|
53
|
+
expected_intent?: SearchIntent;
|
|
54
|
+
query_supplied: boolean;
|
|
55
|
+
usable_query_terms: number;
|
|
56
|
+
primary: IntentPageEvidence;
|
|
57
|
+
competitors: IntentPageEvidence[];
|
|
58
|
+
competitors_submitted: number;
|
|
59
|
+
competitors_eligible: number;
|
|
60
|
+
competitors_with_intent_signals: number;
|
|
61
|
+
coverage_limited: boolean;
|
|
62
|
+
limitations: string[];
|
|
63
|
+
total_findings: number;
|
|
64
|
+
findings: IntentFinding[];
|
|
65
|
+
findings_truncated: boolean;
|
|
66
|
+
}
|
|
67
|
+
export declare function emptyIntentComparison(): IntentComparison;
|
|
68
|
+
export declare function safeIntentUrl(raw: string): string | undefined;
|
|
69
|
+
export declare function queryKeywords(query?: string): string[];
|
|
70
|
+
export declare function compareIntentObservations(primary: IntentObservation, competitors: readonly IntentObservation[], options?: {
|
|
71
|
+
expectedIntent?: SearchIntent;
|
|
72
|
+
query?: string;
|
|
73
|
+
}): IntentComparison;
|
|
74
|
+
export {};
|