dsh-skill-mcp-market 0.5.13 → 0.5.14

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-skill-mcp-market",
3
- "version": "0.5.13",
3
+ "version": "0.5.14",
4
4
  "type": "module",
5
5
  "description": "DSH 技能市场与 MCP 连接器市场:浏览实时技能源,一键安装 SKILL.md 技能与 MCP 连接器,装完即刻可用、无需重启。SKILL & MCP marketplace for DeepSeek Harness — browse live sources, install skills and MCP connectors, effective immediately.",
6
6
  "license": "MIT",
package/src/enrich.js CHANGED
@@ -39,10 +39,14 @@ export async function mapLimit(items, limit, worker) {
39
39
  return out;
40
40
  }
41
41
 
42
- const ENTITIES = { "&quot;": '"', "&amp;": "&", "&lt;": "<", "&gt;": ">", "&#39;": "'", "&nbsp;": " " };
42
+ const ENTITIES = { "&quot;": '"', "&amp;": "&", "&lt;": "<", "&gt;": ">", "&#39;": "'", "&nbsp;": " ", "&#x27;": "'" };
43
43
 
44
44
  function decodeEntities(text) {
45
- return String(text).replace(/&(quot|amp|lt|gt|#39|nbsp);/g, (match) => ENTITIES[match] ?? match);
45
+ return String(text)
46
+ .replace(/&(quot|amp|lt|gt|#39|#x27|nbsp);/g, (match) => ENTITIES[match] ?? match)
47
+ .replace(/&#(x?)([0-9a-fA-F]+);/g, (_match, hex, digits) =>
48
+ String.fromCodePoint(hex ? Number.parseInt(digits, 16) : Number.parseInt(digits, 10)),
49
+ );
46
50
  }
47
51
 
48
52
  /** File index of a GitHub repository (cached 24h), used to locate `<skill>/SKILL.md`. */
@@ -64,6 +68,21 @@ async function repoFileIndex(repo, ref, cache) {
64
68
  return new Set(files);
65
69
  }
66
70
 
71
+ /**
72
+ * Some SKILL.md frontmatters carry junk descriptions ("&gt;" and friends). Only accept text
73
+ * that a human would recognise as a sentence.
74
+ */
75
+ function usableDescription(value) {
76
+ const text = String(value ?? "")
77
+ .replace(/^[\s>#*\-–—]+/, "")
78
+ .replace(/\s+/g, " ")
79
+ .trim();
80
+ if (text.length < 12) return "";
81
+ if (!/[\p{L}\p{N}]/u.test(text)) return "";
82
+ if (/^[\p{P}\p{S}\s]+$/u.test(text)) return "";
83
+ return text;
84
+ }
85
+
67
86
  function locateSkillFile(index, skill) {
68
87
  const wanted = String(skill || "").toLowerCase();
69
88
  const candidates = [...index].filter((path) => path.toLowerCase().endsWith("/skill.md") || path.toLowerCase() === "skill.md");
@@ -110,7 +129,8 @@ export async function enrichSkillsSh(items, cache) {
110
129
  await cache.put(cacheKey, text);
111
130
  }
112
131
  const { data } = parseFrontmatter(text);
113
- if (data.description) item.description = String(data.description).trim();
132
+ const description = usableDescription(data.description);
133
+ if (description) item.description = description;
114
134
  if (data.name) item.name = String(data.name).trim();
115
135
  item.skillDir = path === "SKILL.md" ? "" : path.slice(0, -"/SKILL.md".length);
116
136
  item.describedBy = "SKILL.md";
@@ -177,8 +197,9 @@ export async function enrichSkillsShFast(items, cache, limit = 10) {
177
197
  }
178
198
  }
179
199
  const { data } = parseFrontmatter(text);
180
- if (data.description) {
181
- item.description = String(data.description).trim();
200
+ const description = usableDescription(data.description);
201
+ if (description) {
202
+ item.description = description;
182
203
  if (data.name) item.name = String(data.name).trim();
183
204
  item.skillDir = path === "SKILL.md" ? "" : path.slice(0, -"/SKILL.md".length);
184
205
  const meta = data.metadata && typeof data.metadata === "object" ? data.metadata : {};
@@ -212,8 +233,12 @@ export async function enrichPageDescriptions(items, cache, concurrency = 6) {
212
233
  /<meta[^>]+property="og:description"[^>]+content="([^"]{10,400})"/i.exec(text) ||
213
234
  /<meta[^>]+name="description"[^>]+content="([^"]{10,400})"/i.exec(text);
214
235
  if (meta) {
215
- const description = decodeEntities(meta[1]).replace(/\s+/g, " ").trim();
216
- if (description) {
236
+ const description = decodeEntities(meta[1])
237
+ .replace(/^[\s>#*\-–—]+/, "")
238
+ .replace(/\s+/g, " ")
239
+ .trim();
240
+ // 有些页面的 meta 只是正文开头的 markdown 符号(实测出现过 ">"),丢掉这种残渣。
241
+ if (description.length >= 12 && /[\p{L}\p{N}]/u.test(description)) {
217
242
  item.description = description;
218
243
  item.describedBy = "page-meta";
219
244
  }
package/src/sources.js CHANGED
@@ -77,6 +77,22 @@ function fillMissingDescriptions(items) {
77
77
  }
78
78
 
79
79
  /** 本地分页切片:上游没有 page 参数的源都靠它实现真正的翻页。 */
80
+ // 补描述是「锦上添花」:上游每个技能要一次网络往返,整屏补完可能十几秒。
81
+ // 给一个总预算,超时就先把卡片发出去(描述留空/通用文案),绝不让面板等着转圈。
82
+ const DESCRIPTION_BUDGET_MS = 9000;
83
+
84
+ async function withDeadline(promise, ms) {
85
+ let timer;
86
+ const deadline = new Promise((resolve) => {
87
+ timer = setTimeout(resolve, ms);
88
+ });
89
+ try {
90
+ return await Promise.race([promise, deadline]);
91
+ } finally {
92
+ clearTimeout(timer);
93
+ }
94
+ }
95
+
80
96
  function pageSlice(rows, page, pageSize) {
81
97
  const p = Math.max(1, Number(page) || 1);
82
98
  const size = Math.max(1, Number(pageSize) || 24);
@@ -147,7 +163,7 @@ async function skillsShHighlights(cache) {
147
163
 
148
164
  // 全量目录冷启动约 6 秒(索引 + 两个 10000 行的 shard)。首屏最多等这么久,
149
165
  // 超时就先给首页推荐并让抓取在后台继续,否则打开技能市场会像卡死一样。
150
- const CATALOG_WAIT_MS = 6000;
166
+ const CATALOG_WAIT_MS = 12000;
151
167
 
152
168
  async function loadSkillsShCatalog(cache) {
153
169
  const cached = cache ? await cache.get(SKILLS_SH_CATALOG_KEY, SKILLS_SH_CATALOG_TTL) : undefined;
@@ -182,12 +198,26 @@ export async function browseSkillsSh({ query = "", page = 1, pageSize = 24, cach
182
198
  ? catalog.filter((row) => `${row.owner}/${row.slug}`.toLowerCase().includes(needle))
183
199
  : catalog;
184
200
  const items = pageSlice(matched, p, size).map(skillsShCard);
185
- try {
186
- // 首页/sitemap 都不带描述,按可见的这一屏补(上限 10 条,避免 24 条逐个读太慢)。
187
- await enrichSkillsShFast(items, cache, 10);
188
- } catch {
189
- // descriptions are best-effort: a failed read never blocks the list
190
- }
201
+ // 首页/sitemap 都不带描述:先读 SKILL.md 头,落空的再读 skills.sh 详情页的 meta。
202
+ // 整段有总时间预算,超时就先发卡片(描述退回通用文案),面板不会为此转圈。
203
+ await withDeadline(
204
+ (async () => {
205
+ try {
206
+ // 详情页 meta 一次请求就有准确简介(concurrency 8,24 条约 3 秒)。
207
+ await enrichPageDescriptions(items, cache, 8);
208
+ } catch {
209
+ // 详情页读不到就退回通用文案
210
+ }
211
+ try {
212
+ // 少数详情页也没有 meta 时,再读仓库里的 SKILL.md 头(顺带补出 skillDir)。
213
+ const missing = items.filter((item) => !item.description);
214
+ if (missing.length > 0) await enrichSkillsShFast(missing, cache, 8);
215
+ } catch {
216
+ // descriptions are best-effort: a failed read never blocks the list
217
+ }
218
+ })(),
219
+ DESCRIPTION_BUDGET_MS,
220
+ );
191
221
  fillMissingDescriptions(items);
192
222
  return { source: "skills.sh", items, total: matched.length, hasMore: p * size < matched.length, hint };
193
223
  }
@@ -223,12 +253,18 @@ export async function searchSkillsSh({ query = "", page = 1, pageSize = 24, cach
223
253
  installable: true,
224
254
  };
225
255
  });
226
- try {
227
- // The search API has no description field; the skill page's own meta text does.
228
- await enrichSkillsShFast(items, cache, 10);
229
- } catch {
230
- // descriptions are best-effort
231
- }
256
+ await withDeadline(
257
+ (async () => {
258
+ try {
259
+ // The search API has no description field; the skill page's own meta text does.
260
+ await enrichSkillsShFast(items, cache, 10);
261
+ await enrichPageDescriptions(items.filter((item) => !item.description).slice(0, 10), cache, 6);
262
+ } catch {
263
+ // descriptions are best-effort
264
+ }
265
+ })(),
266
+ DESCRIPTION_BUDGET_MS,
267
+ );
232
268
  fillMissingDescriptions(items);
233
269
  const hasMore = rows.length >= depth;
234
270
  const total = hasMore ? Math.max(Number(data.count) || 0, depth + 1) : (p - 1) * size + rows.length;