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.
Files changed (174) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/README.md +64 -4
  3. package/dist/audit-history.d.ts +9 -0
  4. package/dist/audit-history.js +27 -0
  5. package/dist/audit-history.js.map +1 -1
  6. package/dist/index.js +2508 -2
  7. package/dist/index.js.map +1 -1
  8. package/dist/mcp-bounds.js +8 -3
  9. package/dist/mcp-bounds.js.map +1 -1
  10. package/dist/modules/browser-ux/lighthouse-lab-probe.d.ts +21 -0
  11. package/dist/modules/browser-ux/lighthouse-lab-probe.js +190 -0
  12. package/dist/modules/browser-ux/lighthouse-lab-probe.js.map +1 -0
  13. package/dist/modules/browser-ux/lighthouse-lab.d.ts +61 -0
  14. package/dist/modules/browser-ux/lighthouse-lab.js +98 -0
  15. package/dist/modules/browser-ux/lighthouse-lab.js.map +1 -0
  16. package/dist/modules/browser-ux/media-diagnostics.d.ts +41 -0
  17. package/dist/modules/browser-ux/media-diagnostics.js +183 -0
  18. package/dist/modules/browser-ux/media-diagnostics.js.map +1 -0
  19. package/dist/modules/browser-ux/raw-rendered-diff.d.ts +70 -0
  20. package/dist/modules/browser-ux/raw-rendered-diff.js +262 -0
  21. package/dist/modules/browser-ux/raw-rendered-diff.js.map +1 -0
  22. package/dist/modules/browser-ux/raw-rendered-probe.d.ts +17 -0
  23. package/dist/modules/browser-ux/raw-rendered-probe.js +163 -0
  24. package/dist/modules/browser-ux/raw-rendered-probe.js.map +1 -0
  25. package/dist/modules/browser-ux/resource-failures-probe.d.ts +11 -0
  26. package/dist/modules/browser-ux/resource-failures-probe.js +231 -0
  27. package/dist/modules/browser-ux/resource-failures-probe.js.map +1 -0
  28. package/dist/modules/browser-ux/resource-failures.d.ts +79 -0
  29. package/dist/modules/browser-ux/resource-failures.js +178 -0
  30. package/dist/modules/browser-ux/resource-failures.js.map +1 -0
  31. package/dist/modules/browser-ux/viewport-parity-probe.d.ts +5 -0
  32. package/dist/modules/browser-ux/viewport-parity-probe.js +316 -0
  33. package/dist/modules/browser-ux/viewport-parity-probe.js.map +1 -0
  34. package/dist/modules/browser-ux/viewport-parity.d.ts +112 -0
  35. package/dist/modules/browser-ux/viewport-parity.js +224 -0
  36. package/dist/modules/browser-ux/viewport-parity.js.map +1 -0
  37. package/dist/modules/browser-ux/wcag-interactions.d.ts +95 -0
  38. package/dist/modules/browser-ux/wcag-interactions.js +360 -0
  39. package/dist/modules/browser-ux/wcag-interactions.js.map +1 -0
  40. package/dist/modules/change-regression/availability-history-store.d.ts +18 -0
  41. package/dist/modules/change-regression/availability-history-store.js +168 -0
  42. package/dist/modules/change-regression/availability-history-store.js.map +1 -0
  43. package/dist/modules/change-regression/crawler-log-correlation.d.ts +111 -0
  44. package/dist/modules/change-regression/crawler-log-correlation.js +374 -0
  45. package/dist/modules/change-regression/crawler-log-correlation.js.map +1 -0
  46. package/dist/modules/change-regression/google-common-crawler-ip.d.ts +15 -0
  47. package/dist/modules/change-regression/google-common-crawler-ip.js +129 -0
  48. package/dist/modules/change-regression/google-common-crawler-ip.js.map +1 -0
  49. package/dist/modules/change-regression/historical-comparisons.d.ts +120 -0
  50. package/dist/modules/change-regression/historical-comparisons.js +330 -0
  51. package/dist/modules/change-regression/historical-comparisons.js.map +1 -0
  52. package/dist/modules/change-regression/production-change-comparison.d.ts +68 -0
  53. package/dist/modules/change-regression/production-change-comparison.js +214 -0
  54. package/dist/modules/change-regression/production-change-comparison.js.map +1 -0
  55. package/dist/modules/change-regression/regression-alerts.d.ts +73 -0
  56. package/dist/modules/change-regression/regression-alerts.js +183 -0
  57. package/dist/modules/change-regression/regression-alerts.js.map +1 -0
  58. package/dist/modules/change-regression/strict-observation-time.d.ts +7 -0
  59. package/dist/modules/change-regression/strict-observation-time.js +31 -0
  60. package/dist/modules/change-regression/strict-observation-time.js.map +1 -0
  61. package/dist/modules/content-schema/citation-methodology-consistency.d.ts +108 -0
  62. package/dist/modules/content-schema/citation-methodology-consistency.js +360 -0
  63. package/dist/modules/content-schema/citation-methodology-consistency.js.map +1 -0
  64. package/dist/modules/content-schema/competitor-intent-comparison.d.ts +74 -0
  65. package/dist/modules/content-schema/competitor-intent-comparison.js +185 -0
  66. package/dist/modules/content-schema/competitor-intent-comparison.js.map +1 -0
  67. package/dist/modules/content-schema/empty-boilerplate-content.d.ts +36 -0
  68. package/dist/modules/content-schema/empty-boilerplate-content.js +225 -0
  69. package/dist/modules/content-schema/empty-boilerplate-content.js.map +1 -0
  70. package/dist/modules/content-schema/extract-citation-methodology.d.ts +6 -0
  71. package/dist/modules/content-schema/extract-citation-methodology.js +201 -0
  72. package/dist/modules/content-schema/extract-citation-methodology.js.map +1 -0
  73. package/dist/modules/content-schema/extract-competitor-intent.d.ts +2 -0
  74. package/dist/modules/content-schema/extract-competitor-intent.js +140 -0
  75. package/dist/modules/content-schema/extract-competitor-intent.js.map +1 -0
  76. package/dist/modules/content-schema/extract-main-content.d.ts +6 -0
  77. package/dist/modules/content-schema/extract-main-content.js +33 -0
  78. package/dist/modules/content-schema/extract-main-content.js.map +1 -0
  79. package/dist/modules/content-schema/extract-metadata-consistency.d.ts +3 -0
  80. package/dist/modules/content-schema/extract-metadata-consistency.js +62 -0
  81. package/dist/modules/content-schema/extract-metadata-consistency.js.map +1 -0
  82. package/dist/modules/content-schema/extract-product-claims.d.ts +3 -0
  83. package/dist/modules/content-schema/extract-product-claims.js +58 -0
  84. package/dist/modules/content-schema/extract-product-claims.js.map +1 -0
  85. package/dist/modules/content-schema/extract-structured-data.d.ts +3 -0
  86. package/dist/modules/content-schema/extract-structured-data.js +25 -0
  87. package/dist/modules/content-schema/extract-structured-data.js.map +1 -0
  88. package/dist/modules/content-schema/metadata-consistency.d.ts +66 -0
  89. package/dist/modules/content-schema/metadata-consistency.js +282 -0
  90. package/dist/modules/content-schema/metadata-consistency.js.map +1 -0
  91. package/dist/modules/content-schema/product-claims.d.ts +73 -0
  92. package/dist/modules/content-schema/product-claims.js +195 -0
  93. package/dist/modules/content-schema/product-claims.js.map +1 -0
  94. package/dist/modules/content-schema/same-language-duplicates.d.ts +52 -0
  95. package/dist/modules/content-schema/same-language-duplicates.js +158 -0
  96. package/dist/modules/content-schema/same-language-duplicates.js.map +1 -0
  97. package/dist/modules/content-schema/structured-data-validation.d.ts +37 -0
  98. package/dist/modules/content-schema/structured-data-validation.js +385 -0
  99. package/dist/modules/content-schema/structured-data-validation.js.map +1 -0
  100. package/dist/modules/external-metrics/crux-field-probe.d.ts +10 -0
  101. package/dist/modules/external-metrics/crux-field-probe.js +113 -0
  102. package/dist/modules/external-metrics/crux-field-probe.js.map +1 -0
  103. package/dist/modules/external-metrics/crux-field.d.ts +61 -0
  104. package/dist/modules/external-metrics/crux-field.js +231 -0
  105. package/dist/modules/external-metrics/crux-field.js.map +1 -0
  106. package/dist/modules/http-crawl/availability-observations.d.ts +68 -0
  107. package/dist/modules/http-crawl/availability-observations.js +206 -0
  108. package/dist/modules/http-crawl/availability-observations.js.map +1 -0
  109. package/dist/modules/http-crawl/availability-probe.d.ts +8 -0
  110. package/dist/modules/http-crawl/availability-probe.js +46 -0
  111. package/dist/modules/http-crawl/availability-probe.js.map +1 -0
  112. package/dist/modules/http-crawl/crawler-access-probe.d.ts +6 -0
  113. package/dist/modules/http-crawl/crawler-access-probe.js +79 -0
  114. package/dist/modules/http-crawl/crawler-access-probe.js.map +1 -0
  115. package/dist/modules/http-crawl/crawler-access.d.ts +75 -0
  116. package/dist/modules/http-crawl/crawler-access.js +404 -0
  117. package/dist/modules/http-crawl/crawler-access.js.map +1 -0
  118. package/dist/modules/http-crawl/http-delivery-probe.d.ts +3 -0
  119. package/dist/modules/http-crawl/http-delivery-probe.js +44 -0
  120. package/dist/modules/http-crawl/http-delivery-probe.js.map +1 -0
  121. package/dist/modules/http-crawl/http-delivery.d.ts +64 -0
  122. package/dist/modules/http-crawl/http-delivery.js +273 -0
  123. package/dist/modules/http-crawl/http-delivery.js.map +1 -0
  124. package/dist/modules/http-crawl/https-security.d.ts +84 -0
  125. package/dist/modules/http-crawl/https-security.js +441 -0
  126. package/dist/modules/http-crawl/https-security.js.map +1 -0
  127. package/dist/modules/http-crawl/non-html-directives.d.ts +74 -0
  128. package/dist/modules/http-crawl/non-html-directives.js +353 -0
  129. package/dist/modules/http-crawl/non-html-directives.js.map +1 -0
  130. package/dist/modules/http-crawl/redirect-canonical-chains.d.ts +80 -0
  131. package/dist/modules/http-crawl/redirect-canonical-chains.js +459 -0
  132. package/dist/modules/http-crawl/redirect-canonical-chains.js.map +1 -0
  133. package/dist/modules/http-crawl/redirect-canonical-probe.d.ts +6 -0
  134. package/dist/modules/http-crawl/redirect-canonical-probe.js +83 -0
  135. package/dist/modules/http-crawl/redirect-canonical-probe.js.map +1 -0
  136. package/dist/modules/http-crawl/sitemap-inventory-probe.d.ts +8 -0
  137. package/dist/modules/http-crawl/sitemap-inventory-probe.js +155 -0
  138. package/dist/modules/http-crawl/sitemap-inventory-probe.js.map +1 -0
  139. package/dist/modules/http-crawl/sitemap-inventory.d.ts +107 -0
  140. package/dist/modules/http-crawl/sitemap-inventory.js +557 -0
  141. package/dist/modules/http-crawl/sitemap-inventory.js.map +1 -0
  142. package/dist/modules/http-crawl/url-variants.d.ts +86 -0
  143. package/dist/modules/http-crawl/url-variants.js +379 -0
  144. package/dist/modules/http-crawl/url-variants.js.map +1 -0
  145. package/dist/modules/site-architecture/extract-internal-links.d.ts +3 -0
  146. package/dist/modules/site-architecture/extract-internal-links.js +88 -0
  147. package/dist/modules/site-architecture/extract-internal-links.js.map +1 -0
  148. package/dist/modules/site-architecture/extract-multilingual-page.d.ts +2 -0
  149. package/dist/modules/site-architecture/extract-multilingual-page.js +29 -0
  150. package/dist/modules/site-architecture/extract-multilingual-page.js.map +1 -0
  151. package/dist/modules/site-architecture/internal-link-graph-probe.d.ts +7 -0
  152. package/dist/modules/site-architecture/internal-link-graph-probe.js +116 -0
  153. package/dist/modules/site-architecture/internal-link-graph-probe.js.map +1 -0
  154. package/dist/modules/site-architecture/internal-link-graph.d.ts +113 -0
  155. package/dist/modules/site-architecture/internal-link-graph.js +414 -0
  156. package/dist/modules/site-architecture/internal-link-graph.js.map +1 -0
  157. package/dist/modules/site-architecture/internal-link-quality.d.ts +77 -0
  158. package/dist/modules/site-architecture/internal-link-quality.js +260 -0
  159. package/dist/modules/site-architecture/internal-link-quality.js.map +1 -0
  160. package/dist/modules/site-architecture/multilingual-clusters.d.ts +82 -0
  161. package/dist/modules/site-architecture/multilingual-clusters.js +363 -0
  162. package/dist/modules/site-architecture/multilingual-clusters.js.map +1 -0
  163. package/dist/network.d.ts +4 -0
  164. package/dist/network.js +25 -8
  165. package/dist/network.js.map +1 -1
  166. package/dist/presentation.d.ts +53 -0
  167. package/dist/presentation.js +526 -0
  168. package/dist/presentation.js.map +1 -1
  169. package/dist/screenshot.d.ts +2 -1
  170. package/dist/screenshot.js +4 -2
  171. package/dist/screenshot.js.map +1 -1
  172. package/dist/seo-auditor.js +16 -6
  173. package/dist/seo-auditor.js.map +1 -1
  174. package/package.json +7 -4
