@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,555 @@
1
+ /**
2
+ * CI Mode for Keyword Research
3
+ *
4
+ * Handles automated keyword research in CI/CD pipelines.
5
+ * - If confidence is high enough, adds keywords to PR
6
+ * - If uncertainty is high, skips and warns user
7
+ * - Provides clear instructions for what to do next
8
+ */
9
+
10
+ import {
11
+ runAIKeywordResearch,
12
+ type PaidKeywordResult,
13
+ type FreeKeywordResult,
14
+ type KeywordRecommendation,
15
+ type PlanTier,
16
+ } from './ai-keyword-engine.js';
17
+ import type { SiteSummary } from './ai-summarizer.js';
18
+
19
+ export interface CIKeywordOptions {
20
+ url: string;
21
+ tier: PlanTier;
22
+ openaiApiKey?: string;
23
+ /** Minimum confidence to proceed (default: 0.7) */
24
+ minConfidence?: number;
25
+ /** Maximum keywords to include in PR */
26
+ maxKeywords?: number;
27
+ /** Branch name for context */
28
+ branchName?: string;
29
+ /** PR number if applicable */
30
+ prNumber?: number;
31
+ /** Site ID for dashboard link */
32
+ siteId?: string;
33
+ }
34
+
35
+ export interface CIKeywordResult {
36
+ /** Whether keywords can be added to the PR */
37
+ canAddToPR: boolean;
38
+ /** Keywords to add (if canAddToPR is true) */
39
+ keywords: KeywordRecommendation[];
40
+ /** Warning messages to display */
41
+ warnings: string[];
42
+ /** Error messages (if any) */
43
+ errors: string[];
44
+ /** Info messages */
45
+ info: string[];
46
+ /** Actions user needs to take */
47
+ requiredActions: CIAction[];
48
+ /** PR comment body */
49
+ prCommentBody: string;
50
+ /** Exit code (0 = success, 1 = needs action, 2 = error) */
51
+ exitCode: 0 | 1 | 2;
52
+ /** Detailed explanation */
53
+ explanation: string;
54
+ /** Raw result for debugging */
55
+ rawResult?: PaidKeywordResult | FreeKeywordResult;
56
+ }
57
+
58
+ export interface CIAction {
59
+ title: string;
60
+ description: string;
61
+ command?: string;
62
+ webUrl?: string;
63
+ priority: 'high' | 'medium' | 'low';
64
+ }
65
+
66
+ const CI_CONFIDENCE_THRESHOLD = 0.7;
67
+ const MAX_KEYWORDS_IN_PR = 10;
68
+
69
+ /**
70
+ * Run keyword research in CI mode
71
+ */
72
+ export async function runCIKeywordResearch(
73
+ options: CIKeywordOptions
74
+ ): Promise<CIKeywordResult> {
75
+ const {
76
+ url,
77
+ tier,
78
+ openaiApiKey,
79
+ minConfidence = CI_CONFIDENCE_THRESHOLD,
80
+ maxKeywords = MAX_KEYWORDS_IN_PR,
81
+ siteId,
82
+ } = options;
83
+
84
+ const warnings: string[] = [];
85
+ const errors: string[] = [];
86
+ const info: string[] = [];
87
+ const actions: CIAction[] = [];
88
+
89
+ console.log('đŸ”Ŧ Running keyword research in CI mode...');
90
+
91
+ // Free tier gets limited results and upgrade prompt
92
+ if (tier === 'free') {
93
+ return handleFreeTierCI(url, siteId);
94
+ }
95
+
96
+ // Paid tier - require API key
97
+ if (!openaiApiKey) {
98
+ errors.push('OpenAI API key required for keyword research in CI mode');
99
+ return {
100
+ canAddToPR: false,
101
+ keywords: [],
102
+ warnings,
103
+ errors,
104
+ info,
105
+ requiredActions: [
106
+ {
107
+ title: 'Add OpenAI API Key',
108
+ description: 'Set OPENAI_API_KEY in your GitHub secrets',
109
+ command: 'gh secret set OPENAI_API_KEY',
110
+ priority: 'high',
111
+ },
112
+ ],
113
+ prCommentBody: generateErrorPRComment(errors),
114
+ exitCode: 2,
115
+ explanation: 'Missing required OpenAI API key for AI-powered keyword research.',
116
+ };
117
+ }
118
+
119
+ try {
120
+ // Run the keyword research
121
+ const result = await runAIKeywordResearch({
122
+ url,
123
+ tier,
124
+ openaiApiKey,
125
+ ciMode: true,
126
+ });
127
+
128
+ // Handle paid tier result
129
+ if ('uncertainty' in result) {
130
+ return handlePaidTierCI(result, {
131
+ minConfidence,
132
+ maxKeywords,
133
+ siteId,
134
+ warnings,
135
+ info,
136
+ });
137
+ }
138
+
139
+ // Shouldn't happen, but handle just in case
140
+ return handleFreeTierCI(url, siteId);
141
+ } catch (error) {
142
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
143
+ errors.push(`Keyword research failed: ${errorMessage}`);
144
+
145
+ return {
146
+ canAddToPR: false,
147
+ keywords: [],
148
+ warnings,
149
+ errors,
150
+ info,
151
+ requiredActions: [
152
+ {
153
+ title: 'Check Configuration',
154
+ description: 'Verify your API keys and site URL are correct',
155
+ priority: 'high',
156
+ },
157
+ ],
158
+ prCommentBody: generateErrorPRComment(errors),
159
+ exitCode: 2,
160
+ explanation: `Keyword research encountered an error: ${errorMessage}`,
161
+ };
162
+ }
163
+ }
164
+
165
+ /**
166
+ * Handle free tier CI results
167
+ */
168
+ function handleFreeTierCI(url: string, siteId?: string): CIKeywordResult {
169
+ const dashboardUrl = siteId
170
+ ? `https://rankcli.dev/dashboard/projects/${siteId}/keywords`
171
+ : 'https://rankcli.dev/pricing';
172
+
173
+ return {
174
+ canAddToPR: false,
175
+ keywords: [],
176
+ warnings: [
177
+ 'Keyword research requires a paid plan for CI automation',
178
+ ],
179
+ errors: [],
180
+ info: [
181
+ `Found potential keyword opportunities for ${url}`,
182
+ 'Upgrade to Solo plan or higher for automated keyword research in CI',
183
+ ],
184
+ requiredActions: [
185
+ {
186
+ title: 'Upgrade to Solo Plan',
187
+ description: 'Get AI-powered keyword research with CI/CD automation',
188
+ webUrl: 'https://rankcli.dev/pricing',
189
+ priority: 'medium',
190
+ },
191
+ {
192
+ title: 'Run Manual Keyword Research',
193
+ description: 'Use the CLI wizard to get keyword recommendations',
194
+ command: 'rankcli keywords --wizard',
195
+ priority: 'low',
196
+ },
197
+ ],
198
+ prCommentBody: generateFreeTierPRComment(url, dashboardUrl),
199
+ exitCode: 1,
200
+ explanation: 'Free tier does not support automated keyword research in CI. Upgrade for this feature.',
201
+ };
202
+ }
203
+
204
+ /**
205
+ * Handle paid tier CI results
206
+ */
207
+ function handlePaidTierCI(
208
+ result: PaidKeywordResult,
209
+ options: {
210
+ minConfidence: number;
211
+ maxKeywords: number;
212
+ siteId?: string;
213
+ warnings: string[];
214
+ info: string[];
215
+ }
216
+ ): CIKeywordResult {
217
+ const { minConfidence, maxKeywords, siteId, warnings, info } = options;
218
+ const { uncertainty, recommendations, siteSummary, freeToolIdeas } = result;
219
+
220
+ const dashboardUrl = siteId
221
+ ? `https://rankcli.dev/dashboard/projects/${siteId}/keywords`
222
+ : 'https://rankcli.dev/dashboard';
223
+
224
+ const wizardUrl = siteId
225
+ ? `https://rankcli.dev/dashboard/projects/${siteId}/keywords/wizard`
226
+ : 'https://rankcli.dev/dashboard';
227
+
228
+ // Check confidence level
229
+ if (uncertainty.overallConfidence < minConfidence) {
230
+ // High uncertainty - cannot automate
231
+ const questionsNeeded = uncertainty.questionsToAsk.slice(0, 5);
232
+
233
+ return {
234
+ canAddToPR: false,
235
+ keywords: [],
236
+ warnings: [
237
+ `Confidence level (${Math.round(uncertainty.overallConfidence * 100)}%) is below threshold (${Math.round(minConfidence * 100)}%)`,
238
+ 'Keyword recommendations skipped due to uncertainty',
239
+ ],
240
+ errors: [],
241
+ info: [
242
+ `Site analyzed: ${siteSummary.productName}`,
243
+ `Industry detected: ${siteSummary.industry}`,
244
+ `Found ${recommendations.length} potential keyword opportunities`,
245
+ ],
246
+ requiredActions: [
247
+ {
248
+ title: 'Run Keyword Wizard',
249
+ description: `Answer ${questionsNeeded.length} questions to improve accuracy`,
250
+ command: 'rankcli keywords --wizard',
251
+ webUrl: wizardUrl,
252
+ priority: 'high',
253
+ },
254
+ {
255
+ title: 'Provide Product Context',
256
+ description: 'Add product description to reduce uncertainty',
257
+ command: 'rankcli keywords --context "Your product description"',
258
+ priority: 'medium',
259
+ },
260
+ ],
261
+ prCommentBody: generateUncertaintyPRComment(
262
+ siteSummary,
263
+ uncertainty,
264
+ questionsNeeded,
265
+ wizardUrl
266
+ ),
267
+ exitCode: 1,
268
+ explanation: uncertainty.explanation,
269
+ rawResult: result,
270
+ };
271
+ }
272
+
273
+ // High enough confidence - include keywords
274
+ const keywordsToAdd = recommendations
275
+ .filter((r) => r.action !== 'needs-input' && r.action !== 'skip')
276
+ .slice(0, maxKeywords);
277
+
278
+ if (keywordsToAdd.length === 0) {
279
+ warnings.push('No actionable keywords found meeting criteria');
280
+ return {
281
+ canAddToPR: false,
282
+ keywords: [],
283
+ warnings,
284
+ errors: [],
285
+ info: [
286
+ `Site: ${siteSummary.productName}`,
287
+ `Industry: ${siteSummary.industry}`,
288
+ 'Consider expanding search criteria or running wizard',
289
+ ],
290
+ requiredActions: [
291
+ {
292
+ title: 'Run Keyword Wizard',
293
+ description: 'Get personalized keyword recommendations',
294
+ command: 'rankcli keywords --wizard',
295
+ webUrl: wizardUrl,
296
+ priority: 'medium',
297
+ },
298
+ ],
299
+ prCommentBody: generateNoKeywordsPRComment(siteSummary, dashboardUrl),
300
+ exitCode: 0,
301
+ explanation: 'Analysis complete but no keywords met the criteria for automation.',
302
+ rawResult: result,
303
+ };
304
+ }
305
+
306
+ // Success - keywords can be added
307
+ info.push(`Confidence: ${Math.round(uncertainty.overallConfidence * 100)}%`);
308
+ info.push(`Adding ${keywordsToAdd.length} keyword recommendations`);
309
+
310
+ return {
311
+ canAddToPR: true,
312
+ keywords: keywordsToAdd,
313
+ warnings,
314
+ errors: [],
315
+ info,
316
+ requiredActions: [],
317
+ prCommentBody: generateSuccessPRComment(
318
+ siteSummary,
319
+ keywordsToAdd,
320
+ freeToolIdeas.slice(0, 5),
321
+ uncertainty.overallConfidence,
322
+ dashboardUrl
323
+ ),
324
+ exitCode: 0,
325
+ explanation: `Successfully analyzed ${siteSummary.productName}. ${keywordsToAdd.length} keyword recommendations ready.`,
326
+ rawResult: result,
327
+ };
328
+ }
329
+
330
+ // PR Comment Generators
331
+
332
+ function generateErrorPRComment(errors: string[]): string {
333
+ return `## 🔑 Keyword Research - Error
334
+
335
+ ❌ **Keyword research could not complete**
336
+
337
+ ${errors.map((e) => `- ${e}`).join('\n')}
338
+
339
+ ### Next Steps
340
+ 1. Check your configuration and API keys
341
+ 2. Run \`rankcli keywords --debug\` locally to diagnose
342
+ 3. See [documentation](https://rankcli.dev/docs/keywords) for help
343
+
344
+ ---
345
+ *Generated by [RankCLI](https://rankcli.dev)*`;
346
+ }
347
+
348
+ function generateFreeTierPRComment(url: string, upgradeUrl: string): string {
349
+ return `## 🔑 Keyword Research
350
+
351
+ 📊 **Keyword opportunities detected for ${url}**
352
+
353
+ Automated keyword research in CI requires a paid plan.
354
+
355
+ ### What You Get with Solo Plan ($9/mo):
356
+ - ✅ AI-powered keyword discovery
357
+ - ✅ Automated CI/CD integration
358
+ - ✅ Keyword clustering & prioritization
359
+ - ✅ Free tool ideas with CTAs
360
+ - ✅ Competitive analysis
361
+
362
+ ### Run Manually
363
+ \`\`\`bash
364
+ rankcli keywords --wizard
365
+ \`\`\`
366
+
367
+ [Upgrade to unlock →](${upgradeUrl})
368
+
369
+ ---
370
+ *Generated by [RankCLI](https://rankcli.dev)*`;
371
+ }
372
+
373
+ function generateUncertaintyPRComment(
374
+ summary: SiteSummary,
375
+ uncertainty: any,
376
+ questions: any[],
377
+ wizardUrl: string
378
+ ): string {
379
+ const questionsList = questions
380
+ .map((q, i) => `${i + 1}. ${q.question}`)
381
+ .join('\n');
382
+
383
+ return `## 🔑 Keyword Research - Needs Input
384
+
385
+ âš ī¸ **Confidence: ${Math.round(uncertainty.overallConfidence * 100)}%** - Too low for automation
386
+
387
+ ### What We Detected
388
+ - **Product:** ${summary.productName}
389
+ - **Industry:** ${summary.industry}
390
+ - **Audience:** ${summary.targetAudience}
391
+
392
+ ### Questions to Answer
393
+ To improve accuracy, please answer these questions:
394
+
395
+ ${questionsList}
396
+
397
+ ### How to Proceed
398
+
399
+ **Option 1: Run the wizard (recommended)**
400
+ \`\`\`bash
401
+ rankcli keywords --wizard
402
+ \`\`\`
403
+
404
+ **Option 2: Use the web wizard**
405
+ [Open Keyword Wizard →](${wizardUrl})
406
+
407
+ **Option 3: Provide context directly**
408
+ \`\`\`bash
409
+ rankcli keywords --context "Your product description here"
410
+ \`\`\`
411
+
412
+ ### Why This Matters
413
+ Low confidence means our recommendations might not be relevant to your business. Taking 2 minutes to answer questions will significantly improve results.
414
+
415
+ ---
416
+ *Generated by [RankCLI](https://rankcli.dev)*`;
417
+ }
418
+
419
+ function generateNoKeywordsPRComment(summary: SiteSummary, dashboardUrl: string): string {
420
+ return `## 🔑 Keyword Research - Complete
421
+
422
+ ✅ **Analysis complete for ${summary.productName}**
423
+
424
+ No keywords currently meet the automation criteria (low difficulty + high volume + high relevance).
425
+
426
+ ### What This Means
427
+ - Your niche may be competitive
428
+ - Consider longer-tail keywords
429
+ - Try the wizard for personalized recommendations
430
+
431
+ ### Next Steps
432
+ 1. Run \`rankcli keywords --wizard\` for guided research
433
+ 2. View full analysis in [dashboard](${dashboardUrl})
434
+
435
+ ---
436
+ *Generated by [RankCLI](https://rankcli.dev)*`;
437
+ }
438
+
439
+ function generateSuccessPRComment(
440
+ summary: SiteSummary,
441
+ keywords: KeywordRecommendation[],
442
+ toolIdeas: any[],
443
+ confidence: number,
444
+ dashboardUrl: string
445
+ ): string {
446
+ const keywordTable = keywords
447
+ .map((k, i) => `| ${i + 1} | ${k.keyword} | ${k.action} | ${k.impact} | ${k.effort} |`)
448
+ .join('\n');
449
+
450
+ const toolList = toolIdeas
451
+ .map((t) => `- **${t.toolName}** (${t.volume} searches/mo, KD: ${t.difficulty})`)
452
+ .join('\n');
453
+
454
+ return `## 🔑 Keyword Research - Success
455
+
456
+ ✅ **Confidence: ${Math.round(confidence * 100)}%**
457
+
458
+ ### Site Analysis
459
+ - **Product:** ${summary.productName}
460
+ - **Industry:** ${summary.industry}
461
+ - **Target:** ${summary.targetAudience}
462
+
463
+ ### Top Keyword Recommendations
464
+
465
+ | # | Keyword | Action | Impact | Effort |
466
+ |---|---------|--------|--------|--------|
467
+ ${keywordTable}
468
+
469
+ ### Free Tool Ideas (Engineering as Marketing)
470
+ ${toolList || 'No tool ideas generated'}
471
+
472
+ ### Next Steps
473
+ 1. Review recommendations in [dashboard](${dashboardUrl})
474
+ 2. Start with high-impact, low-effort keywords
475
+ 3. Build free tools to capture search traffic
476
+
477
+ ---
478
+ *Generated by [RankCLI](https://rankcli.dev) â€ĸ [View Full Report](${dashboardUrl})*`;
479
+ }
480
+
481
+ /**
482
+ * Format CI result for console output
483
+ */
484
+ export function formatCIResult(result: CIKeywordResult): string {
485
+ const lines: string[] = [];
486
+
487
+ lines.push('');
488
+ lines.push('═'.repeat(70));
489
+ lines.push(' KEYWORD RESEARCH - CI MODE');
490
+ lines.push('═'.repeat(70));
491
+ lines.push('');
492
+
493
+ // Status
494
+ if (result.canAddToPR) {
495
+ lines.push('✅ STATUS: Keywords ready to add to PR');
496
+ } else if (result.exitCode === 2) {
497
+ lines.push('❌ STATUS: Error occurred');
498
+ } else {
499
+ lines.push('âš ī¸ STATUS: Needs user input');
500
+ }
501
+ lines.push('');
502
+
503
+ // Errors
504
+ if (result.errors.length > 0) {
505
+ lines.push('ERRORS:');
506
+ result.errors.forEach((e) => lines.push(` ❌ ${e}`));
507
+ lines.push('');
508
+ }
509
+
510
+ // Warnings
511
+ if (result.warnings.length > 0) {
512
+ lines.push('WARNINGS:');
513
+ result.warnings.forEach((w) => lines.push(` âš ī¸ ${w}`));
514
+ lines.push('');
515
+ }
516
+
517
+ // Info
518
+ if (result.info.length > 0) {
519
+ lines.push('INFO:');
520
+ result.info.forEach((i) => lines.push(` â„šī¸ ${i}`));
521
+ lines.push('');
522
+ }
523
+
524
+ // Keywords
525
+ if (result.keywords.length > 0) {
526
+ lines.push('KEYWORDS:');
527
+ result.keywords.forEach((k, i) => {
528
+ lines.push(` ${i + 1}. "${k.keyword}" - ${k.action} (${k.impact} impact, ${k.effort} effort)`);
529
+ });
530
+ lines.push('');
531
+ }
532
+
533
+ // Required Actions
534
+ if (result.requiredActions.length > 0) {
535
+ lines.push('REQUIRED ACTIONS:');
536
+ result.requiredActions.forEach((a) => {
537
+ lines.push(` 📌 ${a.title}`);
538
+ lines.push(` ${a.description}`);
539
+ if (a.command) {
540
+ lines.push(` Command: ${a.command}`);
541
+ }
542
+ if (a.webUrl) {
543
+ lines.push(` URL: ${a.webUrl}`);
544
+ }
545
+ lines.push('');
546
+ });
547
+ }
548
+
549
+ // Explanation
550
+ lines.push('─'.repeat(70));
551
+ lines.push(` ${result.explanation}`);
552
+ lines.push('═'.repeat(70));
553
+
554
+ return lines.join('\n');
555
+ }