@rankcli/agent-runtime 0.0.8 → 0.0.11

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 (49) hide show
  1. package/README.md +90 -196
  2. package/dist/analyzer-GMURJADU.mjs +7 -0
  3. package/dist/chunk-2JADKV3Z.mjs +244 -0
  4. package/dist/chunk-3ZSCLNTW.mjs +557 -0
  5. package/dist/chunk-4E4MQOSP.mjs +374 -0
  6. package/dist/chunk-6BWS3CLP.mjs +16 -0
  7. package/dist/chunk-AK2IC22C.mjs +206 -0
  8. package/dist/chunk-K6VSXDD6.mjs +293 -0
  9. package/dist/chunk-M27NQCWW.mjs +303 -0
  10. package/dist/{chunk-YNZYHEYM.mjs → chunk-PJLNXOLN.mjs} +0 -14
  11. package/dist/chunk-VSQD74I7.mjs +474 -0
  12. package/dist/core-web-vitals-analyzer-TE6LQJMS.mjs +7 -0
  13. package/dist/geo-analyzer-D47LTMMA.mjs +25 -0
  14. package/dist/image-optimization-analyzer-XP4OQGRP.mjs +9 -0
  15. package/dist/index.d.mts +1523 -17
  16. package/dist/index.d.ts +1523 -17
  17. package/dist/index.js +9582 -2664
  18. package/dist/index.mjs +4812 -380
  19. package/dist/internal-linking-analyzer-MRMBV7NM.mjs +9 -0
  20. package/dist/mobile-seo-analyzer-67HNQ7IO.mjs +7 -0
  21. package/dist/security-headers-analyzer-3ZUQARS5.mjs +9 -0
  22. package/dist/structured-data-analyzer-2I4NQAUP.mjs +9 -0
  23. package/package.json +2 -2
  24. package/src/analyzers/core-web-vitals-analyzer.test.ts +236 -0
  25. package/src/analyzers/core-web-vitals-analyzer.ts +557 -0
  26. package/src/analyzers/geo-analyzer.test.ts +310 -0
  27. package/src/analyzers/geo-analyzer.ts +814 -0
  28. package/src/analyzers/image-optimization-analyzer.test.ts +145 -0
  29. package/src/analyzers/image-optimization-analyzer.ts +348 -0
  30. package/src/analyzers/index.ts +233 -0
  31. package/src/analyzers/internal-linking-analyzer.test.ts +141 -0
  32. package/src/analyzers/internal-linking-analyzer.ts +419 -0
  33. package/src/analyzers/mobile-seo-analyzer.test.ts +140 -0
  34. package/src/analyzers/mobile-seo-analyzer.ts +455 -0
  35. package/src/analyzers/security-headers-analyzer.test.ts +115 -0
  36. package/src/analyzers/security-headers-analyzer.ts +318 -0
  37. package/src/analyzers/structured-data-analyzer.test.ts +210 -0
  38. package/src/analyzers/structured-data-analyzer.ts +590 -0
  39. package/src/audit/engine.ts +3 -3
  40. package/src/audit/types.ts +3 -2
  41. package/src/fixer/framework-fixes.test.ts +489 -0
  42. package/src/fixer/framework-fixes.ts +3418 -0
  43. package/src/fixer/index.ts +1 -0
  44. package/src/fixer/schemas.ts +971 -0
  45. package/src/frameworks/detector.ts +642 -114
  46. package/src/frameworks/suggestion-engine.ts +38 -1
  47. package/src/index.ts +6 -0
  48. package/src/types.ts +15 -1
  49. package/dist/analyzer-2CSWIQGD.mjs +0 -6
