@gotmar/audit 0.0.0-reserved → 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 jdonnell96
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,5 +1,15 @@
1
1
  # @gotmar/audit
2
2
 
3
- Gotmar SEO and AI-search audit engine.
3
+ The audit engine behind `gotmar audit` and the Gotmar dashboard. It checks a live page the way search and AI crawlers see it: raw HTML, with no JavaScript run.
4
4
 
5
- This is a placeholder that reserves the name. The first real release is coming soon.
5
+ It checks titles, descriptions, canonicals, robots rules for search and AI crawlers, sitemap, llms.txt, structured data, social previews, headings, image alt text and internal links.
6
+
7
+ ```ts
8
+ import { runAudit, toAgentPrompt } from "@gotmar/audit";
9
+
10
+ const report = await runAudit("https://example.com", { maxPages: 10 });
11
+ console.log(report.score, report.grade);
12
+ console.log(toAgentPrompt(report)); // the fixes, written for a coding agent
13
+ ```
14
+
15
+ Most people use it through the CLI: `npx gotmar audit https://your-site.com`. Docs: https://getgotmar.com/docs
@@ -0,0 +1,28 @@
1
+ import type { AuditIssue, AuditPass } from "./types.js";
2
+ export interface FetchedPage {
3
+ status: number;
4
+ text: string;
5
+ finalUrl: string;
6
+ headers: Headers;
7
+ }
8
+ export declare function crawlSite(opts: {
9
+ origin: string;
10
+ homePath: string;
11
+ sitemapUrls: string[];
12
+ maxPages: number;
13
+ preview: boolean;
14
+ fetchPage: (url: string) => Promise<FetchedPage | null>;
15
+ }): Promise<{
16
+ issues: AuditIssue[];
17
+ passed: AuditPass[];
18
+ pagesCrawled: number;
19
+ }>;
20
+ /**
21
+ * Issues in `head` that are not in `base`: new issue types, or known site-wide issues that
22
+ * now affect additional pages. Used by CI to fail only on regressions vs production.
23
+ */
24
+ export declare function newIssues(base: {
25
+ issues: AuditIssue[];
26
+ }, head: {
27
+ issues: AuditIssue[];
28
+ }): AuditIssue[];
package/dist/crawl.js ADDED
@@ -0,0 +1,266 @@
1
+ /**
2
+ * Whole-site crawl: fetch the pages listed in the sitemap (plus the internal links they contain)
3
+ * and find problems that only show up across pages: broken or redirecting sitemap entries,
4
+ * noindex on a deep page, duplicate titles, broken internal links, pages missing from the sitemap.
5
+ */
6
+ import { parse } from "node-html-parser";
7
+ const LINK_CHECK_LIMIT = 40;
8
+ const CONCURRENCY = 5;
9
+ async function pool(items, worker) {
10
+ const out = new Array(items.length);
11
+ let next = 0;
12
+ await Promise.all(Array.from({ length: Math.min(CONCURRENCY, items.length) }, async () => {
13
+ while (next < items.length) {
14
+ const i = next++;
15
+ out[i] = await worker(items[i]);
16
+ }
17
+ }));
18
+ return out;
19
+ }
20
+ function pathOf(url) {
21
+ return url.pathname.replace(/\/+$/, "") || "/";
22
+ }
23
+ function list(paths, max = 5) {
24
+ const shown = paths.slice(0, max).join(", ");
25
+ return paths.length > max ? `${shown} and ${paths.length - max} more` : shown;
26
+ }
27
+ function inspect(path, page, origin, preview) {
28
+ const base = { path, status: page?.status ?? 0, redirectedTo: null, title: null, description: null, noindex: false, canonicalPath: null, h1: 0, words: 0, links: [] };
29
+ if (!page)
30
+ return base;
31
+ const final = new URL(page.finalUrl);
32
+ if (pathOf(final) !== path || final.origin !== origin)
33
+ base.redirectedTo = final.origin === origin ? pathOf(final) : final.href;
34
+ if (page.status >= 400 || !(page.headers.get("content-type") ?? "text/html").includes("html"))
35
+ return base;
36
+ const root = parse(page.text, { comment: false });
37
+ const meta = (key) => root.querySelectorAll("meta").find((m) => (m.getAttribute("name") ?? m.getAttribute("property") ?? "").toLowerCase() === key)?.getAttribute("content")?.trim() || null;
38
+ base.title = root.querySelector("title")?.text.trim() || null;
39
+ base.description = meta("description");
40
+ base.noindex = /noindex/i.test(meta("robots") ?? "") || (!preview && /noindex/i.test(page.headers.get("x-robots-tag") ?? ""));
41
+ const canonical = root.querySelectorAll("link").find((l) => (l.getAttribute("rel") ?? "").toLowerCase().split(/\s+/).includes("canonical"))?.getAttribute("href");
42
+ if (canonical) {
43
+ try {
44
+ base.canonicalPath = pathOf(new URL(canonical, final));
45
+ }
46
+ catch { }
47
+ }
48
+ base.h1 = root.querySelectorAll("h1").length;
49
+ const links = new Set();
50
+ for (const a of root.querySelectorAll("a[href]")) {
51
+ const href = a.getAttribute("href") ?? "";
52
+ if (!href || href.startsWith("#") || /^(mailto|tel|javascript):/i.test(href))
53
+ continue;
54
+ try {
55
+ const u = new URL(href, final);
56
+ if (u.origin === origin && !/\.(png|jpe?g|gif|webp|svg|pdf|zip|xml|txt|json)$/i.test(u.pathname))
57
+ links.add(pathOf(u));
58
+ }
59
+ catch { }
60
+ }
61
+ base.links = [...links];
62
+ const mount = root.querySelector("#root, #app, #__nuxt, #svelte");
63
+ base.clientRendered = !!mount && mount.text.trim().length < 40 && root.querySelectorAll("script[src]").length > 0;
64
+ root.querySelectorAll("script,style,noscript,template,svg").forEach((n) => n.remove());
65
+ base.words = (root.querySelector("body") ?? root).text.split(/\s+/).filter((w) => /[\p{L}\p{N}]/u.test(w)).length;
66
+ return base;
67
+ }
68
+ export async function crawlSite(opts) {
69
+ const issues = [];
70
+ const passed = [];
71
+ const { origin, preview } = opts;
72
+ const sitemapPaths = [];
73
+ for (const raw of opts.sitemapUrls) {
74
+ try {
75
+ const u = new URL(raw);
76
+ // On a preview deployment, sitemap URLs point at production: check the preview's copy instead.
77
+ if (u.origin !== origin && !preview)
78
+ continue;
79
+ const p = pathOf(u);
80
+ if (!sitemapPaths.includes(p))
81
+ sitemapPaths.push(p);
82
+ }
83
+ catch { }
84
+ }
85
+ const toCrawl = sitemapPaths.slice(0, opts.maxPages);
86
+ const pages = await pool(toCrawl, async (p) => inspect(p, await opts.fetchPage(origin + p), origin, preview));
87
+ // Internal links found on crawled pages that we have not fetched yet.
88
+ const crawled = new Set(toCrawl);
89
+ const linkedFrom = new Map();
90
+ for (const page of pages)
91
+ for (const l of page.links)
92
+ if (!crawled.has(l) && !linkedFrom.has(l))
93
+ linkedFrom.set(l, page.path);
94
+ const extra = [...linkedFrom.keys()].slice(0, LINK_CHECK_LIMIT);
95
+ const extraPages = await pool(extra, async (p) => inspect(p, await opts.fetchPage(origin + p), origin, preview));
96
+ const ok = pages.filter((p) => p.status > 0 && p.status < 400 && !p.redirectedTo);
97
+ const broken = pages.filter((p) => p.status === 0 || p.status >= 400);
98
+ const redirected = pages.filter((p) => p.status < 400 && p.redirectedTo);
99
+ if (broken.length) {
100
+ issues.push({
101
+ id: "pages-broken",
102
+ severity: "critical",
103
+ category: "indexing",
104
+ title: "Pages in the sitemap are broken",
105
+ detail: `${broken.length} sitemap URL${broken.length === 1 ? "" : "s"} return an error: ${list(broken.map((p) => `${p.path} (${p.status || "no response"})`))}.`,
106
+ fix: "Fix or restore these pages, or remove them from sitemap.ts if they were deleted on purpose (and redirect old URLs to the closest live page).",
107
+ urls: broken.map((p) => p.path),
108
+ });
109
+ }
110
+ if (redirected.length) {
111
+ issues.push({
112
+ id: "pages-redirect",
113
+ severity: "warning",
114
+ category: "indexing",
115
+ title: "Sitemap lists URLs that redirect",
116
+ detail: `${list(redirected.map((p) => `${p.path} → ${p.redirectedTo}`))}. Sitemaps should only list final URLs.`,
117
+ fix: "Replace these entries in sitemap.ts with the URLs they redirect to (watch trailing slashes and www).",
118
+ urls: redirected.map((p) => p.path),
119
+ });
120
+ }
121
+ const noindex = ok.filter((p) => p.noindex);
122
+ if (noindex.length) {
123
+ issues.push({
124
+ id: "pages-noindex",
125
+ severity: "critical",
126
+ category: "indexing",
127
+ title: "Pages in the sitemap are set to noindex",
128
+ detail: `${list(noindex.map((p) => p.path))} tell search engines not to index them, but the sitemap asks them to.`,
129
+ fix: "Remove `robots: { index: false }` / noindex from these pages' metadata, or take them out of the sitemap if they should stay private.",
130
+ urls: noindex.map((p) => p.path),
131
+ });
132
+ }
133
+ const canonicalElsewhere = ok.filter((p) => !p.noindex && p.canonicalPath && p.canonicalPath !== p.path);
134
+ if (canonicalElsewhere.length) {
135
+ issues.push({
136
+ id: "pages-canonical-elsewhere",
137
+ severity: "warning",
138
+ category: "indexing",
139
+ title: "Pages point their canonical at another page",
140
+ detail: `${list(canonicalElsewhere.map((p) => `${p.path} → ${p.canonicalPath}`))}. Google will index the other page instead. A common cause is a root-layout canonical of "/" inherited by every page.`,
141
+ fix: "Give each page its own `alternates: { canonical: '/its-path' }` in its metadata (or generateMetadata).",
142
+ urls: canonicalElsewhere.map((p) => p.path),
143
+ });
144
+ }
145
+ const noTitle = ok.filter((p) => !p.title);
146
+ if (noTitle.length) {
147
+ issues.push({
148
+ id: "pages-no-title",
149
+ severity: "warning",
150
+ category: "on-page",
151
+ title: "Pages without a title",
152
+ detail: list(noTitle.map((p) => p.path)),
153
+ fix: "Add `metadata.title` (or generateMetadata) to each of these pages.",
154
+ urls: noTitle.map((p) => p.path),
155
+ });
156
+ }
157
+ const groupDupes = (key) => {
158
+ const byValue = new Map();
159
+ for (const p of ok) {
160
+ const v = key(p);
161
+ if (v)
162
+ byValue.set(v, [...(byValue.get(v) ?? []), p.path]);
163
+ }
164
+ return [...byValue.entries()].filter(([, paths]) => paths.length > 1);
165
+ };
166
+ const dupTitles = groupDupes((p) => p.title);
167
+ if (dupTitles.length) {
168
+ issues.push({
169
+ id: "pages-duplicate-title",
170
+ severity: "warning",
171
+ category: "on-page",
172
+ title: "Several pages share the same title",
173
+ detail: dupTitles.map(([t, paths]) => `"${t}" on ${list(paths, 4)}`).join("; "),
174
+ fix: "Give every page a unique title that says what that page is about, e.g. via `generateMetadata` for dynamic routes.",
175
+ urls: dupTitles.flatMap(([, paths]) => paths),
176
+ });
177
+ }
178
+ const dupDesc = groupDupes((p) => p.description);
179
+ if (dupDesc.length) {
180
+ issues.push({
181
+ id: "pages-duplicate-description",
182
+ severity: "info",
183
+ category: "on-page",
184
+ title: "Several pages share the same description",
185
+ detail: `${dupDesc.reduce((n, [, paths]) => n + paths.length, 0)} pages reuse a description, usually the root layout's.`,
186
+ fix: "Add a specific `description` to each page's metadata.",
187
+ urls: dupDesc.flatMap(([, paths]) => paths),
188
+ });
189
+ }
190
+ // Short-but-real pages (a blog index with one post) are fine; flag empty shells only.
191
+ const thin = ok.filter((p) => p.words < 15 || (p.clientRendered && p.words < 50));
192
+ if (thin.length) {
193
+ issues.push({
194
+ id: "pages-empty",
195
+ severity: "warning",
196
+ category: "ai-search",
197
+ title: "Pages that crawlers see as (almost) empty",
198
+ detail: `${list(thin.map((p) => `${p.path} (${p.words} words)`))}. Content rendered only in the browser is invisible to AI crawlers.`,
199
+ fix: "Render these pages' main content on the server (no page-level 'use client'), or remove them from the sitemap if they are app screens rather than public pages.",
200
+ urls: thin.map((p) => p.path),
201
+ });
202
+ }
203
+ const noH1 = ok.filter((p) => p.h1 === 0);
204
+ if (noH1.length) {
205
+ issues.push({
206
+ id: "pages-no-h1",
207
+ severity: "info",
208
+ category: "on-page",
209
+ title: "Pages without an H1",
210
+ detail: list(noH1.map((p) => p.path)),
211
+ fix: "Give each page one <h1> that states its topic.",
212
+ urls: noH1.map((p) => p.path),
213
+ });
214
+ }
215
+ const brokenLinks = extraPages.filter((p) => p.status === 0 || p.status >= 400);
216
+ if (brokenLinks.length) {
217
+ issues.push({
218
+ id: "links-broken",
219
+ severity: "warning",
220
+ category: "on-page",
221
+ title: "Broken internal links",
222
+ detail: list(brokenLinks.map((p) => `${p.path} (${p.status || "no response"}, linked from ${linkedFrom.get(p.path)})`)),
223
+ fix: "Fix or remove these links (or create the missing pages). Broken links waste crawl budget and frustrate visitors.",
224
+ urls: brokenLinks.map((p) => p.path),
225
+ });
226
+ }
227
+ const missingFromSitemap = extraPages.filter((p) => p.status > 0 && p.status < 400 && !p.redirectedTo && !p.noindex && p.words >= 15);
228
+ if (missingFromSitemap.length) {
229
+ issues.push({
230
+ id: "sitemap-missing-pages",
231
+ severity: "info",
232
+ category: "indexing",
233
+ title: "Linked pages missing from the sitemap",
234
+ detail: `${list(missingFromSitemap.map((p) => p.path))} are linked from the site but not listed in the sitemap.`,
235
+ fix: "Add these public pages to sitemap.ts so new ones get discovered quickly.",
236
+ urls: missingFromSitemap.map((p) => p.path),
237
+ });
238
+ }
239
+ if (toCrawl.length) {
240
+ const healthy = !broken.length && !noindex.length && !brokenLinks.length;
241
+ if (healthy)
242
+ passed.push({ id: "crawl", category: "indexing", title: `Crawled ${toCrawl.length} page${toCrawl.length === 1 ? "" : "s"} + ${extra.length} linked: no broken or hidden pages` });
243
+ }
244
+ return { issues, passed, pagesCrawled: toCrawl.length + extra.length };
245
+ }
246
+ /**
247
+ * Issues in `head` that are not in `base`: new issue types, or known site-wide issues that
248
+ * now affect additional pages. Used by CI to fail only on regressions vs production.
249
+ */
250
+ export function newIssues(base, head) {
251
+ const byId = new Map(base.issues.map((i) => [i.id, i]));
252
+ const out = [];
253
+ for (const issue of head.issues) {
254
+ const before = byId.get(issue.id);
255
+ if (!before) {
256
+ out.push(issue);
257
+ continue;
258
+ }
259
+ if (issue.urls && before.urls) {
260
+ const added = issue.urls.filter((u) => !before.urls.includes(u));
261
+ if (added.length)
262
+ out.push({ ...issue, urls: added, detail: `${issue.detail} (new: ${list(added)})` });
263
+ }
264
+ }
265
+ return out;
266
+ }
@@ -0,0 +1,24 @@
1
+ import type { AuditOptions, AuditReport } from "./types.js";
2
+ export * from "./types.js";
3
+ export { isAllowed, parseRobots } from "./robots.js";
4
+ export { newIssues } from "./crawl.js";
5
+ export { LAUNCH_CHANNELS, trackedLink, type LaunchChannel } from "./launch.js";
6
+ /** Crawlers that decide whether you show up in classic search. */
7
+ export declare const SEARCH_BOTS: string[];
8
+ /** Crawlers that fetch pages to answer questions or cite sources in AI search. */
9
+ export declare const AI_SEARCH_BOTS: string[];
10
+ /** Crawlers (or robots tokens) used for model training. Blocking these is a choice, not a mistake. */
11
+ export declare const AI_TRAINING_BOTS: string[];
12
+ export declare const LINKS: {
13
+ searchConsole: string;
14
+ bingWebmaster: string;
15
+ richResults: string;
16
+ pageSpeed: string;
17
+ };
18
+ /**
19
+ * Audit a live URL the way search and AI crawlers see it: raw HTML, no JavaScript.
20
+ * Every issue carries a `fix` written as an instruction a coding agent can follow.
21
+ */
22
+ export declare function runAudit(inputUrl: string, opts?: AuditOptions): Promise<AuditReport>;
23
+ /** Turns a report into a prompt the user can paste into their coding agent. */
24
+ export declare function toAgentPrompt(report: AuditReport): string;