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
@@ -0,0 +1,202 @@
1
+ import chalk from 'chalk';
2
+ import fs from 'fs-extra';
3
+ import path from 'path';
4
+ import { parseSeoMd, getBrand, getPages } from '../utils/parser.js';
5
+ import { AI_BOTS, SCHEMA_TYPES } from '../utils/constants.js';
6
+
7
+ const VALID_TARGETS = ['robots', 'llms', 'schema'];
8
+
9
+ export function buildRobotsTxt(data) {
10
+ const domain = data.site?.domain || 'example.com';
11
+ const canonical = (data.site?.canonical || `https://${domain}`).replace(/\/$/, '');
12
+ const crawl = data.crawl || {};
13
+ const allowAi = crawl.allow_ai_bots !== false;
14
+ const disallow = Array.isArray(crawl.disallow) ? crawl.disallow : ['/admin', '/api/*'];
15
+ const sitemap = crawl.sitemap || '/sitemap.xml';
16
+
17
+ const lines = [
18
+ `# robots.txt generated from SEO.md — https://seomd.dev`,
19
+ '',
20
+ 'User-agent: *',
21
+ 'Allow: /',
22
+ ...disallow.map((d) => `Disallow: ${d}`),
23
+ '',
24
+ ];
25
+
26
+ if (allowAi) {
27
+ lines.push('# AI Search & Citation Crawlers');
28
+ for (const bot of AI_BOTS) {
29
+ lines.push(`User-agent: ${bot.userAgent}`);
30
+ lines.push(`Allow: ${bot.allow}`);
31
+ lines.push('');
32
+ }
33
+ }
34
+
35
+ lines.push(`Sitemap: ${sitemap.startsWith('http') ? sitemap : `${canonical}${sitemap}`}`);
36
+ lines.push('');
37
+
38
+ return lines.join('\n');
39
+ }
40
+
41
+ export function buildLlmsTxt(data, body = '') {
42
+ const brand = getBrand(data);
43
+ const domain = data.site?.domain || 'example.com';
44
+ const canonical = (data.site?.canonical || `https://${domain}`).replace(/\/$/, '');
45
+ const primaryKeyword = data.keywords?.primary || '';
46
+ const pages = getPages(data);
47
+
48
+ // Extract one-liner from Markdown body if present
49
+ const oneLinerMatch = body.match(/\*\*One-liner:\*\*\s*(.+)/i);
50
+ const summary = oneLinerMatch
51
+ ? oneLinerMatch[1].trim()
52
+ : `${brand} (${domain}) — ${primaryKeyword || 'official documentation and product pages'}.`;
53
+
54
+ const lines = [
55
+ `# ${brand}`,
56
+ '',
57
+ `> ${summary}`,
58
+ '',
59
+ '## Key Pages',
60
+ '',
61
+ ];
62
+
63
+ const concretePages = pages.filter((p) => p.url && !p.url.includes('['));
64
+ if (concretePages.length > 0) {
65
+ for (const page of concretePages) {
66
+ const fullUrl = `${canonical}${page.url === '/' ? '' : page.url}`;
67
+ const label = page.primary_keyword ? `${page.id} — ${page.primary_keyword}` : page.id;
68
+ lines.push(`- [${label}](${fullUrl})`);
69
+ }
70
+ } else {
71
+ lines.push(`- [Homepage](${canonical})`);
72
+ }
73
+
74
+ const secondary = Array.isArray(data.keywords?.secondary) ? data.keywords.secondary : [];
75
+ if (primaryKeyword || secondary.length > 0) {
76
+ lines.push('');
77
+ lines.push('## Topics');
78
+ lines.push('');
79
+ if (primaryKeyword) lines.push(`- ${primaryKeyword}`);
80
+ for (const kw of secondary) {
81
+ lines.push(`- ${kw}`);
82
+ }
83
+ }
84
+
85
+ lines.push('');
86
+ return lines.join('\n');
87
+ }
88
+
89
+ export function buildSchemaJsonLd(data) {
90
+ const brand = getBrand(data);
91
+ const domain = data.site?.domain || 'example.com';
92
+ const canonical = (data.site?.canonical || `https://${domain}`).replace(/\/$/, '');
93
+ const siteType = data.site?.type || 'saas';
94
+ const types = Array.isArray(data.schema?.types) && data.schema.types.length > 0
95
+ ? data.schema.types
96
+ : (SCHEMA_TYPES[siteType] || SCHEMA_TYPES.saas);
97
+
98
+ const graph = [];
99
+
100
+ if (types.includes('Organization')) {
101
+ graph.push({
102
+ '@type': 'Organization',
103
+ name: brand,
104
+ url: canonical,
105
+ });
106
+ }
107
+
108
+ if (types.includes('SoftwareApplication')) {
109
+ graph.push({
110
+ '@type': 'SoftwareApplication',
111
+ name: brand,
112
+ applicationCategory: 'BusinessApplication',
113
+ url: canonical,
114
+ });
115
+ }
116
+
117
+ if (types.includes('LocalBusiness')) {
118
+ graph.push({
119
+ '@type': 'LocalBusiness',
120
+ name: brand,
121
+ url: canonical,
122
+ });
123
+ }
124
+
125
+ if (types.includes('WebSite')) {
126
+ graph.push({
127
+ '@type': 'WebSite',
128
+ name: brand,
129
+ url: canonical,
130
+ });
131
+ }
132
+
133
+ if (types.includes('FAQPage')) {
134
+ graph.push({
135
+ '@type': 'FAQPage',
136
+ mainEntity: [
137
+ {
138
+ '@type': 'Question',
139
+ name: `What is ${brand}?`,
140
+ acceptedAnswer: {
141
+ '@type': 'Answer',
142
+ text: `Replace with a concise 40-60 word answer about ${brand}.`,
143
+ },
144
+ },
145
+ ],
146
+ });
147
+ }
148
+
149
+ if (graph.length === 0) {
150
+ graph.push({
151
+ '@type': 'WebPage',
152
+ name: brand,
153
+ url: canonical,
154
+ });
155
+ }
156
+
157
+ return JSON.stringify(
158
+ {
159
+ '@context': 'https://schema.org',
160
+ '@graph': graph,
161
+ },
162
+ null,
163
+ 2
164
+ ) + '\n';
165
+ }
166
+
167
+ export async function generateCommand(target, options = {}) {
168
+ const normalizedTarget = String(target || '').trim().toLowerCase();
169
+
170
+ if (!VALID_TARGETS.includes(normalizedTarget)) {
171
+ console.log(chalk.red(`✗ Unknown generate target '${target}'. Valid targets: ${VALID_TARGETS.join(', ')}`));
172
+ process.exitCode = 1;
173
+ return;
174
+ }
175
+
176
+ try {
177
+ const cwd = process.cwd();
178
+ const { data, body } = await parseSeoMd(cwd);
179
+
180
+ let output = '';
181
+ if (normalizedTarget === 'robots') {
182
+ output = buildRobotsTxt(data);
183
+ } else if (normalizedTarget === 'llms') {
184
+ output = buildLlmsTxt(data, body);
185
+ } else if (normalizedTarget === 'schema') {
186
+ output = buildSchemaJsonLd(data);
187
+ }
188
+
189
+ if (options.out) {
190
+ const outPath = path.resolve(cwd, options.out);
191
+ await fs.ensureDir(path.dirname(outPath));
192
+ await fs.writeFile(outPath, output, 'utf8');
193
+ console.log(chalk.green(`✓ Generated ${normalizedTarget} -> ${path.relative(cwd, outPath) || outPath}`));
194
+ } else {
195
+ process.stdout.write(output);
196
+ }
197
+ process.exitCode = 0;
198
+ } catch (err) {
199
+ console.log(chalk.red(`✗ Generate failed: ${err.message}`));
200
+ process.exitCode = 1;
201
+ }
202
+ }
@@ -1,102 +1,148 @@
1
1
  import chalk from 'chalk';
