@clawdao/limschain-agent 0.5.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.
- package/.env.example +41 -0
- package/CHANGELOG.md +223 -0
- package/Dockerfile +50 -0
- package/LICENSE +21 -0
- package/README.md +627 -0
- package/bin/lims-mcp.mjs +101 -0
- package/bin/lims.mjs +1639 -0
- package/docs/MARKETPLACE-GUIDELINES.md +99 -0
- package/docs/clawdao-mcp-listing.md +308 -0
- package/docs/clawdao-mcp-setup.md +294 -0
- package/docs/ddn-hub-postType-issue.md +54 -0
- package/docs/deploy-http.md +192 -0
- package/docs/install-mcp.md +268 -0
- package/docs/limschain-migration-and-readme-backfill.md +212 -0
- package/docs/marketplace-readmes/clawdao-video-factory.md +49 -0
- package/docs/node-free-install.md +196 -0
- package/docs/release-notes/v1.0.30-short.md +63 -0
- package/docs/site-design-studio-api.md +162 -0
- package/lib/articles.mjs +397 -0
- package/lib/client.mjs +588 -0
- package/lib/courses.mjs +169 -0
- package/lib/dao.mjs +195 -0
- package/lib/env.mjs +32 -0
- package/lib/feedback.mjs +68 -0
- package/lib/http-server.mjs +257 -0
- package/lib/marketplace-readme-path.mjs +17 -0
- package/lib/marketplace.mjs +273 -0
- package/lib/materials.mjs +260 -0
- package/lib/mcp-server.mjs +334 -0
- package/lib/site.mjs +471 -0
- package/lib/versions.mjs +904 -0
- package/mcp-listing.http.json +25 -0
- package/mcp-listing.json +34 -0
- package/package.json +77 -0
- package/scripts/build-binary.mjs +104 -0
- package/scripts/build-site-dashboard.mjs +52 -0
- package/scripts/collect-site-articles.mjs +432 -0
- package/scripts/export-ddn-env.mjs +107 -0
- package/scripts/fetch-article-stats.mjs +212 -0
- package/scripts/pack-and-verify.mjs +111 -0
- package/scripts/publisher.mjs +255 -0
- package/scripts/sync-marketplace-readme.mjs +380 -0
- package/scripts/tool-set.mjs +48 -0
- package/scripts/verify-binary.mjs +115 -0
- package/scripts/verify-clawdao-bridge.mjs +41 -0
- package/scripts/verify-e2e.mjs +176 -0
- package/scripts/verify-http-mcp.mjs +94 -0
- package/scripts/verify-listing-sync.mjs +90 -0
- package/scripts/verify-marketplace-readme.mjs +266 -0
- package/scripts/verify-mcp-handshake.mjs +98 -0
- package/scripts/verify-news-publish.mjs +257 -0
- package/scripts/verify-npx-install.mjs +171 -0
- package/scripts/verify-site-dashboard.mjs +87 -0
- package/scripts/verify-site-layout.mjs +194 -0
- package/tests/client-auth.test.mjs +159 -0
- package/tests/dao-profile.test.mjs +126 -0
- package/tests/marketplace-readme-path.test.mjs +16 -0
- package/tests/mcp-server.test.mjs +187 -0
- package/tests/member-submission.test.mjs +150 -0
- package/tests/official-listing.test.mjs +52 -0
- package/tests/smoke.mjs +262 -0
- package/tests/sync-marketplace-readme.test.mjs +50 -0
- package/tests/tool-set.test.mjs +54 -0
- package/tests/versions-sync-dryrun.test.mjs +315 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* scripts/sync-marketplace-readme.mjs — 应用市场 README / 开源协议 补齐
|
|
4
|
+
* ============================================================================
|
|
5
|
+
*
|
|
6
|
+
* **它解决什么**
|
|
7
|
+
* 应用市场详情页正文读的是 `marketplace_asset.readme`(前端 admin/src/pages/
|
|
8
|
+
* Marketplace/detail.tsx 直接渲染 asset.readme,为空就显示空状态)。
|
|
9
|
+
* 平台**不会**自动去仓库抓 README —— readme 是建档时由发布者手填的字段,
|
|
10
|
+
* 所以第三方开源项目一旦建档时漏填,详情页就永远是空的。
|
|
11
|
+
*
|
|
12
|
+
* **做什么**
|
|
13
|
+
* 1. 拉应用市场资产列表(管理端接口,需要 canManageSystem;无权限时退回公开列表)
|
|
14
|
+
* 2. 找出 readme 为空 / 过短的资产
|
|
15
|
+
* 3. 按 sourceUrl 反查源仓库:
|
|
16
|
+
* github.com/{owner}/{repo} → GitHub API(README + SPDX 协议)
|
|
17
|
+
* → 失败时回退 raw.githubusercontent.com
|
|
18
|
+
* gitee.com/{owner}/{repo} → Gitee raw
|
|
19
|
+
* 仓库不存在 / 不可公开 → 本地文案目录 docs/marketplace-readmes/<slug>.md
|
|
20
|
+
* 4. 用管理端更新接口写回 readme(+ license)
|
|
21
|
+
*
|
|
22
|
+
* **用法**
|
|
23
|
+
* node scripts/sync-marketplace-readme.mjs --dry-run # 只预览,不写
|
|
24
|
+
* node scripts/sync-marketplace-readme.mjs # 真写
|
|
25
|
+
* node scripts/sync-marketplace-readme.mjs --only html-video --json
|
|
26
|
+
*
|
|
27
|
+
* **选项**
|
|
28
|
+
* --dry-run 只打印将要写的内容,不调用写接口
|
|
29
|
+
* --only <slug> 只处理某个 slug(可重复)
|
|
30
|
+
* --json 输出 JSON(便于脚本化)
|
|
31
|
+
* --base-url <url> 覆盖 API 地址(默认读 .env 的 DDN_HUB_BASE_URL)
|
|
32
|
+
* --min-length <n> 小于该字符数视为缺失(默认 50)
|
|
33
|
+
* --local-dir <dir> 本地文案目录(默认 docs/marketplace-readmes)
|
|
34
|
+
*
|
|
35
|
+
* **凭证**
|
|
36
|
+
* 需要 .env 里的 DDN_HUB_AUTH_TOKEN。写入资产需要平台管理员(canManageSystem);
|
|
37
|
+
* GitHub API 未登录时每小时 60 次 / IP,触发限流会自动回退 raw 取文。
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
import { readFileSync, existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
41
|
+
import { resolve, dirname } from 'node:path';
|
|
42
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
43
|
+
|
|
44
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
45
|
+
const ROOT = resolve(__dirname, '..');
|
|
46
|
+
|
|
47
|
+
// ---- .env 加载(与 bin/lims.mjs 一致:只补缺失项) ----
|
|
48
|
+
const ENV_PATH = resolve(ROOT, '.env');
|
|
49
|
+
try {
|
|
50
|
+
if (existsSync(ENV_PATH)) {
|
|
51
|
+
for (const line of readFileSync(ENV_PATH, 'utf-8').split(/\r?\n/)) {
|
|
52
|
+
const trimmed = line.trim();
|
|
53
|
+
if (!trimmed || trimmed.startsWith('#') || !trimmed.includes('=')) continue;
|
|
54
|
+
const eq = trimmed.indexOf('=');
|
|
55
|
+
const key = trimmed.slice(0, eq).trim();
|
|
56
|
+
const val = trimmed.slice(eq + 1).trim().replace(/^['"]|['"]$/g, '');
|
|
57
|
+
if (key && process.env[key] === undefined) process.env[key] = val;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
} catch { /* .env 缺失时忽略 */ }
|
|
61
|
+
|
|
62
|
+
const { LimsClient } = await import('../lib/client.mjs');
|
|
63
|
+
const { MarketplaceManager } = await import('../lib/marketplace.mjs');
|
|
64
|
+
const { resolveMarketplaceReadmePath } = await import('../lib/marketplace-readme-path.mjs');
|
|
65
|
+
|
|
66
|
+
const CACHE_DIR = resolve(ROOT, 'tmp', 'marketplace-readme');
|
|
67
|
+
const DEFAULT_LOCAL_DIR = resolve(ROOT, 'docs', 'marketplace-readmes');
|
|
68
|
+
const USER_AGENT = '@lims/lims-agent/0.1.0';
|
|
69
|
+
|
|
70
|
+
function parseArgs(argv) {
|
|
71
|
+
const opts = {
|
|
72
|
+
dryRun: false, json: false, only: [], minLength: 50, baseUrl: '',
|
|
73
|
+
localDir: DEFAULT_LOCAL_DIR,
|
|
74
|
+
};
|
|
75
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
76
|
+
const a = argv[i];
|
|
77
|
+
if (a === '--dry-run') opts.dryRun = true;
|
|
78
|
+
else if (a === '--json') opts.json = true;
|
|
79
|
+
else if (a === '--only') opts.only.push(argv[++i]);
|
|
80
|
+
else if (a === '--base-url') opts.baseUrl = argv[++i];
|
|
81
|
+
else if (a === '--min-length') opts.minLength = parseInt(argv[++i], 10);
|
|
82
|
+
else if (a === '--local-dir') opts.localDir = resolve(ROOT, argv[++i]);
|
|
83
|
+
else if (a === '--help' || a === '-h') { printHelp(); process.exit(0); }
|
|
84
|
+
}
|
|
85
|
+
return opts;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function printHelp() {
|
|
89
|
+
console.log(`用法: node scripts/sync-marketplace-readme.mjs [选项]
|
|
90
|
+
|
|
91
|
+
--dry-run 只预览不写
|
|
92
|
+
--only <slug> 只处理指定 slug(可重复)
|
|
93
|
+
--json 输出 JSON
|
|
94
|
+
--base-url <url> 覆盖 API 地址
|
|
95
|
+
--min-length <n> 小于该长度视为缺失(默认 50)
|
|
96
|
+
--local-dir <dir> 本地文案目录(默认 docs/marketplace-readmes)`);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** 解析 sourceUrl → { host, owner, repo } */
|
|
100
|
+
function parseRepoUrl(sourceUrl) {
|
|
101
|
+
if (!sourceUrl) return null;
|
|
102
|
+
let u;
|
|
103
|
+
try { u = new URL(sourceUrl); } catch { return null; }
|
|
104
|
+
const seg = u.pathname.split('/').filter(Boolean);
|
|
105
|
+
if (seg.length < 2) return null;
|
|
106
|
+
const host = u.hostname.replace(/^www\./, '');
|
|
107
|
+
if (host !== 'github.com' && host !== 'gitee.com') return null;
|
|
108
|
+
return { host, owner: seg[0], repo: seg[1].replace(/\.git$/, '') };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const fetchText = async (url, headers = {}) => {
|
|
112
|
+
const res = await fetch(url, { headers: { 'User-Agent': USER_AGENT, ...headers } });
|
|
113
|
+
if (!res.ok) {
|
|
114
|
+
const err = new Error(`HTTP ${res.status}`);
|
|
115
|
+
err.status = res.status;
|
|
116
|
+
throw err;
|
|
117
|
+
}
|
|
118
|
+
return res.text();
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const fetchTextSafe = async (url, headers = {}) => {
|
|
122
|
+
try { return await fetchText(url, headers); }
|
|
123
|
+
catch { return null; }
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/** 从 LICENSE 文本识别 SPDX 标识(识别不出就返回 null,不编造) */
|
|
127
|
+
function detectSpdx(text) {
|
|
128
|
+
if (!text) return null;
|
|
129
|
+
const t = text.slice(0, 4000);
|
|
130
|
+
if (/apache license/i.test(t) && /version 2\.0/i.test(t)) return 'Apache-2.0';
|
|
131
|
+
if (/gnu affero general public license/i.test(t)) return 'AGPL-3.0';
|
|
132
|
+
if (/gnu lesser general public license/i.test(t)) return 'LGPL-3.0';
|
|
133
|
+
if (/gnu general public license/i.test(t)) {
|
|
134
|
+
return /version 3/i.test(t) ? 'GPL-3.0' : /version 2/i.test(t) ? 'GPL-2.0' : 'GPL';
|
|
135
|
+
}
|
|
136
|
+
if (/mit license|permission is hereby granted, free of charge/i.test(t)) return 'MIT';
|
|
137
|
+
if (/redistributions of source code must retain/i.test(t) && /neither the name/i.test(t)) return 'BSD-3-Clause';
|
|
138
|
+
if (/mozilla public license/i.test(t)) return 'MPL-2.0';
|
|
139
|
+
if (/the unlicense|this is free and unencumbered/i.test(t)) return 'Unlicense';
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const README_NAMES = ['README.md', 'readme.md', 'Readme.md', 'README.MD', 'README.markdown'];
|
|
144
|
+
const LICENSE_NAMES = ['LICENSE', 'LICENSE.md', 'LICENSE.txt', 'LICENSE-MIT', 'LICENSE-APACHE', 'COPYING'];
|
|
145
|
+
|
|
146
|
+
/** GitHub:README(base64)+ SPDX 协议 */
|
|
147
|
+
async function fetchGithubReadme({ owner, repo }, ref) {
|
|
148
|
+
const headers = { Accept: 'application/vnd.github+json' };
|
|
149
|
+
if (process.env.GITHUB_TOKEN) headers.Authorization = `Bearer ${process.env.GITHUB_TOKEN}`;
|
|
150
|
+
|
|
151
|
+
const attempt = async (r) => {
|
|
152
|
+
const url = new URL(`https://api.github.com/repos/${owner}/${repo}/readme`);
|
|
153
|
+
if (r) url.searchParams.set('ref', r);
|
|
154
|
+
const body = JSON.parse(await fetchText(url, headers));
|
|
155
|
+
const readme = Buffer.from(body.content || '', body.encoding === 'base64' ? 'base64' : 'utf8').toString('utf8');
|
|
156
|
+
return { readme, license: body.license?.spdx_id || null, ref: body.name };
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
try {
|
|
160
|
+
let out = null;
|
|
161
|
+
if (ref) {
|
|
162
|
+
try { out = await attempt(ref); }
|
|
163
|
+
catch (e) { if (e.status !== 404) throw e; }
|
|
164
|
+
}
|
|
165
|
+
if (!out) out = await attempt(null);
|
|
166
|
+
// README 接口不一定带 license,回落到仓库元数据
|
|
167
|
+
if (!out.license) {
|
|
168
|
+
try {
|
|
169
|
+
const meta = JSON.parse(await fetchText(`https://api.github.com/repos/${owner}/${repo}`, headers));
|
|
170
|
+
out.license = meta.license?.spdx_id || null;
|
|
171
|
+
} catch { /* 拿不到就算了,不编造协议 */ }
|
|
172
|
+
}
|
|
173
|
+
return out;
|
|
174
|
+
} catch (e) {
|
|
175
|
+
if (e.status === 404) return null;
|
|
176
|
+
throw e;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** GitHub raw 回退:API 限流 / 403 时直接取原文(不受 API 配额限制) */
|
|
181
|
+
async function fetchGithubRaw({ owner, repo }, ref) {
|
|
182
|
+
const refs = [ref, 'main', 'master'].filter(Boolean);
|
|
183
|
+
for (const r of refs) {
|
|
184
|
+
for (const name of README_NAMES) {
|
|
185
|
+
const readme = await fetchTextSafe(`https://raw.githubusercontent.com/${owner}/${repo}/${r}/${name}`);
|
|
186
|
+
if (readme && readme.trim()) {
|
|
187
|
+
let license = null;
|
|
188
|
+
for (const lname of LICENSE_NAMES) {
|
|
189
|
+
const lic = await fetchTextSafe(`https://raw.githubusercontent.com/${owner}/${repo}/${r}/${lname}`);
|
|
190
|
+
if (lic && lic.trim()) { license = detectSpdx(lic); break; }
|
|
191
|
+
}
|
|
192
|
+
return { readme, license, ref: `${r}/${name}` };
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** Gitee:raw README(无 API 鉴权时也可能被限流,失败即跳过) */
|
|
200
|
+
async function fetchGiteeReadme({ owner, repo }, ref) {
|
|
201
|
+
const branches = [ref, 'master', 'main'].filter(Boolean);
|
|
202
|
+
for (const b of branches) {
|
|
203
|
+
for (const name of README_NAMES) {
|
|
204
|
+
try {
|
|
205
|
+
const readme = await fetchText(`https://gitee.com/${owner}/${repo}/raw/${b}/${name}`);
|
|
206
|
+
if (readme && readme.trim()) return { readme, license: null, ref: `${b}/${name}` };
|
|
207
|
+
} catch { /* 换下一个分支/文件名 */ }
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* 本地文案目录:docs/marketplace-readmes/<slug>.md
|
|
215
|
+
* 文件头可带 YAML front matter(slug / license / source / note),写入前会剥掉。
|
|
216
|
+
*/
|
|
217
|
+
function readLocalReadme(localDir, slug) {
|
|
218
|
+
if (!localDir) return null;
|
|
219
|
+
const file = resolveMarketplaceReadmePath(localDir, slug);
|
|
220
|
+
if (!existsSync(file)) return null;
|
|
221
|
+
const raw = readFileSync(file, 'utf-8');
|
|
222
|
+
const meta = {};
|
|
223
|
+
const fm = raw.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n?/);
|
|
224
|
+
let body = raw;
|
|
225
|
+
if (fm) {
|
|
226
|
+
body = raw.slice(fm[0].length);
|
|
227
|
+
for (const line of fm[1].split(/\r?\n/)) {
|
|
228
|
+
const i = line.indexOf(':');
|
|
229
|
+
if (i > 0) meta[line.slice(0, i).trim()] = line.slice(i + 1).trim();
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (!body.trim()) return null;
|
|
233
|
+
return { readme: body, license: meta.license || null, ref: `local:${slug}.md`, origin: 'local' };
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** 取 README:仓库优先(API → raw),取不到再用本地文案 */
|
|
237
|
+
export async function fetchReadme(asset, opts) {
|
|
238
|
+
const repo = parseRepoUrl(asset.sourceUrl);
|
|
239
|
+
const ref = asset.version && /^[A-Za-z0-9._\-/]+$/.test(asset.version) ? asset.version : null;
|
|
240
|
+
|
|
241
|
+
if (repo?.host === 'github.com') {
|
|
242
|
+
try {
|
|
243
|
+
const got = await fetchGithubReadme(repo, ref);
|
|
244
|
+
if (got) return { ...got, origin: 'github-api' };
|
|
245
|
+
} catch { /* 限流 / 网络异常 → 走 raw 回退 */ }
|
|
246
|
+
|
|
247
|
+
try {
|
|
248
|
+
const raw = await fetchGithubRaw(repo, ref);
|
|
249
|
+
if (raw) return { ...raw, origin: 'github-raw' };
|
|
250
|
+
} catch { /* 忽略 */ }
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (repo?.host === 'gitee.com') {
|
|
254
|
+
const got = await fetchGiteeReadme(repo, ref);
|
|
255
|
+
if (got) return { ...got, origin: 'gitee' };
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const local = readLocalReadme(opts.localDir, asset.slug);
|
|
259
|
+
if (local) return local;
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export async function updateMarketplaceReadme(mp, asset, got, dryRun) {
|
|
264
|
+
const license = got.license || asset.license || null;
|
|
265
|
+
const payload = { readme: got.readme };
|
|
266
|
+
if (license && !asset.license) payload.license = license;
|
|
267
|
+
|
|
268
|
+
if (dryRun) return { status: 'dry_run', length: got.readme.length, license };
|
|
269
|
+
|
|
270
|
+
const res = await mp.update(asset.uuid, payload);
|
|
271
|
+
if (res.ok) return { status: 'updated', length: got.readme.length, license };
|
|
272
|
+
return {
|
|
273
|
+
status: 'failed',
|
|
274
|
+
message: res.message || JSON.stringify(res.error),
|
|
275
|
+
statusCode: res.statusCode || null,
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** 拉资产列表:优先管理端(含草稿等全状态),无平台管理员权限时退回公开列表 */
|
|
280
|
+
async function listAssets(mp, opts) {
|
|
281
|
+
const admin = await mp.listAdmin({ page: 1, pageSize: 200 });
|
|
282
|
+
if (admin.ok) return { items: admin.items || [], total: admin.total || 0, scope: 'admin', error: null };
|
|
283
|
+
|
|
284
|
+
const pub = await mp.list({ page: 1, pageSize: 200 });
|
|
285
|
+
if (pub.ok) {
|
|
286
|
+
return { items: pub.items || [], total: pub.total || 0, scope: 'public', error: admin.message || admin.error?.message || null };
|
|
287
|
+
}
|
|
288
|
+
return { items: [], total: 0, scope: 'none', error: pub.message || admin.message || '未知错误' };
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
async function main() {
|
|
292
|
+
const opts = parseArgs(process.argv.slice(2));
|
|
293
|
+
|
|
294
|
+
const client = new LimsClient({
|
|
295
|
+
baseUrl: opts.baseUrl || process.env.DDN_HUB_BASE_URL || undefined,
|
|
296
|
+
authToken: process.env.DDN_HUB_AUTH_TOKEN,
|
|
297
|
+
daoId: process.env.DDN_HUB_DAO_ID,
|
|
298
|
+
});
|
|
299
|
+
const cfg = client.getConfig();
|
|
300
|
+
if (!cfg.authToken) {
|
|
301
|
+
console.error('❌ 缺 DDN_HUB_AUTH_TOKEN(应用市场写入需要平台管理员 token)');
|
|
302
|
+
process.exit(1);
|
|
303
|
+
}
|
|
304
|
+
const mp = new MarketplaceManager(client);
|
|
305
|
+
|
|
306
|
+
const listed = await listAssets(mp, opts);
|
|
307
|
+
if (!listed.items.length) {
|
|
308
|
+
console.error(`❌ 拉取资产列表失败:${listed.error || '空列表'}`);
|
|
309
|
+
process.exit(1);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const targets = listed.items.filter((it) => {
|
|
313
|
+
if (opts.only.length && !opts.only.includes(it.slug)) return false;
|
|
314
|
+
return String(it.readme || '').trim().length < opts.minLength;
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
if (opts.json) {
|
|
318
|
+
const out = [];
|
|
319
|
+
for (const asset of targets) {
|
|
320
|
+
const got = await fetchReadme(asset, opts);
|
|
321
|
+
out.push({
|
|
322
|
+
uuid: asset.uuid, slug: asset.slug, name: asset.name,
|
|
323
|
+
sourceUrl: asset.sourceUrl, version: asset.version,
|
|
324
|
+
found: !!got, length: got ? got.readme.length : 0,
|
|
325
|
+
license: got?.license || null, origin: got?.origin || null,
|
|
326
|
+
});
|
|
327
|
+
if (got) {
|
|
328
|
+
mkdirSync(CACHE_DIR, { recursive: true });
|
|
329
|
+
writeFileSync(resolveMarketplaceReadmePath(CACHE_DIR, asset.slug), got.readme);
|
|
330
|
+
Object.assign(out[out.length - 1], await updateMarketplaceReadme(mp, asset, got, opts.dryRun));
|
|
331
|
+
} else {
|
|
332
|
+
out[out.length - 1].status = 'not_found';
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
console.log(JSON.stringify({
|
|
336
|
+
baseUrl: cfg.baseUrl, dryRun: opts.dryRun, scope: listed.scope,
|
|
337
|
+
listError: listed.error, targets: out,
|
|
338
|
+
}, null, 2));
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
console.log(`\n🔗 API: ${cfg.baseUrl}`);
|
|
343
|
+
console.log(`📦 资产总数 ${listed.total}(列表范围:${listed.scope === 'admin' ? '管理端' : '公开端'}),其中 ${targets.length} 个缺 README`);
|
|
344
|
+
if (listed.error) console.log(`⚠️ 管理端列表不可用:${listed.error}`);
|
|
345
|
+
console.log('');
|
|
346
|
+
|
|
347
|
+
const results = [];
|
|
348
|
+
for (const asset of targets) {
|
|
349
|
+
const got = await fetchReadme(asset, opts);
|
|
350
|
+
if (!got || !got.readme.trim()) {
|
|
351
|
+
console.log(` ❌ ${asset.slug.padEnd(26)} 源仓库取不到 README(${asset.sourceUrl || '无 sourceUrl'})`);
|
|
352
|
+
results.push({ slug: asset.slug, status: 'not_found' });
|
|
353
|
+
continue;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
mkdirSync(CACHE_DIR, { recursive: true });
|
|
357
|
+
writeFileSync(resolveMarketplaceReadmePath(CACHE_DIR, asset.slug), got.readme);
|
|
358
|
+
|
|
359
|
+
if (opts.dryRun) {
|
|
360
|
+
const update = await updateMarketplaceReadme(mp, asset, got, true);
|
|
361
|
+
console.log(` 🔍 ${asset.slug.padEnd(26)} 待写入 ${update.length} 字符 | license=${update.license || '-'} | 来源=${got.origin || 'repo'} | 缓存 ${resolveMarketplaceReadmePath(CACHE_DIR, asset.slug)}`);
|
|
362
|
+
results.push({ slug: asset.slug, ...update, origin: got.origin || null });
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
const update = await updateMarketplaceReadme(mp, asset, got, false);
|
|
367
|
+
if (update.status === 'updated') {
|
|
368
|
+
console.log(` ✅ ${asset.slug.padEnd(26)} 写入成功 ${update.length} 字符 | license=${update.license || '-'}`);
|
|
369
|
+
results.push({ slug: asset.slug, ...update, origin: got.origin || null });
|
|
370
|
+
} else {
|
|
371
|
+
console.log(` ❌ ${asset.slug.padEnd(26)} 写入失败:${update.message}`);
|
|
372
|
+
results.push({ slug: asset.slug, ...update, origin: got.origin || null });
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
console.log('');
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
if (process.argv[1] && pathToFileURL(resolve(process.argv[1])).href === import.meta.url) {
|
|
379
|
+
await main();
|
|
380
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* scripts/tool-set.mjs
|
|
3
|
+
*
|
|
4
|
+
* 「tools/list 应该长什么样」的**唯一真源**。
|
|
5
|
+
*
|
|
6
|
+
* 为什么要单开一个文件:
|
|
7
|
+
* 1. 加一个工具要改 6 个脚本里的数字(散落的 `!== 14`)⇒ 漏一处就红一处,
|
|
8
|
+
* 更糟的是「数字对但名字不对」时照样绿。
|
|
9
|
+
* 2. 量具不许写死历史值 —— 期望值必须从 `lib/mcp-server.mjs` 的 TOOL_NAMES 派生。
|
|
10
|
+
* 3. 只比数量是不够的:真正要保证的是**名字集合**一致(少一个、多一个、重复都要能报出来)。
|
|
11
|
+
*
|
|
12
|
+
* 用法:
|
|
13
|
+
* import { TOOL_NAMES, describeToolSetDiff } from './tool-set.mjs';
|
|
14
|
+
* const problem = describeToolSetDiff(tools);
|
|
15
|
+
* if (problem) fail(problem);
|
|
16
|
+
*/
|
|
17
|
+
import { TOOL_NAMES as SERVER_TOOL_NAMES } from '../lib/mcp-server.mjs';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 期望的工具名清单 —— 直接从 MCP server 的注册常量导入,
|
|
21
|
+
* **不在这里复制一份**(复制 = 第二份真源 = 迟早漂移)。
|
|
22
|
+
*/
|
|
23
|
+
export const TOOL_NAMES = SERVER_TOOL_NAMES;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 比对 tools/list 返回值与期望清单。
|
|
27
|
+
*
|
|
28
|
+
* @param {Array<{name?: string}>} tools MCP tools/list 响应里的 tools 数组
|
|
29
|
+
* @param {string[]} [expected] 期望清单,默认 TOOL_NAMES
|
|
30
|
+
* @returns {string|null} null 表示通过;否则返回可直接打印的错误文案
|
|
31
|
+
*/
|
|
32
|
+
export function describeToolSetDiff(tools, expected = TOOL_NAMES) {
|
|
33
|
+
const actual = (Array.isArray(tools) ? tools : [])
|
|
34
|
+
.map((t) => (typeof t === 'string' ? t : t?.name))
|
|
35
|
+
.filter((n) => typeof n === 'string' && n.length > 0);
|
|
36
|
+
|
|
37
|
+
const missing = expected.filter((n) => !actual.includes(n));
|
|
38
|
+
const extra = actual.filter((n) => !expected.includes(n));
|
|
39
|
+
const duplicated = [...new Set(actual.filter((n, i) => actual.indexOf(n) !== i))];
|
|
40
|
+
|
|
41
|
+
if (!missing.length && !extra.length && !duplicated.length) return null;
|
|
42
|
+
|
|
43
|
+
const parts = [];
|
|
44
|
+
if (missing.length) parts.push(`缺少 ${missing.length} 个:${missing.join(', ')}`);
|
|
45
|
+
if (extra.length) parts.push(`多出 ${extra.length} 个:${extra.join(', ')}`);
|
|
46
|
+
if (duplicated.length) parts.push(`重复 ${duplicated.length} 个:${duplicated.join(', ')}`);
|
|
47
|
+
return `工具集与期望不一致(期望 ${expected.length} 个,实际 ${actual.length} 个)—— ${parts.join(';')}`;
|
|
48
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* scripts/verify-binary.mjs
|
|
4
|
+
*
|
|
5
|
+
* 验证「免 Node」单文件二进制真的不依赖 Node 运行时:
|
|
6
|
+
* - 用一个**不含任何 node / npm / bun 的 PATH** 拉起二进制
|
|
7
|
+
* - initialize → tools/list(工具名集合与 lib/mcp-server.mjs 的 TOOL_NAMES 一致)→ 一次 tools/call
|
|
8
|
+
* - 顺带确认二进制报的版本号 = package.json 的版本
|
|
9
|
+
*
|
|
10
|
+
* 用法:
|
|
11
|
+
* node scripts/verify-binary.mjs # 验证 dist/ 下本平台产物
|
|
12
|
+
* node scripts/verify-binary.mjs --bin=dist/lims-mcp-darwin-arm64
|
|
13
|
+
*/
|
|
14
|
+
import { spawn } from 'node:child_process';
|
|
15
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
16
|
+
import { join, resolve } from 'node:path';
|
|
17
|
+
import { fileURLToPath } from 'node:url';
|
|
18
|
+
import { describeToolSetDiff } from './tool-set.mjs';
|
|
19
|
+
|
|
20
|
+
const ROOT = resolve(fileURLToPath(import.meta.url), '../..');
|
|
21
|
+
const argv = process.argv.slice(2);
|
|
22
|
+
|
|
23
|
+
const pkg = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf-8'));
|
|
24
|
+
|
|
25
|
+
/** 找一个可执行的本平台二进制 */
|
|
26
|
+
function pickBinary() {
|
|
27
|
+
const explicit = argv.find((a) => a.startsWith('--bin='))?.slice('--bin='.length);
|
|
28
|
+
if (explicit) return resolve(ROOT, explicit);
|
|
29
|
+
const dist = join(ROOT, 'dist');
|
|
30
|
+
if (!existsSync(dist)) return null;
|
|
31
|
+
const cands = readdirSync(dist).filter((f) => f.startsWith('lims-mcp'));
|
|
32
|
+
const arch = process.arch === 'arm64' ? 'arm64' : 'x64';
|
|
33
|
+
const plat = process.platform === 'darwin' ? 'darwin' : process.platform === 'win32' ? 'windows' : 'linux';
|
|
34
|
+
const exact = cands.find((f) => f.includes(plat) && f.includes(arch));
|
|
35
|
+
if (!exact) return null;
|
|
36
|
+
return join(dist, exact);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const bin = pickBinary();
|
|
40
|
+
if (!bin || !existsSync(bin)) {
|
|
41
|
+
console.error('找不到二进制产物 —— 先跑:node scripts/build-binary.mjs');
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// ⭐ 关键:PATH 里只留系统目录,**不放任何 node / npm / bun**(连本机 ~/.local/bin 都不给)
|
|
46
|
+
const MINIMAL_PATH = ['/usr/bin', '/bin', '/usr/sbin', '/sbin'].join(':');
|
|
47
|
+
console.log(`二进制: ${bin}`);
|
|
48
|
+
console.log(`PATH : ${MINIMAL_PATH} ← 故意不含 node/npm/bun`);
|
|
49
|
+
|
|
50
|
+
const child = spawn(bin, [], {
|
|
51
|
+
env: { PATH: MINIMAL_PATH, HOME: process.env.HOME },
|
|
52
|
+
cwd: '/',
|
|
53
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
let buf = '';
|
|
57
|
+
const pending = new Map();
|
|
58
|
+
child.stdout.on('data', (d) => {
|
|
59
|
+
buf += d.toString();
|
|
60
|
+
let idx;
|
|
61
|
+
while ((idx = buf.indexOf('\n')) >= 0) {
|
|
62
|
+
const line = buf.slice(0, idx).trim();
|
|
63
|
+
buf = buf.slice(idx + 1);
|
|
64
|
+
if (!line) continue;
|
|
65
|
+
let msg;
|
|
66
|
+
try { msg = JSON.parse(line); } catch { continue; }
|
|
67
|
+
const h = pending.get(msg.id);
|
|
68
|
+
if (h) { pending.delete(msg.id); h(msg); }
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
child.stderr.on('data', (d) => process.stderr.write(`[binary stderr] ${d}`));
|
|
72
|
+
|
|
73
|
+
let nextId = 1;
|
|
74
|
+
function request(method, params) {
|
|
75
|
+
const id = nextId++;
|
|
76
|
+
return new Promise((res, rej) => {
|
|
77
|
+
const timer = setTimeout(() => rej(new Error(`${method} timeout`)), 30000);
|
|
78
|
+
pending.set(id, (msg) => { clearTimeout(timer); res(msg); });
|
|
79
|
+
child.stdin.write(JSON.stringify({ jsonrpc: '2.0', id, method, params }) + '\n');
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function fail(msg) {
|
|
84
|
+
console.error(`\nFAIL: ${msg}`);
|
|
85
|
+
child.kill();
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const init = await request('initialize', {
|
|
90
|
+
protocolVersion: '2024-11-05',
|
|
91
|
+
capabilities: {},
|
|
92
|
+
clientInfo: { name: 'binary-sim', version: '0.0.1' },
|
|
93
|
+
});
|
|
94
|
+
if (init.error) fail(`initialize error: ${JSON.stringify(init.error)}`);
|
|
95
|
+
const sv = init.result?.serverInfo ?? {};
|
|
96
|
+
console.log(`initialize OK · server=${sv.name} v${sv.version}`);
|
|
97
|
+
if (sv.version !== pkg.version) fail(`版本号不符:二进制报 ${sv.version},package.json 是 ${pkg.version}`);
|
|
98
|
+
|
|
99
|
+
child.stdin.write(JSON.stringify({ jsonrpc: '2.0', method: 'notifications/initialized' }) + '\n');
|
|
100
|
+
|
|
101
|
+
const list = await request('tools/list', {});
|
|
102
|
+
if (list.error) fail(`tools/list error: ${JSON.stringify(list.error)}`);
|
|
103
|
+
const tools = list.result?.tools ?? [];
|
|
104
|
+
console.log(`tools/list OK · ${tools.length} 个工具`);
|
|
105
|
+
const toolSetProblem = describeToolSetDiff(tools);
|
|
106
|
+
if (toolSetProblem) fail(toolSetProblem);
|
|
107
|
+
|
|
108
|
+
const health = await request('tools/call', { name: 'lims_health', arguments: {} });
|
|
109
|
+
const text = health.result?.content?.find((c) => c.type === 'text')?.text ?? '';
|
|
110
|
+
const rt = JSON.parse(text).runtime ?? {};
|
|
111
|
+
console.log(`tools/call OK · lims_health → baseUrl=${rt.baseUrl} hasAuthToken=${rt.hasAuthToken}`);
|
|
112
|
+
|
|
113
|
+
console.log(`\nPASS: 二进制在「PATH 里没有 node」的环境下可正常握手、列出 ${tools.length} 个工具并完成一次调用`);
|
|
114
|
+
child.kill();
|
|
115
|
+
process.exit(0);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 用 ClawDao sidecar 自己的 clawdao-mcp-bridge 实现(loadMcpRegistry + StdioMcpClient)
|
|
3
|
+
* 拉起 limschain,证明 ClawDao 侧真实可见的工具数。
|
|
4
|
+
*/
|
|
5
|
+
const BRIDGE = '/Applications/ClawDao.app/Contents/Resources/embedded/agent-server/src/server/extensions/clawdao-mcp-bridge.ts';
|
|
6
|
+
import { describeToolSetDiff } from './tool-set.mjs';
|
|
7
|
+
const mod = await import(BRIDGE);
|
|
8
|
+
|
|
9
|
+
const servers = mod.loadMcpRegistry();
|
|
10
|
+
console.log('registry servers:', servers.map((s) => `${s.id}(enabled=${s.enabled !== false})`).join(', '));
|
|
11
|
+
|
|
12
|
+
const entry = servers.find((s) => s.id === 'limschain');
|
|
13
|
+
if (!entry) {
|
|
14
|
+
console.error('FAIL: limschain not in registry');
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
console.log('entry:', JSON.stringify({ command: entry.command, args: entry.defaultArgs, transport: entry.transportType }));
|
|
18
|
+
|
|
19
|
+
// 与 bridge 完全一致的 env
|
|
20
|
+
const env = { PATH: process.env.PATH ?? '', HOME: process.env.HOME ?? '' };
|
|
21
|
+
const client = new mod.StdioMcpClient(entry.id, entry.command, entry.defaultArgs ?? [], env);
|
|
22
|
+
const init = await client.spawnAndInit();
|
|
23
|
+
if (!init.ok) {
|
|
24
|
+
console.error('FAIL spawnAndInit:', init.error);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
console.log('initialize OK:', JSON.stringify(init.result?.serverInfo ?? {}));
|
|
28
|
+
const list = await client.request('tools/list', {});
|
|
29
|
+
if (!list.ok) {
|
|
30
|
+
console.error('FAIL tools/list:', list.error);
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
const tools = list.result?.tools ?? [];
|
|
34
|
+
console.log(`tools/list OK: ${tools.length} tools ->`, tools.map((t) => t.name).join(','));
|
|
35
|
+
client.kill();
|
|
36
|
+
const toolSetProblem = describeToolSetDiff(tools);
|
|
37
|
+
if (toolSetProblem) {
|
|
38
|
+
console.error(`FAIL: ${toolSetProblem}`);
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
process.exit(0);
|