@rankcli/agent-runtime 0.0.14 → 0.0.16

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 (199) hide show
  1. package/dist/index.d.mts +77 -393
  2. package/dist/index.d.ts +77 -393
  3. package/dist/index.js +417 -6443
  4. package/dist/index.mjs +296 -6313
  5. package/package.json +6 -1
  6. package/scripts/build-deno.ts +0 -134
  7. package/src/analyzers/core-web-vitals-analyzer.test.ts +0 -236
  8. package/src/analyzers/core-web-vitals-analyzer.ts +0 -557
  9. package/src/analyzers/geo-analyzer.test.ts +0 -310
  10. package/src/analyzers/geo-analyzer.ts +0 -814
  11. package/src/analyzers/image-optimization-analyzer.test.ts +0 -145
  12. package/src/analyzers/image-optimization-analyzer.ts +0 -348
  13. package/src/analyzers/index.ts +0 -233
  14. package/src/analyzers/internal-linking-analyzer.test.ts +0 -141
  15. package/src/analyzers/internal-linking-analyzer.ts +0 -419
  16. package/src/analyzers/mobile-seo-analyzer.test.ts +0 -140
  17. package/src/analyzers/mobile-seo-analyzer.ts +0 -455
  18. package/src/analyzers/security-headers-analyzer.test.ts +0 -115
  19. package/src/analyzers/security-headers-analyzer.ts +0 -318
  20. package/src/analyzers/structured-data-analyzer.test.ts +0 -210
  21. package/src/analyzers/structured-data-analyzer.ts +0 -590
  22. package/src/audit/ai/analyzer.ts +0 -347
  23. package/src/audit/ai/index.ts +0 -29
  24. package/src/audit/ai/prompts/content-analysis.ts +0 -271
  25. package/src/audit/ai/types.ts +0 -179
  26. package/src/audit/checks/additional-checks.ts +0 -439
  27. package/src/audit/checks/ai-citation-worthiness.ts +0 -399
  28. package/src/audit/checks/ai-content-structure.ts +0 -325
  29. package/src/audit/checks/ai-readiness.ts +0 -339
  30. package/src/audit/checks/anchor-text.ts +0 -179
  31. package/src/audit/checks/answer-conciseness.ts +0 -322
  32. package/src/audit/checks/asset-minification.ts +0 -270
  33. package/src/audit/checks/bing-optimization.ts +0 -206
  34. package/src/audit/checks/brand-mention-optimization.ts +0 -349
  35. package/src/audit/checks/caching-headers.ts +0 -305
  36. package/src/audit/checks/canonical-advanced.ts +0 -150
  37. package/src/audit/checks/canonical-domain.ts +0 -196
  38. package/src/audit/checks/citation-quality.ts +0 -358
  39. package/src/audit/checks/client-rendering.ts +0 -542
  40. package/src/audit/checks/color-contrast.ts +0 -342
  41. package/src/audit/checks/content-freshness.ts +0 -170
  42. package/src/audit/checks/content-science.ts +0 -589
  43. package/src/audit/checks/conversion-elements.ts +0 -526
  44. package/src/audit/checks/crawlability.ts +0 -220
  45. package/src/audit/checks/directory-listing.ts +0 -172
  46. package/src/audit/checks/dom-analysis.ts +0 -191
  47. package/src/audit/checks/dom-size.ts +0 -246
  48. package/src/audit/checks/duplicate-content.ts +0 -194
  49. package/src/audit/checks/eeat-signals.ts +0 -990
  50. package/src/audit/checks/entity-seo.ts +0 -396
  51. package/src/audit/checks/featured-snippet.ts +0 -473
  52. package/src/audit/checks/freshness-signals.ts +0 -443
  53. package/src/audit/checks/funnel-intent.ts +0 -463
  54. package/src/audit/checks/hreflang.ts +0 -174
  55. package/src/audit/checks/html-compliance.ts +0 -302
  56. package/src/audit/checks/image-dimensions.ts +0 -167
  57. package/src/audit/checks/images.ts +0 -160
  58. package/src/audit/checks/indexnow.ts +0 -275
  59. package/src/audit/checks/interactive-tools.ts +0 -475
  60. package/src/audit/checks/internal-link-graph.ts +0 -436
  61. package/src/audit/checks/keyword-analysis.ts +0 -239
  62. package/src/audit/checks/keyword-cannibalization.ts +0 -385
  63. package/src/audit/checks/keyword-placement.ts +0 -471
  64. package/src/audit/checks/links.ts +0 -273
  65. package/src/audit/checks/llms-txt.ts +0 -224
  66. package/src/audit/checks/local-seo.ts +0 -296
  67. package/src/audit/checks/mobile.ts +0 -167
  68. package/src/audit/checks/modern-images.ts +0 -226
  69. package/src/audit/checks/navboost-signals.ts +0 -395
  70. package/src/audit/checks/on-page.ts +0 -209
  71. package/src/audit/checks/page-resources.ts +0 -285
  72. package/src/audit/checks/pagination.ts +0 -180
  73. package/src/audit/checks/performance.ts +0 -153
  74. package/src/audit/checks/platform-presence.ts +0 -580
  75. package/src/audit/checks/redirect-analysis.ts +0 -153
  76. package/src/audit/checks/redirect-chain.ts +0 -389
  77. package/src/audit/checks/resource-hints.ts +0 -420
  78. package/src/audit/checks/responsive-css.ts +0 -247
  79. package/src/audit/checks/responsive-images.ts +0 -396
  80. package/src/audit/checks/review-ecosystem.ts +0 -415
  81. package/src/audit/checks/robots-validation.ts +0 -373
  82. package/src/audit/checks/security-headers.ts +0 -188
  83. package/src/audit/checks/security.ts +0 -144
  84. package/src/audit/checks/serp-preview.ts +0 -251
  85. package/src/audit/checks/site-maturity.ts +0 -453
  86. package/src/audit/checks/social-meta.test.ts +0 -275
  87. package/src/audit/checks/social-meta.ts +0 -134
  88. package/src/audit/checks/soft-404.ts +0 -151
  89. package/src/audit/checks/structured-data.ts +0 -238
  90. package/src/audit/checks/tech-detection.ts +0 -496
  91. package/src/audit/checks/topical-clusters.ts +0 -435
  92. package/src/audit/checks/tracker-bloat.ts +0 -462
  93. package/src/audit/checks/tracking-verification.test.ts +0 -371
  94. package/src/audit/checks/tracking-verification.ts +0 -636
  95. package/src/audit/checks/url-safety.ts +0 -682
  96. package/src/audit/deno-entry.ts +0 -66
  97. package/src/audit/discovery/index.ts +0 -15
  98. package/src/audit/discovery/link-crawler.ts +0 -233
  99. package/src/audit/discovery/repo-routes.ts +0 -347
  100. package/src/audit/engine.ts +0 -627
  101. package/src/audit/fixes/index.ts +0 -209
  102. package/src/audit/fixes/social-meta-fixes.test.ts +0 -329
  103. package/src/audit/fixes/social-meta-fixes.ts +0 -463
  104. package/src/audit/index.ts +0 -74
  105. package/src/audit/runner.test.ts +0 -299
  106. package/src/audit/runner.ts +0 -130
  107. package/src/audit/types.ts +0 -1963
  108. package/src/content/featured-snippet.ts +0 -367
  109. package/src/content/generator.test.ts +0 -534
  110. package/src/content/generator.ts +0 -501
  111. package/src/content/headline.ts +0 -317
  112. package/src/content/index.ts +0 -62
  113. package/src/content/intent.ts +0 -258
  114. package/src/content/keyword-density.ts +0 -349
  115. package/src/content/readability.ts +0 -262
  116. package/src/executor.ts +0 -336
  117. package/src/fixer/framework-fixes.test.ts +0 -489
  118. package/src/fixer/framework-fixes.ts +0 -5287
  119. package/src/fixer/index.ts +0 -6
  120. package/src/fixer/schemas.ts +0 -971
  121. package/src/fixer.ts +0 -642
  122. package/src/frameworks/detector.test.ts +0 -248
  123. package/src/frameworks/detector.ts +0 -899
  124. package/src/frameworks/index.ts +0 -68
  125. package/src/frameworks/recipes/angular.yaml +0 -171
  126. package/src/frameworks/recipes/astro.yaml +0 -206
  127. package/src/frameworks/recipes/django.yaml +0 -180
  128. package/src/frameworks/recipes/laravel.yaml +0 -137
  129. package/src/frameworks/recipes/nextjs.yaml +0 -268
  130. package/src/frameworks/recipes/nuxt.yaml +0 -175
  131. package/src/frameworks/recipes/rails.yaml +0 -188
  132. package/src/frameworks/recipes/react.yaml +0 -202
  133. package/src/frameworks/recipes/sveltekit.yaml +0 -154
  134. package/src/frameworks/recipes/vue.yaml +0 -137
  135. package/src/frameworks/recipes/wordpress.yaml +0 -209
  136. package/src/frameworks/suggestion-engine.ts +0 -357
  137. package/src/geo/geo-content.test.ts +0 -305
  138. package/src/geo/geo-content.ts +0 -266
  139. package/src/geo/geo-history.test.ts +0 -473
  140. package/src/geo/geo-history.ts +0 -433
  141. package/src/geo/geo-tracker.test.ts +0 -359
  142. package/src/geo/geo-tracker.ts +0 -411
  143. package/src/geo/index.ts +0 -11
  144. package/src/geo/llm-citation-checker.ts +0 -188
  145. package/src/git/commit-helper.test.ts +0 -261
  146. package/src/git/commit-helper.ts +0 -329
  147. package/src/git/index.ts +0 -12
  148. package/src/git/pr-helper.test.ts +0 -284
  149. package/src/git/pr-helper.ts +0 -307
  150. package/src/index.ts +0 -76
  151. package/src/keywords/ai-keyword-engine.ts +0 -1062
  152. package/src/keywords/ai-summarizer.ts +0 -387
  153. package/src/keywords/ci-mode.ts +0 -555
  154. package/src/keywords/engine.ts +0 -359
  155. package/src/keywords/index.ts +0 -151
  156. package/src/keywords/llm-judge.ts +0 -357
  157. package/src/keywords/nlp-analysis.ts +0 -706
  158. package/src/keywords/prioritizer.ts +0 -295
  159. package/src/keywords/site-crawler.ts +0 -342
  160. package/src/keywords/sources/autocomplete.ts +0 -139
  161. package/src/keywords/sources/competitive-search.ts +0 -450
  162. package/src/keywords/sources/competitor-analysis.ts +0 -374
  163. package/src/keywords/sources/dataforseo.ts +0 -206
  164. package/src/keywords/sources/free-sources.ts +0 -294
  165. package/src/keywords/sources/gsc.ts +0 -123
  166. package/src/keywords/topic-grouping.ts +0 -327
  167. package/src/keywords/types.ts +0 -144
  168. package/src/keywords/wizard.ts +0 -457
  169. package/src/loader.ts +0 -40
  170. package/src/ranking/index.ts +0 -5
  171. package/src/ranking/serp-client.ts +0 -348
  172. package/src/ranking/tracker.ts +0 -380
  173. package/src/ranking/types.ts +0 -123
  174. package/src/reports/index.ts +0 -7
  175. package/src/reports/report-generator.test.ts +0 -293
  176. package/src/reports/report-generator.ts +0 -713
  177. package/src/scheduler/alerts.test.ts +0 -458
  178. package/src/scheduler/alerts.ts +0 -328
  179. package/src/scheduler/index.ts +0 -8
  180. package/src/scheduler/scheduled-audit.test.ts +0 -377
  181. package/src/scheduler/scheduled-audit.ts +0 -149
  182. package/src/test/integration-test.ts +0 -325
  183. package/src/tools/analyzer.ts +0 -373
  184. package/src/tools/crawl.ts +0 -293
  185. package/src/tools/files.ts +0 -301
  186. package/src/tools/h1-fixer.ts +0 -249
  187. package/src/tools/index.ts +0 -67
  188. package/src/tracking/github-action.ts +0 -326
  189. package/src/tracking/google-analytics.ts +0 -265
  190. package/src/tracking/index.ts +0 -45
  191. package/src/tracking/report-generator.ts +0 -386
  192. package/src/tracking/search-console.ts +0 -335
  193. package/src/types.ts +0 -148
  194. package/src/utils/http.ts +0 -302
  195. package/src/wasm-adapter.ts +0 -297
  196. package/src/wasm-entry.ts +0 -14
  197. package/tsconfig.json +0 -17
  198. package/tsup.wasm.config.ts +0 -26
  199. package/vitest.config.ts +0 -15
