@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,325 +0,0 @@
1
- #!/usr/bin/env npx tsx
2
- /**
3
- * Integration Test for SEO Audit Tool
4
- *
5
- * Tests the full workflow:
6
- * 1. Detect framework
7
- * 2. Run SEO audit
8
- * 3. Generate fixes
9
- * 4. Create conventional commits with co-author
10
- *
11
- * Usage:
12
- * npx tsx src/test/integration-test.ts [repo-path]
13
- *
14
- * Test repos in /workspace/test_repos/:
15
- * - html-portfolio (Pure HTML/CSS)
16
- * - astro-blog (Astro)
17
- * - hugo-xmin (Hugo)
18
- * - github-pages-site (Jekyll/GitHub Pages)
19
- */
20
-
21
- import * as fs from 'fs';
22
- import * as path from 'path';
23
- import { fileURLToPath } from 'url';
24
- import {
25
- formatSEOCommitMessage,
26
- createSEOCommit,
27
- generateCommitSummary,
28
- detectGitHubPages,
29
- isGitRepo,
30
- type SEOFixCommit,
31
- type CommitConfig,
32
- } from '../git/commit-helper.js';
33
-
34
- const __filename = fileURLToPath(import.meta.url);
35
- const __dirname = path.dirname(__filename);
36
-
37
- // Framework detection
38
- interface FrameworkInfo {
39
- name: string;
40
- type: 'static' | 'ssr' | 'spa';
41
- configFiles: string[];
42
- fixPattern: string;
43
- }
44
-
45
- const FRAMEWORKS: Record<string, FrameworkInfo> = {
46
- astro: {
47
- name: 'Astro',
48
- type: 'static',
49
- configFiles: ['astro.config.mjs', 'astro.config.ts', 'astro.config.js'],
50
- fixPattern: 'src/components/BaseHead.astro',
51
- },
52
- sveltekit: {
53
- name: 'SvelteKit',
54
- type: 'ssr',
55
- configFiles: ['svelte.config.js', 'svelte.config.ts'],
56
- fixPattern: 'src/routes/+layout.svelte',
57
- },
58
- nextjs: {
59
- name: 'Next.js',
60
- type: 'ssr',
61
- configFiles: ['next.config.js', 'next.config.ts', 'next.config.mjs'],
62
- fixPattern: 'app/layout.tsx',
63
- },
64
- hugo: {
65
- name: 'Hugo',
66
- type: 'static',
67
- configFiles: ['config.toml', 'config.yaml', 'hugo.toml', 'hugo.yaml'],
68
- fixPattern: 'layouts/partials/head.html',
69
- },
70
- jekyll: {
71
- name: 'Jekyll',
72
- type: 'static',
73
- configFiles: ['_config.yml', '_config.yaml'],
74
- fixPattern: '_includes/head.html',
75
- },
76
- html: {
77
- name: 'Static HTML',
78
- type: 'static',
79
- configFiles: [],
80
- fixPattern: 'index.html',
81
- },
82
- };
83
-
84
- function detectFramework(repoPath: string): FrameworkInfo {
85
- for (const [key, framework] of Object.entries(FRAMEWORKS)) {
86
- if (key === 'html') continue; // Fallback
87
-
88
- for (const configFile of framework.configFiles) {
89
- if (fs.existsSync(path.join(repoPath, configFile))) {
90
- return framework;
91
- }
92
- }
93
- }
94
-
95
- return FRAMEWORKS.html;
96
- }
97
-
98
- // Mock SEO audit results for testing
99
- interface MockAuditResult {
100
- category: string;
101
- issues: Array<{
102
- code: string;
103
- title: string;
104
- severity: 'error' | 'warning' | 'notice';
105
- affectedFiles: string[];
106
- }>;
107
- }
108
-
109
- function getMockAuditResults(framework: FrameworkInfo): MockAuditResult[] {
110
- // These simulate what a real audit would find
111
- return [
112
- {
113
- category: 'on-page',
114
- issues: [
115
- {
116
- code: 'TITLE_MISSING',
117
- title: 'Missing title tag',
118
- severity: 'error',
119
- affectedFiles: [framework.fixPattern],
120
- },
121
- {
122
- code: 'META_DESC_MISSING',
123
- title: 'Missing meta description',
124
- severity: 'error',
125
- affectedFiles: [framework.fixPattern],
126
- },
127
- ],
128
- },
129
- {
130
- category: 'social-meta',
131
- issues: [
132
- {
133
- code: 'OG_TITLE_MISSING',
134
- title: 'Missing Open Graph title',
135
- severity: 'warning',
136
- affectedFiles: [framework.fixPattern],
137
- },
138
- {
139
- code: 'TWITTER_CARD_MISSING',
140
- title: 'Missing Twitter Card meta tags',
141
- severity: 'warning',
142
- affectedFiles: [framework.fixPattern],
143
- },
144
- ],
145
- },
146
- {
147
- category: 'crawlability',
148
- issues: [
149
- {
150
- code: 'ROBOTS_TXT_MISSING',
151
- title: 'Missing robots.txt',
152
- severity: 'warning',
153
- affectedFiles: ['robots.txt'],
154
- },
155
- {
156
- code: 'SITEMAP_MISSING',
157
- title: 'Missing sitemap.xml',
158
- severity: 'warning',
159
- affectedFiles: ['sitemap.xml'],
160
- },
161
- ],
162
- },
163
- {
164
- category: 'structured-data',
165
- issues: [
166
- {
167
- code: 'SCHEMA_MISSING',
168
- title: 'No structured data found',
169
- severity: 'warning',
170
- affectedFiles: [framework.fixPattern],
171
- },
172
- ],
173
- },
174
- ];
175
- }
176
-
177
- // Generate mock fixes for testing
178
- function generateMockFixes(auditResults: MockAuditResult[]): SEOFixCommit[] {
179
- return auditResults.map(result => ({
180
- category: result.category,
181
- issues: result.issues.map(i => i.code),
182
- filesChanged: [...new Set(result.issues.flatMap(i => i.affectedFiles))],
183
- description: `add ${result.category.replace('-', ' ')} improvements`,
184
- }));
185
- }
186
-
187
- // Main test function
188
- async function runIntegrationTest(repoPath: string, options: { dryRun?: boolean } = {}) {
189
- console.log('═'.repeat(60));
190
- console.log('SEO AUDIT TOOL - INTEGRATION TEST');
191
- console.log('═'.repeat(60));
192
- console.log('');
193
-
194
- // Validate repo path
195
- if (!fs.existsSync(repoPath)) {
196
- console.error(`❌ Repository not found: ${repoPath}`);
197
- process.exit(1);
198
- }
199
-
200
- console.log(`📁 Repository: ${repoPath}`);
201
-
202
- // Check if it's a git repo
203
- const gitStatus = isGitRepo(repoPath);
204
- console.log(`📋 Git repo: ${gitStatus ? 'Yes' : 'No'}`);
205
-
206
- // Detect GitHub Pages
207
- const ghPages = detectGitHubPages(repoPath);
208
- if (ghPages.isGitHubPages) {
209
- console.log(`🌐 GitHub Pages: Yes (${ghPages.type})`);
210
- if (ghPages.baseUrl) {
211
- console.log(` Base URL: ${ghPages.baseUrl}`);
212
- }
213
- } else {
214
- console.log('🌐 GitHub Pages: No');
215
- }
216
-
217
- // Detect framework
218
- const framework = detectFramework(repoPath);
219
- console.log(`🔧 Framework: ${framework.name} (${framework.type})`);
220
- console.log(`📄 Fix target: ${framework.fixPattern}`);
221
- console.log('');
222
-
223
- // Run mock audit
224
- console.log('─'.repeat(60));
225
- console.log('RUNNING SEO AUDIT...');
226
- console.log('─'.repeat(60));
227
-
228
- const auditResults = getMockAuditResults(framework);
229
- let totalIssues = 0;
230
-
231
- for (const result of auditResults) {
232
- console.log(`\n📊 ${result.category.toUpperCase()}`);
233
- for (const issue of result.issues) {
234
- const icon = issue.severity === 'error' ? '❌' : issue.severity === 'warning' ? '⚠️' : 'ℹ️';
235
- console.log(` ${icon} ${issue.code}: ${issue.title}`);
236
- totalIssues++;
237
- }
238
- }
239
-
240
- console.log(`\n📈 Total issues found: ${totalIssues}`);
241
- console.log('');
242
-
243
- // Generate fixes
244
- console.log('─'.repeat(60));
245
- console.log('GENERATING FIXES...');
246
- console.log('─'.repeat(60));
247
-
248
- const fixes = generateMockFixes(auditResults);
249
-
250
- for (const fix of fixes) {
251
- console.log(`\n🔨 ${fix.category}`);
252
- console.log(` Description: ${fix.description}`);
253
- console.log(` Files: ${fix.filesChanged.join(', ')}`);
254
- console.log(` Issues: ${fix.issues.join(', ')}`);
255
- }
256
- console.log('');
257
-
258
- // Create commits
259
- console.log('─'.repeat(60));
260
- console.log('CREATING COMMITS...');
261
- console.log('─'.repeat(60));
262
- console.log('');
263
-
264
- const commitConfig: CommitConfig = {
265
- systemName: process.env.SEO_SYSTEM_NAME || 'SEO Autopilot',
266
- systemEmail: process.env.SEO_SYSTEM_EMAIL || 'bot@seo-autopilot.dev',
267
- dryRun: options.dryRun ?? true, // Default to dry run for safety
268
- };
269
-
270
- console.log(`🤖 Co-author: ${commitConfig.systemName} <${commitConfig.systemEmail}>`);
271
- console.log(`🏃 Mode: ${commitConfig.dryRun ? 'DRY RUN' : 'LIVE'}`);
272
- console.log('');
273
-
274
- for (const fix of fixes) {
275
- const message = formatSEOCommitMessage(fix, commitConfig);
276
- console.log('┌' + '─'.repeat(58) + '┐');
277
- console.log('│ COMMIT MESSAGE' + ' '.repeat(43) + '│');
278
- console.log('├' + '─'.repeat(58) + '┤');
279
- for (const line of message.split('\n')) {
280
- const paddedLine = line.padEnd(56).slice(0, 56);
281
- console.log(`│ ${paddedLine} │`);
282
- }
283
- console.log('└' + '─'.repeat(58) + '┘');
284
- console.log('');
285
- }
286
-
287
- // Summary
288
- console.log('─'.repeat(60));
289
- console.log('SUMMARY');
290
- console.log('─'.repeat(60));
291
- console.log('');
292
- console.log(`✅ Framework detected: ${framework.name}`);
293
- console.log(`✅ GitHub Pages: ${ghPages.isGitHubPages ? 'Yes' : 'No'}`);
294
- console.log(`✅ Issues found: ${totalIssues}`);
295
- console.log(`✅ Commits prepared: ${fixes.length}`);
296
- console.log('');
297
-
298
- if (commitConfig.dryRun) {
299
- console.log('💡 Run with --live to create actual commits');
300
- }
301
-
302
- return {
303
- framework,
304
- ghPages,
305
- auditResults,
306
- fixes,
307
- totalIssues,
308
- };
309
- }
310
-
311
- // CLI entry point
312
- const args = process.argv.slice(2);
313
- const repoPath = args[0] || path.join(__dirname, '../../../../test_repos/html-portfolio');
314
- const isLive = args.includes('--live');
315
-
316
- runIntegrationTest(repoPath, { dryRun: !isLive })
317
- .then(() => {
318
- console.log('═'.repeat(60));
319
- console.log('TEST COMPLETE');
320
- console.log('═'.repeat(60));
321
- })
322
- .catch((error) => {
323
- console.error('Test failed:', error);
324
- process.exit(1);
325
- });
@@ -1,373 +0,0 @@
1
- import { crawlUrl, extractMeta, analyzeHeadings, extractImages, extractLinks, extractSchema, checkRobots, checkSitemap } from './crawl.js';
2
- import type { SEOIssue, SEOAnalysisResult, MetaData, HeadingStructure, ImageInfo, ToolResult } from '../types.js';
3
-
4
- export async function analyzeUrl(params: { url: string }): Promise<ToolResult> {
5
- const { url } = params;
6
- const issues: SEOIssue[] = [];
7
-
8
- try {
9
- // Crawl the page
10
- const crawlResult = await crawlUrl({ url });
11
- if (!crawlResult.success || !crawlResult.data) {
12
- return { success: false, error: `Failed to crawl URL: ${crawlResult.error}` };
13
- }
14
-
15
- const { html, statusCode, loadTime } = crawlResult.data as { html: string; statusCode: number; loadTime: number };
16
-
17
- if (statusCode !== 200) {
18
- issues.push({
19
- severity: 'critical',
20
- category: 'technical',
21
- code: 'HTTP_ERROR',
22
- message: `Page returned HTTP ${statusCode}`,
23
- impact: 'Search engines cannot index pages that return error codes',
24
- });
25
- }
26
-
27
- // Extract meta tags
28
- const metaResult = await extractMeta({ html, url });
29
- if (metaResult.success && metaResult.data) {
30
- const meta = metaResult.data as MetaData;
31
- analyzeMeta(meta, url, issues);
32
- }
33
-
34
- // Analyze headings
35
- const headingsResult = await analyzeHeadings({ html });
36
- if (headingsResult.success && headingsResult.data) {
37
- const headings = headingsResult.data as HeadingStructure[];
38
- analyzeHeadingStructure(headings, issues);
39
- }
40
-
41
- // Extract and analyze images
42
- const imagesResult = await extractImages({ html });
43
- if (imagesResult.success && imagesResult.data) {
44
- const images = imagesResult.data as ImageInfo[];
45
- analyzeImages(images, issues);
46
- }
47
-
48
- // Extract schema
49
- const schemaResult = await extractSchema({ html });
50
- if (schemaResult.success) {
51
- const schemas = schemaResult.data as { type: string; data: unknown }[];
52
- if (!schemas || schemas.length === 0) {
53
- issues.push({
54
- severity: 'warning',
55
- category: 'schema',
56
- code: 'MISSING_SCHEMA',
57
- message: 'No JSON-LD structured data found',
58
- impact: 'Missing rich snippets in search results. Add Schema.org markup for your content type.',
59
- });
60
- }
61
- }
62
-
63
- // Check robots.txt
64
- const robotsResult = await checkRobots({ url });
65
- if (robotsResult.success) {
66
- const robots = robotsResult.data as { exists: boolean };
67
- if (!robots.exists) {
68
- issues.push({
69
- severity: 'warning',
70
- category: 'technical',
71
- code: 'MISSING_ROBOTS',
72
- message: 'No robots.txt file found',
73
- impact: 'Provide crawling instructions to search engines with robots.txt',
74
- });
75
- }
76
- }
77
-
78
- // Check sitemap
79
- const sitemapResult = await checkSitemap({ url });
80
- if (sitemapResult.success) {
81
- const sitemap = sitemapResult.data as { exists: boolean };
82
- if (!sitemap.exists) {
83
- issues.push({
84
- severity: 'warning',
85
- category: 'technical',
86
- code: 'MISSING_SITEMAP',
87
- message: 'No sitemap.xml found',
88
- impact: 'Sitemap helps search engines discover and index all your pages',
89
- });
90
- }
91
- }
92
-
93
- // Performance check
94
- if (loadTime > 3000) {
95
- issues.push({
96
- severity: loadTime > 5000 ? 'critical' : 'warning',
97
- category: 'performance',
98
- code: 'SLOW_LOAD_TIME',
99
- message: `Page load time is ${(loadTime / 1000).toFixed(1)}s`,
100
- impact: 'Slow pages hurt user experience and search rankings. Target <2.5s LCP.',
101
- });
102
- }
103
-
104
- // Calculate score
105
- const score = calculateScore(issues);
106
-
107
- const result: SEOAnalysisResult = {
108
- url,
109
- score,
110
- issues,
111
- recommendations: generateRecommendations(issues),
112
- };
113
-
114
- return { success: true, data: result };
115
- } catch (error) {
116
- return {
117
- success: false,
118
- error: error instanceof Error ? error.message : 'Analysis failed'
119
- };
120
- }
121
- }
122
-
123
- function analyzeMeta(meta: MetaData, url: string, issues: SEOIssue[]): void {
124
- // Title
125
- if (!meta.title) {
126
- issues.push({
127
- severity: 'critical',
128
- category: 'meta',
129
- code: 'MISSING_TITLE',
130
- message: 'Missing title tag',
131
- impact: 'Title is the most important on-page SEO element. Every page needs a unique title.',
132
- fix: {
133
- file: 'index.html',
134
- before: null,
135
- after: '<title>Your Page Title - Brand Name</title>',
136
- }
137
- });
138
- } else if (meta.title.length < 30) {
139
- issues.push({
140
- severity: 'warning',
141
- category: 'meta',
142
- code: 'TITLE_TOO_SHORT',
143
- message: `Title too short (${meta.title.length} chars)`,
144
- impact: 'Longer titles provide more context. Aim for 50-60 characters.',
145
- element: meta.title,
146
- });
147
- } else if (meta.title.length > 60) {
148
- issues.push({
149
- severity: 'warning',
150
- category: 'meta',
151
- code: 'TITLE_TOO_LONG',
152
- message: `Title too long (${meta.title.length} chars)`,
153
- impact: 'Titles over 60 characters get truncated in search results.',
154
- element: meta.title.substring(0, 60) + '...',
155
- });
156
- }
157
-
158
- // Meta description
159
- if (!meta.description) {
160
- issues.push({
161
- severity: 'critical',
162
- category: 'meta',
163
- code: 'MISSING_META_DESC',
164
- message: 'Missing meta description',
165
- impact: 'Meta description appears in search results and affects click-through rate.',
166
- fix: {
167
- file: 'index.html',
168
- before: null,
169
- after: '<meta name="description" content="A compelling description of your page in 150-160 characters." />',
170
- }
171
- });
172
- } else if (meta.description.length < 120) {
173
- issues.push({
174
- severity: 'warning',
175
- category: 'meta',
176
- code: 'META_DESC_TOO_SHORT',
177
- message: `Meta description too short (${meta.description.length} chars)`,
178
- impact: 'Aim for 150-160 characters for optimal display in search results.',
179
- });
180
- } else if (meta.description.length > 160) {
181
- issues.push({
182
- severity: 'info',
183
- category: 'meta',
184
- code: 'META_DESC_TOO_LONG',
185
- message: `Meta description may be truncated (${meta.description.length} chars)`,
186
- impact: 'Descriptions over 160 characters may be cut off in search results.',
187
- });
188
- }
189
-
190
- // Canonical URL
191
- if (!meta.canonical) {
192
- issues.push({
193
- severity: 'warning',
194
- category: 'technical',
195
- code: 'MISSING_CANONICAL',
196
- message: 'No canonical URL specified',
197
- impact: 'Canonical tags prevent duplicate content issues.',
198
- fix: {
199
- file: 'index.html',
200
- before: null,
201
- after: `<link rel="canonical" href="${url}" />`,
202
- }
203
- });
204
- }
205
-
206
- // Viewport
207
- if (!meta.viewport) {
208
- issues.push({
209
- severity: 'critical',
210
- category: 'technical',
211
- code: 'MISSING_VIEWPORT',
212
- message: 'Missing viewport meta tag',
213
- impact: 'Required for mobile-friendly pages. Google uses mobile-first indexing.',
214
- fix: {
215
- file: 'index.html',
216
- before: null,
217
- after: '<meta name="viewport" content="width=device-width, initial-scale=1" />',
218
- }
219
- });
220
- }
221
-
222
- // Open Graph
223
- const missingOG: string[] = [];
224
- if (!meta.openGraph.title) missingOG.push('og:title');
225
- if (!meta.openGraph.description) missingOG.push('og:description');
226
- if (!meta.openGraph.image) missingOG.push('og:image');
227
-
228
- if (missingOG.length > 0) {
229
- issues.push({
230
- severity: 'warning',
231
- category: 'social',
232
- code: 'MISSING_OG_TAGS',
233
- message: `Missing Open Graph tags: ${missingOG.join(', ')}`,
234
- impact: 'Open Graph tags control how your page appears when shared on social media.',
235
- });
236
- }
237
-
238
- // Twitter Card
239
- if (!meta.twitter.card) {
240
- issues.push({
241
- severity: 'info',
242
- category: 'social',
243
- code: 'MISSING_TWITTER_CARD',
244
- message: 'Missing Twitter Card meta tags',
245
- impact: 'Twitter/X cards improve visibility when your content is shared.',
246
- });
247
- }
248
- }
249
-
250
- function analyzeHeadingStructure(headings: HeadingStructure[], issues: SEOIssue[]): void {
251
- const h1s = headings.filter(h => h.level === 1);
252
-
253
- if (h1s.length === 0) {
254
- issues.push({
255
- severity: 'critical',
256
- category: 'content',
257
- code: 'MISSING_H1',
258
- message: 'No H1 heading found',
259
- impact: 'Every page should have exactly one H1 that describes the main content.',
260
- });
261
- } else if (h1s.length > 1) {
262
- issues.push({
263
- severity: 'warning',
264
- category: 'content',
265
- code: 'MULTIPLE_H1',
266
- message: `Multiple H1 headings found (${h1s.length})`,
267
- impact: 'Best practice is one H1 per page. Use H2-H6 for subsections.',
268
- element: h1s.map(h => h.text).join(', '),
269
- });
270
- }
271
-
272
- // Check for skipped heading levels
273
- let prevLevel = 0;
274
- for (const h of headings) {
275
- if (h.level > prevLevel + 1 && prevLevel > 0) {
276
- issues.push({
277
- severity: 'info',
278
- category: 'content',
279
- code: 'SKIPPED_HEADING_LEVEL',
280
- message: `Skipped heading level: H${prevLevel} to H${h.level}`,
281
- impact: 'Maintain proper heading hierarchy for accessibility and SEO.',
282
- });
283
- break; // Only report once
284
- }
285
- prevLevel = h.level;
286
- }
287
- }
288
-
289
- function analyzeImages(images: ImageInfo[], issues: SEOIssue[]): void {
290
- const missingAlt = images.filter(img => !img.alt);
291
-
292
- if (missingAlt.length > 0) {
293
- issues.push({
294
- severity: 'warning',
295
- category: 'accessibility',
296
- code: 'IMAGES_MISSING_ALT',
297
- message: `${missingAlt.length} image(s) missing alt text`,
298
- impact: 'Alt text is essential for accessibility and helps search engines understand images.',
299
- element: missingAlt.slice(0, 3).map(i => i.src).join(', '),
300
- });
301
- }
302
-
303
- const missingDimensions = images.filter(img => !img.width || !img.height);
304
- if (missingDimensions.length > 0) {
305
- issues.push({
306
- severity: 'info',
307
- category: 'performance',
308
- code: 'IMAGES_MISSING_DIMENSIONS',
309
- message: `${missingDimensions.length} image(s) missing width/height`,
310
- impact: 'Specifying dimensions prevents layout shift (CLS).',
311
- });
312
- }
313
- }
314
-
315
- function calculateScore(issues: SEOIssue[]): number {
316
- const weights = {
317
- critical: 15,
318
- warning: 5,
319
- info: 1,
320
- };
321
-
322
- let totalDeduction = 0;
323
- for (const issue of issues) {
324
- totalDeduction += weights[issue.severity];
325
- }
326
-
327
- return Math.max(0, Math.min(100, 100 - totalDeduction));
328
- }
329
-
330
- function generateRecommendations(issues: SEOIssue[]) {
331
- const recommendations = [];
332
-
333
- const criticalCount = issues.filter(i => i.severity === 'critical').length;
334
- const warningCount = issues.filter(i => i.severity === 'warning').length;
335
-
336
- if (criticalCount > 0) {
337
- recommendations.push({
338
- priority: 'high' as const,
339
- category: 'immediate',
340
- message: `Fix ${criticalCount} critical issue(s) first`,
341
- impact: 'Critical issues directly impact search visibility',
342
- });
343
- }
344
-
345
- if (issues.some(i => i.code === 'MISSING_SCHEMA')) {
346
- recommendations.push({
347
- priority: 'high' as const,
348
- category: 'schema',
349
- message: 'Add JSON-LD structured data',
350
- impact: 'Enable rich snippets in search results',
351
- });
352
- }
353
-
354
- if (issues.some(i => i.code.includes('OG') || i.code.includes('TWITTER'))) {
355
- recommendations.push({
356
- priority: 'medium' as const,
357
- category: 'social',
358
- message: 'Complete social media meta tags',
359
- impact: 'Improve appearance when shared on social platforms',
360
- });
361
- }
362
-
363
- if (warningCount > 3) {
364
- recommendations.push({
365
- priority: 'medium' as const,
366
- category: 'optimization',
367
- message: `Address ${warningCount} warnings to improve score`,
368
- impact: 'Each fix improves overall SEO health',
369
- });
370
- }
371
-
372
- return recommendations;
373
- }