@rebilder/agent-readability 0.1.0 → 0.2.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.
@@ -85,13 +85,13 @@ function deepFreeze(value) {
85
85
  return Object.freeze(value);
86
86
  }
87
87
  var WEIGHTS = {
88
- // D1 Retrievability — 20
89
- "retrievability.reachable": 8,
90
- "retrievability.robots-policy": 6,
91
- "retrievability.render-independence": 6,
92
- // D2 Machine representation — 20
93
- "machine-representation.negotiated-response": 10,
94
- "machine-representation.declared-alternates": 4,
88
+ // D1 Retrievability — 28
89
+ "retrievability.reachable": 11,
90
+ "retrievability.robots-policy": 10,
91
+ "retrievability.render-independence": 7,
92
+ // D2 Machine representation — 18
93
+ "machine-representation.negotiated-response": 9,
94
+ "machine-representation.declared-alternates": 3,
95
95
  "machine-representation.vary-accept": 3,
96
96
  "machine-representation.substance-parity": 3,
97
97
  // D3 Fact coverage — 20
@@ -100,16 +100,20 @@ var WEIGHTS = {
100
100
  // D4 Fact position — 10
101
101
  "fact-position.first-core-fact-offset": 5,
102
102
  "fact-position.front-window": 5,
103
- // D5 Structured data — 15
104
- "structured-data.present": 5,
105
- "structured-data.required-properties": 7,
106
- "structured-data.text-agreement": 3,
107
- // D6 Contract & discovery — 15
103
+ // D5 Structured data — 6
104
+ "structured-data.present": 2,
105
+ "structured-data.required-properties": 3,
106
+ "structured-data.text-agreement": 1,
107
+ // D6 Contract & discovery — 10
108
108
  "contract-discovery.canonical": 4,
109
- "contract-discovery.cache-validators": 3,
110
- "contract-discovery.llms-txt": 2,
111
- "contract-discovery.sitemap": 2,
112
- "contract-discovery.machine-endpoint": 4
109
+ "contract-discovery.cache-validators": 2,
110
+ "contract-discovery.llms-txt": 1,
111
+ "contract-discovery.sitemap": 1,
112
+ "contract-discovery.machine-endpoint": 2,
113
+ // D7 Evidence density — 8
114
+ "evidence-density.quantities": 4,
115
+ "evidence-density.definitions": 2,
116
+ "evidence-density.comparisons": 2
113
117
  };
114
118
  var THRESHOLDS = {
115
119
  /**
@@ -141,6 +145,31 @@ var THRESHOLDS = {
141
145
  * `ratio = 100 × bytes / byteReference[pageKind]`; above the last threshold, 0.
142
146
  */
143
147
  "fact-coverage.context-cost": [100, 6, 200, 5, 500, 3, 1500, 1],
148
+ /**
149
+ * D7.1 quantities, 4 pts. AT-LEAST over the count of DISTINCT quantity tokens
150
+ * in the agent's counted text: a currency amount, a percentage, a number
151
+ * carrying a unit, or an ISO date. Distinct, because a price repeated in a
152
+ * header, a buy box and a footer is one fact stated three times, and counting
153
+ * it three times would reward the repetition this score exists to discourage.
154
+ * Saturates at 12 so a specification table cannot outscore a page that simply
155
+ * states its facts.
156
+ */
157
+ "evidence-density.quantities": [12, 4, 6, 3, 3, 2, 1, 1],
158
+ /**
159
+ * D7.2 definitions, 2 pts. AT-LEAST over the count of `term: value` pairs the
160
+ * agent can read as a labelled fact, counting markdown bold-label lines,
161
+ * list items with a leading label, and HTML definition lists.
162
+ */
163
+ "evidence-density.definitions": [6, 2, 2, 1],
164
+ /**
165
+ * D7.3 comparisons, 2 pts. AT-LEAST over the number of comparable ROWS: a
166
+ * table with at least two data columns contributes its data-row count, minus
167
+ * the header. One row is not a comparison, so the band starts at two; three
168
+ * options laid side by side is a full comparison and pays out. Calibrated
169
+ * against fixture `060`, where a three-row size table is exactly the shape
170
+ * this check exists to reward, and `063`, where one row is not.
171
+ */
172
+ "evidence-density.comparisons": [3, 2, 2, 1],
144
173
  /** D4.1 first-core-fact byte offset, 5 pts. AT-MOST over the offset in bytes; else 0. */
145
174
  "fact-position.first-core-fact-offset": [512, 5, 2048, 4, 8192, 2, 32768, 1],
146
175
  /**
@@ -281,7 +310,7 @@ var BANDS = [
281
310
  }
282
311
  ];
283
312
  var DEFAULT_RULESET = deepFreeze({
284
- version: "0.1.0",
313
+ version: "0.2.0",
285
314
  weights: WEIGHTS,
286
315
  thresholds: THRESHOLDS,
287
316
  audienceTokens: AUDIENCE_TOKENS,
@@ -385,6 +414,33 @@ function pathMatches(pattern, path) {
385
414
  return true;
386
415
  }
387
416
 
417
+ // src/robots-policy.ts
418
+ var ARS_ROBOTS_TOKEN = "rebilder-ars";
419
+ function robotsDisallowsScanner(robotsBody, path) {
420
+ const robots = parseRobots(robotsBody);
421
+ for (const group of robots.groups) {
422
+ if (!group.agents.some((agent) => agent.toLowerCase() === ARS_ROBOTS_TOKEN)) continue;
423
+ let best = null;
424
+ for (const value of group.allow) {
425
+ if (!pathMatches(value, path)) continue;
426
+ if (best === null || value.length > best.value.length) best = { field: "allow", value };
427
+ }
428
+ for (const value of group.disallow) {
429
+ if (!pathMatches(value, path)) continue;
430
+ if (best === null || value.length > best.value.length) best = { field: "disallow", value };
431
+ }
432
+ if (best !== null && best.field === "disallow") {
433
+ return `User-agent: ${ARS_ROBOTS_TOKEN} / Disallow: ${best.value}`;
434
+ }
435
+ }
436
+ return null;
437
+ }
438
+
439
+ // src/probe/headers.ts
440
+ var AGENT_ACCEPT = "text/markdown;q=1.0, text/html;q=0.8, text/plain;q=0.5, */*;q=0.1";
441
+ var BROWSER_ACCEPT = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
442
+ var ASSET_ACCEPT = "text/plain,*/*;q=0.5";
443
+
388
444
  // src/score.ts
389
445
  function idiv(numerator, denominator) {
390
446
  if (denominator === 0) return 0;
@@ -396,44 +452,50 @@ function deepFreeze2(value) {
396
452
  return Object.freeze(value);
397
453
  }
398
454
  deepFreeze2({
399
- /** D1.1, 8 = 4 + 2 + 2. */
400
- reachable: { status2xx: 4, withinRedirectLimit: 2, noAcceptConditionalRedirect: 2 },
401
- /** D1.2, 6 = 3 + 1 + 1 + 1. A disallowed assistant audience scores 0 for all four (§3.7). */
402
- robotsPolicy: { assistantAllowed: 3, parsesClean: 1, noOrphanRules: 1, sitemapDeclared: 1 },
455
+ /** D1.1, 11 = 5 + 3 + 3. */
456
+ reachable: { status2xx: 5, withinRedirectLimit: 3, noAcceptConditionalRedirect: 3 },
457
+ /** D1.2, 10 = 6 + 2 + 1 + 1. A disallowed assistant audience scores 0 for all four (§3.7). */
458
+ robotsPolicy: { assistantAllowed: 6, parsesClean: 2, noOrphanRules: 1, sitemapDeclared: 1 },
403
459
  /**
404
- * D1.3, 6. AT-LEAST band over `100 × coreFactsInHtml / coreProfileSize`, plus
460
+ * D1.3, 7. AT-LEAST band over `100 × coreFactsInHtml / coreProfileSize`, plus
405
461
  * the `<noscript>` floor: a page whose facts are all client-rendered but which
406
462
  * ships a non-empty `<noscript>` has told a JS-less caller something, and §3.8
407
463
  * says that earns partial credit.
408
464
  */
409
465
  renderIndependence: {
410
- band: [100, 6, 75, 5, 50, 3, 25, 1],
466
+ band: [100, 7, 75, 5, 50, 3, 25, 1],
411
467
  noscriptFloor: 1
412
468
  },
413
- /** D2.1, 10. All-or-nothing: a machine media type AND a body that is not HTML. */
414
- negotiatedResponse: { full: 10 },
415
- /** D2.2, 4. All-or-nothing. */
416
- declaredAlternates: { full: 4 },
469
+ /** D2.1, 9. All-or-nothing: a machine media type AND a body that is not HTML. */
470
+ negotiatedResponse: { full: 9 },
471
+ /** D2.2, 3. All-or-nothing. */
472
+ declaredAlternates: { full: 3 },
417
473
  /** D2.3, 3. All-or-nothing, and 0 unless D2.1 > 0. */
418
474
  varyAccept: { full: 3 },
419
475
  /** D2.4, 3. All-or-nothing, and 0 unless D2.1 > 0 and a browser capture exists. */
420
476
  substanceParity: { full: 3 },
421
- /** D5.1, 5. Structured data present AND parsing; a partly-broken graph scores 3. */
422
- structuredDataPresent: { clean: 5, partial: 3 },
423
- /** D5.2, 7 = 2 (a recognised type) + 5 (required-property completeness, scaled). */
424
- requiredProperties: { recognisedType: 2, completeness: 5 },
425
- /** D5.3, 3. All-or-nothing. */
426
- textAgreement: { full: 3 },
477
+ /** D5.1, 2. Structured data present AND parsing; a partly-broken graph scores 1. */
478
+ structuredDataPresent: { clean: 2, partial: 1 },
479
+ /** D5.2, 3 = 1 (a recognised type) + 2 (required-property completeness, scaled). */
480
+ requiredProperties: { recognisedType: 1, completeness: 2 },
481
+ /** D5.3, 1. All-or-nothing. */
482
+ textAgreement: { full: 1 },
427
483
  /** D6.1, 4 = 2 + 1 + 1. */
428
484
  canonical: { present: 2, absolute: 1, consistentAcrossProbes: 1 },
429
- /** D6.2, 3 = 2 + 1. */
430
- cacheValidators: { saneCacheControl: 2, validator: 1 },
431
- /** D6.3, 2. `present` alone for a file that exists; `specShaped` for one that parses as llms.txt. */
432
- llmsTxt: { present: 1, specShaped: 2 },
433
- /** D6.4, 2. All-or-nothing. */
434
- sitemap: { full: 2 },
435
- /** D6.5, 4. All-or-nothing over any ONE declared machine endpoint. */
436
- machineEndpoint: { full: 4 }
485
+ /** D6.2, 2 = 1 + 1. */
486
+ cacheValidators: { saneCacheControl: 1, validator: 1 },
487
+ /**
488
+ * D6.3, 1. `specShaped` — an H1 and at least one Markdown link — is the whole
489
+ * point. `present` is 0 in 0.2: at two points 0.1 could pay one for the file
490
+ * existing and one for it being usable, but at one point that split would make
491
+ * "exists" and "usable" score identically, which is a distinction the standard
492
+ * would then be printing a remedy for and paying nothing to fix.
493
+ */
494
+ llmsTxt: { present: 0, specShaped: 1 },
495
+ /** D6.4, 1. All-or-nothing. */
496
+ sitemap: { full: 1 },
497
+ /** D6.5, 2. All-or-nothing over any ONE declared machine endpoint. */
498
+ machineEndpoint: { full: 2 }
437
499
  });
438
500
  var SHA256_K = [
439
501
  1116352408,
@@ -557,7 +619,7 @@ function sha256Hex(message) {
557
619
  for (const word of h) hex += word.toString(16).padStart(8, "0");
558
620
  return hex;
559
621
  }
560
- sha256Hex("ars-0.1-corpus-unfrozen");
622
+ sha256Hex("ars-0.2-corpus-unfrozen");
561
623
  var ALLOW_PRIVATE_HOSTS = /* @__PURE__ */ Symbol("rebilder.ars.probe.allow-private-hosts");
562
624
  var allowsPrivateHosts = (policy) => policy === ALLOW_PRIVATE_HOSTS;
563
625
  var NOT_AN_IP = { family: null, reserved: false, label: "hostname" };
@@ -1005,11 +1067,7 @@ function createLimiter(options = {}) {
1005
1067
  }
1006
1068
 
1007
1069
  // src/probe/index.ts
1008
- var ARS_USER_AGENT = "rebilder-ars/0.1 (+https://rebilder.com/bots)";
1009
- var ARS_ROBOTS_TOKEN = "rebilder-ars";
1010
- var AGENT_ACCEPT = "text/markdown;q=1.0, text/html;q=0.8, text/plain;q=0.5, */*;q=0.1";
1011
- var BROWSER_ACCEPT = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
1012
- var ASSET_ACCEPT = "text/plain,*/*;q=0.5";
1070
+ var ARS_USER_AGENT = "rebilder-ars/0.2 (+https://rebilder.com/bots)";
1013
1071
  var AGENT_IDENTITY = {
1014
1072
  role: "agent",
1015
1073
  userAgent: ARS_USER_AGENT,
@@ -1244,25 +1302,6 @@ async function fetchWithPolicy(startUrl, headers, context) {
1244
1302
  }
1245
1303
  return failed("too-many-redirects", `More than ${policy.maxRedirects - 1} redirects.`);
1246
1304
  }
1247
- function scannerDisallows(robotsBody, path) {
1248
- const robots = parseRobots(robotsBody);
1249
- for (const group of robots.groups) {
1250
- if (!group.agents.some((agent) => agent.toLowerCase() === ARS_ROBOTS_TOKEN)) continue;
1251
- let best = null;
1252
- for (const value of group.allow) {
1253
- if (!pathMatches(value, path)) continue;
1254
- if (best === null || value.length > best.value.length) best = { field: "allow", value };
1255
- }
1256
- for (const value of group.disallow) {
1257
- if (!pathMatches(value, path)) continue;
1258
- if (best === null || value.length > best.value.length) best = { field: "disallow", value };
1259
- }
1260
- if (best !== null && best.field === "disallow") {
1261
- return `User-agent: ${ARS_ROBOTS_TOKEN} / Disallow: ${best.value}`;
1262
- }
1263
- }
1264
- return null;
1265
- }
1266
1305
  function headersFor(identity) {
1267
1306
  return { accept: identity.accept, "user-agent": identity.userAgent };
1268
1307
  }
@@ -1353,7 +1392,7 @@ async function probeWithHostPolicy(target, policy, hostPolicy, options = {}) {
1353
1392
  }
1354
1393
  const robotsBody = robotsTxt.result.ok ? robotsTxt.result.capture.body ?? "" : "";
1355
1394
  const robotsUsable = robotsTxt.result.ok && robotsTxt.result.capture.status < 400;
1356
- const disallowedFor = (path) => vantage === "public" && robotsUsable ? scannerDisallows(robotsBody, path) : null;
1395
+ const disallowedFor = (path) => vantage === "public" && robotsUsable ? robotsDisallowsScanner(robotsBody, path) : null;
1357
1396
  const pageRule = disallowedFor(url.pathname);
1358
1397
  if (pageRule !== null) {
1359
1398
  const detail = `robots.txt disallows the ${ARS_ROBOTS_TOKEN} token (${pageRule})`;