@rankcli/agent-runtime 0.0.15 → 0.0.17

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.
Files changed (203) hide show
  1. package/README.md +5 -4
  2. package/dist/index.d.mts +44 -393
  3. package/dist/index.d.ts +44 -393
  4. package/dist/index.js +22098 -26131
  5. package/dist/index.mjs +11834 -15857
  6. package/package.json +10 -4
  7. package/scripts/build-deno.ts +0 -134
  8. package/src/analyzers/core-web-vitals-analyzer.test.ts +0 -236
  9. package/src/analyzers/core-web-vitals-analyzer.ts +0 -557
  10. package/src/analyzers/geo-analyzer.test.ts +0 -310
  11. package/src/analyzers/geo-analyzer.ts +0 -814
  12. package/src/analyzers/image-optimization-analyzer.test.ts +0 -145
  13. package/src/analyzers/image-optimization-analyzer.ts +0 -348
  14. package/src/analyzers/index.ts +0 -233
  15. package/src/analyzers/internal-linking-analyzer.test.ts +0 -141
  16. package/src/analyzers/internal-linking-analyzer.ts +0 -419
  17. package/src/analyzers/mobile-seo-analyzer.test.ts +0 -140
  18. package/src/analyzers/mobile-seo-analyzer.ts +0 -455
  19. package/src/analyzers/security-headers-analyzer.test.ts +0 -115
  20. package/src/analyzers/security-headers-analyzer.ts +0 -318
  21. package/src/analyzers/structured-data-analyzer.test.ts +0 -210
  22. package/src/analyzers/structured-data-analyzer.ts +0 -590
  23. package/src/audit/ai/analyzer.ts +0 -347
  24. package/src/audit/ai/index.ts +0 -29
  25. package/src/audit/ai/prompts/content-analysis.ts +0 -271
  26. package/src/audit/ai/types.ts +0 -179
  27. package/src/audit/checks/additional-checks.ts +0 -439
  28. package/src/audit/checks/agent-experience.ts +0 -108
  29. package/src/audit/checks/ai-citation-worthiness.ts +0 -399
  30. package/src/audit/checks/ai-content-structure.ts +0 -325
  31. package/src/audit/checks/ai-readiness.ts +0 -406
  32. package/src/audit/checks/anchor-text.ts +0 -179
  33. package/src/audit/checks/answer-conciseness.ts +0 -322
  34. package/src/audit/checks/asset-minification.ts +0 -270
  35. package/src/audit/checks/bing-optimization.ts +0 -206
  36. package/src/audit/checks/brand-mention-optimization.ts +0 -349
  37. package/src/audit/checks/caching-headers.ts +0 -305
  38. package/src/audit/checks/canonical-advanced.ts +0 -150
  39. package/src/audit/checks/canonical-domain.ts +0 -196
  40. package/src/audit/checks/citation-quality.ts +0 -358
  41. package/src/audit/checks/client-rendering.ts +0 -542
  42. package/src/audit/checks/color-contrast.ts +0 -342
  43. package/src/audit/checks/content-freshness.ts +0 -170
  44. package/src/audit/checks/content-science.ts +0 -589
  45. package/src/audit/checks/conversion-elements.ts +0 -526
  46. package/src/audit/checks/crawlability.ts +0 -220
  47. package/src/audit/checks/directory-listing.ts +0 -172
  48. package/src/audit/checks/dom-analysis.ts +0 -191
  49. package/src/audit/checks/dom-size.ts +0 -246
  50. package/src/audit/checks/duplicate-content.ts +0 -194
  51. package/src/audit/checks/eeat-signals.ts +0 -990
  52. package/src/audit/checks/entity-seo.ts +0 -396
  53. package/src/audit/checks/featured-snippet.ts +0 -473
  54. package/src/audit/checks/freshness-signals.ts +0 -443
  55. package/src/audit/checks/funnel-intent.ts +0 -463
  56. package/src/audit/checks/hreflang.ts +0 -174
  57. package/src/audit/checks/html-compliance.ts +0 -302
  58. package/src/audit/checks/image-dimensions.ts +0 -167
  59. package/src/audit/checks/images.ts +0 -160
  60. package/src/audit/checks/indexnow.ts +0 -275
  61. package/src/audit/checks/interactive-tools.ts +0 -475
  62. package/src/audit/checks/internal-link-graph.ts +0 -436
  63. package/src/audit/checks/keyword-analysis.ts +0 -239
  64. package/src/audit/checks/keyword-cannibalization.ts +0 -385
  65. package/src/audit/checks/keyword-placement.ts +0 -471
  66. package/src/audit/checks/links.ts +0 -273
  67. package/src/audit/checks/llms-txt.ts +0 -224
  68. package/src/audit/checks/local-seo.ts +0 -296
  69. package/src/audit/checks/mobile.ts +0 -167
  70. package/src/audit/checks/modern-images.ts +0 -226
  71. package/src/audit/checks/navboost-signals.ts +0 -395
  72. package/src/audit/checks/on-page.ts +0 -209
  73. package/src/audit/checks/page-resources.ts +0 -285
  74. package/src/audit/checks/pagination.ts +0 -180
  75. package/src/audit/checks/performance.ts +0 -153
  76. package/src/audit/checks/platform-presence.ts +0 -580
  77. package/src/audit/checks/rag-chunk-readiness.test.ts +0 -159
  78. package/src/audit/checks/rag-chunk-readiness.ts +0 -163
  79. package/src/audit/checks/redirect-analysis.ts +0 -153
  80. package/src/audit/checks/redirect-chain.ts +0 -389
  81. package/src/audit/checks/resource-hints.ts +0 -420
  82. package/src/audit/checks/responsive-css.ts +0 -247
  83. package/src/audit/checks/responsive-images.ts +0 -396
  84. package/src/audit/checks/review-ecosystem.ts +0 -415
  85. package/src/audit/checks/robots-validation.ts +0 -373
  86. package/src/audit/checks/security-headers.ts +0 -188
  87. package/src/audit/checks/security.ts +0 -144
  88. package/src/audit/checks/serp-preview.ts +0 -251
  89. package/src/audit/checks/site-maturity.ts +0 -453
  90. package/src/audit/checks/social-meta.test.ts +0 -275
  91. package/src/audit/checks/social-meta.ts +0 -134
  92. package/src/audit/checks/soft-404.ts +0 -151
  93. package/src/audit/checks/structured-data.ts +0 -238
  94. package/src/audit/checks/tech-detection.ts +0 -496
  95. package/src/audit/checks/topical-clusters.ts +0 -435
  96. package/src/audit/checks/tracker-bloat.ts +0 -462
  97. package/src/audit/checks/tracking-verification.test.ts +0 -371
  98. package/src/audit/checks/tracking-verification.ts +0 -636
  99. package/src/audit/checks/url-safety.ts +0 -682
  100. package/src/audit/deno-entry.ts +0 -66
  101. package/src/audit/discovery/index.ts +0 -15
  102. package/src/audit/discovery/link-crawler.ts +0 -233
  103. package/src/audit/discovery/repo-routes.ts +0 -347
  104. package/src/audit/engine.ts +0 -633
  105. package/src/audit/fixes/index.ts +0 -209
  106. package/src/audit/fixes/social-meta-fixes.test.ts +0 -329
  107. package/src/audit/fixes/social-meta-fixes.ts +0 -463
  108. package/src/audit/index.ts +0 -74
  109. package/src/audit/runner.test.ts +0 -299
  110. package/src/audit/runner.ts +0 -130
  111. package/src/audit/types.ts +0 -1987
  112. package/src/content/featured-snippet.ts +0 -367
  113. package/src/content/generator.test.ts +0 -534
  114. package/src/content/generator.ts +0 -501
  115. package/src/content/headline.ts +0 -317
  116. package/src/content/index.ts +0 -62
  117. package/src/content/intent.ts +0 -258
  118. package/src/content/keyword-density.ts +0 -349
  119. package/src/content/readability.ts +0 -262
  120. package/src/executor.ts +0 -336
  121. package/src/fixer/framework-fixes.test.ts +0 -489
  122. package/src/fixer/framework-fixes.ts +0 -5287
  123. package/src/fixer/index.ts +0 -6
  124. package/src/fixer/schemas.ts +0 -971
  125. package/src/fixer.ts +0 -642
  126. package/src/frameworks/detector.test.ts +0 -248
  127. package/src/frameworks/detector.ts +0 -899
  128. package/src/frameworks/index.ts +0 -68
  129. package/src/frameworks/recipes/angular.yaml +0 -171
  130. package/src/frameworks/recipes/astro.yaml +0 -206
  131. package/src/frameworks/recipes/django.yaml +0 -180
  132. package/src/frameworks/recipes/laravel.yaml +0 -137
  133. package/src/frameworks/recipes/nextjs.yaml +0 -268
  134. package/src/frameworks/recipes/nuxt.yaml +0 -175
  135. package/src/frameworks/recipes/rails.yaml +0 -188
  136. package/src/frameworks/recipes/react.yaml +0 -202
  137. package/src/frameworks/recipes/sveltekit.yaml +0 -154
  138. package/src/frameworks/recipes/vue.yaml +0 -137
  139. package/src/frameworks/recipes/wordpress.yaml +0 -209
  140. package/src/frameworks/suggestion-engine.ts +0 -357
  141. package/src/geo/geo-content.test.ts +0 -305
  142. package/src/geo/geo-content.ts +0 -266
  143. package/src/geo/geo-history.test.ts +0 -473
  144. package/src/geo/geo-history.ts +0 -433
  145. package/src/geo/geo-tracker.test.ts +0 -359
  146. package/src/geo/geo-tracker.ts +0 -411
  147. package/src/geo/index.ts +0 -11
  148. package/src/geo/llm-citation-checker.ts +0 -188
  149. package/src/git/commit-helper.test.ts +0 -261
  150. package/src/git/commit-helper.ts +0 -329
  151. package/src/git/index.ts +0 -12
  152. package/src/git/pr-helper.test.ts +0 -284
  153. package/src/git/pr-helper.ts +0 -307
  154. package/src/index.ts +0 -76
  155. package/src/keywords/ai-keyword-engine.ts +0 -1062
  156. package/src/keywords/ai-summarizer.ts +0 -387
  157. package/src/keywords/ci-mode.ts +0 -555
  158. package/src/keywords/engine.ts +0 -359
  159. package/src/keywords/index.ts +0 -151
  160. package/src/keywords/llm-judge.ts +0 -357
  161. package/src/keywords/nlp-analysis.ts +0 -706
  162. package/src/keywords/prioritizer.ts +0 -295
  163. package/src/keywords/site-crawler.ts +0 -342
  164. package/src/keywords/sources/autocomplete.ts +0 -139
  165. package/src/keywords/sources/competitive-search.ts +0 -450
  166. package/src/keywords/sources/competitor-analysis.ts +0 -374
  167. package/src/keywords/sources/dataforseo.ts +0 -206
  168. package/src/keywords/sources/free-sources.ts +0 -294
  169. package/src/keywords/sources/gsc.ts +0 -123
  170. package/src/keywords/topic-grouping.ts +0 -327
  171. package/src/keywords/types.ts +0 -144
  172. package/src/keywords/wizard.ts +0 -457
  173. package/src/loader.ts +0 -40
  174. package/src/ranking/index.ts +0 -5
  175. package/src/ranking/serp-client.ts +0 -348
  176. package/src/ranking/tracker.ts +0 -380
  177. package/src/ranking/types.ts +0 -123
  178. package/src/reports/index.ts +0 -7
  179. package/src/reports/report-generator.test.ts +0 -293
  180. package/src/reports/report-generator.ts +0 -713
  181. package/src/scheduler/alerts.test.ts +0 -458
  182. package/src/scheduler/alerts.ts +0 -328
  183. package/src/scheduler/index.ts +0 -8
  184. package/src/scheduler/scheduled-audit.test.ts +0 -377
  185. package/src/scheduler/scheduled-audit.ts +0 -149
  186. package/src/test/integration-test.ts +0 -325
  187. package/src/tools/analyzer.ts +0 -373
  188. package/src/tools/crawl.ts +0 -293
  189. package/src/tools/files.ts +0 -301
  190. package/src/tools/h1-fixer.ts +0 -249
  191. package/src/tools/index.ts +0 -67
  192. package/src/tracking/github-action.ts +0 -326
  193. package/src/tracking/google-analytics.ts +0 -265
  194. package/src/tracking/index.ts +0 -45
  195. package/src/tracking/report-generator.ts +0 -386
  196. package/src/tracking/search-console.ts +0 -335
  197. package/src/types.ts +0 -148
  198. package/src/utils/http.ts +0 -302
  199. package/src/wasm-adapter.ts +0 -297
  200. package/src/wasm-entry.ts +0 -14
  201. package/tsconfig.json +0 -17
  202. package/tsup.wasm.config.ts +0 -26
  203. package/vitest.config.ts +0 -15
