@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,4 +1,5 @@
1
- import { C as ArsVantage, e as ArsEvidence, c as ArsRuleset } from '../types-B2FhQ1YC.cjs';
1
+ import { F as ArsVantage, e as ArsEvidence, c as ArsRuleset } from '../robots-policy-DE8jix-e.cjs';
2
+ export { i as AGENT_ACCEPT, j as ARS_ROBOTS_TOKEN, l as ASSET_ACCEPT, G as BROWSER_ACCEPT } from '../robots-policy-DE8jix-e.cjs';
2
3
 
3
4
  /**
4
5
  * probe/ssrf.ts — the network-side host policy for `@rebilder/agent-readability`.
@@ -298,13 +299,17 @@ interface ProbeIdentity {
298
299
  readonly userAgent: string;
299
300
  readonly accept: string;
300
301
  }
301
- /** Honest, contactable, and never anybody else's. */
302
- declare const ARS_USER_AGENT = "rebilder-ars/0.1 (+https://rebilder.com/bots)";
303
- /** The robots.txt token this probe answers to. Matched case-insensitively. */
304
- declare const ARS_ROBOTS_TOKEN = "rebilder-ars";
305
- declare const AGENT_ACCEPT = "text/markdown;q=1.0, text/html;q=0.8, text/plain;q=0.5, */*;q=0.1";
306
- declare const BROWSER_ACCEPT = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
307
- declare const ASSET_ACCEPT = "text/plain,*/*;q=0.5";
302
+ /**
303
+ * Honest, contactable, and never anybody else's. The number tracks the spec
304
+ * version, so a server log tells its operator which ruleset scored them.
305
+ *
306
+ * IT IS NOT THE REFUSAL TOKEN. A site that disallowed us under 0.1 is still
307
+ * refusing us under 0.2, because robots.txt is matched on `ARS_ROBOTS_TOKEN`
308
+ * below and that string never moves. Versioning the refusal token would let a
309
+ * spec bump quietly re-open sites that already said no.
310
+ */
311
+ declare const ARS_USER_AGENT = "rebilder-ars/0.2 (+https://rebilder.com/bots)";
312
+
308
313
  declare const DEFAULT_IDENTITIES: readonly ProbeIdentity[];
309
314
  /**
310
315
  * Policy as a type rather than a pile of booleans — and note what is NOT here:
@@ -382,4 +387,4 @@ declare function probeStrict(target: string, policy: ProbePolicy, options?: Prob
382
387
  /** Convenience for one-off callers: a fresh run-scoped limiter and the strict policy. */
383
388
  declare function strictPolicyForRun(overrides?: Partial<ProbePolicy>): ProbePolicy;
384
389
 
385
- export { AGENT_ACCEPT, ARS_ROBOTS_TOKEN, ARS_USER_AGENT, ASSET_ACCEPT, BROWSER_ACCEPT, DEFAULT_IDENTITIES, type HostPolicy, type HostResolver, type IpClassification, type Limiter, type LimiterLease, type LimiterOptions, type PinnedAddress, ProbeBudgetExceededError, type ProbeHttpResponse, type ProbeIdentity, type ProbeOptions, type ProbeOutcome, type ProbePolicy, type ProbeRejection, type ProbeRequestInit, type ProbeRole, type ProbeTransport, type ResolveOutcome, type UrlGuardPolicy, type UrlGuardResult, classifyIp, createDnsResolver, createLimiter, createPinnedTransport, fromWebResponse, guardPreviewUrl, guardUrl, parseIpv4, parseIpv6, probeStrict, probeWithHostPolicy, resolveAndValidate, strictPolicy, strictPolicyForRun };
390
+ export { ARS_USER_AGENT, DEFAULT_IDENTITIES, type HostPolicy, type HostResolver, type IpClassification, type Limiter, type LimiterLease, type LimiterOptions, type PinnedAddress, ProbeBudgetExceededError, type ProbeHttpResponse, type ProbeIdentity, type ProbeOptions, type ProbeOutcome, type ProbePolicy, type ProbeRejection, type ProbeRequestInit, type ProbeRole, type ProbeTransport, type ResolveOutcome, type UrlGuardPolicy, type UrlGuardResult, classifyIp, createDnsResolver, createLimiter, createPinnedTransport, fromWebResponse, guardPreviewUrl, guardUrl, parseIpv4, parseIpv6, probeStrict, probeWithHostPolicy, resolveAndValidate, strictPolicy, strictPolicyForRun };
@@ -1,4 +1,5 @@
1
- import { C as ArsVantage, e as ArsEvidence, c as ArsRuleset } from '../types-B2FhQ1YC.js';
1
+ import { F as ArsVantage, e as ArsEvidence, c as ArsRuleset } from '../robots-policy-DE8jix-e.js';
2
+ export { i as AGENT_ACCEPT, j as ARS_ROBOTS_TOKEN, l as ASSET_ACCEPT, G as BROWSER_ACCEPT } from '../robots-policy-DE8jix-e.js';
2
3
 
