dsh-skill-harbor 0.2.0 → 0.3.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.
@@ -1,255 +1,385 @@
1
- /**
2
- * 路由注册总装 —— 所有 HTTP 入口在这里一次性挂上。
3
- *
4
- * 设计要点:
5
- * - 前缀统一 `/dsh-skill-harbor/api`,写操作全部要求 CSRF 头
6
- * - 写路由只接受 `snapshot.allowlist` 里的路径(不是请求里带来的任意路径)
7
- * - 面板席位在 Phase 2 是独立 api + 客户端渲染,不注册 settings tab
8
- */
9
- import { writeFileSync, renameSync, unlinkSync, existsSync } from 'node:fs'
10
-
11
- import { ROUTE_PREFIX, guarded, sendJson } from './guard.js'
12
- import { buildSnapshot, readSkillBody } from './store.js'
13
- import { isAllowedPath, safePath, isSkillMarkdown } from './safe-path.js'
14
- import { FILE_STATE, isWritable } from '../collect/observe.js'
15
- import { extractSkillMeta } from '../collect/frontmatter.js'
16
-
17
- /** 关闭/开启模型的 frontmatter 键。 */
18
- const DISABLE_KEY = 'disable-model-invocation'
19
-
20
- /** 在正文里切换 `disable-model-invocation`,保留其余内容原样。 */
21
- export function setModelInvocation(text, enabled) {
22
- const line = enabled ? 'false' : 'true'
23
- const prefixed = /^(---\r?\n)([\s\S]*?)(\r?\n---)/.exec(text)
24
-
25
- if (prefixed === null) {
26
- // 没有 frontmatter:新建一个
27
- return `---\n${DISABLE_KEY}: ${line}\n---\n${text}`
28
- }
29
-
30
- const head = prefixed[2]
31
- const entry = `${DISABLE_KEY}: ${line}`
32
- const existing = new RegExp(`^${DISABLE_KEY}\\s*:.*$`, 'm')
33
-
34
- const nextHead = existing.test(head)
35
- ? head.replace(existing, entry)
36
- : `${head}${head.trim() === '' ? '' : '\n'}${entry}`
37
-
38
- return `${prefixed[1]}${nextHead}${prefixed[3]}${text.slice(prefixed[0].length)}`
39
- }
40
-
41
- /** 原子写:先写临时文件再 rename,避免半截文件。 */
42
- function atomicWrite(path, content) {
43
- const temp = `${path}.harbor-tmp-${process.pid}`
44
- writeFileSync(temp, content, 'utf8')
45
- try {
46
- renameSync(temp, path)
47
- } catch (error) {
48
- try {
49
- if (existsSync(temp)) unlinkSync(temp)
50
- } catch {
51
- /* ignore */
52
- }
53
- throw error
54
- }
55
- }
56
-
57
- /**
58
- * 注册全部路由。
59
- * @param {object} ctx
60
- * @param {object} config
61
- * @param {object} [deps] 注入点(便于单测不依赖真实 webServer)
62
- */
63
- export function registerRoutes(ctx, config = {}, deps = {}) {
64
- const webServer = deps.webServer ?? ctx.webServer
65
- if (webServer === undefined || webServer === null || typeof webServer.register !== 'function') {
66
- // 没有 webserver(如纯 CLI 场景):不注册,但 provider 仍然工作
67
- return () => {}
68
- }
69
-
70
- const logger = ctx?.logger ?? console
71
- const disposers = []
72
-
73
- /** 每次请求都重新扫描?否 —— 用短 TTL 缓存,写后立即失效。 */
74
- let cached = null
75
- let cacheAt = 0
76
- const CACHE_MS = 1500
77
-
78
- const snapshot = async () => {
79
- const now = Date.now()
80
- if (cached !== null && now - cacheAt < CACHE_MS) return cached
81
- const registrySummaries = typeof ctx?.skills?.list === 'function' ? await ctx.skills.list() : []
82
- cached = buildSnapshot(config, registrySummaries)
83
- cacheAt = now
84
- return cached
85
- }
86
- const invalidate = () => {
87
- cached = null
88
- cacheAt = 0
89
- }
90
-
91
- const register = (path, methods, handler) => {
92
- const dispose = webServer.register({
93
- kind: 'handler',
94
- path: `${ROUTE_PREFIX}${path}`,
95
- auth: 'required',
96
- handler: guarded(ctx, { methods }, handler),
97
- })
98
- disposers.push(dispose)
99
- }
100
-
101
- // ---- 读:列表 ----
102
- register('/list', ['GET'], async (req, res) => {
103
- const snap = await snapshot()
104
- sendJson(res, 200, {
105
- takenAt: snap.takenAt,
106
- skills: snap.observations.map(observation => ({
107
- name: observation.name,
108
- description: observation.description,
109
- source: observation.source,
110
- rank: observation.rank,
111
- fileState: observation.fileState,
112
- modelInvocable: observation.modelInvocable,
113
- announcementChars: observation.announcementChars,
114
- shadowedBy: observation.shadowedBy ?? null,
115
- // 只有 editable 才暴露 path,且可写
116
- path: observation.fileState === FILE_STATE.EDITABLE ? observation.path : null,
117
- writable: isWritable(observation),
118
- })),
119
- duplicates: snap.duplicates.map(group => ({
120
- name: group.name,
121
- count: group.count,
122
- winner: group.winner === null ? null : { source: group.winner.source, rank: group.winner.rank },
123
- })),
124
- totals: {
125
- all: snap.observations.length,
126
- editable: snap.observations.filter(o => o.fileState === FILE_STATE.EDITABLE).length,
127
- providerFile: snap.observations.filter(o => o.fileState === FILE_STATE.PROVIDER_FILE).length,
128
- virtual: snap.observations.filter(o => o.fileState === FILE_STATE.VIRTUAL).length,
129
- shadowed: snap.observations.filter(o => o.shadowedBy !== undefined).length,
130
- },
131
- })
132
- })
133
-
134
- // ---- 读:单技能正文 ----
135
- register('/read', ['GET'], async (req, res) => {
136
- const snap = await snapshot()
137
- const url = new URL(req.url ?? '/', 'http://localhost')
138
- const target = url.searchParams.get('path')
139
-
140
- const allowed = isAllowedPath(target, snap.allowlist)
141
- if (!allowed.ok) {
142
- sendJson(res, 403, { error: allowed.reason })
143
- return
144
- }
145
- const body = readSkillBody(target, snap.allowlist)
146
- if (!body.ok) {
147
- sendJson(res, 404, { error: body.reason })
148
- return
149
- }
150
- sendJson(res, 200, { path: target, content: body.content, meta: extractSkillMeta(body.content) })
151
- })
152
-
153
- // ---- 写:启停模型调用 ----
154
- register('/set-enabled', ['POST'], async (req, res, body) => {
155
- const snap = await snapshot()
156
- const target = body?.path
157
- const enabled = body?.enabled
158
-
159
- if (typeof enabled !== 'boolean') {
160
- sendJson(res, 400, { error: 'enabled-must-be-boolean' })
161
- return
162
- }
163
- const allowed = isAllowedPath(target, snap.allowlist)
164
- if (!allowed.ok) {
165
- sendJson(res, 403, { error: allowed.reason })
166
- return
167
- }
168
- if (!isSkillMarkdown(target)) {
169
- sendJson(res, 400, { error: 'not-a-skill-markdown' })
170
- return
171
- }
172
-
173
- try {
174
- const current = readSkillBody(target, snap.allowlist)
175
- if (!current.ok) {
176
- sendJson(res, 404, { error: current.reason })
177
- return
178
- }
179
- atomicWrite(target, setModelInvocation(current.content, enabled))
180
- invalidate()
181
- sendJson(res, 200, { ok: true, path: target, enabled })
182
- } catch (error) {
183
- logger.warn?.('[dsh-skill-harbor] set-enabled failed', error)
184
- sendJson(res, 500, { error: 'write-failed', message: String(error?.message ?? error) })
185
- }
186
- })
187
-
188
- // ---- 写:整体更新正文 ----
189
- register('/update', ['POST'], async (req, res, body) => {
190
- const snap = await snapshot()
191
- const target = body?.path
192
- const content = body?.content
193
-
194
- if (typeof content !== 'string') {
195
- sendJson(res, 400, { error: 'content-must-be-string' })
196
- return
197
- }
198
- const allowed = isAllowedPath(target, snap.allowlist)
199
- if (!allowed.ok) {
200
- sendJson(res, 403, { error: allowed.reason })
201
- return
202
- }
203
- if (!isSkillMarkdown(target)) {
204
- sendJson(res, 400, { error: 'not-a-skill-markdown' })
205
- return
206
- }
207
-
208
- try {
209
- atomicWrite(target, content)
210
- invalidate()
211
- sendJson(res, 200, { ok: true, path: target })
212
- } catch (error) {
213
- logger.warn?.('[dsh-skill-harbor] update failed', error)
214
- sendJson(res, 500, { error: 'write-failed', message: String(error?.message ?? error) })
215
- }
216
- })
217
-
218
- // ---- 写:删除 ----
219
- register('/delete', ['POST'], async (req, res, body) => {
220
- const snap = await snapshot()
221
- const target = body?.path
222
-
223
- const allowed = isAllowedPath(target, snap.allowlist)
224
- if (!allowed.ok) {
225
- sendJson(res, 403, { error: allowed.reason })
226
- return
227
- }
228
- if (!isSkillMarkdown(target)) {
229
- sendJson(res, 400, { error: 'not-a-skill-markdown' })
230
- return
231
- }
232
-
233
- try {
234
- unlinkSync(target)
235
- invalidate()
236
- sendJson(res, 200, { ok: true, path: target })
237
- } catch (error) {
238
- logger.warn?.('[dsh-skill-harbor] delete failed', error)
239
- sendJson(res, 500, { error: 'delete-failed', message: String(error?.message ?? error) })
240
- }
241
- })
242
-
243
- return () => {
244
- for (const dispose of disposers) {
245
- try {
246
- dispose()
247
- } catch {
248
- /* ignore */
249
- }
250
- }
251
- disposers.length = 0
252
- }
253
- }
254
-
255
- export { ROUTE_PREFIX, safePath }
1
+ /**
2
+ * 路由注册总装 —— 所有 HTTP 入口在这里一次性挂上。
3
+ *
4
+ * 设计要点:
5
+ * - 前缀统一 `/dsh-skill-harbor/api`,写操作全部要求 CSRF 头
6
+ * - 写路由只接受 `snapshot.allowlist` 里的路径(不是请求里带来的任意路径)
7
+ * - 面板席位在 Phase 2 是独立 api + 客户端渲染,不注册 settings tab
8
+ */
9
+ import { writeFileSync, renameSync, unlinkSync, existsSync } from 'node:fs'
10
+
11
+ import { ROUTE_PREFIX, guarded, sendJson } from './guard.js'
12
+ import { buildSnapshot, readSkillBody } from './store.js'
13
+ import { isAllowedPath, safePath, isSkillMarkdown } from './safe-path.js'
14
+ import { FILE_STATE, isWritable } from '../collect/observe.js'
15
+ import { extractSkillMeta } from '../collect/frontmatter.js'
16
+ import { auditSkillText } from '../audit/rules.js'
17
+ import { budgetReport } from '../budget/announcement.js'
18
+ import { parseSkillsFromArchive, decidePlacement, installSkill } from '../market/install.js'
19
+
20
+ /** 关闭/开启模型的 frontmatter 键。 */
21
+ const DISABLE_KEY = 'disable-model-invocation'
22
+
23
+ /** 在正文里切换 `disable-model-invocation`,保留其余内容原样。 */
24
+ export function setModelInvocation(text, enabled) {
25
+ const line = enabled ? 'false' : 'true'
26
+ const prefixed = /^(---\r?\n)([\s\S]*?)(\r?\n---)/.exec(text)
27
+
28
+ if (prefixed === null) {
29
+ // 没有 frontmatter:新建一个
30
+ return `---\n${DISABLE_KEY}: ${line}\n---\n${text}`
31
+ }
32
+
33
+ const head = prefixed[2]
34
+ const entry = `${DISABLE_KEY}: ${line}`
35
+ const existing = new RegExp(`^${DISABLE_KEY}\\s*:.*$`, 'm')
36
+
37
+ const nextHead = existing.test(head)
38
+ ? head.replace(existing, entry)
39
+ : `${head}${head.trim() === '' ? '' : '\n'}${entry}`
40
+
41
+ return `${prefixed[1]}${nextHead}${prefixed[3]}${text.slice(prefixed[0].length)}`
42
+ }
43
+
44
+ /** 原子写:先写临时文件再 rename,避免半截文件。 */
45
+ function atomicWrite(path, content) {
46
+ const temp = `${path}.harbor-tmp-${process.pid}`
47
+ writeFileSync(temp, content, 'utf8')
48
+ try {
49
+ renameSync(temp, path)
50
+ } catch (error) {
51
+ try {
52
+ if (existsSync(temp)) unlinkSync(temp)
53
+ } catch {
54
+ /* ignore */
55
+ }
56
+ throw error
57
+ }
58
+ }
59
+
60
+ /**
61
+ * 注册全部路由。
62
+ * @param {object} ctx
63
+ * @param {object} config
64
+ * @param {object} [deps] 注入点(便于单测不依赖真实 webServer)
65
+ */
66
+ export function registerRoutes(ctx, config = {}, deps = {}) {
67
+ const webServer = deps.webServer ?? ctx.webServer
68
+ if (webServer === undefined || webServer === null || typeof webServer.register !== 'function') {
69
+ // 没有 webserver(如纯 CLI 场景):不注册,但 provider 仍然工作
70
+ return () => {}
71
+ }
72
+
73
+ const logger = ctx?.logger ?? console
74
+ const disposers = []
75
+
76
+ /** 每次请求都重新扫描?否 —— 用短 TTL 缓存,写后立即失效。 */
77
+ let cached = null
78
+ let cacheAt = 0
79
+ const CACHE_MS = 1500
80
+
81
+ const snapshot = async () => {
82
+ const now = Date.now()
83
+ if (cached !== null && now - cacheAt < CACHE_MS) return cached
84
+ const registrySummaries = typeof ctx?.skills?.list === 'function' ? await ctx.skills.list() : []
85
+ cached = buildSnapshot(config, registrySummaries)
86
+ cacheAt = now
87
+ return cached
88
+ }
89
+ const invalidate = () => {
90
+ cached = null
91
+ cacheAt = 0
92
+ }
93
+
94
+ const register = (path, methods, handler) => {
95
+ const dispose = webServer.register({
96
+ kind: 'handler',
97
+ path: `${ROUTE_PREFIX}${path}`,
98
+ auth: 'required',
99
+ handler: guarded(ctx, { methods }, handler),
100
+ })
101
+ disposers.push(dispose)
102
+ }
103
+
104
+ // ---- 读:列表 ----
105
+ register('/list', ['GET'], async (req, res) => {
106
+ const snap = await snapshot()
107
+ sendJson(res, 200, {
108
+ takenAt: snap.takenAt,
109
+ skills: snap.observations.map(observation => ({
110
+ name: observation.name,
111
+ description: observation.description,
112
+ source: observation.source,
113
+ rank: observation.rank,
114
+ fileState: observation.fileState,
115
+ modelInvocable: observation.modelInvocable,
116
+ announcementChars: observation.announcementChars,
117
+ shadowedBy: observation.shadowedBy ?? null,
118
+ // 只有 editable 才暴露 path,且可写
119
+ path: observation.fileState === FILE_STATE.EDITABLE ? observation.path : null,
120
+ writable: isWritable(observation),
121
+ })),
122
+ duplicates: snap.duplicates.map(group => ({
123
+ name: group.name,
124
+ count: group.count,
125
+ winner: group.winner === null ? null : { source: group.winner.source, rank: group.winner.rank },
126
+ })),
127
+ totals: {
128
+ all: snap.observations.length,
129
+ editable: snap.observations.filter(o => o.fileState === FILE_STATE.EDITABLE).length,
130
+ providerFile: snap.observations.filter(o => o.fileState === FILE_STATE.PROVIDER_FILE).length,
131
+ virtual: snap.observations.filter(o => o.fileState === FILE_STATE.VIRTUAL).length,
132
+ shadowed: snap.observations.filter(o => o.shadowedBy !== undefined).length,
133
+ },
134
+ })
135
+ })
136
+
137
+ // ---- 读:单技能正文 ----
138
+ register('/read', ['GET'], async (req, res) => {
139
+ const snap = await snapshot()
140
+ const url = new URL(req.url ?? '/', 'http://localhost')
141
+ const target = url.searchParams.get('path')
142
+
143
+ const allowed = isAllowedPath(target, snap.allowlist)
144
+ if (!allowed.ok) {
145
+ sendJson(res, 403, { error: allowed.reason })
146
+ return
147
+ }
148
+ const body = readSkillBody(target, snap.allowlist)
149
+ if (!body.ok) {
150
+ sendJson(res, 404, { error: body.reason })
151
+ return
152
+ }
153
+ sendJson(res, 200, { path: target, content: body.content, meta: extractSkillMeta(body.content) })
154
+ })
155
+
156
+ // ---- 写:启停模型调用 ----
157
+ register('/set-enabled', ['POST'], async (req, res, body) => {
158
+ const snap = await snapshot()
159
+ const target = body?.path
160
+ const enabled = body?.enabled
161
+
162
+ if (typeof enabled !== 'boolean') {
163
+ sendJson(res, 400, { error: 'enabled-must-be-boolean' })
164
+ return
165
+ }
166
+ const allowed = isAllowedPath(target, snap.allowlist)
167
+ if (!allowed.ok) {
168
+ sendJson(res, 403, { error: allowed.reason })
169
+ return
170
+ }
171
+ if (!isSkillMarkdown(target)) {
172
+ sendJson(res, 400, { error: 'not-a-skill-markdown' })
173
+ return
174
+ }
175
+
176
+ try {
177
+ const current = readSkillBody(target, snap.allowlist)
178
+ if (!current.ok) {
179
+ sendJson(res, 404, { error: current.reason })
180
+ return
181
+ }
182
+ atomicWrite(target, setModelInvocation(current.content, enabled))
183
+ invalidate()
184
+ sendJson(res, 200, { ok: true, path: target, enabled })
185
+ } catch (error) {
186
+ logger.warn?.('[dsh-skill-harbor] set-enabled failed', error)
187
+ sendJson(res, 500, { error: 'write-failed', message: String(error?.message ?? error) })
188
+ }
189
+ })
190
+
191
+ // ---- 写:整体更新正文 ----
192
+ register('/update', ['POST'], async (req, res, body) => {
193
+ const snap = await snapshot()
194
+ const target = body?.path
195
+ const content = body?.content
196
+
197
+ if (typeof content !== 'string') {
198
+ sendJson(res, 400, { error: 'content-must-be-string' })
199
+ return
200
+ }
201
+ const allowed = isAllowedPath(target, snap.allowlist)
202
+ if (!allowed.ok) {
203
+ sendJson(res, 403, { error: allowed.reason })
204
+ return
205
+ }
206
+ if (!isSkillMarkdown(target)) {
207
+ sendJson(res, 400, { error: 'not-a-skill-markdown' })
208
+ return
209
+ }
210
+
211
+ try {
212
+ atomicWrite(target, content)
213
+ invalidate()
214
+ sendJson(res, 200, { ok: true, path: target })
215
+ } catch (error) {
216
+ logger.warn?.('[dsh-skill-harbor] update failed', error)
217
+ sendJson(res, 500, { error: 'write-failed', message: String(error?.message ?? error) })
218
+ }
219
+ })
220
+
221
+ // ---- 写:删除 ----
222
+ register('/delete', ['POST'], async (req, res, body) => {
223
+ const snap = await snapshot()
224
+ const target = body?.path
225
+
226
+ const allowed = isAllowedPath(target, snap.allowlist)
227
+ if (!allowed.ok) {
228
+ sendJson(res, 403, { error: allowed.reason })
229
+ return
230
+ }
231
+ if (!isSkillMarkdown(target)) {
232
+ sendJson(res, 400, { error: 'not-a-skill-markdown' })
233
+ return
234
+ }
235
+
236
+ try {
237
+ unlinkSync(target)
238
+ invalidate()
239
+ sendJson(res, 200, { ok: true, path: target })
240
+ } catch (error) {
241
+ logger.warn?.('[dsh-skill-harbor] delete failed', error)
242
+ sendJson(res, 500, { error: 'delete-failed', message: String(error?.message ?? error) })
243
+ }
244
+ })
245
+
246
+ // ---- 读:审计全量 ----
247
+ register('/audit', ['GET'], async (req, res) => {
248
+ const snap = await snapshot()
249
+ const results = []
250
+ for (const observation of snap.observations) {
251
+ if (observation.fileState !== FILE_STATE.EDITABLE) {
252
+ // provider-file / virtual 没有可信路径 → 明确是 skipped,不是 ok
253
+ results.push({
254
+ name: observation.name,
255
+ source: observation.source,
256
+ fileState: observation.fileState,
257
+ verdict: 'skipped',
258
+ reason: observation.fileState === FILE_STATE.PROVIDER_FILE
259
+ ? 'file-exists-but-not-scanned'
260
+ : 'no-instruction-file',
261
+ findings: [],
262
+ })
263
+ continue
264
+ }
265
+ const body = readSkillBody(observation.path, snap.allowlist)
266
+ if (!body.ok) {
267
+ results.push({
268
+ name: observation.name,
269
+ source: observation.source,
270
+ fileState: observation.fileState,
271
+ verdict: 'skipped',
272
+ reason: body.reason,
273
+ findings: [],
274
+ })
275
+ continue
276
+ }
277
+ const audit = auditSkillText(body.content, { name: observation.name })
278
+ results.push({
279
+ name: observation.name,
280
+ source: observation.source,
281
+ fileState: observation.fileState,
282
+ verdict: audit.verdict,
283
+ findings: audit.findings,
284
+ stats: audit.stats,
285
+ })
286
+ }
287
+
288
+ sendJson(res, 200, {
289
+ takenAt: snap.takenAt,
290
+ totals: {
291
+ ok: results.filter(r => r.verdict === 'ok').length,
292
+ warn: results.filter(r => r.verdict === 'warn').length,
293
+ fail: results.filter(r => r.verdict === 'fail').length,
294
+ skipped: results.filter(r => r.verdict === 'skipped').length,
295
+ },
296
+ results,
297
+ })
298
+ })
299
+
300
+ // ---- 读:字符预算 ----
301
+ register('/budget', ['GET'], async (req, res) => {
302
+ const snap = await snapshot()
303
+ sendJson(res, 200, { takenAt: snap.takenAt, ...budgetReport(snap.observations) })
304
+ })
305
+
306
+ // ---- 写:导入归档 ----
307
+ register('/import', ['POST'], async (req, res, body) => {
308
+ const snap = await snapshot()
309
+ const archiveBase64 = body?.archive
310
+ const targetSource = body?.targetSource ?? 'user-dsh'
311
+
312
+ if (typeof archiveBase64 !== 'string' || archiveBase64 === '') {
313
+ sendJson(res, 400, { error: 'archive-required' })
314
+ return
315
+ }
316
+
317
+ let buffer
318
+ try {
319
+ buffer = Buffer.from(archiveBase64, 'base64')
320
+ } catch {
321
+ sendJson(res, 400, { error: 'invalid-base64' })
322
+ return
323
+ }
324
+
325
+ const targetRoot = snap.roots.find(root => root.source === targetSource)
326
+ if (targetRoot === undefined) {
327
+ sendJson(res, 400, {
328
+ error: 'unknown-target-source',
329
+ available: snap.roots.map(root => root.source),
330
+ })
331
+ return
332
+ }
333
+
334
+ let parsed
335
+ try {
336
+ parsed = parseSkillsFromArchive(buffer)
337
+ } catch (error) {
338
+ const code = error?.code ?? 'archive-invalid'
339
+ const status = code === 'archive-too-large' || code === 'too-many-entries' || code === 'total-too-large' ? 413
340
+ : code === 'encrypted-entry' ? 422
341
+ : 400
342
+ sendJson(res, status, { error: code, message: String(error?.message ?? error) })
343
+ return
344
+ }
345
+
346
+ const results = []
347
+ for (const skill of parsed.skills) {
348
+ const placement = decidePlacement({
349
+ skillName: skill.name,
350
+ targetRoot,
351
+ allRoots: snap.roots,
352
+ observations: snap.observations,
353
+ })
354
+ if (!placement.ok) {
355
+ results.push({ name: skill.name, installed: false, reason: placement.reason, message: placement.message })
356
+ continue
357
+ }
358
+ const outcome = installSkill({ skill, targetDir: placement.targetDir })
359
+ results.push({ name: skill.name, ...outcome })
360
+ }
361
+
362
+ const installedCount = results.filter(r => r.installed).length
363
+ if (installedCount > 0) invalidate()
364
+
365
+ sendJson(res, installedCount > 0 ? 200 : 422, {
366
+ ok: installedCount > 0,
367
+ skippedSymlinks: parsed.skippedSymlinks,
368
+ totalBytes: parsed.totalBytes,
369
+ results,
370
+ })
371
+ })
372
+
373
+ return () => {
374
+ for (const dispose of disposers) {
375
+ try {
376
+ dispose()
377
+ } catch {
378
+ /* ignore */
379
+ }
380
+ }
381
+ disposers.length = 0
382
+ }
383
+ }
384
+
385
+ export { ROUTE_PREFIX, safePath }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-skill-harbor",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "DSH 技能港湾:技能发现、遮蔽判定、审计与市场管理插件(基础骨架)",
5
5
  "type": "module",
6
6
  "license": "MIT",