dsh-skill-harbor 0.2.0-rc.5 → 0.3.0-rc.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/dsh.plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "dsh-external/dsh-skill-harbor",
3
- "version": "0.2.0-rc.5",
3
+ "version": "0.3.0-rc.1",
4
4
  "main": "./lib/index.js",
5
5
  "description": "技能港湾:技能发现、遮蔽判定、审计与市场管理(基础骨架)",
6
6
  "engines": {
package/lib/client.js CHANGED
@@ -1,23 +1,14 @@
1
1
  /**
2
- * dsh-skill-harbor — client half.
2
+ * dsh-skill-harbor — client half(Phase 1 只占位,面板在 Phase 2 落地)。
3
3
  *
4
4
  * 注册 id **必须**等于 npm 包名,否则 DSH 静默忽略整个客户端半。
5
- * 注册必须发生在 apply 期顶层,关在任何 inject 回调里 = 失活。
6
5
  */
7
- import { createPanel } from './panel.js'
8
- import { LOCALES, LOCALE_IDS } from './locales.js'
9
-
10
6
  const id = 'dsh-skill-harbor'
11
7
 
12
- function factory(_require) {
8
+ function factory() {
13
9
  return {
14
10
  id,
15
- locales: LOCALES,
16
- localeIds: LOCALE_IDS,
17
- /** 宿主调用此方法把面板挂到槽位。 */
18
- createPanel(options = {}) {
19
- return createPanel(options)
20
- },
11
+ // Phase 2 会在这里注册 slots / 面板 / 设置卡片
21
12
  }
22
13
  }
23
14
 
@@ -25,4 +16,4 @@ if (typeof window !== 'undefined' && window.__ModuleLoader__?.load) {
25
16
  window.__ModuleLoader__.load({ id, factory })
26
17
  }
27
18
 
28
- export { id, factory, createPanel }
19
+ export { id, factory }
package/lib/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * dsh-skill-harbor — host half.
3
3
  *
4
- * Phase 1:证据层(扫描 / 三态 / 遮蔽 / provider)
5
- * Phase 2:本地管理(受闸 HTTP 路由 + 导入)
6
- * Phase 3:审计与预算
4
+ * Phase 1(证据层):扫描 6 个约定根、解析 frontmatter、三态判定、遮蔽判定,
5
+ * 通过 provider 把结果交给官方 skill registry。
6
+ * Phase 2(本地管理):受闸保护的 HTTP 路由(列表/读/启停/更新/删除)。
7
7
  *
8
8
  * Phase 0 实测结论(findings.md):
9
9
  * - `ctx.skills.registerProvider` 全线返回 `() => void`,可直接当 disposer
@@ -12,23 +12,15 @@
12
12
  */
13
13
  import { installProvider } from './provider/lifecycle.js'
14
14
  import { registerRoutes } from './routes/index.js'
15
- import { normalizeConfig } from './config.js'
16
15
 
17
16
  export const name = 'dsh-skill-harbor'
18
17
 
19
18
  export const inject = ['skills']
20
19
 
21
- export function apply(ctx, rawConfig = {}) {
22
- const config = normalizeConfig(rawConfig)
23
-
24
- // managementOnly:不注册 provider、不注册工具、不碰 ctx.skills。
25
- // 只保留只读路由(面板仍能列出它自己扫到的东西)。
26
- if (!config.managementOnly) {
27
- installProvider(ctx, config)
28
- }
20
+ export function apply(ctx, config = {}) {
21
+ installProvider(ctx, config)
29
22
 
23
+ // webServer 可能不存在(纯 CLI 场景)→ registerRoutes 内部自行降级
30
24
  const disposeRoutes = registerRoutes(ctx, config)
31
25
  ctx.effect(() => disposeRoutes, 'dsh-skill-harbor.routes')
32
-
33
- return { name, managementOnly: config.managementOnly }
34
26
  }
@@ -15,7 +15,6 @@ import { FILE_STATE, isWritable } from '../collect/observe.js'
15
15
  import { extractSkillMeta } from '../collect/frontmatter.js'
16
16
  import { auditSkillText } from '../audit/rules.js'
17
17
  import { budgetReport } from '../budget/announcement.js'
18
- import { parseSkillsFromArchive, decidePlacement, installSkill } from '../market/install.js'
19
18
 
20
19
  /** 关闭/开启模型的 frontmatter 键。 */
21
20
  const DISABLE_KEY = 'disable-model-invocation'
@@ -303,73 +302,6 @@ export function registerRoutes(ctx, config = {}, deps = {}) {
303
302
  sendJson(res, 200, { takenAt: snap.takenAt, ...budgetReport(snap.observations) })
304
303
  })
305
304
 
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
305
  return () => {
374
306
  for (const dispose of disposers) {
375
307
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-skill-harbor",
3
- "version": "0.2.0-rc.5",
3
+ "version": "0.3.0-rc.1",
4
4
  "description": "DSH 技能港湾:技能发现、遮蔽判定、审计与市场管理插件(基础骨架)",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/client.js CHANGED
@@ -1,23 +1,14 @@
1
1
  /**
2
- * dsh-skill-harbor — client half.
2
+ * dsh-skill-harbor — client half(Phase 1 只占位,面板在 Phase 2 落地)。
3
3
  *
4
4
  * 注册 id **必须**等于 npm 包名,否则 DSH 静默忽略整个客户端半。
5
- * 注册必须发生在 apply 期顶层,关在任何 inject 回调里 = 失活。
6
5
  */
7
- import { createPanel } from './panel.js'
8
- import { LOCALES, LOCALE_IDS } from './locales.js'
9
-
10
6
  const id = 'dsh-skill-harbor'
11
7
 
12
- function factory(_require) {
8
+ function factory() {
13
9
  return {
14
10
  id,
15
- locales: LOCALES,
16
- localeIds: LOCALE_IDS,
17
- /** 宿主调用此方法把面板挂到槽位。 */
18
- createPanel(options = {}) {
19
- return createPanel(options)
20
- },
11
+ // Phase 2 会在这里注册 slots / 面板 / 设置卡片
21
12
  }
22
13
  }
23
14
 
@@ -25,4 +16,4 @@ if (typeof window !== 'undefined' && window.__ModuleLoader__?.load) {
25
16
  window.__ModuleLoader__.load({ id, factory })
26
17
  }
27
18
 
28
- export { id, factory, createPanel }
19
+ export { id, factory }
package/src/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * dsh-skill-harbor — host half.
3
3
  *
4
- * Phase 1:证据层(扫描 / 三态 / 遮蔽 / provider)
5
- * Phase 2:本地管理(受闸 HTTP 路由 + 导入)
6
- * Phase 3:审计与预算
4
+ * Phase 1(证据层):扫描 6 个约定根、解析 frontmatter、三态判定、遮蔽判定,
5
+ * 通过 provider 把结果交给官方 skill registry。
6
+ * Phase 2(本地管理):受闸保护的 HTTP 路由(列表/读/启停/更新/删除)。
7
7
  *
8
8
  * Phase 0 实测结论(findings.md):
9
9
  * - `ctx.skills.registerProvider` 全线返回 `() => void`,可直接当 disposer
@@ -12,23 +12,15 @@
12
12
  */
13
13
  import { installProvider } from './provider/lifecycle.js'
14
14
  import { registerRoutes } from './routes/index.js'
15
- import { normalizeConfig } from './config.js'
16
15
 
17
16
  export const name = 'dsh-skill-harbor'
18
17
 
19
18
  export const inject = ['skills']
20
19
 
21
- export function apply(ctx, rawConfig = {}) {
22
- const config = normalizeConfig(rawConfig)
23
-
24
- // managementOnly:不注册 provider、不注册工具、不碰 ctx.skills。
25
- // 只保留只读路由(面板仍能列出它自己扫到的东西)。
26
- if (!config.managementOnly) {
27
- installProvider(ctx, config)
28
- }
20
+ export function apply(ctx, config = {}) {
21
+ installProvider(ctx, config)
29
22
 
23
+ // webServer 可能不存在(纯 CLI 场景)→ registerRoutes 内部自行降级
30
24
  const disposeRoutes = registerRoutes(ctx, config)
31
25
  ctx.effect(() => disposeRoutes, 'dsh-skill-harbor.routes')
32
-
33
- return { name, managementOnly: config.managementOnly }
34
26
  }
@@ -15,7 +15,6 @@ import { FILE_STATE, isWritable } from '../collect/observe.js'
15
15
  import { extractSkillMeta } from '../collect/frontmatter.js'
16
16
  import { auditSkillText } from '../audit/rules.js'
17
17
  import { budgetReport } from '../budget/announcement.js'
18
- import { parseSkillsFromArchive, decidePlacement, installSkill } from '../market/install.js'
19
18
 
20
19
  /** 关闭/开启模型的 frontmatter 键。 */
21
20
  const DISABLE_KEY = 'disable-model-invocation'
@@ -303,73 +302,6 @@ export function registerRoutes(ctx, config = {}, deps = {}) {
303
302
  sendJson(res, 200, { takenAt: snap.takenAt, ...budgetReport(snap.observations) })
304
303
  })
305
304
 
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
305
  return () => {
374
306
  for (const dispose of disposers) {
375
307
  try {
package/lib/client/api.js DELETED
@@ -1,79 +0,0 @@
1
- /**
2
- * 客户端唯一 fetch 出口。
3
- *
4
- * 必须按 `document.baseURI` 解析 —— 反代带路径前缀(如 `/app/dsh/`)部署时,
5
- * 写死 `/api/...` 会打到站点根而不是应用根,全部 404。
6
- */
7
- import { LOCALES } from './locales.js'
8
-
9
- export const API_PREFIX = '/dsh-skill-harbor/api'
10
- export const CSRF_HEADER = 'x-dsh-skill-harbor'
11
-
12
- /**
13
- * 相对路径 → 绝对 URL,锚定到 document.baseURI。
14
- * 非 `/` 开头或无 document 环境时原样返回。
15
- */
16
- export function resolveApiUrl(path) {
17
- if (typeof path !== 'string') return String(path)
18
- try {
19
- if (path.startsWith('/') && typeof document !== 'undefined' && document.baseURI) {
20
- return new URL(path.slice(1), document.baseURI).href
21
- }
22
- } catch {
23
- /* 落到原样返回 */
24
- }
25
- return path
26
- }
27
-
28
- async function request(path, options = {}) {
29
- const url = resolveApiUrl(`${API_PREFIX}${path}`)
30
- const method = options.method ?? 'GET'
31
-
32
- const headers = { ...options.headers }
33
- if (method !== 'GET' && method !== 'HEAD') {
34
- // 写方法必须带自定义头;跨站表单设不了这个头
35
- headers[CSRF_HEADER] = '1'
36
- if (options.body !== undefined) headers['content-type'] = 'application/json'
37
- }
38
-
39
- const response = await fetch(url, {
40
- method,
41
- headers,
42
- credentials: 'same-origin',
43
- ...options.body === undefined ? {} : { body: JSON.stringify(options.body) },
44
- })
45
-
46
- let payload = null
47
- try {
48
- payload = await response.json()
49
- } catch {
50
- payload = null
51
- }
52
-
53
- if (!response.ok) {
54
- const error = new Error(payload?.message ?? payload?.error ?? `HTTP ${response.status}`)
55
- error.status = response.status
56
- error.payload = payload
57
- throw error
58
- }
59
- return payload
60
- }
61
-
62
- export const api = {
63
- list: () => request('/list'),
64
- read: path => request(`/read?path=${encodeURIComponent(path)}`),
65
- audit: () => request('/audit'),
66
- budget: () => request('/budget'),
67
- setEnabled: (path, enabled) => request('/set-enabled', { method: 'POST', body: { path, enabled } }),
68
- update: (path, content) => request('/update', { method: 'POST', body: { path, content } }),
69
- remove: path => request('/delete', { method: 'POST', body: { path } }),
70
- importArchive: (archive, targetSource) =>
71
- request('/import', { method: 'POST', body: { archive, targetSource } }),
72
- }
73
-
74
- /** 取某语言的字典,缺省回落 zh。 */
75
- export function dict(lang) {
76
- return LOCALES[lang] ?? LOCALES.zh
77
- }
78
-
79
- export { request }
@@ -1,6 +0,0 @@
1
- /** 状态的显示标签(与 locales 分离,供 panel 复用)。 */
2
- export const FILE_STATE_LABEL = Object.freeze({
3
- editable: 'editable',
4
- 'provider-file': 'provider-file',
5
- virtual: 'virtual',
6
- })