@@ -1,814 +0,0 @@
1
- /**
2
- * GEO (Generative Engine Optimization) Analyzer
3
- *
4
- * Industry-first analyzer for AI search visibility.
5
- * Checks if your site is optimized for ChatGPT, Perplexity, Claude, and other AI search engines.
6
- *
7
- * Features:
8
- * - AI crawler accessibility detection
9
- * - LLM-friendly content structure analysis
10
- * - Citation-optimized formatting
11
- * - Entity and fact extraction readiness
12
- * - AI search ranking factors
13
- */
14
-
15
- import * as cheerio from 'cheerio';
16
- import type { AuditIssue, IssueSeverity, IssueCategory } from '../audit/types.js';
17
-
18
- export interface GEOAnalysisResult {
19
- score: number; // 0-100 GEO readiness score
20
- aiCrawlerAccess: AIAccessResult;
21
- contentStructure: ContentStructureResult;
22
- citationReadiness: CitationResult;
23
- entityExtraction: EntityResult;
24
- llmSignals: LLMSignalResult;
25
- issues: AuditIssue[];
26
- recommendations: string[];
27
- }
28
-
29
- export interface AIAccessResult {
30
- robotsTxtAllowsAI: boolean;
31
- blockedCrawlers: string[];
32
- allowedCrawlers: string[];
33
- hasPrerendering: boolean;
34
- jsRenderingRequired: boolean;
35
- serverSideRendered: boolean;
36
- }
37
-
38
- export interface ContentStructureResult {
39
- hasStructuredData: boolean;
40
- hasFAQSchema: boolean;
41
- hasHowToSchema: boolean;
42
- hasArticleSchema: boolean;
43
- hasProductSchema: boolean;
44
- hasBreadcrumbs: boolean;
45
- headingHierarchy: 'good' | 'needs-work' | 'poor';
46
- contentSections: number;
47
- listsAndTables: number;
48
- }
49
-
50
- export interface CitationResult {
51
- hasCitations: boolean;
52
- hasExternalLinks: boolean;
53
- hasStatistics: boolean;
54
- hasQuotes: boolean;
55
- hasAuthorInfo: boolean;
56
- hasPublishDate: boolean;
57
- hasLastModified: boolean;
58
- trustSignals: string[];
59
- }
60
-
61
- export interface EntityResult {
62
- namedEntities: string[];
63
- definedTerms: string[];
64
- hasDefinitions: boolean;
65
- hasComparisons: boolean;
66
- questionAnswerPairs: number;
67
- }
68
-
69
- export interface LLMSignalResult {
70
- contentClarity: number; // 0-100
71
- factDensity: number; // 0-100
72
- structureQuality: number; // 0-100
73
- citationQuality: number; // 0-100
74
- overallLLMFriendliness: number; // 0-100
75
- }
76
-
77
- // Known AI crawlers and their user agents
78
- const AI_CRAWLERS = {
79
- // OpenAI
80
- GPTBot: { userAgent: 'GPTBot', company: 'OpenAI', purpose: 'ChatGPT training & browsing' },
81
- ChatGPTUser: { userAgent: 'ChatGPT-User', company: 'OpenAI', purpose: 'ChatGPT browsing feature' },
82
- OAI_SearchBot: { userAgent: 'OAI-SearchBot', company: 'OpenAI', purpose: 'OpenAI search features' },
83
-
84
- // Anthropic
85
- ClaudeBot: { userAgent: 'Claude-Web', company: 'Anthropic', purpose: 'Claude web access' },
86
- anthropic_ai: { userAgent: 'anthropic-ai', company: 'Anthropic', purpose: 'Claude training' },
87
-
88
- // Perplexity
89
- PerplexityBot: { userAgent: 'PerplexityBot', company: 'Perplexity', purpose: 'Perplexity AI search' },
90
-
91
- // Google AI
92
- GoogleOther: { userAgent: 'Google-Extended', company: 'Google', purpose: 'Bard/Gemini training' },
93
-
94
- // Microsoft/Bing
95
- Bingbot: { userAgent: 'bingbot', company: 'Microsoft', purpose: 'Bing Chat/Copilot' },
96
-
97
- // Meta
98
- FacebookBot: { userAgent: 'FacebookBot', company: 'Meta', purpose: 'Meta AI features' },
99
- MetaAI: { userAgent: 'meta-externalagent', company: 'Meta', purpose: 'Meta AI training' },
100
-
101
- // Apple
102
- Applebot: { userAgent: 'Applebot-Extended', company: 'Apple', purpose: 'Apple Intelligence' },
103
-
104
- // Amazon
105
- Amazonbot: { userAgent: 'Amazonbot', company: 'Amazon', purpose: 'Alexa/Amazon AI' },
106
-
107
- // Others
108
- YouBot: { userAgent: 'YouBot', company: 'You.com', purpose: 'You.com AI search' },
109
- CCBot: { userAgent: 'CCBot', company: 'Common Crawl', purpose: 'Training data' },
110
- cohere_ai: { userAgent: 'cohere-ai', company: 'Cohere', purpose: 'Cohere training' },
111
- };
112
-
113
- /**
114
- * Analyze robots.txt for AI crawler permissions
115
- */
116
- export function analyzeRobotsTxtForAI(robotsTxt: string): {
117
- allowed: string[];
118
- blocked: string[];
119
- recommendations: string[];
120
- } {
121
- const allowed: string[] = [];
122
- const blocked: string[] = [];
123
- const recommendations: string[] = [];
124
-
125
- const lines = robotsTxt.split('\n').map(l => l.trim().toLowerCase());
126
- let currentAgent = '*';
127
-
128
- for (const line of lines) {
129
- if (line.startsWith('user-agent:')) {
130
- currentAgent = line.replace('user-agent:', '').trim();
131
- } else if (line.startsWith('disallow:')) {
132
- const path = line.replace('disallow:', '').trim();
133
- if (path === '/' || path === '/*') {
134
- // Check if this applies to AI crawlers
135
- for (const [name, info] of Object.entries(AI_CRAWLERS)) {
136
- if (currentAgent === '*' || currentAgent.includes(info.userAgent.toLowerCase())) {
137
- if (!blocked.includes(name)) blocked.push(name);
138
- }
139
- }
140
- }
141
- } else if (line.startsWith('allow:')) {
142
- for (const [name, info] of Object.entries(AI_CRAWLERS)) {
143
- if (currentAgent === '*' || currentAgent.includes(info.userAgent.toLowerCase())) {
144
- if (!allowed.includes(name)) allowed.push(name);
145
- }
146
- }
147
- }
148
- }
149
-
150
- // Check for explicit AI crawler rules
151
- for (const [name, info] of Object.entries(AI_CRAWLERS)) {
152
- const hasExplicitRule = lines.some(l =>
153
- l.includes(info.userAgent.toLowerCase())
154
- );
155
-
156
- if (!hasExplicitRule && !blocked.includes(name) && !allowed.includes(name)) {
157
- // No explicit rule, defaults to allowed
158
- allowed.push(name);
159
- }
160
- }
161
-
162
- // Generate recommendations
163
- if (blocked.includes('GPTBot')) {
164
- recommendations.push('⚠️ GPTBot is blocked - your content won\'t appear in ChatGPT responses');
165
- }
166
- if (blocked.includes('PerplexityBot')) {
167
- recommendations.push('⚠️ PerplexityBot is blocked - missing Perplexity AI search visibility');
168
- }
169
- if (blocked.includes('ClaudeBot')) {
170
- recommendations.push('⚠️ Claude-Web is blocked - no visibility in Claude AI responses');
171
- }
172
-
173
- if (allowed.length === 0) {
174
- recommendations.push('🚨 All AI crawlers appear to be blocked - zero AI search visibility');
175
- }
176
-
177
- return { allowed, blocked, recommendations };
178
- }
179
-
180
- /**
181
- * Detect if page is server-side rendered or requires JS
182
- */
183
- export function detectRenderingMode(html: string): {
184
- serverSideRendered: boolean;
185
- jsRenderingRequired: boolean;
186
- hasPrerendering: boolean;
187
- contentInHTML: boolean;
188
- signals: string[];
189
- } {
190
- const $ = cheerio.load(html);
191
- const signals: string[] = [];
192
-
193
- // Check for SSR/SSG indicators
194
- const hasNextData = html.includes('__NEXT_DATA__');
195
- const hasNuxtData = html.includes('__NUXT__');
196
- const hasGatsbyData = html.includes('___gatsby');
197
- const hasAstroIsland = html.includes('astro-island');
198
-
199
- // Check for SPA indicators (minimal server content)
200
- const bodyText = $('body').text().replace(/\s+/g, ' ').trim();
201
- const hasMinimalContent = bodyText.length < 200;
202
- const hasRootDiv = $('#root, #app, #__next, #__nuxt').length > 0;
203
- const hasReactRoot = $('[data-reactroot]').length > 0;
204
-
205
- // Check for prerender hints
206
- const hasPrerender = $('meta[name="prerender-status-code"]').length > 0 ||
207
- $('meta[name="fragment"]').attr('content') === '!';
208
-
209
- // Check for actual content
210
- const paragraphs = $('p').length;
211
- const headings = $('h1, h2, h3, h4, h5, h6').length;
212
- const hasSubstantialContent = paragraphs > 2 || headings > 2;
213
-
214
- // Determine rendering mode
215
- let serverSideRendered = false;
216
- let jsRenderingRequired = false;
217
-
218
- if (hasNextData || hasNuxtData || hasGatsbyData || hasAstroIsland) {
219
- serverSideRendered = true;
220
- signals.push('Meta-framework SSR detected');
221
- }
222
-
223
- if (hasMinimalContent && hasRootDiv) {
224
- jsRenderingRequired = true;
225
- signals.push('SPA with minimal server content detected');
226
- }
227
-
228
- if (hasSubstantialContent) {
229
- serverSideRendered = true;
230
- signals.push('Substantial HTML content present');
231
- }
232
-
233
- if (hasReactRoot && !hasNextData && hasMinimalContent) {
234
- jsRenderingRequired = true;
235
- signals.push('Client-side React app detected');
236
- }
237
-
238
- return {
239
- serverSideRendered,
240
- jsRenderingRequired,
241
- hasPrerendering: hasPrerender,
242
- contentInHTML: hasSubstantialContent,
243
- signals,
244
- };
245
- }
246
-
247
- /**
248
- * Analyze content structure for LLM consumption
249
- */
250
- export function analyzeContentStructure(html: string): ContentStructureResult {
251
- const $ = cheerio.load(html);
252
-
253
- // Check for structured data
254
- const jsonLdScripts = $('script[type="application/ld+json"]');
255
- let hasStructuredData = jsonLdScripts.length > 0;
256
- let hasFAQSchema = false;
257
- let hasHowToSchema = false;
258
- let hasArticleSchema = false;
259
- let hasProductSchema = false;
260
-
261
- jsonLdScripts.each((_, el) => {
262
- try {
263
- const content = $(el).html() || '';
264
- if (content.includes('"FAQPage"') || content.includes('"@type":"FAQPage"')) {
265
- hasFAQSchema = true;
266
- }
267
- if (content.includes('"HowTo"') || content.includes('"@type":"HowTo"')) {
268
- hasHowToSchema = true;
269
- }
270
- if (content.includes('"Article"') || content.includes('"BlogPosting"') ||
271
- content.includes('"NewsArticle"')) {
272
- hasArticleSchema = true;
273
- }
274
- if (content.includes('"Product"')) {
275
- hasProductSchema = true;
276
- }
277
- } catch {}
278
- });
279
-
280
- // Check breadcrumbs
281
- const hasBreadcrumbs = $('[itemtype*="BreadcrumbList"], .breadcrumb, .breadcrumbs, nav[aria-label*="breadcrumb"]').length > 0 ||
282
- html.includes('"BreadcrumbList"');
283
-
284
- // Analyze heading hierarchy
285
- const h1Count = $('h1').length;
286
- const h2Count = $('h2').length;
287
- const h3Count = $('h3').length;
288
-
289
- let headingHierarchy: 'good' | 'needs-work' | 'poor' = 'poor';
290
- if (h1Count === 1 && h2Count >= 2 && h3Count >= 0) {
291
- headingHierarchy = 'good';
292
- } else if (h1Count === 1 && h2Count >= 1) {
293
- headingHierarchy = 'needs-work';
294
- }
295
-
296
- // Count content sections
297
- const contentSections = $('section, article, .section, [class*="section"]').length;
298
-
299
- // Count lists and tables (LLMs love these)
300
- const listsAndTables = $('ul, ol, table, dl').length;
301
-
302
- return {
303
- hasStructuredData,
304
- hasFAQSchema,
305
- hasHowToSchema,
306
- hasArticleSchema,
307
- hasProductSchema,
308
- hasBreadcrumbs,
309
- headingHierarchy,
310
- contentSections,
311
- listsAndTables,
312
- };
313
- }
314
-
315
- /**
316
- * Analyze citation readiness (trust signals for AI)
317
- */
318
- export function analyzeCitationReadiness(html: string): CitationResult {
319
- const $ = cheerio.load(html);
320
- const bodyText = $('body').text();
321
-
322
- // Check for citations
323
- const hasCitations = $('cite, blockquote, [class*="citation"], [class*="reference"]').length > 0 ||
324
- /\[\d+\]|\(\d{4}\)/.test(bodyText);
325
-
326
- // Check for external links (source references)
327
- const externalLinks = $('a[href^="http"]').filter((_, el) => {
328
- const href = $(el).attr('href') || '';
329
- return !href.includes(new URL(href).hostname);
330
- });
331
- const hasExternalLinks = externalLinks.length > 0;
332
-
333
- // Check for statistics
334
- const hasStatistics = /\d+%|\d+\s*(million|billion|thousand)|increased by \d+|decreased by \d+/i.test(bodyText);
335
-
336
- // Check for quotes
337
- const hasQuotes = $('blockquote, q').length > 0 || /"[^"]{20,}"/.test(bodyText);
338
-
339
- // Check for author info
340
- const hasAuthorInfo = $('[rel="author"], .author, [class*="author"], [itemtype*="Person"]').length > 0 ||
341
- $('meta[name="author"]').length > 0;
342
-
343
- // Check for dates
344
- const hasPublishDate = $('time[datetime], meta[property="article:published_time"], .publish-date, .date').length > 0;
345
- const hasLastModified = $('meta[property="article:modified_time"], .updated, .modified').length > 0;
346
-
347
- // Collect trust signals
348
- const trustSignals: string[] = [];
349
- if (hasCitations) trustSignals.push('Citations present');
350
- if (hasExternalLinks) trustSignals.push('External source links');
351
- if (hasStatistics) trustSignals.push('Statistical data');
352
- if (hasQuotes) trustSignals.push('Expert quotes');
353
- if (hasAuthorInfo) trustSignals.push('Author attribution');
354
- if (hasPublishDate) trustSignals.push('Publish date');
355
- if (hasLastModified) trustSignals.push('Last modified date');
356
-
357
- return {
358
- hasCitations,
359
- hasExternalLinks,
360
- hasStatistics,
361
- hasQuotes,
362
- hasAuthorInfo,
363
- hasPublishDate,
364
- hasLastModified,
365
- trustSignals,
366
- };
367
- }
368
-
369
- /**
370
- * Extract entities and structured information
371
- */
372
- export function analyzeEntityExtraction(html: string): EntityResult {
373
- const $ = cheerio.load(html);
374
- const bodyText = $('body').text();
375
-
376
- // Look for defined terms (using <dfn>, <abbr>, or definition patterns)
377
- const definedTerms: string[] = [];
378
- $('dfn, abbr[title]').each((_, el) => {
379
- const term = $(el).text().trim();
380
- if (term) definedTerms.push(term);
381
- });
382
-
383
- // Check for definition patterns
384
- const hasDefinitions = /is defined as|refers to|means that|is the process of/i.test(bodyText) ||
385
- $('dfn, .definition, [class*="definition"]').length > 0;
386
-
387
- // Check for comparisons (great for LLM understanding)
388
- const hasComparisons = /compared to|versus|vs\.|unlike|similar to|difference between/i.test(bodyText) ||
389
- $('table[class*="comparison"], .comparison, [class*="versus"]').length > 0;
390
-
391
- // Count Q&A pairs (excellent for AI)
392
- let questionAnswerPairs = 0;
393
- $('details, .faq-item, [class*="question"], [class*="accordion"]').each(() => {
394
- questionAnswerPairs++;
395
- });
396
-
397
- // Also check for question patterns in headings
398
- $('h2, h3, h4').each((_, el) => {
399
- const text = $(el).text();
400
- if (/^(what|how|why|when|where|who|which|can|does|is|are|should|will)\s/i.test(text) ||
401
- text.endsWith('?')) {
402
- questionAnswerPairs++;
403
- }
404
- });
405
-
406
- // Extract named entities (basic pattern matching)
407
- const namedEntities: string[] = [];
408
-
409
- // Look for proper nouns in strong/b tags (often company/product names)
410
- $('strong, b').each((_, el) => {
411
- const text = $(el).text().trim();
412
- if (text.length > 2 && text.length < 50 && /^[A-Z]/.test(text)) {
413
- if (!namedEntities.includes(text)) namedEntities.push(text);
414
- }
415
- });
416
-
417
- return {
418
- namedEntities: namedEntities.slice(0, 20), // Limit to top 20
419
- definedTerms,
420
- hasDefinitions,
421
- hasComparisons,
422
- questionAnswerPairs,
423
- };
424
- }
425
-
426
- /**
427
- * Calculate LLM-friendliness signals
428
- */
429
- export function calculateLLMSignals(
430
- structure: ContentStructureResult,
431
- citation: CitationResult,
432
- entity: EntityResult,
433
- html: string
434
- ): LLMSignalResult {
435
- const $ = cheerio.load(html);
436
-
437
- // Content clarity (structure + readability)
438
- let contentClarity = 0;
439
- if (structure.headingHierarchy === 'good') contentClarity += 30;
440
- else if (structure.headingHierarchy === 'needs-work') contentClarity += 15;
441
- contentClarity += Math.min(structure.listsAndTables * 5, 25); // Lists help clarity
442
- contentClarity += Math.min(structure.contentSections * 5, 20);
443
- if (structure.hasBreadcrumbs) contentClarity += 10;
444
- contentClarity += entity.hasDefinitions ? 15 : 0;
445
- contentClarity = Math.min(contentClarity, 100);
446
-
447
- // Fact density (citations, stats, specifics)
448
- let factDensity = 0;
449
- if (citation.hasStatistics) factDensity += 25;
450
- if (citation.hasCitations) factDensity += 20;
451
- if (citation.hasExternalLinks) factDensity += 15;
452
- if (citation.hasQuotes) factDensity += 15;
453
- factDensity += Math.min(entity.questionAnswerPairs * 5, 25);
454
- factDensity = Math.min(factDensity, 100);
455
-
456
- // Structure quality (schema, hierarchy)
457
- let structureQuality = 0;
458
- if (structure.hasStructuredData) structureQuality += 25;
459
- if (structure.hasFAQSchema) structureQuality += 20;
460
- if (structure.hasArticleSchema) structureQuality += 15;
461
- if (structure.hasHowToSchema) structureQuality += 15;
462
- if (structure.hasProductSchema) structureQuality += 10;
463
- structureQuality += structure.headingHierarchy === 'good' ? 15 : 0;
464
- structureQuality = Math.min(structureQuality, 100);
465
-
466
- // Citation quality (trust signals)
467
- let citationQuality = 0;
468
- citationQuality += citation.trustSignals.length * 12;
469
- if (citation.hasAuthorInfo) citationQuality += 15;
470
- if (citation.hasPublishDate && citation.hasLastModified) citationQuality += 15;
471
- citationQuality = Math.min(citationQuality, 100);
472
-
473
- // Overall LLM friendliness
474
- const overallLLMFriendliness = Math.round(
475
- (contentClarity * 0.25) +
476
- (factDensity * 0.25) +
477
- (structureQuality * 0.30) +
478
- (citationQuality * 0.20)
479
- );
480
-
481
- return {
482
- contentClarity,
483
- factDensity,
484
- structureQuality,
485
- citationQuality,
486
- overallLLMFriendliness,
487
- };
488
- }
489
-
490
- /**
491
- * Generate GEO-specific issues
492
- */
493
- export function generateGEOIssues(
494
- aiAccess: AIAccessResult,
495
- structure: ContentStructureResult,
496
- citation: CitationResult,
497
- entity: EntityResult,
498
- llmSignals: LLMSignalResult,
499
- url: string
500
- ): AuditIssue[] {
501
- const issues: AuditIssue[] = [];
502
-
503
- // Critical: AI crawler access issues
504
- if (aiAccess.blockedCrawlers.length > 0) {
505
- issues.push({
506
- code: 'GEO_AI_CRAWLERS_BLOCKED',
507
- severity: 'critical',
508
- category: 'technical',
509
- title: `${aiAccess.blockedCrawlers.length} AI crawlers blocked in robots.txt`,
510
- description: `The following AI crawlers are blocked: ${aiAccess.blockedCrawlers.join(', ')}. This prevents your content from appearing in AI search results.`,
511
- impact: 'Your content will NOT appear in ChatGPT, Perplexity, or Claude responses',
512
- howToFix: `Update robots.txt to allow AI crawlers:\n\nUser-agent: GPTBot\nAllow: /\n\nUser-agent: PerplexityBot\nAllow: /\n\nUser-agent: Claude-Web\nAllow: /`,
513
- affectedUrls: [url],
514
- });
515
- }
516
-
517
- // Critical: JS rendering required without prerendering
518
- if (aiAccess.jsRenderingRequired && !aiAccess.hasPrerendering) {
519
- issues.push({
520
- code: 'GEO_JS_RENDERING_REQUIRED',
521
- severity: 'critical',
522
- category: 'technical',
523
- title: 'JavaScript rendering required - AI crawlers see blank page',
524
- description: 'Your site requires JavaScript to render content. Most AI crawlers (GPTBot, PerplexityBot) do not execute JavaScript and will see a blank page.',
525
- impact: 'Zero visibility in AI search - crawlers cannot access your content',
526
- howToFix: 'Implement Server-Side Rendering (SSR) or Static Site Generation (SSG). For React: use Next.js. For Vue: use Nuxt. Alternatively, implement a prerendering service.',
527
- affectedUrls: [url],
528
- });
529
- }
530
-
531
- // High: No structured data
532
- if (!structure.hasStructuredData) {
533
- issues.push({
534
- code: 'GEO_NO_STRUCTURED_DATA',
535
- severity: 'warning',
536
- category: 'technical',
537
- title: 'No JSON-LD structured data found',
538
- description: 'Structured data helps AI systems understand your content\'s context, entities, and relationships.',
539
- impact: 'AI systems may misunderstand or skip your content',
540
- howToFix: 'Add JSON-LD structured data. At minimum, include Organization, WebPage, and Article/Product schemas.',
541
- affectedUrls: [url],
542
- });
543
- }
544
-
545
- // High: No FAQ schema (great for AI)
546
- if (!structure.hasFAQSchema && entity.questionAnswerPairs > 0) {
547
- issues.push({
548
- code: 'GEO_MISSING_FAQ_SCHEMA',
549
- severity: 'warning',
550
- category: 'technical',
551
- title: 'Q&A content without FAQPage schema',
552
- description: `Found ${entity.questionAnswerPairs} question-answer pairs but no FAQPage schema. FAQ schema is excellent for AI search visibility.`,
553
- impact: 'Missing opportunity for featured snippets and AI citations',
554
- howToFix: 'Add FAQPage schema markup for your Q&A content. This dramatically increases chances of being cited by AI.',
555
- affectedUrls: [url],
556
- });
557
- }
558
-
559
- // Medium: Poor heading hierarchy
560
- if (structure.headingHierarchy === 'poor') {
561
- issues.push({
562
- code: 'GEO_POOR_HEADING_STRUCTURE',
563
- severity: 'warning',
564
- category: 'content',
565
- title: 'Poor heading hierarchy hurts AI understanding',
566
- description: 'AI systems use heading structure to understand content organization. Your page lacks a clear H1 → H2 → H3 hierarchy.',
567
- impact: 'AI may struggle to extract key topics and relationships',
568
- howToFix: 'Structure content with one H1 (main topic), multiple H2s (subtopics), and H3s (details). Use question-format headings where appropriate.',
569
- affectedUrls: [url],
570
- });
571
- }
572
-
573
- // Medium: No citations or sources
574
- if (!citation.hasCitations && !citation.hasExternalLinks) {
575
- issues.push({
576
- code: 'GEO_NO_CITATIONS',
577
- severity: 'warning',
578
- category: 'content',
579
- title: 'No citations or source references',
580
- description: 'AI systems prioritize content with verifiable sources and citations. Your page lacks external references.',
581
- impact: 'Lower trust score in AI ranking - may not be cited as authoritative',
582
- howToFix: 'Add citations, link to authoritative sources, include statistics with references, and add expert quotes.',
583
- affectedUrls: [url],
584
- });
585
- }
586
-
587
- // Medium: No author info
588
- if (!citation.hasAuthorInfo) {
589
- issues.push({
590
- code: 'GEO_NO_AUTHOR_INFO',
591
- severity: 'info',
592
- category: 'content',
593
- title: 'Missing author attribution',
594
- description: 'Author information helps establish E-E-A-T (Experience, Expertise, Authoritativeness, Trustworthiness) for AI systems.',
595
- impact: 'Lower credibility score in AI ranking algorithms',
596
- howToFix: 'Add author byline, link to author bio/profile, and consider adding author schema markup.',
597
- affectedUrls: [url],
598
- });
599
- }
600
-
601
- // Medium: No publish/update dates
602
- if (!citation.hasPublishDate || !citation.hasLastModified) {
603
- issues.push({
604
- code: 'GEO_NO_DATES',
605
- severity: 'info',
606
- category: 'content',
607
- title: 'Missing publish/update dates',
608
- description: 'AI systems consider content freshness. Pages without dates may be considered outdated.',
609
- impact: 'May be deprioritized for time-sensitive queries',
610
- howToFix: 'Add visible publish date and "last updated" date. Include datePublished and dateModified in schema.',
611
- affectedUrls: [url],
612
- });
613
- }
614
-
615
- // Low LLM friendliness
616
- if (llmSignals.overallLLMFriendliness < 40) {
617
- issues.push({
618
- code: 'GEO_LOW_LLM_SCORE',
619
- severity: 'warning',
620
- category: 'content',
621
- title: `Low AI-friendliness score: ${llmSignals.overallLLMFriendliness}/100`,
622
- description: 'Your content structure and signals are not optimized for AI consumption. AI systems may struggle to extract and cite your content.',
623
- impact: 'Significantly reduced chances of appearing in AI search results',
624
- howToFix: 'Improve content structure (clear headings, lists, tables), add citations and statistics, include FAQ sections, and add comprehensive schema markup.',
625
- affectedUrls: [url],
626
- });
627
- }
628
-
629
- return issues;
630
- }
631
-
632
- /**
633
- * Main GEO analysis function
634
- */
635
- export async function analyzeGEO(
636
- html: string,
637
- url: string,
638
- robotsTxt?: string
639
- ): Promise<GEOAnalysisResult> {
640
- // Analyze AI crawler access
641
- let aiCrawlerAccess: AIAccessResult = {
642
- robotsTxtAllowsAI: true,
643
- blockedCrawlers: [],
644
- allowedCrawlers: Object.keys(AI_CRAWLERS),
645
- hasPrerendering: false,
646
- jsRenderingRequired: false,
647
- serverSideRendered: true,
648
- };
649
-
650
- if (robotsTxt) {
651
- const robotsAnalysis = analyzeRobotsTxtForAI(robotsTxt);
652
- aiCrawlerAccess.blockedCrawlers = robotsAnalysis.blocked;
653
- aiCrawlerAccess.allowedCrawlers = robotsAnalysis.allowed;
654
- aiCrawlerAccess.robotsTxtAllowsAI = robotsAnalysis.blocked.length === 0;
655
- }
656
-
657
- // Analyze rendering mode
658
- const renderingMode = detectRenderingMode(html);
659
- aiCrawlerAccess.hasPrerendering = renderingMode.hasPrerendering;
660
- aiCrawlerAccess.jsRenderingRequired = renderingMode.jsRenderingRequired;
661
- aiCrawlerAccess.serverSideRendered = renderingMode.serverSideRendered;
662
-
663
- // Analyze content structure
664
- const contentStructure = analyzeContentStructure(html);
665
-
666
- // Analyze citation readiness
667
- const citationReadiness = analyzeCitationReadiness(html);
668
-
669
- // Analyze entity extraction
670
- const entityExtraction = analyzeEntityExtraction(html);
671
-
672
- // Calculate LLM signals
673
- const llmSignals = calculateLLMSignals(
674
- contentStructure,
675
- citationReadiness,
676
- entityExtraction,
677
- html
678
- );
679
-
680
- // Generate issues
681
- const issues = generateGEOIssues(
682
- aiCrawlerAccess,
683
- contentStructure,
684
- citationReadiness,
685
- entityExtraction,
686
- llmSignals,
687
- url
688
- );
689
-
690
- // Generate recommendations
691
- const recommendations: string[] = [];
692
-
693
- if (aiCrawlerAccess.blockedCrawlers.length > 0) {
694
- recommendations.push('🚨 URGENT: Unblock AI crawlers in robots.txt');
695
- }
696
- if (aiCrawlerAccess.jsRenderingRequired) {
697
- recommendations.push('🚨 URGENT: Implement SSR/SSG for AI crawler access');
698
- }
699
- if (!contentStructure.hasFAQSchema && entityExtraction.questionAnswerPairs > 0) {
700
- recommendations.push('Add FAQPage schema for your Q&A content');
701
- }
702
- if (!contentStructure.hasStructuredData) {
703
- recommendations.push('Add JSON-LD structured data (Article, Organization)');
704
- }
705
- if (citationReadiness.trustSignals.length < 3) {
706
- recommendations.push('Add more trust signals: citations, statistics, author info');
707
- }
708
- if (contentStructure.listsAndTables < 2) {
709
- recommendations.push('Add lists and tables - AI loves structured content');
710
- }
711
- if (!entityExtraction.hasDefinitions) {
712
- recommendations.push('Add clear definitions for key terms');
713
- }
714
- if (entityExtraction.questionAnswerPairs < 3) {
715
- recommendations.push('Add FAQ section with common questions');
716
- }
717
-
718
- // Calculate overall GEO score
719
- let score = llmSignals.overallLLMFriendliness;
720
-
721
- // Penalties
722
- if (aiCrawlerAccess.blockedCrawlers.length > 0) {
723
- score -= aiCrawlerAccess.blockedCrawlers.length * 10;
724
- }
725
- if (aiCrawlerAccess.jsRenderingRequired && !aiCrawlerAccess.hasPrerendering) {
726
- score -= 30;
727
- }
728
-
729
- // Bonuses
730
- if (contentStructure.hasFAQSchema) score += 10;
731
- if (contentStructure.hasArticleSchema) score += 5;
732
- if (aiCrawlerAccess.robotsTxtAllowsAI) score += 10;
733
-
734
- score = Math.max(0, Math.min(100, score));
735
-
736
- return {
737
- score: Math.round(score),
738
- aiCrawlerAccess,
739
- contentStructure,
740
- citationReadiness,
741
- entityExtraction,
742
- llmSignals,
743
- issues,
744
- recommendations,
745
- };
746
- }
747
-
748
- /**
749
- * Generate AI-optimized robots.txt
750
- */
751
- export function generateAIFriendlyRobotsTxt(siteUrl: string): string {
752
- return `# AI-Optimized robots.txt
753
- # Generated by RankCLI - https://rankcli.dev
754
-
755
- # Allow all standard crawlers
756
- User-agent: *
757
- Allow: /
758
- Disallow: /api/
759
- Disallow: /admin/
760
- Disallow: /_next/static/
761
- Disallow: /private/
762
-
763
- # === AI Search Crawlers ===
764
- # OpenAI (ChatGPT)
765
- User-agent: GPTBot
766
- Allow: /
767
-
768
- User-agent: ChatGPT-User
769
- Allow: /
770
-
771
- User-agent: OAI-SearchBot
772
- Allow: /
773
-
774
- # Anthropic (Claude)
775
- User-agent: Claude-Web
776
- Allow: /
777
-
778
- User-agent: anthropic-ai
779
- Allow: /
780
-
781
- # Perplexity
782
- User-agent: PerplexityBot
783
- Allow: /
784
-
785
- # Google AI (Gemini/Bard)
786
- User-agent: Google-Extended
787
- Allow: /
788
-
789
- # Microsoft (Copilot)
790
- User-agent: bingbot
791
- Allow: /
792
-
793
- # Apple Intelligence
794
- User-agent: Applebot-Extended
795
- Allow: /
796
-
797
- # Meta AI
798
- User-agent: meta-externalagent
799
- Allow: /
800
-
801
- # You.com
802
- User-agent: YouBot
803
- Allow: /
804
-
805
- # Cohere
806
- User-agent: cohere-ai
807
- Allow: /
808
-
809
- # Sitemap
810
- Sitemap: ${siteUrl}/sitemap.xml
811
- `;
812
- }
813
-
814
- export const AI_CRAWLERS_INFO = AI_CRAWLERS;