@rebilder/agent-readability 0.1.1 → 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.
@@ -1,5 +1,5 @@
1
1
  import { Limiter, ProbePolicy, ProbeOptions, ProbeOutcome } from './index.cjs';
2
- import { c as ArsRuleset } from '../types-B2FhQ1YC.cjs';
2
+ import { c as ArsRuleset } from '../robots-policy-DE8jix-e.cjs';
3
3
 
4
4
  /**
5
5
  * probe/local.ts — `"./probe/local"`. Private hosts and plain http, and NOTHING
@@ -1,5 +1,5 @@
1
1
  import { Limiter, ProbePolicy, ProbeOptions, ProbeOutcome } from './index.js';
2
- import { c as ArsRuleset } from '../types-B2FhQ1YC.js';
2
+ import { c as ArsRuleset } from '../robots-policy-DE8jix-e.js';
3
3
 
4
4
  /**
5
5
  * probe/local.ts — `"./probe/local"`. Private hosts and plain http, and NOTHING
@@ -404,13 +404,13 @@ function deepFreeze(value) {
404
404
  return Object.freeze(value);
405
405
  }
406
406
  var WEIGHTS = {
407
- // D1 Retrievability — 20
408
- "retrievability.reachable": 8,
409
- "retrievability.robots-policy": 6,
410
- "retrievability.render-independence": 6,
411
- // D2 Machine representation — 20
412
- "machine-representation.negotiated-response": 10,
413
- "machine-representation.declared-alternates": 4,
407
+ // D1 Retrievability — 28
408
+ "retrievability.reachable": 11,
409
+ "retrievability.robots-policy": 10,
410
+ "retrievability.render-independence": 7,
411
+ // D2 Machine representation — 18
412
+ "machine-representation.negotiated-response": 9,
413
+ "machine-representation.declared-alternates": 3,
414
414
  "machine-representation.vary-accept": 3,
415
415
  "machine-representation.substance-parity": 3,
416
416
  // D3 Fact coverage — 20
@@ -419,16 +419,20 @@ var WEIGHTS = {
419
419
  // D4 Fact position — 10
420
420
  "fact-position.first-core-fact-offset": 5,
421
421
  "fact-position.front-window": 5,
422
- // D5 Structured data — 15
423
- "structured-data.present": 5,
424
- "structured-data.required-properties": 7,
425
- "structured-data.text-agreement": 3,
426
- // D6 Contract & discovery — 15
422
+ // D5 Structured data — 6
423
+ "structured-data.present": 2,
424
+ "structured-data.required-properties": 3,
425
+ "structured-data.text-agreement": 1,
426
+ // D6 Contract & discovery — 10
427
427
  "contract-discovery.canonical": 4,
428
- "contract-discovery.cache-validators": 3,
429
- "contract-discovery.llms-txt": 2,
430
- "contract-discovery.sitemap": 2,
431
- "contract-discovery.machine-endpoint": 4
428
+ "contract-discovery.cache-validators": 2,
429
+ "contract-discovery.llms-txt": 1,
430
+ "contract-discovery.sitemap": 1,
431
+ "contract-discovery.machine-endpoint": 2,
432
+ // D7 Evidence density — 8
433
+ "evidence-density.quantities": 4,
434
+ "evidence-density.definitions": 2,
435
+ "evidence-density.comparisons": 2
432
436
  };
433
437
  var THRESHOLDS = {
434
438
  /**
@@ -460,6 +464,31 @@ var THRESHOLDS = {
460
464
  * `ratio = 100 × bytes / byteReference[pageKind]`; above the last threshold, 0.
461
465
  */
462
466
  "fact-coverage.context-cost": [100, 6, 200, 5, 500, 3, 1500, 1],
