@rankcli/agent-runtime 0.0.1

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 (178) hide show
  1. package/README.md +242 -0
  2. package/dist/analyzer-2CSWIQGD.mjs +6 -0
  3. package/dist/chunk-YNZYHEYM.mjs +774 -0
  4. package/dist/index.d.mts +4012 -0
  5. package/dist/index.d.ts +4012 -0
  6. package/dist/index.js +29672 -0
  7. package/dist/index.mjs +28602 -0
  8. package/package.json +53 -0
  9. package/scripts/build-deno.ts +134 -0
  10. package/src/audit/ai/analyzer.ts +347 -0
  11. package/src/audit/ai/index.ts +29 -0
  12. package/src/audit/ai/prompts/content-analysis.ts +271 -0
  13. package/src/audit/ai/types.ts +179 -0
  14. package/src/audit/checks/additional-checks.ts +439 -0
  15. package/src/audit/checks/ai-citation-worthiness.ts +399 -0
  16. package/src/audit/checks/ai-content-structure.ts +325 -0
  17. package/src/audit/checks/ai-readiness.ts +339 -0
  18. package/src/audit/checks/anchor-text.ts +179 -0
  19. package/src/audit/checks/answer-conciseness.ts +322 -0
  20. package/src/audit/checks/asset-minification.ts +270 -0
  21. package/src/audit/checks/bing-optimization.ts +206 -0
  22. package/src/audit/checks/brand-mention-optimization.ts +349 -0
  23. package/src/audit/checks/caching-headers.ts +305 -0
  24. package/src/audit/checks/canonical-advanced.ts +150 -0
  25. package/src/audit/checks/canonical-domain.ts +196 -0
  26. package/src/audit/checks/citation-quality.ts +358 -0
  27. package/src/audit/checks/client-rendering.ts +542 -0
  28. package/src/audit/checks/color-contrast.ts +342 -0
  29. package/src/audit/checks/content-freshness.ts +170 -0
  30. package/src/audit/checks/content-science.ts +589 -0
  31. package/src/audit/checks/conversion-elements.ts +526 -0
  32. package/src/audit/checks/crawlability.ts +220 -0
  33. package/src/audit/checks/directory-listing.ts +172 -0
  34. package/src/audit/checks/dom-analysis.ts +191 -0
  35. package/src/audit/checks/dom-size.ts +246 -0
  36. package/src/audit/checks/duplicate-content.ts +194 -0
  37. package/src/audit/checks/eeat-signals.ts +990 -0
  38. package/src/audit/checks/entity-seo.ts +396 -0
  39. package/src/audit/checks/featured-snippet.ts +473 -0
  40. package/src/audit/checks/freshness-signals.ts +443 -0
  41. package/src/audit/checks/funnel-intent.ts +463 -0
  42. package/src/audit/checks/hreflang.ts +174 -0
  43. package/src/audit/checks/html-compliance.ts +302 -0
  44. package/src/audit/checks/image-dimensions.ts +167 -0
  45. package/src/audit/checks/images.ts +160 -0
  46. package/src/audit/checks/indexnow.ts +275 -0
  47. package/src/audit/checks/interactive-tools.ts +475 -0
  48. package/src/audit/checks/internal-link-graph.ts +436 -0
  49. package/src/audit/checks/keyword-analysis.ts +239 -0
  50. package/src/audit/checks/keyword-cannibalization.ts +385 -0
  51. package/src/audit/checks/keyword-placement.ts +471 -0
  52. package/src/audit/checks/links.ts +203 -0
  53. package/src/audit/checks/llms-txt.ts +224 -0
  54. package/src/audit/checks/local-seo.ts +296 -0
  55. package/src/audit/checks/mobile.ts +167 -0
  56. package/src/audit/checks/modern-images.ts +226 -0
  57. package/src/audit/checks/navboost-signals.ts +395 -0
  58. package/src/audit/checks/on-page.ts +209 -0
  59. package/src/audit/checks/page-resources.ts +285 -0
  60. package/src/audit/checks/pagination.ts +180 -0
  61. package/src/audit/checks/performance.ts +153 -0
  62. package/src/audit/checks/platform-presence.ts +580 -0
  63. package/src/audit/checks/redirect-analysis.ts +153 -0
  64. package/src/audit/checks/redirect-chain.ts +389 -0
  65. package/src/audit/checks/resource-hints.ts +420 -0
  66. package/src/audit/checks/responsive-css.ts +247 -0
  67. package/src/audit/checks/responsive-images.ts +396 -0
  68. package/src/audit/checks/review-ecosystem.ts +415 -0
  69. package/src/audit/checks/robots-validation.ts +373 -0
  70. package/src/audit/checks/security-headers.ts +172 -0
  71. package/src/audit/checks/security.ts +144 -0
  72. package/src/audit/checks/serp-preview.ts +251 -0
  73. package/src/audit/checks/site-maturity.ts +444 -0
  74. package/src/audit/checks/social-meta.test.ts +275 -0
  75. package/src/audit/checks/social-meta.ts +134 -0
  76. package/src/audit/checks/soft-404.ts +151 -0
  77. package/src/audit/checks/structured-data.ts +238 -0
  78. package/src/audit/checks/tech-detection.ts +496 -0
  79. package/src/audit/checks/topical-clusters.ts +435 -0
  80. package/src/audit/checks/tracker-bloat.ts +462 -0
  81. package/src/audit/checks/tracking-verification.test.ts +371 -0
  82. package/src/audit/checks/tracking-verification.ts +636 -0
  83. package/src/audit/checks/url-safety.ts +682 -0
  84. package/src/audit/deno-entry.ts +66 -0
  85. package/src/audit/discovery/index.ts +15 -0
  86. package/src/audit/discovery/link-crawler.ts +232 -0
  87. package/src/audit/discovery/repo-routes.ts +347 -0
  88. package/src/audit/engine.ts +620 -0
  89. package/src/audit/fixes/index.ts +209 -0
  90. package/src/audit/fixes/social-meta-fixes.test.ts +329 -0
  91. package/src/audit/fixes/social-meta-fixes.ts +463 -0
  92. package/src/audit/index.ts +74 -0
  93. package/src/audit/runner.test.ts +299 -0
  94. package/src/audit/runner.ts +130 -0
  95. package/src/audit/types.ts +1953 -0
  96. package/src/content/featured-snippet.ts +367 -0
  97. package/src/content/generator.test.ts +534 -0
  98. package/src/content/generator.ts +501 -0
  99. package/src/content/headline.ts +317 -0
  100. package/src/content/index.ts +62 -0
  101. package/src/content/intent.ts +258 -0
  102. package/src/content/keyword-density.ts +349 -0
  103. package/src/content/readability.ts +262 -0
  104. package/src/executor.ts +336 -0
  105. package/src/fixer.ts +416 -0
  106. package/src/frameworks/detector.test.ts +248 -0
  107. package/src/frameworks/detector.ts +371 -0
  108. package/src/frameworks/index.ts +68 -0
  109. package/src/frameworks/recipes/angular.yaml +171 -0
  110. package/src/frameworks/recipes/astro.yaml +206 -0
  111. package/src/frameworks/recipes/django.yaml +180 -0
  112. package/src/frameworks/recipes/laravel.yaml +137 -0
  113. package/src/frameworks/recipes/nextjs.yaml +268 -0
  114. package/src/frameworks/recipes/nuxt.yaml +175 -0
  115. package/src/frameworks/recipes/rails.yaml +188 -0
  116. package/src/frameworks/recipes/react.yaml +202 -0
  117. package/src/frameworks/recipes/sveltekit.yaml +154 -0
  118. package/src/frameworks/recipes/vue.yaml +137 -0
  119. package/src/frameworks/recipes/wordpress.yaml +209 -0
  120. package/src/frameworks/suggestion-engine.ts +320 -0
  121. package/src/geo/geo-content.test.ts +305 -0
  122. package/src/geo/geo-content.ts +266 -0
  123. package/src/geo/geo-history.test.ts +473 -0
  124. package/src/geo/geo-history.ts +433 -0
  125. package/src/geo/geo-tracker.test.ts +359 -0
  126. package/src/geo/geo-tracker.ts +411 -0
  127. package/src/geo/index.ts +10 -0
  128. package/src/git/commit-helper.test.ts +261 -0
  129. package/src/git/commit-helper.ts +329 -0
  130. package/src/git/index.ts +12 -0
  131. package/src/git/pr-helper.test.ts +284 -0
  132. package/src/git/pr-helper.ts +307 -0
  133. package/src/index.ts +66 -0
  134. package/src/keywords/ai-keyword-engine.ts +1062 -0
  135. package/src/keywords/ai-summarizer.ts +387 -0
  136. package/src/keywords/ci-mode.ts +555 -0
  137. package/src/keywords/engine.ts +359 -0
  138. package/src/keywords/index.ts +151 -0
  139. package/src/keywords/llm-judge.ts +357 -0
  140. package/src/keywords/nlp-analysis.ts +706 -0
  141. package/src/keywords/prioritizer.ts +295 -0
  142. package/src/keywords/site-crawler.ts +342 -0
  143. package/src/keywords/sources/autocomplete.ts +139 -0
  144. package/src/keywords/sources/competitive-search.ts +450 -0
  145. package/src/keywords/sources/competitor-analysis.ts +374 -0
  146. package/src/keywords/sources/dataforseo.ts +206 -0
  147. package/src/keywords/sources/free-sources.ts +294 -0
  148. package/src/keywords/sources/gsc.ts +123 -0
  149. package/src/keywords/topic-grouping.ts +327 -0
  150. package/src/keywords/types.ts +144 -0
  151. package/src/keywords/wizard.ts +457 -0
  152. package/src/loader.ts +40 -0
  153. package/src/reports/index.ts +7 -0
  154. package/src/reports/report-generator.test.ts +293 -0
  155. package/src/reports/report-generator.ts +713 -0
  156. package/src/scheduler/alerts.test.ts +458 -0
  157. package/src/scheduler/alerts.ts +328 -0
  158. package/src/scheduler/index.ts +8 -0
  159. package/src/scheduler/scheduled-audit.test.ts +377 -0
  160. package/src/scheduler/scheduled-audit.ts +149 -0
  161. package/src/test/integration-test.ts +325 -0
  162. package/src/tools/analyzer.ts +373 -0
  163. package/src/tools/crawl.ts +293 -0
  164. package/src/tools/files.ts +301 -0
  165. package/src/tools/h1-fixer.ts +249 -0
  166. package/src/tools/index.ts +67 -0
  167. package/src/tracking/github-action.ts +326 -0
  168. package/src/tracking/google-analytics.ts +265 -0
  169. package/src/tracking/index.ts +45 -0
  170. package/src/tracking/report-generator.ts +386 -0
  171. package/src/tracking/search-console.ts +335 -0
  172. package/src/types.ts +134 -0
  173. package/src/utils/http.ts +302 -0
  174. package/src/wasm-adapter.ts +297 -0
  175. package/src/wasm-entry.ts +14 -0
  176. package/tsconfig.json +17 -0
  177. package/tsup.wasm.config.ts +26 -0
  178. package/vitest.config.ts +15 -0
