seomd-cli 1.4.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 +90 -90
  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 +123 -62
  11. package/src/commands/status.js +92 -76
  12. package/src/commands/sync.js +84 -70
  13. package/src/commands/validate.js +52 -25
  14. package/src/generators/directory.js +43 -110
  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 +171 -82
  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 -233
  30. package/src/templates/ecommerce/SEO.REVERSE.md +0 -199
  31. package/src/templates/ecommerce/SEO.md +0 -239
  32. package/src/templates/local/SEO.REVERSE.md +0 -222
  33. package/src/templates/local/SEO.md +0 -245
  34. package/src/templates/marketplace/SEO.REVERSE.md +0 -222
  35. package/src/templates/marketplace/SEO.md +0 -245
  36. package/src/templates/saas/SEO.REVERSE.md +0 -268
  37. package/src/templates/saas/SEO.md +0 -257
@@ -2,16 +2,17 @@ import chalk from 'chalk';
2
2
  import fs from 'fs-extra';
3
3
  import path from 'path';
4
4
  import YAML from 'yaml';
5
- import { parseSeoMd } from '../utils/parser.js';
5
+ import { parseSeoMd, getBrand, getPages } from '../utils/parser.js';
6
+ import { INTENT_CATEGORIES } from '../utils/constants.js';
6
7
 