package/src/fixer.ts DELETED
@@ -1,642 +0,0 @@
1
- import { readFileSync, existsSync, writeFileSync } from 'fs';
2
- import { join } from 'path';
3
- import type { SEOIssue, Fix, FrameworkInfo } from './types.js';
4
- import { detectFramework, findHtmlEntry, readFile } from './tools/files.js';
5
- import { generateH1Fix } from './tools/h1-fixer.js';
6
- import { getFrameworkSpecificFix } from './fixer/framework-fixes.js';
7
-
8
- export interface FixGeneratorOptions {
9
- cwd: string;
10
- url?: string;
11
- framework?: FrameworkInfo;
12
- }
13
-
14
- export interface GeneratedFix extends Fix {
15
- applied?: boolean;
16
- skipped?: boolean;
17
- skipReason?: string;
18
- }
19
-
20
- // Generate fixes for SEO issues based on framework
21
- export async function generateFixes(
22
- issues: SEOIssue[],
23
- options: FixGeneratorOptions
24
- ): Promise<GeneratedFix[]> {
25
- const { cwd, url } = options;
26
-
27
- // Detect framework if not provided
28
- let framework = options.framework;
29
- if (!framework) {
30
- const result = await detectFramework({ cwd });
31
- framework = result.success ? (result.data as FrameworkInfo) : { name: 'Unknown', metaPattern: 'html-head' as const };
32
- }
33
-
34
- const fixes: GeneratedFix[] = [];
35
-
36
- // Find the HTML entry point for Vite/React apps
37
- const htmlEntry = await findHtmlEntry({ cwd });
38
- const htmlPath = htmlEntry.success ? (htmlEntry.data as { path: string; content: string }).path : 'index.html';
39
- const htmlContent = htmlEntry.success ? (htmlEntry.data as { path: string; content: string }).content : '';
40
-
41
- for (const issue of issues) {
42
- const fix = await generateFixForIssue(issue, {
43
- cwd,
44
- url,
45
- framework,
46
- htmlPath,
47
- htmlContent,
48
- });
49
-
50
- if (fix) {
51
- fixes.push(fix);
52
- }
53
- }
54
-
55
- return fixes;
56
- }
57
-
58
- interface FixContext {
59
- cwd: string;
60
- url?: string;
61
- framework: FrameworkInfo;
62
- htmlPath: string;
63
- htmlContent: string;
64
- }
65
-
66
- async function generateFixForIssue(
67
- issue: SEOIssue,
68
- context: FixContext
69
- ): Promise<GeneratedFix | null> {
70
- const { cwd, url, framework, htmlPath, htmlContent } = context;
71
- const fullUrl = url || 'https://example.com';
72
- const siteName = new URL(fullUrl).hostname.replace('www.', '');
73
-
74
- switch (issue.code) {
75
- // Title issues
76
- case 'MISSING_TITLE':
77
- case 'TITLE_MISSING': // Full audit code
78
- case 'TITLE_KEYWORD_MISMATCH':
79
- case 'TITLE_H1_KEYWORD_MISMATCH':
80
- case 'OUTDATED_YEAR_IN_TITLE':
81
- return generateTitleFix(context, siteName);
82
-
83
- // Meta description issues
84
- case 'MISSING_META_DESC':
85
- case 'META_DESC_MISSING': // Full audit code
86
- return generateMetaDescFix(context, siteName);
87
-
88
- // Canonical issues
89
- case 'MISSING_CANONICAL':
90
- case 'CANONICAL_MISSING': // Full audit code
91
- case 'CANONICAL_NO_HTTPS_REDIRECT':
92
- return generateCanonicalFix(context, fullUrl);
93
-
94
- // Viewport issues
95
- case 'MISSING_VIEWPORT':
96
- case 'HTML_NO_VIEWPORT':
97
- case 'RESPONSIVE_NO_VIEWPORT':
98
- case 'VIEWPORT_MISSING': // Full audit code
99
- return generateViewportFix(context);
100
-
101
- // Open Graph issues
102
- case 'MISSING_OG_TAGS':
103
- case 'OG_TITLE_MISSING':
104
- case 'OG_DESC_MISSING':
105
- case 'OG_DESCRIPTION_MISSING': // Full audit code
106
- case 'OG_IMAGE_MISSING':
107
- case 'OG_URL_MISSING':
108
- case 'OG_TYPE_MISSING':
109
- return generateOGFix(context, siteName, fullUrl);
110
-
111
- // Twitter Card issues
112
- case 'MISSING_TWITTER_CARD':
113
- case 'TWITTER_CARD_MISSING':
114
- case 'TWITTER_TITLE_MISSING':
115
- case 'TWITTER_DESC_MISSING':
116
- case 'TWITTER_DESCRIPTION_MISSING': // Full audit code
117
- case 'TWITTER_IMAGE_MISSING':
118
- return generateTwitterFix(context, siteName);
119
-
120
- // Schema/structured data issues
121
- case 'MISSING_SCHEMA':
122
- case 'SCHEMA_MISSING': // Full audit code
123
- case 'SCHEMA_ORG_MISSING':
124
- case 'NO_ORGANIZATION_SCHEMA':
125
- case 'NO_ENTITY_SCHEMA':
126
- case 'FAQ_SCHEMA_MISSING':
127
- return generateSchemaFix(context, siteName, fullUrl);
128
-
129
- // Robots.txt issues
130
- case 'MISSING_ROBOTS':
131
- case 'ROBOTS_TXT_MISSING': // Full audit code
132
- case 'ROBOTS_TXT_WARNINGS':
133
- case 'ROBOTS_TXT_INVALID_SYNTAX':
134
- return generateRobotsFix(context, fullUrl);
135
-
136
- // Sitemap issues
137
- case 'MISSING_SITEMAP':
138
- case 'SITEMAP_MISSING': // Full audit code
139
- case 'BING_SITEMAP_MISSING':
140
- return generateSitemapFix(context, fullUrl);
141
-
142
- // H1 issues
143
- case 'MISSING_H1':
144
- case 'H1_MISSING': // Full audit code
145
- case 'NO_VISIBLE_HEADLINE':
146
- case 'H1_MISSING_KEYWORD':
147
- return await generateH1Fix({ cwd });
148
-
149
- // SPA-specific: add meta management library recommendation
150
- case 'SPA_NO_META_MANAGEMENT':
151
- case 'SPA_WITHOUT_SSR':
152
- case 'CLIENT_SIDE_RENDERING':
153
- return generateSPAMetaFix(context, framework);
154
-
155
- // Internal links - suggest adding links
156
- case 'NO_INTERNAL_LINKS':
157
- case 'LINKS_NO_INTERNAL':
158
- case 'NO_CONTENT_INTERNAL_LINKS':
159
- return {
160
- issue: { code: issue.code, message: 'No internal links found', severity: 'warning' },
161
- file: 'src/components/Footer.tsx',
162
- before: null,
163
- after: `// Add internal navigation links to your footer or content
164
- // Example: <Link to="/about">About</Link>`,
165
- explanation: 'Add internal links to help search engines discover your content',
166
- skipped: true,
167
- skipReason: 'Requires manual content updates - add links to your navigation and content',
168
- };
169
-
170
- // Preconnect issues
171
- case 'GOOGLE_FONTS_NO_PRECONNECT':
172
- case 'MISSING_PRECONNECT':
173
- return generatePreconnectFix(context);
174
-
175
- // Favicon/icons
176
- case 'HTML_NO_FAVICON':
177
- case 'HTML_NO_APPLE_TOUCH_ICON':
178
- case 'FAVICON_MISSING': // Full audit code
179
- return generateFaviconFix(context);
180
-
181
- // Charset/lang
182
- case 'HTML_NO_CHARSET':
183
- case 'HTML_NOT_UTF8':
184
- return generateCharsetFix(context);
185
-
186
- case 'HTML_NO_LANG':
187
- case 'LANG_ATTR_MISSING': // Full audit code
188
- return generateLangFix(context);
189
-
190
- // AI/LLMs.txt
191
- case 'AI_NO_LLMS_TXT':
192
- return generateLlmsTxtFix(context, siteName, fullUrl);
193
-
194
- default:
195
- return null;
196
- }
197
- }
198
-
199
- function generateTitleFix(context: FixContext, siteName: string): GeneratedFix {
200
- const { htmlPath, htmlContent, framework } = context;
201
-
202
- if (framework.metaPattern === 'html-head') {
203
- // Vite/React - modify index.html
204
- const titleTag = `<title>${siteName} - Your Product Tagline</title>`;
205
-
206
- if (htmlContent.includes('<title>')) {
207
- // Replace existing title
208
- const before = htmlContent.match(/<title>.*?<\/title>/)?.[0] || '';
209
- return {
210
- issue: { code: 'MISSING_TITLE', message: 'Missing or empty title tag', severity: 'critical' },
211
- file: htmlPath,
212
- before,
213
- after: titleTag,
214
- explanation: 'Updated the title tag with a descriptive title',
215
- };
216
- } else {
217
- // Add title after <head>
218
- return {
219
- issue: { code: 'MISSING_TITLE', message: 'Missing title tag', severity: 'critical' },
220
- file: htmlPath,
221
- before: '<head>',
222
- after: `<head>\n ${titleTag}`,
223
- explanation: 'Added a title tag to the document head',
224
- };
225
- }
226
- }
227
-
228
- // For other frameworks, provide guidance
229
- return {
230
- issue: { code: 'MISSING_TITLE', message: 'Missing title tag', severity: 'critical' },
231
- file: htmlPath,
232
- before: null,
233
- after: `<title>${siteName} - Your Product Tagline</title>`,
234
- explanation: `Add title using ${framework.name} patterns`,
235
- };
236
- }
237
-
238
- function generateMetaDescFix(context: FixContext, siteName: string): GeneratedFix {
239
- const { htmlPath, htmlContent, framework } = context;
240
- const description = `${siteName} - A brief, compelling description of your product or service. Include key features and benefits.`;
241
-
242
- if (framework.metaPattern === 'html-head') {
243
- const metaTag = `<meta name="description" content="${description}" />`;
244
-
245
- if (htmlContent.includes('<title>')) {
246
- return {
247
- issue: { code: 'MISSING_META_DESC', message: 'Missing meta description', severity: 'critical' },
248
- file: htmlPath,
249
- before: '</title>',
250
- after: `</title>\n ${metaTag}`,
251
- explanation: 'Added meta description after the title tag',
252
- };
253
- } else {
254
- return {
255
- issue: { code: 'MISSING_META_DESC', message: 'Missing meta description', severity: 'critical' },
256
- file: htmlPath,
257
- before: '<head>',
258
- after: `<head>\n ${metaTag}`,
259
- explanation: 'Added meta description to the document head',
260
- };
261
- }
262
- }
263
-
264
- return {
265
- issue: { code: 'MISSING_META_DESC', message: 'Missing meta description', severity: 'critical' },
266
- file: htmlPath,
267
- before: null,
268
- after: `<meta name="description" content="${description}" />`,
269
- explanation: `Add meta description using ${framework.name} patterns`,
270
- };
271
- }
272
-
273
- function generateCanonicalFix(context: FixContext, url: string): GeneratedFix {
274
- const { htmlPath, htmlContent, framework } = context;
275
- const canonicalTag = `<link rel="canonical" href="${url}" />`;
276
-
277
- // Check if canonical already exists
278
- if (htmlContent.includes('rel="canonical"') || htmlContent.includes("rel='canonical'")) {
279
- return {
280
- issue: { code: 'MISSING_CANONICAL', message: 'No canonical URL specified', severity: 'warning' },
281
- file: htmlPath,
282
- before: null,
283
- after: canonicalTag,
284
- explanation: 'Canonical URL already exists',
285
- skipped: true,
286
- skipReason: 'Canonical tag already present',
287
- };
288
- }
289
-
290
- if (framework.metaPattern === 'html-head') {
291
- return {
292
- issue: { code: 'MISSING_CANONICAL', message: 'No canonical URL specified', severity: 'warning' },
293
- file: htmlPath,
294
- before: '</head>',
295
- after: ` ${canonicalTag}\n </head>`,
296
- explanation: 'Added canonical URL to prevent duplicate content issues',
297
- };
298
- }
299
-
300
- return {
301
- issue: { code: 'MISSING_CANONICAL', message: 'No canonical URL specified', severity: 'warning' },
302
- file: htmlPath,
303
- before: null,
304
- after: canonicalTag,
305
- explanation: `Add canonical URL using ${framework.name} patterns`,
306
- };
307
- }
308
-
309
- function generateViewportFix(context: FixContext): GeneratedFix {
310
- const { htmlPath, htmlContent, framework } = context;
311
- const viewportTag = '<meta name="viewport" content="width=device-width, initial-scale=1.0" />';
312
-
313
- if (framework.metaPattern === 'html-head' && !htmlContent.includes('viewport')) {
314
- return {
315
- issue: { code: 'MISSING_VIEWPORT', message: 'Missing viewport meta tag', severity: 'critical' },
316
- file: htmlPath,
317
- before: '<head>',
318
- after: `<head>\n ${viewportTag}`,
319
- explanation: 'Added viewport meta tag for mobile responsiveness',
320
- };
321
- }
322
-
323
- return {
324
- issue: { code: 'MISSING_VIEWPORT', message: 'Missing viewport meta tag', severity: 'critical' },
325
- file: htmlPath,
326
- before: null,
327
- after: viewportTag,
328
- explanation: 'Add viewport meta tag for mobile-first indexing',
329
- };
330
- }
331
-
332
- function generateOGFix(context: FixContext, siteName: string, url: string): GeneratedFix {
333
- const { htmlPath, htmlContent } = context;
334
-
335
- // Check which OG tags are missing
336
- const missingTags: string[] = [];
337
- if (!htmlContent.includes('og:image')) {
338
- missingTags.push(`<meta property="og:image" content="${url}/og-image.png" />`);
339
- }
340
- if (!htmlContent.includes('og:url')) {
341
- missingTags.push(`<meta property="og:url" content="${url}" />`);
342
- }
343
-
344
- if (missingTags.length === 0) {
345
- return {
346
- issue: { code: 'MISSING_OG_TAGS', message: 'Missing Open Graph tags', severity: 'warning' },
347
- file: htmlPath,
348
- before: null,
349
- after: '',
350
- explanation: 'All essential OG tags are present',
351
- skipped: true,
352
- skipReason: 'OG tags already exist',
353
- };
354
- }
355
-
356
- const ogTags = `<!-- SEO Autopilot: Missing OG tags -->\n ${missingTags.join('\n ')}`;
357
-
358
- return {
359
- issue: { code: 'MISSING_OG_TAGS', message: 'Missing Open Graph tags', severity: 'warning' },
360
- file: htmlPath,
361
- before: '</head>',
362
- after: ` ${ogTags}\n </head>`,
363
- explanation: `Added missing Open Graph meta tags: ${missingTags.length} tag(s)`,
364
- };
365
- }
366
-
367
- function generateTwitterFix(context: FixContext, siteName: string): GeneratedFix {
368
- const { htmlPath } = context;
369
-
370
- const twitterTags = `<!-- Twitter -->
371
- <meta name="twitter:card" content="summary_large_image" />
372
- <meta name="twitter:title" content="${siteName} - Your Product Tagline" />
373
- <meta name="twitter:description" content="A compelling description for Twitter sharing." />
374
- <meta name="twitter:image" content="/og-image.png" />`;
375
-
376
- return {
377
- issue: { code: 'MISSING_TWITTER_CARD', message: 'Missing Twitter Card meta tags', severity: 'info' },
378
- file: htmlPath,
379
- before: '</head>',
380
- after: ` ${twitterTags}\n </head>`,
381
- explanation: 'Added Twitter Card meta tags for better X/Twitter sharing',
382
- };
383
- }
384
-
385
- function generateSchemaFix(context: FixContext, siteName: string, url: string): GeneratedFix {
386
- const { htmlPath, framework } = context;
387
-
388
- const schema = {
389
- '@context': 'https://schema.org',
390
- '@type': 'SoftwareApplication',
391
- 'name': siteName,
392
- 'url': url,
393
- 'applicationCategory': 'WebApplication',
394
- 'operatingSystem': 'Web Browser',
395
- 'offers': {
396
- '@type': 'Offer',
397
- 'price': '0',
398
- 'priceCurrency': 'USD',
399
- },
400
- };
401
-
402
- const schemaScript = `<script type="application/ld+json">
403
- ${JSON.stringify(schema, null, 2)}
404
- </script>`;
405
-
406
- return {
407
- issue: { code: 'MISSING_SCHEMA', message: 'No JSON-LD structured data found', severity: 'warning' },
408
- file: htmlPath,
409
- before: '</head>',
410
- after: ` ${schemaScript}\n </head>`,
411
- explanation: 'Added JSON-LD structured data for rich search results',
412
- };
413
- }
414
-
415
- function generateRobotsFix(context: FixContext, url: string): GeneratedFix {
416
- const robotsTxt = `# robots.txt for ${new URL(url).hostname}
417
- User-agent: *
418
- Allow: /
419
-
420
- # Sitemap
421
- Sitemap: ${url}/sitemap.xml`;
422
-
423
- return {
424
- issue: { code: 'MISSING_ROBOTS', message: 'No robots.txt file found', severity: 'warning' },
425
- file: 'public/robots.txt',
426
- before: null,
427
- after: robotsTxt,
428
- explanation: 'Created robots.txt to provide crawling instructions to search engines',
429
- };
430
- }
431
-
432
- function generateSitemapFix(context: FixContext, url: string): GeneratedFix {
433
- const sitemap = `<?xml version="1.0" encoding="UTF-8"?>
434
- <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
435
- <url>
436
- <loc>${url}</loc>
437
- <lastmod>${new Date().toISOString().split('T')[0]}</lastmod>
438
- <priority>1.0</priority>
439
- </url>
440
- </urlset>`;
441
-
442
- return {
443
- issue: { code: 'MISSING_SITEMAP', message: 'No sitemap.xml found', severity: 'warning' },
444
- file: 'public/sitemap.xml',
445
- before: null,
446
- after: sitemap,
447
- explanation: 'Created sitemap.xml to help search engines discover all pages',
448
- };
449
- }
450
-
451
- function generateSPAMetaFix(context: FixContext, framework: FrameworkInfo): GeneratedFix {
452
- const { url } = context;
453
- const fullUrl = url || 'https://example.com';
454
- const siteName = new URL(fullUrl).hostname.replace('www.', '').split('.')[0];
455
- const capitalizedName = siteName.charAt(0).toUpperCase() + siteName.slice(1);
456
-
457
- const generatedCode = getFrameworkSpecificFix(framework, {
458
- siteName: capitalizedName,
459
- siteUrl: fullUrl,
460
- title: `${capitalizedName} - Your tagline here`,
461
- description: `${capitalizedName} - A compelling description of your product or service.`,
462
- image: `${fullUrl}/og-image.png`,
463
- });
464
-
465
- const installInstructions = generatedCode.installCommands
466
- ? `\n\nInstall: ${generatedCode.installCommands.join(' && ')}`
467
- : '';
468
-
469
- return {
470
- issue: { code: 'SPA_NO_META_MANAGEMENT', message: 'SPA without dynamic meta tag management', severity: 'warning' },
471
- file: generatedCode.file,
472
- before: null,
473
- after: generatedCode.code,
474
- explanation: generatedCode.explanation + installInstructions,
475
- };
476
- }
477
-
478
- function generatePreconnectFix(context: FixContext): GeneratedFix {
479
- const { htmlPath, htmlContent } = context;
480
-
481
- const preconnects = `<!-- Preconnect to external origins -->
482
- <link rel="preconnect" href="https://fonts.googleapis.com" />
483
- <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />`;
484
-
485
- return {
486
- issue: { code: 'MISSING_PRECONNECT', message: 'Missing preconnect hints', severity: 'info' },
487
- file: htmlPath,
488
- before: '<head>',
489
- after: `<head>\n ${preconnects}`,
490
- explanation: 'Added preconnect hints to speed up loading of external resources',
491
- };
492
- }
493
-
494
- function generateFaviconFix(context: FixContext): GeneratedFix {
495
- const { htmlPath } = context;
496
-
497
- const faviconTags = `<!-- Favicons -->
498
- <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
499
- <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
500
- <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />`;
501
-
502
- return {
503
- issue: { code: 'HTML_NO_FAVICON', message: 'Missing favicon', severity: 'info' },
504
- file: htmlPath,
505
- before: '<head>',
506
- after: `<head>\n ${faviconTags}`,
507
- explanation: 'Added favicon links. Create favicon files in public/ directory.',
508
- };
509
- }
510
-
511
- function generateCharsetFix(context: FixContext): GeneratedFix {
512
- const { htmlPath, htmlContent } = context;
513
-
514
- if (htmlContent.includes('charset')) {
515
- return {
516
- issue: { code: 'HTML_NO_CHARSET', message: 'Missing charset', severity: 'warning' },
517
- file: htmlPath,
518
- before: null,
519
- after: '<meta charset="UTF-8" />',
520
- skipped: true,
521
- skipReason: 'Charset already defined',
522
- explanation: 'Charset is already present',
523
- };
524
- }
525
-
526
- return {
527
- issue: { code: 'HTML_NO_CHARSET', message: 'Missing charset declaration', severity: 'warning' },
528
- file: htmlPath,
529
- before: '<head>',
530
- after: '<head>\n <meta charset="UTF-8" />',
531
- explanation: 'Added UTF-8 charset declaration as first element in head',
532
- };
533
- }
534
-
535
- function generateLangFix(context: FixContext): GeneratedFix {
536
- const { htmlPath, htmlContent } = context;
537
-
538
- if (htmlContent.includes('<html') && !htmlContent.includes('lang=')) {
539
- return {
540
- issue: { code: 'HTML_NO_LANG', message: 'Missing lang attribute', severity: 'warning' },
541
- file: htmlPath,
542
- before: '<html>',
543
- after: '<html lang="en">',
544
- explanation: 'Added lang attribute for accessibility and SEO',
545
- };
546
- }
547
-
548
- return {
549
- issue: { code: 'HTML_NO_LANG', message: 'Missing lang attribute', severity: 'warning' },
550
- file: htmlPath,
551
- before: '<html',
552
- after: '<html lang="en"',
553
- explanation: 'Added lang attribute for accessibility and SEO',
554
- };
555
- }
556
-
557
- function generateLlmsTxtFix(context: FixContext, siteName: string, url: string): GeneratedFix {
558
- const llmsTxt = `# ${siteName}
559
- > ${siteName} - A brief description of your product/service
560
-
561
- ## About
562
- ${siteName} is... [Add your description here]
563
-
564
- ## Features
565
- - Feature 1
566
- - Feature 2
567
- - Feature 3
568
-
569
- ## Links
570
- - Homepage: ${url}
571
- - Documentation: ${url}/docs
572
- - API: ${url}/api
573
-
574
- ## Contact
575
- - Email: hello@${new URL(url).hostname}
576
- `;
577
-
578
- return {
579
- issue: { code: 'AI_NO_LLMS_TXT', message: 'No llms.txt file for AI crawlers', severity: 'info' },
580
- file: 'public/llms.txt',
581
- before: null,
582
- after: llmsTxt,
583
- explanation: 'Created llms.txt to help AI systems understand your site. Customize the content.',
584
- };
585
- }
586
-
587
- // Apply fixes to the codebase
588
- export async function applyFixes(
589
- fixes: GeneratedFix[],
590
- options: { cwd: string; dryRun?: boolean }
591
- ): Promise<{ applied: GeneratedFix[]; skipped: GeneratedFix[] }> {
592
- const { cwd, dryRun = false } = options;
593
- const applied: GeneratedFix[] = [];
594
- const skipped: GeneratedFix[] = [];
595
-
596
- for (const fix of fixes) {
597
- if (fix.skipped) {
598
- skipped.push(fix);
599
- continue;
600
- }
601
-
602
- try {
603
- const filePath = join(cwd, fix.file);
604
-
605
- if (dryRun) {
606
- applied.push({ ...fix, applied: false });
607
- continue;
608
- }
609
-
610
- if (fix.before === null) {
611
- // Create new file
612
- const dir = join(cwd, fix.file.split('/').slice(0, -1).join('/'));
613
- if (dir !== cwd && !existsSync(dir)) {
614
- const { mkdirSync } = await import('fs');
615
- mkdirSync(dir, { recursive: true });
616
- }
617
- writeFileSync(filePath, fix.after, 'utf-8');
618
- applied.push({ ...fix, applied: true });
619
- } else if (existsSync(filePath)) {
620
- // Modify existing file
621
- let content = readFileSync(filePath, 'utf-8');
622
- if (content.includes(fix.before)) {
623
- content = content.replace(fix.before, fix.after);
624
- writeFileSync(filePath, content, 'utf-8');
625
- applied.push({ ...fix, applied: true });
626
- } else {
627
- skipped.push({ ...fix, skipped: true, skipReason: 'Pattern not found in file' });
628
- }
629
- } else {
630
- skipped.push({ ...fix, skipped: true, skipReason: 'File not found' });
631
- }
632
- } catch (error) {
633
- skipped.push({
634
- ...fix,
635
- skipped: true,
636
- skipReason: error instanceof Error ? error.message : 'Unknown error',
637
- });
638
- }
639
- }
640
-
641
- return { applied, skipped };
642
- }