ai-ready-audit 0.0.0-stage → 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/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/README.md +103 -2
- package/bin/ai-ready-audit.js +44 -0
- package/package.json +54 -4
- package/src/audit.js +210 -0
- package/src/bots.js +39 -0
- package/src/html.js +87 -0
- package/src/index.js +5 -0
- package/src/report.js +49 -0
- package/src/robots.js +95 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 (unreleased)
|
|
4
|
+
|
|
5
|
+
- First release: AI crawler access (robots.txt and firewall), noindex, sitemap, llms.txt, raw HTML word count, head tags, JSON-LD validity, Organization and Product schema completeness. Text, JSON and Markdown output.
|
|
6
|
+
- Re-check (4 Dec 2026): crawler list checked against OpenAI, Google, Anthropic, Perplexity, Meta, Mistral and Amazon documentation; added Storebot-Google (search), Google-Agent, meta-externalfetcher and MistralAI-User (browsing), Amazonbot; OAI-SearchBot test user agent updated to 1.4; notes that user-triggered fetchers may ignore robots.txt.
|
|
7
|
+
- Reads IETF aipref usage preferences: `Content-Usage` rules in robots.txt and the `Content-Usage` header, and the `__usage_ai-training` policy token.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ahmad Zia (https://www.ahmadzia.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,104 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ai-ready-audit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<!-- badges -->
|
|
4
|
+
[](https://www.npmjs.com/package/ai-ready-audit) [](https://github.com/MuhammadAhmadZia/ai-ready-audit/actions/workflows/ci.yml) [](LICENSE) [](skills/ai-ready-audit/SKILL.md) [](https://www.ahmadzia.com/tools/ai-ready-audit)
|
|
5
|
+
|
|
6
|
+
**Can ChatGPT, Claude, Perplexity and Google AI find, read and cite your website?** This CLI checks the things that decide it, in about ten seconds:
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npx ai-ready-audit https://your-store.com
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Built for online stores and small business sites, with extra checks for product pages.
|
|
13
|
+
|
|
14
|
+
## What it checks
|
|
15
|
+
|
|
16
|
+
| Area | Checks |
|
|
17
|
+
|---|---|
|
|
18
|
+
| **Crawler access** | robots.txt rules for 21 AI crawlers (checked against each operator's documentation, December 2026), split into search bots including Google Shopping's Storebot-Google (must allow), browsing agents such as ChatGPT-User and Google-Agent (should allow) and training bots (your choice). AI usage preferences in the IETF aipref format (`Content-Usage: train-ai=n` in robots.txt or as a header, and the `__usage_ai-training` token). Firewall or CDN rules that return 403 or a challenge to AI crawlers. `noindex` tags and headers. XML sitemap. |
|
|
19
|
+
| **Readable content** | How many words exist in the raw HTML before JavaScript runs. Most AI crawlers do not run JavaScript, so a React or Vite shell looks empty to them. `llms.txt` presence and format. H1 structure. |
|
|
20
|
+
| **Meta tags** | Title, meta description, canonical (including www vs non-www mismatch), `lang`, Open Graph. |
|
|
21
|
+
| **Structured data** | JSON-LD validity, Organization / OnlineStore / Person on the home page with `sameAs`, Product schema completeness (name, image, brand, sku or gtin, price, currency, availability), FAQPage. |
|
|
22
|
+
|
|
23
|
+
Training crawlers (GPTBot, ClaudeBot, Google-Extended, CCBot and others) are reported as a note, not an error. Blocking them is a business decision and does not remove you from AI search. Blocking the search crawlers (OAI-SearchBot, Claude-SearchBot, PerplexityBot, Googlebot, Bingbot) does.
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# home page and a product page in one run
|
|
29
|
+
npx ai-ready-audit https://your-store.com https://your-store.com/products/best-seller
|
|
30
|
+
|
|
31
|
+
# save a Markdown report for a client
|
|
32
|
+
npx ai-ready-audit https://your-store.com --md ai-readiness.md
|
|
33
|
+
|
|
34
|
+
# skip the firewall test
|
|
35
|
+
npx ai-ready-audit https://your-store.com --no-firewall
|
|
36
|
+
|
|
37
|
+
# CI: fail if any page scores under 80
|
|
38
|
+
npx ai-ready-audit https://staging.your-store.com --min-score 80
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
| Option | What it does |
|
|
42
|
+
|---|---|
|
|
43
|
+
| `--json` | Machine-readable output |
|
|
44
|
+
| `--md <file>` | Also write a Markdown report |
|
|
45
|
+
| `--no-firewall` | Do not request the page with AI crawler user agents |
|
|
46
|
+
| `--min-score <n>` | Exit code 1 if any page scores below `n` |
|
|
47
|
+
|
|
48
|
+
### From code
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
import { audit, summarize } from 'ai-ready-audit';
|
|
52
|
+
|
|
53
|
+
const result = await audit('https://your-store.com');
|
|
54
|
+
console.log(summarize(result.findings).score);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Good to know (December 2026)
|
|
58
|
+
|
|
59
|
+
- **ChatGPT-User and Google-Agent may ignore robots.txt** when a person asks for your page: OpenAI says robots.txt rules "may not apply" to user-initiated actions, and Google says its user-triggered fetchers generally ignore them. A robots.txt block on them may not work; the report says so.
|
|
60
|
+
- **Storebot-Google** is the crawler for every Google Shopping surface. Blocking it removes products from Shopping, so it is treated like a search crawler.
|
|
61
|
+
- **One standard training opt-out is coming.** The IETF AI Preferences working group is standardising `Content-Usage: train-ai=n` (robots.txt or HTTP header), and Google says it intends to honour a robots.txt `__usage_ai-training` group from early 2027. Both are drafts: the report shows what your site states, and suggests keeping per-bot rules meanwhile.
|
|
62
|
+
|
|
63
|
+
## Sustainable Development Goals
|
|
64
|
+
|
|
65
|
+
This tool supports **SDG target 8.3**: development-oriented policies that encourage the growth of micro, small and medium-sized enterprises. More shopping starts in AI assistants every month, and small stores are the ones most likely to be invisible there because of a default firewall setting or a JavaScript-only page. A free check that names the exact cause gives them the same access to AI discovery that large retailers pay agencies for. It also supports **target 9.c** (access to information and communications technology) indirectly, by keeping small businesses reachable through the new channels people use to find information online.
|
|
66
|
+
|
|
67
|
+
## About the firewall test
|
|
68
|
+
|
|
69
|
+
The tool requests your page three more times with the user agents of OAI-SearchBot, Claude-SearchBot and PerplexityBot. If those requests get a 403, 429, 503 or a challenge page while a normal request works, your CDN or security plugin is probably blocking AI search. Real crawlers also come from published IP ranges, and some firewalls allow them by IP, so confirm in your server logs before changing rules.
|
|
70
|
+
|
|
71
|
+
## Fixing what it finds
|
|
72
|
+
|
|
73
|
+
There is a matching agent skill, **ai-ready-audit**, with copy-ready robots.txt, llms.txt and JSON-LD templates. It lets Claude, ChatGPT, Codex or Cursor fix the issues for you:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
npx skills add MuhammadAhmadZia/ai-ready-audit --skill ai-ready-audit
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Using Astro? [astro-ai-ready](https://www.npmjs.com/package/astro-ai-ready) generates `llms.txt` and `llms-full.txt` from your built pages automatically.
|
|
80
|
+
|
|
81
|
+
## About
|
|
82
|
+
|
|
83
|
+
Built by [Ahmad Zia](https://www.ahmadzia.com), an AI and e-commerce consultant who helps stores get found in AI search. MIT licensed.
|
|
84
|
+
|
|
85
|
+
<!-- ahmadzia-links -->
|
|
86
|
+
## Guide, help and author
|
|
87
|
+
|
|
88
|
+
- **Full guide with examples and FAQs:** [www.ahmadzia.com/tools/ai-ready-audit](https://www.ahmadzia.com/tools/ai-ready-audit)
|
|
89
|
+
- **Background reading:** [AI visibility for online stores: what gets you cited](https://www.ahmadzia.com/blog/ai-visibility-llms-txt-ai-crawlers)
|
|
90
|
+
- **All 30 free tools and agent skills:** [ahmadzia.com/tools](https://www.ahmadzia.com/tools) · [ahmadzia.com/skills](https://www.ahmadzia.com/skills)
|
|
91
|
+
- **Want it set up, fixed or tuned for your store?** [Book a free call](https://www.ahmadzia.com/contact)
|
|
92
|
+
|
|
93
|
+
Built by **[Ahmad Zia](https://www.ahmadzia.com)** (Muhammad Ahmad Zia), an AI consultant for ecommerce since 2020 and green AI researcher at the University of Lahore. [Research](https://www.ahmadzia.com/research) · [Google Scholar](https://scholar.google.com/citations?user=sqjdX2EAAAAJ&hl=en) · [ORCID](https://orcid.org/0000-0002-3208-6246) · [LinkedIn](https://www.linkedin.com/in/muhammad-ahmadzia/) · [GitHub](https://github.com/MuhammadAhmadZia)
|
|
94
|
+
<!-- /ahmadzia-links -->
|
|
95
|
+
|
|
96
|
+
## More AI search and agent readiness tools
|
|
97
|
+
|
|
98
|
+
- [ai-traffic-insights](https://github.com/MuhammadAhmadZia/ai-traffic-insights): See what ChatGPT, Claude and Perplexity actually do on your site, from your own logs
|
|
99
|
+
- [agentic-commerce-readiness](https://github.com/MuhammadAhmadZia/agentic-commerce-readiness): Get your store ready for ChatGPT shopping and AI shopping agents
|
|
100
|
+
- [webmcp-store-tools](https://github.com/MuhammadAhmadZia/webmcp-store-tools): WebMCP tools for WooCommerce and headless stores, plus a checker for any WebMCP site
|
|
101
|
+
- [astro-ai-ready](https://github.com/MuhammadAhmadZia/astro-ai-ready): Generate llms.txt and llms-full.txt for any Astro site on every build
|
|
102
|
+
- [astro-seo-check](https://github.com/MuhammadAhmadZia/astro-seo-check): Catch SEO mistakes in Astro and static sites at build time
|
|
103
|
+
|
|
104
|
+
All 30 tools and agent skills: [github.com/MuhammadAhmadZia](https://github.com/MuhammadAhmadZia) · [ahmadzia.com/tools](https://www.ahmadzia.com/tools)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { writeFile } from 'node:fs/promises';
|
|
3
|
+
import { audit, summarize, formatText, formatMarkdown } from '../src/index.js';
|
|
4
|
+
|
|
5
|
+
const HELP = `ai-ready-audit - can ChatGPT, Claude, Perplexity and Google AI read and cite your site?
|
|
6
|
+
|
|
7
|
+
Usage:
|
|
8
|
+
npx ai-ready-audit <url> [more urls...]
|
|
9
|
+
|
|
10
|
+
Tip: audit your home page AND one product or service page.
|
|
11
|
+
|
|
12
|
+
Options:
|
|
13
|
+
--json Print JSON
|
|
14
|
+
--md <file> Also save a Markdown report
|
|
15
|
+
--no-firewall Skip the test that requests the page as AI crawlers
|
|
16
|
+
--min-score <n> Exit 1 if any page scores below n (for CI)
|
|
17
|
+
-h, --help Show this help`;
|
|
18
|
+
|
|
19
|
+
const args = process.argv.slice(2);
|
|
20
|
+
const opts = { urls: [], firewall: true };
|
|
21
|
+
for (let i = 0; i < args.length; i++) {
|
|
22
|
+
const a = args[i];
|
|
23
|
+
if (a === '-h' || a === '--help') { console.log(HELP); process.exit(0); }
|
|
24
|
+
else if (a === '--json') opts.json = true;
|
|
25
|
+
else if (a === '--md') opts.md = args[++i];
|
|
26
|
+
else if (a === '--no-firewall') opts.firewall = false;
|
|
27
|
+
else if (a === '--min-score') opts.minScore = Number(args[++i]);
|
|
28
|
+
else opts.urls.push(a);
|
|
29
|
+
}
|
|
30
|
+
if (!opts.urls.length) { console.log(HELP); process.exit(1); }
|
|
31
|
+
|
|
32
|
+
const results = [];
|
|
33
|
+
for (const u of opts.urls) {
|
|
34
|
+
try {
|
|
35
|
+
results.push(await audit(u, { firewallTest: opts.firewall, log: opts.json ? () => {} : (m) => console.error(`> ${m}`) }));
|
|
36
|
+
} catch (e) {
|
|
37
|
+
console.error(`Could not audit ${u}: ${e.message}`);
|
|
38
|
+
process.exitCode = 2;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (opts.json) console.log(JSON.stringify(results.map((r) => ({ ...r, summary: summarize(r.findings) })), null, 2));
|
|
42
|
+
else results.forEach((r) => console.log(formatText(r)));
|
|
43
|
+
if (opts.md) await writeFile(opts.md, results.map(formatMarkdown).join('\n---\n\n'));
|
|
44
|
+
if (opts.minScore !== undefined && results.some((r) => summarize(r.findings).score < opts.minScore)) process.exitCode = 1;
|
package/package.json
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai-ready-audit",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Checks if ChatGPT, Claude, Perplexity and Google AI can find, read and cite your website or store: AI crawler access in robots.txt and your firewall, llms.txt, sitemap, server-rendered content, JSON-LD schema (Product, Organization, FAQ) and meta tags.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"ai-ready-audit": "bin/ai-ready-audit.js"
|
|
8
|
+
},
|
|
9
|
+
"main": "src/index.js",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": "./src/index.js"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"bin",
|
|
15
|
+
"src",
|
|
16
|
+
"README.md",
|
|
17
|
+
"LICENSE",
|
|
18
|
+
"CHANGELOG.md"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"test": "node --test test/*.test.js"
|
|
22
|
+
},
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=18.17"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"geo",
|
|
28
|
+
"aeo",
|
|
29
|
+
"ai-seo",
|
|
30
|
+
"llms.txt",
|
|
31
|
+
"robots.txt",
|
|
32
|
+
"gptbot",
|
|
33
|
+
"chatgpt",
|
|
34
|
+
"claude",
|
|
35
|
+
"perplexity",
|
|
36
|
+
"schema.org",
|
|
37
|
+
"json-ld",
|
|
38
|
+
"ecommerce",
|
|
39
|
+
"product-schema",
|
|
40
|
+
"ai-search",
|
|
41
|
+
"seo-audit"
|
|
42
|
+
],
|
|
43
|
+
"author": {
|
|
44
|
+
"name": "Ahmad Zia (Muhammad Ahmad Zia)",
|
|
45
|
+
"url": "https://www.ahmadzia.com"
|
|
46
|
+
},
|
|
47
|
+
"license": "MIT",
|
|
48
|
+
"homepage": "https://www.ahmadzia.com/tools/ai-ready-audit",
|
|
49
|
+
"repository": {
|
|
50
|
+
"type": "git",
|
|
51
|
+
"url": "git+https://github.com/MuhammadAhmadZia/ai-ready-audit.git"
|
|
52
|
+
},
|
|
53
|
+
"bugs": {
|
|
54
|
+
"url": "https://github.com/MuhammadAhmadZia/ai-ready-audit/issues"
|
|
55
|
+
}
|
|
56
|
+
}
|
package/src/audit.js
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { parseRobots, isAllowed, groupFor, aiPreferences } from './robots.js';
|
|
2
|
+
import { AI_BOTS, FIREWALL_TEST_AGENTS } from './bots.js';
|
|
3
|
+
import { getTitle, getMeta, getLinks, getLang, countTag, getJsonLd, typesOf, visibleText } from './html.js';
|
|
4
|
+
|
|
5
|
+
export const USER_AGENT = 'ai-ready-audit/0.1 (+https://www.ahmadzia.com/tools/ai-ready-audit)';
|
|
6
|
+
|
|
7
|
+
async function get(url, { ua = USER_AGENT, timeoutMs = 15000 } = {}) {
|
|
8
|
+
const res = await fetch(url, { headers: { 'user-agent': ua, accept: 'text/html,application/xhtml+xml,text/plain,*/*' }, redirect: 'follow', signal: AbortSignal.timeout(timeoutMs) });
|
|
9
|
+
const text = await res.text();
|
|
10
|
+
return { status: res.status, headers: res.headers, text: text.slice(0, 5_000_000), url: res.url || url };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const PRODUCT_HINTS = /(add[\s-]to[\s-](cart|bag|basket)|buy now|in stock|out of stock|og:type"?\s+content="product|product:price)/i;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Audit one page (usually the home page or a product page) plus site-level files.
|
|
17
|
+
* Returns { target, findings, passes, notes, categories }
|
|
18
|
+
*/
|
|
19
|
+
export async function audit(inputUrl, { timeoutMs = 15000, firewallTest = true, log = () => {} } = {}) {
|
|
20
|
+
let url = /^https?:\/\//i.test(inputUrl) ? inputUrl : 'https://' + inputUrl;
|
|
21
|
+
const findings = [];
|
|
22
|
+
const passes = [];
|
|
23
|
+
const notes = [];
|
|
24
|
+
const add = (category, severity, title, fix, evidence) => findings.push({ category, severity, title, fix, evidence });
|
|
25
|
+
const pass = (category, title) => passes.push({ category, title });
|
|
26
|
+
|
|
27
|
+
log(`Fetching ${url}`);
|
|
28
|
+
const page = await get(url, { timeoutMs });
|
|
29
|
+
url = page.url;
|
|
30
|
+
const origin = new URL(url).origin;
|
|
31
|
+
const path = new URL(url).pathname || '/';
|
|
32
|
+
if (page.status >= 400) {
|
|
33
|
+
add('access', 'critical', `Page returned HTTP ${page.status} to a normal request`, 'Make sure the page is public and returns 200.');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// ---------- robots.txt ----------
|
|
37
|
+
let robots = null;
|
|
38
|
+
try {
|
|
39
|
+
const r = await get(`${origin}/robots.txt`, { timeoutMs });
|
|
40
|
+
if (r.status === 200 && !/<html/i.test(r.text.slice(0, 300))) robots = parseRobots(r.text);
|
|
41
|
+
} catch { /* ignore */ }
|
|
42
|
+
|
|
43
|
+
if (!robots) {
|
|
44
|
+
add('access', 'low', 'No robots.txt found', 'Add a robots.txt that allows AI search crawlers and lists your sitemap. Without it, crawlers assume everything is allowed, which is fine, but you lose the Sitemap hint.');
|
|
45
|
+
} else {
|
|
46
|
+
const blockedSearch = [];
|
|
47
|
+
const blockedUser = [];
|
|
48
|
+
const blockedTraining = [];
|
|
49
|
+
for (const bot of AI_BOTS) {
|
|
50
|
+
if (!isAllowed(robots, bot.token, path)) {
|
|
51
|
+
if (bot.kind === 'search') blockedSearch.push(bot);
|
|
52
|
+
else if (bot.kind === 'user') blockedUser.push(bot);
|
|
53
|
+
else blockedTraining.push(bot);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (blockedSearch.length) {
|
|
57
|
+
add('access', 'critical', `robots.txt blocks AI search crawlers: ${blockedSearch.map((b) => b.token).join(', ')}`,
|
|
58
|
+
'These bots build the index that ChatGPT, Claude, Perplexity and Google AI answers cite. Add "User-agent: <bot>" + "Allow: /" groups for them, or remove the blanket Disallow.',
|
|
59
|
+
blockedSearch.map((b) => b.owner).join('; '));
|
|
60
|
+
} else pass('access', 'robots.txt lets AI search crawlers in');
|
|
61
|
+
if (blockedUser.length) {
|
|
62
|
+
const ignores = blockedUser.filter((b) => b.userTriggered).map((b) => b.token);
|
|
63
|
+
add('access', 'high', `robots.txt blocks AI browsing agents: ${blockedUser.map((b) => b.token).join(', ')}`,
|
|
64
|
+
`These agents fetch your page when a user pastes your link or asks about you. Allow them unless you have a reason not to.${ignores.length ? ` Note: the operators say robots.txt may not apply to ${ignores.join(' and ')} for pages a person asks for, so this rule may not even work; use your firewall if you really want them out.` : ''}`);
|
|
65
|
+
}
|
|
66
|
+
const ap = aiPreferences(robots, path);
|
|
67
|
+
const stated = Object.entries(ap.contentUsage).map(([k, v]) => `${k}=${v}`);
|
|
68
|
+
if (stated.length) notes.push(`robots.txt states AI usage preferences (IETF aipref draft): ${stated.join(', ')}.${ap.contentUsage.search === 'n' ? ' search=n asks AI search not to use your pages: that can keep you out of AI answers.' : ''}`);
|
|
69
|
+
if (ap.trainingToken) notes.push(`robots.txt uses the __usage_ai-training token: AI training ${ap.trainingToken} for this page (Google says it intends to honour this signal from early 2027).`);
|
|
70
|
+
if (!stated.length && !ap.trainingToken && blockedTraining.length) notes.push('You block training crawlers one by one. The IETF is standardising one machine-readable preference instead (Content-Usage: train-ai=n in robots.txt or as an HTTP header); it is still a draft, so keep the per-bot rules as well.');
|
|
71
|
+
if (blockedTraining.length) {
|
|
72
|
+
notes.push(`Training crawlers blocked by robots.txt (your choice, does not affect AI search): ${blockedTraining.map((b) => b.token).join(', ')}.`);
|
|
73
|
+
}
|
|
74
|
+
const wildcard = groupFor(robots, 'SomeUnknownBot');
|
|
75
|
+
if (wildcard.rules.some((r) => !r.allow && r.path === '/')) {
|
|
76
|
+
notes.push('robots.txt disallows everything for "*". Only bots with their own Allow group can read the site.');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// ---------- firewall / WAF test ----------
|
|
81
|
+
if (firewallTest && page.status < 400) {
|
|
82
|
+
const blocked = [];
|
|
83
|
+
for (const a of FIREWALL_TEST_AGENTS) {
|
|
84
|
+
try {
|
|
85
|
+
const r = await get(url, { ua: a.ua, timeoutMs });
|
|
86
|
+
if (r.status === 403 || r.status === 401 || r.status === 429 || r.status === 503 || /cf-challenge|challenge-platform|captcha/i.test(r.text.slice(0, 20000))) {
|
|
87
|
+
blocked.push(`${a.token} (HTTP ${r.status})`);
|
|
88
|
+
}
|
|
89
|
+
} catch { /* ignore */ }
|
|
90
|
+
}
|
|
91
|
+
if (blocked.length) {
|
|
92
|
+
add('access', 'high', `Your server or CDN rejects requests that identify as AI crawlers: ${blocked.join(', ')}`,
|
|
93
|
+
'Check Cloudflare (Security > Bots, "Block AI bots"), Vercel firewall or your security plugin. Allow verified AI search bots. Note: real bots come from published IP ranges, so confirm in your server logs.');
|
|
94
|
+
} else pass('access', 'Server answers AI crawler user agents normally');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// ---------- noindex / noai ----------
|
|
98
|
+
const meta = getMeta(page.text);
|
|
99
|
+
const robotsMeta = `${meta.robots || ''} ${page.headers.get('x-robots-tag') || ''}`.toLowerCase();
|
|
100
|
+
if (/noindex/.test(robotsMeta)) add('access', 'critical', 'Page is marked noindex', 'Remove noindex from the robots meta tag or X-Robots-Tag header if you want this page found.');
|
|
101
|
+
if (/\bnoai\b|noimageai/.test(robotsMeta)) notes.push('Page uses noai/noimageai directives. These are not standard and most AI systems ignore them; the IETF aipref Content-Usage header (still a draft) is the emerging standard way.');
|
|
102
|
+
const cu = page.headers.get('content-usage');
|
|
103
|
+
if (cu) notes.push(`Page sends Content-Usage: ${cu} (IETF aipref draft).`);
|
|
104
|
+
|
|
105
|
+
// ---------- llms.txt ----------
|
|
106
|
+
try {
|
|
107
|
+
const l = await get(`${origin}/llms.txt`, { timeoutMs });
|
|
108
|
+
if (l.status === 200 && !/<html|<!doctype/i.test(l.text.slice(0, 300)) && l.text.trim().length > 20) {
|
|
109
|
+
const hasH1 = /^#\s+\S/m.test(l.text);
|
|
110
|
+
const links = (l.text.match(/\[[^\]]+\]\([^)]+\)/g) || []).length;
|
|
111
|
+
if (!hasH1) add('content', 'low', 'llms.txt exists but does not start with a "# Site name" heading', 'Follow the llms.txt format: an H1 with the site name, a > summary line, then sections of markdown links.');
|
|
112
|
+
else if (!links) add('content', 'low', 'llms.txt has no markdown links to your key pages', 'List your most important pages as [Title](url): description lines so AI agents can find them quickly.');
|
|
113
|
+
else pass('content', `llms.txt present with ${links} link(s)`);
|
|
114
|
+
} else {
|
|
115
|
+
add('content', 'medium', 'No llms.txt file', 'Add /llms.txt: a short markdown guide to your site (name, one-line summary, links to key pages, products and policies). It costs nothing and helps AI agents. For Astro sites, see the astro-ai-ready package.');
|
|
116
|
+
}
|
|
117
|
+
} catch { /* ignore */ }
|
|
118
|
+
|
|
119
|
+
// ---------- sitemap ----------
|
|
120
|
+
const sitemapUrls = robots?.sitemaps?.length ? robots.sitemaps : [`${origin}/sitemap.xml`, `${origin}/sitemap-index.xml`, `${origin}/sitemap_index.xml`];
|
|
121
|
+
let sitemapOk = false;
|
|
122
|
+
for (const s of sitemapUrls.slice(0, 3)) {
|
|
123
|
+
try {
|
|
124
|
+
const r = await get(s, { timeoutMs });
|
|
125
|
+
if (r.status === 200 && /<(urlset|sitemapindex)\b/i.test(r.text)) { sitemapOk = true; break; }
|
|
126
|
+
} catch { /* ignore */ }
|
|
127
|
+
}
|
|
128
|
+
if (sitemapOk) pass('access', 'XML sitemap found');
|
|
129
|
+
else add('access', 'medium', 'No XML sitemap found', 'Publish /sitemap.xml and list it in robots.txt with a "Sitemap:" line. Submit it to Bing Webmaster Tools too, since ChatGPT search leans on Bing.');
|
|
130
|
+
|
|
131
|
+
// ---------- server-rendered content ----------
|
|
132
|
+
const text = visibleText(page.text);
|
|
133
|
+
const words = text ? text.split(' ').length : 0;
|
|
134
|
+
if (words < 50) {
|
|
135
|
+
add('content', 'critical', `Only ${words} words of text in the raw HTML`, 'Most AI crawlers do not run JavaScript, so they see an empty page. Use server-side rendering or static generation (Next.js, Astro, Nuxt), or prerender key pages.');
|
|
136
|
+
} else if (words < 150) {
|
|
137
|
+
add('content', 'medium', `Thin raw HTML: ${words} words before JavaScript runs`, 'Make sure product descriptions, prices and key copy are in the server HTML, not loaded later by JavaScript.');
|
|
138
|
+
} else pass('content', `${words} words readable without JavaScript`);
|
|
139
|
+
|
|
140
|
+
// ---------- head tags ----------
|
|
141
|
+
const title = getTitle(page.text);
|
|
142
|
+
if (!title) add('meta', 'high', 'Missing <title>', 'Add a unique, descriptive title (about 50 to 60 characters).');
|
|
143
|
+
else if (title.length > 70) add('meta', 'low', `Title is long (${title.length} characters)`, 'Keep titles under about 60 characters so they are not cut off.');
|
|
144
|
+
else pass('meta', 'Title present');
|
|
145
|
+
const desc = meta.description;
|
|
146
|
+
if (!desc) add('meta', 'medium', 'Missing meta description', 'Add a 120 to 160 character description. AI answers and search snippets often reuse it.');
|
|
147
|
+
else pass('meta', 'Meta description present');
|
|
148
|
+
const canonical = getLinks(page.text).find((l) => l.rel.split(/\s+/).includes('canonical'));
|
|
149
|
+
if (!canonical) add('meta', 'low', 'No canonical link', 'Add <link rel="canonical" href="..."> so duplicates (www vs non-www, tracking parameters) consolidate to one URL.');
|
|
150
|
+
else {
|
|
151
|
+
try {
|
|
152
|
+
const c = new URL(canonical.href, url);
|
|
153
|
+
if (c.host !== new URL(url).host) add('meta', 'medium', `Canonical points to a different host (${c.host})`, 'Make sure the canonical URL uses the same host you actually serve (watch www vs non-www).');
|
|
154
|
+
else pass('meta', 'Canonical link present');
|
|
155
|
+
} catch { add('meta', 'low', 'Canonical link has an invalid URL', 'Fix the href of the canonical link.'); }
|
|
156
|
+
}
|
|
157
|
+
if (!getLang(page.text)) add('meta', 'low', 'No lang attribute on <html>', 'Add <html lang="en"> (or your language) so AI systems know the content language.');
|
|
158
|
+
const h1 = countTag(page.text, 'h1');
|
|
159
|
+
if (h1 === 0) add('content', 'medium', 'No <h1> heading in the HTML', 'Give each page one clear H1 that says what the page is about.');
|
|
160
|
+
else if (h1 > 1) add('content', 'low', `${h1} <h1> headings`, 'Use one H1 per page and H2/H3 for sections.');
|
|
161
|
+
else pass('content', 'One H1 heading');
|
|
162
|
+
const og = ['og:title', 'og:description', 'og:image'].filter((k) => !meta[k]);
|
|
163
|
+
if (og.length) add('meta', 'low', `Missing Open Graph tags: ${og.join(', ')}`, 'Add Open Graph tags so links shared in chats, social apps and AI tools show a proper preview.');
|
|
164
|
+
else pass('meta', 'Open Graph tags present');
|
|
165
|
+
|
|
166
|
+
// ---------- structured data ----------
|
|
167
|
+
const ld = getJsonLd(page.text);
|
|
168
|
+
for (const e of ld.errors) add('schema', 'high', 'Invalid JSON-LD', 'Fix the JSON syntax. Invalid blocks are ignored completely.', e);
|
|
169
|
+
const types = new Set(ld.items.flatMap(typesOf));
|
|
170
|
+
if (!ld.blocks) {
|
|
171
|
+
add('schema', 'high', 'No JSON-LD structured data', 'Add schema.org JSON-LD. At minimum Organization (or Person) and WebSite on the home page, and Product with Offer on product pages.');
|
|
172
|
+
} else {
|
|
173
|
+
pass('schema', `JSON-LD found: ${[...types].join(', ') || 'no @type'}`);
|
|
174
|
+
const isHome = path === '/' || path === '';
|
|
175
|
+
if (isHome && !['Organization', 'OnlineStore', 'Store', 'LocalBusiness', 'Person', 'Corporation'].some((t) => types.has(t))) {
|
|
176
|
+
add('schema', 'medium', 'Home page has no Organization, Store or Person schema', 'Describe who runs the site with Organization (or OnlineStore / Person), including name, url, logo and sameAs links to your social and marketplace profiles.');
|
|
177
|
+
}
|
|
178
|
+
const org = ld.items.find((n) => typesOf(n).some((t) => ['Organization', 'OnlineStore', 'Store', 'LocalBusiness', 'Person', 'Corporation'].includes(t)));
|
|
179
|
+
if (org && !org.sameAs) add('schema', 'low', `${typesOf(org)[0]} schema has no sameAs links`, 'Add sameAs links (LinkedIn, Instagram, Amazon or Daraz store, Wikidata) so AI systems can connect your brand across the web.');
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const looksLikeProduct = PRODUCT_HINTS.test(page.text) || (meta['og:type'] || '').toLowerCase() === 'product';
|
|
183
|
+
const products = ld.items.filter((n) => typesOf(n).includes('Product') || typesOf(n).includes('ProductGroup'));
|
|
184
|
+
if (looksLikeProduct && !products.length) {
|
|
185
|
+
add('schema', 'high', 'Looks like a product page but has no Product schema', 'Add Product JSON-LD with name, image, description, brand, sku or gtin, and offers (price, priceCurrency, availability). AI shopping answers rely on it.');
|
|
186
|
+
}
|
|
187
|
+
for (const p of products) {
|
|
188
|
+
const name = p.name || 'Product';
|
|
189
|
+
const offers = Array.isArray(p.offers) ? p.offers[0] : p.offers;
|
|
190
|
+
const missing = [];
|
|
191
|
+
if (!p.name) missing.push('name');
|
|
192
|
+
if (!p.image) missing.push('image');
|
|
193
|
+
if (!p.description) missing.push('description');
|
|
194
|
+
if (!p.brand) missing.push('brand');
|
|
195
|
+
if (!p.sku && !p.gtin && !p.gtin13 && !p.gtin12 && !p.gtin8 && !p.mpn) missing.push('sku or gtin');
|
|
196
|
+
if (!offers) missing.push('offers');
|
|
197
|
+
else {
|
|
198
|
+
if (offers.price === undefined && offers.lowPrice === undefined) missing.push('offers.price');
|
|
199
|
+
if (!offers.priceCurrency) missing.push('offers.priceCurrency');
|
|
200
|
+
if (!offers.availability) missing.push('offers.availability');
|
|
201
|
+
}
|
|
202
|
+
if (missing.length) add('schema', missing.some((m) => m.startsWith('offers')) ? 'high' : 'medium', `Product schema for "${name}" is missing: ${missing.join(', ')}`, 'Complete these fields. Price, currency and availability are what AI shopping results show.');
|
|
203
|
+
else pass('schema', `Product schema for "${name}" is complete`);
|
|
204
|
+
if (!p.aggregateRating && !p.review) notes.push(`"${name}" has no aggregateRating or review in schema. Add them if you show real reviews on the page.`);
|
|
205
|
+
}
|
|
206
|
+
if (types.has('FAQPage')) pass('schema', 'FAQPage schema present');
|
|
207
|
+
else notes.push('No FAQPage schema. If the page answers common questions, mark them up; AI answers often quote FAQ content.');
|
|
208
|
+
|
|
209
|
+
return { target: url, findings, passes, notes };
|
|
210
|
+
}
|
package/src/bots.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// AI crawler tokens grouped by what blocking them costs you.
|
|
2
|
+
// search: builds the index AI answers cite from. Blocking = you disappear from AI search.
|
|
3
|
+
// user: fetches a page when a user asks about it. Blocking = AI cannot read your page on request.
|
|
4
|
+
// training: collects model training data. Blocking is a business choice, not an error.
|
|
5
|
+
// Checked against each operator's own crawler documentation on 4 Dec 2026.
|
|
6
|
+
// userTriggered: the operator says robots.txt may not apply when a person asks for the page
|
|
7
|
+
// (OpenAI for ChatGPT-User, Google for its user-triggered fetchers including Google-Agent).
|
|
8
|
+
export const AI_BOTS = [
|
|
9
|
+
{ token: 'OAI-SearchBot', owner: 'OpenAI (ChatGPT search)', kind: 'search' },
|
|
10
|
+
{ token: 'ChatGPT-User', owner: 'OpenAI (ChatGPT browsing)', kind: 'user', userTriggered: true },
|
|
11
|
+
{ token: 'GPTBot', owner: 'OpenAI (training)', kind: 'training' },
|
|
12
|
+
{ token: 'Claude-SearchBot', owner: 'Anthropic (Claude search)', kind: 'search' },
|
|
13
|
+
{ token: 'Claude-User', owner: 'Anthropic (Claude browsing)', kind: 'user' },
|
|
14
|
+
{ token: 'ClaudeBot', owner: 'Anthropic (training)', kind: 'training' },
|
|
15
|
+
{ token: 'PerplexityBot', owner: 'Perplexity (search)', kind: 'search' },
|
|
16
|
+
{ token: 'Perplexity-User', owner: 'Perplexity (browsing)', kind: 'user' },
|
|
17
|
+
{ token: 'Googlebot', owner: 'Google Search, AI Overviews and AI Mode', kind: 'search' },
|
|
18
|
+
{ token: 'Storebot-Google', owner: 'Google Shopping (all surfaces, including the Shopping tab)', kind: 'search', store: true },
|
|
19
|
+
{ token: 'Google-Agent', owner: 'Google agents acting for a user', kind: 'user', userTriggered: true },
|
|
20
|
+
{ token: 'Google-Extended', owner: 'Google (Gemini training and grounding)', kind: 'training' },
|
|
21
|
+
{ token: 'Bingbot', owner: 'Microsoft Bing and Copilot', kind: 'search' },
|
|
22
|
+
{ token: 'DuckAssistBot', owner: 'DuckDuckGo AI answers', kind: 'search' },
|
|
23
|
+
{ token: 'Applebot', owner: 'Apple (Siri, Spotlight)', kind: 'search' },
|
|
24
|
+
{ token: 'Applebot-Extended', owner: 'Apple (AI training)', kind: 'training' },
|
|
25
|
+
{ token: 'meta-externalagent', owner: 'Meta (AI training and indexing)', kind: 'training' },
|
|
26
|
+
{ token: 'meta-externalfetcher', owner: 'Meta AI (fetches a page a user asked about)', kind: 'user' },
|
|
27
|
+
{ token: 'MistralAI-User', owner: 'Mistral Le Chat (browsing)', kind: 'user' },
|
|
28
|
+
{ token: 'Amazonbot', owner: 'Amazon (Alexa and other Amazon services)', kind: 'training' },
|
|
29
|
+
{ token: 'CCBot', owner: 'Common Crawl (open dataset used by many models)', kind: 'training' },
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
// Representative user-agent strings used for the firewall test. Real bots also come from
|
|
33
|
+
// published IP ranges, so a block here is a strong hint, not proof.
|
|
34
|
+
export const FIREWALL_TEST_AGENTS = [
|
|
35
|
+
{ token: 'OAI-SearchBot', ua: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36; compatible; OAI-SearchBot/1.4; +https://openai.com/searchbot' },
|
|
36
|
+
{ token: 'ChatGPT-User', ua: 'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko); compatible; ChatGPT-User/1.0; +https://openai.com/bot' },
|
|
37
|
+
{ token: 'Claude-SearchBot', ua: 'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Claude-SearchBot/1.0; +https://www.anthropic.com)' },
|
|
38
|
+
{ token: 'PerplexityBot', ua: 'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; PerplexityBot/1.0; +https://perplexity.ai/perplexitybot)' },
|
|
39
|
+
];
|
package/src/html.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Small, dependency-free HTML helpers. Good enough for auditing <head> tags and JSON-LD.
|
|
2
|
+
|
|
3
|
+
const decode = (s) => s
|
|
4
|
+
.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
|
5
|
+
.replace(/"/g, '"').replace(/'|'/g, "'").replace(/ /g, ' ');
|
|
6
|
+
|
|
7
|
+
function attr(tag, name) {
|
|
8
|
+
const m = new RegExp(`\\b${name}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`, 'i').exec(tag);
|
|
9
|
+
return m ? decode(m[1] ?? m[2] ?? m[3] ?? '') : null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function getTitle(html) {
|
|
13
|
+
const m = /<title[^>]*>([\s\S]*?)<\/title>/i.exec(html);
|
|
14
|
+
return m ? decode(m[1]).trim() : null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function getMeta(html) {
|
|
18
|
+
const out = {};
|
|
19
|
+
const re = /<meta\b[^>]*>/gi;
|
|
20
|
+
let m;
|
|
21
|
+
while ((m = re.exec(html)) !== null) {
|
|
22
|
+
const key = (attr(m[0], 'name') || attr(m[0], 'property') || '').toLowerCase();
|
|
23
|
+
const content = attr(m[0], 'content');
|
|
24
|
+
if (key && content !== null && !(key in out)) out[key] = content;
|
|
25
|
+
}
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function getLinks(html) {
|
|
30
|
+
const out = [];
|
|
31
|
+
const re = /<link\b[^>]*>/gi;
|
|
32
|
+
let m;
|
|
33
|
+
while ((m = re.exec(html)) !== null) {
|
|
34
|
+
out.push({ rel: (attr(m[0], 'rel') || '').toLowerCase(), href: attr(m[0], 'href'), type: attr(m[0], 'type') });
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function getLang(html) {
|
|
40
|
+
const m = /<html\b[^>]*>/i.exec(html);
|
|
41
|
+
return m ? attr(m[0], 'lang') : null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function countTag(html, tag) {
|
|
45
|
+
return (html.match(new RegExp(`<${tag}\\b`, 'gi')) || []).length;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Parse every JSON-LD block. Returns { items: [...flattened nodes], errors: [...] } */
|
|
49
|
+
export function getJsonLd(html) {
|
|
50
|
+
const items = [];
|
|
51
|
+
const errors = [];
|
|
52
|
+
const re = /<script\b[^>]*type\s*=\s*["']application\/ld\+json["'][^>]*>([\s\S]*?)<\/script>/gi;
|
|
53
|
+
let m;
|
|
54
|
+
let i = 0;
|
|
55
|
+
while ((m = re.exec(html)) !== null) {
|
|
56
|
+
i++;
|
|
57
|
+
try {
|
|
58
|
+
const data = JSON.parse(m[1].trim());
|
|
59
|
+
flatten(data, items);
|
|
60
|
+
} catch (e) {
|
|
61
|
+
errors.push(`JSON-LD block ${i}: ${e.message}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return { items, errors, blocks: i };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function flatten(node, out) {
|
|
68
|
+
if (Array.isArray(node)) return node.forEach((n) => flatten(n, out));
|
|
69
|
+
if (!node || typeof node !== 'object') return;
|
|
70
|
+
if (node['@graph']) flatten(node['@graph'], out);
|
|
71
|
+
if (node['@type']) out.push(node);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function typesOf(node) {
|
|
75
|
+
const t = node['@type'];
|
|
76
|
+
return (Array.isArray(t) ? t : [t]).map(String);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Visible text length after removing scripts, styles, svg, noscript and tags. */
|
|
80
|
+
export function visibleText(html) {
|
|
81
|
+
const body = (/<body\b[^>]*>([\s\S]*)<\/body>/i.exec(html) || [null, html])[1];
|
|
82
|
+
return decode(body
|
|
83
|
+
.replace(/<(script|style|svg|noscript|template)\b[\s\S]*?<\/\1>/gi, ' ')
|
|
84
|
+
.replace(/<[^>]+>/g, ' '))
|
|
85
|
+
.replace(/\s+/g, ' ')
|
|
86
|
+
.trim();
|
|
87
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { audit } from './audit.js';
|
|
2
|
+
export { parseRobots, isAllowed, groupFor } from './robots.js';
|
|
3
|
+
export { AI_BOTS } from './bots.js';
|
|
4
|
+
export { getJsonLd, typesOf, visibleText, getMeta, getTitle } from './html.js';
|
|
5
|
+
export { summarize, formatText, formatMarkdown } from './report.js';
|
package/src/report.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export const SEVERITY_ORDER = ['critical', 'high', 'medium', 'low', 'info'];
|
|
2
|
+
const WEIGHTS = { critical: 20, high: 10, medium: 5, low: 2, info: 0 };
|
|
3
|
+
const LABEL = { critical: '[CRITICAL]', high: '[HIGH] ', medium: '[MEDIUM] ', low: '[LOW] ' };
|
|
4
|
+
const CATEGORY = { access: 'Crawler access', content: 'Readable content', meta: 'Meta tags', schema: 'Structured data' };
|
|
5
|
+
|
|
6
|
+
export function summarize(findings) {
|
|
7
|
+
const counts = Object.fromEntries(SEVERITY_ORDER.map((s) => [s, 0]));
|
|
8
|
+
for (const f of findings) counts[f.severity]++;
|
|
9
|
+
const score = Math.max(0, 100 - findings.reduce((s, f) => s + WEIGHTS[f.severity], 0));
|
|
10
|
+
const grade = score >= 90 ? 'A' : score >= 75 ? 'B' : score >= 60 ? 'C' : score >= 40 ? 'D' : 'F';
|
|
11
|
+
return { counts, score, grade };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const sorted = (f) => [...f].sort((a, b) => SEVERITY_ORDER.indexOf(a.severity) - SEVERITY_ORDER.indexOf(b.severity));
|
|
15
|
+
|
|
16
|
+
export function formatText(r) {
|
|
17
|
+
const { counts, score, grade } = summarize(r.findings);
|
|
18
|
+
const out = ['', `AI readiness report for ${r.target}`, `Score: ${score}/100 (grade ${grade}) critical ${counts.critical} | high ${counts.high} | medium ${counts.medium} | low ${counts.low}`, ''];
|
|
19
|
+
for (const f of sorted(r.findings)) {
|
|
20
|
+
out.push(`${LABEL[f.severity]} ${CATEGORY[f.category] || f.category}: ${f.title}`);
|
|
21
|
+
if (f.evidence) out.push(` evidence: ${f.evidence}`);
|
|
22
|
+
out.push(` fix: ${f.fix}`, '');
|
|
23
|
+
}
|
|
24
|
+
if (r.passes.length) {
|
|
25
|
+
out.push('Passed:');
|
|
26
|
+
for (const p of r.passes) out.push(` [ok] ${p.title}`);
|
|
27
|
+
out.push('');
|
|
28
|
+
}
|
|
29
|
+
if (r.notes.length) {
|
|
30
|
+
out.push('Notes:');
|
|
31
|
+
for (const n of r.notes) out.push(` - ${n}`);
|
|
32
|
+
out.push('');
|
|
33
|
+
}
|
|
34
|
+
out.push('More tools: https://www.ahmadzia.com/tools/ai-ready-audit');
|
|
35
|
+
return out.join('\n');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function formatMarkdown(r) {
|
|
39
|
+
const { counts, score, grade } = summarize(r.findings);
|
|
40
|
+
const esc = (s) => String(s || '').replace(/\|/g, '\\|');
|
|
41
|
+
const out = [`# AI readiness report: ${r.target}`, '', `**Score:** ${score}/100 (grade ${grade}) `, `**Findings:** ${counts.critical} critical, ${counts.high} high, ${counts.medium} medium, ${counts.low} low`, ''];
|
|
42
|
+
if (r.findings.length) {
|
|
43
|
+
out.push('| Severity | Area | Issue | Fix |', '|---|---|---|---|');
|
|
44
|
+
for (const f of sorted(r.findings)) out.push(`| ${f.severity} | ${CATEGORY[f.category] || f.category} | ${esc(f.title)} | ${esc(f.fix)} |`);
|
|
45
|
+
}
|
|
46
|
+
if (r.passes.length) out.push('', '## Passed', ...r.passes.map((p) => `- ${p.title}`));
|
|
47
|
+
if (r.notes.length) out.push('', '## Notes', ...r.notes.map((n) => `- ${n}`));
|
|
48
|
+
return out.join('\n') + '\n';
|
|
49
|
+
}
|
package/src/robots.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// Minimal RFC 9309 robots.txt parser and matcher.
|
|
2
|
+
|
|
3
|
+
export function parseRobots(text) {
|
|
4
|
+
const groups = [];
|
|
5
|
+
const sitemaps = [];
|
|
6
|
+
let current = null;
|
|
7
|
+
let lastWasAgent = false;
|
|
8
|
+
for (const rawLine of text.split(/\r?\n/)) {
|
|
9
|
+
const line = rawLine.replace(/#.*$/, '').trim();
|
|
10
|
+
if (!line) continue;
|
|
11
|
+
const m = /^([A-Za-z-]+)\s*:\s*(.*)$/.exec(line);
|
|
12
|
+
if (!m) continue;
|
|
13
|
+
const key = m[1].toLowerCase();
|
|
14
|
+
const value = m[2].trim();
|
|
15
|
+
if (key === 'user-agent') {
|
|
16
|
+
if (!current || !lastWasAgent) {
|
|
17
|
+
current = { agents: [], rules: [] };
|
|
18
|
+
groups.push(current);
|
|
19
|
+
}
|
|
20
|
+
current.agents.push(value.toLowerCase());
|
|
21
|
+
lastWasAgent = true;
|
|
22
|
+
} else if (key === 'allow' || key === 'disallow') {
|
|
23
|
+
if (current) current.rules.push({ allow: key === 'allow', path: value });
|
|
24
|
+
lastWasAgent = false;
|
|
25
|
+
} else if (key === 'content-usage') {
|
|
26
|
+
// IETF aipref draft (draft-ietf-aipref-attach): Content-Usage: [path] train-ai=n, search=y
|
|
27
|
+
const cm = /^(\/\S*)?\s*(.*)$/.exec(value);
|
|
28
|
+
if (current) current.usage = [...(current.usage || []), { path: cm[1] || '/', prefs: parseUsage(cm[2]) }];
|
|
29
|
+
lastWasAgent = false;
|
|
30
|
+
} else if (key === 'sitemap') {
|
|
31
|
+
sitemaps.push(value);
|
|
32
|
+
lastWasAgent = false;
|
|
33
|
+
} else {
|
|
34
|
+
lastWasAgent = false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return { groups, sitemaps };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Parse an aipref usage preference ("train-ai=n, search=y") into { label: 'y'|'n' }. */
|
|
41
|
+
export function parseUsage(text) {
|
|
42
|
+
const out = {};
|
|
43
|
+
for (const part of String(text || '').split(',')) {
|
|
44
|
+
const m = /^\s*([a-z0-9_.*-]+)\s*=\s*([yn])\b/.exec(part);
|
|
45
|
+
if (m) out[m[1]] = m[2];
|
|
46
|
+
}
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* AI usage preferences a site states in robots.txt:
|
|
52
|
+
* Content-Usage rules (IETF aipref attach draft) and the __usage_ai-training policy token
|
|
53
|
+
* (draft-kelley-aipref-training-preference-signal; Google says it intends to honour it in early 2027).
|
|
54
|
+
*/
|
|
55
|
+
export function aiPreferences(parsed, path = '/') {
|
|
56
|
+
const prefs = {};
|
|
57
|
+
for (const g of parsed.groups) {
|
|
58
|
+
if (!g.agents.includes('*')) continue;
|
|
59
|
+
for (const u of g.usage || []) if (path.startsWith(u.path)) Object.assign(prefs, u.prefs);
|
|
60
|
+
}
|
|
61
|
+
const token = parsed.groups.some((g) => g.agents.includes('__usage_ai-training'));
|
|
62
|
+
return { contentUsage: prefs, trainingToken: token ? (isAllowed(parsed, '__usage_ai-training', path) ? 'allowed' : 'disallowed') : null };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function ruleMatches(pattern, path) {
|
|
66
|
+
if (pattern === '') return false;
|
|
67
|
+
let re = '^';
|
|
68
|
+
for (const ch of pattern) {
|
|
69
|
+
if (ch === '*') re += '.*';
|
|
70
|
+
else if (ch === '$') re += '$';
|
|
71
|
+
else re += ch.replace(/[.+?^{}()|[\]\\]/g, '\\$&');
|
|
72
|
+
}
|
|
73
|
+
return new RegExp(re).test(path);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Returns the group that applies to a bot token, following RFC 9309 (exact token match, else *). */
|
|
77
|
+
export function groupFor(parsed, token) {
|
|
78
|
+
const t = token.toLowerCase();
|
|
79
|
+
const matching = parsed.groups.filter((g) => g.agents.includes(t));
|
|
80
|
+
if (matching.length) return { rules: matching.flatMap((g) => g.rules), specific: true };
|
|
81
|
+
const star = parsed.groups.filter((g) => g.agents.includes('*'));
|
|
82
|
+
return { rules: star.flatMap((g) => g.rules), specific: false };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Is `path` allowed for `token`? Longest matching rule wins; ties go to Allow. */
|
|
86
|
+
export function isAllowed(parsed, token, path = '/') {
|
|
87
|
+
const { rules } = groupFor(parsed, token);
|
|
88
|
+
let best = null;
|
|
89
|
+
for (const r of rules) {
|
|
90
|
+
if (!ruleMatches(r.path, path)) continue;
|
|
91
|
+
const len = r.path.replace(/\*/g, '').length;
|
|
92
|
+
if (!best || len > best.len || (len === best.len && r.allow)) best = { len, allow: r.allow };
|
|
93
|
+
}
|
|
94
|
+
return best ? best.allow : true;
|
|
95
|
+
}
|