@chendb888/dsh-project-steward 0.0.0-stage → 0.1.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/CHANGELOG.md +50 -0
- package/README.md +64 -2
- package/client.js +417 -0
- package/cordis.patch.yml +7 -0
- package/docs/images/cover.png +0 -0
- package/docs/images/icon.png +0 -0
- package/docs/images/update-0.1.0.png +0 -0
- package/icon.svg +14 -0
- package/index.js +24 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +6 -0
- package/package.json +47 -3
- package/src/channel-import.js +97 -0
- package/src/checkers/index.js +113 -0
- package/src/collector-sched.js +119 -0
- package/src/collectors/index.js +101 -0
- package/src/docs-tools.js +44 -0
- package/src/docs.js +254 -0
- package/src/inspect.js +54 -0
- package/src/listing-tools.js +70 -0
- package/src/listing.js +122 -0
- package/src/market/analyze.js +159 -0
- package/src/market/discover.js +52 -0
- package/src/market/features.js +118 -0
- package/src/market/tools.js +34 -0
- package/src/ops-tools.js +70 -0
- package/src/ops.js +65 -0
- package/src/pipeline-tools.js +46 -0
- package/src/pipeline.js +195 -0
- package/src/publish/index.js +51 -0
- package/src/registry.js +121 -0
- package/src/routes.js +185 -0
- package/src/schemas.js +220 -0
- package/src/service.js +113 -0
- package/src/store.js +229 -0
- package/src/templates.js +68 -0
- package/src/tools.js +74 -0
package/src/docs.js
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
// M15 · 项目说明与更新维护(FR7 / R29)。按各商店规则生成/核对项目说明,维护巡检。
|
|
2
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs'
|
|
3
|
+
import { join } from 'node:path'
|
|
4
|
+
import { spawnSync } from 'node:child_process'
|
|
5
|
+
import { storeError } from './store.js'
|
|
6
|
+
|
|
7
|
+
const now = () => new Date().toISOString()
|
|
8
|
+
|
|
9
|
+
// 各商店的项目说明规则(FR7.3 按渠道材料模板)
|
|
10
|
+
export const CHANNEL_RULES = {
|
|
11
|
+
'npm-registry': { label: 'npm', materials: ['readme', 'description', 'keywords'], note: 'README 自动展示于 npmjs.com;package.json description+keywords' },
|
|
12
|
+
'mirror': { label: '镜像', materials: ['readme', 'description'], note: '同步 npm 包内容(README/description)' },
|
|
13
|
+
'source-repo': { label: 'GitHub', materials: ['readme', 'repo-description', 'topics'], note: 'README + 仓库 description + topics' },
|
|
14
|
+
'plugin-market': { label: 'DSH 市场', materials: ['locale-meta', 'detail-doc', 'icon'], note: 'locale meta.title/description + DETAIL.md + icon.svg' },
|
|
15
|
+
'game-store': { label: '游戏商店', materials: ['description', 'tags', 'cover', 'screenshots'], note: '游戏介绍+标签+封面+截图' },
|
|
16
|
+
'web-deploy': { label: 'Web 部署', materials: ['description'], note: '应用说明' },
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class Docs {
|
|
20
|
+
constructor(service) { this.service = service; this.store = service.store }
|
|
21
|
+
|
|
22
|
+
_read(root, f) { try { return readFileSync(join(root, f), 'utf8') } catch { return '' } }
|
|
23
|
+
_exists(root, f) { return existsSync(join(root, f)) }
|
|
24
|
+
|
|
25
|
+
// FR7.3 上架完整性核对:README/CHANGELOG/description/版本说明
|
|
26
|
+
docCheck(projectId) {
|
|
27
|
+
const p = this.service.getProject(projectId)
|
|
28
|
+
if (!p) throw storeError('NOT_FOUND', `项目 ${projectId} 不存在`)
|
|
29
|
+
const root = p.rootPath
|
|
30
|
+
const latest = this.store.list('releases').filter(r => r.projectId === projectId).sort((a, b) => b.releasedAt.localeCompare(a.releasedAt))[0]
|
|
31
|
+
const ver = latest?.version
|
|
32
|
+
const readme = ['README.md', 'readme.md', 'README'].find(f => this._exists(root, f))
|
|
33
|
+
const readmeContent = readme ? this._read(root, readme) : ''
|
|
34
|
+
const changelog = ['CHANGELOG.md', 'CHANGES.md', 'HISTORY.md'].find(f => this._exists(root, f))
|
|
35
|
+
const pkg = this._read(root, 'package.json')
|
|
36
|
+
let pkgDesc = ''
|
|
37
|
+
try { pkgDesc = JSON.parse(pkg).description || '' } catch {}
|
|
38
|
+
const items = [
|
|
39
|
+
{ key: 'readme', label: 'README 项目说明', ok: !!readme && readmeContent.trim().length >= 50, detail: readme ? `${readme}(${readmeContent.trim().length} 字符)` : '缺失' },
|
|
40
|
+
{ key: 'readme-version', label: 'README 含最新版本说明', ok: !!ver && readmeContent.includes(ver), detail: ver ? (readmeContent.includes(ver) ? `含 ${ver}` : `未含 ${ver}`) : '无 release' },
|
|
41
|
+
{ key: 'changelog', label: 'CHANGELOG 逐版本变更', ok: !!changelog && this._read(root, changelog).trim().length > 0, detail: changelog || '缺失' },
|
|
42
|
+
{ key: 'description', label: 'package.json description', ok: pkgDesc.length > 0, detail: pkgDesc || '缺失' },
|
|
43
|
+
]
|
|
44
|
+
const missing = items.filter(i => !i.ok)
|
|
45
|
+
return { projectId, name: p.name, latestVersion: ver || null, items, complete: missing.length === 0, missing: missing.map(i => i.key) }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// FR7.1 生成 README+CHANGELOG 模板(仅补缺失,不覆盖已有)
|
|
49
|
+
docScaffold(projectId, opts = {}) {
|
|
50
|
+
const p = this.service.getProject(projectId)
|
|
51
|
+
if (!p) throw storeError('NOT_FOUND', `项目 ${projectId} 不存在`)
|
|
52
|
+
const root = p.rootPath
|
|
53
|
+
const releases = this.store.list('releases').filter(r => r.projectId === projectId).sort((a, b) => b.releasedAt.localeCompare(a.releasedAt))
|
|
54
|
+
const latest = releases[0]
|
|
55
|
+
const created = []
|
|
56
|
+
const typeLabel = { 'dsh-plugin': 'DSH 插件', game: '游戏', 'web-app': 'Web 应用', 'business-system': '业务系统', engine: '引擎', research: '研究项目', host: '宿主' }[p.type] || p.type
|
|
57
|
+
|
|
58
|
+
if (!['README.md', 'readme.md', 'README'].some(f => this._exists(root, f)) || opts.force) {
|
|
59
|
+
const features = (p.tags || []).map(t => `- ${t}`).join('\n') || '- (待补充功能特性)'
|
|
60
|
+
const install = p.type === 'dsh-plugin' ? `\`\`\`bash\ndsh plugin --profile web add ${opts.packageName || p.name}\n\`\`\`` : '(待补充安装方式)'
|
|
61
|
+
const verSection = latest ? `### ${latest.version}\n${latest.changelog || '- (待补充更新内容)'}` : '### (尚无发布版本)'
|
|
62
|
+
const readme = `# ${p.name}\n\n> ${p.notes || typeLabel + '项目说明(待补充)'}\n\n## 功能特性\n\n${features}\n\n## 安装\n\n${install}\n\n## 使用\n\n(待补充使用说明)\n\n## 版本更新说明\n\n${verSection}\n\n## 许可\n\n${opts.license || 'MIT'}\n`
|
|
63
|
+
writeFileSync(join(root, 'README.md'), readme, 'utf8')
|
|
64
|
+
created.push('README.md')
|
|
65
|
+
}
|
|
66
|
+
if (!['CHANGELOG.md', 'CHANGES.md', 'HISTORY.md'].some(f => this._exists(root, f)) || opts.force) {
|
|
67
|
+
const entries = releases.length ? releases.map(r => `## [${r.version}] - ${r.releasedAt.slice(0, 10)}\n\n${r.changelog || '- (待补充)'}`).join('\n\n') : '## [未发布]\n\n- 初始版本(待补充)'
|
|
68
|
+
const changelog = `# Changelog\n\n本文件记录 ${p.name} 逐版本变更。\n\n${entries}\n`
|
|
69
|
+
writeFileSync(join(root, 'CHANGELOG.md'), changelog, 'utf8')
|
|
70
|
+
created.push('CHANGELOG.md')
|
|
71
|
+
}
|
|
72
|
+
return { projectId, name: p.name, created, check: this.docCheck(projectId) }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// FR7.4 维护巡检:所有项目说明齐备性 + 版本一致性
|
|
76
|
+
maintenanceReport() {
|
|
77
|
+
const projects = this.service.listProjects()
|
|
78
|
+
const reports = projects.map(p => {
|
|
79
|
+
const c = this.docCheck(p.id)
|
|
80
|
+
const issues = [...c.missing]
|
|
81
|
+
// 版本一致性:package.json version vs 最新 release
|
|
82
|
+
const pkg = this._read(p.rootPath, 'package.json')
|
|
83
|
+
try {
|
|
84
|
+
const pv = JSON.parse(pkg).version
|
|
85
|
+
if (c.latestVersion && pv && pv !== c.latestVersion) issues.push('version-mismatch')
|
|
86
|
+
} catch {}
|
|
87
|
+
return { projectId: p.id, name: p.name, type: p.type, complete: c.complete && !issues.includes('version-mismatch'), latestVersion: c.latestVersion, issues }
|
|
88
|
+
})
|
|
89
|
+
return { generatedAt: now(), total: reports.length, incomplete: reports.filter(r => !r.complete).length, reports }
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// FR7.3 按商店规则核对项目说明
|
|
93
|
+
channelCheck(projectId, channelId) {
|
|
94
|
+
const p = this.service.getProject(projectId)
|
|
95
|
+
if (!p) throw storeError('NOT_FOUND', `项目 ${projectId} 不存在`)
|
|
96
|
+
const ch = this.store.get('channels', channelId)
|
|
97
|
+
if (!ch) throw storeError('NOT_FOUND', `渠道 ${channelId} 不存在`)
|
|
98
|
+
const rule = CHANNEL_RULES[ch.category] || { label: ch.category, materials: ['readme', 'description'], note: '' }
|
|
99
|
+
const root = p.rootPath
|
|
100
|
+
const has = f => this._exists(root, f)
|
|
101
|
+
const readme = ['README.md', 'readme.md', 'README'].find(f => has(f))
|
|
102
|
+
const pkg = this._read(root, 'package.json')
|
|
103
|
+
let pkgJson = {}; try { pkgJson = JSON.parse(pkg) } catch {}
|
|
104
|
+
const repo = (p.remote || '').match(/github\.com[/:]([^/]+\/[^/]+?)(?:\.git)?$/)?.[1]
|
|
105
|
+
const checks = {
|
|
106
|
+
readme: !!readme && this._read(root, readme).trim().length >= 50,
|
|
107
|
+
description: (pkgJson.description || '').length > 0,
|
|
108
|
+
keywords: Array.isArray(pkgJson.keywords) && pkgJson.keywords.length > 0,
|
|
109
|
+
'repo-description': false, // 需 GitHub API 核实,下方 complete 时设置
|
|
110
|
+
topics: false,
|
|
111
|
+
'locale-meta': ['locale/en.json', 'locale/zh.json'].every(f => { try { const m = JSON.parse(this._read(root, f)).meta; return m && m.title && m.description } catch { return false } }),
|
|
112
|
+
'detail-doc': has('docs/DETAIL.md'),
|
|
113
|
+
icon: has('icon.svg'),
|
|
114
|
+
tags: (p.tags || []).length > 0,
|
|
115
|
+
cover: false, screenshots: false,
|
|
116
|
+
}
|
|
117
|
+
const items = rule.materials.map(m => ({ key: m, ok: !!checks[m], label: m }))
|
|
118
|
+
return { projectId, channelId, channel: ch.name, category: ch.category, rule: rule.note, items, missing: items.filter(i => !i.ok).map(i => i.key) }
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// FR7.1 按商店规则完成项目说明
|
|
122
|
+
docCompleteChannel(projectId, channelId, opts = {}) {
|
|
123
|
+
const p = this.service.getProject(projectId)
|
|
124
|
+
if (!p) throw storeError('NOT_FOUND', `项目 ${projectId} 不存在`)
|
|
125
|
+
const ch = this.store.get('channels', channelId)
|
|
126
|
+
if (!ch) throw storeError('NOT_FOUND', `渠道 ${channelId} 不存在`)
|
|
127
|
+
const root = p.rootPath
|
|
128
|
+
const done = []
|
|
129
|
+
const desc = (p.notes || p.name).slice(0, 350)
|
|
130
|
+
const repo = (p.remote || '').match(/github\.com[/:]([^/]+\/[^/]+?)(?:\.git)?$/)?.[1]
|
|
131
|
+
|
|
132
|
+
// 通用:README 缺失则生成
|
|
133
|
+
if (!['README.md', 'readme.md', 'README'].some(f => this._exists(root, f))) { this.docScaffold(projectId); done.push('README.md(scaffold)') }
|
|
134
|
+
|
|
135
|
+
if (ch.category === 'npm-registry' || ch.category === 'mirror') {
|
|
136
|
+
// 确保 package.json description + keywords
|
|
137
|
+
const pkgPath = join(root, 'package.json')
|
|
138
|
+
try {
|
|
139
|
+
const pj = JSON.parse(readFileSync(pkgPath, 'utf8'))
|
|
140
|
+
let changed = false
|
|
141
|
+
if (!pj.description) { pj.description = desc; changed = true }
|
|
142
|
+
if (!pj.keywords || !pj.keywords.length) { pj.keywords = p.tags || []; changed = true }
|
|
143
|
+
if (changed) { writeFileSync(pkgPath, JSON.stringify(pj, null, 2)); done.push('package.json description+keywords') }
|
|
144
|
+
} catch {}
|
|
145
|
+
} else if (ch.category === 'source-repo' && repo) {
|
|
146
|
+
// GitHub:设置仓库 description + topics(gh CLI;topics 须小写字母数字连字符)
|
|
147
|
+
const topicMap = { '看板': 'kanban-board', '可视化': 'visualization', '白盒': 'whitebox', '任务': 'task-management', '进度': 'progress', '导游': 'guide' }
|
|
148
|
+
const topics = []
|
|
149
|
+
for (const t of (p.tags || [])) {
|
|
150
|
+
const mapped = topicMap[t] || t
|
|
151
|
+
const clean = String(mapped).toLowerCase().replace(/[^a-z0-9-]/g, '-').replace(/^-+|-+$/g, '').replace(/-+/g, '-')
|
|
152
|
+
if (/^[a-z][a-z0-9-]*$/.test(clean) && clean.length <= 50 && !topics.includes(clean)) topics.push(clean)
|
|
153
|
+
}
|
|
154
|
+
if (!topics.includes('dsh-plugin')) topics.push('dsh-plugin')
|
|
155
|
+
const args = ['repo', 'edit', repo, '--description', desc]
|
|
156
|
+
for (const t of topics.slice(0, 15)) { args.push('--add-topic', t) }
|
|
157
|
+
const r = spawnSync('gh', args, { encoding: 'utf8', timeout: 30000 })
|
|
158
|
+
if (r.status === 0) done.push(`GitHub description+topics (${repo}: ${topics.join(',')})`)
|
|
159
|
+
else done.push(`GitHub 设置失败:${(r.stderr || r.stdout || '').slice(0, 120)}`)
|
|
160
|
+
} else if (ch.category === 'plugin-market') {
|
|
161
|
+
// DSH 市场:locale meta + DETAIL.md + icon
|
|
162
|
+
mkdirSync(join(root, 'locale'), { recursive: true })
|
|
163
|
+
for (const [f, title] of [['locale/en.json', p.name], ['locale/zh.json', p.name]]) {
|
|
164
|
+
const fp = join(root, f)
|
|
165
|
+
let obj = {}; try { obj = JSON.parse(readFileSync(fp, 'utf8')) } catch {}
|
|
166
|
+
obj.meta = obj.meta || {}
|
|
167
|
+
if (!obj.meta.title) obj.meta.title = title
|
|
168
|
+
if (!obj.meta.description) obj.meta.description = desc
|
|
169
|
+
if (f.endsWith('en.json') && !obj.meta.detail) obj.meta.detail = 'docs/DETAIL.md'
|
|
170
|
+
writeFileSync(fp, JSON.stringify(obj, null, 2)); done.push(f + ' meta')
|
|
171
|
+
}
|
|
172
|
+
if (!this._exists(root, 'docs/DETAIL.md')) {
|
|
173
|
+
mkdirSync(join(root, 'docs'), { recursive: true })
|
|
174
|
+
const readme = this._read(root, 'README.md') || desc
|
|
175
|
+
writeFileSync(join(root, 'docs/DETAIL.md'), readme, 'utf8'); done.push('docs/DETAIL.md')
|
|
176
|
+
}
|
|
177
|
+
if (!this._exists(root, 'icon.svg')) done.push('⚠️ 缺 icon.svg(需人工提供)')
|
|
178
|
+
} else if (ch.category === 'game-store') {
|
|
179
|
+
done.push('⚠️ 游戏商店需封面/截图素材(人工提供);介绍文案可由 README 提取')
|
|
180
|
+
}
|
|
181
|
+
return { projectId, channelId, channel: ch.name, done, check: this.channelCheck(projectId, channelId) }
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// FR7.7 生成某版本更新位置标注图(SVG→PNG),落 docs/images/update-<version>.png
|
|
185
|
+
generateUpdateImage(projectId, version, opts = {}) {
|
|
186
|
+
const p = this.service.getProject(projectId)
|
|
187
|
+
if (!p) throw storeError('NOT_FOUND', `项目 ${projectId} 不存在`)
|
|
188
|
+
const root = p.rootPath
|
|
189
|
+
const changelog = this._read(root, 'CHANGELOG.md')
|
|
190
|
+
const bullets = this._versionBullets(changelog, version)
|
|
191
|
+
const svg = this._buildUpdateSvg(p.name, version, bullets)
|
|
192
|
+
const imgDir = join(root, 'docs', 'images')
|
|
193
|
+
mkdirSync(imgDir, { recursive: true })
|
|
194
|
+
const svgPath = join(imgDir, `update-${version}.svg`)
|
|
195
|
+
const pngPath = join(imgDir, `update-${version}.png`)
|
|
196
|
+
writeFileSync(svgPath, svg, 'utf8')
|
|
197
|
+
const chrome = opts.chrome || 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe'
|
|
198
|
+
const r = spawnSync(chrome, ['--headless', '--disable-gpu', '--no-sandbox', `--screenshot=${pngPath}`, '--window-size=900,560', `file:///${svgPath.replace(/\\/g, '/')}`], { encoding: 'utf8', timeout: 30000 })
|
|
199
|
+
const ok = existsSync(pngPath)
|
|
200
|
+
// 推 GitHub(若 remote 是 GitHub)以便 npm 渲染绝对 URL
|
|
201
|
+
let url = null
|
|
202
|
+
const repo = (p.remote || '').match(/github\.com[/:]([^/]+\/[^/]+?)(?:\.git)?$/)?.[1]
|
|
203
|
+
if (ok && repo && !opts.noPush) {
|
|
204
|
+
try {
|
|
205
|
+
const b64 = readFileSync(pngPath).toString('base64')
|
|
206
|
+
const body = JSON.stringify({ message: `docs: ${version} 更新位置标注图`, content: b64 })
|
|
207
|
+
const tmp = join(imgDir, `_body.json`); writeFileSync(tmp, body)
|
|
208
|
+
const gr = spawnSync('gh', ['api', `repos/${repo}/contents/docs/images/update-${version}.png`, '--method', 'PUT', '--input', tmp], { encoding: 'utf8', timeout: 30000 })
|
|
209
|
+
if (gr.status === 0) url = `https://raw.githubusercontent.com/${repo}/main/docs/images/update-${version}.png`
|
|
210
|
+
} catch {}
|
|
211
|
+
}
|
|
212
|
+
return { projectId, version, svgPath, pngPath, ok, url, bullets }
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
_versionBullets(changelog, version) {
|
|
216
|
+
const sec = changelog.split(new RegExp(`##\\s*\\[?${version.replace(/\./g, '\\.')}\\]?`))[1]
|
|
217
|
+
if (!sec) return ['(该版本无 changelog 条目)']
|
|
218
|
+
const body = sec.split(/\n##\s/)[0]
|
|
219
|
+
const bullets = []
|
|
220
|
+
for (const line of body.split('\n')) {
|
|
221
|
+
const m = line.match(/^[-*]\s+(.+)/)
|
|
222
|
+
if (m && !/^\!\[/.test(m[1])) bullets.push(m[1].replace(/\*\*/g, '').trim())
|
|
223
|
+
}
|
|
224
|
+
return bullets.slice(0, 6)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
_buildUpdateSvg(name, version, bullets) {
|
|
228
|
+
const esc = s => String(s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
|
229
|
+
const bl = bullets.slice(0, 4)
|
|
230
|
+
const bulletSvg = bl.map((b, i) => `<text x="40" y="${150 + i * 26}" fill="#ddd" font-size="13">• ${esc(b.slice(0, 60))}</text>`).join('')
|
|
231
|
+
const legend = bl.slice(0, 2).map((b, i) => `<text x="40" y="${470 + i * 24}" fill="#ddd" font-size="12">${i === 0 ? '①' : '②'} ${esc(b.slice(0, 70))}</text>`).join('')
|
|
232
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 900 560" font-family="Segoe UI, Microsoft YaHei, sans-serif">
|
|
233
|
+
<rect width="900" height="560" fill="#1e1e1e"/>
|
|
234
|
+
<rect x="0" y="0" width="900" height="50" fill="#2a2a2a"/>
|
|
235
|
+
<text x="20" y="32" fill="#fff" font-size="17" font-weight="bold">${esc(name)} · v${esc(version)} 更新位置</text>
|
|
236
|
+
<text x="40" y="100" fill="#ff5000" font-size="15" font-weight="bold">本次更新内容</text>
|
|
237
|
+
${bulletSvg}
|
|
238
|
+
<rect x="40" y="270" width="380" height="150" rx="8" fill="#2a2a2a" stroke="#3a3a3a"/>
|
|
239
|
+
<text x="55" y="300" fill="#fff" font-size="13" font-weight="bold">界面区域 A</text>
|
|
240
|
+
<rect x="55" y="315" width="350" height="8" rx="4" fill="#22a06b"/>
|
|
241
|
+
<text x="55" y="350" fill="#888" font-size="11">更新区域①(红框标注)</text>
|
|
242
|
+
<rect x="35" y="265" width="390" height="160" rx="10" fill="none" stroke="#ff3b30" stroke-width="2.5" stroke-dasharray="6 3"/>
|
|
243
|
+
<rect x="450" y="270" width="410" height="150" rx="8" fill="#2a2a2a" stroke="#3a3a3a"/>
|
|
244
|
+
<text x="465" y="300" fill="#fff" font-size="13" font-weight="bold">界面区域 B</text>
|
|
245
|
+
<rect x="465" y="315" width="280" height="8" rx="4" fill="#5b6cff"/>
|
|
246
|
+
<text x="465" y="350" fill="#888" font-size="11">更新区域②(红框标注)</text>
|
|
247
|
+
<rect x="445" y="265" width="420" height="160" rx="10" fill="none" stroke="#ff3b30" stroke-width="2.5" stroke-dasharray="6 3"/>
|
|
248
|
+
<rect x="20" y="440" width="860" height="100" rx="8" fill="#252525"/>
|
|
249
|
+
<text x="40" y="465" fill="#ff5000" font-size="14" font-weight="bold">v${esc(version)} 更新位置图例</text>
|
|
250
|
+
${legend}
|
|
251
|
+
<text x="40" y="528" fill="#888" font-size="11">红虚线框 = 本次更新位置 · 示意图(实际界面以运行时为准)</text>
|
|
252
|
+
</svg>`
|
|
253
|
+
}
|
|
254
|
+
}
|
package/src/inspect.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// 项目管家 · M10 Inspect Provider(06§4):严格只读,供 Agent 写扩展代码前探查。
|
|
2
|
+
import { collections, SCHEMA_VERSION } from './schemas.js'
|
|
3
|
+
|
|
4
|
+
export function buildInspect(service) {
|
|
5
|
+
return {
|
|
6
|
+
id: 'steward',
|
|
7
|
+
description: '项目管家只读探查:项目/模板/run/渠道/市场报告/台账 schema。',
|
|
8
|
+
methods: {
|
|
9
|
+
listProjects: {
|
|
10
|
+
description: '项目摘要目录(可按 type/stage 筛选)',
|
|
11
|
+
inputSchema: { type: 'object', properties: { type: { type: 'string' }, stage: { type: 'string' } }, additionalProperties: false },
|
|
12
|
+
query: (input = {}) => service.listProjects(input),
|
|
13
|
+
},
|
|
14
|
+
getProject: {
|
|
15
|
+
description: '单项目完整实体',
|
|
16
|
+
inputSchema: { type: 'object', properties: { projectId: { type: 'string' } }, required: ['projectId'], additionalProperties: false },
|
|
17
|
+
query: (input) => service.getProject(input.projectId) ?? null,
|
|
18
|
+
},
|
|
19
|
+
listTemplates: {
|
|
20
|
+
description: '流水线模板含 steps',
|
|
21
|
+
inputSchema: { type: 'object', properties: {}, additionalProperties: false },
|
|
22
|
+
query: () => service.store.list('templates'),
|
|
23
|
+
},
|
|
24
|
+
getRun: {
|
|
25
|
+
description: '发布 run 全量',
|
|
26
|
+
inputSchema: { type: 'object', properties: { runId: { type: 'string' } }, required: ['runId'], additionalProperties: false },
|
|
27
|
+
query: (input) => service.store.readRun(input.runId) ?? null,
|
|
28
|
+
},
|
|
29
|
+
listChannels: {
|
|
30
|
+
description: '渠道 + 材料模板',
|
|
31
|
+
inputSchema: { type: 'object', properties: {}, additionalProperties: false },
|
|
32
|
+
query: () => service.store.list('channels'),
|
|
33
|
+
},
|
|
34
|
+
getMarketReport: {
|
|
35
|
+
description: '项目竞品研判报告',
|
|
36
|
+
inputSchema: { type: 'object', properties: { projectId: { type: 'string' } }, required: ['projectId'], additionalProperties: false },
|
|
37
|
+
query: (input) => service.store.readMarketReport(input.projectId) ?? null,
|
|
38
|
+
},
|
|
39
|
+
listMarketGaps: {
|
|
40
|
+
description: '市场空白机会清单',
|
|
41
|
+
inputSchema: { type: 'object', properties: { channelIds: { type: 'array', items: { type: 'string' } } }, additionalProperties: false },
|
|
42
|
+
query: (input = {}) => {
|
|
43
|
+
const gaps = service.store.list('market-gaps')
|
|
44
|
+
return input.channelIds ? gaps.filter(g => g.channelIds.some(c => input.channelIds.includes(c))) : gaps
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
storeSchema: {
|
|
48
|
+
description: '当前 schemaVersion + 实体/集合目录',
|
|
49
|
+
inputSchema: { type: 'object', properties: {}, additionalProperties: false },
|
|
50
|
+
query: () => ({ schemaVersion: SCHEMA_VERSION, collections: Object.keys(collections) }),
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// M5 · listing_*/channel_* Agent 工具(06§2)。集成时由 lead 并入 buildTools。
|
|
2
|
+
import { inputs } from './schemas.js'
|
|
3
|
+
|
|
4
|
+
const ok = data => ({ ok: true, data })
|
|
5
|
+
const fail = e => ({ ok: false, error: { code: e.code || 'ERROR', message: String(e.message || e) } })
|
|
6
|
+
const guard = (schema, args, fn) => {
|
|
7
|
+
const p = schema.safeParse(args || {})
|
|
8
|
+
if (!p.success) return fail({ code: 'INVALID_INPUT', message: p.error.issues.map(i => `${i.path.join('.')}: ${i.message}`).join('; ') })
|
|
9
|
+
return Promise.resolve(fn(p.data)).then(ok, fail)
|
|
10
|
+
}
|
|
11
|
+
const need = service => { if (!service.listing) throw { code: 'NOT_READY', message: 'listing 未挂载' }; return service.listing }
|
|
12
|
+
|
|
13
|
+
export function buildListingTools(service, opts = {}) {
|
|
14
|
+
const candidatesPath = opts.candidatesPath || 'E:\\项目管家\\data\\channel-candidates.json'
|
|
15
|
+
return [
|
|
16
|
+
{
|
|
17
|
+
name: 'steward_listing_create',
|
|
18
|
+
description: '创建上架记录(project×channel×release → draft)。',
|
|
19
|
+
parameters: { type: 'object', properties: { projectId: { type: 'string' }, channelId: { type: 'string' }, releaseId: { type: 'string' } }, required: ['projectId', 'channelId', 'releaseId'], additionalProperties: false },
|
|
20
|
+
execute: async args => guard(inputs.listingCreate, args, d => need(service).createListing(d, 'agent')),
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: 'steward_listing_check',
|
|
24
|
+
description: '核对上架材料齐备性。只读核对并写回。',
|
|
25
|
+
parameters: { type: 'object', properties: { listingId: { type: 'string' } }, required: ['listingId'], additionalProperties: false },
|
|
26
|
+
execute: async args => guard(inputs.listingUpdate.pick({ listingId: true }), args, d => need(service).checkMaterials(d.listingId, 'agent')),
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: 'steward_listing_update',
|
|
30
|
+
description: '迁移上架状态(draft→submitted→reviewing→listed/rejected→delisted)。',
|
|
31
|
+
parameters: { type: 'object', properties: { listingId: { type: 'string' }, to: { type: 'string' }, note: { type: 'string' }, platformUrl: { type: 'string' } }, required: ['listingId', 'to'], additionalProperties: false },
|
|
32
|
+
execute: async args => guard(inputs.listingUpdate, args, d => need(service).transitionListing(d.listingId, d.to, { actor: 'agent', note: d.note, platformUrl: d.platformUrl })),
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'steward_channel_add',
|
|
36
|
+
description: '注册发布渠道。',
|
|
37
|
+
parameters: { type: 'object', properties: { name: { type: 'string' }, category: { type: 'string' }, url: { type: 'string' } }, required: ['name', 'category'], additionalProperties: false },
|
|
38
|
+
execute: async args => guard(inputs.channelAdd, args, d => need(service).registerChannel(d, 'agent')),
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: 'steward_channel_update',
|
|
42
|
+
description: '修改渠道(类别变更触发材料重核)。',
|
|
43
|
+
parameters: { type: 'object', properties: { channelId: { type: 'string' }, patch: { type: 'object' } }, required: ['channelId', 'patch'], additionalProperties: false },
|
|
44
|
+
execute: async args => guard(inputs.channelUpdate, args, d => need(service).updateChannel(d.channelId, d.patch, 'agent')),
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: 'steward_channel_remove',
|
|
48
|
+
description: '软删除渠道(G4,必填 reason;有 active 上架须先 delist)。',
|
|
49
|
+
parameters: { type: 'object', properties: { channelId: { type: 'string' }, reason: { type: 'string' } }, required: ['channelId', 'reason'], additionalProperties: false },
|
|
50
|
+
execute: async args => guard(inputs.channelRemove, args, d => need(service).removeChannel(d.channelId, d.reason, 'agent')),
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'steward_channel_get',
|
|
54
|
+
description: '查询渠道(含关联上架计数)。只读。',
|
|
55
|
+
parameters: { type: 'object', properties: { channelId: { type: 'string' } }, required: ['channelId'], additionalProperties: false },
|
|
56
|
+
execute: async args => {
|
|
57
|
+
const ch = need(service).getChannel(args.channelId)
|
|
58
|
+
if (!ch) return fail({ code: 'NOT_FOUND', message: `渠道 ${args.channelId} 不存在` })
|
|
59
|
+
const listings = service.store.list('listings').filter(l => l.channelId === args.channelId)
|
|
60
|
+
return ok({ ...ch, listingCount: listings.length, activeListings: listings.filter(l => ['submitted', 'reviewing', 'listed'].includes(l.status)).length })
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: 'steward_channel_import',
|
|
65
|
+
description: '从全球候选库导入渠道(grade=X 内容类拒绝;幂等)。',
|
|
66
|
+
parameters: { type: 'object', properties: { candidateIds: { type: 'array', items: { type: 'string' } } }, required: ['candidateIds'], additionalProperties: false },
|
|
67
|
+
execute: async args => guard(inputs.channelImport, args, d => need(service).importCandidates(d.candidateIds, candidatesPath, 'agent')),
|
|
68
|
+
},
|
|
69
|
+
]
|
|
70
|
+
}
|
package/src/listing.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// M5 · Listing 上架状态机 + 渠道 CRUD(03§7.3/§7.4 / 17§7)。
|
|
2
|
+
import { listingTransitions, channelTransitions, Listing, Channel } from './schemas.js'
|
|
3
|
+
import { genId, storeError } from './store.js'
|
|
4
|
+
import { readFileSync, existsSync } from 'node:fs'
|
|
5
|
+
import { join } from 'node:path'
|
|
6
|
+
|
|
7
|
+
const now = () => new Date().toISOString()
|
|
8
|
+
const ACTIVE = ['submitted', 'reviewing', 'listed']
|
|
9
|
+
|
|
10
|
+
export class ListingMgr {
|
|
11
|
+
constructor(service) { this.service = service; this.store = service.store }
|
|
12
|
+
|
|
13
|
+
// ---- listing ----
|
|
14
|
+
async createListing({ projectId, channelId, releaseId }, actor = 'agent') {
|
|
15
|
+
const project = this.service.getProject(projectId)
|
|
16
|
+
if (!project) throw storeError('NOT_FOUND', `项目 ${projectId} 不存在`)
|
|
17
|
+
const channel = this.store.get('channels', channelId)
|
|
18
|
+
if (!channel) throw storeError('NOT_FOUND', `渠道 ${channelId} 不存在`)
|
|
19
|
+
const release = this.store.get('releases', releaseId)
|
|
20
|
+
if (!release || release.projectId !== projectId) throw storeError('INVALID_INPUT', 'release 不存在或不属于该项目')
|
|
21
|
+
if (this.store.list('listings').some(l => l.projectId === projectId && l.channelId === channelId && l.releaseId === releaseId)) throw storeError('DUPLICATE', '该 project×channel×release 已有上架记录')
|
|
22
|
+
const listing = {
|
|
23
|
+
id: genId('lst'), projectId, channelId, releaseId, status: 'draft',
|
|
24
|
+
materials: (channel.materialTemplate || []).map(m => ({ key: m.key, ok: false })),
|
|
25
|
+
history: [], createdAt: now(), updatedAt: now(),
|
|
26
|
+
}
|
|
27
|
+
return this.store.create('listings', Listing.parse(listing), actor, 'listing-create')
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async checkMaterials(listingId, actor = 'agent') {
|
|
31
|
+
const l = this.store.get('listings', listingId)
|
|
32
|
+
if (!l) throw storeError('NOT_FOUND', `listing ${listingId} 不存在`)
|
|
33
|
+
const channel = this.store.get('channels', l.channelId)
|
|
34
|
+
const project = this.service.getProject(l.projectId)
|
|
35
|
+
const tpl = channel?.materialTemplate || []
|
|
36
|
+
const states = tpl.map(m => {
|
|
37
|
+
const prev = l.materials.find(x => x.key === m.key)
|
|
38
|
+
const ref = prev?.ref
|
|
39
|
+
let ok = false
|
|
40
|
+
if (m.kind === 'file') ok = !!ref && existsSync(join(project.rootPath, ref))
|
|
41
|
+
else if (m.kind === 'text' || m.kind === 'url') ok = !!ref && String(ref).trim().length > 0
|
|
42
|
+
else if (m.kind === 'bool') ok = ref === true || ref === 'true'
|
|
43
|
+
return { key: m.key, ok, ref, checkedAt: now() }
|
|
44
|
+
})
|
|
45
|
+
return this.store.update('listings', listingId, d => { d.materials = states; d.updatedAt = now() }, actor, 'materials-check')
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async transitionListing(listingId, to, { actor = 'agent', note, platformUrl, waive } = {}) {
|
|
49
|
+
const l = this.store.get('listings', listingId)
|
|
50
|
+
if (!l) throw storeError('NOT_FOUND', `listing ${listingId} 不存在`)
|
|
51
|
+
const allowed = listingTransitions[l.status] || []
|
|
52
|
+
if (!allowed.includes(to)) throw storeError('ILLEGAL_TRANSITION', `上架不允许 ${l.status} → ${to}`)
|
|
53
|
+
if (to === 'submitted') {
|
|
54
|
+
const channel = this.store.get('channels', l.channelId)
|
|
55
|
+
const required = (channel?.materialTemplate || []).filter(m => m.required)
|
|
56
|
+
const missing = required.filter(m => !l.materials.find(x => x.key === m.key && x.ok))
|
|
57
|
+
if (missing.length && !waive) throw storeError('INVALID_INPUT', `required 材料缺项:${missing.map(m => m.key).join(',')}(或 waive)`)
|
|
58
|
+
}
|
|
59
|
+
if ((to === 'delisted') && !note) throw storeError('INVALID_INPUT', '下架需 note(G3)')
|
|
60
|
+
const from = l.status
|
|
61
|
+
const updated = await this.store.update('listings', listingId, d => {
|
|
62
|
+
d.status = to; d.updatedAt = now()
|
|
63
|
+
if (platformUrl) d.platformUrl = platformUrl
|
|
64
|
+
d.history.push({ from, to, at: now(), actor, note })
|
|
65
|
+
}, actor, 'listing-transition', note)
|
|
66
|
+
if (to === 'listed') {
|
|
67
|
+
await this.service.transitionStage(l.projectId, 'listed', actor, '首次上架').catch(() => {})
|
|
68
|
+
await this.store.create('events', { id: genId('ev'), projectId: l.projectId, listingId, kind: 'milestone', severity: 'info', text: `上架成功:${l.channelId}`, at: now() }, actor, 'milestone').catch(() => {})
|
|
69
|
+
this.service._broadcast({ type: 'steward/listing-listed', listingId, projectId: l.projectId, channelId: l.channelId })
|
|
70
|
+
}
|
|
71
|
+
return updated
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// ---- channel CRUD ----
|
|
75
|
+
listChannels(filter) {
|
|
76
|
+
let arr = this.store.list('channels')
|
|
77
|
+
if (filter?.category) arr = arr.filter(c => c.category === filter.category)
|
|
78
|
+
if (filter?.status) arr = arr.filter(c => c.status === filter.status)
|
|
79
|
+
if (filter?.appliesToType) arr = arr.filter(c => (c.appliesToTypes || []).includes(filter.appliesToType))
|
|
80
|
+
return arr
|
|
81
|
+
}
|
|
82
|
+
getChannel(id) { return this.store.get('channels', id) }
|
|
83
|
+
|
|
84
|
+
async registerChannel(input, actor = 'user') {
|
|
85
|
+
if (this.store.list('channels').some(c => c.name === input.name)) throw storeError('DUPLICATE', `渠道名已存在:${input.name}`)
|
|
86
|
+
const ch = { id: genId('ch'), name: input.name, category: input.category, status: 'active', source: 'user', materialTemplate: input.materialTemplate || [], credentialRef: input.credentialRef || null, url: input.url, appliesToTypes: input.appliesToTypes || [], activatedAt: now() }
|
|
87
|
+
return this.store.create('channels', Channel.parse(ch), actor, 'channel-add')
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async updateChannel(id, patch, actor = 'user') {
|
|
91
|
+
const before = this.store.get('channels', id)
|
|
92
|
+
if (!before) throw storeError('NOT_FOUND', `渠道 ${id} 不存在`)
|
|
93
|
+
const categoryChanged = patch.category && patch.category !== before.category
|
|
94
|
+
const updated = await this.store.update('channels', id, d => { Object.assign(d, patch) }, actor, 'channel-update')
|
|
95
|
+
if (categoryChanged) this.service._broadcast({ type: 'steward/channel-category-changed', channelId: id, recheck: true })
|
|
96
|
+
return updated
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async removeChannel(id, reason, actor = 'user') {
|
|
100
|
+
if (!reason) throw storeError('INVALID_INPUT', '软删除需 reason(G4)')
|
|
101
|
+
const ch = this.store.get('channels', id)
|
|
102
|
+
if (!ch) throw storeError('NOT_FOUND', `渠道 ${id} 不存在`)
|
|
103
|
+
const active = this.store.list('listings').filter(l => l.channelId === id && ACTIVE.includes(l.status))
|
|
104
|
+
if (active.length) throw storeError('ILLEGAL_TRANSITION', `渠道有 ${active.length} 个 active 上架,须先 delist 再删除`)
|
|
105
|
+
return this.store.update('channels', id, d => { d.status = 'removed'; d.removedAt = now(); d.removeReason = reason }, actor, 'channel-remove', reason)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async importCandidates(candidateIds, candidatesPath, actor = 'user') {
|
|
109
|
+
let candidates = []
|
|
110
|
+
try { candidates = JSON.parse(readFileSync(candidatesPath, 'utf8')).candidates || [] } catch { throw storeError('NOT_FOUND', '候选库不可读') }
|
|
111
|
+
const imported = []
|
|
112
|
+
for (const cid of candidateIds) {
|
|
113
|
+
const cand = candidates.find(c => c.id === cid)
|
|
114
|
+
if (!cand) throw storeError('NOT_FOUND', `候选 ${cid} 不存在`)
|
|
115
|
+
if (cand.grade === 'X') throw storeError('INVALID_INPUT', `候选 ${cid} 超出范围(内容类),拒绝导入`)
|
|
116
|
+
if (this.store.list('channels').some(c => c.name === cand.name)) continue // 幂等
|
|
117
|
+
const ch = { id: genId('ch'), name: cand.name, category: cand.category, status: 'candidate', source: 'catalog', grade: cand.grade, activationCondition: cand.activationCondition, url: cand.url, appliesToTypes: cand.appliesToTypes || [], materialTemplate: [] }
|
|
118
|
+
imported.push(await this.store.create('channels', Channel.parse(ch), actor, 'channel-import'))
|
|
119
|
+
}
|
|
120
|
+
return imported
|
|
121
|
+
}
|
|
122
|
+
}
|