milieu-cli 0.3.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (330) hide show
  1. package/README.md +177 -76
  2. package/dist/bridges/context/agents-json.d.ts +0 -1
  3. package/dist/bridges/context/agents-json.js +21 -12
  4. package/dist/bridges/context/auth-clarity.d.ts +0 -1
  5. package/dist/bridges/context/auth-clarity.js +11 -9
  6. package/dist/bridges/context/auth-legibility.d.ts +2 -2
  7. package/dist/bridges/context/auth-legibility.js +67 -60
  8. package/dist/bridges/context/index.d.ts +1 -2
  9. package/dist/bridges/context/index.js +19 -40
  10. package/dist/bridges/context/oauth-metadata.d.ts +14 -0
  11. package/dist/bridges/context/oauth-metadata.js +127 -0
  12. package/dist/bridges/context/probe.d.ts +33 -0
  13. package/dist/bridges/context/probe.js +157 -0
  14. package/dist/bridges/context/rate-limits.d.ts +5 -2
  15. package/dist/bridges/context/rate-limits.js +27 -51
  16. package/dist/bridges/context/tos-contact.d.ts +13 -4
  17. package/dist/bridges/context/tos-contact.js +108 -46
  18. package/dist/bridges/context/versioning.d.ts +1 -2
  19. package/dist/bridges/context/versioning.js +42 -7
  20. package/dist/bridges/index.d.ts +0 -1
  21. package/dist/bridges/index.js +0 -1
  22. package/dist/bridges/reachability/crawler-policy.d.ts +30 -10
  23. package/dist/bridges/reachability/crawler-policy.js +41 -56
  24. package/dist/bridges/reachability/http-status.d.ts +3 -2
  25. package/dist/bridges/reachability/http-status.js +18 -3
  26. package/dist/bridges/reachability/https-check.d.ts +2 -2
  27. package/dist/bridges/reachability/https-check.js +6 -3
  28. package/dist/bridges/reachability/index.d.ts +1 -2
  29. package/dist/bridges/reachability/index.js +34 -43
  30. package/dist/bridges/reachability/meta-robots.d.ts +0 -13
  31. package/dist/bridges/reachability/meta-robots.js +89 -101
  32. package/dist/bridges/reachability/robots-parser.d.ts +7 -7
  33. package/dist/bridges/reachability/robots-parser.js +65 -15
  34. package/dist/bridges/reachability/robots-txt.d.ts +4 -2
  35. package/dist/bridges/reachability/robots-txt.js +33 -60
  36. package/dist/bridges/schema/descriptions.d.ts +2 -2
  37. package/dist/bridges/schema/descriptions.js +79 -44
  38. package/dist/bridges/schema/error-schemas.d.ts +2 -2
  39. package/dist/bridges/schema/error-schemas.js +31 -18
  40. package/dist/bridges/schema/index.d.ts +2 -2
  41. package/dist/bridges/schema/index.js +48 -30
  42. package/dist/bridges/schema/oas-types.d.ts +65 -26
  43. package/dist/bridges/schema/oas-types.js +37 -7
  44. package/dist/bridges/schema/operation-ids.d.ts +2 -2
  45. package/dist/bridges/schema/operation-ids.js +2 -3
  46. package/dist/bridges/schema/required-fields.d.ts +2 -2
  47. package/dist/bridges/schema/required-fields.js +12 -10
  48. package/dist/bridges/schema/schema-sources.d.ts +19 -0
  49. package/dist/bridges/schema/schema-sources.js +182 -0
  50. package/dist/bridges/schema/schema-types.d.ts +2 -2
  51. package/dist/bridges/schema/schema-types.js +20 -21
  52. package/dist/bridges/separation/api-presence.d.ts +3 -15
  53. package/dist/bridges/separation/api-presence.js +34 -85
  54. package/dist/bridges/separation/developer-docs.d.ts +6 -18
  55. package/dist/bridges/separation/developer-docs.js +100 -99
  56. package/dist/bridges/separation/docs-discovery.d.ts +28 -0
  57. package/dist/bridges/separation/docs-discovery.js +95 -0
  58. package/dist/bridges/separation/evidence-summary.d.ts +2 -0
  59. package/dist/bridges/separation/evidence-summary.js +67 -0
  60. package/dist/bridges/separation/index.d.ts +2 -19
  61. package/dist/bridges/separation/index.js +35 -39
  62. package/dist/bridges/separation/published-routes.d.ts +69 -0
  63. package/dist/bridges/separation/published-routes.js +271 -0
  64. package/dist/bridges/separation/sdk-references.d.ts +8 -3
  65. package/dist/bridges/separation/sdk-references.js +86 -61
  66. package/dist/bridges/separation/webhook-support.d.ts +3 -23
  67. package/dist/bridges/separation/webhook-support.js +61 -162
  68. package/dist/bridges/standards/a2a-agent-card.d.ts +0 -1
  69. package/dist/bridges/standards/a2a-agent-card.js +24 -9
  70. package/dist/bridges/standards/graphql.d.ts +3 -4
  71. package/dist/bridges/standards/graphql.js +70 -66
  72. package/dist/bridges/standards/index.d.ts +1 -2
  73. package/dist/bridges/standards/index.js +57 -47
  74. package/dist/bridges/standards/json-ld.d.ts +25 -11
  75. package/dist/bridges/standards/json-ld.js +114 -56
  76. package/dist/bridges/standards/llms-txt.d.ts +4 -2
  77. package/dist/bridges/standards/llms-txt.js +46 -32
  78. package/dist/bridges/standards/markdown-negotiation.d.ts +4 -1
  79. package/dist/bridges/standards/markdown-negotiation.js +16 -11
  80. package/dist/bridges/standards/mcp.d.ts +3 -12
  81. package/dist/bridges/standards/mcp.js +89 -132
  82. package/dist/bridges/standards/openapi.d.ts +7 -15
  83. package/dist/bridges/standards/openapi.js +657 -207
  84. package/dist/bridges/standards/probe-evidence.d.ts +30 -0
  85. package/dist/bridges/standards/probe-evidence.js +90 -0
  86. package/dist/bridges/standards/schema-org.d.ts +15 -9
  87. package/dist/bridges/standards/schema-org.js +38 -64
  88. package/dist/bridges/standards/sitemap.d.ts +2 -3
  89. package/dist/bridges/standards/sitemap.js +161 -169
  90. package/dist/bridges/standards/well-known.d.ts +3 -7
  91. package/dist/bridges/standards/well-known.js +28 -12
  92. package/dist/cli/index.d.ts +1 -1
  93. package/dist/cli/index.js +107 -22
  94. package/dist/cli/journey-commands.d.ts +3 -0
  95. package/dist/cli/journey-commands.js +35 -0
  96. package/dist/cli/read-report.d.ts +2 -0
  97. package/dist/cli/read-report.js +11 -0
  98. package/dist/core/bridge-output.d.ts +11 -0
  99. package/dist/core/bridge-output.js +86 -0
  100. package/dist/core/bridge-session.d.ts +28 -0
  101. package/dist/core/bridge-session.js +58 -0
  102. package/dist/core/bridge-worker.d.ts +1 -0
  103. package/dist/core/bridge-worker.js +66 -0
  104. package/dist/core/diff.d.ts +79 -0
  105. package/dist/core/diff.js +499 -0
  106. package/dist/core/explanations.d.ts +1 -3
  107. package/dist/core/explanations.js +36 -59
  108. package/dist/core/index.d.ts +4 -2
  109. package/dist/core/index.js +2 -3
  110. package/dist/core/scan-options.d.ts +0 -1
  111. package/dist/core/scan-options.js +14 -6
  112. package/dist/core/scan.d.ts +0 -1
  113. package/dist/core/scan.js +91 -41
  114. package/dist/core/scoring.d.ts +6 -0
  115. package/dist/core/scoring.js +27 -0
  116. package/dist/core/types.d.ts +97 -61
  117. package/dist/core/types.js +9 -3
  118. package/dist/core/validate-report.d.ts +5 -0
  119. package/dist/core/validate-report.js +95 -0
  120. package/dist/core/version.d.ts +0 -1
  121. package/dist/core/version.js +0 -1
  122. package/dist/index.d.ts +0 -1
  123. package/dist/index.js +0 -1
  124. package/dist/journey/body-worker.d.ts +27 -0
  125. package/dist/journey/body-worker.js +140 -0
  126. package/dist/journey/case.d.ts +74 -0
  127. package/dist/journey/case.js +187 -0
  128. package/dist/journey/cli.d.ts +14 -0
  129. package/dist/journey/cli.js +226 -0
  130. package/dist/journey/compare.d.ts +43 -0
  131. package/dist/journey/compare.js +83 -0
  132. package/dist/journey/contracts.d.ts +143 -0
  133. package/dist/journey/contracts.js +37 -0
  134. package/dist/journey/decision.d.ts +72 -0
  135. package/dist/journey/decision.js +121 -0
  136. package/dist/journey/demo.d.ts +36 -0
  137. package/dist/journey/demo.js +137 -0
  138. package/dist/journey/document.d.ts +8 -0
  139. package/dist/journey/document.js +113 -0
  140. package/dist/journey/excerpt.d.ts +6 -0
  141. package/dist/journey/excerpt.js +54 -0
  142. package/dist/journey/name-guidance.d.ts +2 -0
  143. package/dist/journey/name-guidance.js +41 -0
  144. package/dist/journey/providers.d.ts +34 -0
  145. package/dist/journey/providers.js +197 -0
  146. package/dist/journey/report-validation.d.ts +3 -0
  147. package/dist/journey/report-validation.js +457 -0
  148. package/dist/journey/runner.d.ts +12 -0
  149. package/dist/journey/runner.js +321 -0
  150. package/dist/journey/scope.d.ts +8 -0
  151. package/dist/journey/scope.js +50 -0
  152. package/dist/journey/transport.d.ts +3 -0
  153. package/dist/journey/transport.js +45 -0
  154. package/dist/journey/verify.d.ts +21 -0
  155. package/dist/journey/verify.js +213 -0
  156. package/dist/render/colors.d.ts +6 -7
  157. package/dist/render/colors.js +16 -25
  158. package/dist/render/discovery-guidance.d.ts +3 -0
  159. package/dist/render/discovery-guidance.js +66 -0
  160. package/dist/render/format-bridge.d.ts +1 -2
  161. package/dist/render/format-bridge.js +22 -17
  162. package/dist/render/format-diff.d.ts +2 -0
  163. package/dist/render/format-diff.js +169 -0
  164. package/dist/render/format-scan.d.ts +0 -1
  165. package/dist/render/format-scan.js +6 -4
  166. package/dist/render/format-verbose.d.ts +0 -1
  167. package/dist/render/format-verbose.js +7 -4
  168. package/dist/render/index.d.ts +0 -1
  169. package/dist/render/index.js +1 -2
  170. package/dist/render/oauth-observations.d.ts +4 -0
  171. package/dist/render/oauth-observations.js +27 -0
  172. package/dist/render/progress-bar.d.ts +1 -2
  173. package/dist/render/progress-bar.js +8 -6
  174. package/dist/render/robots-inventory.d.ts +3 -0
  175. package/dist/render/robots-inventory.js +38 -0
  176. package/dist/render/symbols.d.ts +4 -10
  177. package/dist/render/symbols.js +15 -17
  178. package/dist/render/terminal-text.d.ts +1 -3
  179. package/dist/render/terminal-text.js +1 -5
  180. package/dist/utils/analysis-worker-entry.d.ts +3 -0
  181. package/dist/utils/analysis-worker-entry.js +12 -0
  182. package/dist/utils/analysis-worker.d.ts +12 -0
  183. package/dist/utils/analysis-worker.js +54 -0
  184. package/dist/utils/html.d.ts +39 -0
  185. package/dist/utils/html.js +261 -0
  186. package/dist/utils/http-client.d.ts +24 -17
  187. package/dist/utils/http-client.js +166 -200
  188. package/dist/utils/http-types.d.ts +43 -0
  189. package/dist/utils/http-types.js +11 -0
  190. package/dist/utils/index.d.ts +0 -1
  191. package/dist/utils/index.js +0 -1
  192. package/dist/utils/package-registry.d.ts +11 -0
  193. package/dist/utils/package-registry.js +69 -0
  194. package/dist/utils/read-json-file.d.ts +3 -0
  195. package/dist/utils/read-json-file.js +41 -0
  196. package/dist/utils/record.d.ts +1 -0
  197. package/dist/utils/record.js +3 -0
  198. package/dist/utils/response-body.d.ts +7 -0
  199. package/dist/utils/response-body.js +71 -0
  200. package/dist/utils/ssrf.d.ts +11 -15
  201. package/dist/utils/ssrf.js +80 -44
  202. package/dist/utils/terminal-text.d.ts +2 -0
  203. package/dist/utils/terminal-text.js +4 -0
  204. package/dist/utils/url.d.ts +29 -1
  205. package/dist/utils/url.js +147 -17
  206. package/docs/examples/onboarding/account-claim.json +25 -0
  207. package/docs/examples/onboarding/pages/account-claim.html +3 -0
  208. package/docs/examples/onboarding/pages/production-activation.html +3 -0
  209. package/docs/examples/onboarding/pages/test-credential.html +3 -0
  210. package/docs/examples/onboarding/production-activation.json +25 -0
  211. package/docs/examples/onboarding/test-credential.json +25 -0
  212. package/docs/journey-qualification.md +46 -0
  213. package/docs/journeys.md +83 -0
  214. package/package.json +28 -8
  215. package/dist/bridges/context/agents-json.d.ts.map +0 -1
  216. package/dist/bridges/context/agents-json.js.map +0 -1
  217. package/dist/bridges/context/auth-clarity.d.ts.map +0 -1
  218. package/dist/bridges/context/auth-clarity.js.map +0 -1
  219. package/dist/bridges/context/auth-legibility.d.ts.map +0 -1
  220. package/dist/bridges/context/auth-legibility.js.map +0 -1
  221. package/dist/bridges/context/index.d.ts.map +0 -1
  222. package/dist/bridges/context/index.js.map +0 -1
  223. package/dist/bridges/context/rate-limits.d.ts.map +0 -1
  224. package/dist/bridges/context/rate-limits.js.map +0 -1
  225. package/dist/bridges/context/tos-contact.d.ts.map +0 -1
  226. package/dist/bridges/context/tos-contact.js.map +0 -1
  227. package/dist/bridges/context/versioning.d.ts.map +0 -1
  228. package/dist/bridges/context/versioning.js.map +0 -1
  229. package/dist/bridges/index.d.ts.map +0 -1
  230. package/dist/bridges/index.js.map +0 -1
  231. package/dist/bridges/reachability/crawler-policy.d.ts.map +0 -1
  232. package/dist/bridges/reachability/crawler-policy.js.map +0 -1
  233. package/dist/bridges/reachability/http-status.d.ts.map +0 -1
  234. package/dist/bridges/reachability/http-status.js.map +0 -1
  235. package/dist/bridges/reachability/https-check.d.ts.map +0 -1
  236. package/dist/bridges/reachability/https-check.js.map +0 -1
  237. package/dist/bridges/reachability/index.d.ts.map +0 -1
  238. package/dist/bridges/reachability/index.js.map +0 -1
  239. package/dist/bridges/reachability/meta-robots.d.ts.map +0 -1
  240. package/dist/bridges/reachability/meta-robots.js.map +0 -1
  241. package/dist/bridges/reachability/robots-parser.d.ts.map +0 -1
  242. package/dist/bridges/reachability/robots-parser.js.map +0 -1
  243. package/dist/bridges/reachability/robots-txt.d.ts.map +0 -1
  244. package/dist/bridges/reachability/robots-txt.js.map +0 -1
  245. package/dist/bridges/schema/descriptions.d.ts.map +0 -1
  246. package/dist/bridges/schema/descriptions.js.map +0 -1
  247. package/dist/bridges/schema/error-schemas.d.ts.map +0 -1
  248. package/dist/bridges/schema/error-schemas.js.map +0 -1
  249. package/dist/bridges/schema/index.d.ts.map +0 -1
  250. package/dist/bridges/schema/index.js.map +0 -1
  251. package/dist/bridges/schema/oas-types.d.ts.map +0 -1
  252. package/dist/bridges/schema/oas-types.js.map +0 -1
  253. package/dist/bridges/schema/operation-ids.d.ts.map +0 -1
  254. package/dist/bridges/schema/operation-ids.js.map +0 -1
  255. package/dist/bridges/schema/required-fields.d.ts.map +0 -1
  256. package/dist/bridges/schema/required-fields.js.map +0 -1
  257. package/dist/bridges/schema/schema-types.d.ts.map +0 -1
  258. package/dist/bridges/schema/schema-types.js.map +0 -1
  259. package/dist/bridges/separation/api-presence.d.ts.map +0 -1
  260. package/dist/bridges/separation/api-presence.js.map +0 -1
  261. package/dist/bridges/separation/developer-docs.d.ts.map +0 -1
  262. package/dist/bridges/separation/developer-docs.js.map +0 -1
  263. package/dist/bridges/separation/index.d.ts.map +0 -1
  264. package/dist/bridges/separation/index.js.map +0 -1
  265. package/dist/bridges/separation/sdk-references.d.ts.map +0 -1
  266. package/dist/bridges/separation/sdk-references.js.map +0 -1
  267. package/dist/bridges/separation/webhook-support.d.ts.map +0 -1
  268. package/dist/bridges/separation/webhook-support.js.map +0 -1
  269. package/dist/bridges/standards/a2a-agent-card.d.ts.map +0 -1
  270. package/dist/bridges/standards/a2a-agent-card.js.map +0 -1
  271. package/dist/bridges/standards/graphql.d.ts.map +0 -1
  272. package/dist/bridges/standards/graphql.js.map +0 -1
  273. package/dist/bridges/standards/index.d.ts.map +0 -1
  274. package/dist/bridges/standards/index.js.map +0 -1
  275. package/dist/bridges/standards/json-ld.d.ts.map +0 -1
  276. package/dist/bridges/standards/json-ld.js.map +0 -1
  277. package/dist/bridges/standards/llms-txt.d.ts.map +0 -1
  278. package/dist/bridges/standards/llms-txt.js.map +0 -1
  279. package/dist/bridges/standards/markdown-negotiation.d.ts.map +0 -1
  280. package/dist/bridges/standards/markdown-negotiation.js.map +0 -1
  281. package/dist/bridges/standards/mcp.d.ts.map +0 -1
  282. package/dist/bridges/standards/mcp.js.map +0 -1
  283. package/dist/bridges/standards/openapi.d.ts.map +0 -1
  284. package/dist/bridges/standards/openapi.js.map +0 -1
  285. package/dist/bridges/standards/schema-org.d.ts.map +0 -1
  286. package/dist/bridges/standards/schema-org.js.map +0 -1
  287. package/dist/bridges/standards/sitemap.d.ts.map +0 -1
  288. package/dist/bridges/standards/sitemap.js.map +0 -1
  289. package/dist/bridges/standards/well-known.d.ts.map +0 -1
  290. package/dist/bridges/standards/well-known.js.map +0 -1
  291. package/dist/cli/index.d.ts.map +0 -1
  292. package/dist/cli/index.js.map +0 -1
  293. package/dist/core/explanations.d.ts.map +0 -1
  294. package/dist/core/explanations.js.map +0 -1
  295. package/dist/core/index.d.ts.map +0 -1
  296. package/dist/core/index.js.map +0 -1
  297. package/dist/core/scan-options.d.ts.map +0 -1
  298. package/dist/core/scan-options.js.map +0 -1
  299. package/dist/core/scan.d.ts.map +0 -1
  300. package/dist/core/scan.js.map +0 -1
  301. package/dist/core/types.d.ts.map +0 -1
  302. package/dist/core/types.js.map +0 -1
  303. package/dist/core/version.d.ts.map +0 -1
  304. package/dist/core/version.js.map +0 -1
  305. package/dist/index.d.ts.map +0 -1
  306. package/dist/index.js.map +0 -1
  307. package/dist/render/colors.d.ts.map +0 -1
  308. package/dist/render/colors.js.map +0 -1
  309. package/dist/render/format-bridge.d.ts.map +0 -1
  310. package/dist/render/format-bridge.js.map +0 -1
  311. package/dist/render/format-scan.d.ts.map +0 -1
  312. package/dist/render/format-scan.js.map +0 -1
  313. package/dist/render/format-verbose.d.ts.map +0 -1
  314. package/dist/render/format-verbose.js.map +0 -1
  315. package/dist/render/index.d.ts.map +0 -1
  316. package/dist/render/index.js.map +0 -1
  317. package/dist/render/progress-bar.d.ts.map +0 -1
  318. package/dist/render/progress-bar.js.map +0 -1
  319. package/dist/render/symbols.d.ts.map +0 -1
  320. package/dist/render/symbols.js.map +0 -1
  321. package/dist/render/terminal-text.d.ts.map +0 -1
  322. package/dist/render/terminal-text.js.map +0 -1
  323. package/dist/utils/http-client.d.ts.map +0 -1
  324. package/dist/utils/http-client.js.map +0 -1
  325. package/dist/utils/index.d.ts.map +0 -1
  326. package/dist/utils/index.js.map +0 -1
  327. package/dist/utils/ssrf.d.ts.map +0 -1
  328. package/dist/utils/ssrf.js.map +0 -1
  329. package/dist/utils/url.d.ts.map +0 -1
  330. package/dist/utils/url.js.map +0 -1
