@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,457 @@
1
+ /**
2
+ * Keyword Research Wizard
3
+ *
4
+ * Interactive wizard to reduce uncertainty in keyword research.
5
+ * Works with CLI (inquirer-style) and Web (JSON responses).
6
+ */
7
+
8
+ import OpenAI from 'openai';
9
+ import { crawlSite } from './site-crawler.js';
10
+ import { summarizeSite, type SiteSummary } from './ai-summarizer.js';
11
+
12
+ export interface WizardQuestion {
13
+ id: string;
14
+ question: string;
15
+ description?: string;
16
+ type: 'select' | 'multi-select' | 'text' | 'confirm';
17
+ options?: Array<{
18
+ value: string;
19
+ label: string;
20
+ description?: string;
21
+ }>;
22
+ required: boolean;
23
+ impactOnConfidence: number;
24
+ category: 'product' | 'audience' | 'competition' | 'goals' | 'constraints';
25
+ }
26
+
27
+ export interface WizardResponse {
28
+ questionId: string;
29
+ answer: string | string[];
30
+ confidence: 'certain' | 'somewhat' | 'unsure';
31
+ }
32
+
33
+ export interface WizardSession {
34
+ sessionId: string;
35
+ url: string;
36
+ siteSummary: SiteSummary;
37
+ questions: WizardQuestion[];
38
+ responses: WizardResponse[];
39
+ currentQuestionIndex: number;
40
+ isComplete: boolean;
41
+ finalConfidence: number;
42
+ }
43
+
44
+ export interface WizardResult {
45
+ session: WizardSession;
46
+ canProceed: boolean;
47
+ message: string;
48
+ nextSteps: string[];
49
+ }
50
+
51
+ /**
52
+ * Start a new wizard session
53
+ */
54
+ export async function startWizardSession(
55
+ url: string,
56
+ options: {
57
+ openaiApiKey?: string;
58
+ existingResponses?: WizardResponse[];
59
+ } = {}
60
+ ): Promise<WizardSession> {
61
+ // Crawl site first
62
+ console.log('🔍 Analyzing your site...');
63
+ const crawlResult = await crawlSite(url, { maxPages: 10 });
64
+
65
+ // Get AI summary if API key available
66
+ let siteSummary: SiteSummary;
67
+ if (options.openaiApiKey) {
68
+ siteSummary = await summarizeSite(crawlResult, {
69
+ openaiApiKey: options.openaiApiKey,
70
+ });
71
+ } else {
72
+ // Basic summary without AI
73
+ siteSummary = {
74
+ productName: crawlResult.domain,
75
+ productDescription: 'Unable to determine - AI analysis required',
76
+ targetAudience: 'Unknown',
77
+ keyFeatures: crawlResult.uniqueHeadings.slice(0, 5),
78
+ industry: 'Unknown',
79
+ businessModel: 'other',
80
+ valueProposition: '',
81
+ useCases: [],
82
+ problemsSolved: [],
83
+ suggestedSeedKeywords: [],
84
+ confidence: 0.2,
85
+ uncertainties: [
86
+ 'Product description needs user input',
87
+ 'Target audience is unknown',
88
+ 'Industry classification needed',
89
+ 'Value proposition unclear',
90
+ ],
91
+ };
92
+ }
93
+
94
+ // Generate questions based on uncertainty
95
+ const questions = generateWizardQuestions(siteSummary);
96
+
97
+ // Apply any existing responses
98
+ let responses: WizardResponse[] = [];
99
+ let currentIndex = 0;
100
+
101
+ if (options.existingResponses) {
102
+ responses = options.existingResponses;
103
+ currentIndex = responses.length;
104
+ }
105
+
106
+ return {
107
+ sessionId: `wizard_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
108
+ url,
109
+ siteSummary,
110
+ questions,
111
+ responses,
112
+ currentQuestionIndex: currentIndex,
113
+ isComplete: currentIndex >= questions.length,
114
+ finalConfidence: siteSummary.confidence,
115
+ };
116
+ }
117
+
118
+ /**
119
+ * Generate wizard questions based on site summary uncertainty
120
+ */
121
+ export function generateWizardQuestions(summary: SiteSummary): WizardQuestion[] {
122
+ const questions: WizardQuestion[] = [];
123
+
124
+ // Question 1: Product Description (if unclear)
125
+ if (summary.confidence < 0.8 || summary.productDescription.includes('Unable')) {
126
+ questions.push({
127
+ id: 'product_description',
128
+ question: 'What does your product/service do?',
129
+ description: 'Describe your product in 1-2 sentences',
130
+ type: 'text',
131
+ required: true,
132
+ impactOnConfidence: 0.25,
133
+ category: 'product',
134
+ });
135
+ }
136
+
137
+ // Question 2: Target Audience
138
+ if (summary.targetAudience === 'Unknown' || summary.confidence < 0.7) {
139
+ questions.push({
140
+ id: 'target_audience',
141
+ question: 'Who is your primary target customer?',
142
+ description: 'Select the option that best describes your ideal customer',
143
+ type: 'select',
144
+ options: [
145
+ { value: 'small_business', label: 'Small Businesses', description: '1-50 employees' },
146
+ { value: 'mid_market', label: 'Mid-Market Companies', description: '50-500 employees' },
147
+ { value: 'enterprise', label: 'Enterprise', description: '500+ employees' },
148
+ { value: 'developers', label: 'Developers/Technical Users', description: 'Individual devs or dev teams' },
149
+ { value: 'marketers', label: 'Marketing Teams', description: 'Marketing professionals' },
150
+ { value: 'consumers', label: 'Individual Consumers', description: 'B2C audience' },
151
+ { value: 'freelancers', label: 'Freelancers/Agencies', description: 'Independent professionals' },
152
+ { value: 'other', label: 'Other', description: 'Will specify below' },
153
+ ],
154
+ required: true,
155
+ impactOnConfidence: 0.2,
156
+ category: 'audience',
157
+ });
158
+ }
159
+
160
+ // Question 3: Industry/Category
161
+ if (summary.industry === 'Unknown') {
162
+ questions.push({
163
+ id: 'industry',
164
+ question: 'What industry or category is your product in?',
165
+ description: 'e.g., "Marketing Automation", "Project Management", "AI Tools"',
166
+ type: 'text',
167
+ required: true,
168
+ impactOnConfidence: 0.15,
169
+ category: 'product',
170
+ });
171
+ }
172
+
173
+ // Question 4: Main Problem Solved
174
+ if (summary.problemsSolved.length === 0) {
175
+ questions.push({
176
+ id: 'main_problem',
177
+ question: 'What is the main problem your product solves?',
178
+ description: 'Be specific about the pain point you address',
179
+ type: 'text',
180
+ required: true,
181
+ impactOnConfidence: 0.2,
182
+ category: 'product',
183
+ });
184
+ }
185
+
186
+ // Question 5: Competitors
187
+ questions.push({
188
+ id: 'competitors',
189
+ question: 'Who are your main competitors?',
190
+ description: 'List 2-5 competitors (comma-separated)',
191
+ type: 'text',
192
+ required: false,
193
+ impactOnConfidence: 0.1,
194
+ category: 'competition',
195
+ });
196
+
197
+ // Question 6: Differentiator
198
+ if (!summary.nicheFocus) {
199
+ questions.push({
200
+ id: 'differentiator',
201
+ question: 'What makes your product different from competitors?',
202
+ description: 'Your unique selling point or niche focus',
203
+ type: 'text',
204
+ required: false,
205
+ impactOnConfidence: 0.15,
206
+ category: 'competition',
207
+ });
208
+ }
209
+
210
+ // Question 7: Business Goal
211
+ questions.push({
212
+ id: 'business_goal',
213
+ question: 'What is your primary SEO goal?',
214
+ type: 'select',
215
+ options: [
216
+ { value: 'signups', label: 'Get More Signups/Trials', description: 'SaaS, apps, services' },
217
+ { value: 'leads', label: 'Generate Leads', description: 'Contact forms, demos' },
218
+ { value: 'traffic', label: 'Drive Organic Traffic', description: 'Content, ad revenue' },
219
+ { value: 'awareness', label: 'Build Brand Awareness', description: 'Thought leadership' },
220
+ { value: 'sales', label: 'Direct Sales', description: 'E-commerce, purchases' },
221
+ ],
222
+ required: true,
223
+ impactOnConfidence: 0.1,
224
+ category: 'goals',
225
+ });
226
+
227
+ // Question 8: Content Capacity
228
+ questions.push({
229
+ id: 'content_capacity',
230
+ question: 'How much content can you produce monthly?',
231
+ type: 'select',
232
+ options: [
233
+ { value: 'low', label: '1-2 pages/month', description: 'Limited time or resources' },
234
+ { value: 'medium', label: '3-5 pages/month', description: 'Moderate output' },
235
+ { value: 'high', label: '6+ pages/month', description: 'Dedicated content team' },
236
+ ],
237
+ required: true,
238
+ impactOnConfidence: 0.05,
239
+ category: 'constraints',
240
+ });
241
+
242
+ // Question 9: Domain Authority (self-assessment)
243
+ questions.push({
244
+ id: 'domain_authority',
245
+ question: 'How would you describe your website\'s current SEO standing?',
246
+ type: 'select',
247
+ options: [
248
+ { value: 'new', label: 'New Site', description: 'Less than 6 months old, few/no backlinks' },
249
+ { value: 'growing', label: 'Growing Site', description: '6-24 months, some backlinks' },
250
+ { value: 'established', label: 'Established Site', description: '2+ years, decent backlinks' },
251
+ { value: 'authority', label: 'Authority Site', description: 'Strong domain, many backlinks' },
252
+ ],
253
+ required: true,
254
+ impactOnConfidence: 0.05,
255
+ category: 'constraints',
256
+ });
257
+
258
+ // Sort by impact
259
+ return questions.sort((a, b) => b.impactOnConfidence - a.impactOnConfidence);
260
+ }
261
+
262
+ /**
263
+ * Process a wizard response and update session
264
+ */
265
+ export function processWizardResponse(
266
+ session: WizardSession,
267
+ response: WizardResponse
268
+ ): WizardSession {
269
+ // Add response
270
+ const responses = [...session.responses, response];
271
+
272
+ // Calculate new confidence
273
+ const question = session.questions.find((q) => q.id === response.questionId);
274
+ let confidenceBoost = question?.impactOnConfidence || 0;
275
+
276
+ // Reduce boost if user is unsure
277
+ if (response.confidence === 'unsure') {
278
+ confidenceBoost *= 0.5;
279
+ } else if (response.confidence === 'somewhat') {
280
+ confidenceBoost *= 0.75;
281
+ }
282
+
283
+ const newConfidence = Math.min(1, session.finalConfidence + confidenceBoost);
284
+
285
+ // Update current index
286
+ const currentIndex = session.currentQuestionIndex + 1;
287
+ const isComplete = currentIndex >= session.questions.length;
288
+
289
+ return {
290
+ ...session,
291
+ responses,
292
+ currentQuestionIndex: currentIndex,
293
+ isComplete,
294
+ finalConfidence: newConfidence,
295
+ };
296
+ }
297
+
298
+ /**
299
+ * Get the next question in the wizard
300
+ */
301
+ export function getNextQuestion(session: WizardSession): WizardQuestion | null {
302
+ if (session.isComplete) return null;
303
+ return session.questions[session.currentQuestionIndex] || null;
304
+ }
305
+
306
+ /**
307
+ * Skip to a specific question
308
+ */
309
+ export function skipToQuestion(session: WizardSession, questionId: string): WizardSession {
310
+ const index = session.questions.findIndex((q) => q.id === questionId);
311
+ if (index === -1) return session;
312
+
313
+ return {
314
+ ...session,
315
+ currentQuestionIndex: index,
316
+ };
317
+ }
318
+
319
+ /**
320
+ * Complete the wizard and get result
321
+ */
322
+ export function completeWizard(session: WizardSession): WizardResult {
323
+ const canProceed = session.finalConfidence >= 0.6;
324
+
325
+ let message: string;
326
+ let nextSteps: string[] = [];
327
+
328
+ if (canProceed) {
329
+ message = `✅ Confidence level: ${Math.round(session.finalConfidence * 100)}%. Ready to generate keyword recommendations.`;
330
+ nextSteps = [
331
+ 'Run keyword research with your responses',
332
+ 'Review and prioritize suggested keywords',
333
+ 'Start with low-difficulty, high-relevance keywords',
334
+ ];
335
+ } else {
336
+ message = `⚠️ Confidence level: ${Math.round(session.finalConfidence * 100)}%. Consider providing more details for better recommendations.`;
337
+ nextSteps = [
338
+ 'Answer any skipped questions',
339
+ 'Provide more specific details in text answers',
340
+ 'Run with lower confidence (results may be less accurate)',
341
+ ];
342
+ }
343
+
344
+ return {
345
+ session,
346
+ canProceed,
347
+ message,
348
+ nextSteps,
349
+ };
350
+ }
351
+
352
+ /**
353
+ * Convert wizard responses to keyword research context
354
+ */
355
+ export function wizardResponsesToContext(
356
+ session: WizardSession
357
+ ): {
358
+ productDescription?: string;
359
+ targetAudience?: string;
360
+ competitors?: string[];
361
+ mainProblem?: string;
362
+ differentiator?: string;
363
+ businessGoal?: string;
364
+ contentCapacity?: string;
365
+ domainAuthority?: string;
366
+ } {
367
+ const context: Record<string, any> = {};
368
+
369
+ for (const response of session.responses) {
370
+ const answer = Array.isArray(response.answer) ? response.answer.join(', ') : response.answer;
371
+
372
+ switch (response.questionId) {
373
+ case 'product_description':
374
+ context.productDescription = answer;
375
+ break;
376
+ case 'target_audience':
377
+ context.targetAudience = answer;
378
+ break;
379
+ case 'competitors':
380
+ context.competitors = answer.split(',').map((c: string) => c.trim()).filter(Boolean);
381
+ break;
382
+ case 'main_problem':
383
+ context.mainProblem = answer;
384
+ break;
385
+ case 'differentiator':
386
+ context.differentiator = answer;
387
+ break;
388
+ case 'business_goal':
389
+ context.businessGoal = answer;
390
+ break;
391
+ case 'content_capacity':
392
+ context.contentCapacity = answer;
393
+ break;
394
+ case 'domain_authority':
395
+ context.domainAuthority = answer;
396
+ break;
397
+ case 'industry':
398
+ context.industry = answer;
399
+ break;
400
+ }
401
+ }
402
+
403
+ return context;
404
+ }
405
+
406
+ /**
407
+ * Format wizard session for CLI output
408
+ */
409
+ export function formatWizardProgress(session: WizardSession): string {
410
+ const lines: string[] = [];
411
+
412
+ lines.push('');
413
+ lines.push('═'.repeat(60));
414
+ lines.push(' KEYWORD RESEARCH WIZARD');
415
+ lines.push('═'.repeat(60));
416
+ lines.push('');
417
+ lines.push(` Site: ${session.url}`);
418
+ lines.push(` Progress: ${session.currentQuestionIndex}/${session.questions.length} questions`);
419
+ lines.push(` Confidence: ${Math.round(session.finalConfidence * 100)}%`);
420
+ lines.push('');
421
+
422
+ // Progress bar
423
+ const progress = session.currentQuestionIndex / session.questions.length;
424
+ const filled = Math.round(progress * 40);
425
+ const empty = 40 - filled;
426
+ lines.push(` [${'█'.repeat(filled)}${'░'.repeat(empty)}]`);
427
+ lines.push('');
428
+
429
+ // Current question
430
+ const current = getNextQuestion(session);
431
+ if (current) {
432
+ lines.push('─'.repeat(60));
433
+ lines.push(` Question ${session.currentQuestionIndex + 1}:`);
434
+ lines.push(` ${current.question}`);
435
+ if (current.description) {
436
+ lines.push(` (${current.description})`);
437
+ }
438
+ lines.push('');
439
+
440
+ if (current.options) {
441
+ lines.push(' Options:');
442
+ current.options.forEach((opt, i) => {
443
+ lines.push(` ${i + 1}. ${opt.label}`);
444
+ if (opt.description) {
445
+ lines.push(` ${opt.description}`);
446
+ }
447
+ });
448
+ }
449
+ } else {
450
+ lines.push(' ✅ All questions answered!');
451
+ }
452
+
453
+ lines.push('');
454
+ lines.push('═'.repeat(60));
455
+
456
+ return lines.join('\n');
457
+ }
package/src/loader.ts ADDED
@@ -0,0 +1,40 @@
1
+ import { readFileSync, existsSync } from 'fs';
2
+ import { parse as parseYaml } from 'yaml';
3
+ import { join } from 'path';
4
+ import type { AgentDefinition } from './types.js';
5
+
6
+ export function loadAgent(agentPath: string): AgentDefinition {
7
+ if (!existsSync(agentPath)) {
8
+ throw new Error(`Agent file not found: ${agentPath}`);
9
+ }
10
+
11
+ const content = readFileSync(agentPath, 'utf-8');
12
+ const agent = parseYaml(content) as AgentDefinition;
13
+
14
+ // Validate required fields
15
+ if (!agent.name) throw new Error('Agent missing required field: name');
16
+ if (!agent.model) throw new Error('Agent missing required field: model');
17
+ if (!agent.system) throw new Error('Agent missing required field: system');
18
+ if (!agent.prompt) throw new Error('Agent missing required field: prompt');
19
+
20
+ // Set defaults
21
+ agent.temperature = agent.temperature ?? 0.1;
22
+ agent.max_tokens = agent.max_tokens ?? 4096;
23
+ agent.tools = agent.tools ?? [];
24
+
25
+ return agent;
26
+ }
27
+
28
+ export function loadAgentByName(name: string, agentsDir?: string): AgentDefinition {
29
+ const baseDir = agentsDir || join(process.cwd(), 'agents');
30
+ const agentPath = join(baseDir, `${name}.yaml`);
31
+ return loadAgent(agentPath);
32
+ }
33
+
34
+ export function interpolatePrompt(template: string, variables: Record<string, string>): string {
35
+ let result = template;
36
+ for (const [key, value] of Object.entries(variables)) {
37
+ result = result.replace(new RegExp(`\\{\\{\\s*${key}\\s*\\}\\}`, 'g'), value);
38
+ }
39
+ return result;
40
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Reports Module
3
+ *
4
+ * Generates HTML and PDF reports for SEO audits with white-label branding.
5
+ */
6
+
7
+ export * from './report-generator.js';