@benchcutlogic/repo-checks 0.0.0-stage → 0.2.1

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.
@@ -0,0 +1,522 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { existsSync, readFileSync } from 'node:fs';
3
+ import { join, relative, resolve } from 'node:path';
4
+ import { collectMatchingFiles, isDirectory, readTextSafe, toPosixPath, walkFiles } from '../fs-utils.js';
5
+ const DEFAULT_BUILD_DIRS = ['apps/web/build', 'build', 'dist'];
6
+ const JSONLD_REQUIRED_FIELDS = {
7
+ Article: ['headline'],
8
+ BlogPosting: ['headline'],
9
+ NewsArticle: ['headline'],
10
+ Book: ['name'],
11
+ Review: ['itemReviewed', 'author'],
12
+ WebSite: ['name'],
13
+ Organization: ['name'],
14
+ Person: ['name']
15
+ };
16
+ function resolveBuildDir(ctx) {
17
+ const explicit = ctx.buildDirOverride ?? ctx.config.web.buildDir;
18
+ if (explicit) {
19
+ const full = resolve(ctx.root, explicit);
20
+ return isDirectory(full)
21
+ ? { dir: full, missingExplicit: null }
22
+ : { dir: null, missingExplicit: toPosixPath(explicit) };
23
+ }
24
+ for (const candidate of DEFAULT_BUILD_DIRS) {
25
+ const full = join(ctx.root, candidate);
26
+ if (isDirectory(full))
27
+ return { dir: full, missingExplicit: null };
28
+ }
29
+ return { dir: null, missingExplicit: null };
30
+ }
31
+ function validateXmlSitemap(xml, sourceLabel, findings, isChild) {
32
+ const trimmed = xml.trim();
33
+ const isUrlset = /<urlset[\s>]/.test(trimmed) && /<\/urlset>/.test(trimmed);
34
+ const isIndex = /<sitemapindex[\s>]/.test(trimmed) && /<\/sitemapindex>/.test(trimmed);
35
+ if (!isUrlset && !isIndex) {
36
+ findings.push({
37
+ check: 'web',
38
+ severity: 'error',
39
+ file: sourceLabel,
40
+ rule: 'web-sitemap-invalid-xml',
41
+ message: `Invalid sitemap XML in '${sourceLabel}': expected <urlset> or <sitemapindex>.`
42
+ });
43
+ return [];
44
+ }
45
+ if (isChild && isIndex) {
46
+ findings.push({
47
+ check: 'web',
48
+ severity: 'error',
49
+ file: sourceLabel,
50
+ rule: 'web-sitemap-nested-index',
51
+ message: `Nested <sitemapindex> detected in '${sourceLabel}'; <sitemapindex> may only reference leaf <urlset> sitemaps.`
52
+ });
53
+ }
54
+ const locs = [];
55
+ const locRe = /<loc>\s*([^<]+?)\s*<\/loc>/g;
56
+ let m;
57
+ while ((m = locRe.exec(trimmed)) !== null) {
58
+ const loc = m[1].trim();
59
+ locs.push(loc);
60
+ if (!loc.startsWith('https://')) {
61
+ findings.push({
62
+ check: 'web',
63
+ severity: 'error',
64
+ file: sourceLabel,
65
+ rule: 'web-sitemap-non-https-loc',
66
+ message: `Sitemap <loc> must be an absolute https:// URL; found '${loc}'.`
67
+ });
68
+ }
69
+ }
70
+ if (locs.length === 0) {
71
+ findings.push({
72
+ check: 'web',
73
+ severity: 'error',
74
+ file: sourceLabel,
75
+ rule: 'web-sitemap-empty',
76
+ message: `Sitemap '${sourceLabel}' contains zero <loc> entries.`
77
+ });
78
+ }
79
+ return isIndex ? locs : [];
80
+ }
81
+ async function checkSitemap(ctx, buildDir, findings) {
82
+ if (ctx.fetchFn && ctx.config.web.baseUrl) {
83
+ const base = ctx.config.web.baseUrl.replace(/\/+$/, '');
84
+ const rootUrl = `${base}/sitemap.xml`;
85
+ const res = await ctx.fetchFn(rootUrl);
86
+ if (res.status !== 200) {
87
+ findings.push({
88
+ check: 'web',
89
+ severity: 'error',
90
+ file: rootUrl,
91
+ rule: 'web-sitemap-status',
92
+ message: `GET ${rootUrl} returned HTTP ${res.status} (expected 200 without redirect).`
93
+ });
94
+ return;
95
+ }
96
+ const xml = await res.text();
97
+ const childLocs = validateXmlSitemap(xml, rootUrl, findings, false);
98
+ for (const childUrl of childLocs) {
99
+ const childRes = await ctx.fetchFn(childUrl);
100
+ if (childRes.status !== 200) {
101
+ findings.push({
102
+ check: 'web',
103
+ severity: 'error',
104
+ file: childUrl,
105
+ rule: 'web-sitemap-child-status',
106
+ message: `Child sitemap ${childUrl} returned HTTP ${childRes.status}.`
107
+ });
108
+ continue;
109
+ }
110
+ const childXml = await childRes.text();
111
+ validateXmlSitemap(childXml, childUrl, findings, true);
112
+ }
113
+ return;
114
+ }
115
+ if (!buildDir)
116
+ return;
117
+ const sitemapPath = join(buildDir, 'sitemap.xml');
118
+ const relSitemap = toPosixPath(relative(ctx.root, sitemapPath));
119
+ if (!existsSync(sitemapPath)) {
120
+ findings.push({
121
+ check: 'web',
122
+ severity: 'error',
123
+ file: relSitemap,
124
+ rule: 'web-sitemap-missing',
125
+ message: `Missing built sitemap at '${relSitemap}'.`
126
+ });
127
+ return;
128
+ }
129
+ const xml = readFileSync(sitemapPath, 'utf8');
130
+ const childLocs = validateXmlSitemap(xml, relSitemap, findings, false);
131
+ for (const loc of childLocs) {
132
+ try {
133
+ const parsedUrl = new URL(loc);
134
+ const childRelPath = parsedUrl.pathname.replace(/^\/+/, '');
135
+ const childDiskPath = join(buildDir, childRelPath);
136
+ if (!existsSync(childDiskPath)) {
137
+ findings.push({
138
+ check: 'web',
139
+ severity: 'error',
140
+ file: relSitemap,
141
+ rule: 'web-sitemap-child-missing',
142
+ message: `Referenced child sitemap '${loc}' was not found in buildDir at '${childRelPath}'.`
143
+ });
144
+ continue;
145
+ }
146
+ const childXml = readFileSync(childDiskPath, 'utf8');
147
+ validateXmlSitemap(childXml, toPosixPath(relative(ctx.root, childDiskPath)), findings, true);
148
+ }
149
+ catch {
150
+ // non-URL already reported above
151
+ }
152
+ }
153
+ }
154
+ function hasIcoOrPngMagic(bytes) {
155
+ if (bytes.length < 4)
156
+ return false;
157
+ const isIco = bytes[0] === 0x00 && bytes[1] === 0x00 && bytes[2] === 0x01 && bytes[3] === 0x00;
158
+ const isPng = bytes[0] === 0x89 && bytes[1] === 0x50 && bytes[2] === 0x4e && bytes[3] === 0x47;
159
+ return isIco || isPng;
160
+ }
161
+ async function checkFavicon(ctx, buildDir, findings) {
162
+ if (ctx.fetchFn && ctx.config.web.baseUrl) {
163
+ const base = ctx.config.web.baseUrl.replace(/\/+$/, '');
164
+ const icoUrl = `${base}/favicon.ico`;
165
+ const icoRes = await ctx.fetchFn(icoUrl);
166
+ if (icoRes.status !== 200) {
167
+ findings.push({
168
+ check: 'web',
169
+ severity: 'error',
170
+ file: icoUrl,
171
+ rule: 'web-favicon-ico-status',
172
+ message: `GET ${icoUrl} returned HTTP ${icoRes.status} (expected 200).`
173
+ });
174
+ }
175
+ else {
176
+ const buf = new Uint8Array(await icoRes.arrayBuffer());
177
+ if (!hasIcoOrPngMagic(buf)) {
178
+ findings.push({
179
+ check: 'web',
180
+ severity: 'error',
181
+ file: icoUrl,
182
+ rule: 'web-favicon-ico-magic',
183
+ message: `${icoUrl} does not have valid binary ICO (00 00 01 00) or PNG (89 50 4E 47) magic bytes.`
184
+ });
185
+ }
186
+ }
187
+ const svgUrl = `${base}/favicon.svg`;
188
+ const svgRes = await ctx.fetchFn(svgUrl);
189
+ if (svgRes.status === 200) {
190
+ const svgText = await svgRes.text();
191
+ if (/<text[\s>]/i.test(svgText)) {
192
+ findings.push({
193
+ check: 'web',
194
+ severity: 'error',
195
+ file: svgUrl,
196
+ rule: 'web-favicon-svg-text',
197
+ message: `${svgUrl} contains a <text> element; convert glyphs to outlined <path> elements.`
198
+ });
199
+ }
200
+ }
201
+ return;
202
+ }
203
+ if (!buildDir)
204
+ return;
205
+ const icoPath = join(buildDir, 'favicon.ico');
206
+ const relIco = toPosixPath(relative(ctx.root, icoPath));
207
+ if (!existsSync(icoPath)) {
208
+ findings.push({
209
+ check: 'web',
210
+ severity: 'error',
211
+ file: relIco,
212
+ rule: 'web-favicon-ico-missing',
213
+ message: `Missing binary favicon at '${relIco}'.`
214
+ });
215
+ }
216
+ else {
217
+ const bytes = readFileSync(icoPath);
218
+ if (!hasIcoOrPngMagic(bytes)) {
219
+ findings.push({
220
+ check: 'web',
221
+ severity: 'error',
222
+ file: relIco,
223
+ rule: 'web-favicon-ico-magic',
224
+ message: `'${relIco}' does not start with valid binary ICO (00 00 01 00) or PNG (89 50 4E 47) magic bytes (do not serve SVG/HTML as favicon.ico).`
225
+ });
226
+ }
227
+ }
228
+ const svgPath = join(buildDir, 'favicon.svg');
229
+ if (existsSync(svgPath)) {
230
+ const svgText = readFileSync(svgPath, 'utf8');
231
+ if (/<text[\s>]/i.test(svgText)) {
232
+ findings.push({
233
+ check: 'web',
234
+ severity: 'error',
235
+ file: toPosixPath(relative(ctx.root, svgPath)),
236
+ rule: 'web-favicon-svg-text',
237
+ message: 'favicon.svg contains <text> elements; outline glyphs as SVG paths instead.'
238
+ });
239
+ }
240
+ }
241
+ }
242
+ function validateJsonLdObject(obj, relHtml, findings) {
243
+ if (typeof obj['@context'] !== 'string' && typeof obj['@context'] !== 'object') {
244
+ findings.push({
245
+ check: 'web',
246
+ severity: 'error',
247
+ file: relHtml,
248
+ rule: 'web-jsonld-missing-context',
249
+ message: 'JSON-LD script is missing `@context`.'
250
+ });
251
+ }
252
+ if (Array.isArray(obj['@graph'])) {
253
+ for (const node of obj['@graph']) {
254
+ if (node && typeof node === 'object') {
255
+ validateJsonLdNode(node, relHtml, findings);
256
+ }
257
+ }
258
+ return;
259
+ }
260
+ validateJsonLdNode(obj, relHtml, findings);
261
+ }
262
+ function validateJsonLdNode(node, relHtml, findings) {
263
+ const typeVal = node['@type'];
264
+ const types = Array.isArray(typeVal)
265
+ ? typeVal.filter((t) => typeof t === 'string')
266
+ : typeof typeVal === 'string'
267
+ ? [typeVal]
268
+ : [];
269
+ if (types.length === 0) {
270
+ findings.push({
271
+ check: 'web',
272
+ severity: 'error',
273
+ file: relHtml,
274
+ rule: 'web-jsonld-missing-type',
275
+ message: 'JSON-LD object is missing `@type`.'
276
+ });
277
+ return;
278
+ }
279
+ for (const t of types) {
280
+ const required = JSONLD_REQUIRED_FIELDS[t];
281
+ if (!required)
282
+ continue;
283
+ for (const field of required) {
284
+ if (!(field in node) ||
285
+ node[field] === '' ||
286
+ node[field] === null ||
287
+ node[field] === undefined) {
288
+ findings.push({
289
+ check: 'web',
290
+ severity: 'error',
291
+ file: relHtml,
292
+ rule: 'web-jsonld-missing-field',
293
+ message: `JSON-LD '${t}' is missing required field '${field}'.`
294
+ });
295
+ }
296
+ }
297
+ }
298
+ }
299
+ function checkMetaAndJsonLd(ctx, buildDir, findings) {
300
+ if (!buildDir)
301
+ return;
302
+ const htmlFiles = walkFiles(buildDir, { skipDirs: new Set() }).filter((f) => f.endsWith('.html'));
303
+ const { titleMax, descriptionMax } = ctx.config.web;
304
+ for (const relInBuild of htmlFiles) {
305
+ const abs = join(buildDir, relInBuild);
306
+ const relHtml = toPosixPath(relative(ctx.root, abs));
307
+ const html = readFileSync(abs, 'utf8');
308
+ const titleMatch = html.match(/<title[^>]*>([\s\S]*?)<\/title>/i);
309
+ if (titleMatch?.[1]) {
310
+ const titleText = titleMatch[1].trim();
311
+ if (titleText.length > titleMax) {
312
+ findings.push({
313
+ check: 'web',
314
+ severity: 'error',
315
+ file: relHtml,
316
+ rule: 'web-title-length',
317
+ message: `<title> is ${titleText.length} characters (max ${titleMax}).`
318
+ });
319
+ }
320
+ }
321
+ const descMatch = html.match(/<meta\b[^>]*\bname=["']description["'][^>]*\bcontent=["']([^"']*)["'][^>]*>/i) ??
322
+ html.match(/<meta\b[^>]*\bcontent=["']([^"']*)["'][^>]*\bname=["']description["'][^>]*>/i);
323
+ if (descMatch?.[1] !== undefined) {
324
+ const desc = descMatch[1].trim();
325
+ if (desc.length > descriptionMax) {
326
+ findings.push({
327
+ check: 'web',
328
+ severity: 'error',
329
+ file: relHtml,
330
+ rule: 'web-description-length',
331
+ message: `<meta name="description"> is ${desc.length} characters (max ${descriptionMax}).`
332
+ });
333
+ }
334
+ }
335
+ const ogImageMatch = html.match(/<meta\b[^>]*\bproperty=["']og:image["'][^>]*\bcontent=["']([^"']*)["'][^>]*>/i) ??
336
+ html.match(/<meta\b[^>]*\bcontent=["']([^"']*)["'][^>]*\bproperty=["']og:image["'][^>]*>/i);
337
+ if (ogImageMatch?.[1] !== undefined) {
338
+ const ogUrl = ogImageMatch[1].trim();
339
+ if (!ogUrl.startsWith('https://')) {
340
+ findings.push({
341
+ check: 'web',
342
+ severity: 'error',
343
+ file: relHtml,
344
+ rule: 'web-og-image-https',
345
+ message: `<meta property="og:image"> must be an absolute https:// URL; found '${ogUrl}'.`
346
+ });
347
+ }
348
+ }
349
+ const canonicalMatch = html.match(/<link\b[^>]*\brel=["']canonical["'][^>]*\bhref=["']([^"']*)["'][^>]*>/i) ??
350
+ html.match(/<link\b[^>]*\bhref=["']([^"']*)["'][^>]*\brel=["']canonical["'][^>]*>/i);
351
+ if (canonicalMatch?.[1] !== undefined) {
352
+ const canonUrl = canonicalMatch[1].trim();
353
+ if (!canonUrl.startsWith('https://')) {
354
+ findings.push({
355
+ check: 'web',
356
+ severity: 'error',
357
+ file: relHtml,
358
+ rule: 'web-canonical-https',
359
+ message: `<link rel="canonical"> must be an absolute https:// URL; found '${canonUrl}'.`
360
+ });
361
+ }
362
+ }
363
+ const jsonLdRe = /<script\b[^>]*\btype=["']application\/ld\+json["'][^>]*>([\s\S]*?)<\/script>/gi;
364
+ let jm;
365
+ while ((jm = jsonLdRe.exec(html)) !== null) {
366
+ const rawJson = (jm[1] ?? '').trim();
367
+ try {
368
+ const parsed = JSON.parse(rawJson);
369
+ if (Array.isArray(parsed)) {
370
+ for (const item of parsed) {
371
+ if (item && typeof item === 'object') {
372
+ validateJsonLdObject(item, relHtml, findings);
373
+ }
374
+ }
375
+ }
376
+ else if (parsed && typeof parsed === 'object') {
377
+ validateJsonLdObject(parsed, relHtml, findings);
378
+ }
379
+ else {
380
+ findings.push({
381
+ check: 'web',
382
+ severity: 'error',
383
+ file: relHtml,
384
+ rule: 'web-jsonld-invalid',
385
+ message: 'JSON-LD block must be a JSON object or array of objects.'
386
+ });
387
+ }
388
+ }
389
+ catch (err) {
390
+ findings.push({
391
+ check: 'web',
392
+ severity: 'error',
393
+ file: relHtml,
394
+ rule: 'web-jsonld-parse-error',
395
+ message: `Invalid JSON-LD block: ${err.message}`
396
+ });
397
+ }
398
+ }
399
+ }
400
+ }
401
+ function validateShellSnippet(code, file, line, unpublishedPackages, findings) {
402
+ const trimmed = code.trim();
403
+ if (!trimmed)
404
+ return;
405
+ // Check unpublished npx package invocations
406
+ for (const pkg of unpublishedPackages) {
407
+ const escaped = pkg.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
408
+ if (new RegExp(`\\bnpx\\s+(?:-y\\s+)?${escaped}(?:@|\\s|$)`).test(trimmed)) {
409
+ findings.push({
410
+ check: 'web',
411
+ severity: 'error',
412
+ file,
413
+ line,
414
+ rule: 'web-snippet-unpublished-npx',
415
+ message: `Shell snippet invokes \`npx ${pkg}\`, which is listed as unpublished on npm.`
416
+ });
417
+ }
418
+ }
419
+ const check = spawnSync('bash', ['-n'], {
420
+ input: trimmed,
421
+ encoding: 'utf8'
422
+ });
423
+ if (check.error) {
424
+ findings.push({
425
+ check: 'web',
426
+ severity: 'error',
427
+ file,
428
+ line,
429
+ rule: 'web-snippet-bash-unavailable',
430
+ message: `Could not run \`bash -n\` to check this shell snippet: ${check.error.message}. Install bash or remove 'snippets' from web.checks.`
431
+ });
432
+ return;
433
+ }
434
+ if (check.status !== 0) {
435
+ const errText = (check.stderr || check.stdout || 'bash syntax error').trim().split('\n')[0] ?? '';
436
+ findings.push({
437
+ check: 'web',
438
+ severity: 'error',
439
+ file,
440
+ line,
441
+ rule: 'web-snippet-bash-syntax',
442
+ message: `Shell snippet failed \`bash -n\` syntax check: ${errText}`
443
+ });
444
+ }
445
+ }
446
+ function checkSnippets(ctx, buildDir, findings) {
447
+ const mdFiles = collectMatchingFiles(ctx.root, ctx.config.web.snippetFiles, [], ctx.config.files);
448
+ for (const rel of mdFiles) {
449
+ const content = readTextSafe(join(ctx.root, rel));
450
+ if (content === null)
451
+ continue;
452
+ const lines = content.split(/\r?\n/);
453
+ let inShellFence = false;
454
+ let startLine = 0;
455
+ let buf = [];
456
+ for (let i = 0; i < lines.length; i += 1) {
457
+ const line = lines[i] ?? '';
458
+ if (!inShellFence) {
459
+ const openMatch = line.match(/^\s*```(sh|bash|shell)\s*$/i);
460
+ if (openMatch) {
461
+ inShellFence = true;
462
+ startLine = i + 2;
463
+ buf = [];
464
+ }
465
+ }
466
+ else if (/^\s*```\s*$/.test(line)) {
467
+ validateShellSnippet(buf.join('\n'), rel, startLine, ctx.config.web.unpublishedPackages, findings);
468
+ inShellFence = false;
469
+ buf = [];
470
+ }
471
+ else {
472
+ buf.push(line);
473
+ }
474
+ }
475
+ }
476
+ if (buildDir) {
477
+ const htmlFiles = walkFiles(buildDir, { skipDirs: new Set() }).filter((f) => f.endsWith('.html'));
478
+ for (const relInBuild of htmlFiles) {
479
+ const abs = join(buildDir, relInBuild);
480
+ const relHtml = toPosixPath(relative(ctx.root, abs));
481
+ const html = readFileSync(abs, 'utf8');
482
+ const codeRe = /<code\b[^>]*class=["'][^"']*language-(?:bash|sh|shell)[^"']*["'][^>]*>([\s\S]*?)<\/code>/gi;
483
+ let m;
484
+ while ((m = codeRe.exec(html)) !== null) {
485
+ const decoded = (m[1] ?? '')
486
+ .replace(/&lt;/g, '<')
487
+ .replace(/&gt;/g, '>')
488
+ .replace(/&amp;/g, '&')
489
+ .replace(/&quot;/g, '"')
490
+ .replace(/&#39;/g, "'");
491
+ validateShellSnippet(decoded, relHtml, 1, ctx.config.web.unpublishedPackages, findings);
492
+ }
493
+ }
494
+ }
495
+ }
496
+ export async function checkWeb(ctx) {
497
+ const findings = [];
498
+ const { dir: buildDir, missingExplicit } = resolveBuildDir(ctx);
499
+ const enabled = new Set(ctx.config.web.checks);
500
+ if (missingExplicit !== null) {
501
+ findings.push({
502
+ check: 'web',
503
+ severity: 'error',
504
+ file: missingExplicit,
505
+ rule: 'web-missing-build-dir',
506
+ message: `Configured web build directory '${missingExplicit}' does not exist.`
507
+ });
508
+ }
509
+ if (enabled.has('sitemap')) {
510
+ await checkSitemap(ctx, buildDir, findings);
511
+ }
512
+ if (enabled.has('favicon')) {
513
+ await checkFavicon(ctx, buildDir, findings);
514
+ }
515
+ if (enabled.has('meta-jsonld')) {
516
+ checkMetaAndJsonLd(ctx, buildDir, findings);
517
+ }
518
+ if (enabled.has('snippets')) {
519
+ checkSnippets(ctx, buildDir, findings);
520
+ }
521
+ return { check: 'web', findings };
522
+ }
package/dist/cli.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+ /** The installed package version, read from this package's package.json. */
3
+ export declare function packageVersion(): string;
4
+ export interface ParsedArgs {
5
+ readonly command: string;
6
+ readonly root: string;
7
+ readonly json: boolean;
8
+ readonly strict: boolean;
9
+ readonly buildDir?: string;
10
+ readonly help: boolean;
11
+ readonly version: boolean;
12
+ }
13
+ export declare function parseCliArgs(argv: ReadonlyArray<string>): ParsedArgs;
14
+ export declare function runCli(argv: ReadonlyArray<string>, io?: {
15
+ readonly stdout: (s: string) => void;
16
+ readonly stderr: (s: string) => void;
17
+ }): Promise<number>;
18
+ export declare function isDirectEntryPoint(metaUrl: string, argv1: string | undefined): boolean;
package/dist/cli.js ADDED
@@ -0,0 +1,147 @@
1
+ #!/usr/bin/env node
2
+ import { readFileSync, realpathSync } from 'node:fs';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { ALL_CHECKS, formatSummaryText, runChecks } from './index.js';
5
+ const USAGE = `Usage: bench-check <command> [--root <dir>] [--json] [--strict] [--build-dir <dir>]
6
+ bench-check --version
7
+
8
+ Commands:
9
+ run Run configured repo checks (default: core checks)
10
+ doc-paths Verify markdown links and backticked file paths
11
+ agent-contracts 5-pass SKILL.md / AGENTS.md / sgpack / Effect v4 contract verifier
12
+ agents-budget Check AGENTS.md byte budget and CLAUDE.md / .claude/skills parity
13
+ lockfile-registry Reject private Tailscale/localhost/LAN URLs in lockfiles
14
+ unique-error-tags Enforce unique TaggedError _tag values and non-duplicated pgEnum tuples
15
+ effect-boundaries Enforce pure package imports and Effect.run* entry-point boundaries
16
+ svelte-tokens Enforce semantic theme tokens and dark-mode contrast rules
17
+ storybook-catalog Verify Storybook story catalog parity or clean discovery
18
+ web Validate built sitemap, favicon, meta/JSON-LD, and shell snippets
19
+ prose Validate markdown frontmatter, code fences, banned terms, and slop`;
20
+ /** The installed package version, read from this package's package.json. */
21
+ export function packageVersion() {
22
+ const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
23
+ if (typeof pkg.version !== 'string') {
24
+ throw new Error('@benchcutlogic/repo-checks package.json has no version field');
25
+ }
26
+ return pkg.version;
27
+ }
28
+ const VALID_CHECK_SET = new Set(ALL_CHECKS);
29
+ export function parseCliArgs(argv) {
30
+ let command = '';
31
+ let root = process.cwd();
32
+ let json = false;
33
+ let strict = false;
34
+ let buildDir;
35
+ let help = false;
36
+ let version = false;
37
+ for (let i = 0; i < argv.length; i += 1) {
38
+ const arg = argv[i];
39
+ if (arg === '--help' || arg === '-h') {
40
+ help = true;
41
+ }
42
+ else if (arg === '--version' || arg === '-v') {
43
+ version = true;
44
+ }
45
+ else if (arg === '--json') {
46
+ json = true;
47
+ }
48
+ else if (arg === '--strict') {
49
+ strict = true;
50
+ }
51
+ else if (arg === '--root') {
52
+ const next = argv[i + 1];
53
+ if (!next)
54
+ throw new Error('--root requires a directory argument');
55
+ root = next;
56
+ i += 1;
57
+ }
58
+ else if (arg === '--build-dir') {
59
+ const next = argv[i + 1];
60
+ if (!next)
61
+ throw new Error('--build-dir requires a directory argument');
62
+ buildDir = next;
63
+ i += 1;
64
+ }
65
+ else if (!arg.startsWith('-') && !command) {
66
+ command = arg;
67
+ }
68
+ else {
69
+ throw new Error(`Unknown argument: ${arg}`);
70
+ }
71
+ }
72
+ return { command, root, json, strict, buildDir, help, version };
73
+ }
74
+ export async function runCli(argv, io) {
75
+ const out = io?.stdout ?? ((s) => process.stdout.write(`${s}\n`));
76
+ const err = io?.stderr ?? ((s) => process.stderr.write(`${s}\n`));
77
+ let parsed;
78
+ try {
79
+ parsed = parseCliArgs(argv);
80
+ }
81
+ catch (e) {
82
+ err(e.message);
83
+ err(USAGE);
84
+ return 2;
85
+ }
86
+ if (parsed.version) {
87
+ out(packageVersion());
88
+ return 0;
89
+ }
90
+ if (parsed.help || !parsed.command) {
91
+ out(USAGE);
92
+ return parsed.help ? 0 : 2;
93
+ }
94
+ let checks;
95
+ if (parsed.command === 'run') {
96
+ checks = undefined;
97
+ }
98
+ else if (VALID_CHECK_SET.has(parsed.command)) {
99
+ checks = [parsed.command];
100
+ }
101
+ else {
102
+ err(`Unknown command: ${parsed.command}`);
103
+ err(USAGE);
104
+ return 2;
105
+ }
106
+ let summary;
107
+ try {
108
+ summary = await runChecks({
109
+ root: parsed.root,
110
+ checks,
111
+ strict: parsed.strict,
112
+ buildDir: parsed.buildDir
113
+ });
114
+ }
115
+ catch (e) {
116
+ err(e instanceof Error ? e.message : String(e));
117
+ return 2;
118
+ }
119
+ if (parsed.json) {
120
+ out(JSON.stringify(summary, null, 2));
121
+ }
122
+ else {
123
+ out(formatSummaryText(summary));
124
+ }
125
+ return summary.passed ? 0 : 1;
126
+ }
127
+ export function isDirectEntryPoint(metaUrl, argv1) {
128
+ if (typeof argv1 !== 'string' || argv1.length === 0) {
129
+ return false;
130
+ }
131
+ try {
132
+ return realpathSync(fileURLToPath(metaUrl)) === realpathSync(argv1);
133
+ }
134
+ catch {
135
+ return false;
136
+ }
137
+ }
138
+ if (isDirectEntryPoint(import.meta.url, process.argv[1])) {
139
+ runCli(process.argv.slice(2))
140
+ .then((code) => {
141
+ process.exitCode = code;
142
+ })
143
+ .catch((error) => {
144
+ process.stderr.write(`${error.stack ?? String(error)}\n`);
145
+ process.exitCode = 1;
146
+ });
147
+ }
@@ -0,0 +1,7 @@
1
+ import type { CheckName, ResolvedBenchCheckConfig } from './types.js';
2
+ export declare const CORE_CHECKS: ReadonlyArray<CheckName>;
3
+ export declare const ALL_CHECKS: ReadonlyArray<CheckName>;
4
+ export declare const DEFAULT_FORBIDDEN_IMPORTS: ReadonlyArray<string>;
5
+ export declare const DEFAULT_ALLOWED_RUNTIME_ENTRIES: ReadonlyArray<string>;
6
+ export declare const DEFAULT_CONFIG: ResolvedBenchCheckConfig;
7
+ export declare function loadConfig(root: string): ResolvedBenchCheckConfig;