#!/usr/bin/env node // Run the Shopworthy check on a store and print what an assistant needs to know; optionally compare with an // earlier run. Node 18+ (built-in fetch), no dependencies. // // node check.mjs [--out file.json] [--compare before.json] [--base https://…] // // The base address comes from --base, then SHOPWORTHY_BASE, then the address this skill was downloaded from. import { readFile, writeFile, mkdir } from 'node:fs/promises'; import path from 'node:path'; const DEFAULT_BASE = 'https://www.shopworthy.ai'; const ORDER = { fail: 0, warn: 1, unknown: 2, info: 3, pass: 4 }; function args(argv) { const o = { url: null, out: null, compare: null, base: process.env.SHOPWORTHY_BASE || DEFAULT_BASE }; for (let i = 0; i < argv.length; i++) { const a = argv[i]; if (a === '--out') o.out = argv[++i]; else if (a === '--compare') o.compare = argv[++i]; else if (a === '--base') o.base = argv[++i]; else if (a === '-h' || a === '--help') o.help = true; else if (!a.startsWith('--')) o.url = a; } return o; } const plat = (a) => a?.storeSignals?.platform?.id || null; const line = (c) => `${c.status.toUpperCase().padEnd(7)} ${c.id.padEnd(18)} w${c.weight ?? 0} ${c.title || ''}${c.fix ? `\n fix: ${String(c.fix).slice(0, 220)}` : ''}`; function summary(a) { const out = []; if (a.inconclusive) { out.push(`INCONCLUSIVE: the site turned the checker away (${a.inconclusive.reason || 'blocked'}${a.inconclusive.status ? `, HTTP ${a.inconclusive.status}` : ''}).`); out.push('A firewall or bot rule is probably blocking assistants too. See references/platforms.md, "CDN and firewall".'); return out.join('\n'); } out.push(`${a.siteName || a.domain} ${a.finalUrl || a.url}`); out.push(`Score ${a.score}/100, grade ${a.grade}${a.coverage?.partial ? ' (partly checked)' : ''}`); out.push(`Platform: ${plat(a) || 'not detected'}${a.isStore === false ? ' · not detected as a store' : ''}`); if (a.verdict) out.push(`Verdict: ${a.verdict}`); const open = (a.checks || []).filter((c) => c.status !== 'pass' && c.status !== 'info') .sort((x, y) => (ORDER[x.status] - ORDER[y.status]) || ((y.weight || 0) - (x.weight || 0))); out.push('', open.length ? `Not passing (${open.length}), worst first:` : 'Every scored check passes.'); for (const c of open) out.push(` ${line(c)}`); const engines = a.access?.engines || []; if (engines.length) out.push('', 'Access per assistant: ' + engines.map((e) => `${e.engine} ${e.status}`).join(', ')); if ((a.fixes || []).length) { out.push('', 'Drafted fixes in the report (fixes[].content holds the file):'); for (const f of a.fixes) out.push(` ${f.id.padEnd(10)} ${f.title} → ${f.filename}${f.template ? ' (template: fill in the TODOs)' : ''}`); } return out.join('\n'); } function compare(before, after) { const out = ['', `Before → after: score ${before.score ?? '?'} (${before.grade ?? '?'}) → ${after.score ?? '?'} (${after.grade ?? '?'})`]; const prev = new Map((before.checks || []).map((c) => [c.id, c.status])); const changed = (after.checks || []).filter((c) => prev.has(c.id) && prev.get(c.id) !== c.status); if (before.coverage?.partial || after.coverage?.partial) { out.push('Note: at least one run was only partly checked (the site limited or blocked some page requests), so some differences can come from which pages were read rather than from your changes. Compare the checks you actually changed.'); } if (!changed.length) out.push('No check changed status. Caches and crawlers can lag; robots.txt changes take about a day to reach OpenAI.'); for (const c of changed) out.push(` ${c.id.padEnd(18)} ${prev.get(c.id)} → ${c.status}`); return out.join('\n'); } const o = args(process.argv.slice(2)); if (o.help || !o.url) { console.log('Usage: node check.mjs [--out file.json] [--compare before.json] [--base https://…]'); process.exit(o.help ? 0 : 1); } if (!/^https?:\/\//.test(o.base) || o.base.includes('__SHOPWORTHY')) { console.error('Set the Shopworthy address with --base or SHOPWORTHY_BASE (for example https://shopworthy.ai).'); process.exit(1); } const target = /^https?:\/\//i.test(o.url) ? o.url : `https://${o.url}`; const api = `${o.base.replace(/\/+$/, '')}/api/audit?url=${encodeURIComponent(target)}`; let audit; try { const res = await fetch(api, { headers: { accept: 'application/json' }, signal: AbortSignal.timeout(180000) }); const body = await res.json().catch(() => ({})); if (!res.ok) { console.error(`The check failed (HTTP ${res.status}): ${body.error || 'no details'}`); process.exit(1); } audit = body; } catch (e) { console.error(`Could not reach ${o.base}: ${e.message}. If this environment blocks the network, fetch ${api} with your web fetch tool instead.`); process.exit(1); } if (o.out) { await mkdir(path.dirname(path.resolve(o.out)), { recursive: true }); await writeFile(o.out, JSON.stringify(audit, null, 2)); } console.log(summary(audit)); if (o.compare) { try { console.log(compare(JSON.parse(await readFile(o.compare, 'utf8')), audit)); } catch (e) { console.error(`Could not read ${o.compare}: ${e.message}`); } } if (o.out) console.log(`\nSaved the full report to ${o.out}`);