seomd-cli 1.3.0 → 2.0.0

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 (37) hide show
  1. package/PROVIDER_SPEC.md +125 -0
  2. package/README.md +54 -190
  3. package/SKILL.md +44 -0
  4. package/bin/seomd.js +78 -31
  5. package/package.json +11 -7
  6. package/src/commands/analyze.js +92 -92
  7. package/src/commands/check.js +301 -0
  8. package/src/commands/doctor.js +109 -0
  9. package/src/commands/generate.js +202 -0
  10. package/src/commands/init.js +127 -79
  11. package/src/commands/status.js +107 -79
  12. package/src/commands/sync.js +86 -72
  13. package/src/commands/validate.js +52 -25
  14. package/src/generators/directory.js +44 -143
  15. package/src/generators/reverse.js +46 -56
  16. package/src/generators/seomd.js +197 -44
  17. package/src/providers/http.js +67 -0
  18. package/src/providers/index.js +194 -0
  19. package/src/utils/agent-wiring.js +97 -0
  20. package/src/utils/api-client.js +14 -56
  21. package/src/utils/constants.js +110 -12
  22. package/src/utils/parser.js +114 -25
  23. package/src/utils/repo-scanner.js +207 -0
  24. package/src/utils/writeback.js +181 -100
  25. package/src/validators/seomd.js +255 -93
  26. package/scripts/release-contributors.js +0 -196
  27. package/scripts/release-notes.js +0 -194
  28. package/src/templates/blog/SEO.REVERSE.md +0 -176
  29. package/src/templates/blog/SEO.md +0 -348
  30. package/src/templates/ecommerce/SEO.REVERSE.md +0 -199
  31. package/src/templates/ecommerce/SEO.md +0 -354
  32. package/src/templates/local/SEO.REVERSE.md +0 -222
  33. package/src/templates/local/SEO.md +0 -360
  34. package/src/templates/marketplace/SEO.REVERSE.md +0 -222
  35. package/src/templates/marketplace/SEO.md +0 -360
  36. package/src/templates/saas/SEO.REVERSE.md +0 -268
  37. package/src/templates/saas/SEO.md +0 -372
@@ -1,79 +1,102 @@
1
1
  import chalk from 'chalk';
2
- import { parseSeoMd } from '../utils/parser.js';
2
+ import fs from 'fs-extra';
3
+ import path from 'path';
4
+ import YAML from 'yaml';
5
+ import { parseSeoMd, getBrand, getPages } from '../utils/parser.js';
6
+ import { INTENT_CATEGORIES } from '../utils/constants.js';
3
7
 
