seomd-cli 1.4.0 → 2.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 (39) 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 +79 -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 +215 -0
  10. package/src/commands/init.js +170 -66
  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 +46 -114
  15. package/src/generators/reverse.js +46 -56
  16. package/src/generators/seomd.js +226 -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/migrate.js +99 -0
  23. package/src/utils/parser.js +114 -25
  24. package/src/utils/placeholders.js +31 -0
  25. package/src/utils/repo-scanner.js +207 -0
  26. package/src/utils/writeback.js +171 -82
  27. package/src/validators/seomd.js +263 -93
  28. package/scripts/release-contributors.js +0 -196
  29. package/scripts/release-notes.js +0 -194
  30. package/src/templates/blog/SEO.REVERSE.md +0 -176
  31. package/src/templates/blog/SEO.md +0 -233
  32. package/src/templates/ecommerce/SEO.REVERSE.md +0 -199
  33. package/src/templates/ecommerce/SEO.md +0 -239
  34. package/src/templates/local/SEO.REVERSE.md +0 -222
  35. package/src/templates/local/SEO.md +0 -245
  36. package/src/templates/marketplace/SEO.REVERSE.md +0 -222
  37. package/src/templates/marketplace/SEO.md +0 -245
  38. package/src/templates/saas/SEO.REVERSE.md +0 -268
  39. package/src/templates/saas/SEO.md +0 -257
@@ -1,21 +1,237 @@
1
- import { SITE_TYPES, INTENT_CATEGORIES } from '../utils/constants.js';
1
+ import { findPlaceholders } from '../utils/placeholders.js';
2
+ import {
3
+ VALID_SITE_TYPES,
4
+ INTENT_CATEGORIES,
5
+ VALID_PRIORITIES,
6
+ VALID_PAGE_STATUSES,
7
+ } from '../utils/constants.js';
2
8
 
3
9
  /**
4
- * Validates a parsed seo.md configuration object against the spec.
5
- *
6
- * @param {any} data - The parsed seo.md JS object
7
- * @returns {{errors: Array<{path: string, message: string}>, warnings: Array<{path: string, message: string}>}} Validation results
10
+ * Validates a parsed SEO.md configuration object against spec v2.0 (or legacy v1.0).
11
+ *
12
+ * @param {any} data - Parsed YAML data (frontmatter in v2, full doc in v1)
13
+ * @param {{ format?: 'v2'|'v1', body?: string }} [meta] - Optional parser metadata
14
+ * @returns {{ errors: Array<{path: string, message: string}>, warnings: Array<{path: string, message: string}>, specVersion: string }}
8
15
  */