467
+ /**
468
+ * D7.1 quantities, 4 pts. AT-LEAST over the count of DISTINCT quantity tokens
469
+ * in the agent's counted text: a currency amount, a percentage, a number
470
+ * carrying a unit, or an ISO date. Distinct, because a price repeated in a
471
+ * header, a buy box and a footer is one fact stated three times, and counting
472
+ * it three times would reward the repetition this score exists to discourage.
473
+ * Saturates at 12 so a specification table cannot outscore a page that simply
474
+ * states its facts.
475
+ */
476
+ "evidence-density.quantities": [12, 4, 6, 3, 3, 2, 1, 1],
477
+ /**
478
+ * D7.2 definitions, 2 pts. AT-LEAST over the count of `term: value` pairs the
479
+ * agent can read as a labelled fact, counting markdown bold-label lines,
480
+ * list items with a leading label, and HTML definition lists.
481
+ */
482
+ "evidence-density.definitions": [6, 2, 2, 1],
483
+ /**
484
+ * D7.3 comparisons, 2 pts. AT-LEAST over the number of comparable ROWS: a
485
+ * table with at least two data columns contributes its data-row count, minus
486
+ * the header. One row is not a comparison, so the band starts at two; three
487
+ * options laid side by side is a full comparison and pays out. Calibrated
488
+ * against fixture `060`, where a three-row size table is exactly the shape
489
+ * this check exists to reward, and `063`, where one row is not.
490
+ */
491
+ "evidence-density.comparisons": [3, 2, 2, 1],
463
492
  /** D4.1 first-core-fact byte offset, 5 pts. AT-MOST over the offset in bytes; else 0. */
464
493
  "fact-position.first-core-fact-offset": [512, 5, 2048, 4, 8192, 2, 32768, 1],
465
494
  /**
@@ -600,7 +629,7 @@ var BANDS = [
600
629
  }
601
630
  ];
602
631
  var DEFAULT_RULESET = deepFreeze({
603
- version: "0.1.0",
632
+ version: "0.2.0",
604
633
  weights: WEIGHTS,
605
634
  thresholds: THRESHOLDS,
606
635
  audienceTokens: AUDIENCE_TOKENS,
@@ -704,6 +733,33 @@ function pathMatches(pattern, path) {
704
733
  return true;
705
734
  }
706
735
 
736
+ // src/robots-policy.ts
737
+ var ARS_ROBOTS_TOKEN = "rebilder-ars";
738
+ function robotsDisallowsScanner(robotsBody, path) {
739
+ const robots = parseRobots(robotsBody);
740
+ for (const group of robots.groups) {
741
+ if (!group.agents.some((agent) => agent.toLowerCase() === ARS_ROBOTS_TOKEN)) continue;
742
+ let best = null;
743
+ for (const value of group.allow) {
744
+ if (!pathMatches(value, path)) continue;
745
+ if (best === null || value.length > best.value.length) best = { field: "allow", value };
746
+ }
747
+ for (const value of group.disallow) {
748
+ if (!pathMatches(value, path)) continue;
749
+ if (best === null || value.length > best.value.length) best = { field: "disallow", value };
750
+ }
751
+ if (best !== null && best.field === "disallow") {
752
+ return `User-agent: ${ARS_ROBOTS_TOKEN} / Disallow: ${best.value}`;
753
+ }
754
+ }
755
+ return null;
756
+ }
757
+
758
+ // src/probe/headers.ts
759
+ var AGENT_ACCEPT = "text/markdown;q=1.0, text/html;q=0.8, text/plain;q=0.5, */*;q=0.1";
760
+ var BROWSER_ACCEPT = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
761
+ var ASSET_ACCEPT = "text/plain,*/*;q=0.5";
762
+
707
763
  // src/score.ts
