rebilder 0.1.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/dist/index.cjs ADDED
@@ -0,0 +1,1649 @@
1
+ 'use strict';
2
+
3
+ var util = require('util');
4
+ var agentReadability = require('@rebilder/agent-readability');
5
+ var promises = require('fs/promises');
6
+ var path = require('path');
7
+ var probe = require('@rebilder/agent-readability/probe');
8
+
9
+ // src/args.ts
10
+
11
+ // src/exit.ts
12
+ var EXIT = {
13
+ /** Completed; threshold met, or no threshold set. */
14
+ OK: 0,
15
+ /** Completed; threshold NOT met. Only ever produced by a real score. */
16
+ THRESHOLD: 1,
17
+ /** Usage error — unknown flag, bad value, missing argument, unparseable URL. */
18
+ USAGE: 2,
19
+ /** Probe failed / target unreachable. INFRASTRUCTURE, not a score failure. */
20
+ PROBE: 3,
21
+ /** Blocked by policy — SSRF guard, robots opt-out, exhausted probe budget. */
22
+ POLICY: 4
23
+ };
24
+ var SEVERITY = [EXIT.USAGE, EXIT.POLICY, EXIT.PROBE, EXIT.THRESHOLD, EXIT.OK];
25
+ function worstExit(codes) {
26
+ for (const candidate of SEVERITY) {
27
+ if (codes.includes(candidate)) return candidate;
28
+ }
29
+ return EXIT.OK;
30
+ }
31
+ var UsageError = class extends Error {
32
+ constructor(message) {
33
+ super(message);
34
+ this.name = "UsageError";
35
+ }
36
+ };
37
+
38
+ // src/args.ts
39
+ var FORMATS = ["pretty", "json", "markdown", "junit"];
40
+ var GRADES = ["A", "B", "C", "D", "F"];
41
+ var COMMANDS = ["check", "diff", "init", "badge"];
42
+ var OPTIONS = {
43
+ format: { type: "string" },
44
+ "fail-on": { type: "string" },
45
+ out: { type: "string" },
46
+ "allow-private": { type: "boolean" },
47
+ "allow-http": { type: "boolean" },
48
+ concurrency: { type: "string" },
49
+ framework: { type: "string" },
50
+ help: { type: "boolean", short: "h" },
51
+ version: { type: "boolean", short: "v" }
52
+ };
53
+ function asFormat(value, fallback) {
54
+ if (value === void 0) return fallback;
55
+ const match = FORMATS.find((format) => format === value);
56
+ if (match === void 0) {
57
+ throw new UsageError(`--format must be one of ${FORMATS.join(", ")} (received "${value}")`);
58
+ }
59
+ return match;
60
+ }
61
+ function asGrade(value) {
62
+ if (value === void 0) return null;
63
+ const upper = value.toUpperCase();
64
+ const match = GRADES.find((grade) => grade === upper);
65
+ if (match === void 0) {
66
+ throw new UsageError(`--fail-on must be one of ${GRADES.join(", ")} (received "${value}")`);
67
+ }
68
+ return match;
69
+ }
70
+ var MAX_CONCURRENCY = 8;
71
+ function asConcurrency(value) {
72
+ if (value === void 0) return 1;
73
+ if (!/^[0-9]+$/.test(value)) {
74
+ throw new UsageError(`--concurrency must be a positive integer (received "${value}")`);
75
+ }
76
+ const parsed = Number.parseInt(value, 10);
77
+ if (parsed < 1) throw new UsageError("--concurrency must be at least 1");
78
+ if (parsed > MAX_CONCURRENCY) {
79
+ throw new UsageError(
80
+ `--concurrency is capped at ${MAX_CONCURRENCY}; the probe's politeness limiter allows at most 2 in-flight requests globally in any case`
81
+ );
82
+ }
83
+ return parsed;
84
+ }
85
+ var LABEL_CHARS = /^[a-z0-9-]+$/;
86
+ function isLabel(label) {
87
+ if (label.length < 1 || label.length > 63) return false;
88
+ if (label.startsWith("-") || label.endsWith("-")) return false;
89
+ return LABEL_CHARS.test(label);
90
+ }
91
+ function isDomain(value) {
92
+ if (value.length === 0 || value.length > 253) return false;
93
+ const labels = value.split(".");
94
+ if (labels.length < 2) return false;
95
+ return labels.every(isLabel);
96
+ }
97
+ function normalizeDomain(input) {
98
+ let value = input.trim().toLowerCase();
99
+ if (value.includes("://")) {
100
+ try {
101
+ value = new URL(value).hostname;
102
+ } catch {
103
+ throw new UsageError(`"${input}" is not a domain`);
104
+ }
105
+ }
106
+ value = value.replace(/\/.*$/, "").replace(/\.$/, "");
107
+ if (!isDomain(value)) {
108
+ throw new UsageError(
109
+ `"${input}" is not a domain. Pass a registrable hostname such as example.com \u2014 not a URL, not a path.`
110
+ );
111
+ }
112
+ return value;
113
+ }
114
+ function parseCommandLine(argv) {
115
+ let parsed;
116
+ try {
117
+ parsed = util.parseArgs({
118
+ args: [...argv],
119
+ options: OPTIONS,
120
+ allowPositionals: true,
121
+ strict: true
122
+ });
123
+ } catch (error) {
124
+ throw new UsageError(error instanceof Error ? error.message : String(error));
125
+ }
126
+ const { values, positionals } = parsed;
127
+ const [first, ...rest] = positionals;
128
+ if (values.version === true) return { kind: "version" };
129
+ if (values.help === true || first === void 0 || first === "help") {
130
+ const topicCandidate = first === "help" ? rest[0] : first;
131
+ const topic = COMMANDS.find((name2) => name2 === topicCandidate) ?? null;
132
+ if (first === "help" && rest[0] !== void 0 && topic === null) {
133
+ throw new UsageError(`unknown command "${rest[0]}". Expected one of ${COMMANDS.join(", ")}.`);
134
+ }
135
+ return { kind: "help", topic };
136
+ }
137
+ const name = COMMANDS.find((command) => command === first);
138
+ if (name === void 0) {
139
+ throw new UsageError(`unknown command "${first}". Expected one of ${COMMANDS.join(", ")}.`);
140
+ }
141
+ const out = values.out ?? null;
142
+ const allowPrivate = values["allow-private"] === true;
143
+ const allowHttp = values["allow-http"] === true || allowPrivate;
144
+ switch (name) {
145
+ case "check": {
146
+ if (rest.length === 0) {
147
+ throw new UsageError("check needs at least one URL. Usage: rebilder check <url...>");
148
+ }
149
+ return {
150
+ kind: "command",
151
+ command: {
152
+ name: "check",
153
+ urls: rest,
154
+ format: asFormat(values.format, "pretty"),
155
+ failOn: asGrade(values["fail-on"]),
156
+ out,
157
+ allowPrivate,
158
+ allowHttp,
159
+ concurrency: asConcurrency(values.concurrency)
160
+ }
161
+ };
162
+ }
163
+ case "diff": {
164
+ if (rest.length === 0) throw new UsageError("diff needs a URL. Usage: rebilder diff <url>");
165
+ if (rest.length > 1) {
166
+ throw new UsageError(
167
+ "diff takes exactly one URL. It is a two-representation comparison of a single page; use `check` for a set."
168
+ );
169
+ }
170
+ if (values["fail-on"] !== void 0) {
171
+ throw new UsageError(
172
+ "--fail-on is not supported by `diff`. diff reports what the two representations contain; it does not grade. Use `rebilder check --fail-on`."
173
+ );
174
+ }
175
+ const url = rest[0];
176
+ if (url === void 0) throw new UsageError("diff needs a URL. Usage: rebilder diff <url>");
177
+ return {
178
+ kind: "command",
179
+ command: {
180
+ name: "diff",
181
+ url,
182
+ format: asFormat(values.format, "pretty"),
183
+ out,
184
+ allowPrivate,
185
+ allowHttp
186
+ }
187
+ };
188
+ }
189
+ case "init": {
190
+ if (rest.length > 0) {
191
+ throw new UsageError(
192
+ `init takes no positional arguments (received "${rest[0]}"). Use --framework to override detection.`
193
+ );
194
+ }
195
+ return {
196
+ kind: "command",
197
+ command: {
198
+ name: "init",
199
+ framework: values.framework ?? null,
200
+ out,
201
+ format: asFormat(values.format, "pretty")
202
+ }
203
+ };
204
+ }
205
+ case "badge": {
206
+ if (rest.length === 0) {
207
+ throw new UsageError("badge needs a domain. Usage: rebilder badge <domain>");
208
+ }
209
+ if (rest.length > 1) throw new UsageError("badge takes exactly one domain.");
210
+ const domain = rest[0];
211
+ if (domain === void 0) throw new UsageError("badge needs a domain.");
212
+ return {
213
+ kind: "command",
214
+ command: {
215
+ name: "badge",
216
+ domain: normalizeDomain(domain),
217
+ format: asFormat(values.format, "pretty"),
218
+ out
219
+ }
220
+ };
221
+ }
222
+ }
223
+ }
224
+
225
+ // src/commands/badge.ts
226
+ var BADGE_ORIGIN = "https://rebilder.com";
227
+ function runBadge(command) {
228
+ const { domain } = command;
229
+ const svgUrl = `${BADGE_ORIGIN}/badge/${domain}.svg`;
230
+ const pageUrl = `${BADGE_ORIGIN}/readable/${domain}`;
231
+ const alt = `Agent Readability Score for ${domain}`;
232
+ return {
233
+ domain,
234
+ svgUrl,
235
+ pageUrl,
236
+ markdown: `[![${alt}](${svgUrl})](${pageUrl})`,
237
+ html: `<a href="${pageUrl}"><img src="${svgUrl}" alt="${alt}" height="20"></a>`,
238
+ notes: [
239
+ "A grade renders only for a verified opted-in domain. Every other domain gets a neutral \u201Cnot rated\u201D badge, served at 200 so it never shows as a broken image.",
240
+ "Verify by publishing a DNS TXT record `rebilder-verify=<token>`, or by serving `X-Rebilder-Path` from your origin where we can observe it.",
241
+ "The badge is served live from our data: you capture nothing and freeze nothing. It degrades to \u201Cunverified\u201D after 30 days without a successful re-scan.",
242
+ "It always names its subject (`example.com \xB7 A \xB7 94 \xB7 Mar 2026`) and it shows the ruleset hash alongside the spec version \u2014 two scores from different rulesets must not render identically.",
243
+ "No score ever comes from the query string. Removal from the index is free, self-serve, permanent, and never purchasable.",
244
+ "This command makes no network request. It builds the snippet locally, so we never learn which domain you asked about."
245
+ ]
246
+ };
247
+ }
248
+ async function runCheck(command, probe) {
249
+ return mapWithConcurrency(command.urls, command.concurrency, (url) => probeOne(url, probe));
250
+ }
251
+ async function probeOne(url, probe) {
252
+ const outcome = await probe(url);
253
+ if (!outcome.ok) {
254
+ return { kind: "rejected", url, rejection: outcome.rejection, detail: outcome.detail };
255
+ }
256
+ return { kind: "probed", url, result: agentReadability.score(outcome.evidence) };
257
+ }
258
+ async function mapWithConcurrency(items, concurrency, worker) {
259
+ const results = new Array(items.length);
260
+ let next = 0;
261
+ const lanes = Array.from(
262
+ { length: Math.min(Math.max(1, concurrency), items.length) },
263
+ async () => {
264
+ for (; ; ) {
265
+ const index = next++;
266
+ if (index >= items.length) return;
267
+ const item = items[index];
268
+ if (item === void 0) return;
269
+ results[index] = await worker(item, index);
270
+ }
271
+ }
272
+ );
273
+ await Promise.all(lanes);
274
+ return results;
275
+ }
276
+ var PARITY_CHECK_ID = "machine-representation.substance-parity";
277
+ async function runDiff(command, probe) {
278
+ const outcome = await probe(command.url);
279
+ if (!outcome.ok) {
280
+ const report2 = {
281
+ kind: "rejected",
282
+ url: command.url,
283
+ rejection: outcome.rejection,
284
+ detail: outcome.detail
285
+ };
286
+ return { url: command.url, agent: null, browser: null, parity: null, result: null, report: report2 };
287
+ }
288
+ const result = agentReadability.score(outcome.evidence);
289
+ const report = { kind: "probed", url: command.url, result };
290
+ return {
291
+ url: command.url,
292
+ agent: sideOf(outcome.evidence, "agent"),
293
+ browser: sideOf(outcome.evidence, "browser"),
294
+ parity: parityCheck(result),
295
+ result,
296
+ report
297
+ };
298
+ }
299
+ function parityCheck(result) {
300
+ for (const dimension of result.dimensions) {
301
+ for (const check of dimension.checks) {
302
+ if (check.id === PARITY_CHECK_ID) return check;
303
+ }
304
+ }
305
+ return null;
306
+ }
307
+ function sideOf(evidence, role) {
308
+ const record = evidence.probes[role];
309
+ const accept = record.requestHeaders["accept"] ?? "(none)";
310
+ if (!record.result.ok) {
311
+ return {
312
+ role,
313
+ accept,
314
+ status: null,
315
+ contentType: null,
316
+ bytes: null,
317
+ approxTokens: null,
318
+ truncated: false,
319
+ redirects: 0,
320
+ error: `${record.result.error}${record.result.detail === void 0 ? "" : `: ${record.result.detail}`}`
321
+ };
322
+ }
323
+ const capture = record.result.capture;
324
+ return {
325
+ role,
326
+ accept,
327
+ status: capture.status,
328
+ contentType: capture.headers["content-type"]?.[0] ?? null,
329
+ bytes: capture.bytes,
330
+ approxTokens: approxTokensOf(capture),
331
+ truncated: capture.truncated,
332
+ redirects: capture.redirects.length,
333
+ error: null
334
+ };
335
+ }
336
+ function approxTokensOf(capture) {
337
+ const characters = capture.body?.length ?? capture.bytes;
338
+ return Math.round(characters / 4);
339
+ }
340
+
341
+ // src/commands/init.ts
342
+ var FRAMEWORKS = ["next", "node", "edge", "shopify"];
343
+ var MARKER_FILES = [
344
+ {
345
+ file: "shopify.app.toml",
346
+ framework: "shopify",
347
+ reason: "shopify.app.toml in the working directory"
348
+ },
349
+ { file: "next.config.ts", framework: "next", reason: "next.config.ts in the working directory" },
350
+ {
351
+ file: "next.config.mjs",
352
+ framework: "next",
353
+ reason: "next.config.mjs in the working directory"
354
+ },
355
+ { file: "next.config.js", framework: "next", reason: "next.config.js in the working directory" },
356
+ { file: "wrangler.toml", framework: "edge", reason: "wrangler.toml in the working directory" },
357
+ { file: "wrangler.jsonc", framework: "edge", reason: "wrangler.jsonc in the working directory" }
358
+ ];
359
+ var DEPENDENCY_MARKERS = [
360
+ { dependency: "@shopify/shopify-app-remix", framework: "shopify" },
361
+ { dependency: "@shopify/shopify-api", framework: "shopify" },
362
+ { dependency: "next", framework: "next" },
363
+ { dependency: "@cloudflare/workers-types", framework: "edge" },
364
+ { dependency: "wrangler", framework: "edge" },
365
+ { dependency: "hono", framework: "edge" },
366
+ { dependency: "express", framework: "node" },
367
+ { dependency: "fastify", framework: "node" }
368
+ ];
369
+ async function detectFramework(runtime) {
370
+ for (const marker of MARKER_FILES) {
371
+ if (await runtime.readFile(marker.file) !== null) {
372
+ return { framework: marker.framework, reason: `detected from ${marker.reason}` };
373
+ }
374
+ }
375
+ const manifest = await runtime.readFile("package.json");
376
+ if (manifest !== null) {
377
+ let dependencies = {};
378
+ try {
379
+ const parsed = JSON.parse(manifest);
380
+ if (typeof parsed === "object" && parsed !== null) {
381
+ const record = parsed;
382
+ dependencies = {
383
+ ...asRecord(record["dependencies"]),
384
+ ...asRecord(record["devDependencies"])
385
+ };
386
+ }
387
+ } catch {
388
+ dependencies = {};
389
+ }
390
+ for (const marker of DEPENDENCY_MARKERS) {
391
+ if (marker.dependency in dependencies) {
392
+ return {
393
+ framework: marker.framework,
394
+ reason: `detected from "${marker.dependency}" in package.json`
395
+ };
396
+ }
397
+ }
398
+ }
399
+ return {
400
+ framework: "node",
401
+ reason: "no framework marker found \u2014 defaulting to the Node adapter. Pass --framework next|node|edge|shopify to choose."
402
+ };
403
+ }
404
+ function asRecord(value) {
405
+ return typeof value === "object" && value !== null ? value : {};
406
+ }
407
+ async function runInit(command, runtime) {
408
+ let framework;
409
+ let detection;
410
+ if (command.framework !== null) {
411
+ const match = FRAMEWORKS.find((name) => name === command.framework);
412
+ if (match === void 0) {
413
+ throw new UsageError(
414
+ `--framework must be one of ${FRAMEWORKS.join(", ")} (received "${command.framework}")`
415
+ );
416
+ }
417
+ framework = match;
418
+ detection = "chosen with --framework";
419
+ } else {
420
+ const detected = await detectFramework(runtime);
421
+ framework = detected.framework;
422
+ detection = detected.reason;
423
+ }
424
+ return { ...SCAFFOLDS[framework], framework, detection };
425
+ }
426
+ var SHARED_NOTES = [
427
+ "The resolvers return your source of truth. Every substantive value \u2014 price, stock, hours, policy text \u2014 comes from these fields; the gateway never invents one.",
428
+ "The gateway has no concept of a plan, licence, tier or quota, and never will. Free-tier cost control happens at ingest, never at the edge.",
429
+ "Run `rebilder check <url>` before and after to see what changed. Content negotiation is D2.1 (10 points) and unlocks D2.3 and D2.4."
430
+ ];
431
+ var CONFIG_BODY = `import type { GatewayConfig } from '@rebilder/gateway'
432
+
433
+ /**
434
+ * Wiring to YOUR source of truth. Each resolver takes a URL and returns the
435
+ * fields for that page, or null to fall through to your normal HTML.
436
+ *
437
+ * Resolvers run on the request hot path: p95 < 50ms of compute, and no network
438
+ * call except a cache. Anything slower belongs in a build step.
439
+ */
440
+ export const gatewayConfig: GatewayConfig = {
441
+ storeId: 'TODO-your-store-id',
442
+ sources: {
443
+ // TODO: return your product fields, or null when the URL is not a PDP.
444
+ product: async (url) => {
445
+ void url
446
+ return null
447
+ },
448
+ // TODO: policies, catalog, document, collection \u2014 add the ones you have.
449
+ },
450
+ // Optional: emit @rebilder/events RebilderEventV0 into your observation layer.
451
+ // onEvent: (event) => { void event },
452
+ }
453
+ `;
454
+ var SCAFFOLDS = {
455
+ next: {
456
+ suggestedPath: "lib/gateway-config.ts",
457
+ language: "ts",
458
+ notes: [
459
+ "Then add the proxy: `const gateway = createGatewayProxy(gatewayConfig)` in proxy.ts (Next 16) or middleware.ts (Next 15 and earlier), returning `(await gateway(req)) ?? NextResponse.next()`.",
460
+ ...SHARED_NOTES
461
+ ],
462
+ contents: `${CONFIG_BODY}
463
+ /* \u2500\u2500 proxy.ts (Next 16) or middleware.ts (Next \u226415) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
464
+ //
465
+ // import { NextResponse } from 'next/server'
466
+ // import { createGatewayProxy } from '@rebilder/gateway/next'
467
+ // import { gatewayConfig } from './lib/gateway-config'
468
+ //
469
+ // const gateway = createGatewayProxy(gatewayConfig)
470
+ //
471
+ // export default async function proxy(req: Request) {
472
+ // return (await gateway(req)) ?? NextResponse.next()
473
+ // }
474
+ `
475
+ },
476
+ node: {
477
+ suggestedPath: "gateway-config.ts",
478
+ language: "ts",
479
+ notes: [
480
+ "Then mount it before your routes: `app.use(createGatewayMiddleware(gatewayConfig))`.",
481
+ ...SHARED_NOTES
482
+ ],
483
+ contents: `${CONFIG_BODY}
484
+ /* \u2500\u2500 Express \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
485
+ //
486
+ // import express from 'express'
487
+ // import { createGatewayMiddleware } from '@rebilder/gateway/node'
488
+ // import { gatewayConfig } from './gateway-config'
489
+ //
490
+ // const app = express()
491
+ // app.use(createGatewayMiddleware(gatewayConfig)) // before your routes
492
+ `
493
+ },
494
+ edge: {
495
+ suggestedPath: "gateway-config.ts",
496
+ language: "ts",
497
+ notes: [
498
+ "Then export the fetch handler: `export default { fetch: createGatewayFetchHandler(gatewayConfig) }`.",
499
+ "On a route-mounted Worker, non-markdown requests pass through to your origin unchanged, so browsers and crawlers keep receiving the canonical HTML.",
500
+ ...SHARED_NOTES
501
+ ],
502
+ contents: `${CONFIG_BODY}
503
+ /* \u2500\u2500 worker.ts (Cloudflare Workers, Vercel Edge, Deno Deploy) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
504
+ //
505
+ // import { createGatewayFetchHandler } from '@rebilder/gateway/edge'
506
+ // import { gatewayConfig } from './gateway-config'
507
+ //
508
+ // export default { fetch: createGatewayFetchHandler(gatewayConfig) }
509
+ `
510
+ },
511
+ shopify: {
512
+ suggestedPath: "app/gateway-config.ts",
513
+ language: "ts",
514
+ notes: [
515
+ "Then mount the app-proxy handler and give it your app\u2019s shared secret; requests are signature-verified before anything is rendered.",
516
+ ...SHARED_NOTES
517
+ ],
518
+ contents: `${CONFIG_BODY}
519
+ /* \u2500\u2500 Shopify app proxy \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
520
+ //
521
+ // import { createShopifyAppProxyHandler } from '@rebilder/gateway/shopify'
522
+ // import { gatewayConfig } from './gateway-config'
523
+ //
524
+ // export const loader = createShopifyAppProxyHandler(gatewayConfig, {
525
+ // sharedSecret: process.env.SHOPIFY_API_SECRET ?? '',
526
+ // })
527
+ `
528
+ }
529
+ };
530
+
531
+ // src/disclosure.ts
532
+ var ARS_NOTICE_LINES = [
533
+ "ARS measures format and retrievability. It does not measure whether the",
534
+ "facts are true, or whether any assistant cites this page."
535
+ ];
536
+ var ARS_NOTICE = ARS_NOTICE_LINES.join(" ");
537
+ var CONFLICT_OF_INTEREST_LINES = [
538
+ "ARS is authored by Rebilder, which sells content-negotiation middleware.",
539
+ "Two ARS checks (D2.1 content negotiation, D5 structured data) can be",
540
+ "satisfied by Rebilder\u2019s free gateway, and reaching an A requires both.",
541
+ "The full ruleset, thresholds, and conformance corpus are published so this",
542
+ "bias is auditable rather than hidden."
543
+ ];
544
+ var CONFLICT_OF_INTEREST = CONFLICT_OF_INTEREST_LINES.join(" ");
545
+ var TELEMETRY_LINES = [
546
+ "This CLI ships zero telemetry. It never uploads a scan, a URL, a hostname,",
547
+ "or a result. The only requests it makes are to the target you name."
548
+ ];
549
+
550
+ // src/report.ts
551
+ var ORDER = GRADES;
552
+ function meetsThreshold(grade, failOn) {
553
+ return ORDER.indexOf(grade) <= ORDER.indexOf(failOn);
554
+ }
555
+ function exitCodeFor(report, failOn) {
556
+ if (report.kind === "rejected") {
557
+ switch (report.rejection) {
558
+ case "invalid-url":
559
+ return EXIT.USAGE;
560
+ case "policy-rejected":
561
+ case "budget-exceeded":
562
+ return EXIT.POLICY;
563
+ }
564
+ }
565
+ const { outcome } = report.result;
566
+ switch (outcome.kind) {
567
+ case "opt-out":
568
+ return EXIT.POLICY;
569
+ case "unscored":
570
+ return outcome.reason === "robots-disallow-scanner" ? EXIT.POLICY : EXIT.PROBE;
571
+ case "scored":
572
+ if (failOn === null) return EXIT.OK;
573
+ return meetsThreshold(outcome.grade, failOn) ? EXIT.OK : EXIT.THRESHOLD;
574
+ }
575
+ }
576
+ var UNSCORED_TEXT = {
577
+ "blocked-at-edge": "blocked at the edge (403 or challenge) \u2014 the block is itself the finding",
578
+ unreachable: "unreachable",
579
+ "non-2xx": "the agent path did not return 2xx",
580
+ "too-many-redirects": "too many redirects",
581
+ "robots-disallow-scanner": "robots.txt disallows rebilder-ars \u2014 we obeyed it and did not score",
582
+ "robots-unavailable": "robots.txt returned a persistent error; a policy we cannot read is not a policy we may assume",
583
+ "truncated-evidence": "the response exceeded the 2 MiB body cap and the evidence is incomplete",
584
+ "evidence-incomplete": "the evidence bundle is incomplete"
585
+ };
586
+ var REJECTION_TEXT = {
587
+ "invalid-url": "not a URL",
588
+ "policy-rejected": "refused by the URL guard",
589
+ "budget-exceeded": "the probe budget for this run is spent"
590
+ };
591
+ function outcomeSummary(report) {
592
+ if (report.kind === "rejected") {
593
+ return `${REJECTION_TEXT[report.rejection]}: ${report.detail}`;
594
+ }
595
+ const { outcome } = report.result;
596
+ switch (outcome.kind) {
597
+ case "scored":
598
+ return `${outcome.score}/100 ${outcome.grade}`;
599
+ case "opt-out":
600
+ return `OPT-OUT \u2014 a deliberate, well-formed robots disallow for the ${outcome.audience} audience. Not a failure and not a grade.`;
601
+ case "unscored":
602
+ return `UNSCORED \u2014 ${UNSCORED_TEXT[outcome.reason] ?? outcome.reason}${outcome.detail === void 0 ? "" : ` (${outcome.detail})`}`;
603
+ }
604
+ }
605
+ function statusOf(report) {
606
+ return report.kind === "rejected" ? "rejected" : report.result.outcome.kind;
607
+ }
608
+
609
+ // src/format/json.ts
610
+ function renderJson(payload, ctx) {
611
+ return JSON.stringify(jsonValue(payload, ctx), null, 2) + "\n";
612
+ }
613
+ function jsonValue(payload, ctx) {
614
+ const envelope = {
615
+ tool: "rebilder",
616
+ toolVersion: ctx.cliVersion,
617
+ generatedAt: ctx.generatedAt,
618
+ notice: ARS_NOTICE
619
+ };
620
+ switch (payload.command) {
621
+ case "check":
622
+ return {
623
+ ...envelope,
624
+ command: "check",
625
+ failOn: payload.failOn,
626
+ results: payload.reports.map((report) => ({
627
+ url: report.url,
628
+ status: statusOf(report),
629
+ summary: outcomeSummary(report),
630
+ exitCode: exitCodeFor(report, payload.failOn),
631
+ ...report.kind === "rejected" ? { rejection: report.rejection, detail: report.detail, result: null } : { rejection: null, detail: null, result: report.result }
632
+ }))
633
+ };
634
+ case "diff":
635
+ return {
636
+ ...envelope,
637
+ command: "diff",
638
+ url: payload.diff.url,
639
+ status: statusOf(payload.diff.report),
640
+ agent: payload.diff.agent,
641
+ browser: payload.diff.browser,
642
+ substanceParity: payload.diff.parity,
643
+ result: payload.diff.result
644
+ };
645
+ case "init":
646
+ return { ...envelope, command: "init", scaffold: payload.scaffold };
647
+ case "badge":
648
+ return { ...envelope, command: "badge", badge: payload.badge };
649
+ }
650
+ }
651
+
652
+ // src/format/shared.ts
653
+ function absent(unicode) {
654
+ return unicode ? "\u2014" : "-";
655
+ }
656
+ function basisLabel(basis) {
657
+ return basis === "heuristic" ? "heuristic" : "measured";
658
+ }
659
+ function bytesText(bytes, truncated, unicode) {
660
+ if (bytes === null) return absent(unicode);
661
+ const formatted = `${bytes.toLocaleString("en-US")} B`;
662
+ if (!truncated) return formatted;
663
+ return `${unicode ? "\u2265" : ">="} ${formatted} (truncated at the 2 MiB cap)`;
664
+ }
665
+ function approxTokens(tokens, unicode) {
666
+ if (tokens === null) return absent(unicode);
667
+ return `${unicode ? "\u2248" : "~"}${tokens.toLocaleString("en-US")} tokens (est.)`;
668
+ }
669
+ function percent(numerator, denominator) {
670
+ if (denominator === 0) return "0%";
671
+ return `${Math.round(numerator * 100 / denominator)}%`;
672
+ }
673
+ function checkMark(check, unicode) {
674
+ if (check.earned >= check.weight) return unicode ? "\u2714" : "+";
675
+ if (check.earned > 0) return unicode ? "\u25D0" : "~";
676
+ return unicode ? "\u2718" : "x";
677
+ }
678
+ function shortHash(hash) {
679
+ return hash.slice(0, 12);
680
+ }
681
+ function escapeXml(text2) {
682
+ return text2.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;").replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g, "");
683
+ }
684
+ function escapeCell(text2) {
685
+ return text2.replace(/\|/g, "\\|").replace(/\r?\n/g, " ");
686
+ }
687
+
688
+ // src/format/junit.ts
689
+ var SUITE_NAME = "rebilder.ars";
690
+ function renderJunit(payload, ctx) {
691
+ const suites = [];
692
+ let tests = 0;
693
+ let failures = 0;
694
+ let errors = 0;
695
+ if (payload.command === "check") {
696
+ for (const report of payload.reports) {
697
+ const suite = checkSuite(report, payload.failOn, ctx);
698
+ suites.push(suite.xml);
699
+ tests += suite.tests;
700
+ failures += suite.failures;
701
+ errors += suite.errors;
702
+ }
703
+ } else if (payload.command === "diff") {
704
+ const suite = checkSuite(payload.diff.report, null, ctx);
705
+ suites.push(suite.xml);
706
+ tests += suite.tests;
707
+ failures += suite.failures;
708
+ errors += suite.errors;
709
+ } else {
710
+ suites.push(
711
+ ` <testsuite name="${SUITE_NAME}.${payload.command}" tests="0" failures="0" errors="0"/>`
712
+ );
713
+ }
714
+ return [
715
+ '<?xml version="1.0" encoding="UTF-8"?>',
716
+ `<testsuites name="${SUITE_NAME}" tests="${tests}" failures="${failures}" errors="${errors}">`,
717
+ ...suites,
718
+ "</testsuites>",
719
+ ""
720
+ ].join("\n");
721
+ }
722
+ function checkSuite(report, failOn, ctx) {
723
+ const cases = [];
724
+ let tests = 0;
725
+ let failures = 0;
726
+ let errors = 0;
727
+ const properties = [
728
+ ` <property name="notice" value="${escapeXml(ARS_NOTICE)}"/>`,
729
+ ` <property name="url" value="${escapeXml(report.url)}"/>`,
730
+ ` <property name="generatedAt" value="${escapeXml(ctx.generatedAt)}"/>`,
731
+ ` <property name="tool" value="rebilder ${escapeXml(ctx.cliVersion)}"/>`
732
+ ];
733
+ if (report.kind === "probed") {
734
+ const { result } = report;
735
+ properties.push(
736
+ ` <property name="specVersion" value="${escapeXml(result.specVersion)}"/>`,
737
+ ` <property name="rulesetHash" value="${escapeXml(result.rulesetHash)}"/>`,
738
+ ` <property name="corpusHash" value="${escapeXml(result.corpusHash)}"/>`,
739
+ ` <property name="evidenceHash" value="${escapeXml(result.evidenceHash)}"/>`,
740
+ ` <property name="measuredWeight" value="${result.measuredWeight}"/>`,
741
+ ` <property name="heuristicWeight" value="${result.heuristicWeight}"/>`
742
+ );
743
+ }
744
+ const status = statusOf(report);
745
+ if (report.kind === "rejected" || report.result.outcome.kind !== "scored") {
746
+ tests += 1;
747
+ errors += 1;
748
+ cases.push(
749
+ [
750
+ ` <testcase classname="${escapeXml(report.url)}" name="probe">`,
751
+ ` <error type="${escapeXml(status)}" message="${escapeXml(outcomeSummary(report))}"/>`,
752
+ " </testcase>"
753
+ ].join("\n")
754
+ );
755
+ } else {
756
+ const { result } = report;
757
+ for (const dimension of result.dimensions) {
758
+ for (const check of dimension.checks) {
759
+ tests += 1;
760
+ const passed = check.earned >= check.weight;
761
+ const name = `${check.id} [${basisLabel(check.basis)}] ${check.earned}/${check.weight}`;
762
+ if (passed) {
763
+ cases.push(
764
+ ` <testcase classname="${escapeXml(report.url)}" name="${escapeXml(name)}"/>`
765
+ );
766
+ continue;
767
+ }
768
+ failures += 1;
769
+ const detail = [
770
+ check.remedy ?? "",
771
+ ...check.evidence.map(
772
+ (item) => `${item.label}: ${item.value} [${basisLabel(item.basis)}]`
773
+ )
774
+ ].filter((line) => line.length > 0).join("\n");
775
+ cases.push(
776
+ [
777
+ ` <testcase classname="${escapeXml(report.url)}" name="${escapeXml(name)}">`,
778
+ ` <failure type="${escapeXml(check.basis)}" message="${escapeXml(`${check.label} earned ${check.earned} of ${check.weight}`)}">${escapeXml(detail)}</failure>`,
779
+ " </testcase>"
780
+ ].join("\n")
781
+ );
782
+ }
783
+ }
784
+ if (failOn !== null && result.grade !== null) {
785
+ tests += 1;
786
+ const met = meetsThreshold(result.grade, failOn);
787
+ const name = `threshold --fail-on ${failOn}`;
788
+ if (met) {
789
+ cases.push(` <testcase classname="${escapeXml(report.url)}" name="${escapeXml(name)}"/>`);
790
+ } else {
791
+ failures += 1;
792
+ cases.push(
793
+ [
794
+ ` <testcase classname="${escapeXml(report.url)}" name="${escapeXml(name)}">`,
795
+ ` <failure type="threshold" message="${escapeXml(`graded ${result.grade} (${result.score}/100); the threshold is ${failOn} or better`)}"/>`,
796
+ " </testcase>"
797
+ ].join("\n")
798
+ );
799
+ }
800
+ }
801
+ }
802
+ const exitCode = exitCodeFor(report, failOn);
803
+ properties.push(` <property name="exitCode" value="${exitCode}"/>`);
804
+ if (exitCode === EXIT.PROBE || exitCode === EXIT.POLICY) {
805
+ properties.push(
806
+ ` <property name="notAScoreFailure" value="${exitCode === EXIT.PROBE ? "probe failure \u2014 infrastructure" : "blocked by policy"}"/>`
807
+ );
808
+ }
809
+ const xml = [
810
+ ` <testsuite name="${escapeXml(report.url)}" tests="${tests}" failures="${failures}" errors="${errors}">`,
811
+ " <properties>",
812
+ ...properties,
813
+ " </properties>",
814
+ ...cases,
815
+ " </testsuite>"
816
+ ].join("\n");
817
+ return { xml, tests, failures, errors };
818
+ }
819
+
820
+ // src/format/markdown.ts
821
+ function renderMarkdown(payload, ctx) {
822
+ switch (payload.command) {
823
+ case "check":
824
+ return payload.reports.map((report) => checkSection(report)).join("\n---\n\n") + notice();
825
+ case "diff":
826
+ return diffSection(payload.diff) + notice();
827
+ case "init":
828
+ return initSection(payload, ctx);
829
+ case "badge":
830
+ return badgeSection(payload);
831
+ }
832
+ }
833
+ function notice() {
834
+ return `
835
+ ${ARS_NOTICE_LINES.map((line) => `> ${line}`).join("\n")}
836
+ `;
837
+ }
838
+ function checkSection(report) {
839
+ const out = [`## ${escapeCell(report.url)}`, ""];
840
+ if (report.kind === "rejected") {
841
+ out.push(`**REJECTED** \u2014 ${outcomeSummary(report)}`, "");
842
+ return out.join("\n");
843
+ }
844
+ const { result } = report;
845
+ if (statusOf(report) !== "scored") {
846
+ out.push(outcomeSummary(report), "");
847
+ out.push(policyLine(result), "");
848
+ out.push(identityLine(result), "");
849
+ return out.join("\n");
850
+ }
851
+ out.push(
852
+ `**${result.grade} \u2014 ${result.bandLabel}** \xB7 ${result.score}/100 \xB7 page kind \`${result.pageKind}\` (${result.pageKindConfidence} confidence, ${basisLabel(result.pageKindBasis)})`,
853
+ "",
854
+ `${result.measuredWeight} of the 100 points are measured; ${result.heuristicWeight} are heuristic.`,
855
+ "",
856
+ "| Check | Points | Basis |",
857
+ "| --- | ---: | --- |"
858
+ );
859
+ for (const dimension of result.dimensions) {
860
+ out.push(
861
+ `| **${escapeCell(dimension.label)}** | **${dimension.earned}/${dimension.weight}** | ${basisLabel(dimension.basis)} |`
862
+ );
863
+ for (const check of dimension.checks) {
864
+ out.push(
865
+ `| ${escapeCell(check.label)} | ${check.earned}/${check.weight} | ${basisLabel(check.basis)} |`
866
+ );
867
+ }
868
+ }
869
+ out.push("", "### What an agent pays", "");
870
+ out.push("| | Bytes | Tokens |", "| --- | --- | --- |");
871
+ out.push(
872
+ `| HTML | ${bytesText(result.cost.htmlBytes, result.cost.truncated, true)} | ${approxTokens(result.cost.approxHtmlTokens, true)} |`
873
+ );
874
+ out.push(
875
+ `| Negotiated | ${bytesText(result.cost.negotiatedBytes, result.cost.truncated, true)} | ${approxTokens(result.cost.approxNegotiatedTokens, true)} |`
876
+ );
877
+ if (result.cost.reductionRatio !== null) {
878
+ out.push(`| Reduction | ${result.cost.reductionRatio}% | |`);
879
+ }
880
+ if (result.flags.length > 0) {
881
+ out.push("", "### Flags", "");
882
+ for (const flag of result.flags) {
883
+ out.push(`- \`${flag.id}\` (${flag.severity}, ${basisLabel(flag.basis)}) \u2014 ${flag.message}`);
884
+ }
885
+ }
886
+ if (result.recommendations.length > 0) {
887
+ out.push("", "### Fixes, most points first", "");
888
+ out.push("| Points | Fix | Effort |", "| ---: | --- | --- |");
889
+ for (const recommendation of result.recommendations) {
890
+ out.push(
891
+ `| +${recommendation.pointsAvailable} | ${escapeCell(recommendation.title)} | ${recommendation.effort} |`
892
+ );
893
+ }
894
+ }
895
+ out.push("", policyLine(result), "", identityLine(result), "");
896
+ return out.join("\n");
897
+ }
898
+ function policyLine(result) {
899
+ const { policy } = result;
900
+ return `Policy: robots.txt ${policy.robotsTxtStatus} \xB7 assistant ${policy.audiences.assistant.decision} \xB7 training ${policy.audiences.training.decision} (neutral) \xB7 sitemap ${policy.sitemapDeclared ? "declared" : "not declared"}`;
901
+ }
902
+ function identityLine(result) {
903
+ return `ARS ${result.specVersion} \xB7 ruleset \`${shortHash(result.rulesetHash)}\` \xB7 corpus \`${shortHash(result.corpusHash)}\` \xB7 evidence \`${shortHash(result.evidenceHash)}\` \xB7 vantage ${result.vantage}`;
904
+ }
905
+ function diffSection(diff) {
906
+ const out = [`## ${escapeCell(diff.url)} \u2014 agent view vs browser view`, ""];
907
+ if (diff.report.kind === "rejected") {
908
+ out.push(`**REJECTED** \u2014 ${outcomeSummary(diff.report)}`, "");
909
+ return out.join("\n");
910
+ }
911
+ out.push(
912
+ "The two requests differ in the `Accept` header and in nothing else \u2014 same User-Agent, same everything.",
913
+ "",
914
+ "| | Agent | Browser |",
915
+ "| --- | --- | --- |",
916
+ `| Accept | \`${escapeCell(diff.agent?.accept ?? "\u2014")}\` | \`${escapeCell(diff.browser?.accept ?? "\u2014")}\` |`,
917
+ `| Status | ${diff.agent?.status ?? "\u2014"} | ${diff.browser?.status ?? "\u2014"} |`,
918
+ `| Content-Type | ${escapeCell(diff.agent?.contentType ?? "\u2014")} | ${escapeCell(diff.browser?.contentType ?? "\u2014")} |`,
919
+ `| Bytes | ${bytesText(diff.agent?.bytes ?? null, diff.agent?.truncated ?? false, true)} | ${bytesText(diff.browser?.bytes ?? null, diff.browser?.truncated ?? false, true)} |`,
920
+ `| Tokens | ${approxTokens(diff.agent?.approxTokens ?? null, true)} | ${approxTokens(diff.browser?.approxTokens ?? null, true)} |`,
921
+ `| Redirects | ${diff.agent?.redirects ?? "\u2014"} | ${diff.browser?.redirects ?? "\u2014"} |`
922
+ );
923
+ if (diff.parity !== null) {
924
+ out.push(
925
+ "",
926
+ `### Substance parity \u2014 ${diff.parity.earned}/${diff.parity.weight} (${basisLabel(diff.parity.basis)})`,
927
+ "",
928
+ "Compared on price, currency, availability and title only \u2014 never description or free text.",
929
+ ""
930
+ );
931
+ for (const evidence of diff.parity.evidence) {
932
+ out.push(
933
+ `- ${escapeCell(evidence.label)}: ${escapeCell(evidence.value)} (${basisLabel(evidence.basis)})`
934
+ );
935
+ }
936
+ }
937
+ if (diff.result !== null) out.push("", identityLine(diff.result), "");
938
+ return out.join("\n");
939
+ }
940
+ function initSection(payload, ctx) {
941
+ const { scaffold } = payload;
942
+ const out = [
943
+ `## Rebilder gateway scaffold \u2014 ${scaffold.framework}`,
944
+ "",
945
+ scaffold.detection,
946
+ "",
947
+ `Suggested path: \`${scaffold.suggestedPath}\``,
948
+ "",
949
+ "```" + scaffold.language,
950
+ scaffold.contents.trimEnd(),
951
+ "```",
952
+ ""
953
+ ];
954
+ for (const note of scaffold.notes) out.push(`- ${note}`);
955
+ out.push("", `<!-- generated by rebilder ${ctx.cliVersion} -->`, "");
956
+ return out.join("\n");
957
+ }
958
+ function badgeSection(payload) {
959
+ const { badge } = payload;
960
+ const out = [
961
+ `## Rebilder badge \u2014 ${badge.domain}`,
962
+ "",
963
+ "```markdown",
964
+ badge.markdown,
965
+ "```",
966
+ "",
967
+ "```html",
968
+ badge.html,
969
+ "```",
970
+ ""
971
+ ];
972
+ for (const note of badge.notes) out.push(`- ${note}`);
973
+ out.push("");
974
+ return out.join("\n");
975
+ }
976
+
977
+ // src/term.ts
978
+ var MIN_WIDTH = 40;
979
+ var MAX_WIDTH = 100;
980
+ function detectCapabilities(environment) {
981
+ const { env, isTty } = environment;
982
+ const noColor = env["NO_COLOR"] !== void 0;
983
+ const forceColor = env["FORCE_COLOR"] !== void 0 && env["FORCE_COLOR"] !== "0";
984
+ const dumbTerm = env["TERM"] === "dumb";
985
+ const color = !noColor && !dumbTerm && (forceColor || isTty);
986
+ const locale = `${env["LC_ALL"] ?? ""} ${env["LC_CTYPE"] ?? ""} ${env["LANG"] ?? ""}`;
987
+ const unicode = /utf-?8/i.test(locale);
988
+ const raw = environment.columns ?? 80;
989
+ const width = Math.max(MIN_WIDTH, Math.min(MAX_WIDTH, Number.isFinite(raw) ? raw : 80));
990
+ return { color, unicode, width };
991
+ }
992
+ var CODES = {
993
+ reset: 0,
994
+ bold: 1,
995
+ dim: 2,
996
+ red: 31,
997
+ green: 32,
998
+ yellow: 33,
999
+ blue: 34,
1000
+ magenta: 35,
1001
+ cyan: 36,
1002
+ gray: 90
1003
+ };
1004
+ function createPainter(enabled) {
1005
+ const paint = (text2, ...styles) => {
1006
+ if (!enabled || styles.length === 0) return text2;
1007
+ const open = styles.map((style) => `\x1B[${CODES[style]}m`).join("");
1008
+ return `${open}${text2}\x1B[${CODES.reset}m`;
1009
+ };
1010
+ return Object.assign(paint, { enabled });
1011
+ }
1012
+ var ANSI_RE = /\u001b\[[0-9;]*m/g;
1013
+ function visibleWidth(text2) {
1014
+ return [...text2.replace(ANSI_RE, "")].length;
1015
+ }
1016
+ function padEnd(text2, width) {
1017
+ const pad = width - visibleWidth(text2);
1018
+ return pad > 0 ? text2 + " ".repeat(pad) : text2;
1019
+ }
1020
+ function padStart(text2, width) {
1021
+ const pad = width - visibleWidth(text2);
1022
+ return pad > 0 ? " ".repeat(pad) + text2 : text2;
1023
+ }
1024
+ function truncate(text2, width, unicode) {
1025
+ if (visibleWidth(text2) <= width) return text2;
1026
+ const marker = unicode ? "\u2026" : "...";
1027
+ const budget = Math.max(0, width - marker.length);
1028
+ let out = "";
1029
+ let used = 0;
1030
+ for (const codePoint of text2) {
1031
+ if (used + 1 > budget) break;
1032
+ out += codePoint;
1033
+ used += 1;
1034
+ }
1035
+ return out + marker;
1036
+ }
1037
+ var UNICODE_GLYPHS = {
1038
+ horizontal: "\u2500",
1039
+ vertical: "\u2502",
1040
+ topLeft: "\u250C",
1041
+ topRight: "\u2510",
1042
+ bottomLeft: "\u2514",
1043
+ bottomRight: "\u2518",
1044
+ teeLeft: "\u251C",
1045
+ teeRight: "\u2524",
1046
+ bullet: "\u2022",
1047
+ check: "\u2714",
1048
+ cross: "\u2718",
1049
+ partial: "\u25D0",
1050
+ arrow: "\u2192"
1051
+ };
1052
+ var ASCII_GLYPHS = {
1053
+ horizontal: "-",
1054
+ vertical: "|",
1055
+ topLeft: "+",
1056
+ topRight: "+",
1057
+ bottomLeft: "+",
1058
+ bottomRight: "+",
1059
+ teeLeft: "+",
1060
+ teeRight: "+",
1061
+ bullet: "*",
1062
+ // One code point each, matching the Unicode set, so the status column is the
1063
+ // same width in both renderings and the table does not need two layouts.
1064
+ check: "+",
1065
+ cross: "x",
1066
+ partial: "~",
1067
+ arrow: ">"
1068
+ };
1069
+ function glyphsFor(unicode) {
1070
+ return unicode ? UNICODE_GLYPHS : ASCII_GLYPHS;
1071
+ }
1072
+
1073
+ // src/format/pretty.ts
1074
+ var BASIS_COLUMN = 9;
1075
+ var POINTS_COLUMN = 7;
1076
+ function renderPretty(payload, caps, _ctx) {
1077
+ const pretty = { caps, paint: createPainter(caps.color) };
1078
+ switch (payload.command) {
1079
+ case "check":
1080
+ return joinBlocks(payload.reports.map((report) => checkBlock(report, pretty)));
1081
+ case "diff":
1082
+ return joinBlocks([diffBlock(payload.diff, pretty)]);
1083
+ case "init":
1084
+ return joinBlocks([initBlock(payload.scaffold, pretty)]);
1085
+ case "badge":
1086
+ return joinBlocks([badgeBlock(payload.badge, pretty)]);
1087
+ }
1088
+ }
1089
+ function joinBlocks(blocks) {
1090
+ return blocks.map((lines) => lines.map((line) => line.replace(/[ \t]+$/, "")).join("\n")).join("\n\n") + "\n";
1091
+ }
1092
+ function gradeStyle(grade) {
1093
+ if (grade === "A") return "green";
1094
+ if (grade === "B") return "cyan";
1095
+ if (grade === "C") return "yellow";
1096
+ return "red";
1097
+ }
1098
+ function checkBlock(report, pretty) {
1099
+ const { paint, caps } = pretty;
1100
+ const glyphs = glyphsFor(caps.unicode);
1101
+ const lines = [];
1102
+ const width = caps.width;
1103
+ lines.push(paint(truncate(report.url, width, caps.unicode), "bold"));
1104
+ lines.push(paint(glyphs.horizontal.repeat(Math.min(width, 64)), "gray"));
1105
+ if (report.kind === "rejected") {
1106
+ lines.push(`${paint("REJECTED", "red", "bold")} ${outcomeSummary(report)}`);
1107
+ lines.push(...noticeLines(pretty));
1108
+ return lines;
1109
+ }
1110
+ const { result } = report;
1111
+ const status = statusOf(report);
1112
+ if (status !== "scored") {
1113
+ lines.push(paint(outcomeSummary(report), "yellow"));
1114
+ lines.push("");
1115
+ lines.push(...policyLines(result, pretty));
1116
+ lines.push(...identityLines(result, pretty));
1117
+ lines.push(...noticeLines(pretty));
1118
+ return lines;
1119
+ }
1120
+ const grade = result.grade ?? "?";
1121
+ const scoreText = `${result.score ?? 0}/100`;
1122
+ lines.push(
1123
+ `${paint(grade, gradeStyle(grade), "bold")} ${paint(result.bandLabel ?? "", "bold")} ${paint(scoreText, "gray")}`
1124
+ );
1125
+ lines.push(
1126
+ paint(
1127
+ `${result.measuredWeight} of the 100 points are measured, ${result.heuristicWeight} heuristic`,
1128
+ "gray"
1129
+ )
1130
+ );
1131
+ lines.push(
1132
+ paint(
1133
+ `page kind: ${result.pageKind} (${result.pageKindConfidence} confidence, ${basisLabel(result.pageKindBasis)})`,
1134
+ "gray"
1135
+ )
1136
+ );
1137
+ lines.push("");
1138
+ for (const dimension of result.dimensions) {
1139
+ lines.push(...dimensionLines(dimension, pretty));
1140
+ }
1141
+ lines.push("");
1142
+ lines.push(...costLines(result, pretty));
1143
+ if (result.flags.length > 0) {
1144
+ lines.push("");
1145
+ lines.push(paint("Flags", "bold"));
1146
+ for (const flag of result.flags) {
1147
+ const tone = flag.severity === "warn" ? "yellow" : "gray";
1148
+ lines.push(
1149
+ ` ${glyphs.bullet} ${paint(flag.id, tone)} [${basisLabel(flag.basis)}] ${flag.message}`
1150
+ );
1151
+ }
1152
+ }
1153
+ if (result.recommendations.length > 0) {
1154
+ lines.push("");
1155
+ lines.push(paint("Fixes, most points first", "bold"));
1156
+ for (const recommendation of result.recommendations) {
1157
+ lines.push(
1158
+ ` ${padStart(`+${recommendation.pointsAvailable}`, 4)} ${paint(recommendation.title, "bold")} ${paint(`(${recommendation.effort})`, "gray")}`
1159
+ );
1160
+ lines.push(
1161
+ paint(` ${truncate(recommendation.detail, caps.width - 8, caps.unicode)}`, "gray")
1162
+ );
1163
+ }
1164
+ }
1165
+ lines.push("");
1166
+ lines.push(...policyLines(result, pretty));
1167
+ lines.push(...identityLines(result, pretty));
1168
+ lines.push(...noticeLines(pretty));
1169
+ return lines;
1170
+ }
1171
+ function dimensionLines(dimension, pretty) {
1172
+ const { paint, caps } = pretty;
1173
+ const lines = [];
1174
+ const head = `${dimension.label}`;
1175
+ const points = `${dimension.earned}/${dimension.weight}`;
1176
+ const labelWidth = Math.max(10, caps.width - POINTS_COLUMN - BASIS_COLUMN - 4);
1177
+ lines.push(
1178
+ `${paint(padEnd(truncate(head, labelWidth, caps.unicode), labelWidth), "bold")} ${padStart(points, POINTS_COLUMN)} ${padEnd(basisLabel(dimension.basis), BASIS_COLUMN)}`
1179
+ );
1180
+ for (const check of dimension.checks) {
1181
+ lines.push(checkLine(check, pretty, labelWidth));
1182
+ }
1183
+ return lines;
1184
+ }
1185
+ function checkLine(check, pretty, labelWidth) {
1186
+ const { paint, caps } = pretty;
1187
+ const mark = checkMark(check, caps.unicode);
1188
+ const tone = check.earned >= check.weight ? "green" : check.earned > 0 ? "yellow" : "red";
1189
+ const label = ` ${mark} ${check.label}`;
1190
+ const points = `${check.earned}/${check.weight}`;
1191
+ return `${padEnd(truncate(label, labelWidth, caps.unicode), labelWidth)} ${paint(padStart(points, POINTS_COLUMN), tone)} ${paint(padEnd(basisLabel(check.basis), BASIS_COLUMN), "gray")}`;
1192
+ }
1193
+ function costLines(result, pretty) {
1194
+ const { paint, caps } = pretty;
1195
+ const { cost } = result;
1196
+ const lines = [paint("What an agent pays", "bold")];
1197
+ const html = bytesText(cost.htmlBytes, cost.truncated, caps.unicode);
1198
+ const negotiated = bytesText(cost.negotiatedBytes, cost.truncated, caps.unicode);
1199
+ const byteColumn = Math.max(visibleWidth(html), visibleWidth(negotiated)) + 3;
1200
+ lines.push(
1201
+ ` HTML ${padEnd(html, byteColumn)}${approxTokens(cost.approxHtmlTokens, caps.unicode)}`
1202
+ );
1203
+ lines.push(
1204
+ ` Negotiated ${padEnd(negotiated, byteColumn)}${approxTokens(cost.approxNegotiatedTokens, caps.unicode)}`
1205
+ );
1206
+ if (cost.reductionRatio !== null) {
1207
+ lines.push(paint(` Reduction ${cost.reductionRatio}%`, "green"));
1208
+ }
1209
+ lines.push(
1210
+ ` First core fact at byte ${cost.firstCoreFactOffset === null ? absent(caps.unicode) : cost.firstCoreFactOffset.toLocaleString("en-US")}`
1211
+ );
1212
+ const core = result.factProfile.core;
1213
+ const found = result.facts.filter((fact) => core.includes(fact.kind)).length;
1214
+ lines.push(
1215
+ paint(
1216
+ ` Core facts found ${found}/${core.length} (${percent(found, core.length)}) for a ${result.pageKind} page \u2014 heuristic`,
1217
+ "gray"
1218
+ )
1219
+ );
1220
+ return lines;
1221
+ }
1222
+ function policyLines(result, pretty) {
1223
+ const { paint } = pretty;
1224
+ const { policy } = result;
1225
+ const parts = [
1226
+ `robots.txt ${policy.robotsTxtStatus}`,
1227
+ `assistant ${policy.audiences.assistant.decision}`,
1228
+ `training ${policy.audiences.training.decision} (neutral)`,
1229
+ `sitemap ${policy.sitemapDeclared ? "declared" : "not declared"}`
1230
+ ];
1231
+ return [paint(`Policy: ${parts.join(" \xB7 ")}`, "gray")];
1232
+ }
1233
+ function identityLines(result, pretty) {
1234
+ const { paint } = pretty;
1235
+ return [
1236
+ paint(
1237
+ `ARS ${result.specVersion} \xB7 ruleset ${shortHash(result.rulesetHash)} \xB7 corpus ${shortHash(result.corpusHash)} \xB7 evidence ${shortHash(result.evidenceHash)} \xB7 vantage ${result.vantage}`,
1238
+ "gray"
1239
+ )
1240
+ ];
1241
+ }
1242
+ function noticeLines(pretty) {
1243
+ return ["", ...ARS_NOTICE_LINES.map((line) => pretty.paint(line, "gray"))];
1244
+ }
1245
+ function diffBlock(diff, pretty) {
1246
+ const { paint, caps } = pretty;
1247
+ const glyphs = glyphsFor(caps.unicode);
1248
+ const lines = [
1249
+ paint(truncate(diff.url, caps.width, caps.unicode), "bold"),
1250
+ paint(glyphs.horizontal.repeat(Math.min(caps.width, 64)), "gray")
1251
+ ];
1252
+ if (diff.report.kind === "rejected") {
1253
+ lines.push(`${paint("REJECTED", "red", "bold")} ${outcomeSummary(diff.report)}`);
1254
+ lines.push(...noticeLines(pretty));
1255
+ return lines;
1256
+ }
1257
+ lines.push(
1258
+ paint(
1259
+ "The two requests differ in the Accept header and in nothing else \u2014 same User-Agent, same everything (\xA73.3).",
1260
+ "gray"
1261
+ )
1262
+ );
1263
+ lines.push("");
1264
+ const rows = [
1265
+ ["", "agent", "browser"],
1266
+ [
1267
+ "Accept",
1268
+ diff.agent?.accept ?? absent(caps.unicode),
1269
+ diff.browser?.accept ?? absent(caps.unicode)
1270
+ ],
1271
+ ["Status", text(diff.agent?.status, caps.unicode), text(diff.browser?.status, caps.unicode)],
1272
+ [
1273
+ "Content-Type",
1274
+ diff.agent?.contentType ?? absent(caps.unicode),
1275
+ diff.browser?.contentType ?? absent(caps.unicode)
1276
+ ],
1277
+ [
1278
+ "Bytes",
1279
+ bytesText(diff.agent?.bytes ?? null, diff.agent?.truncated ?? false, caps.unicode),
1280
+ bytesText(diff.browser?.bytes ?? null, diff.browser?.truncated ?? false, caps.unicode)
1281
+ ],
1282
+ [
1283
+ "Tokens",
1284
+ approxTokens(diff.agent?.approxTokens ?? null, caps.unicode),
1285
+ approxTokens(diff.browser?.approxTokens ?? null, caps.unicode)
1286
+ ],
1287
+ [
1288
+ "Redirects",
1289
+ text(diff.agent?.redirects, caps.unicode),
1290
+ text(diff.browser?.redirects, caps.unicode)
1291
+ ],
1292
+ [
1293
+ "Error",
1294
+ diff.agent?.error ?? absent(caps.unicode),
1295
+ diff.browser?.error ?? absent(caps.unicode)
1296
+ ]
1297
+ ];
1298
+ const labelWidth = Math.max(...rows.map((row) => row[0].length)) + 2;
1299
+ const columnWidth = Math.max(12, Math.floor((caps.width - labelWidth - 2) / 2));
1300
+ for (const [label, agentCell, browserCell] of rows) {
1301
+ lines.push(
1302
+ `${paint(padEnd(label, labelWidth), "bold")}${padEnd(truncate(agentCell, columnWidth, caps.unicode), columnWidth + 2)}${truncate(browserCell, columnWidth, caps.unicode)}`
1303
+ );
1304
+ }
1305
+ if (diff.parity !== null) {
1306
+ lines.push("");
1307
+ lines.push(
1308
+ `${paint("Substance parity", "bold")} ${paint(`[${basisLabel(diff.parity.basis)}]`, "gray")} ${diff.parity.earned}/${diff.parity.weight}`
1309
+ );
1310
+ lines.push(
1311
+ paint(
1312
+ " Compared on price, currency, availability and title only \u2014 never description or free text (\xA73.8).",
1313
+ "gray"
1314
+ )
1315
+ );
1316
+ for (const evidence of diff.parity.evidence) {
1317
+ lines.push(
1318
+ ` ${glyphs.bullet} ${evidence.label}: ${evidence.value} [${basisLabel(evidence.basis)}]`
1319
+ );
1320
+ }
1321
+ }
1322
+ if (diff.result !== null) {
1323
+ lines.push("");
1324
+ lines.push(paint(`Score: ${outcomeSummary(diff.report)}`, "gray"));
1325
+ lines.push(...identityLines(diff.result, pretty));
1326
+ }
1327
+ lines.push(...noticeLines(pretty));
1328
+ return lines;
1329
+ }
1330
+ function text(value, unicode) {
1331
+ return value === void 0 || value === null ? absent(unicode) : String(value);
1332
+ }
1333
+ function initBlock(scaffold, pretty) {
1334
+ const { paint } = pretty;
1335
+ const lines = [
1336
+ paint(`Detected framework: ${scaffold.framework}`, "bold"),
1337
+ paint(` ${scaffold.detection}`, "gray"),
1338
+ "",
1339
+ paint(`Suggested path: ${scaffold.suggestedPath}`, "gray"),
1340
+ "",
1341
+ scaffold.contents.trimEnd()
1342
+ ];
1343
+ if (scaffold.notes.length > 0) {
1344
+ lines.push("");
1345
+ for (const note of scaffold.notes) lines.push(paint(` ${note}`, "gray"));
1346
+ }
1347
+ return lines;
1348
+ }
1349
+ function badgeBlock(badge, pretty) {
1350
+ const { paint } = pretty;
1351
+ const lines = [
1352
+ paint(`Badge for ${badge.domain}`, "bold"),
1353
+ "",
1354
+ paint("Markdown", "bold"),
1355
+ badge.markdown,
1356
+ "",
1357
+ paint("HTML", "bold"),
1358
+ badge.html,
1359
+ ""
1360
+ ];
1361
+ for (const note of badge.notes) lines.push(paint(` ${note}`, "gray"));
1362
+ return lines;
1363
+ }
1364
+
1365
+ // src/format/index.ts
1366
+ function render(payload, format, caps, ctx) {
1367
+ if (format === "junit" && (payload.command === "init" || payload.command === "badge")) {
1368
+ throw new UsageError(
1369
+ `--format junit reports observations about a page; \`${payload.command}\` makes none. Use pretty, json or markdown.`
1370
+ );
1371
+ }
1372
+ switch (format) {
1373
+ case "pretty":
1374
+ return renderPretty(payload, caps);
1375
+ case "json":
1376
+ return renderJson(payload, ctx);
1377
+ case "markdown":
1378
+ return renderMarkdown(payload, ctx);
1379
+ case "junit":
1380
+ return renderJunit(payload, ctx);
1381
+ }
1382
+ }
1383
+
1384
+ // src/help.ts
1385
+ var EXIT_TABLE = [
1386
+ ` ${EXIT.OK} completed; threshold met, or no threshold set`,
1387
+ ` ${EXIT.THRESHOLD} completed; threshold NOT met`,
1388
+ ` ${EXIT.USAGE} usage error`,
1389
+ ` ${EXIT.PROBE} probe failed / target unreachable \u2014 infrastructure, not a score failure`,
1390
+ ` ${EXIT.POLICY} blocked by policy (SSRF guard, robots opt-out, probe budget spent)`
1391
+ ];
1392
+ var GENERAL = `rebilder \u2014 the Agent Readability Score, from your machine.
1393
+
1394
+ USAGE
1395
+ rebilder check <url...> [--format ${FORMATS.join("|")}] [--fail-on ${GRADES.join("|")}]
1396
+ [--out <file>] [--allow-private] [--allow-http]
1397
+ [--concurrency <n>]
1398
+ rebilder diff <url> agent view vs browser view
1399
+ rebilder init gateway config scaffold for the detected framework
1400
+ rebilder badge <domain> embed snippet
1401
+
1402
+ rebilder help <command> detail for one command
1403
+ rebilder --version
1404
+
1405
+ EXIT CODES (a stable contract; never renumbered)
1406
+ ${EXIT_TABLE.join("\n")}
1407
+
1408
+ The 1-vs-3 split is load-bearing. A flaky network exits 3, never 1: if an
1409
+ unreachable host failed your build as a score failure, the check would be
1410
+ deleted from CI within a week. --fail-on defaults to nothing, so plain
1411
+ \`rebilder check <url>\` reports and exits 0.
1412
+
1413
+ ZERO TELEMETRY
1414
+ ${TELEMETRY_LINES.map((line) => ` ${line}`).join("\n")}
1415
+
1416
+ DISCLOSURE
1417
+ ${CONFLICT_OF_INTEREST_LINES.map((line) => ` ${line}`).join("\n")}
1418
+
1419
+ Spec: https://rebilder.com/spec/ars Crawler policy: https://rebilder.com/bots
1420
+ `;
1421
+ var CHECK = `rebilder check <url...>
1422
+
1423
+ Probes each URL twice \u2014 an agent request and a browser control that differ in
1424
+ the Accept header and in nothing else \u2014 plus /robots.txt, /llms.txt and
1425
+ /.well-known/ucp per origin. Nothing else is requested. robots.txt is fetched
1426
+ first and obeyed.
1427
+
1428
+ OPTIONS
1429
+ --format ${FORMATS.join("|")} default pretty
1430
+ --fail-on ${GRADES.join("|")} default none. "--fail-on C" means C or
1431
+ better passes; a worse grade exits 1.
1432
+ --out <file> write the same rendering to a file
1433
+ --concurrency <n> URLs in flight; default 1, max 8. The
1434
+ probe's politeness limiter still allows
1435
+ at most 1 request per host and 2 globally.
1436
+ --allow-http permit plain http targets
1437
+ --allow-private permit private, loopback and link-local
1438
+ targets. Routes through a separate,
1439
+ import-time-gated entry point; it is opt-in
1440
+ per invocation, never a config default, and
1441
+ refuses to load in a hosted runtime.
1442
+ Implies --allow-http.
1443
+
1444
+ A non-graded outcome \u2014 a deliberate robots opt-out, a 403 at the edge, an
1445
+ unreachable host \u2014 never produces exit 1. Only a real score compared against a
1446
+ threshold you set can do that.
1447
+
1448
+ DISCLOSURE
1449
+ ${CONFLICT_OF_INTEREST_LINES.map((line) => ` ${line}`).join("\n")}
1450
+ `;
1451
+ var DIFF = `rebilder diff <url>
1452
+
1453
+ Shows what the agent request received next to what the browser request
1454
+ received: status, content type, decoded bytes, an estimated token count, and
1455
+ the D2.4 substance-parity comparison verbatim.
1456
+
1457
+ It shows structure and numbers, never an excerpt of the page. --fail-on is not
1458
+ supported: diff reports, it does not grade.
1459
+
1460
+ OPTIONS
1461
+ --format ${FORMATS.join("|")} default pretty
1462
+ --out <file> write the same rendering to a file
1463
+ --allow-http, --allow-private as \`check\`
1464
+ `;
1465
+ var INIT = `rebilder init
1466
+
1467
+ Writes a @rebilder/gateway config scaffold for the framework it detects in the
1468
+ working directory, and prints how it decided. Makes no network request and
1469
+ reads nothing outside the working directory.
1470
+
1471
+ OPTIONS
1472
+ --framework next|node|edge|shopify override detection
1473
+ --out <file> write the scaffold to a file
1474
+ --format ${FORMATS.join("|")} junit is refused: init makes no observations
1475
+
1476
+ The scaffold is a skeleton with TODOs, not a working config. The resolvers
1477
+ return YOUR source of truth \u2014 every substantive value comes from those fields,
1478
+ and the gateway never invents one.
1479
+ `;
1480
+ var BADGE = `rebilder badge <domain>
1481
+
1482
+ Prints the markdown and HTML embed snippets for a domain's badge. Built
1483
+ locally: no network request, so we never learn which domain you asked about.
1484
+
1485
+ A grade renders only for a verified opted-in domain; every other domain gets a
1486
+ neutral "not rated" badge at 200, not 404. The badge always names its subject,
1487
+ is served live, and degrades to "unverified" after 30 days without a
1488
+ successful re-scan.
1489
+
1490
+ OPTIONS
1491
+ --format ${FORMATS.join("|")} junit is refused: badge makes no observations
1492
+ --out <file> write the snippet to a file
1493
+ `;
1494
+ var TOPICS = {
1495
+ check: CHECK,
1496
+ diff: DIFF,
1497
+ init: INIT,
1498
+ badge: BADGE
1499
+ };
1500
+ function helpText(topic) {
1501
+ if (topic === null) return GENERAL;
1502
+ return TOPICS[topic];
1503
+ }
1504
+
1505
+ // src/cli.ts
1506
+ var CLI_VERSION = "0.1.0";
1507
+ async function runCli(argv, runtime) {
1508
+ const caps = detectCapabilities({
1509
+ env: runtime.env,
1510
+ isTty: runtime.isTty,
1511
+ columns: runtime.columns
1512
+ });
1513
+ try {
1514
+ const parsed = parseCommandLine(argv);
1515
+ if (parsed.kind === "version") {
1516
+ runtime.write(`${CLI_VERSION}
1517
+ `);
1518
+ return EXIT.OK;
1519
+ }
1520
+ if (parsed.kind === "help") {
1521
+ runtime.write(helpText(parsed.topic));
1522
+ return EXIT.OK;
1523
+ }
1524
+ const { command } = parsed;
1525
+ const { payload, exitCode } = await execute(command, runtime);
1526
+ const ctx = {
1527
+ unicode: caps.unicode,
1528
+ generatedAt: runtime.now().toISOString(),
1529
+ cliVersion: CLI_VERSION
1530
+ };
1531
+ const rendered = render(payload, command.format, caps, ctx);
1532
+ runtime.write(rendered);
1533
+ if (command.out !== null) {
1534
+ await runtime.writeFile(command.out, rendered);
1535
+ }
1536
+ return exitCode;
1537
+ } catch (error) {
1538
+ if (error instanceof UsageError) {
1539
+ runtime.writeError(`rebilder: ${error.message}
1540
+
1541
+ Run \`rebilder --help\`.
1542
+ `);
1543
+ return EXIT.USAGE;
1544
+ }
1545
+ runtime.writeError(`rebilder: ${error instanceof Error ? error.message : String(error)}
1546
+ `);
1547
+ return EXIT.PROBE;
1548
+ }
1549
+ }
1550
+ async function execute(command, runtime) {
1551
+ switch (command.name) {
1552
+ case "check": {
1553
+ const probe = await buildProbe(runtime, command.urls.length, command);
1554
+ const reports = await runCheck(command, probe);
1555
+ return {
1556
+ payload: { command: "check", reports, failOn: command.failOn },
1557
+ exitCode: worstExit(reports.map((report) => exitCodeFor(report, command.failOn)))
1558
+ };
1559
+ }
1560
+ case "diff": {
1561
+ const probe = await buildProbe(runtime, 1, command);
1562
+ const diff = await runDiff(command, probe);
1563
+ return { payload: { command: "diff", diff }, exitCode: exitCodeFor(diff.report, null) };
1564
+ }
1565
+ case "init": {
1566
+ const scaffold = await runInit(command, runtime);
1567
+ return { payload: { command: "init", scaffold }, exitCode: EXIT.OK };
1568
+ }
1569
+ case "badge": {
1570
+ return { payload: { command: "badge", badge: runBadge(command) }, exitCode: EXIT.OK };
1571
+ }
1572
+ }
1573
+ }
1574
+ function buildProbe(runtime, urlCount, flags) {
1575
+ return runtime.probe({
1576
+ allowPrivate: flags.allowPrivate,
1577
+ allowHttp: flags.allowHttp,
1578
+ urlCount
1579
+ });
1580
+ }
1581
+ function budgetFor(urlCount) {
1582
+ return Math.max(20, urlCount * 6 + 4);
1583
+ }
1584
+ function policyFor(setup, base) {
1585
+ return { ...base, allowHttp: setup.allowHttp || base.allowHttp };
1586
+ }
1587
+ var nodeProbeFactory = async (setup) => {
1588
+ const limiter = probe.createLimiter({ maxProbesPerRun: budgetFor(setup.urlCount) });
1589
+ if (!setup.allowPrivate) {
1590
+ const policy2 = policyFor(setup, probe.strictPolicy(limiter));
1591
+ return (target) => probe.probeStrict(target, policy2);
1592
+ }
1593
+ const local = await import('@rebilder/agent-readability/probe/local');
1594
+ const policy = policyFor(setup, local.localPolicy(limiter));
1595
+ return (target) => local.probeLocal(target, policy);
1596
+ };
1597
+ function createNodeRuntime() {
1598
+ return {
1599
+ env: process.env,
1600
+ cwd: process.cwd(),
1601
+ isTty: process.stdout.isTTY === true,
1602
+ columns: process.stdout.columns,
1603
+ write: (text2) => process.stdout.write(text2),
1604
+ writeError: (text2) => process.stderr.write(text2),
1605
+ writeFile: async (path$1, contents) => {
1606
+ await promises.writeFile(path.resolve(process.cwd(), path$1), contents, "utf8");
1607
+ },
1608
+ readFile: async (path$1) => {
1609
+ try {
1610
+ return await promises.readFile(path.resolve(process.cwd(), path$1), "utf8");
1611
+ } catch {
1612
+ return null;
1613
+ }
1614
+ },
1615
+ probe: nodeProbeFactory,
1616
+ now: () => /* @__PURE__ */ new Date()
1617
+ };
1618
+ }
1619
+
1620
+ exports.ARS_NOTICE = ARS_NOTICE;
1621
+ exports.ARS_NOTICE_LINES = ARS_NOTICE_LINES;
1622
+ exports.BADGE_ORIGIN = BADGE_ORIGIN;
1623
+ exports.CLI_VERSION = CLI_VERSION;
1624
+ exports.COMMANDS = COMMANDS;
1625
+ exports.CONFLICT_OF_INTEREST = CONFLICT_OF_INTEREST;
1626
+ exports.CONFLICT_OF_INTEREST_LINES = CONFLICT_OF_INTEREST_LINES;
1627
+ exports.EXIT = EXIT;
1628
+ exports.FORMATS = FORMATS;
1629
+ exports.FRAMEWORKS = FRAMEWORKS;
1630
+ exports.GRADES = GRADES;
1631
+ exports.TELEMETRY_LINES = TELEMETRY_LINES;
1632
+ exports.UsageError = UsageError;
1633
+ exports.budgetFor = budgetFor;
1634
+ exports.createNodeRuntime = createNodeRuntime;
1635
+ exports.detectCapabilities = detectCapabilities;
1636
+ exports.detectFramework = detectFramework;
1637
+ exports.exitCodeFor = exitCodeFor;
1638
+ exports.helpText = helpText;
1639
+ exports.meetsThreshold = meetsThreshold;
1640
+ exports.nodeProbeFactory = nodeProbeFactory;
1641
+ exports.normalizeDomain = normalizeDomain;
1642
+ exports.outcomeSummary = outcomeSummary;
1643
+ exports.parseCommandLine = parseCommandLine;
1644
+ exports.render = render;
1645
+ exports.runCli = runCli;
1646
+ exports.statusOf = statusOf;
1647
+ exports.worstExit = worstExit;
1648
+ //# sourceMappingURL=index.cjs.map
1649
+ //# sourceMappingURL=index.cjs.map