9
- export function validateSeoMd(data) {
16
+ export function validateSeoMd(data, meta = {}) {
10
17
  const errors = [];
11
18
  const warnings = [];
12
19
 
13
20
  if (!data || typeof data !== 'object') {
14
21
  errors.push({ path: '', message: 'Specification must be a valid YAML object' });
15
- return { errors, warnings };
22
+ return { errors, warnings, specVersion: 'unknown' };
16
23
  }
17
24
 
18
- // 1. Required top-level sections
25
+ const isV2 =
26
+ meta.format === 'v2' ||
27
+ (typeof data.spec === 'string' && data.spec.startsWith('2')) ||
28
+ Array.isArray(data.pages);
29
+
30
+ if (isV2) {
31
+ validateV2(data, meta.body || '', errors, warnings);
32
+ return { errors, warnings, specVersion: String(data.spec || '2.0.0') };
33
+ }
34
+
35
+ validateV1(data, errors, warnings);
36
+ return { errors, warnings, specVersion: '1.0' };
37
+ }
38
+
39
+ function validatePageEntry(page, prefix, seenIds, errors) {
40
+ if (!page || typeof page !== 'object') {
41
+ errors.push({ path: prefix, message: `Page entry at ${prefix} must be an object` });
42
+ return;
43
+ }
44
+
45
+ if (!page.id || typeof page.id !== 'string') {
46
+ errors.push({ path: `${prefix}.id`, message: `Page at ${prefix} is missing a valid 'id'` });
47
+ } else if (seenIds.has(page.id)) {
48
+ errors.push({ path: `${prefix}.id`, message: `Duplicate page id '${page.id}'` });
49
+ } else {
50
+ seenIds.add(page.id);
51
+ }
52
+
53
+ if (!page.url || typeof page.url !== 'string') {
54
+ errors.push({ path: `${prefix}.url`, message: `Page '${page.id || prefix}' is missing 'url'` });
55
+ } else if (!page.url.startsWith('/')) {
56
+ errors.push({ path: `${prefix}.url`, message: `Page '${page.id || prefix}' url '${page.url}' must start with '/'` });
57
+ }
58
+
59
+ if (!page.status) {
60
+ errors.push({ path: `${prefix}.status`, message: `Page '${page.id || prefix}' is missing 'status'` });
61
+ } else if (!VALID_PAGE_STATUSES.includes(page.status)) {
62
+ errors.push({
63
+ path: `${prefix}.status`,
64
+ message: `Invalid status '${page.status}' for page '${page.id || prefix}'. Must be one of: ${VALID_PAGE_STATUSES.join(', ')}`,
65
+ });
66
+ }
67
+
68
+ if (page.priority === undefined || page.priority === null) {
69
+ errors.push({ path: `${prefix}.priority`, message: `Page '${page.id || prefix}' is missing 'priority'` });
70
+ } else if (typeof page.priority !== 'number') {
71
+ errors.push({ path: `${prefix}.priority`, message: `Priority for page '${page.id || prefix}' must be a number` });
72
+ }
73
+ }
74
+
75
+ function validateDomain(domain, errors, warnings) {
76
+ if (!domain) {
77
+ errors.push({ path: 'site.domain', message: 'site.domain is required' });
78
+ } else if (typeof domain !== 'string') {
79
+ errors.push({ path: 'site.domain', message: 'site.domain must be a string' });
80
+ } else if (/^https?:\/\//i.test(domain) || domain.includes('/')) {
81
+ warnings.push({
82
+ path: 'site.domain',
83
+ message: `site.domain '${domain}' should be a bare hostname (e.g. 'example.com') without protocol or path`,
84
+ });
85
+ }
86
+ }
87
+
88
+ function validateCanonical(canonical, errors) {
89
+ if (canonical === undefined || canonical === null) return;
90
+ if (typeof canonical !== 'string') {
91
+ errors.push({ path: 'site.canonical', message: 'site.canonical must be a string' });
92
+ } else if (!/^https?:\/\/.+/i.test(canonical)) {
93
+ errors.push({ path: 'site.canonical', message: `site.canonical '${canonical}' must be a full http(s) URL` });
94
+ }
95
+ }
96
+
97
+ function validateV2(data, body, errors, warnings) {
98
+ if (!data.spec) {
99
+ warnings.push({ path: 'spec', message: "Missing 'spec' version field in frontmatter (recommended: '2.0.0')" });
100
+ }
101
+
102
+ // 1. Required top-level keys
103
+ for (const section of ['site', 'keywords', 'pages']) {
104
+ if (!(section in data) || data[section] === null || data[section] === undefined) {
105
+ errors.push({ path: section, message: `Missing required frontmatter section: '${section}'` });
106
+ }
107
+ }
108
+
109
+ if (errors.some((e) => ['site', 'keywords', 'pages'].includes(e.path))) {
110
+ return;
111
+ }
112
+
113
+ // 2. site
114
+ const site = data.site;
115
+ if (typeof site !== 'object') {
116
+ errors.push({ path: 'site', message: 'site must be an object' });
117
+ } else {
118
+ const brand = site.brand || data.identity?.brand;
119
+ if (!brand || typeof brand !== 'string') {
120
+ errors.push({ path: 'site.brand', message: 'site.brand is required' });
121
+ }
122
+
123
+ if (!site.type) {
124
+ errors.push({ path: 'site.type', message: 'site.type is required' });
125
+ } else if (!VALID_SITE_TYPES.includes(site.type)) {
126
+ errors.push({
127
+ path: 'site.type',
128
+ message: `Invalid site.type '${site.type}'. Must be one of: ${VALID_SITE_TYPES.join(', ')}`,
129
+ });
130
+ }
131
+
132
+ validateDomain(site.domain, errors, warnings);
133
+ validateCanonical(site.canonical, errors);
134
+ }
135
+
136
+ // 3. keywords
137
+ const keywords = data.keywords;
138
+ if (typeof keywords !== 'object') {
139
+ errors.push({ path: 'keywords', message: 'keywords must be an object' });
140
+ } else {
141
+ if (!keywords.primary || typeof keywords.primary !== 'string' || !keywords.primary.trim()) {
142
+ errors.push({ path: 'keywords.primary', message: 'keywords.primary is required' });
143
+ }
144
+ if (keywords.secondary !== undefined && !Array.isArray(keywords.secondary)) {
145
+ errors.push({ path: 'keywords.secondary', message: 'keywords.secondary must be an array' });
146
+ } else if (!keywords.secondary || keywords.secondary.length === 0) {
147
+ warnings.push({ path: 'keywords.secondary', message: 'keywords.secondary is empty. Consider adding secondary terms.' });
148
+ }
149
+ if (keywords.negative !== undefined && !Array.isArray(keywords.negative)) {
150
+ errors.push({ path: 'keywords.negative', message: 'keywords.negative must be an array' });
151
+ }
152
+ }
153
+
154
+ // 4. pages
155
+ const seenIds = new Set();
156
+ if (!Array.isArray(data.pages)) {
157
+ errors.push({ path: 'pages', message: 'pages must be an array in spec v2' });
158
+ } else if (data.pages.length === 0) {
159
+ errors.push({ path: 'pages', message: 'pages array cannot be empty' });
160
+ } else {
161
+ data.pages.forEach((page, index) => {
162
+ validatePageEntry(page, `pages[${index}]`, seenIds, errors);
163
+ });
164
+ }
165
+
166
+ // 5. intent (optional in v2, validated if present)
167
+ if (data.intent !== undefined && data.intent !== null) {
168
+ if (typeof data.intent !== 'object') {
169
+ errors.push({ path: 'intent', message: 'intent must be an object' });
170
+ } else {
171
+ for (const [cat, catData] of Object.entries(data.intent)) {
172
+ if (cat === '_analysis') continue;
173
+ if (!INTENT_CATEGORIES.includes(cat)) {
174
+ warnings.push({
175
+ path: `intent.${cat}`,
176
+ message: `Unrecognized intent category '${cat}'. Standard categories: ${INTENT_CATEGORIES.join(', ')}`,
177
+ });
178
+ }
179
+ if (!catData || typeof catData !== 'object') {
180
+ errors.push({ path: `intent.${cat}`, message: `intent.${cat} must be an object` });
181
+ continue;
182
+ }
183
+ if (catData.priority && !VALID_PRIORITIES.includes(String(catData.priority).toLowerCase())) {
184
+ errors.push({
185
+ path: `intent.${cat}.priority`,
186
+ message: `Invalid priority '${catData.priority}' for intent.${cat}. Must be one of: ${VALID_PRIORITIES.join(', ')}`,
187
+ });
188
+ }
189
+ if (catData.queries !== undefined && !Array.isArray(catData.queries)) {
190
+ errors.push({ path: `intent.${cat}.queries`, message: `intent.${cat}.queries must be an array` });
191
+ } else if (!catData.queries || catData.queries.length === 0) {
192
+ warnings.push({ path: `intent.${cat}.queries`, message: `intent.${cat}.queries is empty.` });
193
+ }
194
+ }
195
+ }
196
+ }
197
+
198
+ // 6. crawl (optional)
199
+ if (data.crawl && typeof data.crawl === 'object') {
200
+ const robots = data.crawl.robots ?? data.crawl.robots_txt;
201
+ if (robots !== undefined && robots !== null && typeof robots !== 'string') {
202
+ errors.push({ path: 'crawl.robots', message: 'crawl.robots must be a string' });
203
+ }
204
+ if (data.crawl.sitemap !== undefined && data.crawl.sitemap !== null && typeof data.crawl.sitemap !== 'string') {
205
+ errors.push({ path: 'crawl.sitemap', message: 'crawl.sitemap must be a string' });
206
+ }
207
+ if (data.crawl.llms_txt !== undefined && data.crawl.llms_txt !== null && typeof data.crawl.llms_txt !== 'string') {
208
+ errors.push({ path: 'crawl.llms_txt', message: 'crawl.llms_txt must be a string' });
209
+ }
210
+ }
211
+
212
+ // 7. provider (optional)
213
+ const provider = data.provider || data.platform || {};
214
+ if (provider.endpoint && typeof provider.endpoint === 'string' && !/^https?:\/\/.+/i.test(provider.endpoint)) {
215
+ errors.push({ path: 'provider.endpoint', message: 'provider.endpoint must be a valid http(s) URL' });
216
+ }
217
+
218
+ // 8. Markdown body check
219
+ const placeholders = findPlaceholders(body);
220
+ if (placeholders.length > 0) {
221
+ warnings.push({
222
+ path: 'body',
223
+ message: `Canonical Product Facts still have template text: ${placeholders.join(', ')}. Coding agents and generated llms.txt/JSON-LD need real facts.`,
224
+ });
225
+ }
226
+ if (!body || body.trim().length < 20) {
227
+ warnings.push({
228
+ path: 'body',
229
+ message: 'Markdown body is empty or very short. Add canonical product facts and agent rules so coding agents can act on SEO.md.',
230
+ });
231
+ }
232
+ }
233
+
234
+ function validateV1(data, errors, warnings) {
19
235
  const requiredSections = [
20
236
  'site',
21
237
  'identity',
@@ -25,7 +241,7 @@ export function validateSeoMd(data) {
25
241
  'schema',
26
242
  'crawl',
27
243
  'performance',
28
- 'monitoring'
244
+ 'monitoring',
29
245
  ];
30
246
 
31
247
  for (const section of requiredSections) {
@@ -34,67 +250,52 @@ export function validateSeoMd(data) {
34
250
  }
35
251
  }
36
252
 
37
- // If critical sections are missing, stop early to avoid nested property access errors
38
- if (errors.some(e => ['site', 'identity', 'keywords', 'intent', 'pages'].includes(e.path))) {
39
- return { errors, warnings };
253
+ if (errors.some((e) => ['site', 'identity', 'keywords', 'intent', 'pages'].includes(e.path))) {
254
+ return;
40
255
  }
41
256
 
42
- // 2. Validate 'site' section
257
+ // site
43
258
  const site = data.site || {};
44
- const validSiteTypes = SITE_TYPES.map(t => t.value);
45
-
46
259
  if (!site.type) {
47
260
  errors.push({ path: 'site.type', message: 'site.type is required' });
48
- } else if (!validSiteTypes.includes(site.type)) {
49
- errors.push({
50
- path: 'site.type',
51
- message: `Invalid site.type '${site.type}'. Must be one of: ${validSiteTypes.join(', ')}`
261
+ } else if (!VALID_SITE_TYPES.includes(site.type)) {
262
+ errors.push({
263
+ path: 'site.type',
264
+ message: `Invalid site.type '${site.type}'. Must be one of: ${VALID_SITE_TYPES.join(', ')}`,
52
265
  });
53
266
  }
267
+ validateDomain(site.domain, errors, warnings);
268
+ validateCanonical(site.canonical, errors);
54
269
 
55
- if (!site.domain) {
56
- errors.push({ path: 'site.domain', message: 'site.domain is required' });
57
- } else if (typeof site.domain !== 'string') {
58
- errors.push({ path: 'site.domain', message: 'site.domain must be a string' });
59
- }
60
-
61
- if (site.canonical && typeof site.canonical !== 'string') {
62
- errors.push({ path: 'site.canonical', message: 'site.canonical must be a string' });
63
- }
64
-
65
- // 3. Validate 'identity' section
270
+ // identity
66
271
  const identity = data.identity || {};
67
272
  if (!identity.brand) {
68
273
  errors.push({ path: 'identity.brand', message: 'identity.brand is required' });
69
274
  } else if (typeof identity.brand !== 'string') {
70
275
  errors.push({ path: 'identity.brand', message: 'identity.brand must be a string' });
71
276
  }
72
-
73
277
  if (!identity.tagline) {
74
278
  warnings.push({ path: 'identity.tagline', message: 'identity.tagline is missing or empty' });
75
279
  }
76
280
 
77
- // 4. Validate 'keywords' section
281
+ // keywords
78
282
  const keywords = data.keywords || {};
79
283
  if (!keywords.primary) {
80
284
  errors.push({ path: 'keywords.primary', message: 'keywords.primary is required' });
81
285
  } else if (typeof keywords.primary !== 'string') {
82
286
  errors.push({ path: 'keywords.primary', message: 'keywords.primary must be a string' });
83
287
  }
84
-
85
288
  if (!keywords.secondary || !Array.isArray(keywords.secondary) || keywords.secondary.length === 0) {
86
289
  warnings.push({ path: 'keywords.secondary', message: 'keywords.secondary is empty. Consider adding target secondary terms.' });
87
290
  }
88
-
89
291
  if (!keywords.negative || !Array.isArray(keywords.negative)) {
90
292
  warnings.push({ path: 'keywords.negative', message: 'keywords.negative should be an array of terms to filter out' });
91
293
  }
92
-
93
294
  if (!keywords.long_tail || !Array.isArray(keywords.long_tail) || keywords.long_tail.length === 0) {
94
295
  warnings.push({ path: 'keywords.long_tail', message: 'keywords.long_tail is empty. Consider adding long-tail variations.' });
95
296
  }
96
297
 
97
- // 5. Validate 'intent' section
298
+ // intent
98
299
  const intent = data.intent || {};
99
300
  for (const cat of INTENT_CATEGORIES) {
100
301
  const catData = intent[cat];
@@ -102,17 +303,14 @@ export function validateSeoMd(data) {
102
303
  errors.push({ path: `intent.${cat}`, message: `Missing or invalid intent category: 'intent.${cat}'` });
103
304
  continue;
104
305
  }
105
-
106
- const validPriorities = ['low', 'medium', 'high', 'critical'];
107
306
  if (!catData.priority) {
108
307
  errors.push({ path: `intent.${cat}.priority`, message: `intent.${cat}.priority is required` });
109
- } else if (!validPriorities.includes(String(catData.priority).toLowerCase())) {
110
- errors.push({
111
- path: `intent.${cat}.priority`,
112
- message: `Invalid priority '${catData.priority}' for intent.${cat}. Must be one of: ${validPriorities.join(', ')}`
308
+ } else if (!VALID_PRIORITIES.includes(String(catData.priority).toLowerCase())) {
309
+ errors.push({
310
+ path: `intent.${cat}.priority`,
311
+ message: `Invalid priority '${catData.priority}' for intent.${cat}. Must be one of: ${VALID_PRIORITIES.join(', ')}`,
113
312
  });
114
313
  }
115
-
116
314
  if (!catData.queries || !Array.isArray(catData.queries)) {
117
315
  errors.push({ path: `intent.${cat}.queries`, message: `intent.${cat}.queries must be an array` });
118
316
  } else if (catData.queries.length === 0) {
@@ -120,52 +318,31 @@ export function validateSeoMd(data) {
120
318
  }
121
319
  }
122
320
 
123
- // 6. Validate 'pages' section
321
+ // pages
124
322
  const pages = data.pages || {};
323
+ const seenIds = new Set();
125
324
  if (!pages.required || !Array.isArray(pages.required)) {
126
325
  errors.push({ path: 'pages.required', message: 'pages.required must be an array' });
127
326
  } else if (pages.required.length === 0) {
128
327
  errors.push({ path: 'pages.required', message: 'pages.required array cannot be empty' });
129
328
  } else {
130
329
  pages.required.forEach((page, index) => {
131
- const prefix = `pages.required[${index}]`;
132
- if (!page || typeof page !== 'object') {
133
- errors.push({ path: prefix, message: `Page entry at index ${index} must be an object` });
134
- return;
135
- }
136
-
137
- if (!page.id) {
138
- errors.push({ path: `${prefix}.id`, message: `Page at index ${index} is missing 'id'` });
139
- }
140
- if (!page.url) {
141
- errors.push({ path: `${prefix}.url`, message: `Page '${page.id || index}' is missing 'url'` });
142
- }
143
-
144
- const validStatus = ['live', 'draft', 'planned'];
145
- if (!page.status) {
146
- errors.push({ path: `${prefix}.status`, message: `Page '${page.id || index}' is missing 'status'` });
147
- } else if (!validStatus.includes(page.status)) {
148
- errors.push({
149
- path: `${prefix}.status`,
150
- message: `Invalid status '${page.status}' for page '${page.id || index}'. Must be one of: ${validStatus.join(', ')}`
151
- });
152
- }
153
-
154
- if (page.priority === undefined || page.priority === null) {
155
- errors.push({ path: `${prefix}.priority`, message: `Page '${page.id || index}' is missing 'priority'` });
156
- } else if (typeof page.priority !== 'number') {
157
- errors.push({ path: `${prefix}.priority`, message: `Priority for page '${page.id || index}' must be a number` });
158
- }
330
+ validatePageEntry(page, `pages.required[${index}]`, seenIds, errors);
331
+ });
332
+ }
333
+ if (Array.isArray(pages.optional)) {
334
+ pages.optional.forEach((page, index) => {
335
+ validatePageEntry(page, `pages.optional[${index}]`, seenIds, errors);
159
336
  });
160
337
  }
161
338
 
162
- // 7. Validate 'schema' section
339
+ // schema
163
340
  const schema = data.schema || {};
164
341
  if (schema.types && !Array.isArray(schema.types)) {
165
342
  errors.push({ path: 'schema.types', message: 'schema.types must be an array' });
166
343
  }
167
344
 
168
- // 8. Validate 'crawl' section
345
+ // crawl
169
346
  const crawl = data.crawl || {};
170
347
  if (crawl.sitemap && typeof crawl.sitemap !== 'string') {
171
348
  errors.push({ path: 'crawl.sitemap', message: 'crawl.sitemap must be a string' });
@@ -174,38 +351,31 @@ export function validateSeoMd(data) {
174
351
  errors.push({ path: 'crawl.robots_txt', message: 'crawl.robots_txt must be a string' });
175
352
  }
176
353
 
177
- // 9. Validate 'performance' section
354
+ // performance
178
355
  const perf = data.performance || {};
179
- const stringFields = ['lcp', 'cls', 'fid', 'page_size', 'ttfb'];
180
- for (const field of stringFields) {
356
+ for (const field of ['lcp', 'cls', 'fid', 'inp', 'page_size', 'ttfb']) {
181
357
  if (perf[field] !== undefined && perf[field] !== null && typeof perf[field] !== 'string' && typeof perf[field] !== 'number') {
182
358
  errors.push({ path: `performance.${field}`, message: `performance.${field} must be a string or number` });
183
359
  }
184
360
  }
185
361
 
186
- // 10. Validate 'authority' section
362
+ // authority
187
363
  const authority = data.authority || {};
188
- if (authority.eeat_signals) {
189
- const eeat = authority.eeat_signals;
190
- if (typeof eeat === 'object') {
191
- const fields = ['experience', 'expertise', 'authority', 'trust'];
192
- const missingEeat = fields.filter(f => !eeat[f]);
193
- if (missingEeat.length > 0) {
194
- warnings.push({
195
- path: 'authority.eeat_signals',
196
- message: `EEAT signals are missing values for: ${missingEeat.join(', ')}`
197
- });
198
- }
364
+ if (authority.eeat_signals && typeof authority.eeat_signals === 'object') {
365
+ const missingEeat = ['experience', 'expertise', 'authority', 'trust'].filter((f) => !authority.eeat_signals[f]);
366
+ if (missingEeat.length > 0) {
367
+ warnings.push({
368
+ path: 'authority.eeat_signals',
369
+ message: `EEAT signals are missing values for: ${missingEeat.join(', ')}`,
370
+ });
199
371
  }
200
372
  } else {
201
373
  warnings.push({ path: 'authority.eeat_signals', message: 'authority.eeat_signals section is missing. Highly recommended for AEO.' });
202
374
  }
203
375
 
204
- // 11. Validate 'platform' section
376
+ // platform
205
377
  const platform = data.platform || {};
206
378
  if (!platform.provider) {
207
- warnings.push({ path: 'platform.provider', message: 'platform.provider is null. CLI requires connection for analyze/sync.' });
379
+ warnings.push({ path: 'platform.provider', message: 'platform.provider is null. Configure a provider for analyze/sync.' });
208
380
  }
209
-
210
- return { errors, warnings };
211
381
  }
@@ -1,196 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import { execSync } from 'child_process';
4
- import YAML from 'yaml';
5
-
6
- function parseArgs(argv) {
7
- const out = { from: null, to: null, outFile: null };
8
- for (let i = 2; i < argv.length; i += 1) {
9
- const arg = argv[i];
10
- const next = argv[i + 1];
11
- if (arg === '--from' && next) {
12
- out.from = next;
13
- i += 1;
14
- } else if (arg === '--to' && next) {
15
- out.to = next;
16
- i += 1;
17
- } else if (arg === '--out' && next) {
18
- out.outFile = next;
19
- i += 1;
20
- }
21
- }
22
- return out;
23
- }
24
-
25
- function readContributorsMap(repoRoot) {
26
- const filePath = path.join(repoRoot, '.github', 'contributors.yml');
27
- if (!fs.existsSync(filePath)) {
28
- return { version: 1, contributors: [] };
29
- }
30
- const parsed = YAML.parse(fs.readFileSync(filePath, 'utf8')) || {};
31
- return {
32
- version: parsed.version || 1,
33
- contributors: Array.isArray(parsed.contributors) ? parsed.contributors : []
34
- };
35
- }
36
-
37
- function normalizeEmail(email) {
38
- return String(email || '').trim().toLowerCase();
39
- }
40
-
41
- function normalizeName(name) {
42
- return String(name || '').trim().toLowerCase();
43
- }
44
-
45
- function resolveHandle(map, { name, email }) {
46
- const nEmail = normalizeEmail(email);
47
- const nName = normalizeName(name);
48
-
49
- for (const c of map.contributors) {
50
- if (!c || typeof c !== 'object') continue;
51
- if (!c.github) continue;
52
- const emails = Array.isArray(c.emails) ? c.emails.map(normalizeEmail) : [];
53
- if (nEmail && emails.includes(nEmail)) return c.github;
54
- const names = Array.isArray(c.names) ? c.names.map(normalizeName) : [];
55
- if (nName && names.includes(nName)) return c.github;
56
- }
57
- return null;
58
- }
59
-
60
- function git(repoRoot, args) {
61
- return execSync(`git ${args}`, { cwd: repoRoot, stdio: ['ignore', 'pipe', 'pipe'] }).toString('utf8');
62
- }
63
-
64
- function getRepoRoot() {
65
- return execSync('git rev-parse --show-toplevel', { stdio: ['ignore', 'pipe', 'pipe'] }).toString('utf8').trim();
66
- }
67
-
68
- function getCommitBodies(repoRoot, range) {
69
- const sepCommit = '\u001e';
70
- const sepField = '\u001f';
71
- const out = git(repoRoot, `log ${range} --no-color --format=%H${sepField}%an${sepField}%ae${sepField}%B${sepCommit}`);
72
- const rawCommits = out.split(sepCommit).map(s => s.trim()).filter(Boolean);
73
- return rawCommits.map(entry => {
74
- const parts = entry.split(sepField);
75
- const [sha, authorName, authorEmail] = parts;
76
- const body = parts.slice(3).join(sepField);
77
- return { sha, authorName, authorEmail, body };
78
- });
79
- }
80
-
81
- function extractCoAuthors(commitBody) {
82
- const out = [];
83
- const lines = String(commitBody || '').split('\n');
84
- for (const line of lines) {
85
- const m = line.match(/^Co-authored-by:\s*(.+?)\s*<(.+?)>\s*$/i);
86
- if (m) out.push({ name: m[1], email: m[2] });
87
- }
88
- return out;
89
- }
90
-
91
- function bumpCounter(map, key, display) {
92
- const existing = map.get(key);
93
- if (existing) {
94
- existing.count += 1;
95
- return;
96
- }
97
- map.set(key, { count: 1, display });
98
- }
99
-
100
- function fmtHandle(handle) {
101
- if (!handle) return null;
102
- return handle.startsWith('@') ? handle : `@${handle}`;
103
- }
104
-
105
- function buildContribMarkdown({ from, to, resolvedCounts, unresolvedCounts }) {
106
- const lines = [];
107
- const rangeLabel = from && to ? `${from}..${to}` : 'range';
108
-
109
- lines.push(`## Contributors`);
110
- lines.push('');
111
- lines.push(`Commit range: ${rangeLabel}`);
112
- lines.push('');
113
-
114
- const resolved = Array.from(resolvedCounts.entries())
115
- .sort((a, b) => b[1].count - a[1].count || a[0].localeCompare(b[0]));
116
-
117
- if (resolved.length > 0) {
118
- for (const [handle, info] of resolved) {
119
- lines.push(`- ${fmtHandle(handle)} (${info.count})`);
120
- }
121
- lines.push('');
122
- } else {
123
- lines.push(`- None`);
124
- lines.push('');
125
- }
126
-
127
- const unresolved = Array.from(unresolvedCounts.entries())
128
- .sort((a, b) => b[1].count - a[1].count || a[0].localeCompare(b[0]));
129
-
130
- if (unresolved.length > 0) {
131
- lines.push(`## Unmapped Contributors`);
132
- lines.push('');
133
- for (const [key, info] of unresolved) {
134
- lines.push(`- ${info.display} (${info.count})`);
135
- }
136
- lines.push('');
137
- lines.push(`To tag these contributors, add their name/email to .github/contributors.yml.`);
138
- lines.push('');
139
- }
140
-
141
- return lines.join('\n');
142
- }
143
-
144
- function main() {
145
- const args = parseArgs(process.argv);
146
- if (!args.from || !args.to) {
147
- process.stderr.write('Usage: node scripts/release-contributors.js --from <tag> --to <tag> [--out <file>]\n');
148
- process.exit(1);
149
- }
150
-
151
- const repoRoot = getRepoRoot();
152
- const contribMap = readContributorsMap(repoRoot);
153
- const range = `${args.from}..${args.to}`;
154
- const commits = getCommitBodies(repoRoot, range);
155
-
156
- const resolvedCounts = new Map();
157
- const unresolvedCounts = new Map();
158
-
159
- for (const c of commits) {
160
- const authorHandle = resolveHandle(contribMap, { name: c.authorName, email: c.authorEmail });
161
- if (authorHandle) {
162
- bumpCounter(resolvedCounts, authorHandle, fmtHandle(authorHandle));
163
- } else {
164
- bumpCounter(unresolvedCounts, `${normalizeName(c.authorName)}|${normalizeEmail(c.authorEmail)}`, `${c.authorName} <${c.authorEmail}>`);
165
- }
166
-
167
- for (const co of extractCoAuthors(c.body)) {
168
- const coHandle = resolveHandle(contribMap, co);
169
- if (coHandle) {
170
- bumpCounter(resolvedCounts, coHandle, fmtHandle(coHandle));
171
- } else {
172
- bumpCounter(unresolvedCounts, `${normalizeName(co.name)}|${normalizeEmail(co.email)}`, `${co.name} <${co.email}>`);
173
- }
174
- }
175
- }
176
-
177
- const md = buildContribMarkdown({
178
- from: args.from,
179
- to: args.to,
180
- resolvedCounts,
181
- unresolvedCounts
182
- });
183
-
184
- if (args.outFile) {
185
- const outPath = path.isAbsolute(args.outFile) ? args.outFile : path.join(repoRoot, args.outFile);
186
- fs.mkdirSync(path.dirname(outPath), { recursive: true });
187
- fs.writeFileSync(outPath, md, 'utf8');
188
- process.stdout.write(`${outPath}\n`);
189
- return;
190
- }
191
-
192
- process.stdout.write(md + '\n');
193
- }
194
-
195
- main();
196
-