mcp-web-validator 1.3.51 → 1.3.54
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 +55 -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/mcp-bounds.js +8 -3
- package/dist/mcp-bounds.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 +316 -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 +273 -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 +25 -8
- 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,195 @@
|
|
|
1
|
+
export const MAX_PRODUCT_CLAIM_HTML_BYTES = 250_000;
|
|
2
|
+
export const MAX_PRODUCT_CLAIM_TOOLS = 20;
|
|
3
|
+
export const MAX_PRODUCT_CLAIM_FINDINGS = 10;
|
|
4
|
+
const MAX_CATALOG_TOOLS = 64;
|
|
5
|
+
const MAX_TOOL_ID_CHARS = 64;
|
|
6
|
+
export function isPublicToolName(value) {
|
|
7
|
+
return value.length > 2 && value.length <= MAX_TOOL_ID_CHARS &&
|
|
8
|
+
/^[a-z][a-z0-9]*(?:[._][a-z0-9]+)+$/.test(value);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Take a snapshot of the SDK's runtime registration map. The Zod-to-JSON
|
|
12
|
+
* converter is supplied by each runtime, avoiding dependencies in this core.
|
|
13
|
+
* Missing metadata stays unknown; it must never become a fabricated limit.
|
|
14
|
+
*/
|
|
15
|
+
export function registeredToolEvidence(registrations, toJsonSchema) {
|
|
16
|
+
if (!registrations || typeof registrations !== "object")
|
|
17
|
+
return [];
|
|
18
|
+
const entries = Object.entries(registrations);
|
|
19
|
+
if (entries.length > MAX_CATALOG_TOOLS)
|
|
20
|
+
return [];
|
|
21
|
+
const tools = [];
|
|
22
|
+
for (const [name, raw] of entries) {
|
|
23
|
+
if (!isPublicToolName(name) || !raw || typeof raw !== "object")
|
|
24
|
+
continue;
|
|
25
|
+
const record = raw;
|
|
26
|
+
if (record.enabled === false)
|
|
27
|
+
continue;
|
|
28
|
+
const value = { name };
|
|
29
|
+
const annotations = record.annotations;
|
|
30
|
+
if (annotations && typeof annotations === "object") {
|
|
31
|
+
const hint = annotations.readOnlyHint;
|
|
32
|
+
if (typeof hint === "boolean")
|
|
33
|
+
value.readOnlyHint = hint;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const schema = toJsonSchema(record.inputSchema);
|
|
37
|
+
if (schema && typeof schema === "object") {
|
|
38
|
+
const properties = schema.properties;
|
|
39
|
+
if (properties && typeof properties === "object") {
|
|
40
|
+
const object = properties;
|
|
41
|
+
for (const [property, key] of [
|
|
42
|
+
["max_pages", "maxPages"], ["max_links", "maxLinks"],
|
|
43
|
+
]) {
|
|
44
|
+
const element = object[property];
|
|
45
|
+
if (!element || typeof element !== "object")
|
|
46
|
+
continue;
|
|
47
|
+
const maximum = element.maximum;
|
|
48
|
+
if (typeof maximum === "number" && Number.isSafeInteger(maximum) &&
|
|
49
|
+
maximum > 0 && maximum < 100_000)
|
|
50
|
+
value[key] = maximum;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
// SDK/Zod versions differ in JSON-schema support; absence is unverified.
|
|
57
|
+
}
|
|
58
|
+
tools.push(value);
|
|
59
|
+
}
|
|
60
|
+
return tools;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* This check establishes registry consistency only. Do not invent tool
|
|
64
|
+
* behavior, credentials, live health, data-access rights, or page quality.
|
|
65
|
+
*/
|
|
66
|
+
export function compareProductClaims(observation, registered, surface) {
|
|
67
|
+
const catalogAvailable = registered.length > 0 && registered.length <= MAX_CATALOG_TOOLS;
|
|
68
|
+
const known = new Map(registered.filter((tool) => isPublicToolName(tool.name))
|
|
69
|
+
.map((tool) => [tool.name, tool]));
|
|
70
|
+
const claimed = surface === "hosted" ? observation.hostedTools : observation.localTools;
|
|
71
|
+
const advertisedTools = [...new Set(claimed)].slice(0, MAX_PRODUCT_CLAIM_TOOLS)
|
|
72
|
+
.filter(isPublicToolName).map((name) => ({ name, registered: known.has(name) }));
|
|
73
|
+
const findings = [];
|
|
74
|
+
let checked = 0;
|
|
75
|
+
let consistent = 0;
|
|
76
|
+
let contradicted = 0;
|
|
77
|
+
let unverified = 0;
|
|
78
|
+
function count(verdict, finding) {
|
|
79
|
+
checked += 1;
|
|
80
|
+
if (verdict === "consistent")
|
|
81
|
+
consistent += 1;
|
|
82
|
+
else if (verdict === "contradicted")
|
|
83
|
+
contradicted += 1;
|
|
84
|
+
else
|
|
85
|
+
unverified += 1;
|
|
86
|
+
if (finding)
|
|
87
|
+
findings.push(finding);
|
|
88
|
+
}
|
|
89
|
+
for (const { name, registered: exists } of advertisedTools) {
|
|
90
|
+
if (!catalogAvailable) {
|
|
91
|
+
count("unverifiable");
|
|
92
|
+
}
|
|
93
|
+
else if (exists) {
|
|
94
|
+
count("consistent");
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
count("contradicted", {
|
|
98
|
+
code: "product.tool_missing", severity: "warning", verdict: "contradicted",
|
|
99
|
+
claim: name, evidence_tool: name,
|
|
100
|
+
message: "The landing page lists this MCP tool but it is absent from the current runtime tool registry.",
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
let siteBatchLimit;
|
|
105
|
+
if (surface === "hosted" && observation.siteBatchLimit !== undefined) {
|
|
106
|
+
const advertised = observation.siteBatchLimit;
|
|
107
|
+
const actual = known.get("audit_public_site")?.maxPages;
|
|
108
|
+
siteBatchLimit = { advertised, ...(actual ? { registered: actual } : {}) };
|
|
109
|
+
if (!catalogAvailable || !actual)
|
|
110
|
+
count("unverifiable", {
|
|
111
|
+
code: "product.site_batch_limit_unknown", severity: "info", verdict: "unverifiable",
|
|
112
|
+
claim: "site batch limit", evidence_tool: "audit_public_site",
|
|
113
|
+
message: "The advertised site-batch size cannot be checked against the registered tool input-schema maximum.",
|
|
114
|
+
});
|
|
115
|
+
else if (advertised > actual)
|
|
116
|
+
count("contradicted", {
|
|
117
|
+
code: "product.site_batch_overclaim", severity: "warning", verdict: "contradicted",
|
|
118
|
+
claim: "site batch limit", evidence_tool: "audit_public_site",
|
|
119
|
+
message: "The advertised site-batch size exceeds the maximum accepted by the registered MCP tool.",
|
|
120
|
+
});
|
|
121
|
+
else
|
|
122
|
+
count("consistent");
|
|
123
|
+
}
|
|
124
|
+
if (surface === "local" && observation.localScreenshotClaim) {
|
|
125
|
+
if (!catalogAvailable)
|
|
126
|
+
count("unverifiable");
|
|
127
|
+
else if (known.has("screenshot.capture"))
|
|
128
|
+
count("consistent");
|
|
129
|
+
else
|
|
130
|
+
count("contradicted", {
|
|
131
|
+
code: "product.local_screenshot_unverified", severity: "warning",
|
|
132
|
+
verdict: "contradicted", claim: "local responsive screenshots",
|
|
133
|
+
evidence_tool: "screenshot.capture",
|
|
134
|
+
message: "The landing page promises local screenshots, but the screenshot capture tool is not registered.",
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
if (surface === "hosted" && observation.hostedNoScreenshotsClaim) {
|
|
138
|
+
if (!catalogAvailable)
|
|
139
|
+
count("unverifiable");
|
|
140
|
+
else if (!known.has("screenshot.capture"))
|
|
141
|
+
count("consistent");
|
|
142
|
+
else
|
|
143
|
+
count("contradicted", {
|
|
144
|
+
code: "product.hosted_screenshot_conflict", severity: "warning",
|
|
145
|
+
verdict: "contradicted", claim: "hosted screenshots unavailable",
|
|
146
|
+
evidence_tool: "screenshot.capture",
|
|
147
|
+
message: "The landing page excludes hosted screenshot capture, but the hosted runtime registers a screenshot tool.",
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
if (surface === "hosted" && observation.hostedReadOnlyClaim) {
|
|
151
|
+
if (!catalogAvailable || registered.some((tool) => tool.readOnlyHint === undefined)) {
|
|
152
|
+
count("unverifiable", {
|
|
153
|
+
code: "product.read_only_unverified", severity: "info", verdict: "unverifiable",
|
|
154
|
+
claim: "hosted tools read-only",
|
|
155
|
+
message: "The registered MCP tools do not all declare read-only metadata, so this promise needs behavioral review.",
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
else if (registered.some((tool) => tool.readOnlyHint !== true)) {
|
|
159
|
+
count("contradicted", {
|
|
160
|
+
code: "product.read_only_conflict", severity: "warning", verdict: "contradicted",
|
|
161
|
+
claim: "hosted tools read-only",
|
|
162
|
+
message: "At least one hosted tool advertises a non-read-only annotation; reconcile the landing-page promise.",
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
else
|
|
166
|
+
count("consistent");
|
|
167
|
+
}
|
|
168
|
+
const sectionFound = surface === "hosted"
|
|
169
|
+
? observation.hostedSectionFound : observation.localSectionFound;
|
|
170
|
+
const coverageLimited = !catalogAvailable || !observation.hasMain
|
|
171
|
+
|| observation.extractionTruncated || !sectionFound
|
|
172
|
+
|| checked === 0 || unverified > 0;
|
|
173
|
+
const limitations = [
|
|
174
|
+
"Only explicit tool names and selected bounded/surface promises are checked against observed MCP registration metadata, not arbitrary marketing semantics.",
|
|
175
|
+
"Registration and input-schema compatibility do NOT prove a successful tool call, live service health, screenshots, Google indexing, or functional correctness.",
|
|
176
|
+
...(!sectionFound ? ["No explicit tool listing for this runtime was found in the visible main-content section."] : []),
|
|
177
|
+
...(!catalogAvailable ? ["Runtime tool-registration metadata is unavailable; unsupported claims cannot be determined."] : []),
|
|
178
|
+
...(observation.extractionTruncated ? ["The landing-page claim extraction reached its hard limit; some claims were not checked."] : []),
|
|
179
|
+
];
|
|
180
|
+
const ordered = findings.sort((a, b) => (a.severity === "warning" ? 0 : 1)
|
|
181
|
+
- (b.severity === "warning" ? 0 : 1) || a.code.localeCompare(b.code) || a.claim.localeCompare(b.claim));
|
|
182
|
+
return {
|
|
183
|
+
scope: "landing_html_vs_registered_mcp_metadata",
|
|
184
|
+
surface, catalog_available: catalogAvailable, registered_tools: registered.length,
|
|
185
|
+
tool_claims_checked: advertisedTools.length, checked_claims: checked,
|
|
186
|
+
consistent_claims: consistent, contradicted_claims: contradicted,
|
|
187
|
+
unverified_claims: unverified, advertised_tools: advertisedTools,
|
|
188
|
+
...(siteBatchLimit ? { site_batch_limit: siteBatchLimit } : {}),
|
|
189
|
+
coverage_limited: coverageLimited,
|
|
190
|
+
limitations, total_findings: ordered.length,
|
|
191
|
+
findings: ordered.slice(0, MAX_PRODUCT_CLAIM_FINDINGS),
|
|
192
|
+
findings_truncated: ordered.length > MAX_PRODUCT_CLAIM_FINDINGS,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=product-claims.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product-claims.js","sourceRoot":"","sources":["../../../src/modules/content-schema/product-claims.ts"],"names":[],"mappings":"AAiEA,MAAM,CAAC,MAAM,4BAA4B,GAAG,OAAO,CAAC;AACpD,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAC1C,MAAM,CAAC,MAAM,0BAA0B,GAAG,EAAE,CAAC;AAC7C,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAC7B,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAE7B,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC5C,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,MAAM,IAAI,iBAAiB;QAC1D,oCAAoC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACrD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CACpC,aAAsB,EACtB,YAA0C;IAE1C,IAAI,CAAC,aAAa,IAAI,OAAO,aAAa,KAAK,QAAQ;QAAE,OAAO,EAAE,CAAC;IACnE,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,aAAwC,CAAC,CAAC;IACzE,IAAI,OAAO,CAAC,MAAM,GAAG,iBAAiB;QAAE,OAAO,EAAE,CAAC;IAClD,MAAM,KAAK,GAA0B,EAAE,CAAC;IACxC,KAAK,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,OAAO,EAAE,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;QACjC,WAAW,EAAE,cAAc,EAAE,OAAO,CAAC,MAAM;QAC3C,QAAQ,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,0BAA0B,CAAC;QACtD,kBAAkB,EAAE,OAAO,CAAC,MAAM,GAAG,0BAA0B;KAChE,CAAC;AACJ,CAAC","sourcesContent":["/**\n * P1-04: explicit first-party landing-page promises versus the MCP runtime's\n * actual registered tool metadata. This intentionally does not claim that a\n * listed tool has succeeded on a particular URL or that prose can be judged\n * semantically from a few keywords.\n */\nexport type ProductSurface = \"hosted\" | \"local\";\n\nexport interface ToolCatalogEvidence {\n name: string;\n readOnlyHint?: boolean;\n maxPages?: number;\n maxLinks?: number;\n}\n\nexport interface ProductClaimObservation {\n hasMain: boolean;\n hostedSectionFound: boolean;\n localSectionFound: boolean;\n hostedTools: string[];\n localTools: string[];\n siteBatchLimit?: number;\n localScreenshotClaim: boolean;\n hostedReadOnlyClaim: boolean;\n hostedNoScreenshotsClaim: boolean;\n extractionTruncated: boolean;\n}\n\nexport type ProductClaimCode =\n | \"product.tool_missing\"\n | \"product.site_batch_overclaim\"\n | \"product.site_batch_limit_unknown\"\n | \"product.local_screenshot_unverified\"\n | \"product.hosted_screenshot_conflict\"\n | \"product.read_only_conflict\"\n | \"product.read_only_unverified\";\n\nexport interface ProductClaimFinding {\n code: ProductClaimCode;\n severity: \"warning\" | \"info\";\n verdict: \"contradicted\" | \"unverifiable\";\n claim: string;\n message: string;\n evidence_tool?: string;\n}\n\nexport interface ProductClaimResult {\n scope: \"landing_html_vs_registered_mcp_metadata\";\n surface: ProductSurface;\n catalog_available: boolean;\n registered_tools: number;\n tool_claims_checked: number;\n checked_claims: number;\n consistent_claims: number;\n contradicted_claims: number;\n unverified_claims: number;\n advertised_tools: Array<{ name: string; registered: boolean }>;\n site_batch_limit?: { advertised: number; registered?: number };\n coverage_limited: boolean;\n limitations: string[];\n total_findings: number;\n findings: ProductClaimFinding[];\n findings_truncated: boolean;\n}\n\nexport const MAX_PRODUCT_CLAIM_HTML_BYTES = 250_000;\nexport const MAX_PRODUCT_CLAIM_TOOLS = 20;\nexport const MAX_PRODUCT_CLAIM_FINDINGS = 10;\nconst MAX_CATALOG_TOOLS = 64;\nconst MAX_TOOL_ID_CHARS = 64;\n\nexport function isPublicToolName(value: string): boolean {\n return value.length > 2 && value.length <= MAX_TOOL_ID_CHARS &&\n /^[a-z][a-z0-9]*(?:[._][a-z0-9]+)+$/.test(value);\n}\n\n/**\n * Take a snapshot of the SDK's runtime registration map. The Zod-to-JSON\n * converter is supplied by each runtime, avoiding dependencies in this core.\n * Missing metadata stays unknown; it must never become a fabricated limit.\n */\nexport function registeredToolEvidence(\n registrations: unknown,\n toJsonSchema: (schema: unknown) => unknown,\n): ToolCatalogEvidence[] {\n if (!registrations || typeof registrations !== \"object\") return [];\n const entries = Object.entries(registrations as Record<string, unknown>);\n if (entries.length > MAX_CATALOG_TOOLS) return [];\n const tools: ToolCatalogEvidence[] = [];\n for (const [name, raw] of entries) {\n if (!isPublicToolName(name) || !raw || typeof raw !== \"object\") continue;\n const record = raw as Record<string, unknown>;\n if (record.enabled === false) continue;\n const value: ToolCatalogEvidence = { name };\n const annotations = record.annotations;\n if (annotations && typeof annotations === \"object\") {\n const hint = (annotations as Record<string, unknown>).readOnlyHint;\n if (typeof hint === \"boolean\") value.readOnlyHint = hint;\n }\n try {\n const schema = toJsonSchema(record.inputSchema);\n if (schema && typeof schema === \"object\") {\n const properties = (schema as Record<string, unknown>).properties;\n if (properties && typeof properties === \"object\") {\n const object = properties as Record<string, unknown>;\n for (const [property, key] of [\n [\"max_pages\", \"maxPages\"], [\"max_links\", \"maxLinks\"],\n ] as const) {\n const element = object[property];\n if (!element || typeof element !== \"object\") continue;\n const maximum = (element as Record<string, unknown>).maximum;\n if (typeof maximum === \"number\" && Number.isSafeInteger(maximum) &&\n maximum > 0 && maximum < 100_000) value[key] = maximum;\n }\n }\n }\n } catch {\n // SDK/Zod versions differ in JSON-schema support; absence is unverified.\n }\n tools.push(value);\n }\n return tools;\n}\n\n/**\n * This check establishes registry consistency only. Do not invent tool\n * behavior, credentials, live health, data-access rights, or page quality.\n */\nexport function compareProductClaims(\n observation: ProductClaimObservation,\n registered: readonly ToolCatalogEvidence[],\n surface: ProductSurface,\n): ProductClaimResult {\n const catalogAvailable = registered.length > 0 && registered.length <= MAX_CATALOG_TOOLS;\n const known = new Map(registered.filter((tool) => isPublicToolName(tool.name))\n .map((tool) => [tool.name, tool]));\n const claimed = surface === \"hosted\" ? observation.hostedTools : observation.localTools;\n const advertisedTools = [...new Set(claimed)].slice(0, MAX_PRODUCT_CLAIM_TOOLS)\n .filter(isPublicToolName).map((name) => ({ name, registered: known.has(name) }));\n const findings: ProductClaimFinding[] = [];\n let checked = 0;\n let consistent = 0;\n let contradicted = 0;\n let unverified = 0;\n function count(verdict: \"consistent\" | \"contradicted\" | \"unverifiable\",\n finding?: ProductClaimFinding) {\n checked += 1;\n if (verdict === \"consistent\") consistent += 1;\n else if (verdict === \"contradicted\") contradicted += 1;\n else unverified += 1;\n if (finding) findings.push(finding);\n }\n for (const { name, registered: exists } of advertisedTools) {\n if (!catalogAvailable) {\n count(\"unverifiable\");\n } else if (exists) {\n count(\"consistent\");\n } else {\n count(\"contradicted\", {\n code: \"product.tool_missing\", severity: \"warning\", verdict: \"contradicted\",\n claim: name, evidence_tool: name,\n message: \"The landing page lists this MCP tool but it is absent from the current runtime tool registry.\",\n });\n }\n }\n\n let siteBatchLimit: ProductClaimResult[\"site_batch_limit\"];\n if (surface === \"hosted\" && observation.siteBatchLimit !== undefined) {\n const advertised = observation.siteBatchLimit;\n const actual = known.get(\"audit_public_site\")?.maxPages;\n siteBatchLimit = { advertised, ...(actual ? { registered: actual } : {}) };\n if (!catalogAvailable || !actual) count(\"unverifiable\", {\n code: \"product.site_batch_limit_unknown\", severity: \"info\", verdict: \"unverifiable\",\n claim: \"site batch limit\", evidence_tool: \"audit_public_site\",\n message: \"The advertised site-batch size cannot be checked against the registered tool input-schema maximum.\",\n });\n else if (advertised > actual) count(\"contradicted\", {\n code: \"product.site_batch_overclaim\", severity: \"warning\", verdict: \"contradicted\",\n claim: \"site batch limit\", evidence_tool: \"audit_public_site\",\n message: \"The advertised site-batch size exceeds the maximum accepted by the registered MCP tool.\",\n });\n else count(\"consistent\");\n }\n if (surface === \"local\" && observation.localScreenshotClaim) {\n if (!catalogAvailable) count(\"unverifiable\");\n else if (known.has(\"screenshot.capture\")) count(\"consistent\");\n else count(\"contradicted\", {\n code: \"product.local_screenshot_unverified\", severity: \"warning\",\n verdict: \"contradicted\", claim: \"local responsive screenshots\",\n evidence_tool: \"screenshot.capture\",\n message: \"The landing page promises local screenshots, but the screenshot capture tool is not registered.\",\n });\n }\n if (surface === \"hosted\" && observation.hostedNoScreenshotsClaim) {\n if (!catalogAvailable) count(\"unverifiable\");\n else if (!known.has(\"screenshot.capture\")) count(\"consistent\");\n else count(\"contradicted\", {\n code: \"product.hosted_screenshot_conflict\", severity: \"warning\",\n verdict: \"contradicted\", claim: \"hosted screenshots unavailable\",\n evidence_tool: \"screenshot.capture\",\n message: \"The landing page excludes hosted screenshot capture, but the hosted runtime registers a screenshot tool.\",\n });\n }\n if (surface === \"hosted\" && observation.hostedReadOnlyClaim) {\n if (!catalogAvailable || registered.some((tool) => tool.readOnlyHint === undefined)) {\n count(\"unverifiable\", {\n code: \"product.read_only_unverified\", severity: \"info\", verdict: \"unverifiable\",\n claim: \"hosted tools read-only\",\n message: \"The registered MCP tools do not all declare read-only metadata, so this promise needs behavioral review.\",\n });\n } else if (registered.some((tool) => tool.readOnlyHint !== true)) {\n count(\"contradicted\", {\n code: \"product.read_only_conflict\", severity: \"warning\", verdict: \"contradicted\",\n claim: \"hosted tools read-only\",\n message: \"At least one hosted tool advertises a non-read-only annotation; reconcile the landing-page promise.\",\n });\n } else count(\"consistent\");\n }\n\n const sectionFound = surface === \"hosted\"\n ? observation.hostedSectionFound : observation.localSectionFound;\n const coverageLimited = !catalogAvailable || !observation.hasMain\n || observation.extractionTruncated || !sectionFound\n || checked === 0 || unverified > 0;\n const limitations = [\n \"Only explicit tool names and selected bounded/surface promises are checked against observed MCP registration metadata, not arbitrary marketing semantics.\",\n \"Registration and input-schema compatibility do NOT prove a successful tool call, live service health, screenshots, Google indexing, or functional correctness.\",\n ...(!sectionFound ? [\"No explicit tool listing for this runtime was found in the visible main-content section.\"] : []),\n ...(!catalogAvailable ? [\"Runtime tool-registration metadata is unavailable; unsupported claims cannot be determined.\"] : []),\n ...(observation.extractionTruncated ? [\"The landing-page claim extraction reached its hard limit; some claims were not checked.\"] : []),\n ];\n const ordered = findings.sort((a, b) => (a.severity === \"warning\" ? 0 : 1)\n - (b.severity === \"warning\" ? 0 : 1) || a.code.localeCompare(b.code) || a.claim.localeCompare(b.claim));\n return {\n scope: \"landing_html_vs_registered_mcp_metadata\",\n surface, catalog_available: catalogAvailable, registered_tools: registered.length,\n tool_claims_checked: advertisedTools.length, checked_claims: checked,\n consistent_claims: consistent, contradicted_claims: contradicted,\n unverified_claims: unverified, advertised_tools: advertisedTools,\n ...(siteBatchLimit ? { site_batch_limit: siteBatchLimit } : {}),\n coverage_limited: coverageLimited,\n limitations, total_findings: ordered.length,\n findings: ordered.slice(0, MAX_PRODUCT_CLAIM_FINDINGS),\n findings_truncated: ordered.length > MAX_PRODUCT_CLAIM_FINDINGS,\n };\n}\n"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* P1-01: deterministic, evidence-limited same-language main-content comparisons.
|
|
3
|
+
*
|
|
4
|
+
* This pure module is shared by the local stdio MCP and the hosted Worker.
|
|
5
|
+
* HTML extraction happens in the two runtime adapters; only already-observed
|
|
6
|
+
* static main text reaches this function. No network, storage, embeddings or AI.
|
|
7
|
+
*/
|
|
8
|
+
export type MainContentSource = "main" | "article" | "body_fallback" | "missing";
|
|
9
|
+
export interface MainContentObservation {
|
|
10
|
+
url: string;
|
|
11
|
+
language: string | undefined;
|
|
12
|
+
text: string;
|
|
13
|
+
source: MainContentSource;
|
|
14
|
+
/** Optional bounded main-text blocks for P1-03; never returned to clients. */
|
|
15
|
+
blocks?: string[];
|
|
16
|
+
blocksTruncated?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface ContentDuplicatePair {
|
|
19
|
+
first_url: string;
|
|
20
|
+
second_url: string;
|
|
21
|
+
language: string;
|
|
22
|
+
kind: "exact" | "near";
|
|
23
|
+
confidence: "observed" | "potential";
|
|
24
|
+
similarity_percent: number;
|
|
25
|
+
first_words: number;
|
|
26
|
+
second_words: number;
|
|
27
|
+
}
|
|
28
|
+
export interface SameLanguageDuplicateAnalysis {
|
|
29
|
+
scope: "sampled_pages_only";
|
|
30
|
+
sampled_pages: number;
|
|
31
|
+
eligible_pages: number;
|
|
32
|
+
skipped_pages: number;
|
|
33
|
+
coverage_limited: boolean;
|
|
34
|
+
limitations: string[];
|
|
35
|
+
total_pairs: number;
|
|
36
|
+
pairs: ContentDuplicatePair[];
|
|
37
|
+
pairs_truncated: boolean;
|
|
38
|
+
}
|
|
39
|
+
export declare const MIN_MAIN_CONTENT_WORDS = 80;
|
|
40
|
+
export declare const MAX_MAIN_CONTENT_CHARS = 120000;
|
|
41
|
+
export declare const MAX_MAIN_CONTENT_WORDS = 6000;
|
|
42
|
+
export declare const MAX_CONTENT_DUPLICATE_PAIRS = 8;
|
|
43
|
+
export declare const MAIN_CONTENT_EXCLUDED_SELECTORS: string;
|
|
44
|
+
export declare const MAIN_CONTENT_BLOCK_SELECTORS = "p,h1,h2,h3,h4,h5,h6,li,div,section,article,blockquote,pre,br,dt,dd,tr";
|
|
45
|
+
export declare function safeObservedUrl(value: string): string | undefined;
|
|
46
|
+
/** Same base language, but preserve explicit script differences (sr-Cyrl vs sr-Latn). */
|
|
47
|
+
export declare function comparisonLanguage(value: string | undefined): string | undefined;
|
|
48
|
+
export declare function tokensFromText(text: string, language: string): string[];
|
|
49
|
+
export declare function analyzeSameLanguageDuplicates(observations: readonly MainContentObservation[], options?: {
|
|
50
|
+
sampledPages?: number;
|
|
51
|
+
coverageLimited?: boolean;
|
|
52
|
+
}): SameLanguageDuplicateAnalysis;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
export const MIN_MAIN_CONTENT_WORDS = 80;
|
|
2
|
+
export const MAX_MAIN_CONTENT_CHARS = 120_000;
|
|
3
|
+
export const MAX_MAIN_CONTENT_WORDS = 6_000;
|
|
4
|
+
export const MAX_CONTENT_DUPLICATE_PAIRS = 8;
|
|
5
|
+
export const MAIN_CONTENT_EXCLUDED_SELECTORS = [
|
|
6
|
+
"script", "style", "noscript", "svg", "template", "nav", "header", "footer", "aside",
|
|
7
|
+
"form", "button", "[hidden]", "[aria-hidden='true']", "[role='navigation']",
|
|
8
|
+
"[role='banner']", "[role='contentinfo']", "[role='complementary']",
|
|
9
|
+
].join(",");
|
|
10
|
+
export const MAIN_CONTENT_BLOCK_SELECTORS = "p,h1,h2,h3,h4,h5,h6,li,div,section,article,blockquote,pre,br,dt,dd,tr";
|
|
11
|
+
const SHINGLE_SIZE = 5;
|
|
12
|
+
const MIN_DISTINCT_SHINGLES = 20;
|
|
13
|
+
const NEAR_JACCARD_THRESHOLD = 0.82;
|
|
14
|
+
const MIN_NEAR_LENGTH_RATIO = 0.82;
|
|
15
|
+
const MAX_RESULT_URL_CHARS = 512;
|
|
16
|
+
export function safeObservedUrl(value) {
|
|
17
|
+
try {
|
|
18
|
+
if (value.length > MAX_RESULT_URL_CHARS)
|
|
19
|
+
return undefined;
|
|
20
|
+
const url = new URL(value);
|
|
21
|
+
if ((url.protocol !== "http:" && url.protocol !== "https:")
|
|
22
|
+
|| url.username || url.password || url.search || url.hash || !url.hostname)
|
|
23
|
+
return undefined;
|
|
24
|
+
return url.href;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** Same base language, but preserve explicit script differences (sr-Cyrl vs sr-Latn). */
|
|
31
|
+
export function comparisonLanguage(value) {
|
|
32
|
+
if (!value || value.length > 48)
|
|
33
|
+
return undefined;
|
|
34
|
+
try {
|
|
35
|
+
const locale = new Intl.Locale(value.trim());
|
|
36
|
+
if (!/^[a-z]{2,3}$/.test(locale.language) || ["und", "zxx"].includes(locale.language)) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
return locale.language + (locale.script ? "-" + locale.script.toLowerCase() : "");
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export function tokensFromText(text, language) {
|
|
46
|
+
const segmenter = new Intl.Segmenter(language, { granularity: "word" });
|
|
47
|
+
const tokens = [];
|
|
48
|
+
for (const part of segmenter.segment(text)) {
|
|
49
|
+
if (part.isWordLike && /[\p{L}\p{N}]/u.test(part.segment)) {
|
|
50
|
+
tokens.push(part.segment);
|
|
51
|
+
if (tokens.length > MAX_MAIN_CONTENT_WORDS)
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return tokens;
|
|
56
|
+
}
|
|
57
|
+
/** Bounded, length-prefixed shingle keys avoid separator-collision ambiguity. */
|
|
58
|
+
function shingles(tokens) {
|
|
59
|
+
const result = new Set();
|
|
60
|
+
for (let i = 0; i <= tokens.length - SHINGLE_SIZE; i += 1) {
|
|
61
|
+
const key = tokens.slice(i, i + SHINGLE_SIZE)
|
|
62
|
+
.map((token) => token.length + ":" + token).join("");
|
|
63
|
+
result.add(key);
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
function jaccard(left, right) {
|
|
68
|
+
if (left.size < MIN_DISTINCT_SHINGLES || right.size < MIN_DISTINCT_SHINGLES)
|
|
69
|
+
return 0;
|
|
70
|
+
const smaller = left.size <= right.size ? left : right;
|
|
71
|
+
const larger = left.size <= right.size ? right : left;
|
|
72
|
+
let overlap = 0;
|
|
73
|
+
for (const shingle of smaller)
|
|
74
|
+
if (larger.has(shingle))
|
|
75
|
+
overlap += 1;
|
|
76
|
+
return overlap / (left.size + right.size - overlap);
|
|
77
|
+
}
|
|
78
|
+
function prepare(input) {
|
|
79
|
+
const url = safeObservedUrl(input.url);
|
|
80
|
+
const language = comparisonLanguage(input.language);
|
|
81
|
+
if (!url || !language || input.source === "missing"
|
|
82
|
+
|| !input.text || input.text.length > MAX_MAIN_CONTENT_CHARS)
|
|
83
|
+
return undefined;
|
|
84
|
+
const normalized = input.text.normalize("NFKC").replace(/\s+/gu, " ").trim().toLocaleLowerCase(language);
|
|
85
|
+
if (!normalized || normalized.length > MAX_MAIN_CONTENT_CHARS)
|
|
86
|
+
return undefined;
|
|
87
|
+
const tokens = tokensFromText(normalized, language);
|
|
88
|
+
if (tokens.length < MIN_MAIN_CONTENT_WORDS || tokens.length > MAX_MAIN_CONTENT_WORDS)
|
|
89
|
+
return undefined;
|
|
90
|
+
return { url, language, source: input.source, normalized, tokens, shingles: shingles(tokens) };
|
|
91
|
+
}
|
|
92
|
+
export function analyzeSameLanguageDuplicates(observations, options = {}) {
|
|
93
|
+
// At most eight pages per call; reject rather than silently skip extra comparisons.
|
|
94
|
+
if (observations.length > 8)
|
|
95
|
+
throw new Error("Same-language duplicate analysis supports at most eight pages.");
|
|
96
|
+
const sampledPages = options.sampledPages ?? observations.length;
|
|
97
|
+
if (!Number.isSafeInteger(sampledPages) || sampledPages < observations.length || sampledPages > 8) {
|
|
98
|
+
throw new Error("sampledPages must be between the observed page count and eight.");
|
|
99
|
+
}
|
|
100
|
+
const prepared = observations.flatMap((observation) => {
|
|
101
|
+
const document = prepare(observation);
|
|
102
|
+
return document ? [document] : [];
|
|
103
|
+
});
|
|
104
|
+
const matched = [];
|
|
105
|
+
for (let i = 0; i < prepared.length; i += 1) {
|
|
106
|
+
for (let j = i + 1; j < prepared.length; j += 1) {
|
|
107
|
+
const left = prepared[i];
|
|
108
|
+
const right = prepared[j];
|
|
109
|
+
if (left.url === right.url || left.language !== right.language)
|
|
110
|
+
continue;
|
|
111
|
+
const exact = left.normalized === right.normalized;
|
|
112
|
+
let similarity = 0;
|
|
113
|
+
if (!exact) {
|
|
114
|
+
const ratio = Math.min(left.tokens.length, right.tokens.length)
|
|
115
|
+
/ Math.max(left.tokens.length, right.tokens.length);
|
|
116
|
+
if (ratio < MIN_NEAR_LENGTH_RATIO)
|
|
117
|
+
continue;
|
|
118
|
+
similarity = jaccard(left.shingles, right.shingles);
|
|
119
|
+
if (similarity < NEAR_JACCARD_THRESHOLD)
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
matched.push({
|
|
123
|
+
first_url: left.url,
|
|
124
|
+
second_url: right.url,
|
|
125
|
+
language: left.language,
|
|
126
|
+
kind: exact ? "exact" : "near",
|
|
127
|
+
confidence: exact && left.source !== "body_fallback" && right.source !== "body_fallback"
|
|
128
|
+
? "observed" : "potential",
|
|
129
|
+
similarity_percent: exact ? 100 : Math.min(99, Math.round(similarity * 100)),
|
|
130
|
+
first_words: left.tokens.length,
|
|
131
|
+
second_words: right.tokens.length,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
matched.sort((a, b) => (a.kind === "exact" ? 0 : 1) - (b.kind === "exact" ? 0 : 1)
|
|
136
|
+
|| b.similarity_percent - a.similarity_percent
|
|
137
|
+
|| a.first_url.localeCompare(b.first_url)
|
|
138
|
+
|| a.second_url.localeCompare(b.second_url));
|
|
139
|
+
const skippedPages = sampledPages - prepared.length;
|
|
140
|
+
const limitations = [
|
|
141
|
+
"Compares only supplied or selected, already-fetched pages; absence of matches does not prove site-wide uniqueness.",
|
|
142
|
+
"Static text similarity is not a semantic or Google duplicate-content verdict.",
|
|
143
|
+
...(skippedPages ? [`${skippedPages} page(s) lacked a usable language, enough main content, a safe URL, or were over the size limit.`] : []),
|
|
144
|
+
...(options.coverageLimited ? ["Sitemap or page selection coverage is incomplete."] : []),
|
|
145
|
+
];
|
|
146
|
+
return {
|
|
147
|
+
scope: "sampled_pages_only",
|
|
148
|
+
sampled_pages: sampledPages,
|
|
149
|
+
eligible_pages: prepared.length,
|
|
150
|
+
skipped_pages: skippedPages,
|
|
151
|
+
coverage_limited: Boolean(options.coverageLimited) || sampledPages < 2 || skippedPages > 0,
|
|
152
|
+
limitations,
|
|
153
|
+
total_pairs: matched.length,
|
|
154
|
+
pairs: matched.slice(0, MAX_CONTENT_DUPLICATE_PAIRS),
|
|
155
|
+
pairs_truncated: matched.length > MAX_CONTENT_DUPLICATE_PAIRS,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=same-language-duplicates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"same-language-duplicates.js","sourceRoot":"","sources":["../../../src/modules/content-schema/same-language-duplicates.ts"],"names":[],"mappings":"AA0CA,MAAM,CAAC,MAAM,sBAAsB,GAAG,EAAE,CAAC;AACzC,MAAM,CAAC,MAAM,sBAAsB,GAAG,OAAO,CAAC;AAC9C,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,CAAC;AAC5C,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC;AAC7C,MAAM,CAAC,MAAM,+BAA+B,GAAG;IAC7C,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO;IACpF,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,sBAAsB,EAAE,qBAAqB;IAC3E,iBAAiB,EAAE,sBAAsB,EAAE,wBAAwB;CACpE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACZ,MAAM,CAAC,MAAM,4BAA4B,GAAG,uEAAuE,CAAC;AACpH,MAAM,YAAY,GAAG,CAAC,CAAC;AACvB,MAAM,qBAAqB,GAAG,EAAE,CAAC;AACjC,MAAM,sBAAsB,GAAG,IAAI,CAAC;AACpC,MAAM,qBAAqB,GAAG,IAAI,CAAC;AACnC,MAA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AAW,EAAE,OAAO,CAAC,MAAM;QAC3B,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,2BAA2B,CAAC;QACpD,eAAe,EAAE,OAAO,CAAC,MAAM,GAAG,2BAA2B;KAC9D,CAAC;AACJ,CAAC","sourcesContent":["/**\n * P1-01: deterministic, evidence-limited same-language main-content comparisons.\n *\n * This pure module is shared by the local stdio MCP and the hosted Worker.\n * HTML extraction happens in the two runtime adapters; only already-observed\n * static main text reaches this function. No network, storage, embeddings or AI.\n */\nexport type MainContentSource = \"main\" | \"article\" | \"body_fallback\" | \"missing\";\n\nexport interface MainContentObservation {\n url: string;\n language: string | undefined;\n text: string;\n source: MainContentSource;\n /** Optional bounded main-text blocks for P1-03; never returned to clients. */\n blocks?: string[];\n blocksTruncated?: boolean;\n}\n\nexport interface ContentDuplicatePair {\n first_url: string;\n second_url: string;\n language: string;\n kind: \"exact\" | \"near\";\n confidence: \"observed\" | \"potential\";\n similarity_percent: number;\n first_words: number;\n second_words: number;\n}\n\nexport interface SameLanguageDuplicateAnalysis {\n scope: \"sampled_pages_only\";\n sampled_pages: number;\n eligible_pages: number;\n skipped_pages: number;\n coverage_limited: boolean;\n limitations: string[];\n total_pairs: number;\n pairs: ContentDuplicatePair[];\n pairs_truncated: boolean;\n}\n\nexport const MIN_MAIN_CONTENT_WORDS = 80;\nexport const MAX_MAIN_CONTENT_CHARS = 120_000;\nexport const MAX_MAIN_CONTENT_WORDS = 6_000;\nexport const MAX_CONTENT_DUPLICATE_PAIRS = 8;\nexport const MAIN_CONTENT_EXCLUDED_SELECTORS = [\n \"script\", \"style\", \"noscript\", \"svg\", \"template\", \"nav\", \"header\", \"footer\", \"aside\",\n \"form\", \"button\", \"[hidden]\", \"[aria-hidden='true']\", \"[role='navigation']\",\n \"[role='banner']\", \"[role='contentinfo']\", \"[role='complementary']\",\n].join(\",\");\nexport const MAIN_CONTENT_BLOCK_SELECTORS = \"p,h1,h2,h3,h4,h5,h6,li,div,section,article,blockquote,pre,br,dt,dd,tr\";\nconst SHINGLE_SIZE = 5;\nconst MIN_DISTINCT_SHINGLES = 20;\nconst NEAR_JACCARD_THRESHOLD = 0.82;\nconst MIN_NEAR_LENGTH_RATIO = 0.82;\nconst MAX_RESULT_URL_CHARS = 512;\n\ninterface PreparedDocument {\n url: string;\n language: string;\n source: MainContentSource;\n normalized: string;\n tokens: string[];\n shingles: Set<string>;\n}\n\nexport function safeObservedUrl(value: string): string | undefined {\n try {\n if (value.length > MAX_RESULT_URL_CHARS) return undefined;\n const url = new URL(value);\n if ((url.protocol !== \"http:\" && url.protocol !== \"https:\")\n || url.username || url.password || url.search || url.hash || !url.hostname) return undefined;\n return url.href;\n } catch {\n return undefined;\n }\n}\n\n/** Same base language, but preserve explicit script differences (sr-Cyrl vs sr-Latn). */\nexport function comparisonLanguage(value: string | undefined): string | undefined {\n if (!value || value.length > 48) return undefined;\n try {\n const locale = new Intl.Locale(value.trim());\n if (!/^[a-z]{2,3}$/.test(locale.language) || [\"und\", \"zxx\"].includes(locale.language)) {\n return undefined;\n }\n return locale.language + (locale.script ? \"-\" + locale.script.toLowerCase() : \"\");\n } catch {\n return undefined;\n }\n}\n\nexport function tokensFromText(text: string, language: string): string[] {\n const segmenter = new Intl.Segmenter(language, { granularity: \"word\" });\n const tokens: string[] = [];\n for (const part of segmenter.segment(text)) {\n if (part.isWordLike && /[\\p{L}\\p{N}]/u.test(part.segment)) {\n tokens.push(part.segment);\n if (tokens.length > MAX_MAIN_CONTENT_WORDS) break;\n }\n }\n return tokens;\n}\n\n/** Bounded, length-prefixed shingle keys avoid separator-collision ambiguity. */\nfunction shingles(tokens: string[]): Set<string> {\n const result = new Set<string>();\n for (let i = 0; i <= tokens.length - SHINGLE_SIZE; i += 1) {\n const key = tokens.slice(i, i + SHINGLE_SIZE)\n .map((token) => token.length + \":\" + token).join(\"\");\n result.add(key);\n }\n return result;\n}\n\nfunction jaccard(left: Set<string>, right: Set<string>): number {\n if (left.size < MIN_DISTINCT_SHINGLES || right.size < MIN_DISTINCT_SHINGLES) return 0;\n const smaller = left.size <= right.size ? left : right;\n const larger = left.size <= right.size ? right : left;\n let overlap = 0;\n for (const shingle of smaller) if (larger.has(shingle)) overlap += 1;\n return overlap / (left.size + right.size - overlap);\n}\n\nfunction prepare(input: MainContentObservation): PreparedDocument | undefined {\n const url = safeObservedUrl(input.url);\n const language = comparisonLanguage(input.language);\n if (!url || !language || input.source === \"missing\"\n || !input.text || input.text.length > MAX_MAIN_CONTENT_CHARS) return undefined;\n const normalized = input.text.normalize(\"NFKC\").replace(/\\s+/gu, \" \").trim().toLocaleLowerCase(language);\n if (!normalized || normalized.length > MAX_MAIN_CONTENT_CHARS) return undefined;\n const tokens = tokensFromText(normalized, language);\n if (tokens.length < MIN_MAIN_CONTENT_WORDS || tokens.length > MAX_MAIN_CONTENT_WORDS) return undefined;\n return { url, language, source: input.source, normalized, tokens, shingles: shingles(tokens) };\n}\n\nexport function analyzeSameLanguageDuplicates(\n observations: readonly MainContentObservation[],\n options: { sampledPages?: number; coverageLimited?: boolean } = {},\n): SameLanguageDuplicateAnalysis {\n // At most eight pages per call; reject rather than silently skip extra comparisons.\n if (observations.length > 8) throw new Error(\"Same-language duplicate analysis supports at most eight pages.\");\n const sampledPages = options.sampledPages ?? observations.length;\n if (!Number.isSafeInteger(sampledPages) || sampledPages < observations.length || sampledPages > 8) {\n throw new Error(\"sampledPages must be between the observed page count and eight.\");\n }\n\n const prepared = observations.flatMap((observation) => {\n const document = prepare(observation);\n return document ? [document] : [];\n });\n const matched: ContentDuplicatePair[] = [];\n for (let i = 0; i < prepared.length; i += 1) {\n for (let j = i + 1; j < prepared.length; j += 1) {\n const left = prepared[i];\n const right = prepared[j];\n if (left.url === right.url || left.language !== right.language) continue;\n const exact = left.normalized === right.normalized;\n let similarity = 0;\n if (!exact) {\n const ratio = Math.min(left.tokens.length, right.tokens.length)\n / Math.max(left.tokens.length, right.tokens.length);\n if (ratio < MIN_NEAR_LENGTH_RATIO) continue;\n similarity = jaccard(left.shingles, right.shingles);\n if (similarity < NEAR_JACCARD_THRESHOLD) continue;\n }\n matched.push({\n first_url: left.url,\n second_url: right.url,\n language: left.language,\n kind: exact ? \"exact\" : \"near\",\n confidence: exact && left.source !== \"body_fallback\" && right.source !== \"body_fallback\"\n ? \"observed\" : \"potential\",\n similarity_percent: exact ? 100 : Math.min(99, Math.round(similarity * 100)),\n first_words: left.tokens.length,\n second_words: right.tokens.length,\n });\n }\n }\n matched.sort((a, b) =>\n (a.kind === \"exact\" ? 0 : 1) - (b.kind === \"exact\" ? 0 : 1)\n || b.similarity_percent - a.similarity_percent\n || a.first_url.localeCompare(b.first_url)\n || a.second_url.localeCompare(b.second_url),\n );\n const skippedPages = sampledPages - prepared.length;\n const limitations = [\n \"Compares only supplied or selected, already-fetched pages; absence of matches does not prove site-wide uniqueness.\",\n \"Static text similarity is not a semantic or Google duplicate-content verdict.\",\n ...(skippedPages ? [`${skippedPages} page(s) lacked a usable language, enough main content, a safe URL, or were over the size limit.`] : []),\n ...(options.coverageLimited ? [\"Sitemap or page selection coverage is incomplete.\"] : []),\n ];\n return {\n scope: \"sampled_pages_only\",\n sampled_pages: sampledPages,\n eligible_pages: prepared.length,\n skipped_pages: skippedPages,\n coverage_limited: Boolean(options.coverageLimited) || sampledPages < 2 || skippedPages > 0,\n limitations,\n total_pairs: matched.length,\n pairs: matched.slice(0, MAX_CONTENT_DUPLICATE_PAIRS),\n pairs_truncated: matched.length > MAX_CONTENT_DUPLICATE_PAIRS,\n };\n}\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export declare const MAX_SUPPORTED_SCHEMA_HTML_BYTES = 250000;
|
|
2
|
+
export declare const MAX_SUPPORTED_SCHEMA_SCRIPTS = 12;
|
|
3
|
+
export declare const MAX_SUPPORTED_SCHEMA_SCRIPT_BYTES = 64000;
|
|
4
|
+
export declare const MAX_SUPPORTED_SCHEMA_NODES = 64;
|
|
5
|
+
export declare const MAX_SUPPORTED_SCHEMA_FINDINGS = 12;
|
|
6
|
+
export declare const SUPPORTED_SCHEMA_TYPES: readonly ["Article", "NewsArticle", "BlogPosting", "Product", "BreadcrumbList", "FAQPage", "Organization", "WebSite"];
|
|
7
|
+
export type SupportedSchemaType = typeof SUPPORTED_SCHEMA_TYPES[number];
|
|
8
|
+
export type SchemaFindingCode = "empty_block" | "invalid_json" | "invalid_document" | "invalid_graph" | "large_block_skipped" | "context_unverified" | "type_unverified" | "unsupported_type" | "missing_profile_field" | "invalid_field_type" | "invalid_date" | "product_evidence_missing" | "invalid_offer" | "invalid_price" | "invalid_currency" | "breadcrumb_too_short" | "breadcrumb_invalid_position" | "breadcrumb_duplicate_position" | "breadcrumb_gap" | "breadcrumb_item_missing" | "faq_question_incomplete" | "reference_unresolved";
|
|
9
|
+
export interface StructuredSchemaFinding {
|
|
10
|
+
code: SchemaFindingCode;
|
|
11
|
+
severity: "error" | "warning" | "info";
|
|
12
|
+
block: number;
|
|
13
|
+
node: number;
|
|
14
|
+
type?: SupportedSchemaType;
|
|
15
|
+
property?: string;
|
|
16
|
+
message: string;
|
|
17
|
+
}
|
|
18
|
+
export interface SupportedSchemaReview {
|
|
19
|
+
scope: "bounded_jsonld_structural_profiles";
|
|
20
|
+
blocks_seen: number;
|
|
21
|
+
blocks_checked: number;
|
|
22
|
+
blocks_skipped: number;
|
|
23
|
+
nodes_examined: number;
|
|
24
|
+
supported_nodes: number;
|
|
25
|
+
unsupported_nodes: number;
|
|
26
|
+
context_unverified_nodes: number;
|
|
27
|
+
types_checked: SupportedSchemaType[];
|
|
28
|
+
errors: number;
|
|
29
|
+
warnings: number;
|
|
30
|
+
unverified: number;
|
|
31
|
+
coverage_limited: boolean;
|
|
32
|
+
limitations: string[];
|
|
33
|
+
total_findings: number;
|
|
34
|
+
findings: StructuredSchemaFinding[];
|
|
35
|
+
findings_truncated: boolean;
|
|
36
|
+
}
|
|
37
|
+
export declare function reviewSupportedJsonLd(scriptTexts: readonly string[], blocksSeen?: number): SupportedSchemaReview;
|