2
2
  import enquirer from 'enquirer';
3
- const { prompt } = enquirer;
4
3
  import ora from 'ora';
5
4
  import fs from 'fs-extra';
6
5
  import path from 'path';
7
- import { generateSeoMd } from '../generators/seomd.js';
6
+ import { readFileSync } from 'fs';
7
+ import { fileURLToPath } from 'url';
8
+ import { generateSeoMd, normalizeDomain } from '../generators/seomd.js';
8
9
  import { generateReverseMd } from '../generators/reverse.js';
9
10
  import { createSeomdDir } from '../generators/directory.js';
10
- import { SITE_TYPES } from '../utils/constants.js';
11
+ import { scanRepo } from '../utils/repo-scanner.js';
12
+ import { wireAgentFiles } from '../utils/agent-wiring.js';
13
+ import { SITE_TYPES, VALID_SITE_TYPES, SITE_TYPE_PROFILES } from '../utils/constants.js';
14
+
15
+ const { prompt } = enquirer;
16
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
17
+ const pkg = JSON.parse(readFileSync(path.join(__dirname, '../../package.json'), 'utf8'));
11
18
 
12
- export async function initCommand(options) {
19
+ export async function initCommand(options = {}) {
13
20
  console.log('');
14
- console.log(chalk.bold('SEO.md') + chalk.dim(' v0.1.0 — https://seomd.dev'));
21
+ console.log(chalk.bold('SEO.md') + chalk.dim(` v${pkg.version} — https://seomd.dev`));
15
22
  console.log('');
16
- console.log(chalk.dim('The open standard for AI-era SEO configuration.'));
23
+ console.log(chalk.dim('The open standard for AI-era search & citation configuration.'));
17
24
  console.log('');
18
25
 
26
+ // Validate --type upfront before touching the filesystem
27
+ if (options.type && !VALID_SITE_TYPES.includes(options.type)) {
28
+ console.log(
29
+ chalk.red(`Invalid --type '${options.type}'. Must be one of: ${VALID_SITE_TYPES.join(', ')}`)
30
+ );
31
+ process.exitCode = 1;
32
+ return;
33
+ }
34
+
19
35
  // Determine target directory
20
36
  let workingDir = process.cwd();
21
37
  if (options.output) {
22
38
  const resolved = path.resolve(options.output);
23
- if (await fs.pathExists(resolved) && (await fs.readdir(resolved)).length > 0) {
39
+ if ((await fs.pathExists(resolved)) && (await fs.readdir(resolved)).length > 0) {
24
40
  console.log(chalk.red(`Output directory must be empty or non-existent: ${resolved}`));
25
- process.exit(1);
41
+ process.exitCode = 1;
42
+ return;
26
43
  }
27
44
  await fs.ensureDir(resolved);
28
45
  workingDir = resolved;
29
46
  }
30
47
 
48
+ // Non-interactive if -y OR any config flag provided
49
+ const hasConfigFlags =
50
+ options.brand !== undefined ||
51
+ options.domain !== undefined ||
52
+ options.primaryKeyword !== undefined ||
53
+ options.competitors !== undefined;
54
+ const isNonInteractive = Boolean(options.yes || hasConfigFlags);
55
+
31
56
  const seomdPath = path.join(workingDir, 'SEO.md');
32
57
  if (await fs.pathExists(seomdPath)) {
33
- console.log(chalk.yellow('⚠ SEO.md already exists in this directory.'));
34
- const { overwrite } = await prompt({
35
- type: 'confirm',
36
- name: 'overwrite',
37
- message: 'Overwrite existing SEO.md?',
38
- initial: false,
39
- });
40
- if (!overwrite) {
41
- console.log(chalk.dim('Aborted.'));
42
- process.exit(0);
58
+ if (!isNonInteractive && !options.force) {
59
+ console.log(chalk.yellow('⚠ SEO.md already exists in this directory.'));
60
+ const { overwrite } = await prompt({
61
+ type: 'confirm',
62
+ name: 'overwrite',
63
+ message: 'Overwrite existing SEO.md?',
64
+ initial: false,
65
+ });
66
+ if (!overwrite) {
67
+ console.log(chalk.dim('Aborted.'));
68
+ process.exitCode = 0;
69
+ return;
70
+ }
43
71
  }
44
72
  }
45
73
 
46
- let answers;
74
+ // Inspect repository for framework, existing routes, and crawl files
75
+ const repoInfo = await scanRepo(workingDir);
76
+ if (repoInfo.framework || repoInfo.routes.length > 0) {
77
+ const fwLabel = repoInfo.framework ? ` (${repoInfo.framework})` : '';
78
+ console.log(
79
+ chalk.dim(
80
+ `Detected project${fwLabel}: ${repoInfo.routes.length} route(s) discovered`
81
+ )
82
+ );
83
+ console.log('');
84
+ }
47
85
 
48
- // Mode 5: non-interactive if -y OR any config field provided
49
- const hasConfigFlags =
50
- options.brand !== undefined ||
51
- options.domain !== undefined ||
52
- options.primaryKeyword !== undefined ||
53
- options.competitors !== undefined;
86
+ const inferredBrand = repoInfo.packageName
87
+ ? repoInfo.packageName.replace(/^@[^/]+\//, '').replace(/[-_]+/g, ' ')
88
+ : 'My Brand';
89
+ const inferredDomain = repoInfo.homepage
90
+ ? normalizeDomain(repoInfo.homepage)
91
+ : 'example.com';
54
92
 
55
- if (options.yes || hasConfigFlags) {
93
+ let answers;
94
+ if (isNonInteractive) {
95
+ const siteType = options.type || 'saas';
96
+ const profile = SITE_TYPE_PROFILES[siteType];
56
97
  answers = {
57
- site_type: options.type || 'saas',
58
- domain: options.domain || 'example.com',
59
- brand: options.brand || 'My Brand',
60
- primary_keyword: options.primaryKeyword || '',
98
+ site_type: siteType,
99
+ domain: normalizeDomain(options.domain || inferredDomain),
100
+ brand: (options.brand || inferredBrand).trim(),
101
+ primary_keyword: (options.primaryKeyword || profile.defaultKeyword).trim(),
61
102
  competitors: options.competitors
62
103
  ? options.competitors
63
104
  .split(',')
64
- .map((c) => c.trim())
105
+ .map((c) => normalizeDomain(c))
65
106
  .filter(Boolean)
66
- .slice(0, 3)
107
+ .slice(0, 5)
67
108
  : [],
109
+ provider: options.provider || null,
68
110
  };
69
111
  } else {
70
- // The 5-question init flow
112
+ const initialTypeIdx = options.type
113
+ ? Math.max(0, SITE_TYPES.findIndex((t) => t.value === options.type))
114
+ : 0;
115
+
71
116
  answers = await prompt([
72
117
  {
73
118
  type: 'select',
74
119
  name: 'site_type',
75
120
  message: 'Site type:',
76
- choices: SITE_TYPES.map(t => ({ name: t.value, message: t.name })),
77
- initial: options.type ? SITE_TYPES.findIndex(t => t.value === options.type) : 0,
121
+ choices: SITE_TYPES.map((t) => ({ name: t.value, message: t.name })),
122
+ initial: initialTypeIdx,
78
123
  },
79
124
  {
80
125
  type: 'input',
81
126
  name: 'domain',
82
127
  message: 'Primary domain:',
128
+ initial: inferredDomain !== 'example.com' ? inferredDomain : undefined,
83
129
  hint: 'e.g. myapp.com',
84
130
  validate(value) {
85
- if (!value) return 'Domain is required';
86
- // Strip protocol if provided
131
+ if (!value || !value.trim()) return 'Domain is required';
87
132
  return true;
88
133
  },
89
134
  result(value) {
90
- return value.replace(/^https?:\/\//, '').replace(/\/$/, '');
135
+ return normalizeDomain(value);
91
136
  },
92
137
  },
93
138
  {
94
139
  type: 'input',
95
140
  name: 'brand',
96
141
  message: 'Brand name:',
142
+ initial: inferredBrand !== 'My Brand' ? inferredBrand : undefined,
97
143
  hint: 'e.g. MyApp',
98
144
  validate(value) {
99
- if (!value) return 'Brand name is required';
145
+ if (!value || !value.trim()) return 'Brand name is required';
100
146
  return true;
101
147
  },
102
148
  },
@@ -106,64 +152,79 @@ export async function initCommand(options) {
106
152
  message: 'Primary keyword:',
107
153
  hint: 'e.g. project management software',
108
154
  validate(value) {
109
- if (!value) return 'Primary keyword is required';
155
+ if (!value || !value.trim()) return 'Primary keyword is required';
110
156
  return true;
111
157
  },
112
158
  },
113
159
  {
114
160
  type: 'input',
115
161
  name: 'competitors',
116
- message: 'Top 3 competitors (comma separated):',
162
+ message: 'Top competitors (comma separated, optional):',
117
163
  hint: 'e.g. asana.com, monday.com, notion.so',
118
164
  result(value) {
119
- return value
165
+ return String(value || '')
120
166
  .split(',')
121
- .map(c => c.trim())
167
+ .map((c) => normalizeDomain(c))
122
168
  .filter(Boolean)
123
- .slice(0, 3);
169
+ .slice(0, 5);
124
170
  },
125
171
  },
126
172
  ]);
173
+ answers.provider = options.provider || null;
127
174
  }
128
175
 
129
176
  console.log('');
130
- const spinner = ora('Scaffolding your SEO.md files...').start();
177
+ const spinner = ora('Scaffolding your SEO.md workspace...').start();
131
178
 
132
179
  try {
133
- // 1. Generate SEO.md
134
- const seomdContent = generateSeoMd(answers);
180
+ // 1. Generate v2 SEO.md (YAML frontmatter + Markdown body)
181
+ const seomdContent = generateSeoMd(answers, repoInfo);
135
182
  await fs.writeFile(path.join(workingDir, 'SEO.md'), seomdContent, 'utf8');
136
- spinner.succeed(chalk.green('SEO.md created'));
183
+ spinner.succeed(chalk.green('SEO.md created (spec v2.0.0)'));
137
184
 
138
- // 2. Create .seo/ directory structure
185
+ // 2. Create .seo/ workspace directory
139
186
  await createSeomdDir(workingDir, answers);
140
- spinner.succeed(chalk.green('.seo/ directory created'));
187
+ spinner.succeed(chalk.green('.seo/ workspace created'));
141
188
 
142
- // 3. Generate .seo/REVERSE.md
189
+ // 3. Initialize .seo/REVERSE.md
143
190
  const reverseContent = generateReverseMd(answers);
144
191
  await fs.writeFile(path.join(workingDir, '.seo', 'REVERSE.md'), reverseContent, 'utf8');
145
192
  spinner.succeed(chalk.green('.seo/REVERSE.md initialized'));
146
193
 
147
-
194
+ // 4. Wire AGENTS.md / CLAUDE.md unless opted out via --no-wire-agents
195
+ let agentResult = { updated: [], created: [] };
196
+ if (options.wireAgents !== false) {
197
+ agentResult = await wireAgentFiles(workingDir);
198
+ const wiredList = [...agentResult.created, ...agentResult.updated];
199
+ if (wiredList.length > 0) {
200
+ spinner.succeed(chalk.green(`Agent instructions wired into ${wiredList.join(', ')}`));
201
+ }
202
+ }
148
203
 
149
204
  console.log('');
150
205
  console.log(chalk.bold.green('✓ SEO.md initialized successfully'));
151
206
  console.log('');
152
- console.log(chalk.dim('Files created:'));
153
- console.log(' ' + chalk.cyan('SEO.md') + chalk.dim(' — your living SEO config'));
154
- console.log(' ' + chalk.cyan('.seo/REVERSE.md') + chalk.dim(' — reverse engineer output (platform generated)'));
155
- console.log(' ' + chalk.cyan('.seo/') + chalk.dim(' — intelligence directory'));
207
+ console.log(chalk.dim('Files created / updated:'));
208
+ console.log(' ' + chalk.cyan('SEO.md') + chalk.dim(' — your Markdown + frontmatter SEO/AEO spec'));
209
+ console.log(' ' + chalk.cyan('.seo/REVERSE.md') + chalk.dim(' — competitor intelligence scaffold'));
210
+ console.log(' ' + chalk.cyan('.seo/') + chalk.dim(' — provider intelligence workspace'));
211
+ for (const f of [...agentResult.created, ...agentResult.updated]) {
212
+ console.log(' ' + chalk.cyan(f.padEnd(18)) + chalk.dim(' — wired so coding agents auto-read SEO.md'));
213
+ }
156
214
  console.log('');
157
- console.log(chalk.dim('Next steps:'));
158
- console.log(' ' + chalk.white('npx seomd analyze') + chalk.dim(' — run your first citation analysis'));
159
- console.log(' ' + chalk.white('npx seomd status') + chalk.dim(' — view current gap scores'));
215
+ console.log(chalk.dim('Next steps (works locally with zero API key):'));
216
+ console.log(' ' + chalk.white('npx seomd-cli validate') + chalk.dim(' — validate SEO.md'));
217
+ console.log(' ' + chalk.white('npx seomd-cli check ./public') + chalk.dim(' — audit local files / localhost against SEO.md'));
218
+ console.log(' ' + chalk.white('npx seomd-cli generate robots') + chalk.dim(' — generate AI-bot-friendly robots.txt or llms.txt'));
219
+ console.log(' ' + chalk.white('npx seomd-cli doctor') + chalk.dim(' — inspect repo & provider readiness'));
160
220
  console.log('');
161
- console.log(chalk.dim('Connect your platform at ') + chalk.cyan('https://seomd.dev/connect'));
221
+ console.log(chalk.dim('Optional live AI citation scans (any compatible provider — see PROVIDER_SPEC.md):'));
222
+ console.log(' ' + chalk.white('npx seomd-cli analyze') + chalk.dim(' — run live multi-LLM citation analysis'));
162
223
  console.log('');
163
-
224
+ process.exitCode = 0;
164
225
  } catch (err) {
165
226
  spinner.fail(chalk.red('Failed to scaffold SEO.md'));
166
227
  console.error(chalk.dim(err.message));
167
- process.exit(1);
228
+ process.exitCode = 1;
168
229
  }
169
230
  }