4
- export async function statusCommand(options) {
8
+ export async function statusCommand(options = {}) {
5
9
  try {
6
- const { data } = await parseSeoMd(process.cwd());
10
+ const cwd = process.cwd();
11
+ const { data } = await parseSeoMd(cwd);
7
12
 
8
- const aeoAnalysis = data.aeo?._analysis || {};
9
- const intentAnalysis = data.intent?._analysis || {};
10
- const pagesRequired = data.pages?.required || [];
11
- const pagesAnalysis = data.pages?._analysis?.pages || [];
13
+ let statusData = {};
14
+ const statusPath = path.join(cwd, '.seo', 'STATUS.yml');
15
+
16
+ if (await fs.pathExists(statusPath)) {
17
+ const content = await fs.readFile(statusPath, 'utf8');
18
+ statusData = YAML.parse(content) || {};
19
+ }
20
+
21
+ const aeoAnalysis = statusData.aeo || {};
22
+ const intentAnalysis = statusData.intent || {};
23
+ const declaredPages = getPages(data);
24
+ const pagesAnalysis = Array.isArray(statusData.pages?.pages) ? statusData.pages.pages : [];
25
+
26
+ // Combine declared pages + any ad-hoc analyzed pages not in SEO.md
27
+ const mergedPages = [...declaredPages];
28
+ const declaredIds = new Set(declaredPages.map((p) => p.id));
29
+ for (const analyzed of pagesAnalysis) {
30
+ if (analyzed?.id && !declaredIds.has(analyzed.id)) {
31
+ mergedPages.push({
32
+ id: analyzed.id,
33
+ url: analyzed.url || '/',
34
+ status: 'analyzed',
35
+ priority: 0,
36
+ });
37
+ }
38
+ }
39
+
40
+ const hasOverallData =
41
+ aeoAnalysis.overall_citation_rate !== null &&
42
+ aeoAnalysis.overall_citation_rate !== undefined;
12
43
 
13
- // Check if there is any analysis data
14
- const hasOverallData = aeoAnalysis.overall_citation_rate !== null && aeoAnalysis.overall_citation_rate !== undefined;
15
-
16
44
  if (!hasOverallData) {
17
45
  if (options.json) {
18
- console.log(JSON.stringify({ status: "no_data", message: "No analysis data found" }, null, 2));
46
+ console.log(JSON.stringify({ status: 'no_data', message: 'No analysis data found' }, null, 2));
19
47
  } else {
20
48
  console.log('');
21
- console.log(chalk.yellow('⚠ No analysis data found in SEO.md.'));
49
+ console.log(chalk.yellow('⚠ No analysis data found in .seo/STATUS.yml.'));
22
50
  console.log('');
23
- console.log('To populate analysis data:');
24
- console.log(` 1. Get an API key at ${chalk.cyan('https://seomd.dev/connect')}`);
25
- console.log(' 2. Add it to your .env file:');
51
+ console.log('To populate live citation data:');
52
+ console.log(' 1. Configure a compatible provider in `.env`:');
53
+ console.log(chalk.cyan(' SEOMD_PROVIDER=foxcite'));
26
54
  console.log(chalk.cyan(' SEOMD_API_KEY=your_key_here'));
27
- console.log(' 3. Run citation analysis:');
28
- console.log(chalk.white(' npx seomd analyze'));
55
+ console.log(' 2. Run citation analysis:');
56
+ console.log(chalk.white(' npx seomd-cli analyze'));
29
57
  console.log('');
30
58
  }
31
59
  process.exitCode = 0;
32
60
  return;
33
61
  }
34
62
 
35
- // Format overall metrics
36
- const overallCitation = formatPercentage(aeoAnalysis.overall_citation_rate);
37
- const overallGap = formatScore(aeoAnalysis.overall_gap_score);
38
-
39
63
  if (options.json) {
40
- // Output structured JSON
41
64
  const output = {
65
+ source: statusData.source || null,
42
66
  site: {
43
67
  type: data.site?.type || null,
44
68
  domain: data.site?.domain || null,
45
- brand: data.identity?.brand || null,
69
+ brand: getBrand(data),
46
70
  },
47
71
  overall: {
48
72
  citation_rate: aeoAnalysis.overall_citation_rate,
49
- gap_score: aeoAnalysis.overall_gap_score,
50
- last_analyzed: aeoAnalysis.last_analyzed || null,
73
+ gap_score: aeoAnalysis.overall_gap_score ?? null,
74
+ last_analyzed: statusData.last_analyzed || null,
51
75
  },
52
76
  intent: {},
53
- pages: []
77
+ pages: [],
54
78
  };
55
79
 
56
- const categories = ['informational', 'comparison', 'transactional', 'reputational', 'category'];
57
- categories.forEach(cat => {
80
+ INTENT_CATEGORIES.forEach((cat) => {
58
81
  const catData = intentAnalysis[cat] || {};
59
82
  const declared = data.intent?.[cat] || {};
60
83
  output.intent[cat] = {
61
- priority: declared.priority || null,
62
- citation_rate: catData.citation_rate || null,
63
- gap_score: catData.gap_score || null,
64
- trend: catData.trend || null
84
+ priority: declared.priority ?? null,
85
+ citation_rate: catData.citation_rate ?? null,
86
+ gap_score: catData.gap_score ?? null,
87
+ trend: catData.trend ?? null,
65
88
  };
66
89
  });
67
90
 
68
- pagesRequired.forEach(req => {
69
- const anal = pagesAnalysis.find(p => p.id === req.id) || {};
91
+ mergedPages.forEach((req) => {
92
+ const anal = pagesAnalysis.find((p) => p.id === req.id) || {};
70
93
  output.pages.push({
71
94
  id: req.id,
72
95
  url: req.url,
73
96
  status: req.status || 'planned',
74
- priority: req.priority || 0,
75
- citation_rate: anal.citation_rate !== undefined ? anal.citation_rate : null,
76
- gap_score: anal.gap_score !== undefined ? anal.gap_score : null,
97
+ priority: req.priority ?? 0,
98
+ citation_rate: anal.citation_rate ?? null,
99
+ gap_score: anal.gap_score ?? null,
77
100
  });
78
101
  });
79
102
 
@@ -82,40 +105,44 @@ export async function statusCommand(options) {
82
105
  return;
83
106
  }
84
107
 
85
- // Output beautiful terminal dashboard
108
+ const brand = getBrand(data);
109
+ const overallCitation = formatPercentage(aeoAnalysis.overall_citation_rate);
110
+ const overallGap = formatScore(aeoAnalysis.overall_gap_score);
111
+
86
112
  console.log('');
87
- console.log(chalk.bold('SEO.md Status Dashboard') + chalk.dim(` — ${data.identity?.brand || 'Brand'} (${data.site?.domain || 'domain'})`));
88
- console.log(chalk.dim(`Last analyzed: ${aeoAnalysis.last_analyzed || 'N/A'}`));
89
- console.log(chalk.dim('─'.repeat(60)));
90
-
91
- // Overall block
113
+ console.log(chalk.bold('SEO.md Status Dashboard') + chalk.dim(` — ${brand} (${data.site?.domain || 'domain'})`));
114
+ console.log(
115
+ chalk.dim(
116
+ `Source: ${statusData.source || 'unknown'} | Last analyzed: ${statusData.last_analyzed || 'N/A'}`
117
+ )
118
+ );
119
+ console.log(chalk.dim('─'.repeat(65)));
120
+
92
121
  console.log(`Overall Citation Rate: ${colorCitation(aeoAnalysis.overall_citation_rate, overallCitation)}`);
93
122
  console.log(`Overall Gap Score: ${colorGap(aeoAnalysis.overall_gap_score, overallGap)}`);
94
- console.log(chalk.dim('─'.repeat(60)));
123
+ console.log(chalk.dim('─'.repeat(65)));
95
124
 
96
- // Intent Categories Table
125
+ // Intent Categories Table (pad BEFORE applying ANSI color)
97
126
  console.log(chalk.bold('INTENT CATEGORY SUMMARY'));
98
127
  console.log('');
99
128
  console.log(formatRow('Category', 'Priority', 'Citation Rate', 'Gap Score', 'Trend'));
100
129
  console.log(chalk.dim('─'.repeat(65)));
101
130
 
102
- const categories = ['informational', 'comparison', 'transactional', 'reputational', 'category'];
103
- categories.forEach(cat => {
131
+ INTENT_CATEGORIES.forEach((cat) => {
104
132
  const declared = data.intent?.[cat] || {};
105
133
  const anal = intentAnalysis[cat] || {};
106
-
134
+
107
135
  const name = cat.charAt(0).toUpperCase() + cat.slice(1);
108
136
  const priority = declared.priority || 'medium';
109
- const citationVal = anal.citation_rate;
110
- const gapVal = anal.gap_score;
137
+ const rawCit = formatPercentage(anal.citation_rate).padEnd(13);
138
+ const rawGap = formatScore(anal.gap_score).padEnd(9);
111
139
  const trend = anal.trend || '-';
112
140
 
113
- const citationStr = colorCitation(citationVal, formatPercentage(citationVal));
114
- const gapStr = colorGap(gapVal, formatScore(gapVal));
115
-
116
- console.log(formatRow(name, priority, citationStr, gapStr, trend));
141
+ console.log(
142
+ `${name.padEnd(16)} │ ${priority.padEnd(10)} │ ${colorCitation(anal.citation_rate, rawCit)} │ ${colorGap(anal.gap_score, rawGap)} │ ${trend}`
143
+ );
117
144
  });
118
-
145
+
119
146
  console.log(chalk.dim('─'.repeat(65)));
120
147
  console.log('');
121
148
 
@@ -123,42 +150,43 @@ export async function statusCommand(options) {
123
150
  console.log(chalk.bold('PAGE ANALYSIS SUMMARY'));
124
151
  console.log('');
125
152
  console.log(formatRowPage('Page ID', 'URL', 'Status', 'Citation Rate', 'Gap Score'));
126
- console.log(chalk.dim('─'.repeat(70)));
127
-
128
- pagesRequired.forEach(req => {
129
- const anal = pagesAnalysis.find(p => p.id === req.id) || {};
130
-
131
- const id = req.id;
132
- const url = req.url;
133
- const status = req.status || 'planned';
134
- const citationVal = anal.citation_rate;
135
- const gapVal = anal.gap_score;
136
-
137
- const citationStr = colorCitation(citationVal, formatPercentage(citationVal));
138
- const gapStr = colorGap(gapVal, formatScore(gapVal));
139
-
140
- console.log(formatRowPage(id, url, status, citationStr, gapStr));
153
+ console.log(chalk.dim('─'.repeat(76)));
154
+
155
+ mergedPages.forEach((req) => {
156
+ const anal = pagesAnalysis.find((p) => p.id === req.id) || {};
157
+ const id = truncate(req.id, 16).padEnd(16);
158
+ const url = truncate(req.url, 22).padEnd(22);
159
+ const status = String(req.status || 'planned').padEnd(8);
160
+ const rawCit = formatPercentage(anal.citation_rate).padEnd(13);
161
+ const rawGap = formatScore(anal.gap_score).padEnd(9);
162
+
163
+ console.log(
164
+ `${id} │ ${url} │ ${status} │ ${colorCitation(anal.citation_rate, rawCit)} │ ${colorGap(anal.gap_score, rawGap)}`
165
+ );
141
166
  });
142
167
 
143
- console.log(chalk.dim('─'.repeat(70)));
168
+ console.log(chalk.dim('─'.repeat(76)));
144
169
  console.log('');
145
-
170
+ process.exitCode = 0;
146
171
  } catch (err) {
147
172
  console.log(chalk.red('✗ ') + chalk.bold('Failed to display status:'));
148
173
  console.log(` ${chalk.dim(err.message)}`);
149
174
  console.log('');
150
175
  process.exitCode = 1;
151
- return;
152
176
  }
153
177
  }
154
178
 
155
- // Helpers for string formatting/alignment
179
+ function truncate(str, max) {
180
+ const s = String(str || '');
181
+ return s.length > max ? `${s.slice(0, max - 1)}…` : s;
182
+ }
183
+
156
184
  function formatRow(cat, pri, cit, gap, trend) {
157
- return `${cat.padEnd(16)} │ ${pri.padEnd(10)} │ ${cit.padEnd(23)} │ ${gap.padEnd(19)} │ ${trend}`;
185
+ return `${cat.padEnd(16)} │ ${pri.padEnd(10)} │ ${cit.padEnd(13)} │ ${gap.padEnd(9)} │ ${trend}`;
158
186
  }
159
187
 
160
188
  function formatRowPage(id, url, status, cit, gap) {
161
- return `${id.padEnd(14)} │ ${url.padEnd(20)} │ ${status.padEnd(8)} │ ${cit.padEnd(23)} │ ${gap.padEnd(19)}`;
189
+ return `${id.padEnd(16)} │ ${url.padEnd(22)} │ ${status.padEnd(8)} │ ${cit.padEnd(13)} │ ${gap.padEnd(9)}`;
162
190
  }
163
191
 
164
192
  function formatPercentage(val) {
@@ -177,8 +205,8 @@ function formatScore(val) {
177
205
  function colorCitation(val, str) {
178
206
  if (val === null || val === undefined) return chalk.dim(str);
179
207
  const num = typeof val === 'number' ? val * 100 : parseFloat(val);
180
- if (isNaN(num)) return chalk.dim(str);
181
-
208
+ if (Number.isNaN(num)) return chalk.dim(str);
209
+
182
210
  if (num >= 20) return chalk.green.bold(str);
183
211
  if (num >= 5) return chalk.yellow.bold(str);
184
212
  return chalk.red.bold(str);
@@ -187,7 +215,7 @@ function colorCitation(val, str) {
187
215
  function colorGap(val, str) {
188
216
  if (val === null || val === undefined) return chalk.dim(str);
189
217
  const num = parseInt(val, 10);
190
- if (isNaN(num)) return chalk.dim(str);
218
+ if (Number.isNaN(num)) return chalk.dim(str);
191
219
 
192
220
  if (num < 30) return chalk.green.bold(str);
193
221
  if (num <= 70) return chalk.yellow.bold(str);
@@ -1,29 +1,13 @@
1
1
  import chalk from 'chalk';
2
2
  import ora from 'ora';
3
3
  import fs from 'fs-extra';
4
- import dotenv from 'dotenv';
5
- import { parseSeoMd } from '../utils/parser.js';
6
- import { client } from '../utils/api-client.js';
4
+ import path from 'path';
5
+ import YAML from 'yaml';
6
+ import { parseSeoMd, getBrand, getPages } from '../utils/parser.js';
7
+ import { resolveProvider } from '../providers/index.js';
7
8
  import { writeAnalysisToSeoMd, writeReverseMd, writePageAnalysis } from '../utils/writeback.js';
8
9
 
9
- dotenv.config();
10
-
11
- export async function syncCommand(options) {
12
- const apiKey = process.env.SEOMD_API_KEY;
13
- const paymentToken = process.env.SEOMD_PAYMENT_TOKEN;
14
-
15
- if (!apiKey && !paymentToken) {
16
- console.log('');
17
- console.log(chalk.yellow('⚠ No API key or payment token found.'));
18
- console.log('');
19
- console.log('Add your API key to .env:');
20
- console.log(chalk.cyan(' SEOMD_API_KEY=your_key_here'));
21
- console.log('');
22
- console.log('Get your API key at ' + chalk.cyan('https://seomd.dev/connect'));
23
- console.log('');
24
- process.exit(1);
25
- }
26
-
10
+ export async function syncCommand(options = {}) {
27
11
  const cwd = process.cwd();
28
12
  let doc, data;
29
13
 
@@ -32,91 +16,121 @@ export async function syncCommand(options) {
32
16
  doc = parsed.doc;
33
17
  data = parsed.data;
34
18
  } catch (err) {
35
- console.log(chalk.red(`\n❌ Error: ${err.message}`));
36
- process.exit(1);
19
+ console.log(chalk.red(`\n✗ Error: ${err.message}`));
20
+ process.exitCode = 1;
21
+ return;
22
+ }
23
+
24
+ const provider = resolveProvider(data);
25
+ if (!provider) {
26
+ console.log('');
27
+ console.log(chalk.yellow('⚠ No intelligence provider configured.'));
28
+ console.log('');
29
+ console.log('Set your provider credentials in `.env`:');
30
+ console.log(chalk.cyan(' SEOMD_PROVIDER=foxcite # or custom | semrush | ahrefs | profound | peec'));
31
+ console.log(chalk.cyan(' SEOMD_API_KEY=your_key_here'));
32
+ console.log('');
33
+ console.log('Provider protocol & compatible platforms: ' + chalk.cyan('https://seomd.dev/providers'));
34
+ console.log('');
35
+ process.exitCode = 1;
36
+ return;
37
37
  }
38
38
 
39
39
  const domain = data.site?.domain;
40
40
  if (!domain) {
41
- console.log(chalk.red('\n❌ Error: "site.domain" is required in SEO.md.'));
42
- process.exit(1);
41
+ console.log(chalk.red('\n✗ Error: "site.domain" is required in SEO.md.'));
42
+ process.exitCode = 1;
43
+ return;
43
44
  }
44
45
 
45
- // Extract pages
46
- let pagesList = [];
47
- if (data.pages) {
48
- if (Array.isArray(data.pages.required)) {
49
- pagesList = pagesList.concat(data.pages.required);
50
- }
51
- if (Array.isArray(data.pages.optional)) {
52
- pagesList = pagesList.concat(data.pages.optional);
53
- }
54
- }
46
+ const pagesList = getPages(data);
55
47
 
56
- console.log(chalk.bold.cyan(`\n🔄 foxcite: Syncing AI Search Audit for ${chalk.white(domain)}`));
57
- const spinner = ora('Fetching cached analysis from platform...').start();
48
+ console.log(chalk.bold.cyan(`\n🔄 ${provider.displayName}: Syncing AI Search Audit for ${chalk.white(domain)}`));
49
+ const spinner = ora('Fetching cached analysis from provider...').start();
58
50
 
59
51
  try {
60
- const pagesParam = JSON.stringify(pagesList.map(p => ({
61
- id: p.id,
62
- url: p.url,
63
- primary_keyword: p.primary_keyword
64
- })));
65
-
66
- const response = await client.get('/cli/sync', {
67
- params: { domain, pages: pagesParam }
68
- });
69
- const results = response.data;
52
+ const results = await provider.sync({ domain, pages: pagesList });
53
+ const aeo = results?.aeo_analysis || {};
70
54
 
71
55
  if (options.dryRun) {
72
56
  spinner.succeed(chalk.green('Sync check completed (Dry Run)!'));
73
57
  console.log('');
74
58
  console.log(chalk.bold('--- Dry-Run Updates Preview ---'));
75
- const aeo = results.aeo_analysis;
76
- console.log(`Overall Citation Rate : ${chalk.bold.green((aeo.overall_citation_rate * 100).toFixed(0) + '%')}`);
77
- console.log(`Overall Gap Score : ${chalk.bold.red(aeo.overall_gap_score)}`);
78
- console.log(`Last Analyzed : ${chalk.dim(aeo.last_analyzed)}`);
59
+
60
+ // Load previous STATUS.yml if available to show metric deltas
61
+ let prevAeo = {};
62
+ const statusPath = path.join(cwd, '.seo', 'STATUS.yml');
63
+ if (await fs.pathExists(statusPath)) {
64
+ try {
65
+ const prev = YAML.parse(await fs.readFile(statusPath, 'utf8')) || {};
66
+ prevAeo = prev.aeo || {};
67
+ } catch {
68
+ prevAeo = {};
69
+ }
70
+ }
71
+
72
+ if (typeof aeo.overall_citation_rate === 'number') {
73
+ const delta =
74
+ typeof prevAeo.overall_citation_rate === 'number'
75
+ ? ` (${formatDelta((aeo.overall_citation_rate - prevAeo.overall_citation_rate) * 100, '%')})`
76
+ : '';
77
+ console.log(
78
+ `Overall Citation Rate : ${chalk.bold.green((aeo.overall_citation_rate * 100).toFixed(0) + '%')}${chalk.dim(delta)}`
79
+ );
80
+ }
81
+ if (aeo.overall_gap_score !== undefined && aeo.overall_gap_score !== null) {
82
+ const delta =
83
+ typeof prevAeo.overall_gap_score === 'number'
84
+ ? ` (${formatDelta(aeo.overall_gap_score - prevAeo.overall_gap_score, '')})`
85
+ : '';
86
+ console.log(`Overall Gap Score : ${chalk.bold.red(aeo.overall_gap_score)}${chalk.dim(delta)}`);
87
+ }
88
+ console.log(`Pages in payload : ${Array.isArray(results?.page_analysis) ? results.page_analysis.length : 0}`);
89
+ console.log(`Last Analyzed : ${chalk.dim(aeo.last_analyzed || 'N/A')}`);
79
90
  console.log(chalk.yellow('\n⚠ Dry-run enabled: No files were modified.'));
80
91
  console.log('');
92
+ process.exitCode = 0;
81
93
  return;
82
94
  }
83
95
 
84
- spinner.text = 'Updating repository files...';
85
-
86
- // Writeback to SEO.md
87
- await writeAnalysisToSeoMd(doc, results, cwd);
88
-
89
- // Writeback to SEO.REVERSE.md
90
- const brandName = data.identity?.brand || 'My Brand';
91
- await writeReverseMd(cwd, results, domain, brandName);
96
+ spinner.text = 'Updating .seo/ workspace files...';
92
97
 
93
- // Writeback to .seo/pages/*.md
98
+ const brandName = getBrand(data);
99
+ await writeAnalysisToSeoMd(doc, results, cwd, { provider: provider.name });
100
+ await writeReverseMd(cwd, results, domain, brandName, { provider: provider.name });
94
101
  await writePageAnalysis(cwd, results);
95
102
 
96
103
  spinner.succeed(chalk.green('Sync completed successfully!'));
97
104
  console.log('');
98
105
 
99
- // Display results summary
100
- const aeo = results.aeo_analysis;
101
106
  console.log(chalk.bold('--- Sync Results Summary ---'));
102
- console.log(`Overall Citation Rate : ${chalk.bold.green((aeo.overall_citation_rate * 100).toFixed(0) + '%')}`);
103
- console.log(`Overall Gap Score : ${chalk.bold.red(aeo.overall_gap_score)}`);
104
-
105
- if (results.credits_remaining !== null) {
107
+ if (typeof aeo.overall_citation_rate === 'number') {
108
+ console.log(`Overall Citation Rate : ${chalk.bold.green((aeo.overall_citation_rate * 100).toFixed(0) + '%')}`);
109
+ }
110
+ if (aeo.overall_gap_score !== undefined && aeo.overall_gap_score !== null) {
111
+ console.log(`Overall Gap Score : ${chalk.bold.red(aeo.overall_gap_score)}`);
112
+ }
113
+ if (results?.credits_remaining !== null && results?.credits_remaining !== undefined) {
106
114
  console.log(`Credits Remaining : ${chalk.cyan(results.credits_remaining)}`);
107
115
  }
108
- console.log(`Last Analyzed : ${chalk.dim(aeo.last_analyzed)}`);
109
- console.log(`Next Analysis Target : ${chalk.dim(aeo.next_analysis)}`);
116
+ console.log(`Last Analyzed : ${chalk.dim(aeo.last_analyzed || 'N/A')}`);
117
+ console.log(`Next Analysis Target : ${chalk.dim(aeo.next_analysis || 'N/A')}`);
110
118
  console.log('----------------------------');
111
119
  console.log('');
112
- console.log(chalk.green('✔ SEO.md updated.'));
113
- console.log(chalk.green('✔ SEO.REVERSE.md updated.'));
120
+ console.log(chalk.green('✔ .seo/STATUS.yml updated.'));
121
+ console.log(chalk.green('✔ .seo/REVERSE.md updated.'));
114
122
  console.log(chalk.green('✔ .seo/pages/ playbooks synchronized.'));
115
123
  console.log('');
116
-
124
+ process.exitCode = 0;
117
125
  } catch (err) {
118
126
  spinner.fail(chalk.red('Sync failed'));
119
127
  console.error(chalk.bold.red(`\nError: ${err.message}`));
120
- process.exit(1);
128
+ process.exitCode = 1;
121
129
  }
122
130
  }
131
+
132
+ function formatDelta(diff, suffix) {
133
+ const rounded = Math.round(diff);
134
+ if (rounded === 0) return `no change`;
135
+ return `${rounded > 0 ? '+' : ''}${rounded}${suffix}`;
136
+ }
@@ -2,61 +2,88 @@ import chalk from 'chalk';
2
2
  import { parseSeoMd } from '../utils/parser.js';
3
3
  import { validateSeoMd } from '../validators/seomd.js';
4
4
 
5
- export async function validateCommand() {
6
- console.log('');
7
- console.log(chalk.bold('Validating SEO.md...') + '\n');
8
-
5
+ export async function validateCommand(options = {}) {
9
6
  try {
10
- const { data } = await parseSeoMd(process.cwd());
11
- const { errors, warnings } = validateSeoMd(data);
7
+ const { format, data, body } = await parseSeoMd(process.cwd());
8
+ const { errors, warnings, specVersion } = validateSeoMd(data, { format, body });
9
+ const failed = errors.length > 0 || (Boolean(options.strict) && warnings.length > 0);
10
+
11
+ if (options.json) {
12
+ console.log(
13
+ JSON.stringify(
14
+ {
15
+ valid: !failed,
16
+ format,
17
+ spec: specVersion,
18
+ errors,
19
+ warnings,
20
+ },
21
+ null,
22
+ 2
23
+ )
24
+ );
25
+ process.exitCode = failed ? 1 : 0;
26
+ return;
27
+ }
28
+
29
+ console.log('');
30
+ console.log(chalk.bold('Validating SEO.md...') + chalk.dim(` (format: ${format}, spec v${specVersion})\n`));
12
31
 
13
32
  if (errors.length === 0 && warnings.length === 0) {
14
- console.log(chalk.green(' ✓ ') + chalk.bold('SEO.md is fully compliant with spec v1.0!'));
33
+ console.log(chalk.green(' ✓ ') + chalk.bold(`SEO.md is fully compliant with spec v${specVersion}!`));
15
34
  console.log('');
16
35
  process.exitCode = 0;
17
36
  return;
18
37
  }
19
38
 
20
- // Print errors
21
39
  if (errors.length > 0) {
22
40
  console.log(chalk.red.bold(` Errors (${errors.length}):`));
23
- errors.forEach(err => {
41
+ errors.forEach((err) => {
24
42
  const pathStr = err.path ? chalk.dim(`[${err.path}]`) : '';
25
43
  console.log(` ${chalk.red('✗')} ${err.message} ${pathStr}`);
26
44
  });
27
45
  console.log('');
28
46
  }
29
47
 
30
- // Print warnings
31
48
  if (warnings.length > 0) {
32
49
  console.log(chalk.yellow.bold(` Warnings (${warnings.length}):`));
33
- warnings.forEach(warn => {
50
+ warnings.forEach((warn) => {
34
51
  const pathStr = warn.path ? chalk.dim(`[${warn.path}]`) : '';
35
52
  console.log(` ${chalk.yellow('⚠')} ${warn.message} ${pathStr}`);
36
53
  });
37
54
  console.log('');
38
55
  }
39
56
 
40
- // Final status report
41
- if (errors.length > 0) {
42
- console.log(chalk.red.bold(`✗ Validation failed: ${errors.length} error(s) and ${warnings.length} warning(s) found.`));
43
- console.log(chalk.dim('Please fix the errors to make your SEO.md valid.'));
57
+ if (failed) {
58
+ console.log(
59
+ chalk.red.bold(
60
+ `✗ Validation failed: ${errors.length} error(s) and ${warnings.length} warning(s) found.`
61
+ )
62
+ );
63
+ console.log(
64
+ chalk.dim(
65
+ options.strict && errors.length === 0
66
+ ? 'Strict mode is enabled: resolve warnings to pass.'
67
+ : 'Please fix the errors to make your SEO.md valid.'
68
+ )
69
+ );
44
70
  console.log('');
45
71
  process.exitCode = 1;
46
72
  return;
47
- } else {
48
- console.log(chalk.yellow.bold(`✓ Validation passed with ${warnings.length} warning(s).`));
49
- console.log(chalk.dim('Warnings are optional recommendations and do not block compliance.'));
50
- console.log('');
51
- process.exitCode = 0;
52
- return;
53
73
  }
54
74
 
55
- } catch (err) {
56
- console.log(chalk.red('✗ ') + chalk.bold('Validation process failed:'));
57
- console.log(` ${chalk.dim(err.message)}`);
75
+ console.log(chalk.yellow.bold(`✓ Validation passed with ${warnings.length} warning(s).`));
76
+ console.log(chalk.dim('Warnings are optional recommendations and do not block compliance.'));
58
77
  console.log('');
78
+ process.exitCode = 0;
79
+ } catch (err) {
80
+ if (options.json) {
81
+ console.log(JSON.stringify({ valid: false, errors: [{ path: '', message: err.message }], warnings: [] }, null, 2));
82
+ } else {
83
+ console.log(chalk.red('✗ ') + chalk.bold('Validation process failed:'));
84
+ console.log(` ${chalk.dim(err.message)}`);
85
+ console.log('');
86
+ }
59
87
  process.exitCode = 1;
60
- return;
61
88
  }
62
89
  }