@@ -0,0 +1,419 @@
1
+ /**
2
+ * Internal Linking Analyzer
3
+ *
4
+ * Analyzes internal link structure for SEO optimization.
5
+ * Checks link distribution, anchor text, orphan pages, and link depth.
6
+ */
7
+
8
+ import * as cheerio from 'cheerio';
9
+ import type { AuditIssue } from '../audit/types.js';
10
+
11
+ export interface InternalLinkingResult {
12
+ score: number;
13
+ totalLinks: number;
14
+ internalLinks: number;
15
+ externalLinks: number;
16
+ navigationLinks: number;
17
+ contentLinks: number;
18
+ uniqueInternalTargets: number;
19
+ linksWithKeywords: number;
20
+ linksWithGenericText: number;
21
+ orphanRisk: boolean;
22
+ linkDetails: LinkInfo[];
23
+ anchorTextAnalysis: AnchorTextStats;
24
+ issues: AuditIssue[];
25
+ recommendations: string[];
26
+ }
27
+
28
+ export interface LinkInfo {
29
+ href: string;
30
+ text: string;
31
+ isInternal: boolean;
32
+ isNavigation: boolean;
33
+ rel?: string;
34
+ title?: string;
35
+ issues: string[];
36
+ }
37
+
38
+ export interface AnchorTextStats {
39
+ total: number;
40
+ descriptive: number;
41
+ generic: number;
42
+ empty: number;
43
+ tooLong: number;
44
+ imageLinks: number;
45
+ patterns: { text: string; count: number }[];
46
+ }
47
+
48
+ const GENERIC_ANCHOR_TEXTS = [
49
+ 'click here',
50
+ 'read more',
51
+ 'learn more',
52
+ 'here',
53
+ 'link',
54
+ 'this',
55
+ 'more',
56
+ 'continue',
57
+ 'see more',
58
+ 'view more',
59
+ 'details',
60
+ 'go',
61
+ 'continue reading',
62
+ '>>',
63
+ '→',
64
+ 'next',
65
+ 'previous',
66
+ ];
67
+
68
+ /**
69
+ * Check if URL is internal
70
+ */
71
+ function isInternalUrl(href: string, baseUrl: string): boolean {
72
+ if (!href || href.startsWith('#') || href.startsWith('javascript:') || href.startsWith('mailto:') || href.startsWith('tel:')) {
73
+ return false;
74
+ }
75
+
76
+ if (href.startsWith('/') && !href.startsWith('//')) {
77
+ return true;
78
+ }
79
+
80
+ try {
81
+ const base = new URL(baseUrl);
82
+ const link = new URL(href, baseUrl);
83
+ return link.hostname === base.hostname;
84
+ } catch {
85
+ return false;
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Check if link is in navigation
91
+ */
92
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
93
+ function isNavigationLink($el: cheerio.Cheerio<any>, $: cheerio.CheerioAPI): boolean {
94
+ const parent = $el.parents('nav, header, footer, [role="navigation"], .nav, .navigation, .menu, .sidebar').first();
95
+ return parent.length > 0;
96
+ }
97
+
98
+ /**
99
+ * Analyze anchor text quality
100
+ */
101
+ function analyzeAnchorText(text: string): { isGeneric: boolean; isTooLong: boolean; isEmpty: boolean } {
102
+ const normalized = text.toLowerCase().trim();
103
+
104
+ return {
105
+ isEmpty: normalized.length === 0,
106
+ isGeneric: GENERIC_ANCHOR_TEXTS.some(g => normalized === g || normalized.includes(g)),
107
+ isTooLong: normalized.length > 100,
108
+ };
109
+ }
110
+
111
+ /**
112
+ * Analyze internal linking structure
113
+ */
114
+ export function analyzeInternalLinking(html: string, url: string): InternalLinkingResult {
115
+ const $ = cheerio.load(html);
116
+ const issues: AuditIssue[] = [];
117
+ const recommendations: string[] = [];
118
+ let score = 100;
119
+
120
+ const linkDetails: LinkInfo[] = [];
121
+ const anchorTextCounts: Record<string, number> = {};
122
+
123
+ let totalLinks = 0;
124
+ let internalLinks = 0;
125
+ let externalLinks = 0;
126
+ let navigationLinks = 0;
127
+ let contentLinks = 0;
128
+ let linksWithGenericText = 0;
129
+ let linksWithKeywords = 0;
130
+ let emptyAnchorLinks = 0;
131
+ let tooLongAnchorLinks = 0;
132
+ let imageLinks = 0;
133
+
134
+ const internalTargets = new Set<string>();
135
+
136
+ $('a[href]').each((_, el) => {
137
+ const $link = $(el);
138
+ const href = $link.attr('href') || '';
139
+ const text = $link.text().trim();
140
+ const rel = $link.attr('rel');
141
+ const title = $link.attr('title');
142
+ const hasImage = $link.find('img').length > 0;
143
+
144
+ // Skip non-HTTP links
145
+ if (href.startsWith('mailto:') || href.startsWith('tel:') || href.startsWith('javascript:')) {
146
+ return;
147
+ }
148
+
149
+ totalLinks++;
150
+ const linkIssues: string[] = [];
151
+ const isInternal = isInternalUrl(href, url);
152
+ const isNav = isNavigationLink($link, $);
153
+
154
+ if (isInternal) {
155
+ internalLinks++;
156
+
157
+ // Track unique targets
158
+ try {
159
+ const targetUrl = new URL(href, url).pathname;
160
+ internalTargets.add(targetUrl);
161
+ } catch {}
162
+ } else if (href.startsWith('http')) {
163
+ externalLinks++;
164
+ }
165
+
166
+ if (isNav) {
167
+ navigationLinks++;
168
+ } else {
169
+ contentLinks++;
170
+ }
171
+
172
+ // Analyze anchor text
173
+ const anchorAnalysis = analyzeAnchorText(text);
174
+
175
+ if (hasImage && !text) {
176
+ imageLinks++;
177
+ const imgAlt = $link.find('img').attr('alt');
178
+ if (!imgAlt) {
179
+ linkIssues.push('Image link without alt text');
180
+ }
181
+ } else if (anchorAnalysis.isEmpty) {
182
+ emptyAnchorLinks++;
183
+ linkIssues.push('Empty anchor text');
184
+ } else if (anchorAnalysis.isGeneric) {
185
+ linksWithGenericText++;
186
+ linkIssues.push('Generic anchor text');
187
+ } else {
188
+ linksWithKeywords++;
189
+ }
190
+
191
+ if (anchorAnalysis.isTooLong) {
192
+ tooLongAnchorLinks++;
193
+ linkIssues.push('Anchor text too long');
194
+ }
195
+
196
+ // Track anchor text patterns
197
+ if (text) {
198
+ const normalizedText = text.toLowerCase().substring(0, 50);
199
+ anchorTextCounts[normalizedText] = (anchorTextCounts[normalizedText] || 0) + 1;
200
+ }
201
+
202
+ // Check for nofollow on internal links
203
+ if (isInternal && rel?.includes('nofollow')) {
204
+ linkIssues.push('nofollow on internal link');
205
+ }
206
+
207
+ // Check for sponsored/ugc on internal links
208
+ if (isInternal && (rel?.includes('sponsored') || rel?.includes('ugc'))) {
209
+ linkIssues.push('sponsored/ugc on internal link');
210
+ }
211
+
212
+ linkDetails.push({
213
+ href: href.substring(0, 200),
214
+ text: text.substring(0, 100),
215
+ isInternal,
216
+ isNavigation: isNav,
217
+ rel,
218
+ title,
219
+ issues: linkIssues,
220
+ });
221
+ });
222
+
223
+ // Generate anchor text patterns
224
+ const anchorPatterns = Object.entries(anchorTextCounts)
225
+ .sort((a, b) => b[1] - a[1])
226
+ .slice(0, 10)
227
+ .map(([text, count]) => ({ text, count }));
228
+
229
+ // Analyze results
230
+ const uniqueInternalTargets = internalTargets.size;
231
+
232
+ // Check for orphan risk (very few internal links)
233
+ const orphanRisk = internalLinks < 3 && contentLinks < 2;
234
+
235
+ // Generate issues
236
+ if (internalLinks === 0) {
237
+ issues.push({
238
+ code: 'LINK_NO_INTERNAL',
239
+ severity: 'critical',
240
+ category: 'content',
241
+ title: 'No internal links found',
242
+ description: 'This page has no internal links to other pages on your site.',
243
+ impact: 'Poor link equity distribution, crawlability issues',
244
+ howToFix: 'Add relevant internal links to other pages on your site.',
245
+ affectedUrls: [url],
246
+ });
247
+ score -= 25;
248
+ } else if (contentLinks === 0 && internalLinks < 5) {
249
+ issues.push({
250
+ code: 'LINK_LOW_INTERNAL',
251
+ severity: 'warning',
252
+ category: 'content',
253
+ title: 'Very few internal links in content',
254
+ description: `Only ${internalLinks} internal links found, all in navigation.`,
255
+ impact: 'Limited topic relevance signals',
256
+ howToFix: 'Add contextual internal links within your content.',
257
+ affectedUrls: [url],
258
+ });
259
+ score -= 15;
260
+ }
261
+
262
+ if (linksWithGenericText > 3) {
263
+ const percentage = Math.round((linksWithGenericText / totalLinks) * 100);
264
+ issues.push({
265
+ code: 'LINK_GENERIC_ANCHOR',
266
+ severity: 'warning',
267
+ category: 'content',
268
+ title: `${linksWithGenericText} links with generic anchor text`,
269
+ description: `${percentage}% of links use non-descriptive text like "click here" or "read more".`,
270
+ impact: 'Missed keyword relevance signals',
271
+ howToFix: 'Replace generic anchors with descriptive, keyword-rich text.',
272
+ affectedUrls: [url],
273
+ });
274
+ score -= Math.min(linksWithGenericText * 2, 15);
275
+ }
276
+
277
+ if (emptyAnchorLinks > 0) {
278
+ issues.push({
279
+ code: 'LINK_EMPTY_ANCHOR',
280
+ severity: 'warning',
281
+ category: 'content',
282
+ title: `${emptyAnchorLinks} links with empty anchor text`,
283
+ description: 'Links without text or alt text are inaccessible and provide no SEO value.',
284
+ impact: 'Accessibility issues, wasted link equity',
285
+ howToFix: 'Add descriptive text or ensure image links have alt text.',
286
+ affectedUrls: [url],
287
+ });
288
+ score -= Math.min(emptyAnchorLinks * 3, 15);
289
+ }
290
+
291
+ if (orphanRisk) {
292
+ issues.push({
293
+ code: 'LINK_ORPHAN_RISK',
294
+ severity: 'info',
295
+ category: 'content',
296
+ title: 'Page may be an orphan',
297
+ description: 'This page has very few internal links, which may indicate it\'s poorly connected in your site structure.',
298
+ impact: 'Difficult for users and crawlers to find',
299
+ howToFix: 'Link to this page from related content and relevant hub pages.',
300
+ affectedUrls: [url],
301
+ });
302
+ score -= 10;
303
+ }
304
+
305
+ // Check internal link nofollow
306
+ const nofollowInternalLinks = linkDetails.filter(l => l.isInternal && l.rel?.includes('nofollow'));
307
+ if (nofollowInternalLinks.length > 0) {
308
+ issues.push({
309
+ code: 'LINK_NOFOLLOW_INTERNAL',
310
+ severity: 'warning',
311
+ category: 'technical',
312
+ title: `${nofollowInternalLinks.length} internal links with nofollow`,
313
+ description: 'Internal links should not have nofollow - it wastes PageRank.',
314
+ impact: 'Reduced internal link equity flow',
315
+ howToFix: 'Remove nofollow from internal links.',
316
+ affectedUrls: [url],
317
+ });
318
+ score -= nofollowInternalLinks.length * 3;
319
+ }
320
+
321
+ // Check for excessive external links
322
+ if (externalLinks > internalLinks && externalLinks > 10) {
323
+ issues.push({
324
+ code: 'LINK_EXTERNAL_HEAVY',
325
+ severity: 'info',
326
+ category: 'content',
327
+ title: 'More external links than internal',
328
+ description: `${externalLinks} external vs ${internalLinks} internal links.`,
329
+ impact: 'May leak PageRank to external sites',
330
+ howToFix: 'Consider adding more internal links or using nofollow/sponsored for some external links.',
331
+ affectedUrls: [url],
332
+ });
333
+ }
334
+
335
+ // Recommendations
336
+ if (contentLinks < 3 && internalLinks > 0) {
337
+ recommendations.push('Add 2-3 contextual internal links within your content');
338
+ }
339
+
340
+ if (linksWithKeywords / Math.max(totalLinks, 1) > 0.7) {
341
+ recommendations.push('✓ Good use of descriptive anchor text');
342
+ }
343
+
344
+ if (uniqueInternalTargets > 5) {
345
+ recommendations.push('✓ Good diversity of internal link targets');
346
+ }
347
+
348
+ // Suggest hub pages
349
+ if (internalLinks > 10) {
350
+ recommendations.push('Consider creating a hub/pillar page to consolidate topic authority');
351
+ }
352
+
353
+ return {
354
+ score: Math.max(0, Math.min(100, score)),
355
+ totalLinks,
356
+ internalLinks,
357
+ externalLinks,
358
+ navigationLinks,
359
+ contentLinks,
360
+ uniqueInternalTargets,
361
+ linksWithKeywords,
362
+ linksWithGenericText,
363
+ orphanRisk,
364
+ linkDetails,
365
+ anchorTextAnalysis: {
366
+ total: totalLinks,
367
+ descriptive: linksWithKeywords,
368
+ generic: linksWithGenericText,
369
+ empty: emptyAnchorLinks,
370
+ tooLong: tooLongAnchorLinks,
371
+ imageLinks,
372
+ patterns: anchorPatterns,
373
+ },
374
+ issues,
375
+ recommendations,
376
+ };
377
+ }
378
+
379
+ /**
380
+ * Suggest internal linking opportunities
381
+ */
382
+ export function suggestInternalLinks(content: string, availablePages: { url: string; title: string; keywords: string[] }[]): {
383
+ keyword: string;
384
+ suggestedUrl: string;
385
+ suggestedTitle: string;
386
+ relevance: number;
387
+ }[] {
388
+ const suggestions: { keyword: string; suggestedUrl: string; suggestedTitle: string; relevance: number }[] = [];
389
+ const contentLower = content.toLowerCase();
390
+
391
+ for (const page of availablePages) {
392
+ for (const keyword of page.keywords) {
393
+ if (contentLower.includes(keyword.toLowerCase())) {
394
+ // Check if not already linked
395
+ const alreadyLinked = content.includes(`href="${page.url}"`) ||
396
+ content.includes(`href='${page.url}'`);
397
+
398
+ if (!alreadyLinked) {
399
+ // Simple relevance: keyword length + position
400
+ const position = contentLower.indexOf(keyword.toLowerCase());
401
+ const relevance = (keyword.length * 2) + (1000 - Math.min(position, 1000)) / 100;
402
+
403
+ suggestions.push({
404
+ keyword,
405
+ suggestedUrl: page.url,
406
+ suggestedTitle: page.title,
407
+ relevance,
408
+ });
409
+ }
410
+ }
411
+ }
412
+ }
413
+
414
+ // Sort by relevance and dedupe
415
+ return suggestions
416
+ .sort((a, b) => b.relevance - a.relevance)
417
+ .filter((s, i, arr) => arr.findIndex(x => x.suggestedUrl === s.suggestedUrl) === i)
418
+ .slice(0, 10);
419
+ }
@@ -0,0 +1,140 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { analyzeMobileSEO } from './mobile-seo-analyzer.js';
3
+
4
+ describe('Mobile SEO Analyzer', () => {
5
+ describe('analyzeMobileSEO', () => {
6
+ it('detects proper viewport', () => {
7
+ const html = `
8
+ <!DOCTYPE html>
9
+ <html>
10
+ <head>
11
+ <meta name="viewport" content="width=device-width, initial-scale=1">
12
+ </head>
13
+ <body><h1>Test</h1></body>
14
+ </html>
15
+ `;
16
+ const result = analyzeMobileSEO(html, 'https://example.com');
17
+ expect(result.viewport.hasViewport).toBe(true);
18
+ expect(result.viewport.isResponsive).toBe(true);
19
+ });
20
+
21
+ it('detects missing viewport', () => {
22
+ const html = `
23
+ <!DOCTYPE html>
24
+ <html>
25
+ <head><title>Test</title></head>
26
+ <body><h1>Test</h1></body>
27
+ </html>
28
+ `;
29
+ const result = analyzeMobileSEO(html, 'https://example.com');
30
+ expect(result.viewport.hasViewport).toBe(false);
31
+ expect(result.issues.some(i => i.code === 'MOBILE_NO_VIEWPORT')).toBe(true);
32
+ });
33
+
34
+ it('detects fixed viewport width', () => {
35
+ const html = `
36
+ <!DOCTYPE html>
37
+ <html>
38
+ <head>
39
+ <meta name="viewport" content="width=1024">
40
+ </head>
41
+ <body><h1>Test</h1></body>
42
+ </html>
43
+ `;
44
+ const result = analyzeMobileSEO(html, 'https://example.com');
45
+ expect(result.viewport.isResponsive).toBe(false);
46
+ });
47
+
48
+ it('warns about disabled zooming', () => {
49
+ const html = `
50
+ <!DOCTYPE html>
51
+ <html>
52
+ <head>
53
+ <meta name="viewport" content="width=device-width, user-scalable=no">
54
+ </head>
55
+ <body><h1>Test</h1></body>
56
+ </html>
57
+ `;
58
+ const result = analyzeMobileSEO(html, 'https://example.com');
59
+ expect(result.issues.some(i => i.code === 'MOBILE_ZOOM_DISABLED')).toBe(true);
60
+ });
61
+
62
+ it('detects apple touch icon', () => {
63
+ const html = `
64
+ <!DOCTYPE html>
65
+ <html>
66
+ <head>
67
+ <meta name="viewport" content="width=device-width, initial-scale=1">
68
+ <link rel="apple-touch-icon" href="/apple-touch-icon.png">
69
+ </head>
70
+ <body><h1>Test</h1></body>
71
+ </html>
72
+ `;
73
+ const result = analyzeMobileSEO(html, 'https://example.com');
74
+ expect(result.mobileSpecific.hasAppleTouchIcon).toBe(true);
75
+ });
76
+
77
+ it('detects theme color', () => {
78
+ const html = `
79
+ <!DOCTYPE html>
80
+ <html>
81
+ <head>
82
+ <meta name="viewport" content="width=device-width, initial-scale=1">
83
+ <meta name="theme-color" content="#ffffff">
84
+ </head>
85
+ <body><h1>Test</h1></body>
86
+ </html>
87
+ `;
88
+ const result = analyzeMobileSEO(html, 'https://example.com');
89
+ expect(result.mobileSpecific.hasThemeColor).toBe(true);
90
+ });
91
+
92
+ it('detects web app manifest', () => {
93
+ const html = `
94
+ <!DOCTYPE html>
95
+ <html>
96
+ <head>
97
+ <meta name="viewport" content="width=device-width, initial-scale=1">
98
+ <link rel="manifest" href="/manifest.json">
99
+ </head>
100
+ <body><h1>Test</h1></body>
101
+ </html>
102
+ `;
103
+ const result = analyzeMobileSEO(html, 'https://example.com');
104
+ expect(result.mobileSpecific.hasManifest).toBe(true);
105
+ });
106
+
107
+ it('detects responsive images', () => {
108
+ const html = `
109
+ <!DOCTYPE html>
110
+ <html>
111
+ <head>
112
+ <meta name="viewport" content="width=device-width, initial-scale=1">
113
+ </head>
114
+ <body>
115
+ <img srcset="/image-400.jpg 400w, /image-800.jpg 800w" src="/image.jpg" alt="Test">
116
+ </body>
117
+ </html>
118
+ `;
119
+ const result = analyzeMobileSEO(html, 'https://example.com');
120
+ expect(result.mobileSpecific.hasMobileOptimizedImages).toBe(true);
121
+ });
122
+
123
+ it('calculates overall score', () => {
124
+ const html = `
125
+ <!DOCTYPE html>
126
+ <html>
127
+ <head>
128
+ <meta name="viewport" content="width=device-width, initial-scale=1">
129
+ <meta name="theme-color" content="#000000">
130
+ <link rel="manifest" href="/manifest.json">
131
+ <link rel="apple-touch-icon" href="/icon.png">
132
+ </head>
133
+ <body><h1>Test</h1></body>
134
+ </html>
135
+ `;
136
+ const result = analyzeMobileSEO(html, 'https://example.com');
137
+ expect(result.score).toBeGreaterThan(80);
138
+ });
139
+ });
140
+ });