3
4
  /**
4
5
  * probe/ssrf.ts — the network-side host policy for `@rebilder/agent-readability`.
@@ -298,13 +299,17 @@ interface ProbeIdentity {
298
299
  readonly userAgent: string;
299
300
  readonly accept: string;
300
301
  }
301
- /** Honest, contactable, and never anybody else's. */
302
- declare const ARS_USER_AGENT = "rebilder-ars/0.1 (+https://rebilder.com/bots)";
303
- /** The robots.txt token this probe answers to. Matched case-insensitively. */
304
- declare const ARS_ROBOTS_TOKEN = "rebilder-ars";
305
- declare const AGENT_ACCEPT = "text/markdown;q=1.0, text/html;q=0.8, text/plain;q=0.5, */*;q=0.1";
306
- declare const BROWSER_ACCEPT = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
307
- declare const ASSET_ACCEPT = "text/plain,*/*;q=0.5";
302
+ /**
303
+ * Honest, contactable, and never anybody else's. The number tracks the spec
304
+ * version, so a server log tells its operator which ruleset scored them.
305
+ *
306
+ * IT IS NOT THE REFUSAL TOKEN. A site that disallowed us under 0.1 is still
307
+ * refusing us under 0.2, because robots.txt is matched on `ARS_ROBOTS_TOKEN`
308
+ * below and that string never moves. Versioning the refusal token would let a
309
+ * spec bump quietly re-open sites that already said no.
310
+ */
311
+ declare const ARS_USER_AGENT = "rebilder-ars/0.2 (+https://rebilder.com/bots)";
312
+
308
313
  declare const DEFAULT_IDENTITIES: readonly ProbeIdentity[];
309
314
  /**
310
315
  * Policy as a type rather than a pile of booleans — and note what is NOT here:
@@ -382,4 +387,4 @@ declare function probeStrict(target: string, policy: ProbePolicy, options?: Prob
382
387
  /** Convenience for one-off callers: a fresh run-scoped limiter and the strict policy. */
383
388
  declare function strictPolicyForRun(overrides?: Partial<ProbePolicy>): ProbePolicy;
384
389
 
385
- export { AGENT_ACCEPT, ARS_ROBOTS_TOKEN, ARS_USER_AGENT, ASSET_ACCEPT, BROWSER_ACCEPT, DEFAULT_IDENTITIES, type HostPolicy, type HostResolver, type IpClassification, type Limiter, type LimiterLease, type LimiterOptions, type PinnedAddress, ProbeBudgetExceededError, type ProbeHttpResponse, type ProbeIdentity, type ProbeOptions, type ProbeOutcome, type ProbePolicy, type ProbeRejection, type ProbeRequestInit, type ProbeRole, type ProbeTransport, type ResolveOutcome, type UrlGuardPolicy, type UrlGuardResult, classifyIp, createDnsResolver, createLimiter, createPinnedTransport, fromWebResponse, guardPreviewUrl, guardUrl, parseIpv4, parseIpv6, probeStrict, probeWithHostPolicy, resolveAndValidate, strictPolicy, strictPolicyForRun };
390
+ export { ARS_USER_AGENT, DEFAULT_IDENTITIES, type HostPolicy, type HostResolver, type IpClassification, type Limiter, type LimiterLease, type LimiterOptions, type PinnedAddress, ProbeBudgetExceededError, type ProbeHttpResponse, type ProbeIdentity, type ProbeOptions, type ProbeOutcome, type ProbePolicy, type ProbeRejection, type ProbeRequestInit, type ProbeRole, type ProbeTransport, type ResolveOutcome, type UrlGuardPolicy, type UrlGuardResult, classifyIp, createDnsResolver, createLimiter, createPinnedTransport, fromWebResponse, guardPreviewUrl, guardUrl, parseIpv4, parseIpv6, probeStrict, probeWithHostPolicy, resolveAndValidate, strictPolicy, strictPolicyForRun };
@@ -62,13 +62,13 @@ function deepFreeze(value) {
62
62
  return Object.freeze(value);
63
63
  }