@@ -1,58 +1,34 @@
1
- import { httpGet } from "../../utils/http-client.js";
2
- import { collectOperations } from "../schema/oas-types.js";
3
- const RATE_LIMIT_HEADERS = ["ratelimit-limit", "x-ratelimit-limit", "x-rate-limit-limit"];
1
+ import { observeProbe, readProbe } from "./probe.js";
2
+ const RATE_LIMIT_HEADERS = ["ratelimit", "ratelimit-policy", "ratelimit-limit", "x-ratelimit-limit", "x-rate-limit-limit",
3
+ "ratelimit-remaining", "ratelimit-reset", "x-ratelimit-remaining", "x-ratelimit-reset", "x-rate-limit-remaining", "x-rate-limit-reset"];
4
4
  const RETRY_AFTER = "retry-after";
5
- function findSimpleGetPath(spec) {
6
- if (!spec)
7
- return null;
8
- const ops = collectOperations(spec);
9
- for (const [path, method, op] of ops) {
10
- if (method !== "get")
11
- continue;
12
- if (path.includes("{"))
13
- continue;
14
- if (op.parameters == null || (Array.isArray(op.parameters) && op.parameters.every((p) => p && !p.required)))
15
- return path;
16
- }
17
- return null;
18
- }
19
5
  const id = "context_rate_limit_headers";
