@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.
- package/README.md +15 -14
- package/dist/index.cjs +266 -53
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +209 -48
- package/dist/index.d.ts +209 -48
- package/dist/index.js +259 -54
- package/dist/index.js.map +1 -1
- package/dist/probe/index.cjs +106 -67
- package/dist/probe/index.cjs.map +1 -1
- package/dist/probe/index.d.cts +14 -9
- package/dist/probe/index.d.ts +14 -9
- package/dist/probe/index.js +106 -67
- package/dist/probe/index.js.map +1 -1
- package/dist/probe/local.cjs +106 -67
- package/dist/probe/local.cjs.map +1 -1
- package/dist/probe/local.d.cts +1 -1
- package/dist/probe/local.d.ts +1 -1
- package/dist/probe/local.js +106 -67
- package/dist/probe/local.js.map +1 -1
- package/dist/{types-B2FhQ1YC.d.cts → robots-policy-DE8jix-e.d.cts} +62 -9
- package/dist/{types-B2FhQ1YC.d.ts → robots-policy-DE8jix-e.d.ts} +62 -9
- package/package.json +4 -8
package/dist/probe/local.cjs
CHANGED
|
@@ -427,13 +427,13 @@ function deepFreeze(value) {
|
|
|
427
427
|
return Object.freeze(value);
|
|
428
428
|
}
|
|
429
429
|
var WEIGHTS = {
|
|
430
|
-
// D1 Retrievability —
|
|
431
|
-
"retrievability.reachable":
|
|
432
|
-
"retrievability.robots-policy":
|
|
433
|
-
"retrievability.render-independence":
|
|
434
|
-
// D2 Machine representation —
|
|
435
|
-
"machine-representation.negotiated-response":
|
|
436
|
-
"machine-representation.declared-alternates":
|
|
430
|
+
// D1 Retrievability — 28
|
|
431
|
+
"retrievability.reachable": 11,
|
|
432
|
+
"retrievability.robots-policy": 10,
|
|
433
|
+
"retrievability.render-independence": 7,
|
|
434
|
+
// D2 Machine representation — 18
|
|
435
|
+
"machine-representation.negotiated-response": 9,
|
|
436
|
+
"machine-representation.declared-alternates": 3,
|
|
437
437
|
"machine-representation.vary-accept": 3,
|
|
438
438
|
"machine-representation.substance-parity": 3,
|
|
439
439
|
// D3 Fact coverage — 20
|
|
@@ -442,16 +442,20 @@ var WEIGHTS = {
|
|
|
442
442
|
// D4 Fact position — 10
|
|
443
443
|
"fact-position.first-core-fact-offset": 5,
|
|
444
444
|
"fact-position.front-window": 5,
|
|
445
|
-
// D5 Structured data —
|
|
446
|
-
"structured-data.present":
|
|
447
|
-
"structured-data.required-properties":
|
|
448
|
-
"structured-data.text-agreement":
|
|
449
|
-
// D6 Contract & discovery —
|
|
445
|
+
// D5 Structured data — 6
|
|
446
|
+
"structured-data.present": 2,
|
|
447
|
+
"structured-data.required-properties": 3,
|
|
448
|
+
"structured-data.text-agreement": 1,
|
|
449
|
+
// D6 Contract & discovery — 10
|
|
450
450
|
"contract-discovery.canonical": 4,
|
|
451
|
-
"contract-discovery.cache-validators":
|
|
452
|
-
"contract-discovery.llms-txt":
|
|
453
|
-
"contract-discovery.sitemap":
|
|
454
|
-
"contract-discovery.machine-endpoint":
|
|
451
|
+
"contract-discovery.cache-validators": 2,
|
|
452
|
+
"contract-discovery.llms-txt": 1,
|
|
453
|
+
"contract-discovery.sitemap": 1,
|
|
454
|
+
"contract-discovery.machine-endpoint": 2,
|
|
455
|
+
// D7 Evidence density — 8
|
|
456
|
+
"evidence-density.quantities": 4,
|
|
457
|
+
"evidence-density.definitions": 2,
|
|
458
|
+
"evidence-density.comparisons": 2
|
|
455
459
|
};
|
|
456
460
|
var THRESHOLDS = {
|
|
457
461
|
/**
|
|
@@ -483,6 +487,31 @@ var THRESHOLDS = {
|
|
|
483
487
|
* `ratio = 100 × bytes / byteReference[pageKind]`; above the last threshold, 0.
|
|
484
488
|
*/
|
|
485
489
|
"fact-coverage.context-cost": [100, 6, 200, 5, 500, 3, 1500, 1],
|
|
490
|
+
/**
|
|
491
|
+
* D7.1 quantities, 4 pts. AT-LEAST over the count of DISTINCT quantity tokens
|
|
492
|
+
* in the agent's counted text: a currency amount, a percentage, a number
|
|
493
|
+
* carrying a unit, or an ISO date. Distinct, because a price repeated in a
|
|
494
|
+
* header, a buy box and a footer is one fact stated three times, and counting
|
|
495
|
+
* it three times would reward the repetition this score exists to discourage.
|
|
496
|
+
* Saturates at 12 so a specification table cannot outscore a page that simply
|
|
497
|
+
* states its facts.
|
|
498
|
+
*/
|
|
499
|
+
"evidence-density.quantities": [12, 4, 6, 3, 3, 2, 1, 1],
|
|
500
|
+
/**
|
|
501
|
+
* D7.2 definitions, 2 pts. AT-LEAST over the count of `term: value` pairs the
|
|
502
|
+
* agent can read as a labelled fact, counting markdown bold-label lines,
|
|
503
|
+
* list items with a leading label, and HTML definition lists.
|
|
504
|
+
*/
|
|
505
|
+
"evidence-density.definitions": [6, 2, 2, 1],
|
|
506
|
+
/**
|
|
507
|
+
* D7.3 comparisons, 2 pts. AT-LEAST over the number of comparable ROWS: a
|
|
508
|
+
* table with at least two data columns contributes its data-row count, minus
|
|
509
|
+
* the header. One row is not a comparison, so the band starts at two; three
|
|
510
|
+
* options laid side by side is a full comparison and pays out. Calibrated
|
|
511
|
+
* against fixture `060`, where a three-row size table is exactly the shape
|
|
512
|
+
* this check exists to reward, and `063`, where one row is not.
|
|
513
|
+
*/
|
|
514
|
+
"evidence-density.comparisons": [3, 2, 2, 1],
|
|
486
515
|
/** D4.1 first-core-fact byte offset, 5 pts. AT-MOST over the offset in bytes; else 0. */
|
|
487
516
|
"fact-position.first-core-fact-offset": [512, 5, 2048, 4, 8192, 2, 32768, 1],
|
|
488
517
|
/**
|
|
@@ -623,7 +652,7 @@ var BANDS = [
|
|
|
623
652
|
}
|
|
624
653
|
];
|
|
625
654
|
var DEFAULT_RULESET = deepFreeze({
|
|
626
|
-
version: "0.
|
|
655
|
+
version: "0.2.0",
|
|
627
656
|
weights: WEIGHTS,
|
|
628
657
|
thresholds: THRESHOLDS,
|
|
629
658
|
audienceTokens: AUDIENCE_TOKENS,
|
|
@@ -727,6 +756,33 @@ function pathMatches(pattern, path) {
|
|
|
727
756
|
return true;
|
|
728
757
|
}
|
|
729
758
|
|
|
759
|
+
// src/robots-policy.ts
|
|
760
|
+
var ARS_ROBOTS_TOKEN = "rebilder-ars";
|
|
761
|
+
function robotsDisallowsScanner(robotsBody, path) {
|
|
762
|
+
const robots = parseRobots(robotsBody);
|
|
763
|
+
for (const group of robots.groups) {
|
|
764
|
+
if (!group.agents.some((agent) => agent.toLowerCase() === ARS_ROBOTS_TOKEN)) continue;
|
|
765
|
+
let best = null;
|
|
766
|
+
for (const value of group.allow) {
|
|
767
|
+
if (!pathMatches(value, path)) continue;
|
|
768
|
+
if (best === null || value.length > best.value.length) best = { field: "allow", value };
|
|
769
|
+
}
|
|
770
|
+
for (const value of group.disallow) {
|
|
771
|
+
if (!pathMatches(value, path)) continue;
|
|
772
|
+
if (best === null || value.length > best.value.length) best = { field: "disallow", value };
|
|
773
|
+
}
|
|
774
|
+
if (best !== null && best.field === "disallow") {
|
|
775
|
+
return `User-agent: ${ARS_ROBOTS_TOKEN} / Disallow: ${best.value}`;
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
return null;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
// src/probe/headers.ts
|
|
782
|
+
var AGENT_ACCEPT = "text/markdown;q=1.0, text/html;q=0.8, text/plain;q=0.5, */*;q=0.1";
|
|
783
|
+
var BROWSER_ACCEPT = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
|
|
784
|
+
var ASSET_ACCEPT = "text/plain,*/*;q=0.5";
|
|
785
|
+
|
|
730
786
|
// src/score.ts
|
|
731
787
|
function idiv(numerator, denominator) {
|
|
732
788
|
if (denominator === 0) return 0;
|
|
@@ -738,44 +794,50 @@ function deepFreeze2(value) {
|
|
|
738
794
|
return Object.freeze(value);
|
|
739
795
|
}
|
|
740
796
|
deepFreeze2({
|
|
741
|
-
/** D1.1,
|
|
742
|
-
reachable: { status2xx:
|
|
743
|
-
/** D1.2,
|
|
744
|
-
robotsPolicy: { assistantAllowed:
|
|
797
|
+
/** D1.1, 11 = 5 + 3 + 3. */
|
|
798
|
+
reachable: { status2xx: 5, withinRedirectLimit: 3, noAcceptConditionalRedirect: 3 },
|
|
799
|
+
/** D1.2, 10 = 6 + 2 + 1 + 1. A disallowed assistant audience scores 0 for all four (§3.7). */
|
|
800
|
+
robotsPolicy: { assistantAllowed: 6, parsesClean: 2, noOrphanRules: 1, sitemapDeclared: 1 },
|
|
745
801
|
/**
|
|
746
|
-
* D1.3,
|
|
802
|
+
* D1.3, 7. AT-LEAST band over `100 × coreFactsInHtml / coreProfileSize`, plus
|
|
747
803
|
* the `<noscript>` floor: a page whose facts are all client-rendered but which
|
|
748
804
|
* ships a non-empty `<noscript>` has told a JS-less caller something, and §3.8
|
|
749
805
|
* says that earns partial credit.
|
|
750
806
|
*/
|
|
751
807
|
renderIndependence: {
|
|
752
|
-
band: [100,
|
|
808
|
+
band: [100, 7, 75, 5, 50, 3, 25, 1],
|
|
753
809
|
noscriptFloor: 1
|
|
754
810
|
},
|
|
755
|
-
/** D2.1,
|
|
756
|
-
negotiatedResponse: { full:
|
|
757
|
-
/** D2.2,
|
|
758
|
-
declaredAlternates: { full:
|
|
811
|
+
/** D2.1, 9. All-or-nothing: a machine media type AND a body that is not HTML. */
|
|
812
|
+
negotiatedResponse: { full: 9 },
|
|
813
|
+
/** D2.2, 3. All-or-nothing. */
|
|
814
|
+
declaredAlternates: { full: 3 },
|
|
759
815
|
/** D2.3, 3. All-or-nothing, and 0 unless D2.1 > 0. */
|
|
760
816
|
varyAccept: { full: 3 },
|
|
761
817
|
/** D2.4, 3. All-or-nothing, and 0 unless D2.1 > 0 and a browser capture exists. */
|
|
762
818
|
substanceParity: { full: 3 },
|
|
763
|
-
/** D5.1,
|
|
764
|
-
structuredDataPresent: { clean:
|
|
765
|
-
/** D5.2,
|
|
766
|
-
requiredProperties: { recognisedType:
|
|
767
|
-
/** D5.3,
|
|
768
|
-
textAgreement: { full:
|
|
819
|
+
/** D5.1, 2. Structured data present AND parsing; a partly-broken graph scores 1. */
|
|
820
|
+
structuredDataPresent: { clean: 2, partial: 1 },
|
|
821
|
+
/** D5.2, 3 = 1 (a recognised type) + 2 (required-property completeness, scaled). */
|
|
822
|
+
requiredProperties: { recognisedType: 1, completeness: 2 },
|
|
823
|
+
/** D5.3, 1. All-or-nothing. */
|
|
824
|
+
textAgreement: { full: 1 },
|
|
769
825
|
/** D6.1, 4 = 2 + 1 + 1. */
|
|
770
826
|
canonical: { present: 2, absolute: 1, consistentAcrossProbes: 1 },
|
|
771
|
-
/** D6.2,
|
|
772
|
-
cacheValidators: { saneCacheControl:
|
|
773
|
-
/**
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
827
|
+
/** D6.2, 2 = 1 + 1. */
|
|
828
|
+
cacheValidators: { saneCacheControl: 1, validator: 1 },
|
|
829
|
+
/**
|
|
830
|
+
* D6.3, 1. `specShaped` — an H1 and at least one Markdown link — is the whole
|
|
831
|
+
* point. `present` is 0 in 0.2: at two points 0.1 could pay one for the file
|
|
832
|
+
* existing and one for it being usable, but at one point that split would make
|
|
833
|
+
* "exists" and "usable" score identically, which is a distinction the standard
|
|
834
|
+
* would then be printing a remedy for and paying nothing to fix.
|
|
835
|
+
*/
|
|
836
|
+
llmsTxt: { present: 0, specShaped: 1 },
|
|
837
|
+
/** D6.4, 1. All-or-nothing. */
|
|
838
|
+
sitemap: { full: 1 },
|
|
839
|
+
/** D6.5, 2. All-or-nothing over any ONE declared machine endpoint. */
|
|
840
|
+
machineEndpoint: { full: 2 }
|
|
779
841
|
});
|
|
780
842
|
var SHA256_K = [
|
|
781
843
|
1116352408,
|
|
@@ -899,7 +961,7 @@ function sha256Hex(message) {
|
|
|
899
961
|
for (const word of h) hex += word.toString(16).padStart(8, "0");
|
|
900
962
|
return hex;
|
|
901
963
|
}
|
|
902
|
-
sha256Hex("ars-0.
|
|
964
|
+
sha256Hex("ars-0.2-corpus-unfrozen");
|
|
903
965
|
|
|
904
966
|
// src/probe/limiter.ts
|
|
905
967
|
var ProbeBudgetExceededError = class extends Error {
|
|
@@ -914,11 +976,7 @@ var ProbeBudgetExceededError = class extends Error {
|
|
|
914
976
|
};
|
|
915
977
|
|
|
916
978
|
// src/probe/index.ts
|
|
917
|
-
var ARS_USER_AGENT = "rebilder-ars/0.
|
|
918
|
-
var ARS_ROBOTS_TOKEN = "rebilder-ars";
|
|
919
|
-
var AGENT_ACCEPT = "text/markdown;q=1.0, text/html;q=0.8, text/plain;q=0.5, */*;q=0.1";
|
|
920
|
-
var BROWSER_ACCEPT = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
|
|
921
|
-
var ASSET_ACCEPT = "text/plain,*/*;q=0.5";
|
|
979
|
+
var ARS_USER_AGENT = "rebilder-ars/0.2 (+https://rebilder.com/bots)";
|
|
922
980
|
var AGENT_IDENTITY = {
|
|
923
981
|
role: "agent",
|
|
924
982
|
userAgent: ARS_USER_AGENT,
|
|
@@ -1153,25 +1211,6 @@ async function fetchWithPolicy(startUrl, headers, context) {
|
|
|
1153
1211
|
}
|
|
1154
1212
|
return failed("too-many-redirects", `More than ${policy.maxRedirects - 1} redirects.`);
|
|
1155
1213
|
}
|
|
1156
|
-
function scannerDisallows(robotsBody, path) {
|
|
1157
|
-
const robots = parseRobots(robotsBody);
|
|
1158
|
-
for (const group of robots.groups) {
|
|
1159
|
-
if (!group.agents.some((agent) => agent.toLowerCase() === ARS_ROBOTS_TOKEN)) continue;
|
|
1160
|
-
let best = null;
|
|
1161
|
-
for (const value of group.allow) {
|
|
1162
|
-
if (!pathMatches(value, path)) continue;
|
|
1163
|
-
if (best === null || value.length > best.value.length) best = { field: "allow", value };
|
|
1164
|
-
}
|
|
1165
|
-
for (const value of group.disallow) {
|
|
1166
|
-
if (!pathMatches(value, path)) continue;
|
|
1167
|
-
if (best === null || value.length > best.value.length) best = { field: "disallow", value };
|
|
1168
|
-
}
|
|
1169
|
-
if (best !== null && best.field === "disallow") {
|
|
1170
|
-
return `User-agent: ${ARS_ROBOTS_TOKEN} / Disallow: ${best.value}`;
|
|
1171
|
-
}
|
|
1172
|
-
}
|
|
1173
|
-
return null;
|
|
1174
|
-
}
|
|
1175
1214
|
function headersFor(identity) {
|
|
1176
1215
|
return { accept: identity.accept, "user-agent": identity.userAgent };
|
|
1177
1216
|
}
|
|
@@ -1262,7 +1301,7 @@ async function probeWithHostPolicy(target, policy, hostPolicy, options = {}) {
|
|
|
1262
1301
|
}
|
|
1263
1302
|
const robotsBody = robotsTxt.result.ok ? robotsTxt.result.capture.body ?? "" : "";
|
|
1264
1303
|
const robotsUsable = robotsTxt.result.ok && robotsTxt.result.capture.status < 400;
|
|
1265
|
-
const disallowedFor = (path) => vantage === "public" && robotsUsable ?
|
|
1304
|
+
const disallowedFor = (path) => vantage === "public" && robotsUsable ? robotsDisallowsScanner(robotsBody, path) : null;
|
|
1266
1305
|
const pageRule = disallowedFor(url.pathname);
|
|
1267
1306
|
if (pageRule !== null) {
|
|
1268
1307
|
const detail = `robots.txt disallows the ${ARS_ROBOTS_TOKEN} token (${pageRule})`;
|