@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
@@ -1,66 +0,0 @@
1
- /**
2
- * Deno-compatible entry point for the audit module.
3
- * This excludes Node-specific code and dependencies.
4
- */
5
-
6
- // Types
7
- export type { AuditIssue, AuditReport, HealthScore, PageAudit } from './types.js';
8
- export { ISSUE_DEFINITIONS } from './types.js';
9
-
10
- // Main engine
11
- export { runFullAudit, formatReport } from './engine.js';
12
- export type { AuditOptions } from './engine.js';
13
-
14
- // Individual check modules (all use isomorphic fetch)
15
- export { runCrawlabilityChecks, checkRobotsTxt, checkSitemap, checkRedirects } from './checks/crawlability.js';
16
- export { analyzeOnPage } from './checks/on-page.js';
17
- export { analyzeLinks } from './checks/links.js';
18
- export { analyzeImages } from './checks/images.js';
19
- export { analyzePerformance } from './checks/performance.js';
20
- export { analyzeSecurity, checkCertificate } from './checks/security.js';
21
- export { analyzeStructuredData, suggestSchemaTypes } from './checks/structured-data.js';
22
- export { analyzeMobile, checkMobileResources } from './checks/mobile.js';
23
-
24
- // Advanced checks
25
- export { analyzeHreflang } from './checks/hreflang.js';
26
- export { analyzeSocialMeta } from './checks/social-meta.js';
27
- export { detectSoft404 } from './checks/soft-404.js';
28
- export { analyzeAnchorText } from './checks/anchor-text.js';
29
- export { analyzeCanonicalAdvanced } from './checks/canonical-advanced.js';
30
- export { analyzePagination } from './checks/pagination.js';
31
- export { analyzeRedirects } from './checks/redirect-analysis.js';
32
-
33
- // New competitor-parity checks
34
- export { runAIReadinessChecks, checkLlmsTxt, checkAIBotBlocking } from './checks/ai-readiness.js';
35
- export { analyzeSERPPreview } from './checks/serp-preview.js';
36
- export { analyzeLocalSEO } from './checks/local-seo.js';
37
- export { analyzeSecurityHeaders } from './checks/security-headers.js';
38
- export { analyzeContentFreshness } from './checks/content-freshness.js';
39
- export { analyzeDOMStructure } from './checks/dom-analysis.js';
40
- export { analyzeModernImages } from './checks/modern-images.js';
41
- export { detectTechnologies } from './checks/tech-detection.js';
42
- export { analyzeKeywords } from './checks/keyword-analysis.js';
43
-
44
- // URL Safety (Google Safe Browsing-style local hash database)
45
- export { urlSafetyDatabase, analyzeUrlSafety } from './checks/url-safety.js';
46
-
47
- // Advanced SEO checks
48
- export { analyzeTrackerBloat } from './checks/tracker-bloat.js';
49
- export { analyzeClientRendering } from './checks/client-rendering.js';
50
- export { analyzeRedirectChain } from './checks/redirect-chain.js';
51
- export { analyzeResponsiveImages } from './checks/responsive-images.js';
52
- export { analyzeConversionElements } from './checks/conversion-elements.js';
53
- export { analyzeKeywordPlacement } from './checks/keyword-placement.js';
54
- export { analyzeTopicalClusters } from './checks/topical-clusters.js';
55
- export { analyzePlatformPresence } from './checks/platform-presence.js';
56
- export { analyzeInteractiveTools } from './checks/interactive-tools.js';
57
- export { analyzeFunnelIntent } from './checks/funnel-intent.js';
58
- export { analyzeNavBoostSignals } from './checks/navboost-signals.js';
59
- export { analyzeEntitySEO } from './checks/entity-seo.js';
60
- export { analyzeFreshnessSignals } from './checks/freshness-signals.js';
61
-
62
- // Page discovery (multi-page crawling)
63
- export { discoverPagesFromLinks, parseSitemap, mergePages } from './discovery/link-crawler.js';
64
- export { discoverRoutesFromRepo, detectFramework, routesToUrls } from './discovery/repo-routes.js';
65
- export type { DiscoveredPage } from './discovery/link-crawler.js';
66
- export type { RouteInfo } from './discovery/repo-routes.js';
@@ -1,15 +0,0 @@
1
- /**
2
- * Discovery Module
3
- *
4
- * Discovers pages to audit from various sources:
5
- * - Internal links from homepage
6
- * - Sitemap
7
- * - Route files (with repo access)
8
- */
9
-
10
- export { discoverPagesFromLinks, parseSitemap, mergePages } from './link-crawler.js';
11
- export type { DiscoveredPage } from './link-crawler.js';
12
-
13
- // Route discovery is exported separately
14
- export { discoverRoutesFromRepo } from './repo-routes.js';
15
- export type { RouteInfo } from './repo-routes.js';
@@ -1,233 +0,0 @@
1
- /**
2
- * Link Crawler Module
3
- *
4
- * Discovers pages from a website by following internal links from the homepage.
5
- * Prioritizes important pages like /pricing, /about, /features, etc.
6
- */
7
-
8
- export interface DiscoveredPage {
9
- url: string;
10
- source: 'homepage' | 'sitemap' | 'internal-link';
11
- priority: number; // 1-10, higher = more important
12
- }
13
-
14
- // Priority patterns - pages we want to audit first
15
- const HIGH_PRIORITY_PATTERNS = [
16
- /^\/(pricing|about|features|contact|demo|signup|login|blog)\/?$/i,
17
- /^\/(products?|services?|solutions?|plans?)\/?$/i,
18
- /^\/(docs?|documentation|help|support|faq)\/?$/i,
19
- /^\/(careers?|jobs?|team|company)\/?$/i,
20
- ];
21
-
22
- const MEDIUM_PRIORITY_PATTERNS = [
23
- /^\/(privacy|terms|legal|security)\/?$/i,
24
- /^\/[a-z0-9-]+\/?$/i, // Top-level pages
25
- ];
26
-
27
- // Patterns to exclude
28
- const EXCLUDE_PATTERNS = [
29
- /\.(png|jpg|jpeg|gif|svg|webp|ico|pdf|zip|tar|gz)$/i, // Images & archives
30
- /\.(json|xml|txt|webmanifest|rss|atom)$/i, // Data files (not HTML)
31
- /^(mailto:|tel:|javascript:|#)/i, // Non-HTTP
32
- /\/(api|_next|static|assets|cdn)\//i, // Technical paths
33
- /[?&](utm_|ref=|source=)/i, // Tracking params
34
- ];
35
-
36
- /**
37
- * Extract all internal links from HTML content
38
- */
39
- function extractLinks(html: string, baseUrl: string): string[] {
40
- const base = new URL(baseUrl);
41
- const links: Set<string> = new Set();
42
-
43
- // Match all href attributes
44
- const hrefRegex = /href=["']([^"']+)["']/gi;
45
- let match;
46
-
47
- while ((match = hrefRegex.exec(html)) !== null) {
48
- try {
49
- const href = match[1];
50
-
51
- // Skip excluded patterns
52
- if (EXCLUDE_PATTERNS.some(pattern => pattern.test(href))) {
53
- continue;
54
- }
55
-
56
- // Parse the URL
57
- let url: URL;
58
- if (href.startsWith('http://') || href.startsWith('https://')) {
59
- url = new URL(href);
60
- } else if (href.startsWith('/')) {
61
- url = new URL(href, base);
62
- } else {
63
- continue; // Skip relative paths that don't start with /
64
- }
65
-
66
- // Only include same-domain links
67
- if (url.hostname !== base.hostname) {
68
- continue;
69
- }
70
-
71
- // Normalize the URL
72
- const normalized = normalizeUrl(url);
73
- if (normalized) {
74
- links.add(normalized);
75
- }
76
- } catch {
77
- // Invalid URL, skip
78
- }
79
- }
80
-
81
- return Array.from(links);
82
- }
83
-
84
- /**
85
- * Normalize a URL for deduplication
86
- */
87
- function normalizeUrl(url: URL): string | null {
88
- // Remove hash
89
- url.hash = '';
90
-
91
- // Remove common tracking parameters
92
- const paramsToRemove = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term', 'ref', 'source'];
93
- for (const param of paramsToRemove) {
94
- url.searchParams.delete(param);
95
- }
96
-
97
- // Remove trailing slash for consistency
98
- let pathname = url.pathname;
99
- if (pathname.length > 1 && pathname.endsWith('/')) {
100
- pathname = pathname.slice(0, -1);
101
- }
102
-
103
- // Skip root (we already have it)
104
- if (pathname === '' || pathname === '/') {
105
- return null;
106
- }
107
-
108
- return `${url.protocol}//${url.hostname}${pathname}${url.search}`;
109
- }
110
-
111
- /**
112
- * Calculate priority score for a URL
113
- */
114
- function calculatePriority(url: string): number {
115
- try {
116
- const pathname = new URL(url).pathname;
117
-
118
- // High priority pages (8-10)
119
- for (const pattern of HIGH_PRIORITY_PATTERNS) {
120
- if (pattern.test(pathname)) {
121
- return 9;
122
- }
123
- }
124
-
125
- // Medium priority pages (5-7)
126
- for (const pattern of MEDIUM_PRIORITY_PATTERNS) {
127
- if (pattern.test(pathname)) {
128
- return 6;
129
- }
130
- }
131
-
132
- // Lower priority for deep paths (2-4)
133
- const depth = (pathname.match(/\//g) || []).length;
134
- if (depth >= 3) {
135
- return 2;
136
- }
137
- if (depth === 2) {
138
- return 4;
139
- }
140
-
141
- // Default priority for other pages
142
- return 5;
143
- } catch {
144
- return 1;
145
- }
146
- }
147
-
148
- /**
149
- * Discover pages from HTML content
150
- *
151
- * @param baseUrl - The base URL of the site
152
- * @param html - The HTML content of the homepage
153
- * @param maxPages - Maximum number of pages to return
154
- * @returns Array of discovered pages sorted by priority
155
- */
156
- export function discoverPagesFromLinks(
157
- baseUrl: string,
158
- html: string,
159
- maxPages: number = 5
160
- ): DiscoveredPage[] {
161
- const links = extractLinks(html, baseUrl);
162
-
163
- // Score and sort links
164
- const pages: DiscoveredPage[] = links.map(url => ({
165
- url,
166
- source: 'internal-link' as const,
167
- priority: calculatePriority(url),
168
- }));
169
-
170
- // Sort by priority (descending) and take top N
171
- pages.sort((a, b) => b.priority - a.priority);
172
-
173
- return pages.slice(0, maxPages);
174
- }
175
-
176
- /**
177
- * Parse sitemap XML to extract URLs
178
- */
179
- export function parseSitemap(xml: string, baseUrl: string): DiscoveredPage[] {
180
- const pages: DiscoveredPage[] = [];
181
- const base = new URL(baseUrl);
182
-
183
- // Simple regex-based XML parsing for <loc> tags
184
- const locRegex = /<loc>([^<]+)<\/loc>/gi;
185
- let match;
186
-
187
- while ((match = locRegex.exec(xml)) !== null) {
188
- try {
189
- const url = new URL(match[1]);
190
-
191
- // Only include same-domain URLs
192
- if (url.hostname !== base.hostname) {
193
- continue;
194
- }
195
-
196
- // Skip excluded patterns
197
- if (EXCLUDE_PATTERNS.some(pattern => pattern.test(url.pathname))) {
198
- continue;
199
- }
200
-
201
- pages.push({
202
- url: url.href,
203
- source: 'sitemap',
204
- priority: calculatePriority(url.href),
205
- });
206
- } catch {
207
- // Invalid URL, skip
208
- }
209
- }
210
-
211
- return pages;
212
- }
213
-
214
- /**
215
- * Merge pages from multiple sources, deduplicating by URL
216
- */
217
- export function mergePages(
218
- ...pageSets: DiscoveredPage[][]
219
- ): DiscoveredPage[] {
220
- const seen = new Map<string, DiscoveredPage>();
221
-
222
- for (const pages of pageSets) {
223
- for (const page of pages) {
224
- const existing = seen.get(page.url);
225
- if (!existing || page.priority > existing.priority) {
226
- seen.set(page.url, page);
227
- }
228
- }
229
- }
230
-
231
- return Array.from(seen.values())
232
- .sort((a, b) => b.priority - a.priority);
233
- }
@@ -1,347 +0,0 @@
1
- /**
2
- * Route Discovery Module
3
- *
4
- * Discovers routes from repository files based on framework-specific patterns.
5
- * Supports: Next.js (App/Pages), Astro, React Router, Vue Router, SvelteKit
6
- */
7
-
8
- export interface RouteInfo {
9
- path: string;
10
- type: 'static' | 'dynamic';
11
- sourceFile: string;
12
- }
13
-
14
- type Framework = 'nextjs' | 'astro' | 'react' | 'react-vite' | 'vue' | 'sveltekit' | 'unknown';
15
-
16
- /**
17
- * Detect framework from package.json and file structure
18
- */
19
- export function detectFramework(
20
- packageJson: { dependencies?: Record<string, string>; devDependencies?: Record<string, string> } | null,
21
- files: string[]
22
- ): Framework {
23
- if (!packageJson) return 'unknown';
24
-
25
- const deps = { ...packageJson.dependencies, ...packageJson.devDependencies };
26
-
27
- // Check for Next.js
28
- if (deps['next']) {
29
- return 'nextjs';
30
- }
31
-
32
- // Check for Astro
33
- if (deps['astro']) {
34
- return 'astro';
35
- }
36
-
37
- // Check for SvelteKit
38
- if (deps['@sveltejs/kit']) {
39
- return 'sveltekit';
40
- }
41
-
42
- // Check for Vue with router
43
- if (deps['vue-router'] || deps['@vue/router']) {
44
- return 'vue';
45
- }
46
-
47
- // Check for React with Vite (our pattern)
48
- if (deps['react'] && deps['vite']) {
49
- return 'react-vite';
50
- }
51
-
52
- // Check for React
53
- if (deps['react'] || deps['react-dom']) {
54
- // Check if it has router files
55
- const hasRouterFile = files.some(f =>
56
- f.match(/routes?\.(tsx?|jsx?)$/) ||
57
- f.includes('router') ||
58
- f.endsWith('App.tsx') ||
59
- f.endsWith('App.jsx')
60
- );
61
- if (hasRouterFile) {
62
- return 'react';
63
- }
64
- }
65
-
66
- return 'unknown';
67
- }
68
-
69
- /**
70
- * Discover routes based on framework
71
- */
72
- export async function discoverRoutesFromRepo(
73
- files: string[],
74
- framework: Framework,
75
- fetchFile: (path: string) => Promise<string | null>
76
- ): Promise<RouteInfo[]> {
77
- switch (framework) {
78
- case 'nextjs':
79
- return discoverNextRoutes(files);
80
- case 'astro':
81
- return discoverAstroRoutes(files);
82
- case 'react':
83
- case 'react-vite':
84
- return discoverReactRouterRoutes(files, fetchFile);
85
- case 'vue':
86
- return discoverVueRouterRoutes(files, fetchFile);
87
- case 'sveltekit':
88
- return discoverSvelteRoutes(files);
89
- default:
90
- return []; // Fall back to link crawling
91
- }
92
- }
93
-
94
- /**
95
- * Next.js: file-based routing (App Router and Pages Router)
96
- */
97
- function discoverNextRoutes(files: string[]): RouteInfo[] {
98
- const routes: RouteInfo[] = [];
99
-
100
- for (const file of files) {
101
- // App Router: app/**/page.tsx
102
- const appMatch = file.match(/^app\/(.*)\/page\.(tsx?|jsx?)$/);
103
- if (appMatch) {
104
- let path = '/' + appMatch[1];
105
- // Handle route groups (parentheses)
106
- path = path.replace(/\/\([^)]+\)/g, '');
107
- // Handle root page
108
- if (path === '/') path = '/';
109
-
110
- const isDynamic = path.includes('[');
111
- routes.push({
112
- path,
113
- type: isDynamic ? 'dynamic' : 'static',
114
- sourceFile: file
115
- });
116
- continue;
117
- }
118
-
119
- // App Router: app/page.tsx (root)
120
- if (file.match(/^app\/page\.(tsx?|jsx?)$/)) {
121
- routes.push({
122
- path: '/',
123
- type: 'static',
124
- sourceFile: file
125
- });
126
- continue;
127
- }
128
-
129
- // Pages Router: pages/**/*.tsx
130
- const pagesMatch = file.match(/^pages\/(.+)\.(tsx?|jsx?)$/);
131
- if (pagesMatch) {
132
- const pagePath = pagesMatch[1];
133
-
134
- // Skip special files
135
- if (pagePath.startsWith('_') || pagePath.startsWith('api/')) {
136
- continue;
137
- }
138
-
139
- let path = '/' + pagePath;
140
- // Handle index files
141
- path = path.replace(/\/index$/, '');
142
- if (path === '') path = '/';
143
-
144
- const isDynamic = path.includes('[');
145
- routes.push({
146
- path,
147
- type: isDynamic ? 'dynamic' : 'static',
148
- sourceFile: file
149
- });
150
- }
151
- }
152
-
153
- // Deduplicate by path (prefer App Router)
154
- const seen = new Map<string, RouteInfo>();
155
- for (const route of routes) {
156
- if (!seen.has(route.path)) {
157
- seen.set(route.path, route);
158
- }
159
- }
160
-
161
- return Array.from(seen.values());
162
- }
163
-
164
- /**
165
- * Astro: file-based routing
166
- */
167
- function discoverAstroRoutes(files: string[]): RouteInfo[] {
168
- const routes: RouteInfo[] = [];
169
-
170
- for (const file of files) {
171
- // Match src/pages/**/*.astro or src/pages/**/*.md(x)
172
- const match = file.match(/^src\/pages\/(.+)\.(astro|md|mdx)$/);
173
- if (match) {
174
- let path = '/' + match[1];
175
-
176
- // Handle index files
177
- path = path.replace(/\/index$/, '');
178
- if (path === '') path = '/';
179
-
180
- const isDynamic = path.includes('[');
181
- routes.push({
182
- path,
183
- type: isDynamic ? 'dynamic' : 'static',
184
- sourceFile: file
185
- });
186
- }
187
- }
188
-
189
- return routes;
190
- }
191
-
192
- /**
193
- * SvelteKit: file-based routing
194
- */
195
- function discoverSvelteRoutes(files: string[]): RouteInfo[] {
196
- const routes: RouteInfo[] = [];
197
-
198
- for (const file of files) {
199
- // Match src/routes/**/+page.svelte
200
- const match = file.match(/^src\/routes\/(.*)\/?\+page\.svelte$/);
201
- if (match) {
202
- let path = '/' + (match[1] || '');
203
-
204
- // Handle route groups (parentheses)
205
- path = path.replace(/\/\([^)]+\)/g, '');
206
-
207
- // Clean up double slashes
208
- path = path.replace(/\/+/g, '/');
209
- if (path === '') path = '/';
210
-
211
- const isDynamic = path.includes('[');
212
- routes.push({
213
- path,
214
- type: isDynamic ? 'dynamic' : 'static',
215
- sourceFile: file
216
- });
217
- }
218
- }
219
-
220
- return routes;
221
- }
222
-
223
- /**
224
- * React Router: parse JSX/TSX for Route definitions
225
- */
226
- async function discoverReactRouterRoutes(
227
- files: string[],
228
- fetchFile: (path: string) => Promise<string | null>
229
- ): Promise<RouteInfo[]> {
230
- // Find likely router files
231
- const routerFiles = files.filter(f =>
232
- f.match(/routes?\.(tsx?|jsx?)$/) ||
233
- f.includes('router') ||
234
- f.endsWith('App.tsx') ||
235
- f.endsWith('App.jsx') ||
236
- f.includes('Router')
237
- );
238
-
239
- const routes: RouteInfo[] = [];
240
-
241
- for (const file of routerFiles) {
242
- const content = await fetchFile(file);
243
- if (!content) continue;
244
-
245
- // Match various route definition patterns:
246
- // <Route path="/about" ...
247
- // <Route path='/about' ...
248
- // { path: "/about" ...
249
- // { path: '/about' ...
250
- // path="/about"
251
- const patterns = [
252
- /<Route[^>]*\spath=["']([^"']+)["']/g,
253
- /{\s*path:\s*["']([^"']+)["']/g,
254
- /createBrowserRouter\([^)]*path:\s*["']([^"']+)["']/g,
255
- ];
256
-
257
- for (const pattern of patterns) {
258
- let match;
259
- while ((match = pattern.exec(content)) !== null) {
260
- const path = match[1];
261
-
262
- // Skip catch-all and layout routes
263
- if (path === '*' || path.includes('*')) continue;
264
-
265
- routes.push({
266
- path,
267
- type: path.includes(':') ? 'dynamic' : 'static',
268
- sourceFile: file
269
- });
270
- }
271
- }
272
- }
273
-
274
- // Deduplicate
275
- const seen = new Set<string>();
276
- return routes.filter(r => {
277
- if (seen.has(r.path)) return false;
278
- seen.add(r.path);
279
- return true;
280
- });
281
- }
282
-
283
- /**
284
- * Vue Router: parse router configuration
285
- */
286
- async function discoverVueRouterRoutes(
287
- files: string[],
288
- fetchFile: (path: string) => Promise<string | null>
289
- ): Promise<RouteInfo[]> {
290
- // Find router configuration files
291
- const routerFiles = files.filter(f =>
292
- f.match(/router\/index\.(ts|js)$/) ||
293
- f.match(/router\.(ts|js)$/) ||
294
- f.includes('routes')
295
- );
296
-
297
- const routes: RouteInfo[] = [];
298
-
299
- for (const file of routerFiles) {
300
- const content = await fetchFile(file);
301
- if (!content) continue;
302
-
303
- // Match route definitions: { path: '/about' ...
304
- const pathRegex = /path:\s*["']([^"']+)["']/g;
305
- let match;
306
-
307
- while ((match = pathRegex.exec(content)) !== null) {
308
- const path = match[1];
309
-
310
- // Skip catch-all routes
311
- if (path.includes('*') || path === '/:pathMatch(.*)') continue;
312
-
313
- routes.push({
314
- path,
315
- type: path.includes(':') ? 'dynamic' : 'static',
316
- sourceFile: file
317
- });
318
- }
319
- }
320
-
321
- // Deduplicate
322
- const seen = new Set<string>();
323
- return routes.filter(r => {
324
- if (seen.has(r.path)) return false;
325
- seen.add(r.path);
326
- return true;
327
- });
328
- }
329
-
330
- /**
331
- * Convert static routes to full URLs
332
- */
333
- export function routesToUrls(
334
- routes: RouteInfo[],
335
- baseUrl: string,
336
- maxUrls: number = 5
337
- ): string[] {
338
- const base = new URL(baseUrl);
339
-
340
- return routes
341
- .filter(r => r.type === 'static')
342
- .slice(0, maxUrls)
343
- .map(r => {
344
- const url = new URL(r.path, base);
345
- return url.href;
346
- });
347
- }