20
6
  const label = "Rate Limit Headers";
21
- /** Grade a response's headers for rate-limit signals (works on any status). */
22
- function gradeHeaders(headers, probeUrl) {
23
- for (const header of RATE_LIMIT_HEADERS) {
24
- const value = headers[header];
25
- if (value !== undefined) {
26
- return { id, label, status: "pass", detail: `Rate-limit header found: ${header}: ${value}`, data: { probeUrl, headerFound: header } };
27
- }
7
+ export async function checkRateLimitHeaders(ctx, cache) {
8
+ const probeResult = await readProbe(ctx, "rate", cache);
9
+ if (!probeResult) {
10
+ const check = { id, label, status: "error", detail: "OpenAPI inspection exceeded its work limit during probe selection",
11
+ data: { measurement: "unmeasured", measured: false } };
12
+ return { check, headers: {} };
28
13
  }
29
- const retryAfter = headers[RETRY_AFTER];
30
- if (retryAfter !== undefined) {
31
- return { id, label, status: "partial", detail: `Only retry-after header found (no rate ceiling): ${retryAfter}`, data: { probeUrl, headerFound: RETRY_AFTER } };
32
- }
33
- return { id, label, status: "fail", detail: "No rate-limit headers found in response", data: { probeUrl, headerFound: null } };
34
- }
35
- export async function checkRateLimitHeaders(ctx) {
36
- const spec = ctx.shared.openApiSpec;
37
- const simplePath = findSimpleGetPath(spec);
38
- const probeUrl = simplePath ? `${ctx.baseUrl}${simplePath}` : `${ctx.baseUrl}/api`;
39
- const probeTimeout = Math.min(ctx.options.timeout ?? 10000, 5000);
40
- const result = await httpGet(probeUrl, { timeout: probeTimeout });
41
- if (!result.ok) {
42
- if (result.error.kind === "request_budget_exhausted") {
43
- ctx.shared.contextProbeHeaders = {};
44
- return { id, label, status: "error", detail: "Rate-limit probe skipped: scan request budget exhausted", data: { probeUrl, headerFound: null } };
45
- }
46
- // Rate-limit headers commonly ride on error responses too (e.g. a 429 or
47
- // an authenticated 401) — grade them rather than discarding the response.
48
- if (result.response) {
49
- ctx.shared.contextProbeHeaders = result.response.headers;
50
- return gradeHeaders(result.response.headers, probeUrl);
14
+ const { selected, result } = probeResult;
15
+ const { data, response, attributable, html } = observeProbe(selected, result);
16
+ const { httpStatus } = data;
17
+ const eligible = result.ok || ((!result.ok && result.error.kind === "http_error") && (httpStatus === 401 || httpStatus === 403)) || httpStatus === 429;
18
+ let headers = {};
19
+ if (attributable && !html && eligible && response) {
20
+ headers = response.headers;
21
+ const limit = RATE_LIMIT_HEADERS.find(name => response.headers[name]?.trim());
22
+ const headerFound = limit ?? (response.headers[RETRY_AFTER]?.trim() ? RETRY_AFTER : null);
23
+ if (headerFound || (selected.probeSource === "operation" && httpStatus !== 401 && httpStatus !== 403)) {
24
+ return { headers, check: { id, label, status: limit ? "pass" : headerFound ? "partial" : "fail",
25
+ detail: headerFound ? `Rate-limit header observed: ${headerFound}` : "No rate-limit headers found in response",
26
+ data: { ...data, headerFound, measurement: "measured", measured: true },
27
+ } };
51
28
  }
52
- ctx.shared.contextProbeHeaders = {};
53
- return { id, label, status: "fail", detail: `Could not reach ${probeUrl} to check rate-limit headers`, data: { probeUrl, headerFound: null } };
54
29
  }
55
- ctx.shared.contextProbeHeaders = result.headers;
56
- return gradeHeaders(result.headers, probeUrl);
30
+ return { headers, check: { id, label, status: "error",
31
+ detail: `Rate-limit guidance could not be measured for the selected GET (${httpStatus === null ? "no HTTP response" : `HTTP ${httpStatus}`})`,
32
+ data: { ...data, headerFound: null, measurement: "unmeasured", measured: false, ...(!result.ok && { errorKind: result.error.kind }) },
33
+ } };
57
34
  }
58
- //# sourceMappingURL=rate-limits.js.map
@@ -1,7 +1,16 @@
1
+ import type { DefaultTreeAdapterTypes } from "parse5";
1
2
  import type { Check } from "../../core/types.js";
2
3
  import type { ParsedOpenApiSpec } from "../schema/oas-types.js";
3
4
  export declare function extractTosUrl(text: string): string | null;
4
- export declare function extractTosUrlFromHtml(html: string, baseUrl: string): string | null;
5
- export declare function checkTosUrl(spec: ParsedOpenApiSpec | undefined, llmsTxtBody: string | null, pageBody: string | null, baseUrl: string): Check;
6
- export declare function checkContactInfo(spec: ParsedOpenApiSpec | undefined, securityTxtBody: string | null): Check;
7
- //# sourceMappingURL=tos-contact.d.ts.map
5
+ export declare function extractTosUrlFromHtml(html: string | Iterable<DefaultTreeAdapterTypes.Element>, baseUrl: string): string | null;
6
+ export declare function checkTosUrl(spec: ParsedOpenApiSpec | undefined, llmsTxtBody: string | null, pageBody: string | null, baseUrl: string,
7
+ /** The link Standards read from the page. Given, the page is not parsed here. */
8
+ pageTermsUrl?: string | null): Check;
9
+ /**
10
+ * What the contact check reports of a security.txt: its first usable Contact URI. Standards reads this from the
11
+ * file, which can be megabytes, so that no later bridge holds the file for one line of it.
12
+ */
13
+ export declare function securityTxtContact(securityTxt: string): Pick<Check, "detail" | "data"> | null;
14
+ export declare function checkContactInfo(spec: ParsedOpenApiSpec | undefined,
15
+ /** The file's text, or what Standards read from it. */
16
+ securityTxt: string | Pick<Check, "detail" | "data"> | null): Check;
@@ -1,55 +1,119 @@
1
- /** Select a web URL with a legal path segment, preferring a direct terms link. */
2
- function selectTosUrl(candidates, baseUrl) {
3
- let legalUrl = null;
4
- for (const match of candidates) {
5
- const href = baseUrl ? match[1] : match[0].replace(/[.,;:!?)}\]]+$/, "");
6
- if (href.startsWith("#"))
7
- continue;
8
- const url = URL.parse(href, baseUrl);
9
- if (!url || (url.protocol !== "http:" && url.protocol !== "https:"))
10
- continue;
11
- if (/\/(?:terms|tos)(?=[-/]|$)/i.test(url.pathname))
12
- return url.href;
13
- if (!legalUrl && /\/legal(?=[-/]|$)/i.test(url.pathname))
14
- legalUrl = url.href;
15
- }
16
- return legalUrl;
1
+ import { htmlElements } from "../../utils/html.js";
2
+ import { documentBase, parseReference } from "../../utils/url.js";
3
+ import { securityContact } from "../standards/well-known.js";
4
+ const TERMS_PATH = /\/(?:terms|tos)(?=[-/.]|$)/i;
5
+ function webUrl(href, base) {
6
+ if (!href.trim() || href.startsWith("#"))
7
+ return;
8
+ const url = parseReference(href, base);
9
+ if (url?.protocol === "https:" || url?.protocol === "http:")
10
+ return url;
17
11
  }
18
12
  export function extractTosUrl(text) {
19
- return selectTosUrl(text.matchAll(/https?:\/\/[^\s<>"'()\]]+/gi));
13
+ for (const [raw] of text.matchAll(/https?:\/\/[^\s<>"'()\]]+/gi)) {
14
+ // Starting only at the first character of a run keeps a long inner run of punctuation linear.
15
+ const url = webUrl(raw.replace(/(?<![.,;:!?)}\]])[.,;:!?)}\]]+$/, ""));
16
+ if (url && TERMS_PATH.test(url.pathname))
17
+ return url.href;
18
+ }
19
+ return null;
20
20
  }
21
21
  export function extractTosUrlFromHtml(html, baseUrl) {
22
- const hrefPattern = /<a(?=\s)[^<>]*?\shref\s*=\s*["']([^"']+)["']/gi;
23
- return selectTosUrl(html.matchAll(hrefPattern), baseUrl);
22
+ // A link left open is rebuilt in every later paragraph: judge each reference once, not once per copy. Only whether
23
+ // it resolves is kept. Under a long base every resolved URL is as long, and a page of them outgrows the bridge's heap.
24
+ const resolves = new Map();
25
+ // The first <base> applies to the whole document, including anchors that precede it.
26
+ let base;
27
+ const anchors = [];
28
+ for (const element of typeof html === "string" ? htmlElements(html) : html) {
29
+ const href = element.attrs.find(a => a.name === "href")?.value;
30
+ if (element.tagName === "base" && href !== undefined && base === undefined)
31
+ base = documentBase(href, baseUrl);
32
+ if (element.tagName === "a")
33
+ anchors.push(element);
34
+ }
35
+ // Under a base the scan cannot use (null), only an absolute link resolves.
36
+ const resolve = (href) => webUrl(href, base === null ? undefined : base ?? baseUrl);
37
+ for (const element of anchors) {
38
+ const href = element.attrs.find(a => a.name === "href")?.value ?? "";
39
+ if (!resolves.has(href)) {
40
+ const url = resolve(href);
41
+ if (url && TERMS_PATH.test(url.pathname))
42
+ return url.href;
43
+ resolves.set(href, url !== undefined);
44
+ }
45
+ if (!resolves.get(href))
46
+ continue;
47
+ const stack = element.childNodes.slice().reverse();
48
+ const text = [];
49
+ while (stack.length) {
50
+ const node = stack.pop();
51
+ if ("value" in node)
52
+ text.push(node.value);
53
+ else if ("childNodes" in node) {
54
+ for (let i = node.childNodes.length - 1; i >= 0; i--)
55
+ stack.push(node.childNodes[i]);
56
+ }
57
+ }
58
+ if (!/^terms(?: of (?:service|use)| (?:&|and) conditions)?$/i.test(text.join("").trim()))
59
+ continue;
60
+ const url = resolve(href);
61
+ if (url)
62
+ return url.href;
63
+ }
64
+ return null;
24
65
  }
25
- export function checkTosUrl(spec, llmsTxtBody, pageBody, baseUrl) {
66
+ export function checkTosUrl(spec, llmsTxtBody, pageBody, baseUrl,
67
+ /** The link Standards read from the page. Given, the page is not parsed here. */
68
+ pageTermsUrl) {
26
69
  const id = "context_tos_url";
27
70
  const label = "Terms of Service URL";
28
71
  const specTos = spec?.info?.termsOfService;
29
- const url = typeof specTos === "string" ? URL.parse(specTos) : null;
30
- if (url?.protocol === "https:" || url?.protocol === "http:") {
31
- return { id, label, status: "pass", detail: `Terms of Service URL found in spec: ${specTos}`, data: { source: "spec", url: specTos } };
72
+ const url = typeof specTos === "string" ? parseReference(specTos) : null;
73
+ function found(link, source) {
74
+ const status = source === "spec" ? "pass" : "partial";
75
+ // A clipped URL could point to a different resource. Keep the finding and omit the value.
76
+ if (link.length > 2048)
77
+ return { id, label, status, detail: `Terms of Service URL found in ${source} (URL exceeds display limit)`,
78
+ data: { source, url: null, urlOmitted: true } };
79
+ return { id, label, status, detail: `Terms of Service URL found in ${source}: ${link}`, data: { source, url: link } };
32
80
  }
81
+ if (typeof specTos === "string" && (url?.protocol === "https:" || url?.protocol === "http:"))
82
+ return found(specTos, "spec");
33
83
  if (llmsTxtBody) {
34
- const url = extractTosUrl(llmsTxtBody);
35
- if (url)
36
- return { id, label, status: "partial", detail: `Terms of Service URL found in llms.txt: ${url}`, data: { source: "llms.txt", url } };
37
- }
38
- if (pageBody) {
39
- const url = extractTosUrlFromHtml(pageBody, baseUrl);
40
- if (url)
41
- return { id, label, status: "partial", detail: `Terms of Service URL found in page: ${url}`, data: { source: "page", url } };
84
+ const link = extractTosUrl(llmsTxtBody);
85
+ if (link)
86
+ return found(link, "llms.txt");
42
87
  }
88
+ const pageLink = pageTermsUrl !== undefined ? pageTermsUrl : pageBody ? extractTosUrlFromHtml(pageBody, baseUrl) : null;
89
+ if (pageLink)
90
+ return found(pageLink, "page");
43
91
  return { id, label, status: "fail", detail: "No Terms of Service URL found", data: { source: null, url: null } };
44
92
  }
93
+ // As with the Terms URL, a clipped contact could name a different recipient. Keep the finding and omit the value.
94
+ const omit = (value) => value !== null && value.length > 2048;
45
95
  /**
46
- * Extract Contact email from security.txt body (RFC 9116 Contact: field).
96
+ * What the contact check reports of a security.txt: its first usable Contact URI. Standards reads this from the
97
+ * file, which can be megabytes, so that no later bridge holds the file for one line of it.
47
98
  */
48
- function extractSecurityTxtContact(securityTxtBody) {
49
- const match = securityTxtBody.match(/^Contact:\s*(.+)/mi);
50
- return match ? match[1].trim() : null;
99
+ export function securityTxtContact(securityTxt) {
100
+ const contactValue = securityContact(securityTxt);
101
+ if (!contactValue)
102
+ return null;
103
+ const mailto = contactValue.protocol === "mailto:";
104
+ const stored = mailto ? contactValue.pathname : contactValue.href;
105
+ // An address is cut from its URI, and V8 keeps the whole of a string for a piece of it: megabytes, under a long
106
+ // query. The address kept is a copy.
107
+ const data = omit(stored) ? { email: null, url: null, ...(mailto ? { emailOmitted: true } : { urlOmitted: true }) }
108
+ : mailto ? { email: (" " + stored).slice(1), url: null } : { email: null, url: stored };
109
+ // The detail prints the whole URI, and a mailto query or fragment is no part of the stored address.
110
+ const detail = omit(contactValue.href) ? "Contact info found in security.txt (URI exceeds display limit)"
111
+ : `Contact info found in security.txt: ${contactValue}`;
112
+ return { detail, data };
51
113
  }
52
- export function checkContactInfo(spec, securityTxtBody) {
114
+ export function checkContactInfo(spec,
115
+ /** The file's text, or what Standards read from it. */
116
+ securityTxt) {
53
117
  const id = "context_contact_info";
54
118
  const label = "Contact Info";
55
119
  const contact = spec?.info?.contact;
@@ -58,17 +122,15 @@ export function checkContactInfo(spec, securityTxtBody) {
58
122
  if (email || url) {
59
123
  const parts = [];
60
124
  if (email)
61
- parts.push(`email: ${email}`);
125
+ parts.push(omit(email) ? "email (exceeds display limit)" : `email: ${email}`);
62
126
  if (url)
63
- parts.push(`url: ${url}`);
64
- return { id, label, status: "pass", detail: `Contact info found in spec: ${parts.join(", ")}`, data: { email, url } };
65
- }
66
- if (securityTxtBody) {
67
- const contactValue = extractSecurityTxtContact(securityTxtBody);
68
- if (contactValue) {
69
- return { id, label, status: "partial", detail: `Contact info found in security.txt: ${contactValue}`, data: { email: null, url: contactValue } };
70
- }
127
+ parts.push(omit(url) ? "url (exceeds display limit)" : `url: ${url}`);
128
+ const data = { email: omit(email) ? null : email, ...(omit(email) && { emailOmitted: true }),
129
+ url: omit(url) ? null : url, ...(omit(url) && { urlOmitted: true }) };
130
+ return { id, label, status: "pass", detail: `Contact info found in spec: ${parts.join(", ")}`, data };
71
131
  }
132
+ const published = typeof securityTxt === "string" ? securityTxtContact(securityTxt) : securityTxt;
133
+ if (published)
134
+ return { id, label, status: "partial", ...published };
72
135
  return { id, label, status: "fail", detail: "No contact info found", data: { email: null, url: null } };
73
136
  }
74
- //# sourceMappingURL=tos-contact.js.map
@@ -1,4 +1,3 @@
1
1
  import type { Check } from "../../core/types.js";
2
- import type { ParsedOpenApiSpec } from "../schema/oas-types.js";
2
+ import { type ParsedOpenApiSpec } from "../schema/oas-types.js";
3
3
  export declare function checkVersioningSignal(spec: ParsedOpenApiSpec | undefined, contextProbeHeaders: Record<string, string>): Check;
4
- //# sourceMappingURL=versioning.d.ts.map
@@ -1,22 +1,57 @@
1
+ import { parseReference } from "../../utils/url.js";
2
+ import { openApiServerUrl } from "../schema/oas-types.js";
1
3
  const VERSION_HEADERS = ["x-api-version", "api-version", "x-version"];
2
4
  export function checkVersioningSignal(spec, contextProbeHeaders) {
3
5
  const id = "context_versioning_signal";
4
6
  const label = "Versioning Signal";
5
- if (spec?.paths) {
6
- for (const path of Object.keys(spec.paths)) {
7
- if (/^\/v\d+\//.test(path))
8
- return { id, label, status: "pass", detail: `Path-based versioning detected: ${path}`, data: { signal: "path", value: path } };
7
+ const paths = Object.keys(spec?.paths ?? {});
8
+ if (spec?.swagger === "2.0" && typeof spec.basePath === "string")
9
+ paths.unshift(spec.basePath);
10
+ if (Array.isArray(spec?.servers)) {
11
+ for (const server of spec.servers) {
12
+ const raw = openApiServerUrl(server);
13
+ if (!raw)
14
+ continue;
15
+ const url = parseReference(raw, "https://example.invalid/");
16
+ if (url)
17
+ paths.push(url.pathname);
9
18
  }
10
19
  }
20
+ // A clipped path or version is a different value. Keep the finding and omit an overlong value.
21
+ const omitted = (signal, status, source) => ({ id, label, status, detail: `${source} (value exceeds display limit)`, data: { signal, value: null, valueOmitted: true } });
22
+ let longPath = false;
23
+ for (const path of paths) {
24
+ if (path.startsWith("/") && !path.startsWith("//") && /\/v\d+(?:[.-]\d+)*(?:\/|$)/i.test(path)) {
25
+ // A shorter versioned path is reportable evidence for the same signal.
26
+ if (path.length > 2048) {
27
+ longPath = true;
28
+ continue;
29
+ }
30
+ return { id, label, status: "pass", detail: `Path-based versioning detected: ${path}`, data: { signal: "path", value: path } };
31
+ }
32
+ }
33
+ if (longPath)
34
+ return omitted("path", "pass", "Path-based versioning detected");
35
+ let longHeader = false;
11
36
  for (const header of VERSION_HEADERS) {
12
37
  const value = contextProbeHeaders[header];
13
- if (value !== undefined)
14
- return { id, label, status: "pass", detail: `Version header found: ${header}: ${value}`, data: { signal: "header", value: `${header}: ${value}` } };
38
+ if (!value?.trim())
39
+ continue;
40
+ const stored = `${header}: ${value}`;
41
+ // As for paths: a header that fits is reportable evidence for the same signal.
42
+ if (stored.length > 2048) {
43
+ longHeader = true;
44
+ continue;
45
+ }
46
+ return { id, label, status: "pass", detail: `Version header found: ${stored}`, data: { signal: "header", value: stored } };
15
47
  }
48
+ if (longHeader)
49
+ return omitted("header", "pass", "Version header found");
16
50
  const specVersion = spec?.info?.version;
17
51
  if (typeof specVersion === "string" && specVersion.trim() !== "") {
52
+ if (specVersion.length > 2048)
53
+ return omitted("spec_info", "partial", "Spec info.version found");
18
54
  return { id, label, status: "partial", detail: `Spec info.version found: ${specVersion}`, data: { signal: "spec_info", value: specVersion } };
19
55
  }
20
56
  return { id, label, status: "fail", detail: "No versioning signal found", data: { signal: null, value: null } };
21
57
  }
22
- //# sourceMappingURL=versioning.js.map
@@ -3,4 +3,3 @@ export { runStandardsBridge } from "./standards/index.js";
3
3
  export { runSeparationBridge } from "./separation/index.js";
4
4
  export { runSchemaBridge } from "./schema/index.js";
5
5
  export { runContextBridge } from "./context/index.js";
6
- //# sourceMappingURL=index.d.ts.map
@@ -3,4 +3,3 @@ export { runStandardsBridge } from "./standards/index.js";
3
3
  export { runSeparationBridge } from "./separation/index.js";
4
4
  export { runSchemaBridge } from "./schema/index.js";
5
5
  export { runContextBridge } from "./context/index.js";
6
- //# sourceMappingURL=index.js.map
@@ -13,13 +13,13 @@ export declare const AI_CRAWLERS: readonly [{
13
13
  readonly name: "CCBot";
14
14
  readonly userAgent: "ccbot";
15
15
  }, {
16
- readonly id: "googlebot";
17
- readonly name: "Googlebot";
18
- readonly userAgent: "googlebot";
16
+ readonly id: "google_extended";
17
+ readonly name: "Google-Extended";
18
+ readonly userAgent: "google-extended";
19
19
  }, {
20
- readonly id: "bingbot";
21
- readonly name: "Bingbot";
22
- readonly userAgent: "bingbot";
20
+ readonly id: "applebot_extended";
21
+ readonly name: "Applebot-Extended";
22
+ readonly userAgent: "applebot-extended";
23
23
  }, {
24
24
  readonly id: "perplexitybot";
25
25
  readonly name: "PerplexityBot";
@@ -28,9 +28,29 @@ export declare const AI_CRAWLERS: readonly [{
28
28
  /**
29
29
  * Evaluate per-AI-crawler policy from parsed robots.txt data.
30
30
  *
31
- * @param parsed - Parsed robots.txt result, or null if robots.txt was not found (404)
32
- * @param unavailable - robots.txt could not be evaluated
31
+ * @param parsed - Parsed robots.txt result, or null if robots.txt was unavailable or absent
32
+ * @param coverage - whether a complete policy file was observed
33
33
  * @returns Array of 6 Check objects, one per AI crawler
34
34
  */
35
- export declare function evaluateCrawlerPolicies(parsed: RobotsTxtResult | null, unavailable?: boolean): Check[];
36
- //# sourceMappingURL=crawler-policy.d.ts.map
35
+ export declare function evaluateCrawlerPolicies(parsed: RobotsTxtResult | null, coverage?: DirectiveInventory["coverage"]): Check[];
36
+ /** Supplementary declarations, independent of the six scored crawler policies. */
37
+ declare const PURPOSE_TOKENS: readonly [readonly ["ChatGPT-User", "user-directed"], readonly ["Claude-User", "user-directed"], readonly ["OAI-SearchBot", "search"], readonly ["Claude-SearchBot", "search"], readonly ["GPTBot", "training"], readonly ["ClaudeBot", "training"]];
38
+ export type DirectiveInventory = {
39
+ coverage: "absent" | "unavailable" | "incomplete";
40
+ } | {
41
+ coverage: "parsed";
42
+ agents: ReturnType<typeof agentDeclarations>[];
43
+ };
44
+ declare function agentDeclarations(parsed: RobotsTxtResult, [token, purpose]: typeof PURPOSE_TOKENS[number]): {
45
+ token: "GPTBot" | "ClaudeBot" | "ChatGPT-User" | "Claude-User" | "OAI-SearchBot" | "Claude-SearchBot";
46
+ purpose: "search" | "user-directed" | "training";
47
+ matchedToken: string | null;
48
+ ruleCount: number;
49
+ rules: {
50
+ clipped?: boolean | undefined;
51
+ type: "allow" | "disallow";
52
+ path: string;
53
+ }[];
54
+ };
55
+ export declare function directiveInventory(parsed: RobotsTxtResult): DirectiveInventory;
56
+ export {};
@@ -1,27 +1,30 @@
1
1
  // AI crawler policy evaluation from parsed robots.txt data
2
- import { matchesPath } from "./robots-parser.js";
2
+ import { isAllowed } from "./robots-parser.js";
3
+ // Product tokens checked December 2026. Google-Extended and Applebot-Extended govern use of crawled data.
4
+ // https://developers.google.com/crawling/docs/google-extended
5
+ // https://support.apple.com/en-ie/119829
3
6
  export const AI_CRAWLERS = [
4
7
  { id: "gptbot", name: "GPTBot", userAgent: "gptbot" },
5
8
  { id: "claudebot", name: "ClaudeBot", userAgent: "claudebot" },
6
9
  { id: "ccbot", name: "CCBot", userAgent: "ccbot" },
7
- { id: "googlebot", name: "Googlebot", userAgent: "googlebot" },
8
- { id: "bingbot", name: "Bingbot", userAgent: "bingbot" },
10
+ { id: "google_extended", name: "Google-Extended", userAgent: "google-extended" },
11
+ { id: "applebot_extended", name: "Applebot-Extended", userAgent: "applebot-extended" },
9
12
  { id: "perplexitybot", name: "PerplexityBot", userAgent: "perplexitybot" },
10
13
  ];
11
14
  /**
12
15
  * Evaluate per-AI-crawler policy from parsed robots.txt data.
13
16
  *
14
- * @param parsed - Parsed robots.txt result, or null if robots.txt was not found (404)
15
- * @param unavailable - robots.txt could not be evaluated
17
+ * @param parsed - Parsed robots.txt result, or null if robots.txt was unavailable or absent
18
+ * @param coverage - whether a complete policy file was observed
16
19
  * @returns Array of 6 Check objects, one per AI crawler
17
20
  */
18
- export function evaluateCrawlerPolicies(parsed, unavailable = false) {
21
+ export function evaluateCrawlerPolicies(parsed, coverage = parsed ? "parsed" : "absent") {
19
22
  return AI_CRAWLERS.map((crawler) => {
20
23
  const id = `crawler_policy_${crawler.id}`;
21
24
  const label = `${crawler.name} Policy`;
22
- if (unavailable)
23
- return { id, label, status: "error", detail: "Could not evaluate crawler policy without robots.txt" };
24
- // No robots.txt (404 case): skip
25
+ if (coverage === "unavailable" || coverage === "incomplete")
26
+ return { id, label, status: "error", detail: "Could not evaluate crawler policy without a complete robots.txt" };
27
+ // No published file: exclude this policy from scoring.
25
28
  if (parsed === null) {
26
29
  return {
27
30
  id,
@@ -32,7 +35,7 @@ export function evaluateCrawlerPolicies(parsed, unavailable = false) {
32
35
  };
33
36
  }
34
37
  // Find group matching this crawler
35
- const rules = findMatchingRules(parsed, crawler.userAgent);
38
+ const rules = matchingGroups(parsed, crawler.userAgent).flatMap(group => group.rules).filter(rule => rule.path !== "");
36
39
  if (!rules.length) {
37
40
  // No matching group at all -> allowed
38
41
  return {
@@ -51,56 +54,38 @@ export function evaluateCrawlerPolicies(parsed, unavailable = false) {
51
54
  * Find the most specific matching group for a crawler.
52
55
  * Prefer crawler-specific group over * group (RFC 9309).
53
56
  */
54
- function findMatchingRules(parsed, userAgent) {
57
+ function matchingGroups(parsed, userAgent) {
55
58
  const specific = parsed.groups.filter((group) => group.userAgents.includes(userAgent));
56
- const matching = specific.length ? specific : parsed.groups.filter((group) => group.userAgents.includes("*"));
57
- return matching.flatMap((group) => group.rules).filter((rule) => rule.path !== "");
59
+ return specific.length ? specific : parsed.groups.filter(group => group.userAgents.includes("*"));
58
60
  }
59
61
  /**
60
62
  * Evaluate a crawler's policy from its matching group's rules.
61
63
  */
62
64
  function evaluateGroupPolicy(rules, id, label) {
63
- const disallowRules = rules.filter((r) => r.type === "disallow");
64
- const allowRules = rules.filter((r) => r.type === "allow");
65
- // No rules or only empty-path Disallow -> pass
66
- if (disallowRules.length === 0) {
67
- return {
68
- id,
69
- label,
70
- status: "pass",
71
- detail: "Allowed",
72
- data: { policy: "pass" },
73
- };
74
- }
75
- // Has Disallow: / (root block)?
76
- const hasRootBlock = disallowRules.some((r) => matchesPath(r.path, "/"));
77
- if (hasRootBlock && allowRules.length > 0) {
78
- // Disallow: / with Allow rules -> partial
79
- return {
80
- id,
81
- label,
82
- status: "partial",
83
- detail: "Partially restricted",
84
- data: { policy: "partial" },
85
- };
86
- }
87
- if (hasRootBlock) {
88
- // Disallow: / with no Allow -> blocked
89
- return {
90
- id,
91
- label,
92
- status: "fail",
93
- detail: "Blocked",
94
- data: { policy: "fail" },
95
- };
96
- }
97
- // Non-root Disallow rules -> partial
98
- return {
99
- id,
100
- label,
101
- status: "partial",
102
- detail: "Partially restricted",
103
- data: { policy: "partial" },
104
- };
65
+ // Equivalent rules resolve to Allow, independent of group and source order.
66
+ const allowedPatterns = new Set(rules.filter(r => r.type === "allow").map(r => r.path));
67
+ const restrictions = rules.filter(r => r.type === "disallow" && !allowedPatterns.has(r.path));
68
+ const blanketBlock = restrictions.some(r => /^\/\**$/.test(r.path) || r.path === "*");
69
+ const rootAllowed = isAllowed(rules, "/");
70
+ const status = !restrictions.length ? "pass" :
71
+ blanketBlock && !rootAllowed && !allowedPatterns.size ? "fail" : "partial";
72
+ const detail = { pass: "Allowed", partial: "Partially restricted", fail: "Blocked" }[status];
73
+ return { id, label, status, detail, data: { policy: status, rootAllowed } };
74
+ }
75
+ /** Supplementary declarations, independent of the six scored crawler policies. */
76
+ const PURPOSE_TOKENS = [
77
+ ["ChatGPT-User", "user-directed"], ["Claude-User", "user-directed"],
78
+ ["OAI-SearchBot", "search"], ["Claude-SearchBot", "search"],
79
+ ["GPTBot", "training"], ["ClaudeBot", "training"],
80
+ ];
81
+ function agentDeclarations(parsed, [token, purpose]) {
82
+ const key = token.toLowerCase();
83
+ const groups = matchingGroups(parsed, key);
84
+ const matchedToken = !groups.length ? null : groups[0].userAgents.includes(key) ? token : "*";
85
+ const declarations = groups.flatMap(group => group.rules).filter(rule => rule.path !== "");
86
+ const rules = declarations.slice(0, 8).map(({ type, path }) => ({ type, path: path.slice(0, 256), ...(path.length > 256 && { clipped: true }) }));
87
+ return { token, purpose, matchedToken, ruleCount: declarations.length, rules };
88
+ }
89
+ export function directiveInventory(parsed) {
90
+ return { coverage: "parsed", agents: PURPOSE_TOKENS.map(token => agentDeclarations(parsed, token)) };
105
91
  }
106
- //# sourceMappingURL=crawler-policy.js.map
@@ -1,7 +1,8 @@
1
- import type { Check, HttpResponse } from "../../core/types.js";
1
+ import type { Check, HttpErrorKind, HttpResponse } from "../../core/types.js";
2
+ /** Only the requested URL can establish its own unreachability. A redirect proves that it answered. */
3
+ export declare function transportFailureAt(response: HttpResponse, requestedUrl: string): HttpErrorKind | undefined;
2
4
  /**
3
5
  * Check HTTP status from a pre-fetched page response.
4
6
  * Does NOT make any HTTP calls -- takes the already-fetched response.
5
7
  */
6
8
  export declare function checkHttpStatus(pageResponse: HttpResponse): Check;
7
- //# sourceMappingURL=http-status.d.ts.map