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.
- package/PROVIDER_SPEC.md +125 -0
- package/README.md +54 -190
- package/SKILL.md +44 -0
- package/bin/seomd.js +79 -31
- package/package.json +11 -7
- package/src/commands/analyze.js +90 -90
- package/src/commands/check.js +301 -0
- package/src/commands/doctor.js +109 -0
- package/src/commands/generate.js +215 -0
- package/src/commands/init.js +170 -66
- package/src/commands/status.js +92 -76
- package/src/commands/sync.js +84 -70
- package/src/commands/validate.js +52 -25
- package/src/generators/directory.js +46 -114
- package/src/generators/reverse.js +46 -56
- package/src/generators/seomd.js +226 -44
- package/src/providers/http.js +67 -0
- package/src/providers/index.js +194 -0
- package/src/utils/agent-wiring.js +97 -0
- package/src/utils/api-client.js +14 -56
- package/src/utils/constants.js +110 -12
- package/src/utils/migrate.js +99 -0
- package/src/utils/parser.js +114 -25
- package/src/utils/placeholders.js +31 -0
- package/src/utils/repo-scanner.js +207 -0
- package/src/utils/writeback.js +171 -82
- package/src/validators/seomd.js +263 -93
- package/scripts/release-contributors.js +0 -196
- package/scripts/release-notes.js +0 -194
- package/src/templates/blog/SEO.REVERSE.md +0 -176
- package/src/templates/blog/SEO.md +0 -233
- package/src/templates/ecommerce/SEO.REVERSE.md +0 -199
- package/src/templates/ecommerce/SEO.md +0 -239
- package/src/templates/local/SEO.REVERSE.md +0 -222
- package/src/templates/local/SEO.md +0 -245
- package/src/templates/marketplace/SEO.REVERSE.md +0 -222
- package/src/templates/marketplace/SEO.md +0 -245
- package/src/templates/saas/SEO.REVERSE.md +0 -268
- package/src/templates/saas/SEO.md +0 -257
package/src/utils/writeback.js
CHANGED
|
@@ -1,121 +1,210 @@
|
|
|
1
1
|
import fs from 'fs-extra';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import YAML from 'yaml';
|
|
4
|
+
import { INTENT_CATEGORIES } from './constants.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* @param {YAML.Document} doc - The YAML Document of SEO.md (deprecated, but kept for signature compatibility)
|
|
9
|
-
* @param {any} response - The API response from analyze/sync
|
|
10
|
-
* @param {string} cwd - Current working directory
|
|
7
|
+
* Sanitizes a page ID so it can never escape `.seo/pages/`.
|
|
11
8
|
*/
|
|
12
|
-
export
|
|
13
|
-
const
|
|
14
|
-
|
|
9
|
+
export function sanitizePageId(id) {
|
|
10
|
+
const cleaned = String(id || 'page')
|
|
11
|
+
.replace(/[^a-zA-Z0-9_-]/g, '-')
|
|
12
|
+
.replace(/-+/g, '-')
|
|
13
|
+
.replace(/^-+|-+$/g, '');
|
|
14
|
+
return cleaned || 'page';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function mergePagesById(existingPages = [], incomingPages = []) {
|
|
18
|
+
const map = new Map();
|
|
19
|
+
for (const p of existingPages) {
|
|
20
|
+
if (p && p.id) map.set(p.id, p);
|
|
21
|
+
}
|
|
22
|
+
for (const p of incomingPages) {
|
|
23
|
+
if (p && p.id) map.set(p.id, p);
|
|
24
|
+
}
|
|
25
|
+
return Array.from(map.values());
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Writes (and merges) platform analysis metrics into `.seo/STATUS.yml`.
|
|
30
|
+
*
|
|
31
|
+
* @param {any} _doc - Deprecated parameter kept for backwards signature compatibility
|
|
32
|
+
* @param {any} response - API response from analyze/sync
|
|
33
|
+
* @param {string} cwd - Project root directory
|
|
34
|
+
* @param {{ provider?: string }} [options]
|
|
35
|
+
*/
|
|
36
|
+
export async function writeAnalysisToSeoMd(_doc, response, cwd, options = {}) {
|
|
37
|
+
const seomdDir = path.join(cwd, '.seo');
|
|
38
|
+
await fs.ensureDir(seomdDir);
|
|
39
|
+
const statusPath = path.join(seomdDir, 'STATUS.yml');
|
|
40
|
+
|
|
41
|
+
let existing = {};
|
|
42
|
+
if (await fs.pathExists(statusPath)) {
|
|
43
|
+
try {
|
|
44
|
+
existing = YAML.parse(await fs.readFile(statusPath, 'utf8')) || {};
|
|
45
|
+
} catch {
|
|
46
|
+
existing = {};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const aeo = response?.aeo_analysis || {};
|
|
51
|
+
const incomingPages = Array.isArray(response?.page_analysis)
|
|
52
|
+
? response.page_analysis.map((p) => ({
|
|
53
|
+
id: p.id,
|
|
54
|
+
url: p.url,
|
|
55
|
+
citation_rate: p.citation_rate ?? null,
|
|
56
|
+
gap_score: p.gap_score ?? null,
|
|
57
|
+
top_cited_competitor: p.top_cited_competitor ?? null,
|
|
58
|
+
}))
|
|
59
|
+
: [];
|
|
60
|
+
|
|
61
|
+
const existingPages = Array.isArray(existing?.pages?.pages) ? existing.pages.pages : [];
|
|
62
|
+
const mergedPages = mergePagesById(existingPages, incomingPages);
|
|
63
|
+
|
|
64
|
+
const mergedIntent = { ...(existing.intent || {}) };
|
|
65
|
+
if (response?.intent_analysis && typeof response.intent_analysis === 'object') {
|
|
66
|
+
for (const cat of INTENT_CATEGORIES) {
|
|
67
|
+
if (response.intent_analysis[cat]) {
|
|
68
|
+
mergedIntent[cat] = {
|
|
69
|
+
citation_rate: response.intent_analysis[cat].citation_rate ?? null,
|
|
70
|
+
top_cited_competitor: response.intent_analysis[cat].top_cited_competitor ?? null,
|
|
71
|
+
gap_score: response.intent_analysis[cat].gap_score ?? null,
|
|
72
|
+
trend: response.intent_analysis[cat].trend || 'stable',
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const source = response?.provider || options.provider || existing.source || 'custom';
|
|
15
79
|
|
|
16
80
|
const statusData = {
|
|
17
|
-
source
|
|
18
|
-
last_analyzed:
|
|
19
|
-
next_analysis:
|
|
81
|
+
source,
|
|
82
|
+
last_analyzed: aeo.last_analyzed ?? existing.last_analyzed ?? null,
|
|
83
|
+
next_analysis: aeo.next_analysis ?? existing.next_analysis ?? null,
|
|
20
84
|
aeo: {
|
|
21
|
-
overall_citation_rate:
|
|
22
|
-
overall_gap_score:
|
|
23
|
-
engines_tracked:
|
|
85
|
+
overall_citation_rate: aeo.overall_citation_rate ?? existing.aeo?.overall_citation_rate ?? null,
|
|
86
|
+
overall_gap_score: aeo.overall_gap_score ?? existing.aeo?.overall_gap_score ?? null,
|
|
87
|
+
engines_tracked: aeo.engines_tracked ?? existing.aeo?.engines_tracked ?? [],
|
|
24
88
|
},
|
|
25
|
-
intent:
|
|
89
|
+
intent: mergedIntent,
|
|
26
90
|
pages: {
|
|
27
|
-
pages:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
citation_rate: p.citation_rate,
|
|
31
|
-
gap_score: p.gap_score,
|
|
32
|
-
top_cited_competitor: p.top_cited_competitor
|
|
33
|
-
})),
|
|
34
|
-
missing_pages: [],
|
|
35
|
-
build_order_recommendation: []
|
|
91
|
+
pages: mergedPages,
|
|
92
|
+
missing_pages: existing.pages?.missing_pages || [],
|
|
93
|
+
build_order_recommendation: existing.pages?.build_order_recommendation || [],
|
|
36
94
|
},
|
|
37
|
-
keywords: {}
|
|
95
|
+
keywords: existing.keywords || {},
|
|
38
96
|
};
|
|
39
97
|
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
trend: response.intent_analysis[cat].trend || 'stable'
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
}
|
|
98
|
+
const header = [
|
|
99
|
+
'# .seo/STATUS.yml',
|
|
100
|
+
'#',
|
|
101
|
+
'# Auto-generated by your connected SEO.md provider.',
|
|
102
|
+
'# Do not edit manually — run `npx seomd-cli analyze` or `npx seomd-cli sync` to update.',
|
|
103
|
+
'',
|
|
104
|
+
].join('\n');
|
|
51
105
|
|
|
52
|
-
|
|
53
|
-
await fs.ensureDir(seomdDir);
|
|
54
|
-
const statusPath = path.join(seomdDir, 'STATUS.yml');
|
|
55
|
-
|
|
56
|
-
const header = `# .seo/STATUS.yml\n#\n# This file is auto-generated by your connected SEO.md platform.\n# Do not edit manually — run \`npx seomd analyze\` to update.\n# Run \`npx seomd sync\` to pull latest intelligence.\n\n`;
|
|
57
|
-
await fs.writeFile(statusPath, header + YAML.stringify(statusData), 'utf8');
|
|
106
|
+
await fs.writeFile(statusPath, `${header}\n${YAML.stringify(statusData)}`, 'utf8');
|
|
58
107
|
}
|
|
59
108
|
|
|
109
|
+
export const writeStatusYml = writeAnalysisToSeoMd;
|
|
110
|
+
|
|
60
111
|
/**
|
|
61
|
-
* Generates and
|
|
62
|
-
*
|
|
63
|
-
* @param {string} cwd -
|
|
64
|
-
* @param {any} response -
|
|
112
|
+
* Generates and merges `.seo/REVERSE.md`.
|
|
113
|
+
*
|
|
114
|
+
* @param {string} cwd - Project root directory
|
|
115
|
+
* @param {any} response - API response from analyze/sync
|
|
116
|
+
* @param {string} [defaultDomain='example.com']
|
|
117
|
+
* @param {string} [defaultBrand='My Brand']
|
|
118
|
+
* @param {{ provider?: string }} [options]
|
|
65
119
|
*/
|
|
66
|
-
export async function writeReverseMd(
|
|
120
|
+
export async function writeReverseMd(
|
|
121
|
+
cwd,
|
|
122
|
+
response,
|
|
123
|
+
defaultDomain = 'example.com',
|
|
124
|
+
defaultBrand = 'My Brand',
|
|
125
|
+
options = {}
|
|
126
|
+
) {
|
|
67
127
|
const seomdDir = path.join(cwd, '.seo');
|
|
68
128
|
await fs.ensureDir(seomdDir);
|
|
69
129
|
const reversePath = path.join(seomdDir, 'REVERSE.md');
|
|
70
130
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
131
|
+
let existing = {};
|
|
132
|
+
if (await fs.pathExists(reversePath)) {
|
|
133
|
+
try {
|
|
134
|
+
existing = YAML.parse(await fs.readFile(reversePath, 'utf8')) || {};
|
|
135
|
+
} catch {
|
|
136
|
+
existing = {};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const incomingPages = Array.isArray(response?.page_analysis)
|
|
141
|
+
? response.page_analysis.map((p) => ({
|
|
142
|
+
id: p.id,
|
|
143
|
+
url: p.url,
|
|
144
|
+
status: p.status || 'planned',
|
|
145
|
+
citation_rate: p.citation_rate ?? null,
|
|
146
|
+
gap_score: p.gap_score ?? null,
|
|
147
|
+
top_cited_competitor: p.top_cited_competitor ?? null,
|
|
148
|
+
why_page_won: p.why_page_won || [],
|
|
149
|
+
citation_hooks: p.citation_hooks || [],
|
|
150
|
+
gaps_for_brand: p.gaps_for_brand || p.gaps_for_my_brand || [],
|
|
151
|
+
remediation_playbook: p.remediation_playbook || [],
|
|
152
|
+
fastest_win: p.fastest_win || { action: null, estimated_gap_score_improvement: null, effort: null },
|
|
153
|
+
suggested_content_outline: p.suggested_content_outline || [],
|
|
154
|
+
}))
|
|
155
|
+
: [];
|
|
156
|
+
|
|
157
|
+
const existingPages = Array.isArray(existing.pages) ? existing.pages : [];
|
|
158
|
+
const mergedPages = mergePagesById(existingPages, incomingPages);
|
|
159
|
+
|
|
160
|
+
const aeo = response?.aeo_analysis || {};
|
|
161
|
+
const primaryCompetitor =
|
|
162
|
+
response?.intent_analysis?.comparison?.top_cited_competitor ||
|
|
163
|
+
existing.primary_competitor ||
|
|
164
|
+
null;
|
|
165
|
+
|
|
166
|
+
const source = response?.provider || options.provider || existing.source || 'custom';
|
|
87
167
|
|
|
88
168
|
const reverseDoc = {
|
|
89
|
-
domain: response.domain || defaultDomain,
|
|
90
|
-
brand: response
|
|
169
|
+
domain: response?.domain || existing.domain || defaultDomain,
|
|
170
|
+
brand: response?.brand_name || existing.brand || defaultBrand,
|
|
91
171
|
primary_competitor: primaryCompetitor,
|
|
92
|
-
last_analyzed:
|
|
93
|
-
next_analysis:
|
|
94
|
-
source
|
|
95
|
-
pages:
|
|
172
|
+
last_analyzed: aeo.last_analyzed ?? existing.last_analyzed ?? null,
|
|
173
|
+
next_analysis: aeo.next_analysis ?? existing.next_analysis ?? null,
|
|
174
|
+
source,
|
|
175
|
+
pages: mergedPages,
|
|
176
|
+
...(Array.isArray(existing.competitors) ? { competitors: existing.competitors } : {}),
|
|
96
177
|
};
|
|
97
178
|
|
|
98
|
-
const header =
|
|
179
|
+
const header = [
|
|
180
|
+
'# .seo/REVERSE.md',
|
|
181
|
+
'#',
|
|
182
|
+
'# Auto-generated by your connected SEO.md provider.',
|
|
183
|
+
'# Do not edit manually — run `npx seomd-cli analyze` or `npx seomd-cli sync` to update.',
|
|
184
|
+
'',
|
|
185
|
+
].join('\n');
|
|
99
186
|
|
|
100
|
-
|
|
101
|
-
await fs.writeFile(reversePath, header + yamlContent, 'utf8');
|
|
187
|
+
await fs.writeFile(reversePath, `${header}\n${YAML.stringify(reverseDoc)}`, 'utf8');
|
|
102
188
|
}
|
|
103
189
|
|
|
104
190
|
/**
|
|
105
|
-
* Writes individual page playbooks into
|
|
106
|
-
*
|
|
107
|
-
* @param {string} cwd -
|
|
108
|
-
* @param {any} response -
|
|
191
|
+
* Writes individual page playbooks into `.seo/pages/{sanitized-id}.md`.
|
|
192
|
+
*
|
|
193
|
+
* @param {string} cwd - Project root directory
|
|
194
|
+
* @param {any} response - API response from analyze/sync
|
|
109
195
|
*/
|
|
110
196
|
export async function writePageAnalysis(cwd, response) {
|
|
111
|
-
const
|
|
112
|
-
const pagesDir = path.join(seomdDir, 'pages');
|
|
113
|
-
|
|
197
|
+
const pagesDir = path.resolve(cwd, '.seo', 'pages');
|
|
114
198
|
await fs.ensureDir(pagesDir);
|
|
115
199
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
200
|
+
const pages = Array.isArray(response?.page_analysis) ? response.page_analysis : [];
|
|
201
|
+
for (const page of pages) {
|
|
202
|
+
if (page && page.markdown_content) {
|
|
203
|
+
const safeId = sanitizePageId(page.id);
|
|
204
|
+
const filePath = path.resolve(pagesDir, `${safeId}.md`);
|
|
205
|
+
if (!filePath.startsWith(pagesDir + path.sep)) {
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
119
208
|
await fs.writeFile(filePath, page.markdown_content, 'utf8');
|
|
120
209
|
}
|
|
121
210
|
}
|