7
- export async function statusCommand(options) {
8
+ export async function statusCommand(options = {}) {
8
9
  try {
9
10
  const cwd = process.cwd();
10
11
  const { data } = await parseSeoMd(cwd);
11
-
12
+
12
13
  let statusData = {};
13
14
  const statusPath = path.join(cwd, '.seo', 'STATUS.yml');
14
-
15
+
15
16
  if (await fs.pathExists(statusPath)) {
16
17
  const content = await fs.readFile(statusPath, 'utf8');
17
18
  statusData = YAML.parse(content) || {};
@@ -19,73 +20,83 @@ export async function statusCommand(options) {
19
20
 
20
21
  const aeoAnalysis = statusData.aeo || {};
21
22
  const intentAnalysis = statusData.intent || {};
22
- const pagesRequired = data.pages?.required || [];
23
- const pagesAnalysis = statusData.pages?.pages || [];
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;
24
43
 
25
- // Check if there is any analysis data
26
- const hasOverallData = aeoAnalysis.overall_citation_rate !== null && aeoAnalysis.overall_citation_rate !== undefined;
27
-
28
44
  if (!hasOverallData) {
29
45
  if (options.json) {
30
- 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));
31
47
  } else {
32
48
  console.log('');
33
49
  console.log(chalk.yellow('⚠ No analysis data found in .seo/STATUS.yml.'));
34
50
  console.log('');
35
- console.log('To populate analysis data:');
36
- console.log(` 1. Get an API key at ${chalk.cyan('https://seomd.dev/connect')}`);
37
- 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'));
38
54
  console.log(chalk.cyan(' SEOMD_API_KEY=your_key_here'));
39
- console.log(' 3. Run citation analysis:');
40
- console.log(chalk.white(' npx seomd analyze'));
55
+ console.log(' 2. Run citation analysis:');
56
+ console.log(chalk.white(' npx seomd-cli analyze'));
41
57
  console.log('');
42
58
  }
43
59
  process.exitCode = 0;
44
60
  return;
45
61
  }
46
62
 
47
- // Format overall metrics
48
- const overallCitation = formatPercentage(aeoAnalysis.overall_citation_rate);
49
- const overallGap = formatScore(aeoAnalysis.overall_gap_score);
50
-
51
63
  if (options.json) {
52
- // Output structured JSON
53
64
  const output = {
65
+ source: statusData.source || null,
54
66
  site: {
55
67
  type: data.site?.type || null,
56
68
  domain: data.site?.domain || null,
57
- brand: data.identity?.brand || null,
69
+ brand: getBrand(data),
58
70
  },
59
71
  overall: {
60
72
  citation_rate: aeoAnalysis.overall_citation_rate,
61
- gap_score: aeoAnalysis.overall_gap_score,
73
+ gap_score: aeoAnalysis.overall_gap_score ?? null,
62
74
  last_analyzed: statusData.last_analyzed || null,
63
75
  },
64
76
  intent: {},
65
- pages: []
77
+ pages: [],
66
78
  };
67
79
 
68
- const categories = ['informational', 'comparison', 'transactional', 'reputational', 'category'];
69
- categories.forEach(cat => {
80
+ INTENT_CATEGORIES.forEach((cat) => {
70
81
  const catData = intentAnalysis[cat] || {};
71
82
  const declared = data.intent?.[cat] || {};
72
83
  output.intent[cat] = {
73
- priority: declared.priority || null,
74
- citation_rate: catData.citation_rate || null,
75
- gap_score: catData.gap_score || null,
76
- 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,
77
88
  };
78
89
  });
79
90
 
80
- pagesRequired.forEach(req => {
81
- const anal = pagesAnalysis.find(p => p.id === req.id) || {};
91
+ mergedPages.forEach((req) => {
92
+ const anal = pagesAnalysis.find((p) => p.id === req.id) || {};
82
93
  output.pages.push({
83
94
  id: req.id,
84
95
  url: req.url,
85
96
  status: req.status || 'planned',
86
- priority: req.priority || 0,
87
- citation_rate: anal.citation_rate !== undefined ? anal.citation_rate : null,
88
- 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,
89
100
  });
90
101
  });
91
102
 
@@ -94,40 +105,44 @@ export async function statusCommand(options) {
94
105
  return;
95
106
  }
96
107
 
97
- // 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
+
98
112
  console.log('');
99
- console.log(chalk.bold('SEO.md Status Dashboard') + chalk.dim(` — ${data.identity?.brand || 'Brand'} (${data.site?.domain || 'domain'})`));
100
- console.log(chalk.dim(`Last analyzed: ${statusData.last_analyzed || 'N/A'}`));
101
- console.log(chalk.dim('─'.repeat(60)));
102
-
103
- // 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
+
104
121
  console.log(`Overall Citation Rate: ${colorCitation(aeoAnalysis.overall_citation_rate, overallCitation)}`);
105
122
  console.log(`Overall Gap Score: ${colorGap(aeoAnalysis.overall_gap_score, overallGap)}`);
106
- console.log(chalk.dim('─'.repeat(60)));
123
+ console.log(chalk.dim('─'.repeat(65)));
107
124
 
108
- // Intent Categories Table
125
+ // Intent Categories Table (pad BEFORE applying ANSI color)
109
126
  console.log(chalk.bold('INTENT CATEGORY SUMMARY'));
110
127
  console.log('');
111
128
  console.log(formatRow('Category', 'Priority', 'Citation Rate', 'Gap Score', 'Trend'));
112
129
  console.log(chalk.dim('─'.repeat(65)));
113
130
 
114
- const categories = ['informational', 'comparison', 'transactional', 'reputational', 'category'];
115
- categories.forEach(cat => {
131
+ INTENT_CATEGORIES.forEach((cat) => {
116
132
  const declared = data.intent?.[cat] || {};
117
133
  const anal = intentAnalysis[cat] || {};
118
-
134
+
119
135
  const name = cat.charAt(0).toUpperCase() + cat.slice(1);
120
136
  const priority = declared.priority || 'medium';
121
- const citationVal = anal.citation_rate;
122
- const gapVal = anal.gap_score;
137
+ const rawCit = formatPercentage(anal.citation_rate).padEnd(13);
138
+ const rawGap = formatScore(anal.gap_score).padEnd(9);
123
139
  const trend = anal.trend || '-';
124
140
 
125
- const citationStr = colorCitation(citationVal, formatPercentage(citationVal));
126
- const gapStr = colorGap(gapVal, formatScore(gapVal));
127
-
128
- 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
+ );
129
144
  });
130
-
145
+
131
146
  console.log(chalk.dim('─'.repeat(65)));
132
147
  console.log('');
133
148
 
@@ -135,42 +150,43 @@ export async function statusCommand(options) {
135
150
  console.log(chalk.bold('PAGE ANALYSIS SUMMARY'));
136
151
  console.log('');
137
152
  console.log(formatRowPage('Page ID', 'URL', 'Status', 'Citation Rate', 'Gap Score'));
138
- console.log(chalk.dim('─'.repeat(70)));
139
-
140
- pagesRequired.forEach(req => {
141
- const anal = pagesAnalysis.find(p => p.id === req.id) || {};
142
-
143
- const id = req.id;
144
- const url = req.url;
145
- const status = req.status || 'planned';
146
- const citationVal = anal.citation_rate;
147
- const gapVal = anal.gap_score;
148
-
149
- const citationStr = colorCitation(citationVal, formatPercentage(citationVal));
150
- const gapStr = colorGap(gapVal, formatScore(gapVal));
151
-
152
- 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
+ );
153
166
  });
154
167
 
155
- console.log(chalk.dim('─'.repeat(70)));
168
+ console.log(chalk.dim('─'.repeat(76)));
156
169
  console.log('');
157
-
170
+ process.exitCode = 0;
158
171
  } catch (err) {
159
172
  console.log(chalk.red('✗ ') + chalk.bold('Failed to display status:'));
160
173
  console.log(` ${chalk.dim(err.message)}`);
161
174
  console.log('');
162
175
  process.exitCode = 1;
163
- return;
164
176
  }
165
177
  }
166
178
 
167
- // 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
+
168
184
  function formatRow(cat, pri, cit, gap, trend) {
169
- 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}`;
170
186
  }
171
187
 
172
188
  function formatRowPage(id, url, status, cit, gap) {
173
- 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)}`;
174
190
  }
175
191
 
176
192
  function formatPercentage(val) {
@@ -189,8 +205,8 @@ function formatScore(val) {
189
205
  function colorCitation(val, str) {
190
206
  if (val === null || val === undefined) return chalk.dim(str);
191
207
  const num = typeof val === 'number' ? val * 100 : parseFloat(val);
192
- if (isNaN(num)) return chalk.dim(str);
193
-
208
+ if (Number.isNaN(num)) return chalk.dim(str);
209
+
194
210
  if (num >= 20) return chalk.green.bold(str);
195
211
  if (num >= 5) return chalk.yellow.bold(str);
196
212
  return chalk.red.bold(str);
@@ -199,7 +215,7 @@ function colorCitation(val, str) {
199
215
  function colorGap(val, str) {
200
216
  if (val === null || val === undefined) return chalk.dim(str);
201
217
  const num = parseInt(val, 10);
202
- if (isNaN(num)) return chalk.dim(str);
218
+ if (Number.isNaN(num)) return chalk.dim(str);
203
219
 
204
220
  if (num < 30) return chalk.green.bold(str);
205
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/STATUS.yml
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
120
  console.log(chalk.green('✔ .seo/STATUS.yml updated.'));
113
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
  }