64
64
  var WEIGHTS = {
65
- // D1 Retrievability — 20
66
- "retrievability.reachable": 8,
67
- "retrievability.robots-policy": 6,
68
- "retrievability.render-independence": 6,
69
- // D2 Machine representation — 20
70
- "machine-representation.negotiated-response": 10,
71
- "machine-representation.declared-alternates": 4,
65
+ // D1 Retrievability — 28
66
+ "retrievability.reachable": 11,
67
+ "retrievability.robots-policy": 10,
68
+ "retrievability.render-independence": 7,
69
+ // D2 Machine representation — 18
70
+ "machine-representation.negotiated-response": 9,
71
+ "machine-representation.declared-alternates": 3,
72
72
  "machine-representation.vary-accept": 3,
73
73
  "machine-representation.substance-parity": 3,
74
74
  // D3 Fact coverage — 20
@@ -77,16 +77,20 @@ var WEIGHTS = {
77
77
  // D4 Fact position — 10
78
78
  "fact-position.first-core-fact-offset": 5,
79
79
  "fact-position.front-window": 5,
80
- // D5 Structured data — 15
81
- "structured-data.present": 5,
82
- "structured-data.required-properties": 7,
83
- "structured-data.text-agreement": 3,
84
- // D6 Contract & discovery — 15
80
+ // D5 Structured data — 6
81
+ "structured-data.present": 2,
82
+ "structured-data.required-properties": 3,
83
+ "structured-data.text-agreement": 1,
84
+ // D6 Contract & discovery — 10
85
85
  "contract-discovery.canonical": 4,
86
- "contract-discovery.cache-validators": 3,
87
- "contract-discovery.llms-txt": 2,
88
- "contract-discovery.sitemap": 2,
89
- "contract-discovery.machine-endpoint": 4
86
+ "contract-discovery.cache-validators": 2,
87
+ "contract-discovery.llms-txt": 1,
88
+ "contract-discovery.sitemap": 1,
89
+ "contract-discovery.machine-endpoint": 2,
90
+ // D7 Evidence density — 8
91
+ "evidence-density.quantities": 4,
92
+ "evidence-density.definitions": 2,
93
+ "evidence-density.comparisons": 2
90
94
  };
91
95
  var THRESHOLDS = {
92
96
  /**
@@ -118,6 +122,31 @@ var THRESHOLDS = {
118
122
  * `ratio = 100 × bytes / byteReference[pageKind]`; above the last threshold, 0.
119
123
  */
120
124
  "fact-coverage.context-cost": [100, 6, 200, 5, 500, 3, 1500, 1],
125
+ /**
126
+ * D7.1 quantities, 4 pts. AT-LEAST over the count of DISTINCT quantity tokens
127
+ * in the agent's counted text: a currency amount, a percentage, a number
128
+ * carrying a unit, or an ISO date. Distinct, because a price repeated in a
129
+ * header, a buy box and a footer is one fact stated three times, and counting
130
+ * it three times would reward the repetition this score exists to discourage.
131
+ * Saturates at 12 so a specification table cannot outscore a page that simply
132
+ * states its facts.
133
+ */
134
+ "evidence-density.quantities": [12, 4, 6, 3, 3, 2, 1, 1],
135
+ /**
136
+ * D7.2 definitions, 2 pts. AT-LEAST over the count of `term: value` pairs the
137
+ * agent can read as a labelled fact, counting markdown bold-label lines,
138
+ * list items with a leading label, and HTML definition lists.
139
+ */
140
+ "evidence-density.definitions": [6, 2, 2, 1],
141
+ /**
142
+ * D7.3 comparisons, 2 pts. AT-LEAST over the number of comparable ROWS: a
143
+ * table with at least two data columns contributes its data-row count, minus
144
+ * the header. One row is not a comparison, so the band starts at two; three
145
+ * options laid side by side is a full comparison and pays out. Calibrated
146
+ * against fixture `060`, where a three-row size table is exactly the shape
147
+ * this check exists to reward, and `063`, where one row is not.
148
+ */
149
+ "evidence-density.comparisons": [3, 2, 2, 1],
121
150
  /** D4.1 first-core-fact byte offset, 5 pts. AT-MOST over the offset in bytes; else 0. */
122
151
  "fact-position.first-core-fact-offset": [512, 5, 2048, 4, 8192, 2, 32768, 1],
123
152
  /**
@@ -258,7 +287,7 @@ var BANDS = [
258
287
  }
259
288
  ];
260
289
  var DEFAULT_RULESET = deepFreeze({
261
- version: "0.1.0",
290
+ version: "0.2.0",
262
291
  weights: WEIGHTS,
263
292
  thresholds: THRESHOLDS,
264
293
  audienceTokens: AUDIENCE_TOKENS,
@@ -362,6 +391,33 @@ function pathMatches(pattern, path) {
362
391
  return true;
363
392
  }
364
393
 
394
+ // src/robots-policy.ts
395
+ var ARS_ROBOTS_TOKEN = "rebilder-ars";
396
+ function robotsDisallowsScanner(robotsBody, path) {
397
+ const robots = parseRobots(robotsBody);
398
+ for (const group of robots.groups) {
399
+ if (!group.agents.some((agent) => agent.toLowerCase() === ARS_ROBOTS_TOKEN)) continue;
400
+ let best = null;
401
+ for (const value of group.allow) {
402
+ if (!pathMatches(value, path)) continue;
403
+ if (best === null || value.length > best.value.length) best = { field: "allow", value };
404
+ }
405
+ for (const value of group.disallow) {
406
+ if (!pathMatches(value, path)) continue;
407
+ if (best === null || value.length > best.value.length) best = { field: "disallow", value };
408
+ }
409
+ if (best !== null && best.field === "disallow") {
410
+ return `User-agent: ${ARS_ROBOTS_TOKEN} / Disallow: ${best.value}`;
411
+ }
412
+ }
413
+ return null;
414
+ }
415
+
416
+ // src/probe/headers.ts
417
+ var AGENT_ACCEPT = "text/markdown;q=1.0, text/html;q=0.8, text/plain;q=0.5, */*;q=0.1";
418
+ var BROWSER_ACCEPT = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
419
+ var ASSET_ACCEPT = "text/plain,*/*;q=0.5";
420
+
365
421
  // src/score.ts
366
422
  function idiv(numerator, denominator) {
367
423
  if (denominator === 0) return 0;
@@ -373,44 +429,50 @@ function deepFreeze2(value) {
373
429
  return Object.freeze(value);
374
430
  }
375
431
  deepFreeze2({
376
- /** D1.1, 8 = 4 + 2 + 2. */
377
- reachable: { status2xx: 4, withinRedirectLimit: 2, noAcceptConditionalRedirect: 2 },
378
- /** D1.2, 6 = 3 + 1 + 1 + 1. A disallowed assistant audience scores 0 for all four (§3.7). */
379
- robotsPolicy: { assistantAllowed: 3, parsesClean: 1, noOrphanRules: 1, sitemapDeclared: 1 },
432
+ /** D1.1, 11 = 5 + 3 + 3. */
433
+ reachable: { status2xx: 5, withinRedirectLimit: 3, noAcceptConditionalRedirect: 3 },
434
+ /** D1.2, 10 = 6 + 2 + 1 + 1. A disallowed assistant audience scores 0 for all four (§3.7). */
435
+ robotsPolicy: { assistantAllowed: 6, parsesClean: 2, noOrphanRules: 1, sitemapDeclared: 1 },
380
436
  /**
381
- * D1.3, 6. AT-LEAST band over `100 × coreFactsInHtml / coreProfileSize`, plus
437
+ * D1.3, 7. AT-LEAST band over `100 × coreFactsInHtml / coreProfileSize`, plus
382
438
  * the `<noscript>` floor: a page whose facts are all client-rendered but which
383
439
  * ships a non-empty `<noscript>` has told a JS-less caller something, and §3.8
384
440
  * says that earns partial credit.
385
441
  */
386
442
  renderIndependence: {
387
- band: [100, 6, 75, 5, 50, 3, 25, 1],
443
+ band: [100, 7, 75, 5, 50, 3, 25, 1],
388
444
  noscriptFloor: 1
389
445
  },
390
- /** D2.1, 10. All-or-nothing: a machine media type AND a body that is not HTML. */
391
- negotiatedResponse: { full: 10 },
392
- /** D2.2, 4. All-or-nothing. */
393
- declaredAlternates: { full: 4 },
446
+ /** D2.1, 9. All-or-nothing: a machine media type AND a body that is not HTML. */
447
+ negotiatedResponse: { full: 9 },
448
+ /** D2.2, 3. All-or-nothing. */
449
+ declaredAlternates: { full: 3 },
394
450
  /** D2.3, 3. All-or-nothing, and 0 unless D2.1 > 0. */
395
451
  varyAccept: { full: 3 },
396
452
  /** D2.4, 3. All-or-nothing, and 0 unless D2.1 > 0 and a browser capture exists. */
397
453
  substanceParity: { full: 3 },
398
- /** D5.1, 5. Structured data present AND parsing; a partly-broken graph scores 3. */
399
- structuredDataPresent: { clean: 5, partial: 3 },
400
- /** D5.2, 7 = 2 (a recognised type) + 5 (required-property completeness, scaled). */
401
- requiredProperties: { recognisedType: 2, completeness: 5 },
402
- /** D5.3, 3. All-or-nothing. */
403
- textAgreement: { full: 3 },
454
+ /** D5.1, 2. Structured data present AND parsing; a partly-broken graph scores 1. */
455
+ structuredDataPresent: { clean: 2, partial: 1 },
456
+ /** D5.2, 3 = 1 (a recognised type) + 2 (required-property completeness, scaled). */
457
+ requiredProperties: { recognisedType: 1, completeness: 2 },
458
+ /** D5.3, 1. All-or-nothing. */
459
+ textAgreement: { full: 1 },
404
460
  /** D6.1, 4 = 2 + 1 + 1. */
405
461
  canonical: { present: 2, absolute: 1, consistentAcrossProbes: 1 },
406
- /** D6.2, 3 = 2 + 1. */
407
- cacheValidators: { saneCacheControl: 2, validator: 1 },
408
- /** D6.3, 2. `present` alone for a file that exists; `specShaped` for one that parses as llms.txt. */
409
- llmsTxt: { present: 1, specShaped: 2 },
410
- /** D6.4, 2. All-or-nothing. */
411
- sitemap: { full: 2 },
412
- /** D6.5, 4. All-or-nothing over any ONE declared machine endpoint. */
413
- machineEndpoint: { full: 4 }
462
+ /** D6.2, 2 = 1 + 1. */
463
+ cacheValidators: { saneCacheControl: 1, validator: 1 },
464
+ /**
465
+ * D6.3, 1. `specShaped` — an H1 and at least one Markdown link — is the whole
466
+ * point. `present` is 0 in 0.2: at two points 0.1 could pay one for the file
467
+ * existing and one for it being usable, but at one point that split would make
468
+ * "exists" and "usable" score identically, which is a distinction the standard
469
+ * would then be printing a remedy for and paying nothing to fix.
470
+ */
471
+ llmsTxt: { present: 0, specShaped: 1 },
472
+ /** D6.4, 1. All-or-nothing. */
473
+ sitemap: { full: 1 },
474
+ /** D6.5, 2. All-or-nothing over any ONE declared machine endpoint. */
475
+ machineEndpoint: { full: 2 }
414
476
  });
415
477
  var SHA256_K = [
416
478
  1116352408,
@@ -534,7 +596,7 @@ function sha256Hex(message) {
534
596
  for (const word of h) hex += word.toString(16).padStart(8, "0");
535
597
  return hex;
536
598
  }
537
- sha256Hex("ars-0.1-corpus-unfrozen");
599
+ sha256Hex("ars-0.2-corpus-unfrozen");
538
600
  var ALLOW_PRIVATE_HOSTS = /* @__PURE__ */ Symbol("rebilder.ars.probe.allow-private-hosts");
539
601
  var allowsPrivateHosts = (policy) => policy === ALLOW_PRIVATE_HOSTS;
540
602
  var NOT_AN_IP = { family: null, reserved: false, label: "hostname" };
@@ -982,11 +1044,7 @@ function createLimiter(options = {}) {
982
1044
  }
983
1045
 
984
1046
  // src/probe/index.ts
985
- var ARS_USER_AGENT = "rebilder-ars/0.1 (+https://rebilder.com/bots)";
986
- var ARS_ROBOTS_TOKEN = "rebilder-ars";
987
- var AGENT_ACCEPT = "text/markdown;q=1.0, text/html;q=0.8, text/plain;q=0.5, */*;q=0.1";
988
- var BROWSER_ACCEPT = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
989
- var ASSET_ACCEPT = "text/plain,*/*;q=0.5";
1047
+ var ARS_USER_AGENT = "rebilder-ars/0.2 (+https://rebilder.com/bots)";
990
1048
  var AGENT_IDENTITY = {
991
1049
  role: "agent",
992
1050
  userAgent: ARS_USER_AGENT,
@@ -1221,25 +1279,6 @@ async function fetchWithPolicy(startUrl, headers, context) {
1221
1279
  }
1222
1280
  return failed("too-many-redirects", `More than ${policy.maxRedirects - 1} redirects.`);
1223
1281
  }
1224
- function scannerDisallows(robotsBody, path) {
1225
- const robots = parseRobots(robotsBody);
1226
- for (const group of robots.groups) {
1227
- if (!group.agents.some((agent) => agent.toLowerCase() === ARS_ROBOTS_TOKEN)) continue;
1228
- let best = null;
1229
- for (const value of group.allow) {
1230
- if (!pathMatches(value, path)) continue;
1231
- if (best === null || value.length > best.value.length) best = { field: "allow", value };
1232
- }
1233
- for (const value of group.disallow) {
1234
- if (!pathMatches(value, path)) continue;
1235
- if (best === null || value.length > best.value.length) best = { field: "disallow", value };
1236
- }
1237
- if (best !== null && best.field === "disallow") {
1238
- return `User-agent: ${ARS_ROBOTS_TOKEN} / Disallow: ${best.value}`;
1239
- }
1240
- }
1241
- return null;
1242
- }
1243
1282
  function headersFor(identity) {
1244
1283
  return { accept: identity.accept, "user-agent": identity.userAgent };
1245
1284
  }
@@ -1330,7 +1369,7 @@ async function probeWithHostPolicy(target, policy, hostPolicy, options = {}) {
1330
1369
  }
1331
1370
  const robotsBody = robotsTxt.result.ok ? robotsTxt.result.capture.body ?? "" : "";
1332
1371
  const robotsUsable = robotsTxt.result.ok && robotsTxt.result.capture.status < 400;
1333
- const disallowedFor = (path) => vantage === "public" && robotsUsable ? scannerDisallows(robotsBody, path) : null;
1372
+ const disallowedFor = (path) => vantage === "public" && robotsUsable ? robotsDisallowsScanner(robotsBody, path) : null;
1334
1373
  const pageRule = disallowedFor(url.pathname);
1335
1374
  if (pageRule !== null) {
1336
1375
  const detail = `robots.txt disallows the ${ARS_ROBOTS_TOKEN} token (${pageRule})`;