@@ -0,0 +1,414 @@
1
+ /**
2
+ * V06: bounded, static internal-link graph analysis.
3
+ * Only observed <a href> URLs are edges; no script execution, network, storage,
4
+ * Googlebot identity, full-site orphan verdict, ranking or PageRank.
5
+ */
6
+ import { load } from "cheerio";
7
+ import { safeLinkPageUrl } from "./internal-link-quality.js";
8
+ export const MAX_GRAPH_PAGES = 8;
9
+ export const MAX_GRAPH_HTML_BYTES = 1_048_576;
10
+ // The hosted MCP has a 2 MiB request-body cap; leave room for JSON metadata.
11
+ export const MAX_GRAPH_TOTAL_HTML_BYTES = 1_500_000;
12
+ export const MAX_GRAPH_LINKS_PER_PAGE = 240;
13
+ export const MAX_GRAPH_CATALOG_URLS = 256;
14
+ export const MAX_GRAPH_FINDINGS = 24;
15
+ export const MAX_GRAPH_LIVE_PAGES = 3;
16
+ export const GRAPH_FINDING_CODES = [
17
+ "entry_not_sampled", "entry_not_crawlable", "sampled_page_unreachable",
18
+ "possible_orphan_in_sample", "sampled_deep_page", "link_sample_truncated",
19
+ "linked_to_http_error", "linked_to_robots_blocked", "linked_to_noindex",
20
+ "linked_to_noncanonical", "nofollow_only_path", "unobserved_link_targets",
21
+ "sitemap_pages_unobserved", "unsafe_links_excluded", "query_links_excluded",
22
+ "external_base_ignored", "page_html_unverified", "no_sampled_outgoing_links",
23
+ ];
24
+ const limitations = [
25
+ "Depth is the shortest observed static <a href> path inside the supplied page sample, not a whole-site or Googlebot crawl depth.",
26
+ "An orphan candidate has no incoming links from other supplied pages; unobserved site pages and external links may still reach it.",
27
+ "Sitemap URLs are independent caller-supplied labels. Unobserved sitemap pages are not proven orphans, and a sitemap does not guarantee indexing.",
28
+ "JavaScript-rendered links, query variants, historical responses, redirects and Google-selected canonicals are not followed or verified.",
29
+ ];
30
+ const bytes = (s) => new TextEncoder().encode(s).byteLength;
31
+ const statusOK = (s) => s === undefined || (s >= 200 && s < 300 && ![204, 205, 206].includes(s));
32
+ function safeLabel(value) {
33
+ if (typeof value !== "string" || bytes(value) > 512 ||
34
+ /[\u0000-\u001f\u007f-\u009f\u202a-\u202e\u2066-\u2069\\]/u.test(value))
35
+ return undefined;
36
+ return safeLinkPageUrl(value);
37
+ }
38
+ /** Reuse this pure extractor to select a tiny subset of safe same-origin live links. */
39
+ export function extractGraphLinks(html, pageUrl) {
40
+ const safe = safeLabel(pageUrl);
41
+ if (!safe || typeof html !== "string" || bytes(html) > MAX_GRAPH_HTML_BYTES) {
42
+ throw new Error("Graph HTML or URL is not safe within bounded limits.");
43
+ }
44
+ const origin = new URL(safe).origin;
45
+ const $ = load(html);
46
+ // Template/JS nodes have no established network-visible navigation edges.
47
+ $("template,script,noscript").remove();
48
+ const baseHref = $("head > base[href]").first().attr("href");
49
+ let base = safe;
50
+ let ignoredBase = false;
51
+ if (baseHref !== undefined) {
52
+ try {
53
+ const candidate = new URL(baseHref, safe);
54
+ const usable = safeLabel(candidate.href);
55
+ if (!usable || candidate.origin !== origin)
56
+ ignoredBase = true;
57
+ else
58
+ base = usable;
59
+ }
60
+ catch {
61
+ ignoredBase = true;
62
+ }
63
+ }
64
+ const anchors = $("body a[href]").toArray();
65
+ const sample = anchors.slice(0, MAX_GRAPH_LINKS_PER_PAGE);
66
+ const out = {
67
+ links: sample.length, internal: 0, external: 0, fragments: 0,
68
+ query: 0, unsafe: 0, self: 0, nofollow: 0,
69
+ limited: anchors.length > MAX_GRAPH_LINKS_PER_PAGE,
70
+ ignoredBase, edges: [],
71
+ };
72
+ for (const anchor of sample) {
73
+ const raw = ($(anchor).attr("href") ?? "").trim();
74
+ if (!raw || bytes(raw) > 1_024 ||
75
+ /[\u0000-\u001f\u007f-\u009f\u202a-\u202e\u2066-\u2069\\]/u.test(raw)) {
76
+ out.unsafe++;
77
+ continue;
78
+ }
79
+ if (raw.startsWith("#")) {
80
+ out.fragments++;
81
+ continue;
82
+ }
83
+ // A foreign or invalid <base> changes how relative URLs resolve in a browser.
84
+ // Do not silently assume they refer to this site's own paths.
85
+ if (ignoredBase && !/^[a-z][a-z0-9+.-]*:/iu.test(raw) && !raw.startsWith("//")) {
86
+ out.unsafe++;
87
+ continue;
88
+ }
89
+ try {
90
+ const target = new URL(raw, base);
91
+ if (!["http:", "https:"].includes(target.protocol) ||
92
+ !target.hostname || target.username || target.password || target.port) {
93
+ out.unsafe++;
94
+ continue;
95
+ }
96
+ if (target.origin !== origin) {
97
+ out.external++;
98
+ continue;
99
+ }
100
+ if (target.search || raw.includes("?")) {
101
+ out.query++;
102
+ continue;
103
+ }
104
+ target.hash = "";
105
+ const usable = safeLabel(target.href);
106
+ if (!usable) {
107
+ out.unsafe++;
108
+ continue;
109
+ }
110
+ out.internal++;
111
+ if (usable === safe) {
112
+ out.self++;
113
+ continue;
114
+ }
115
+ const nofollow = ($(anchor).attr("rel") ?? "").toLowerCase()
116
+ .split(/\s+/u).includes("nofollow");
117
+ if (nofollow)
118
+ out.nofollow++;
119
+ out.edges.push({ to: usable, nofollow });
120
+ }
121
+ catch {
122
+ out.unsafe++;
123
+ }
124
+ }
125
+ return out;
126
+ }
127
+ /** Select next live targets without leaking the target URLs in MCP results. */
128
+ export function graphLiveTargets(html, pageUrl) {
129
+ const links = extractGraphLinks(html, pageUrl);
130
+ return Array.from(new Set(links.edges.filter((e) => !e.nofollow)
131
+ .map((e) => e.to))).slice(0, MAX_GRAPH_LINKS_PER_PAGE);
132
+ }
133
+ function noindexInHtml(html) {
134
+ const $ = load(html);
135
+ for (const el of $("head meta[name][content]").toArray()) {
136
+ const name = ($(el).attr("name") ?? "").trim().toLowerCase();
137
+ if (name !== "robots" && name !== "googlebot")
138
+ continue;
139
+ const content = ($(el).attr("content") ?? "").toLowerCase();
140
+ if (content.split(/[,;\s]+/u).some((token) => token === "noindex" || token === "none"))
141
+ return true;
142
+ }
143
+ return false;
144
+ }
145
+ function canonicalInHtml(html, url) {
146
+ const $ = load(html);
147
+ const values = $("head link[rel][href]").toArray().filter((el) => ($(el).attr("rel") ?? "").toLowerCase().split(/\s+/u).includes("canonical"));
148
+ if (!values.length)
149
+ return "unknown";
150
+ const targets = new Set();
151
+ for (const el of values) {
152
+ const href = $(el).attr("href") ?? "";
153
+ try {
154
+ const target = new URL(href, url);
155
+ target.hash = "";
156
+ const safe = safeLabel(target.href);
157
+ if (!safe)
158
+ return "ambiguous";
159
+ targets.add(safe);
160
+ }
161
+ catch {
162
+ return "ambiguous";
163
+ }
164
+ }
165
+ if (targets.size !== 1)
166
+ return "ambiguous";
167
+ return [...targets][0] === url ? "self" : "different";
168
+ }
169
+ export function emptyInternalLinkGraphReview(scope = "caller_supplied_link_graph") {
170
+ return {
171
+ scope, pages_observed: 0, html_pages_examined: 0,
172
+ entry_pages_observed: 0, entry_pages_missing: 0,
173
+ pages_reachable_within_sample: 0, pages_unreachable_within_sample: 0,
174
+ deepest_observed_sample_depth: null, deep_pages_at_three_or_more: 0,
175
+ potential_orphans_within_sample: 0, unique_observed_sample_edges: 0,
176
+ internal_links_observed: 0, external_links_observed: 0,
177
+ nofollow_internal_links: 0, distinct_unsampled_link_targets: 0,
178
+ unsafe_or_query_links_excluded: 0, pages_with_truncated_links: 0,
179
+ linked_http_error_pages: 0, linked_robots_blocked_pages: 0,
180
+ linked_declared_noindex_pages: 0, linked_noncanonical_pages: 0,
181
+ sitemap_urls_provided: 0, sitemap_urls_without_page_sample: 0,
182
+ sampled_pages_not_in_sitemap: 0, robots_unknown_pages: 0,
183
+ status_unknown_pages: 0, coverage_limited: true, limitations,
184
+ pages: [], total_findings: 0, findings: [], findings_truncated: false,
185
+ };
186
+ }
187
+ export function analyzeInternalLinkGraph(input, scope = "caller_supplied_link_graph") {
188
+ const site = safeLabel(input?.site_url);
189
+ if (!site || !Array.isArray(input.pages) ||
190
+ input.pages.length < 1 || input.pages.length > MAX_GRAPH_PAGES) {
191
+ throw new Error("Supply one to eight safe, same-origin page observations.");
192
+ }
193
+ const rootSite = new URL(site).origin;
194
+ const refs = input.pages.map((item) => {
195
+ const url = safeLabel(item?.url);
196
+ if (!url || new URL(url).origin !== rootSite ||
197
+ (item.html !== undefined && (typeof item.html !== "string" ||
198
+ bytes(item.html) > MAX_GRAPH_HTML_BYTES)) ||
199
+ (item.status_code !== undefined && (!Number.isInteger(item.status_code) ||
200
+ item.status_code < 100 || item.status_code > 599)) ||
201
+ (item.noindex !== undefined && typeof item.noindex !== "boolean") ||
202
+ (item.robots_allowed !== undefined && typeof item.robots_allowed !== "boolean") ||
203
+ (item.canonical_url !== undefined && !safeLabel(item.canonical_url))) {
204
+ throw new Error("All page evidence must be valid, bounded and same-origin.");
205
+ }
206
+ return url;
207
+ });
208
+ if (new Set(refs).size !== refs.length)
209
+ throw new Error("Page URLs must be unique.");
210
+ const totalHtml = input.pages.reduce((sum, page) => sum + bytes(page.html ?? ""), 0);
211
+ if (totalHtml > MAX_GRAPH_TOTAL_HTML_BYTES)
212
+ throw new Error("Combined HTML exceeds the graph byte budget.");
213
+ const entries = input.entry_urls ?? [rootSite + "/"];
214
+ const catalog = input.sitemap_urls ?? [];
215
+ if (!Array.isArray(entries) || entries.length > MAX_GRAPH_PAGES ||
216
+ !Array.isArray(catalog) || catalog.length > MAX_GRAPH_CATALOG_URLS) {
217
+ throw new Error("Entry roots or sitemap URL evidence exceed bounded limits.");
218
+ }
219
+ const entryRefs = entries.map((value) => {
220
+ const normalized = safeLabel(value);
221
+ if (!normalized || new URL(normalized).origin !== rootSite)
222
+ throw new Error("Invalid entry URL evidence.");
223
+ return normalized;
224
+ });
225
+ const catalogRefs = catalog.map((value) => {
226
+ const normalized = safeLabel(value);
227
+ if (!normalized || new URL(normalized).origin !== rootSite)
228
+ throw new Error("Invalid sitemap URL evidence.");
229
+ return normalized;
230
+ });
231
+ if (new Set(entryRefs).size !== entryRefs.length ||
232
+ new Set(catalogRefs).size !== catalogRefs.length)
233
+ throw new Error("Graph label arrays require unique URLs.");
234
+ const review = emptyInternalLinkGraphReview(scope);
235
+ review.pages_observed = input.pages.length;
236
+ review.sitemap_urls_provided = catalogRefs.length;
237
+ const byUrl = new Map(refs.map((url, index) => [url, index]));
238
+ review.sitemap_urls_without_page_sample = catalogRefs.filter((url) => !byUrl.has(url)).length;
239
+ const inSitemap = new Set(catalogRefs);
240
+ if (catalogRefs.length)
241
+ review.sampled_pages_not_in_sitemap =
242
+ refs.filter((url) => !inSitemap.has(url)).length;
243
+ const roots = new Set(entryRefs.map((value) => byUrl.get(value)).filter((n) => n !== undefined));
244
+ review.entry_pages_observed = roots.size;
245
+ review.entry_pages_missing = entryRefs.length - roots.size;
246
+ const outgoing = [];
247
+ const incoming = refs.map(() => new Set());
248
+ const incomingFollowable = refs.map(() => new Set());
249
+ const ignoredBasePages = new Set();
250
+ const uniqueEdges = new Set();
251
+ const unseen = new Set();
252
+ const reports = [];
253
+ const canTraverse = [];
254
+ for (const [i, page] of input.pages.entries()) {
255
+ const examined = page.html !== undefined && statusOK(page.status_code);
256
+ const parsed = examined ? extractGraphLinks(page.html, refs[i]) : undefined;
257
+ if (parsed?.ignoredBase)
258
+ ignoredBasePages.add(i);
259
+ const htmlNoindex = examined ? noindexInHtml(page.html) : false;
260
+ const noindexState = page.noindex === true || htmlNoindex ? "declared"
261
+ : examined || page.noindex === false ? "not_observed" : "unknown";
262
+ const observedCanonical = page.canonical_url ? safeLabel(page.canonical_url) : undefined;
263
+ const canonicalState = observedCanonical
264
+ ? observedCanonical === refs[i] ? "self" : "different"
265
+ : examined ? canonicalInHtml(page.html, refs[i]) : "unknown";
266
+ const report = {
267
+ page: i + 1, html_examined: examined,
268
+ ...(page.status_code === undefined ? {} : { status_code: page.status_code }),
269
+ robots_access: page.robots_allowed === undefined ? "unknown"
270
+ : page.robots_allowed ? "allowed" : "disallowed",
271
+ noindex_state: noindexState, canonical_state: canonicalState,
272
+ links_observed: parsed?.links ?? 0,
273
+ internal_links: parsed?.internal ?? 0, external_links: parsed?.external ?? 0,
274
+ fragment_links: parsed?.fragments ?? 0, query_links_excluded: parsed?.query ?? 0,
275
+ unsafe_links_excluded: parsed?.unsafe ?? 0,
276
+ self_links: parsed?.self ?? 0, nofollow_internal: parsed?.nofollow ?? 0,
277
+ sampled_targets: 0, unobserved_internal_targets: 0,
278
+ incoming_sampled_sources: 0, depth_from_entry: null,
279
+ potential_orphan_in_sample: false, extraction_limited: parsed?.limited ?? false,
280
+ };
281
+ reports.push(report);
282
+ canTraverse.push(examined && page.robots_allowed !== false);
283
+ const targetsHere = new Set();
284
+ const unobservedHere = new Set();
285
+ const edges = [];
286
+ if (parsed) {
287
+ for (const e of parsed.edges) {
288
+ const index = byUrl.get(e.to);
289
+ if (index === undefined) {
290
+ unseen.add(e.to);
291
+ unobservedHere.add(e.to);
292
+ continue;
293
+ }
294
+ targetsHere.add(index);
295
+ incoming[index].add(i);
296
+ if (!e.nofollow)
297
+ incomingFollowable[index].add(i);
298
+ uniqueEdges.add(i + ":" + index);
299
+ edges.push({ target: index, nofollow: e.nofollow });
300
+ }
301
+ }
302
+ outgoing.push(edges);
303
+ report.sampled_targets = targetsHere.size;
304
+ report.unobserved_internal_targets = unobservedHere.size;
305
+ review.internal_links_observed += parsed?.internal ?? 0;
306
+ review.external_links_observed += parsed?.external ?? 0;
307
+ review.nofollow_internal_links += parsed?.nofollow ?? 0;
308
+ review.unsafe_or_query_links_excluded += (parsed?.unsafe ?? 0) + (parsed?.query ?? 0);
309
+ if (report.extraction_limited)
310
+ review.pages_with_truncated_links++;
311
+ if (examined)
312
+ review.html_pages_examined++;
313
+ if (page.robots_allowed === undefined)
314
+ review.robots_unknown_pages++;
315
+ if (page.status_code === undefined)
316
+ review.status_unknown_pages++;
317
+ }
318
+ review.unique_observed_sample_edges = uniqueEdges.size;
319
+ review.distinct_unsampled_link_targets = unseen.size;
320
+ for (let j = 0; j < refs.length; j++) {
321
+ reports[j].incoming_sampled_sources = incoming[j].size;
322
+ reports[j].potential_orphan_in_sample =
323
+ reports[j].html_examined &&
324
+ reports[j].robots_access !== "disallowed" &&
325
+ !roots.has(j) && incoming[j].size === 0;
326
+ }
327
+ // BFS explores only observed HTML links; nofollow and explicitly disallowed
328
+ // targets cannot establish a confident *sampled* navigational route.
329
+ const queue = [];
330
+ for (const root of roots) {
331
+ if (!canTraverse[root])
332
+ continue;
333
+ reports[root].depth_from_entry = 0;
334
+ queue.push(root);
335
+ }
336
+ for (let p = 0; p < queue.length; p++) {
337
+ const at = queue[p];
338
+ if (!canTraverse[at])
339
+ continue;
340
+ for (const edge of outgoing[at]) {
341
+ if (edge.nofollow || input.pages[edge.target].robots_allowed === false ||
342
+ !statusOK(input.pages[edge.target].status_code) ||
343
+ reports[edge.target].depth_from_entry !== null)
344
+ continue;
345
+ reports[edge.target].depth_from_entry = reports[at].depth_from_entry + 1;
346
+ queue.push(edge.target);
347
+ }
348
+ }
349
+ review.pages = reports;
350
+ review.pages_reachable_within_sample = reports.filter((page) => page.depth_from_entry !== null).length;
351
+ review.pages_unreachable_within_sample = reports.length - review.pages_reachable_within_sample;
352
+ review.deepest_observed_sample_depth = Math.max(-1, ...reports.map((page) => page.depth_from_entry ?? -1)) < 0 ? null
353
+ : Math.max(...reports.map((page) => page.depth_from_entry ?? -1));
354
+ review.deep_pages_at_three_or_more =
355
+ reports.filter((page) => (page.depth_from_entry ?? -1) >= 3).length;
356
+ review.potential_orphans_within_sample =
357
+ reports.filter((page) => page.potential_orphan_in_sample).length;
358
+ const referenced = new Set(outgoing.flatMap((edges) => edges.map((e) => e.target)));
359
+ const linkedIssues = (predicate) => [...referenced].filter((target) => predicate(reports[target])).length;
360
+ review.linked_http_error_pages = linkedIssues((p) => p.status_code !== undefined &&
361
+ p.status_code >= 400);
362
+ review.linked_robots_blocked_pages = linkedIssues((p) => p.robots_access === "disallowed");
363
+ review.linked_declared_noindex_pages = linkedIssues((p) => p.noindex_state === "declared");
364
+ review.linked_noncanonical_pages = linkedIssues((p) => p.canonical_state === "different");
365
+ function finding(code, severity, page, count, message, target_page) {
366
+ if (!count)
367
+ return;
368
+ review.total_findings++;
369
+ review.findings.push({
370
+ code, severity, page, count, message,
371
+ ...(target_page ? { target_page } : {}),
372
+ });
373
+ }
374
+ finding("entry_not_sampled", "info", 0, review.entry_pages_missing, "At least one declared entry URL was not included in the page sample; depth for other pages may be unknown.");
375
+ finding("entry_not_crawlable", "warning", 0, [...roots].filter((root) => !statusOK(input.pages[root].status_code) ||
376
+ input.pages[root].robots_allowed === false).length, "At least one observed entry has an HTTP error or explicit robots disallow; it was not traversed.");
377
+ finding("sitemap_pages_unobserved", "info", 0, review.sitemap_urls_without_page_sample, "Some supplied sitemap URLs have no sampled HTML; no orphan or HTTP-status conclusion is possible.");
378
+ finding("unobserved_link_targets", "info", 0, unseen.size, "Observed same-origin links point beyond the supplied page set; those targets have not been verified.");
379
+ finding("sampled_deep_page", "info", 0, review.deep_pages_at_three_or_more, "One or more sampled pages require three or more observed anchor steps from a supplied entry.");
380
+ finding("linked_to_http_error", "warning", 0, review.linked_http_error_pages, "Observed links target sampled pages with supplied HTTP 4xx or 5xx error evidence.");
381
+ finding("linked_to_robots_blocked", "warning", 0, review.linked_robots_blocked_pages, "Some observed links lead to pages reported robots-disallowed for the evaluated service or crawler.");
382
+ finding("linked_to_noindex", "info", 0, review.linked_declared_noindex_pages, "Some observed links target sampled pages declaring noindex; this does not prove actual index status.");
383
+ finding("linked_to_noncanonical", "info", 0, review.linked_noncanonical_pages, "Some observed links target pages declaring a different canonical preference.");
384
+ for (const item of reports) {
385
+ if (!item.html_examined)
386
+ finding("page_html_unverified", "info", item.page, 1, "No usable static HTML was supplied for this page; its outgoing links are unknown.");
387
+ if (item.extraction_limited)
388
+ finding("link_sample_truncated", "info", item.page, 1, "The link extraction cap was reached; additional edges may exist.");
389
+ if (item.potential_orphan_in_sample)
390
+ finding("possible_orphan_in_sample", "info", item.page, 1, "No incoming links from other supplied pages were observed; this is not a verified whole-site orphan.");
391
+ if (item.depth_from_entry === null)
392
+ finding("sampled_page_unreachable", "info", item.page, 1, "No path from the observed entry pages was established within this sampled static graph.");
393
+ if (item.depth_from_entry === null && incoming[item.page - 1].size > 0 &&
394
+ incomingFollowable[item.page - 1].size === 0) {
395
+ finding("nofollow_only_path", "info", item.page, 1, "This page only has sampled inbound links marked nofollow; those links are treated as discovery hints, not hard blocks.");
396
+ }
397
+ if (item.html_examined && item.internal_links === 0)
398
+ finding("no_sampled_outgoing_links", "info", item.page, 1, "No usable same-origin anchor links were found in the inspected static HTML.");
399
+ if (item.unsafe_links_excluded)
400
+ finding("unsafe_links_excluded", "info", item.page, item.unsafe_links_excluded, "Some links were excluded for unsafe or unsupported URL syntax.");
401
+ if (item.query_links_excluded)
402
+ finding("query_links_excluded", "info", item.page, item.query_links_excluded, "Query-bearing URL variants are not conflated with clean path-only pages.");
403
+ if (ignoredBasePages.has(item.page - 1))
404
+ finding("external_base_ignored", "info", item.page, 1, "Untrusted HTML base URL was ignored; relative links were not incorrectly attributed to this origin.");
405
+ }
406
+ review.findings.sort((a, b) => (a.severity === b.severity ? 0 :
407
+ a.severity === "warning" ? -1 : 1) || a.page - b.page || a.code.localeCompare(b.code));
408
+ if (review.total_findings > MAX_GRAPH_FINDINGS) {
409
+ review.findings = review.findings.slice(0, MAX_GRAPH_FINDINGS);
410
+ review.findings_truncated = true;
411
+ }
412
+ return review;
413
+ }
414
+ //# sourceMappingURL=internal-link-graph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal-link-graph.js","sourceRoot":"","sources":["../../../src/modules/site-architecture/internal-link-graph.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC;AACjC,MAAM,CAAC,MAAM,oBAAoB,GAAG,SAAS,CAAC;AAC9C,6EAA6E;AAC7E,MAAM,CAAC,MAAM,0BAA0B,GAAG,SAAS,CAAC;AACpD,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAC5C,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,CAAC;AAC1C,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,CAAC;AACrC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAEtC,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,mBAAmB,EAAE,qBAAqB,EAAE,0BAA0B;IACtE,2BAA2B,EAAE,mBAAmB,EAAE,uBAAuB;IACzE,sBAAsB,EAAE,0BAA0B,EAAE,mBAAmB;IACvE,wBAAwB,EAAE,oBAAoB,EAAE,yBAAyB;IACzE,0BAA0B,EAAE,uBAAuB,EAAE,sBAAsB;IAC3E,uBAAuB,EAAE,sBAAsB,EAAE,2BAA2B;CACpE,CAAC;AAkFX,MAAM,WAAW,GAAG;IAClB,iIAAiI;IACjI,mIAAmI;IACnI,kJAAkJ;IAClJ,yIAAyI;CAC1I,CAAC;AACF,MAAM,K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CAAC;QAC/D,MAAM,CAAC,kBAAkB,GAAG,IAAI,CAAC;IACnC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/**\n * V06: bounded, static internal-link graph analysis.\n * Only observed <a href> URLs are edges; no script execution, network, storage,\n * Googlebot identity, full-site orphan verdict, ranking or PageRank.\n */\nimport { load } from \"cheerio\";\nimport { safeLinkPageUrl } from \"./internal-link-quality.js\";\n\nexport const MAX_GRAPH_PAGES = 8;\nexport const MAX_GRAPH_HTML_BYTES = 1_048_576;\n// The hosted MCP has a 2 MiB request-body cap; leave room for JSON metadata.\nexport const MAX_GRAPH_TOTAL_HTML_BYTES = 1_500_000;\nexport const MAX_GRAPH_LINKS_PER_PAGE = 240;\nexport const MAX_GRAPH_CATALOG_URLS = 256;\nexport const MAX_GRAPH_FINDINGS = 24;\nexport const MAX_GRAPH_LIVE_PAGES = 3;\n\nexport const GRAPH_FINDING_CODES = [\n \"entry_not_sampled\", \"entry_not_crawlable\", \"sampled_page_unreachable\",\n \"possible_orphan_in_sample\", \"sampled_deep_page\", \"link_sample_truncated\",\n \"linked_to_http_error\", \"linked_to_robots_blocked\", \"linked_to_noindex\",\n \"linked_to_noncanonical\", \"nofollow_only_path\", \"unobserved_link_targets\",\n \"sitemap_pages_unobserved\", \"unsafe_links_excluded\", \"query_links_excluded\",\n \"external_base_ignored\", \"page_html_unverified\", \"no_sampled_outgoing_links\",\n] as const;\nexport type GraphFindingCode = typeof GRAPH_FINDING_CODES[number];\ntype GraphScope = \"caller_supplied_link_graph\" | \"live_bounded_public_link_graph\";\nexport interface GraphPageInput {\n url: string;\n html?: string;\n status_code?: number;\n robots_allowed?: boolean;\n noindex?: boolean;\n canonical_url?: string;\n}\nexport interface InternalLinkGraphInput {\n site_url: string;\n pages: GraphPageInput[];\n entry_urls?: string[];\n sitemap_urls?: string[];\n}\nexport interface GraphPageReport {\n page: number;\n html_examined: boolean;\n status_code?: number;\n robots_access: \"allowed\" | \"disallowed\" | \"unknown\";\n noindex_state: \"declared\" | \"not_observed\" | \"unknown\";\n canonical_state: \"self\" | \"different\" | \"ambiguous\" | \"unknown\";\n links_observed: number;\n internal_links: number;\n external_links: number;\n fragment_links: number;\n query_links_excluded: number;\n unsafe_links_excluded: number;\n self_links: number;\n nofollow_internal: number;\n sampled_targets: number;\n unobserved_internal_targets: number;\n incoming_sampled_sources: number;\n depth_from_entry: number | null;\n potential_orphan_in_sample: boolean;\n extraction_limited: boolean;\n}\nexport interface GraphFinding {\n code: GraphFindingCode;\n severity: \"warning\" | \"info\";\n page: number;\n target_page?: number;\n count: number;\n message: string;\n}\nexport interface InternalLinkGraphReview {\n scope: GraphScope;\n pages_observed: number;\n html_pages_examined: number;\n entry_pages_observed: number;\n entry_pages_missing: number;\n pages_reachable_within_sample: number;\n pages_unreachable_within_sample: number;\n deepest_observed_sample_depth: number | null;\n deep_pages_at_three_or_more: number;\n potential_orphans_within_sample: number;\n unique_observed_sample_edges: number;\n internal_links_observed: number;\n external_links_observed: number;\n nofollow_internal_links: number;\n distinct_unsampled_link_targets: number;\n unsafe_or_query_links_excluded: number;\n pages_with_truncated_links: number;\n linked_http_error_pages: number;\n linked_robots_blocked_pages: number;\n linked_declared_noindex_pages: number;\n linked_noncanonical_pages: number;\n sitemap_urls_provided: number;\n sitemap_urls_without_page_sample: number;\n sampled_pages_not_in_sitemap: number;\n robots_unknown_pages: number;\n status_unknown_pages: number;\n coverage_limited: true;\n limitations: string[];\n pages: GraphPageReport[];\n total_findings: number;\n findings: GraphFinding[];\n findings_truncated: boolean;\n error?: string;\n}\nconst limitations = [\n \"Depth is the shortest observed static <a href> path inside the supplied page sample, not a whole-site or Googlebot crawl depth.\",\n \"An orphan candidate has no incoming links from other supplied pages; unobserved site pages and external links may still reach it.\",\n \"Sitemap URLs are independent caller-supplied labels. Unobserved sitemap pages are not proven orphans, and a sitemap does not guarantee indexing.\",\n \"JavaScript-rendered links, query variants, historical responses, redirects and Google-selected canonicals are not followed or verified.\",\n];\nconst bytes = (s: string): number => new TextEncoder().encode(s).byteLength;\nconst statusOK = (s?: number): boolean =>\n s === undefined || (s >= 200 && s < 300 && ![204, 205, 206].includes(s));\nfunction safeLabel(value: unknown): string | undefined {\n if (typeof value !== \"string\" || bytes(value) > 512 ||\n /[\\u0000-\\u001f\\u007f-\\u009f\\u202a-\\u202e\\u2066-\\u2069\\\\]/u.test(value)) return undefined;\n return safeLinkPageUrl(value);\n}\n\ntype Edge = { to: string; nofollow: boolean };\ntype Extraction = {\n links: number; internal: number; external: number; fragments: number;\n query: number; unsafe: number; self: number; nofollow: number;\n limited: boolean; ignoredBase: boolean; edges: Edge[];\n};\n\n/** Reuse this pure extractor to select a tiny subset of safe same-origin live links. */\nexport function extractGraphLinks(html: string, pageUrl: string): Extraction {\n const safe = safeLabel(pageUrl);\n if (!safe || typeof html !== \"string\" || bytes(html) > MAX_GRAPH_HTML_BYTES) {\n throw new Error(\"Graph HTML or URL is not safe within bounded limits.\");\n }\n const origin = new URL(safe).origin;\n const $ = load(html);\n // Template/JS nodes have no established network-visible navigation edges.\n $(\"template,script,noscript\").remove();\n const baseHref = $(\"head > base[href]\").first().attr(\"href\");\n let base = safe;\n let ignoredBase = false;\n if (baseHref !== undefined) {\n try {\n const candidate = new URL(baseHref, safe);\n const usable = safeLabel(candidate.href);\n if (!usable || candidate.origin !== origin) ignoredBase = true;\n else base = usable;\n } catch {\n ignoredBase = true;\n }\n }\n const anchors = $(\"body a[href]\").toArray();\n const sample = anchors.slice(0, MAX_GRAPH_LINKS_PER_PAGE);\n const out: Extraction = {\n links: sample.length, internal: 0, external: 0, fragments: 0,\n query: 0, unsafe: 0, self: 0, nofollow: 0,\n limited: anchors.length > MAX_GRAPH_LINKS_PER_PAGE,\n ignoredBase, edges: [],\n };\n for (const anchor of sample) {\n const raw = ($(anchor).attr(\"href\") ?? \"\").trim();\n if (!raw || bytes(raw) > 1_024 ||\n /[\\u0000-\\u001f\\u007f-\\u009f\\u202a-\\u202e\\u2066-\\u2069\\\\]/u.test(raw)) {\n out.unsafe++; continue;\n }\n if (raw.startsWith(\"#\")) { out.fragments++; continue; }\n // A foreign or invalid <base> changes how relative URLs resolve in a browser.\n // Do not silently assume they refer to this site's own paths.\n if (ignoredBase && !/^[a-z][a-z0-9+.-]*:/iu.test(raw) && !raw.startsWith(\"//\")) {\n out.unsafe++; continue;\n }\n try {\n const target = new URL(raw, base);\n if (![\"http:\", \"https:\"].includes(target.protocol) ||\n !target.hostname || target.username || target.password || target.port) {\n out.unsafe++; continue;\n }\n if (target.origin !== origin) { out.external++; continue; }\n if (target.search || raw.includes(\"?\")) { out.query++; continue; }\n target.hash = \"\";\n const usable = safeLabel(target.href);\n if (!usable) { out.unsafe++; continue; }\n out.internal++;\n if (usable === safe) { out.self++; continue; }\n const nofollow = ($(anchor).attr(\"rel\") ?? \"\").toLowerCase()\n .split(/\\s+/u).includes(\"nofollow\");\n if (nofollow) out.nofollow++;\n out.edges.push({ to: usable, nofollow });\n } catch {\n out.unsafe++;\n }\n }\n return out;\n}\n\n/** Select next live targets without leaking the target URLs in MCP results. */\nexport function graphLiveTargets(html: string, pageUrl: string): string[] {\n const links = extractGraphLinks(html, pageUrl);\n return Array.from(new Set(links.edges.filter((e) => !e.nofollow)\n .map((e) => e.to))).slice(0, MAX_GRAPH_LINKS_PER_PAGE);\n}\n\nfunction noindexInHtml(html: string): boolean {\n const $ = load(html);\n for (const el of $(\"head meta[name][content]\").toArray()) {\n const name = ($(el).attr(\"name\") ?? \"\").trim().toLowerCase();\n if (name !== \"robots\" && name !== \"googlebot\") continue;\n const content = ($(el).attr(\"content\") ?? \"\").toLowerCase();\n if (content.split(/[,;\\s]+/u).some((token) => token === \"noindex\" || token === \"none\")) return true;\n }\n return false;\n}\nfunction canonicalInHtml(html: string, url: string): \"self\" | \"different\" | \"ambiguous\" | \"unknown\" {\n const $ = load(html);\n const values = $(\"head link[rel][href]\").toArray().filter((el) =>\n ($(el).attr(\"rel\") ?? \"\").toLowerCase().split(/\\s+/u).includes(\"canonical\"));\n if (!values.length) return \"unknown\";\n const targets = new Set<string>();\n for (const el of values) {\n const href = $(el).attr(\"href\") ?? \"\";\n try {\n const target = new URL(href, url);\n target.hash = \"\";\n const safe = safeLabel(target.href);\n if (!safe) return \"ambiguous\";\n targets.add(safe);\n } catch { return \"ambiguous\"; }\n }\n if (targets.size !== 1) return \"ambiguous\";\n return [...targets][0] === url ? \"self\" : \"different\";\n}\n\nexport function emptyInternalLinkGraphReview(\n scope: GraphScope = \"caller_supplied_link_graph\",\n): InternalLinkGraphReview {\n return {\n scope, pages_observed: 0, html_pages_examined: 0,\n entry_pages_observed: 0, entry_pages_missing: 0,\n pages_reachable_within_sample: 0, pages_unreachable_within_sample: 0,\n deepest_observed_sample_depth: null, deep_pages_at_three_or_more: 0,\n potential_orphans_within_sample: 0, unique_observed_sample_edges: 0,\n internal_links_observed: 0, external_links_observed: 0,\n nofollow_internal_links: 0, distinct_unsampled_link_targets: 0,\n unsafe_or_query_links_excluded: 0, pages_with_truncated_links: 0,\n linked_http_error_pages: 0, linked_robots_blocked_pages: 0,\n linked_declared_noindex_pages: 0, linked_noncanonical_pages: 0,\n sitemap_urls_provided: 0, sitemap_urls_without_page_sample: 0,\n sampled_pages_not_in_sitemap: 0, robots_unknown_pages: 0,\n status_unknown_pages: 0, coverage_limited: true, limitations,\n pages: [], total_findings: 0, findings: [], findings_truncated: false,\n };\n}\n\nexport function analyzeInternalLinkGraph(\n input: InternalLinkGraphInput,\n scope: GraphScope = \"caller_supplied_link_graph\",\n): InternalLinkGraphReview {\n const site = safeLabel(input?.site_url);\n if (!site || !Array.isArray(input.pages) ||\n input.pages.length < 1 || input.pages.length > MAX_GRAPH_PAGES) {\n throw new Error(\"Supply one to eight safe, same-origin page observations.\");\n }\n const rootSite = new URL(site).origin;\n const refs = input.pages.map((item) => {\n const url = safeLabel(item?.url);\n if (!url || new URL(url).origin !== rootSite ||\n (item.html !== undefined && (typeof item.html !== \"string\" ||\n bytes(item.html) > MAX_GRAPH_HTML_BYTES)) ||\n (item.status_code !== undefined && (!Number.isInteger(item.status_code) ||\n item.status_code < 100 || item.status_code > 599)) ||\n (item.noindex !== undefined && typeof item.noindex !== \"boolean\") ||\n (item.robots_allowed !== undefined && typeof item.robots_allowed !== \"boolean\") ||\n (item.canonical_url !== undefined && !safeLabel(item.canonical_url))) {\n throw new Error(\"All page evidence must be valid, bounded and same-origin.\");\n }\n return url;\n });\n if (new Set(refs).size !== refs.length) throw new Error(\"Page URLs must be unique.\");\n const totalHtml = input.pages.reduce((sum, page) => sum + bytes(page.html ?? \"\"), 0);\n if (totalHtml > MAX_GRAPH_TOTAL_HTML_BYTES) throw new Error(\"Combined HTML exceeds the graph byte budget.\");\n const entries = input.entry_urls ?? [rootSite + \"/\"];\n const catalog = input.sitemap_urls ?? [];\n if (!Array.isArray(entries) || entries.length > MAX_GRAPH_PAGES ||\n !Array.isArray(catalog) || catalog.length > MAX_GRAPH_CATALOG_URLS) {\n throw new Error(\"Entry roots or sitemap URL evidence exceed bounded limits.\");\n }\n const entryRefs = entries.map((value) => {\n const normalized = safeLabel(value);\n if (!normalized || new URL(normalized).origin !== rootSite) throw new Error(\"Invalid entry URL evidence.\");\n return normalized;\n });\n const catalogRefs = catalog.map((value) => {\n const normalized = safeLabel(value);\n if (!normalized || new URL(normalized).origin !== rootSite) throw new Error(\"Invalid sitemap URL evidence.\");\n return normalized;\n });\n if (new Set(entryRefs).size !== entryRefs.length ||\n new Set(catalogRefs).size !== catalogRefs.length) throw new Error(\"Graph label arrays require unique URLs.\");\n const review = emptyInternalLinkGraphReview(scope);\n review.pages_observed = input.pages.length;\n review.sitemap_urls_provided = catalogRefs.length;\n const byUrl = new Map(refs.map((url, index) => [url, index]));\n review.sitemap_urls_without_page_sample = catalogRefs.filter((url) => !byUrl.has(url)).length;\n const inSitemap = new Set(catalogRefs);\n if (catalogRefs.length) review.sampled_pages_not_in_sitemap =\n refs.filter((url) => !inSitemap.has(url)).length;\n const roots = new Set(entryRefs.map((value) => byUrl.get(value)).filter((n): n is number => n !== undefined));\n review.entry_pages_observed = roots.size;\n review.entry_pages_missing = entryRefs.length - roots.size;\n\n const outgoing: Array<Array<{ target: number; nofollow: boolean }>> = [];\n const incoming: Array<Set<number>> = refs.map(() => new Set());\n const incomingFollowable: Array<Set<number>> = refs.map(() => new Set());\n const ignoredBasePages = new Set<number>();\n const uniqueEdges = new Set<string>();\n const unseen = new Set<string>();\n const reports: GraphPageReport[] = [];\n const canTraverse: boolean[] = [];\n\n for (const [i, page] of input.pages.entries()) {\n const examined = page.html !== undefined && statusOK(page.status_code);\n const parsed = examined ? extractGraphLinks(page.html!, refs[i]) : undefined;\n if (parsed?.ignoredBase) ignoredBasePages.add(i);\n const htmlNoindex = examined ? noindexInHtml(page.html!) : false;\n const noindexState: GraphPageReport[\"noindex_state\"] =\n page.noindex === true || htmlNoindex ? \"declared\"\n : examined || page.noindex === false ? \"not_observed\" : \"unknown\";\n const observedCanonical = page.canonical_url ? safeLabel(page.canonical_url) : undefined;\n const canonicalState: GraphPageReport[\"canonical_state\"] = observedCanonical\n ? observedCanonical === refs[i] ? \"self\" : \"different\"\n : examined ? canonicalInHtml(page.html!, refs[i]) : \"unknown\";\n const report: GraphPageReport = {\n page: i + 1, html_examined: examined,\n ...(page.status_code === undefined ? {} : { status_code: page.status_code }),\n robots_access: page.robots_allowed === undefined ? \"unknown\"\n : page.robots_allowed ? \"allowed\" : \"disallowed\",\n noindex_state: noindexState, canonical_state: canonicalState,\n links_observed: parsed?.links ?? 0,\n internal_links: parsed?.internal ?? 0, external_links: parsed?.external ?? 0,\n fragment_links: parsed?.fragments ?? 0, query_links_excluded: parsed?.query ?? 0,\n unsafe_links_excluded: parsed?.unsafe ?? 0,\n self_links: parsed?.self ?? 0, nofollow_internal: parsed?.nofollow ?? 0,\n sampled_targets: 0, unobserved_internal_targets: 0,\n incoming_sampled_sources: 0, depth_from_entry: null,\n potential_orphan_in_sample: false, extraction_limited: parsed?.limited ?? false,\n };\n reports.push(report);\n canTraverse.push(examined && page.robots_allowed !== false);\n const targetsHere = new Set<number>();\n const unobservedHere = new Set<string>();\n const edges: Array<{ target: number; nofollow: boolean }> = [];\n if (parsed) {\n for (const e of parsed.edges) {\n const index = byUrl.get(e.to);\n if (index === undefined) { unseen.add(e.to); unobservedHere.add(e.to); continue; }\n targetsHere.add(index);\n incoming[index].add(i);\n if (!e.nofollow) incomingFollowable[index].add(i);\n uniqueEdges.add(i + \":\" + index);\n edges.push({ target: index, nofollow: e.nofollow });\n }\n }\n outgoing.push(edges);\n report.sampled_targets = targetsHere.size;\n report.unobserved_internal_targets = unobservedHere.size;\n review.internal_links_observed += parsed?.internal ?? 0;\n review.external_links_observed += parsed?.external ?? 0;\n review.nofollow_internal_links += parsed?.nofollow ?? 0;\n review.unsafe_or_query_links_excluded += (parsed?.unsafe ?? 0) + (parsed?.query ?? 0);\n if (report.extraction_limited) review.pages_with_truncated_links++;\n if (examined) review.html_pages_examined++;\n if (page.robots_allowed === undefined) review.robots_unknown_pages++;\n if (page.status_code === undefined) review.status_unknown_pages++;\n }\n review.unique_observed_sample_edges = uniqueEdges.size;\n review.distinct_unsampled_link_targets = unseen.size;\n for (let j = 0; j < refs.length; j++) {\n reports[j].incoming_sampled_sources = incoming[j].size;\n reports[j].potential_orphan_in_sample =\n reports[j].html_examined &&\n reports[j].robots_access !== \"disallowed\" &&\n !roots.has(j) && incoming[j].size === 0;\n }\n\n // BFS explores only observed HTML links; nofollow and explicitly disallowed\n // targets cannot establish a confident *sampled* navigational route.\n const queue: number[] = [];\n for (const root of roots) {\n if (!canTraverse[root]) continue;\n reports[root].depth_from_entry = 0;\n queue.push(root);\n }\n for (let p = 0; p < queue.length; p++) {\n const at = queue[p];\n if (!canTraverse[at]) continue;\n for (const edge of outgoing[at]) {\n if (edge.nofollow || input.pages[edge.target].robots_allowed === false ||\n !statusOK(input.pages[edge.target].status_code) ||\n reports[edge.target].depth_from_entry !== null) continue;\n reports[edge.target].depth_from_entry = reports[at].depth_from_entry! + 1;\n queue.push(edge.target);\n }\n }\n review.pages = reports;\n review.pages_reachable_within_sample = reports.filter((page) => page.depth_from_entry !== null).length;\n review.pages_unreachable_within_sample = reports.length - review.pages_reachable_within_sample;\n review.deepest_observed_sample_depth = Math.max(-1,\n ...reports.map((page) => page.depth_from_entry ?? -1)) < 0 ? null\n : Math.max(...reports.map((page) => page.depth_from_entry ?? -1));\n review.deep_pages_at_three_or_more =\n reports.filter((page) => (page.depth_from_entry ?? -1) >= 3).length;\n review.potential_orphans_within_sample =\n reports.filter((page) => page.potential_orphan_in_sample).length;\n\n const referenced = new Set(outgoing.flatMap((edges) => edges.map((e) => e.target)));\n const linkedIssues = (predicate: (n: GraphPageReport) => boolean): number =>\n [...referenced].filter((target) => predicate(reports[target])).length;\n review.linked_http_error_pages = linkedIssues((p) => p.status_code !== undefined &&\n p.status_code >= 400);\n review.linked_robots_blocked_pages = linkedIssues((p) => p.robots_access === \"disallowed\");\n review.linked_declared_noindex_pages = linkedIssues((p) => p.noindex_state === \"declared\");\n review.linked_noncanonical_pages = linkedIssues((p) => p.canonical_state === \"different\");\n\n function finding(code: GraphFindingCode, severity: GraphFinding[\"severity\"],\n page: number, count: number, message: string, target_page?: number): void {\n if (!count) return;\n review.total_findings++;\n review.findings.push({\n code, severity, page, count, message,\n ...(target_page ? { target_page } : {}),\n });\n }\n finding(\"entry_not_sampled\", \"info\", 0, review.entry_pages_missing,\n \"At least one declared entry URL was not included in the page sample; depth for other pages may be unknown.\");\n finding(\"entry_not_crawlable\", \"warning\", 0,\n [...roots].filter((root) => !statusOK(input.pages[root].status_code) ||\n input.pages[root].robots_allowed === false).length,\n \"At least one observed entry has an HTTP error or explicit robots disallow; it was not traversed.\");\n finding(\"sitemap_pages_unobserved\", \"info\", 0, review.sitemap_urls_without_page_sample,\n \"Some supplied sitemap URLs have no sampled HTML; no orphan or HTTP-status conclusion is possible.\");\n finding(\"unobserved_link_targets\", \"info\", 0, unseen.size,\n \"Observed same-origin links point beyond the supplied page set; those targets have not been verified.\");\n finding(\"sampled_deep_page\", \"info\", 0, review.deep_pages_at_three_or_more,\n \"One or more sampled pages require three or more observed anchor steps from a supplied entry.\");\n finding(\"linked_to_http_error\", \"warning\", 0, review.linked_http_error_pages,\n \"Observed links target sampled pages with supplied HTTP 4xx or 5xx error evidence.\");\n finding(\"linked_to_robots_blocked\", \"warning\", 0, review.linked_robots_blocked_pages,\n \"Some observed links lead to pages reported robots-disallowed for the evaluated service or crawler.\");\n finding(\"linked_to_noindex\", \"info\", 0, review.linked_declared_noindex_pages,\n \"Some observed links target sampled pages declaring noindex; this does not prove actual index status.\");\n finding(\"linked_to_noncanonical\", \"info\", 0, review.linked_noncanonical_pages,\n \"Some observed links target pages declaring a different canonical preference.\");\n for (const item of reports) {\n if (!item.html_examined) finding(\"page_html_unverified\", \"info\", item.page, 1,\n \"No usable static HTML was supplied for this page; its outgoing links are unknown.\");\n if (item.extraction_limited) finding(\"link_sample_truncated\", \"info\", item.page, 1,\n \"The link extraction cap was reached; additional edges may exist.\");\n if (item.potential_orphan_in_sample) finding(\"possible_orphan_in_sample\", \"info\",\n item.page, 1, \"No incoming links from other supplied pages were observed; this is not a verified whole-site orphan.\");\n if (item.depth_from_entry === null) finding(\"sampled_page_unreachable\", \"info\",\n item.page, 1, \"No path from the observed entry pages was established within this sampled static graph.\");\n if (item.depth_from_entry === null && incoming[item.page - 1].size > 0 &&\n incomingFollowable[item.page - 1].size === 0) {\n finding(\"nofollow_only_path\", \"info\", item.page, 1,\n \"This page only has sampled inbound links marked nofollow; those links are treated as discovery hints, not hard blocks.\");\n }\n if (item.html_examined && item.internal_links === 0) finding(\"no_sampled_outgoing_links\",\n \"info\", item.page, 1, \"No usable same-origin anchor links were found in the inspected static HTML.\");\n if (item.unsafe_links_excluded) finding(\"unsafe_links_excluded\", \"info\",\n item.page, item.unsafe_links_excluded, \"Some links were excluded for unsafe or unsupported URL syntax.\");\n if (item.query_links_excluded) finding(\"query_links_excluded\", \"info\",\n item.page, item.query_links_excluded, \"Query-bearing URL variants are not conflated with clean path-only pages.\");\n if (ignoredBasePages.has(item.page - 1)) finding(\"external_base_ignored\", \"info\",\n item.page, 1, \"Untrusted HTML base URL was ignored; relative links were not incorrectly attributed to this origin.\");\n }\n review.findings.sort((a, b) => (a.severity === b.severity ? 0 :\n a.severity === \"warning\" ? -1 : 1) || a.page - b.page || a.code.localeCompare(b.code));\n if (review.total_findings > MAX_GRAPH_FINDINGS) {\n review.findings = review.findings.slice(0, MAX_GRAPH_FINDINGS);\n review.findings_truncated = true;\n }\n return review;\n}\n"]}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * P1-08: conservative internal-link and anchor-label quality review.
3
+ *
4
+ * The analyzed graph is strictly the caller-supplied same-origin HTML sample.
5
+ * No network, source authentication, semantic topic classifier or ranking data.
6
+ */
7
+ export declare const MAX_LINK_PAGES = 8;
8
+ export declare const MAX_LINK_HTML_BYTES = 160000;
9
+ export declare const MAX_LINK_TOTAL_HTML_BYTES = 900000;
10
+ export declare const MAX_LINKS_PER_PAGE = 160;
11
+ export declare const MAX_LINK_FINDINGS = 12;
12
+ export interface InternalLinkObservation {
13
+ url: string;
14
+ title: string;
15
+ h1: string;
16
+ main_present: boolean;
17
+ navigation_links_excluded: number;
18
+ extraction_limited: boolean;
19
+ links: Array<{
20
+ href: string;
21
+ label: string;
22
+ accessible: boolean;
23
+ nofollow: boolean;
24
+ }>;
25
+ }
26
+ export type InternalLinkFindingCode = "accessible_anchor_missing" | "generic_anchor_text" | "repeated_anchor_multiple_targets" | "anchor_target_heading_low_overlap" | "nofollow_contextual_internal" | "no_sampled_contextual_internal_links" | "no_contextual_internal_links" | "sampled_target_unobserved" | "page_main_missing" | "link_sample_truncated";
27
+ export interface InternalLinkFinding {
28
+ code: InternalLinkFindingCode;
29
+ severity: "warning" | "info";
30
+ confidence: "observed" | "review";
31
+ source_page: number;
32
+ target_page?: number;
33
+ count: number;
34
+ message: string;
35
+ }
36
+ export interface InternalLinkPageReview {
37
+ page: number;
38
+ main_present: boolean;
39
+ internal_links: number;
40
+ external_links: number;
41
+ linked_sample_pages: number;
42
+ unmatched_internal_links: number;
43
+ missing_anchor_labels: number;
44
+ generic_anchor_links: number;
45
+ nofollow_internal_links: number;
46
+ self_links: number;
47
+ fragment_only_links: number;
48
+ extraction_limited: boolean;
49
+ }
50
+ export interface InternalLinkReview {
51
+ scope: "caller_supplied_same_origin_html_only";
52
+ pages_sampled: number;
53
+ pages_eligible: number;
54
+ origin: string;
55
+ internal_links_observed: number;
56
+ external_links_observed: number;
57
+ excluded_navigation_links: number;
58
+ linked_sample_targets: number;
59
+ unmatched_internal_links: number;
60
+ missing_anchor_labels: number;
61
+ generic_anchor_links: number;
62
+ low_heading_overlap_links: number;
63
+ ambiguous_anchor_target_groups: number;
64
+ nofollow_internal_links: number;
65
+ self_links: number;
66
+ fragment_only_links: number;
67
+ skipped_non_http_links: number;
68
+ pages: InternalLinkPageReview[];
69
+ coverage_limited: true;
70
+ limitations: string[];
71
+ total_findings: number;
72
+ findings: InternalLinkFinding[];
73
+ findings_truncated: boolean;
74
+ }
75
+ export declare function emptyInternalLinkReview(): InternalLinkReview;
76
+ export declare function safeLinkPageUrl(raw: string): string | undefined;
77
+ export declare function reviewInternalLinks(observations: readonly InternalLinkObservation[]): InternalLinkReview;