708
764
  function idiv(numerator, denominator) {
709
765
  if (denominator === 0) return 0;
@@ -715,44 +771,50 @@ function deepFreeze2(value) {
715
771
  return Object.freeze(value);
716
772
  }
717
773
  deepFreeze2({
718
- /** D1.1, 8 = 4 + 2 + 2. */
719
- reachable: { status2xx: 4, withinRedirectLimit: 2, noAcceptConditionalRedirect: 2 },
720
- /** D1.2, 6 = 3 + 1 + 1 + 1. A disallowed assistant audience scores 0 for all four (§3.7). */
721
- robotsPolicy: { assistantAllowed: 3, parsesClean: 1, noOrphanRules: 1, sitemapDeclared: 1 },
774
+ /** D1.1, 11 = 5 + 3 + 3. */
775
+ reachable: { status2xx: 5, withinRedirectLimit: 3, noAcceptConditionalRedirect: 3 },
776
+ /** D1.2, 10 = 6 + 2 + 1 + 1. A disallowed assistant audience scores 0 for all four (§3.7). */
777
+ robotsPolicy: { assistantAllowed: 6, parsesClean: 2, noOrphanRules: 1, sitemapDeclared: 1 },
722
778
  /**
723
- * D1.3, 6. AT-LEAST band over `100 × coreFactsInHtml / coreProfileSize`, plus
779
+ * D1.3, 7. AT-LEAST band over `100 × coreFactsInHtml / coreProfileSize`, plus
724
780
  * the `<noscript>` floor: a page whose facts are all client-rendered but which
725
781
  * ships a non-empty `<noscript>` has told a JS-less caller something, and §3.8
726
782
  * says that earns partial credit.
727
783
  */
728
784
  renderIndependence: {
729
- band: [100, 6, 75, 5, 50, 3, 25, 1],
785
+ band: [100, 7, 75, 5, 50, 3, 25, 1],
730
786
  noscriptFloor: 1
731
787
  },
732
- /** D2.1, 10. All-or-nothing: a machine media type AND a body that is not HTML. */
733
- negotiatedResponse: { full: 10 },
734
- /** D2.2, 4. All-or-nothing. */
735
- declaredAlternates: { full: 4 },
788
+ /** D2.1, 9. All-or-nothing: a machine media type AND a body that is not HTML. */
789
+ negotiatedResponse: { full: 9 },
790
+ /** D2.2, 3. All-or-nothing. */
791
+ declaredAlternates: { full: 3 },
736
792
  /** D2.3, 3. All-or-nothing, and 0 unless D2.1 > 0. */
737
793
  varyAccept: { full: 3 },
738
794
  /** D2.4, 3. All-or-nothing, and 0 unless D2.1 > 0 and a browser capture exists. */
739
795
  substanceParity: { full: 3 },
740
- /** D5.1, 5. Structured data present AND parsing; a partly-broken graph scores 3. */
741
- structuredDataPresent: { clean: 5, partial: 3 },
742
- /** D5.2, 7 = 2 (a recognised type) + 5 (required-property completeness, scaled). */
743
- requiredProperties: { recognisedType: 2, completeness: 5 },
744
- /** D5.3, 3. All-or-nothing. */
745
- textAgreement: { full: 3 },
796
+ /** D5.1, 2. Structured data present AND parsing; a partly-broken graph scores 1. */
797
+ structuredDataPresent: { clean: 2, partial: 1 },
798
+ /** D5.2, 3 = 1 (a recognised type) + 2 (required-property completeness, scaled). */
799
+ requiredProperties: { recognisedType: 1, completeness: 2 },
800
+ /** D5.3, 1. All-or-nothing. */
801
+ textAgreement: { full: 1 },
746
802
  /** D6.1, 4 = 2 + 1 + 1. */
747
803
  canonical: { present: 2, absolute: 1, consistentAcrossProbes: 1 },
748
- /** D6.2, 3 = 2 + 1. */
749
- cacheValidators: { saneCacheControl: 2, validator: 1 },
750
- /** D6.3, 2. `present` alone for a file that exists; `specShaped` for one that parses as llms.txt. */
751
- llmsTxt: { present: 1, specShaped: 2 },
752
- /** D6.4, 2. All-or-nothing. */
753
- sitemap: { full: 2 },
754
- /** D6.5, 4. All-or-nothing over any ONE declared machine endpoint. */
755
- machineEndpoint: { full: 4 }
804
+ /** D6.2, 2 = 1 + 1. */
805
+ cacheValidators: { saneCacheControl: 1, validator: 1 },
806
+ /**
807
+ * D6.3, 1. `specShaped` — an H1 and at least one Markdown link — is the whole
808
+ * point. `present` is 0 in 0.2: at two points 0.1 could pay one for the file
809
+ * existing and one for it being usable, but at one point that split would make
810
+ * "exists" and "usable" score identically, which is a distinction the standard
811
+ * would then be printing a remedy for and paying nothing to fix.
812
+ */
813
+ llmsTxt: { present: 0, specShaped: 1 },
814
+ /** D6.4, 1. All-or-nothing. */
815
+ sitemap: { full: 1 },
816
+ /** D6.5, 2. All-or-nothing over any ONE declared machine endpoint. */
817
+ machineEndpoint: { full: 2 }
756
818
  });
757
819
  var SHA256_K = [
758
820
  1116352408,
@@ -876,7 +938,7 @@ function sha256Hex(message) {
876
938
  for (const word of h) hex += word.toString(16).padStart(8, "0");
877
939
  return hex;
878
940
  }
879
- sha256Hex("ars-0.1-corpus-unfrozen");
941
+ sha256Hex("ars-0.2-corpus-unfrozen");
880
942
 
881
943
  // src/probe/limiter.ts
882
944
  var ProbeBudgetExceededError = class extends Error {
@@ -891,11 +953,7 @@ var ProbeBudgetExceededError = class extends Error {
891
953
  };
892
954
 
893
955
  // src/probe/index.ts
894
- var ARS_USER_AGENT = "rebilder-ars/0.1 (+https://rebilder.com/bots)";
895
- var ARS_ROBOTS_TOKEN = "rebilder-ars";
896
- var AGENT_ACCEPT = "text/markdown;q=1.0, text/html;q=0.8, text/plain;q=0.5, */*;q=0.1";
897
- var BROWSER_ACCEPT = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
898
- var ASSET_ACCEPT = "text/plain,*/*;q=0.5";
956
+ var ARS_USER_AGENT = "rebilder-ars/0.2 (+https://rebilder.com/bots)";
899
957
  var AGENT_IDENTITY = {
900
958
  role: "agent",
901
959
  userAgent: ARS_USER_AGENT,
@@ -1130,25 +1188,6 @@ async function fetchWithPolicy(startUrl, headers, context) {
1130
1188
  }
1131
1189
  return failed("too-many-redirects", `More than ${policy.maxRedirects - 1} redirects.`);
1132
1190
  }
1133
- function scannerDisallows(robotsBody, path) {
1134
- const robots = parseRobots(robotsBody);
1135
- for (const group of robots.groups) {
1136
- if (!group.agents.some((agent) => agent.toLowerCase() === ARS_ROBOTS_TOKEN)) continue;
1137
- let best = null;
1138
- for (const value of group.allow) {
1139
- if (!pathMatches(value, path)) continue;
1140
- if (best === null || value.length > best.value.length) best = { field: "allow", value };
1141
- }
1142
- for (const value of group.disallow) {
1143
- if (!pathMatches(value, path)) continue;
1144
- if (best === null || value.length > best.value.length) best = { field: "disallow", value };
1145
- }
1146
- if (best !== null && best.field === "disallow") {
1147
- return `User-agent: ${ARS_ROBOTS_TOKEN} / Disallow: ${best.value}`;
1148
- }
1149
- }
1150
- return null;
1151
- }
1152
1191
  function headersFor(identity) {
1153
1192
  return { accept: identity.accept, "user-agent": identity.userAgent };
1154
1193
  }
@@ -1239,7 +1278,7 @@ async function probeWithHostPolicy(target, policy, hostPolicy, options = {}) {
1239
1278
  }
1240
1279
  const robotsBody = robotsTxt.result.ok ? robotsTxt.result.capture.body ?? "" : "";
1241
1280
  const robotsUsable = robotsTxt.result.ok && robotsTxt.result.capture.status < 400;
1242
- const disallowedFor = (path) => vantage === "public" && robotsUsable ? scannerDisallows(robotsBody, path) : null;
1281
+ const disallowedFor = (path) => vantage === "public" && robotsUsable ? robotsDisallowsScanner(robotsBody, path) : null;
1243
1282
  const pageRule = disallowedFor(url.pathname);
1244
1283
  if (pageRule !== null) {
1245
1284
  const detail = `robots.txt disallows the ${ARS_ROBOTS_TOKEN} token (${pageRule})`;