@@ -0,0 +1,317 @@
1
+ // Headline Analysis & Optimization
2
+ // Scores headlines for SEO and engagement effectiveness
3
+
4
+ export interface HeadlineAnalysis {
5
+ headline: string;
6
+ score: number; // 0-100
7
+ wordCount: number;
8
+ charCount: number;
9
+ // Score breakdown
10
+ breakdown: {
11
+ length: number;
12
+ powerWords: number;
13
+ emotionalWords: number;
14
+ numbers: number;
15
+ readability: number;
16
+ uniqueness: number;
17
+ };
18
+ // Issues and suggestions
19
+ issues: string[];
20
+ suggestions: string[];
21
+ // Classification
22
+ type: 'how-to' | 'list' | 'question' | 'statement' | 'guide' | 'other';
23
+ sentiment: 'positive' | 'negative' | 'neutral';
24
+ }
25
+
26
+ // Power words that drive engagement
27
+ const POWER_WORDS = new Set([
28
+ 'ultimate', 'essential', 'proven', 'powerful', 'incredible', 'amazing',
29
+ 'exclusive', 'secret', 'free', 'new', 'best', 'top', 'complete', 'simple',
30
+ 'easy', 'quick', 'fast', 'instant', 'guaranteed', 'effective', 'brilliant',
31
+ 'stunning', 'remarkable', 'exceptional', 'revolutionary', 'breakthrough',
32
+ 'transform', 'discover', 'unlock', 'master', 'boost', 'skyrocket', 'crush',
33
+ ]);
34
+
35
+ // Emotional trigger words
36
+ const EMOTIONAL_WORDS = new Set([
37
+ 'love', 'hate', 'fear', 'anxiety', 'stress', 'happy', 'sad', 'angry',
38
+ 'frustrated', 'excited', 'thrilled', 'terrified', 'worried', 'confident',
39
+ 'surprising', 'shocking', 'devastating', 'inspiring', 'heartwarming',
40
+ 'painful', 'embarrassing', 'awkward', 'dangerous', 'risky', 'safe',
41
+ ]);
42
+
43
+ // Common/weak words to avoid
44
+ const WEAK_WORDS = new Set([
45
+ 'things', 'stuff', 'very', 'really', 'just', 'actually', 'basically',
46
+ 'literally', 'nice', 'good', 'great', 'awesome', 'cool', 'interesting',
47
+ ]);
48
+
49
+ /**
50
+ * Analyze headline effectiveness
51
+ */
52
+ export function analyzeHeadline(headline: string): HeadlineAnalysis {
53
+ const words = headline.toLowerCase().split(/\s+/).filter(w => w.length > 0);
54
+ const wordCount = words.length;
55
+ const charCount = headline.length;
56
+
57
+ const issues: string[] = [];
58
+ const suggestions: string[] = [];
59
+
60
+ // Score components
61
+ const breakdown = {
62
+ length: 0,
63
+ powerWords: 0,
64
+ emotionalWords: 0,
65
+ numbers: 0,
66
+ readability: 0,
67
+ uniqueness: 0,
68
+ };
69
+
70
+ // 1. Length score (ideal: 6-12 words, 50-60 chars for SEO)
71
+ if (wordCount >= 6 && wordCount <= 12) {
72
+ breakdown.length = 25;
73
+ } else if (wordCount >= 4 && wordCount <= 15) {
74
+ breakdown.length = 15;
75
+ } else if (wordCount < 4) {
76
+ breakdown.length = 5;
77
+ issues.push('Too short - aim for 6-12 words');
78
+ suggestions.push('Add more descriptive words to convey value');
79
+ } else {
80
+ breakdown.length = 10;
81
+ issues.push('Too long - may get truncated in SERPs');
82
+ suggestions.push('Trim to under 60 characters for display');
83
+ }
84
+
85
+ if (charCount <= 60) {
86
+ breakdown.length += 5;
87
+ } else if (charCount <= 70) {
88
+ breakdown.length += 2;
89
+ } else {
90
+ issues.push(`Title is ${charCount} chars (${charCount - 60} over limit)`);
91
+ }
92
+
93
+ // 2. Power words
94
+ const powerWordCount = words.filter(w => POWER_WORDS.has(w.replace(/[^a-z]/g, ''))).length;
95
+ if (powerWordCount >= 2) {
96
+ breakdown.powerWords = 20;
97
+ } else if (powerWordCount === 1) {
98
+ breakdown.powerWords = 15;
99
+ suggestions.push('Add another power word for more impact');
100
+ } else {
101
+ breakdown.powerWords = 0;
102
+ suggestions.push('Include power words like: ultimate, proven, essential, free');
103
+ }
104
+
105
+ // 3. Emotional words
106
+ const emotionalCount = words.filter(w => EMOTIONAL_WORDS.has(w.replace(/[^a-z]/g, ''))).length;
107
+ if (emotionalCount >= 1) {
108
+ breakdown.emotionalWords = 15;
109
+ } else {
110
+ breakdown.emotionalWords = 5;
111
+ suggestions.push('Consider adding emotional trigger words for engagement');
112
+ }
113
+
114
+ // 4. Numbers (lists perform well)
115
+ const hasNumber = /\d+/.test(headline);
116
+ if (hasNumber) {
117
+ breakdown.numbers = 15;
118
+ // Odd numbers perform better
119
+ const numbers = headline.match(/\d+/g) || [];
120
+ const hasOddNumber = numbers.some(n => parseInt(n) % 2 !== 0);
121
+ if (hasOddNumber) {
122
+ breakdown.numbers += 5;
123
+ }
124
+ } else {
125
+ breakdown.numbers = 0;
126
+ suggestions.push('Consider adding a number (e.g., "7 Ways to...", "5 Tips for...")');
127
+ }
128
+
129
+ // 5. Readability
130
+ const weakWordCount = words.filter(w => WEAK_WORDS.has(w)).length;
131
+ if (weakWordCount === 0) {
132
+ breakdown.readability = 15;
133
+ } else {
134
+ breakdown.readability = Math.max(0, 15 - weakWordCount * 5);
135
+ issues.push(`Contains weak/vague words: ${words.filter(w => WEAK_WORDS.has(w)).join(', ')}`);
136
+ }
137
+
138
+ // Check for sentence case (Title Case vs sentence case)
139
+ const titleCaseWords = words.filter((w, i) => i > 0 && /^[A-Z]/.test(headline.split(/\s+/)[i]));
140
+ if (titleCaseWords.length > words.length * 0.7) {
141
+ suggestions.push('Consider sentence case instead of Title Case for better readability');
142
+ }
143
+
144
+ // 6. Uniqueness (check for clichés)
145
+ const cliches = [
146
+ 'you need to know',
147
+ 'you won\'t believe',
148
+ 'the truth about',
149
+ 'everything you need',
150
+ 'game changer',
151
+ 'must read',
152
+ ];
153
+ const hasCliche = cliches.some(c => headline.toLowerCase().includes(c));
154
+ if (hasCliche) {
155
+ breakdown.uniqueness = 5;
156
+ issues.push('Contains overused phrases/clichés');
157
+ suggestions.push('Try a more original angle or phrasing');
158
+ } else {
159
+ breakdown.uniqueness = 10;
160
+ }
161
+
162
+ // Classify headline type
163
+ const type = classifyHeadlineType(headline);
164
+
165
+ // Determine sentiment
166
+ const sentiment = analyzeSentiment(words);
167
+
168
+ // Calculate total score
169
+ const score = Math.min(100,
170
+ breakdown.length +
171
+ breakdown.powerWords +
172
+ breakdown.emotionalWords +
173
+ breakdown.numbers +
174
+ breakdown.readability +
175
+ breakdown.uniqueness
176
+ );
177
+
178
+ // Add type-specific suggestions
179
+ if (type === 'question' && !headline.endsWith('?')) {
180
+ suggestions.push('Question headlines should end with a question mark');
181
+ }
182
+
183
+ if (type === 'how-to' && !headline.toLowerCase().startsWith('how to')) {
184
+ suggestions.push('Ensure "How to" appears at the beginning for clarity');
185
+ }
186
+
187
+ return {
188
+ headline,
189
+ score,
190
+ wordCount,
191
+ charCount,
192
+ breakdown,
193
+ issues,
194
+ suggestions,
195
+ type,
196
+ sentiment,
197
+ };
198
+ }
199
+
200
+ function classifyHeadlineType(headline: string): HeadlineAnalysis['type'] {
201
+ const h = headline.toLowerCase();
202
+
203
+ if (h.startsWith('how to') || h.includes('how to')) return 'how-to';
204
+ if (/^\d+\s/.test(h) || /\btop\s+\d+\b/.test(h)) return 'list';
205
+ if (h.endsWith('?') || h.startsWith('what') || h.startsWith('why') || h.startsWith('when')) return 'question';
206
+ if (h.includes('guide') || h.includes('tutorial')) return 'guide';
207
+ if (/^(the|a|an)\s/i.test(h)) return 'statement';
208
+
209
+ return 'other';
210
+ }
211
+
212
+ function analyzeSentiment(words: string[]): HeadlineAnalysis['sentiment'] {
213
+ const positiveWords = new Set(['best', 'top', 'amazing', 'great', 'success', 'win', 'boost', 'improve', 'easy', 'free', 'new']);
214
+ const negativeWords = new Set(['worst', 'bad', 'fail', 'mistake', 'avoid', 'stop', 'never', 'wrong', 'problem', 'risk', 'danger']);
215
+
216
+ let positiveCount = 0;
217
+ let negativeCount = 0;
218
+
219
+ for (const word of words) {
220
+ const w = word.replace(/[^a-z]/g, '');
221
+ if (positiveWords.has(w)) positiveCount++;
222
+ if (negativeWords.has(w)) negativeCount++;
223
+ }
224
+
225
+ if (positiveCount > negativeCount) return 'positive';
226
+ if (negativeCount > positiveCount) return 'negative';
227
+ return 'neutral';
228
+ }
229
+
230
+ /**
231
+ * Generate headline variations
232
+ */
233
+ export function generateHeadlineVariations(topic: string, keywords: string[]): string[] {
234
+ const variations: string[] = [];
235
+ const mainKeyword = keywords[0] || topic;
236
+
237
+ // How-to format
238
+ variations.push(`How to ${topic} in ${Math.floor(Math.random() * 5) + 3} Simple Steps`);
239
+ variations.push(`How to ${topic}: A Complete Guide`);
240
+
241
+ // List format (odd numbers perform better)
242
+ const oddNumbers = [3, 5, 7, 9, 11, 13];
243
+ const num = oddNumbers[Math.floor(Math.random() * oddNumbers.length)];
244
+ variations.push(`${num} Proven Ways to ${topic}`);
245
+ variations.push(`${num} ${mainKeyword} Tips That Actually Work`);
246
+
247
+ // Question format
248
+ variations.push(`What Is ${topic}? Everything You Need to Know`);
249
+ variations.push(`Why ${topic} Matters More Than Ever in ${new Date().getFullYear()}`);
250
+
251
+ // Statement with power words
252
+ variations.push(`The Ultimate Guide to ${topic}`);
253
+ variations.push(`${topic}: The Complete ${new Date().getFullYear()} Guide`);
254
+
255
+ // Problem/solution
256
+ variations.push(`${topic} Made Simple: A Beginner's Guide`);
257
+ variations.push(`Master ${topic} Without the Confusion`);
258
+
259
+ return variations;
260
+ }
261
+
262
+ /**
263
+ * Format headline analysis report
264
+ */
265
+ export function formatHeadlineReport(analysis: HeadlineAnalysis): string {
266
+ const lines: string[] = [];
267
+
268
+ lines.push('');
269
+ lines.push('═'.repeat(60));
270
+ lines.push(' HEADLINE ANALYSIS');
271
+ lines.push('═'.repeat(60));
272
+ lines.push('');
273
+
274
+ // Headline and score
275
+ lines.push(`"${analysis.headline}"`);
276
+ lines.push('');
277
+
278
+ const scoreIcon = analysis.score >= 70 ? '🟢' : analysis.score >= 50 ? '🟡' : '🔴';
279
+ lines.push(`${scoreIcon} Score: ${analysis.score}/100`);
280
+ lines.push(` Type: ${analysis.type} | Sentiment: ${analysis.sentiment}`);
281
+ lines.push(` Length: ${analysis.wordCount} words, ${analysis.charCount} chars`);
282
+ lines.push('');
283
+
284
+ // Score breakdown
285
+ lines.push('📊 SCORE BREAKDOWN');
286
+ lines.push('─'.repeat(60));
287
+ lines.push(` Length: ${analysis.breakdown.length}/30`);
288
+ lines.push(` Power Words: ${analysis.breakdown.powerWords}/20`);
289
+ lines.push(` Emotion: ${analysis.breakdown.emotionalWords}/15`);
290
+ lines.push(` Numbers: ${analysis.breakdown.numbers}/20`);
291
+ lines.push(` Readability: ${analysis.breakdown.readability}/15`);
292
+ lines.push('');
293
+
294
+ // Issues
295
+ if (analysis.issues.length > 0) {
296
+ lines.push('⚠️ ISSUES');
297
+ lines.push('─'.repeat(60));
298
+ for (const issue of analysis.issues) {
299
+ lines.push(` • ${issue}`);
300
+ }
301
+ lines.push('');
302
+ }
303
+
304
+ // Suggestions
305
+ if (analysis.suggestions.length > 0) {
306
+ lines.push('💡 SUGGESTIONS');
307
+ lines.push('─'.repeat(60));
308
+ for (const suggestion of analysis.suggestions) {
309
+ lines.push(` • ${suggestion}`);
310
+ }
311
+ lines.push('');
312
+ }
313
+
314
+ lines.push('═'.repeat(60));
315
+
316
+ return lines.join('\n');
317
+ }
@@ -0,0 +1,62 @@
1
+ // Content Analysis & Optimization Module
2
+ // Tools for analyzing and optimizing content for SEO
3
+
4
+ // Readability Analysis
5
+ export {
6
+ analyzeReadability,
7
+ formatReadabilityReport,
8
+ type ReadabilityResult,
9
+ } from './readability.js';
10
+
11
+ // Search Intent Classification
12
+ export {
13
+ classifyIntent,
14
+ classifyIntents,
15
+ formatIntentReport,
16
+ type SearchIntent,
17
+ type IntentAnalysis,
18
+ } from './intent.js';
19
+
20
+ // Headline Analysis
21
+ export {
22
+ analyzeHeadline,
23
+ generateHeadlineVariations,
24
+ formatHeadlineReport,
25
+ type HeadlineAnalysis,
26
+ } from './headline.js';
27
+
28
+ // Featured Snippet Optimization
29
+ export {
30
+ analyzeFeaturedSnippetPotential,
31
+ formatFeaturedSnippetReport,
32
+ type SnippetType,
33
+ type FeaturedSnippetAnalysis,
34
+ type SnippetRecommendation,
35
+ } from './featured-snippet.js';
36
+
37
+ // Keyword Density & LSI
38
+ export {
39
+ analyzeKeywordDensity,
40
+ findLSIKeywords,
41
+ calculateTFIDF,
42
+ formatKeywordDensityReport,
43
+ type KeywordDensityAnalysis,
44
+ type LSIKeyword,
45
+ type ContentElements,
46
+ } from './keyword-density.js';
47
+
48
+ // Content Generation
49
+ export {
50
+ generateBlogPost,
51
+ generateChangelog,
52
+ optimizeReadme,
53
+ scoreContentSEO,
54
+ type BlogPostConfig,
55
+ type ChangelogConfig,
56
+ type ReadmeConfig,
57
+ type GeneratedContent,
58
+ type ChangelogResult,
59
+ type ReadmeResult,
60
+ type SEOScore,
61
+ type ContentGeneratorOptions,
62
+ } from './generator.js';
@@ -0,0 +1,258 @@
1
+ // Search Intent Classification
2
+ // Categorizes queries as informational, navigational, transactional, or commercial
3
+
4
+ export type SearchIntent = 'informational' | 'navigational' | 'transactional' | 'commercial';
5
+
6
+ export interface IntentAnalysis {
7
+ intent: SearchIntent;
8
+ confidence: number; // 0-100
9
+ signals: string[];
10
+ recommendedContentFormat: string;
11
+ contentSuggestions: string[];
12
+ }
13
+
14
+ /**
15
+ * Classify search intent for a keyword/query
16
+ */
17
+ export function classifyIntent(query: string): IntentAnalysis {
18
+ const q = query.toLowerCase().trim();
19
+ const signals: string[] = [];
20
+ const scores: Record<SearchIntent, number> = {
21
+ informational: 0,
22
+ navigational: 0,
23
+ transactional: 0,
24
+ commercial: 0,
25
+ };
26
+
27
+ // Informational signals (user wants to learn)
28
+ const informationalPatterns = [
29
+ { pattern: /^(what|who|why|when|where|which)\b/, weight: 30, signal: 'Question word (what/who/why)' },
30
+ { pattern: /^how (to|do|does|can|should)\b/, weight: 35, signal: 'How-to question' },
31
+ { pattern: /\b(guide|tutorial|learn|understand|explain)\b/, weight: 25, signal: 'Learning intent' },
32
+ { pattern: /\b(definition|meaning|example|history)\b/, weight: 25, signal: 'Definition/meaning query' },
33
+ { pattern: /\b(tips|ideas|ways to|steps)\b/, weight: 20, signal: 'Tips/ideas request' },
34
+ { pattern: /^(is|are|can|does|do)\b/, weight: 15, signal: 'Yes/no question' },
35
+ { pattern: /\b(vs|versus|difference between|compared to)\b/, weight: 20, signal: 'Comparison query' },
36
+ ];
37
+
38
+ // Navigational signals (user wants to go somewhere specific)
39
+ const navigationalPatterns = [
40
+ { pattern: /\b(login|sign in|log in|signin)\b/, weight: 40, signal: 'Login intent' },
41
+ { pattern: /\b(\.com|\.org|\.net|\.io)\b/, weight: 35, signal: 'Domain in query' },
42
+ { pattern: /\b(official|website|homepage|site)\b/, weight: 30, signal: 'Website reference' },
43
+ { pattern: /\b(facebook|twitter|instagram|youtube|linkedin|github)\b/, weight: 40, signal: 'Social platform' },
44
+ { pattern: /\b(amazon|google|apple|microsoft)\b/, weight: 25, signal: 'Brand name' },
45
+ { pattern: /\b(app|download|install)\b/, weight: 20, signal: 'App/download intent' },
46
+ ];
47
+
48
+ // Transactional signals (user wants to take action/buy)
49
+ const transactionalPatterns = [
50
+ { pattern: /\b(buy|purchase|order|shop)\b/, weight: 40, signal: 'Purchase intent' },
51
+ { pattern: /\b(price|pricing|cost|cheap|discount|deal|sale|coupon)\b/, weight: 35, signal: 'Price interest' },
52
+ { pattern: /\b(free trial|free download|download free)\b/, weight: 30, signal: 'Free trial/download' },
53
+ { pattern: /\b(subscribe|sign up|signup|register)\b/, weight: 30, signal: 'Signup intent' },
54
+ { pattern: /\b(book|reserve|schedule|appointment)\b/, weight: 30, signal: 'Booking intent' },
55
+ { pattern: /\b(hire|service|quote)\b/, weight: 25, signal: 'Service request' },
56
+ { pattern: /\b(near me|nearby|local)\b/, weight: 25, signal: 'Local intent' },
57
+ ];
58
+
59
+ // Commercial investigation signals (user researching before purchase)
60
+ const commercialPatterns = [
61
+ { pattern: /\b(best|top|review|reviews)\b/, weight: 35, signal: 'Review/best-of query' },
62
+ { pattern: /\b(comparison|compare|vs|versus|or)\b/, weight: 30, signal: 'Comparison shopping' },
63
+ { pattern: /\b(alternative|alternatives to)\b/, weight: 30, signal: 'Alternative search' },
64
+ { pattern: /\b(pros and cons|advantages|disadvantages)\b/, weight: 25, signal: 'Evaluation query' },
65
+ { pattern: /\b(worth it|should i|is it good)\b/, weight: 25, signal: 'Purchase consideration' },
66
+ { pattern: /\b(for (small business|enterprise|startups|developers))\b/, weight: 20, signal: 'Segment-specific' },
67
+ { pattern: /\b20\d{2}\b/, weight: 15, signal: 'Year reference (recency)' },
68
+ ];
69
+
70
+ // Calculate scores
71
+ for (const p of informationalPatterns) {
72
+ if (p.pattern.test(q)) {
73
+ scores.informational += p.weight;
74
+ signals.push(`[INFO] ${p.signal}`);
75
+ }
76
+ }
77
+
78
+ for (const p of navigationalPatterns) {
79
+ if (p.pattern.test(q)) {
80
+ scores.navigational += p.weight;
81
+ signals.push(`[NAV] ${p.signal}`);
82
+ }
83
+ }
84
+
85
+ for (const p of transactionalPatterns) {
86
+ if (p.pattern.test(q)) {
87
+ scores.transactional += p.weight;
88
+ signals.push(`[TRANS] ${p.signal}`);
89
+ }
90
+ }
91
+
92
+ for (const p of commercialPatterns) {
93
+ if (p.pattern.test(q)) {
94
+ scores.commercial += p.weight;
95
+ signals.push(`[COMM] ${p.signal}`);
96
+ }
97
+ }
98
+
99
+ // Determine winner
100
+ const maxScore = Math.max(...Object.values(scores));
101
+ let intent: SearchIntent = 'informational'; // Default
102
+
103
+ if (maxScore === 0) {
104
+ // No clear signals, use heuristics
105
+ const wordCount = q.split(/\s+/).length;
106
+ if (wordCount <= 2) {
107
+ intent = 'navigational';
108
+ signals.push('[DEFAULT] Short query - likely navigational');
109
+ } else {
110
+ intent = 'informational';
111
+ signals.push('[DEFAULT] No clear signals - defaulting to informational');
112
+ }
113
+ } else {
114
+ intent = (Object.entries(scores) as [SearchIntent, number][])
115
+ .sort((a, b) => b[1] - a[1])[0][0];
116
+ }
117
+
118
+ // Calculate confidence
119
+ const totalScore = Object.values(scores).reduce((a, b) => a + b, 0);
120
+ const confidence = totalScore > 0
121
+ ? Math.min(100, Math.round((scores[intent] / totalScore) * 100))
122
+ : 50;
123
+
124
+ // Get recommendations
125
+ const { recommendedContentFormat, contentSuggestions } = getContentRecommendations(intent);
126
+
127
+ return {
128
+ intent,
129
+ confidence,
130
+ signals,
131
+ recommendedContentFormat,
132
+ contentSuggestions,
133
+ };
134
+ }
135
+
136
+ function getContentRecommendations(intent: SearchIntent): {
137
+ recommendedContentFormat: string;
138
+ contentSuggestions: string[];
139
+ } {
140
+ switch (intent) {
141
+ case 'informational':
142
+ return {
143
+ recommendedContentFormat: 'Long-form blog post, guide, or tutorial',
144
+ contentSuggestions: [
145
+ 'Create comprehensive how-to content',
146
+ 'Include step-by-step instructions',
147
+ 'Add FAQ section for related questions',
148
+ 'Use clear headings (H2, H3) for scanability',
149
+ 'Include images/diagrams to illustrate concepts',
150
+ 'Target featured snippet with direct answers',
151
+ ],
152
+ };
153
+
154
+ case 'navigational':
155
+ return {
156
+ recommendedContentFormat: 'Brand landing page or homepage',
157
+ contentSuggestions: [
158
+ 'Ensure brand name is in title and H1',
159
+ 'Include clear navigation to key sections',
160
+ 'Add structured data for organization/website',
161
+ 'Optimize for brand + product variations',
162
+ 'Include social proof and trust signals',
163
+ ],
164
+ };
165
+
166
+ case 'transactional':
167
+ return {
168
+ recommendedContentFormat: 'Product page or service landing page',
169
+ contentSuggestions: [
170
+ 'Include clear CTA (Buy, Sign Up, Download)',
171
+ 'Show pricing information prominently',
172
+ 'Add product schema markup',
173
+ 'Include trust signals (reviews, testimonials)',
174
+ 'Optimize for "buy", "price", "discount" variations',
175
+ 'Add urgency elements (limited time, stock)',
176
+ ],
177
+ };
178
+
179
+ case 'commercial':
180
+ return {
181
+ recommendedContentFormat: 'Comparison page, review, or buying guide',
182
+ contentSuggestions: [
183
+ 'Create detailed comparison tables',
184
+ 'Include pros and cons lists',
185
+ 'Add expert opinions or user reviews',
186
+ 'Compare features, pricing, use cases',
187
+ 'Include clear recommendation/winner',
188
+ 'Add affiliate-friendly product links',
189
+ ],
190
+ };
191
+ }
192
+ }
193
+
194
+ /**
195
+ * Batch classify multiple keywords
196
+ */
197
+ export function classifyIntents(keywords: string[]): Map<string, IntentAnalysis> {
198
+ const results = new Map<string, IntentAnalysis>();
199
+ for (const kw of keywords) {
200
+ results.set(kw, classifyIntent(kw));
201
+ }
202
+ return results;
203
+ }
204
+
205
+ /**
206
+ * Format intent analysis report
207
+ */
208
+ export function formatIntentReport(query: string, analysis: IntentAnalysis): string {
209
+ const lines: string[] = [];
210
+
211
+ const intentIcons: Record<SearchIntent, string> = {
212
+ informational: '📚',
213
+ navigational: '🧭',
214
+ transactional: '💰',
215
+ commercial: '🔍',
216
+ };
217
+
218
+ lines.push('');
219
+ lines.push('═'.repeat(60));
220
+ lines.push(' SEARCH INTENT ANALYSIS');
221
+ lines.push('═'.repeat(60));
222
+ lines.push('');
223
+
224
+ lines.push(`Query: "${query}"`);
225
+ lines.push('');
226
+
227
+ lines.push(`${intentIcons[analysis.intent]} Intent: ${analysis.intent.toUpperCase()}`);
228
+ lines.push(` Confidence: ${analysis.confidence}%`);
229
+ lines.push('');
230
+
231
+ // Signals
232
+ if (analysis.signals.length > 0) {
233
+ lines.push('📊 SIGNALS DETECTED');
234
+ lines.push('─'.repeat(60));
235
+ for (const signal of analysis.signals) {
236
+ lines.push(` • ${signal}`);
237
+ }
238
+ lines.push('');
239
+ }
240
+
241
+ // Content format
242
+ lines.push('📝 RECOMMENDED CONTENT');
243
+ lines.push('─'.repeat(60));
244
+ lines.push(` Format: ${analysis.recommendedContentFormat}`);
245
+ lines.push('');
246
+
247
+ // Suggestions
248
+ lines.push('💡 CONTENT SUGGESTIONS');
249
+ lines.push('─'.repeat(60));
250
+ for (const suggestion of analysis.contentSuggestions) {
251
+ lines.push(` • ${suggestion}`);
252
+ }
253
+ lines.push('');
254
+
255
+ lines.push('═'.repeat(60));
256
+
257
+ return lines.join('\n');
258
+ }