dsh-skill-hub 0.3.6 → 0.3.8

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.
Files changed (122) hide show
  1. package/README.md +40 -50
  2. package/README.zh.md +38 -48
  3. package/lib/client.js +2569 -1646
  4. package/lib/client.js.map +1 -1
  5. package/lib/index.js +988 -400
  6. package/lib/types/client/SkillHubSettingsCard.d.ts +1 -2
  7. package/lib/types/client/api.d.ts +15 -5
  8. package/lib/types/client/helpers.d.ts +10 -1
  9. package/lib/types/client/locales/common.d.ts +52 -0
  10. package/lib/types/client/locales/detail.d.ts +16 -0
  11. package/lib/types/client/locales/market.d.ts +73 -0
  12. package/lib/types/client/locales/settings.d.ts +41 -0
  13. package/lib/types/client/locales/skills.d.ts +65 -0
  14. package/lib/types/client/locales/sources.d.ts +35 -0
  15. package/lib/types/client/locales.d.ts +147 -111
  16. package/lib/types/client/panel/DisabledRow.d.ts +2 -0
  17. package/lib/types/client/panel/MarketSourceRow.d.ts +12 -0
  18. package/lib/types/client/panel/MarketView.d.ts +1 -0
  19. package/lib/types/client/panel/RepoScanCard.d.ts +10 -0
  20. package/lib/types/client/panel/SkillDetailView.d.ts +5 -1
  21. package/lib/types/client/panel/dialogs.d.ts +19 -0
  22. package/lib/types/client/panel/hooks/shared.d.ts +72 -0
  23. package/lib/types/client/panel/hooks/useCatalogFlow.d.ts +62 -0
  24. package/lib/types/client/panel/hooks/useGroupFlow.d.ts +41 -0
  25. package/lib/types/client/panel/hooks/useMarketFlow.d.ts +73 -0
  26. package/lib/types/client/panel/hooks/useMetaFlow.d.ts +18 -0
  27. package/lib/types/client/panel/hooks/useSourceFlow.d.ts +44 -0
  28. package/lib/types/client/panel/market-format.d.ts +6 -0
  29. package/lib/types/client/panel/useSkillHub.d.ts +54 -71
  30. package/lib/types/client/settings-card.d.ts +20 -17
  31. package/lib/types/client/settings-form.d.ts +6 -1
  32. package/lib/types/protocol/api.d.ts +38 -0
  33. package/lib/types/protocol/catalog.d.ts +155 -0
  34. package/lib/types/protocol/config.d.ts +113 -0
  35. package/lib/types/protocol/groups.d.ts +95 -0
  36. package/lib/types/protocol/market.d.ts +94 -0
  37. package/lib/types/protocol/repo.d.ts +107 -0
  38. package/lib/types/protocol/sources.d.ts +139 -0
  39. package/lib/types/protocol/stats.d.ts +46 -0
  40. package/lib/types/protocol.d.ts +13 -720
  41. package/lib/types/repo/github-client.d.ts +42 -0
  42. package/lib/types/repo.d.ts +9 -22
  43. package/lib/types/routes/catalog.d.ts +7 -0
  44. package/lib/types/routes/config.d.ts +7 -0
  45. package/lib/types/routes/groups.d.ts +7 -0
  46. package/lib/types/routes/helpers.d.ts +145 -0
  47. package/lib/types/routes/market.d.ts +8 -0
  48. package/lib/types/routes/repo-import.d.ts +7 -0
  49. package/lib/types/routes/route-state.d.ts +55 -0
  50. package/lib/types/routes/sources.d.ts +8 -0
  51. package/lib/types/routes.d.ts +5 -34
  52. package/lib/types/skillfs.d.ts +13 -0
  53. package/lib/types/stats.d.ts +3 -2
  54. package/lib/types/store/errors.d.ts +10 -0
  55. package/lib/types/store/migrate.d.ts +44 -0
  56. package/lib/types/store/paths.d.ts +32 -0
  57. package/lib/types/store/store.d.ts +133 -0
  58. package/lib/types/store.d.ts +7 -146
  59. package/package.json +30 -28
  60. package/src/client/SkillHubSettingsCard.tsx +17 -5
  61. package/src/client/api.ts +108 -184
  62. package/src/client/helpers.ts +50 -1
  63. package/src/client/locales/common.ts +102 -0
  64. package/src/client/locales/detail.ts +30 -0
  65. package/src/client/locales/market.ts +144 -0
  66. package/src/client/locales/settings.ts +80 -0
  67. package/src/client/locales/skills.ts +128 -0
  68. package/src/client/locales/sources.ts +68 -0
  69. package/src/client/locales.ts +26 -452
  70. package/src/client/panel/DisabledRow.tsx +22 -7
  71. package/src/client/panel/MarketSourceRow.tsx +108 -0
  72. package/src/client/panel/MarketView.tsx +12 -246
  73. package/src/client/panel/RepoScanCard.tsx +171 -0
  74. package/src/client/panel/ScenesView.tsx +1 -1
  75. package/src/client/panel/SkillDetailView.tsx +35 -11
  76. package/src/client/panel/SkillHubPanel.tsx +42 -4
  77. package/src/client/panel/SkillRow.tsx +5 -2
  78. package/src/client/panel/SourcesView.tsx +2 -17
  79. package/src/client/panel/dialogs.tsx +61 -0
  80. package/src/client/panel/hooks/shared.ts +81 -0
  81. package/src/client/panel/hooks/useCatalogFlow.ts +211 -0
  82. package/src/client/panel/hooks/useGroupFlow.ts +240 -0
  83. package/src/client/panel/hooks/useMarketFlow.ts +421 -0
  84. package/src/client/panel/hooks/useMetaFlow.ts +58 -0
  85. package/src/client/panel/hooks/useSourceFlow.ts +193 -0
  86. package/src/client/panel/market-format.ts +22 -0
  87. package/src/client/panel/panel.module.css +1 -8
  88. package/src/client/panel/useSkillHub.ts +142 -948
  89. package/src/client/settings-card.tsx +51 -42
  90. package/src/client/settings-form.ts +19 -5
  91. package/src/index.ts +14 -4
  92. package/src/protocol/api.ts +38 -0
  93. package/src/protocol/catalog.ts +168 -0
  94. package/src/protocol/config.ts +145 -0
  95. package/src/protocol/groups.ts +106 -0
  96. package/src/protocol/market.ts +100 -0
  97. package/src/protocol/repo.ts +104 -0
  98. package/src/protocol/sources.ts +146 -0
  99. package/src/protocol/stats.ts +42 -0
  100. package/src/protocol.ts +83 -775
  101. package/src/repo/github-client.ts +131 -0
  102. package/src/repo.test.ts +24 -1
  103. package/src/repo.ts +69 -147
  104. package/src/routes/catalog.ts +309 -0
  105. package/src/routes/config.ts +119 -0
  106. package/src/routes/groups.ts +133 -0
  107. package/src/routes/helpers.ts +489 -0
  108. package/src/routes/market.ts +255 -0
  109. package/src/routes/repo-import.ts +267 -0
  110. package/src/routes/route-state.ts +89 -0
  111. package/src/routes/sources.ts +318 -0
  112. package/src/routes.test.ts +42 -0
  113. package/src/routes.ts +21 -1528
  114. package/src/skillfs.ts +188 -3
  115. package/src/stats.test.ts +58 -3
  116. package/src/stats.ts +45 -16
  117. package/src/store/errors.ts +14 -0
  118. package/src/store/migrate.ts +272 -0
  119. package/src/store/paths.ts +43 -0
  120. package/src/store/store.ts +532 -0
  121. package/src/store.test.ts +18 -0
  122. package/src/store.ts +7 -737
package/src/protocol.ts CHANGED
@@ -3,780 +3,88 @@
3
3
  * both the host half and the browser half import. The browser half must never
4
4
  * depend on host SDK packages, so registry types are re-spelled here as
5
5
  * plain JSON-safe interfaces.
6
+ *
7
+ * 按域拆分后的重导出入口:老 `from './protocol.ts'` 写法保持可用,
8
+ * 新代码可按需直引 `from './protocol/<domain>.ts'`。
6
9
  */
7
10
 
8
- /** Browser-facing base paths of the skill-hub API family. */
9
- export const SKILL_HUB_API = {
10
- catalog: '/api/skill-hub/catalog',
11
- skill: '/api/skill-hub/skill',
12
- skillDelete: '/api/skill-hub/skill/delete',
13
- toggle: '/api/skill-hub/toggle',
14
- toggleBatch: '/api/skill-hub/toggle-batch',
15
- create: '/api/skill-hub/create',
16
- stats: '/api/skill-hub/stats',
17
- config: '/api/skill-hub/config',
18
- market: '/api/skill-hub/market',
19
- marketSource: '/api/skill-hub/market/source',
20
- marketSourceDelete: '/api/skill-hub/market/source/delete',
21
- marketSourceRef: '/api/skill-hub/market/source/ref',
22
- marketCheck: '/api/skill-hub/market/check',
23
- marketSync: '/api/skill-hub/market/source/sync',
24
- repo: '/api/skill-hub/repo',
25
- repoImport: '/api/skill-hub/repo/import',
26
- repoImportProgress: '/api/skill-hub/repo/import/progress',
27
- repoImportCancel: '/api/skill-hub/repo/import/cancel',
28
- update: '/api/skill-hub/update',
29
- groups: '/api/skill-hub/groups',
30
- tag: '/api/skill-hub/tag',
31
- tagDelete: '/api/skill-hub/tag/delete',
32
- tagMembers: '/api/skill-hub/tag/members',
33
- tagReorder: '/api/skill-hub/tag/reorder',
34
- collectionReorder: '/api/skill-hub/collections/reorder',
35
- sourceGroupReorder: '/api/skill-hub/source-groups/reorder',
36
- sources: '/api/skill-hub/sources',
37
- sourceCheck: '/api/skill-hub/sources/check',
38
- sourceSync: '/api/skill-hub/sources/sync',
39
- sourceDelete: '/api/skill-hub/sources/delete',
40
- sourceRestore: '/api/skill-hub/sources/restore',
41
- sourceTrashClear: '/api/skill-hub/sources/trash/clear',
42
- } as const
43
-
44
- /** User-level roots the hub may write to (matches dsh-skill-filesystem ranks 400/500). */
45
- export type WritableRoot = 'user-dsh' | 'user-agents'
46
-
47
- /** Invocation policy resolved by the registry, re-spelled for the wire. */
48
- export interface HubInvocation {
49
- /** Whether model-facing catalogs may load this skill. */
50
- modelInvocable: boolean
51
- /** Whether human-facing command catalogs may load this skill. */
52
- userInvocable: boolean
53
- }
54
-
55
- /** One enabled skill row in the catalog. */
56
- export interface CatalogSkill {
57
- name: string
58
- description: string
59
- whenToUse?: string
60
- invocation: HubInvocation
61
- provider: string
62
- /** Whether the hub may toggle this skill (user-level filesystem skills only). */
63
- writable: boolean
64
- /** 技能来源标识(user-dsh/user-agents/project-dsh/project-agents/...)。 */
65
- source: string
66
- /** SKILL.md creation time (epoch ms); used for "added" sorting. Absent when unknown. */
67
- addedAt?: number
68
- /** SKILL.md last-modified time (epoch ms); used for "updated" display. Absent when unknown. */
69
- updatedAt?: number
70
- /** 项目技能的所属工作区路径(仅 project-dsh/project-agents 来源携带)。 */
71
- workspace?: string
72
- /** 工作区显示标题(来自 workspace.json;无则回退为路径)。 */
73
- workspaceTitle?: string
74
- }
75
-
76
- /** One disabled skill tracked by the hub sidecar (SKILL.md renamed away). */
77
- export interface DisabledSkill {
78
- name: string
79
- description: string
80
- /** Absolute path of the renamed file (SKILL.md.disabled / <name>.md.disabled). */
81
- path: string
82
- root: WritableRoot
83
- disabledAt: number
84
- }
85
-
86
- /** One discovery diagnostic: a file the filesystem provider skips, with the reason. */
87
- export interface DiagnosticEntry {
88
- path: string
89
- root: string
90
- reason: string
91
- }
92
-
93
- /** GET /api/skill-hub/catalog */
94
- export interface CatalogResponse {
95
- ok: true
96
- /** 已安装插件自身的版本号(package.json version),面板标题旁显示。 */
97
- pluginVersion: string
98
- /** Whether discovery completed within a stable catalog revision. */
99
- complete: boolean
100
- /** Sorted winning summaries of every enabled skill (all roots + providers). */
101
- skills: CatalogSkill[]
102
- /** Skills the hub has toggled off (kept outside provider discovery). */
103
- disabled: DisabledSkill[]
104
- /** Files in the writable roots the provider ignores, with reasons. */
105
- diagnostics: DiagnosticEntry[]
106
- }
107
-
108
- /** GET /api/skill-hub/skill */
109
- export interface SkillDetail {
110
- name: string
111
- description: string
112
- whenToUse?: string
113
- invocation: HubInvocation
114
- provider: string
115
- /** Absolute file path when the skill came from disk. */
116
- path?: string
117
- /** SKILL.md creation time (epoch ms); absent when the file is unreadable. */
118
- addedAt?: number
119
- /** SKILL.md last-modified time (epoch ms); absent when the file is unreadable. */
120
- updatedAt?: number
121
- /** Markdown instruction body. */
122
- content: string
123
- }
124
-
125
- export interface SkillDetailResponse {
126
- ok: true
127
- skill: SkillDetail
128
- }
129
-
130
- /** POST /api/skill-hub/skill/delete — 把单个技能移入回收站(可恢复)。 */
131
- export interface SkillDeleteRequest {
132
- name: string
133
- }
134
-
135
- /** POST /api/skill-hub/skill/delete */
136
- export interface SkillDeleteResponse {
137
- ok: true
138
- name: string
139
- /** 移入回收站后的路径(目录或文件)。 */
140
- path: string
141
- }
142
-
143
- /** POST /api/skill-hub/toggle */
144
- export interface ToggleRequest {
145
- /** Kebab-case skill name. */
146
- name: string
147
- /** true re-enables a hub-disabled skill; false disables an enabled one. */
148
- enabled: boolean
149
- }
150
-
151
- export interface ToggleResponse {
152
- ok: true
153
- /** Fresh catalog after the mutation (the filesystem provider may lag a beat). */
154
- catalog: CatalogResponse
155
- }
156
-
157
- /** POST /api/skill-hub/toggle-batch — one group of skills, one write. */
158
- export interface ToggleBatchRequest {
159
- names: string[]
160
- enabled: boolean
161
- }
162
-
163
- /** POST /api/skill-hub/toggle-batch */
164
- export interface ToggleBatchResponse {
165
- ok: true
166
- catalog: CatalogResponse
167
- /** Per-name failures (unknown/read-only skills); empty means all landed. */
168
- failures: Array<{ name: string; error: string }>
169
- }
170
-
171
- /** POST /api/skill-hub/create */
172
- export interface CreateRequest {
173
- /** Kebab-case skill name (validated with the official isSkillName grammar). */
174
- name: string
175
- /** Optional one-line routing description for the frontmatter. */
176
- description?: string
177
- /** Target user root; defaults to user-dsh (~/.dsh/skills). */
178
- root?: WritableRoot
179
- }
180
-
181
- export interface CreateResponse {
182
- ok: true
183
- path: string
184
- root: WritableRoot
185
- }
186
-
187
- /** One skill's invocation stats across the local session logs. */
188
- export interface SkillStat {
189
- /** Kebab-case skill name. */
190
- name: string
191
- /** How many sessions recorded a user-explicit invocation of this skill. */
192
- count: number
193
- /** Unix epoch ms of the most recent invocation (absent when never called). */
194
- lastUsed?: number
195
- }
196
-
197
- /** GET /api/skill-hub/stats */
198
- export interface StatsResponse {
199
- ok: true
200
- /** Whether a session-log source was available (false means counts are empty). */
201
- available: boolean
202
- /** Sorted per-skill invocation counts. */
203
- stats: SkillStat[]
204
- }
205
-
206
- /**
207
- * Persisted incremental-scan checkpoint for the usage statistics (sidecar
208
- * `skillStats` field). Sessions created before `frozenBefore` are treated as
209
- * finalized: their per-session counts live in `frozenSessions` (only sessions
210
- * with at least one invocation are kept) and they are not re-read on
211
- * incremental scans. A daily full reconciliation rebuilds the cache and
212
- * advances the watermark, so a resumed old session is eventually re-counted.
213
- */
214
- export interface SkillStatsCheckpoint {
215
- /** The rolling-window configuration this checkpoint was built for (0 = all history). */
216
- windowDays: number
217
- /** Watermark: every session with header.createdAt < this value is frozen. */
218
- frozenBefore: number
219
- /** Per-session counts of finalized sessions, keyed by session id. */
220
- frozenSessions: Record<string, { createdAt: number; counts: Record<string, { count: number; lastUsed: number }> }>
221
- /** Epoch ms of the last full reconciliation (drives the daily cadence). */
222
- lastFullReconcile: number
223
- }
224
-
225
- /** JSON error body shared by every route. */
226
- export interface ErrorResponse {
227
- error: string
228
- }
229
-
230
- /** The skill hub's own runtime configuration, edited from the settings card. */
231
- export interface HubConfig {
232
- /** Master switch: routes, provider, and announcement all go live with this. */
233
- enabled: boolean
234
- /** When true, a system-prompt section announces the hub to every agent. */
235
- announceToAgent: boolean
236
- /** Model-invocable dot color (#rrggbb); absent means the panel default. */
237
- dotModelColor?: string
238
- /** User-invocable dot color (#rrggbb); absent means the panel default. */
239
- dotUserColor?: string
240
- /** Show per-skill invocation count chip. Default true. */
241
- showUseCount?: boolean
242
- /** Show per-skill last-used relative time. Default true. */
243
- showUseTime?: boolean
244
- /** Show group-header usage summaries (count + last used). Default true. */
245
- showGroupSummary?: boolean
246
- /** 统计滚动窗口天数:只统计最近 N 天的使用;0 = 全部历史。默认 0。 */
247
- statsWindowDays?: number
248
- /** 自动统计扫描间隔(分钟,最小 1)。默认 5。 */
249
- statsScanMinutes?: number
250
- }
251
-
252
- /**
253
- * The resolved shape of the hub's settings namespace (schema defaults, then
254
- * the composition base, then the user layer). Kept as a type alias so the
255
- * browser-side settings scope snapshot is index-compatible with the card
256
- * form's record shape.
257
- */
258
- export type HubSettingsValue = {
259
- enabled: boolean
260
- announceToAgent: boolean
261
- showUseCount: boolean
262
- showUseTime: boolean
263
- showGroupSummary: boolean
264
- /** Model-invocable dot color (#rrggbb); absent means the panel default. */
265
- dotModelColor?: string
266
- /** User-invocable dot color (#rrggbb); absent means the panel default. */
267
- dotUserColor?: string
268
- /** 统计滚动窗口天数(0 = 全部历史)。 */
269
- statsWindowDays?: number
270
- /** 自动统计扫描间隔(分钟)。 */
271
- statsScanMinutes?: number
272
- }
273
-
274
- /**
275
- * Hub config defaults — the single source every layer reads: the cordis
276
- * schema (index.ts), the host's saved-override merge, and the routes'
277
- * fallback view. Changing a default here changes all three.
278
- */
279
- export const HUB_CONFIG_DEFAULTS = {
280
- enabled: true,
281
- announceToAgent: true,
282
- showUseCount: true,
283
- showUseTime: true,
284
- showGroupSummary: true,
285
- statsWindowDays: 14,
286
- statsScanMinutes: 5,
287
- } as const
288
-
289
- /**
290
- * Resolve the effective hub config: saved sidecar overrides win over the
291
- * cordis composition entry (the web card owns runtime config), missing
292
- * booleans fall back to HUB_CONFIG_DEFAULTS, and dot colors pass through
293
- * (saved first, then base) only when set. Numeric stats knobs are clamped to
294
- * their sane ranges (window ≥ 0, scan interval ≥ 1 minute).
295
- */
296
- export function resolveHubConfig(saved: Partial<HubConfig>, base: Partial<HubConfig> = {}): HubConfig {
297
- const dotModelColor = saved.dotModelColor !== undefined ? saved.dotModelColor : base.dotModelColor
298
- const dotUserColor = saved.dotUserColor !== undefined ? saved.dotUserColor : base.dotUserColor
299
- const windowDays = clampNumber(saved.statsWindowDays ?? base.statsWindowDays, 0) ?? HUB_CONFIG_DEFAULTS.statsWindowDays
300
- const scanMinutes = clampNumber(saved.statsScanMinutes ?? base.statsScanMinutes, 1) ?? HUB_CONFIG_DEFAULTS.statsScanMinutes
301
- return {
302
- enabled: saved.enabled ?? base.enabled ?? HUB_CONFIG_DEFAULTS.enabled,
303
- announceToAgent: saved.announceToAgent ?? base.announceToAgent ?? HUB_CONFIG_DEFAULTS.announceToAgent,
304
- showUseCount: saved.showUseCount ?? base.showUseCount ?? HUB_CONFIG_DEFAULTS.showUseCount,
305
- showUseTime: saved.showUseTime ?? base.showUseTime ?? HUB_CONFIG_DEFAULTS.showUseTime,
306
- showGroupSummary: saved.showGroupSummary ?? base.showGroupSummary ?? HUB_CONFIG_DEFAULTS.showGroupSummary,
307
- statsWindowDays: windowDays,
308
- statsScanMinutes: scanMinutes,
309
- ...(dotModelColor !== undefined ? { dotModelColor } : {}),
310
- ...(dotUserColor !== undefined ? { dotUserColor } : {}),
311
- }
312
- }
313
-
314
- /** Clamp a numeric override into a valid value; undefined/invalid stays undefined. */
315
- function clampNumber(value: unknown, min: number): number | undefined {
316
- if (typeof value !== 'number' || !Number.isFinite(value) || value < min) return undefined
317
- return Math.floor(value)
318
- }
319
-
320
- /** HEX color validation shared by host routes and the settings card. */
321
- export const HEX_COLOR_RE = /^#[0-9a-f]{6}$/i
322
-
323
- /** GET /api/skill-hub/config */
324
- export interface ConfigResponse {
325
- ok: true
326
- /** 已安装插件自身的版本号(package.json version),设置卡标题旁显示。 */
327
- pluginVersion: string
328
- /** Effective configuration (saved overrides merged over the defaults). */
329
- config: HubConfig
330
- /** Raw user overrides persisted in the sidecar (absent fields inherit defaults). */
331
- saved: Partial<HubConfig>
332
- }
333
-
334
- /** POST /api/skill-hub/config — a partial patch; omitted fields keep their values. */
335
- export interface ConfigRequest {
336
- /** Set the field; null clears the saved override so it re-inherits the default. */
337
- enabled?: boolean | null
338
- /** Set the field; null clears the saved override so it re-inherits the default. */
339
- announceToAgent?: boolean | null
340
- /** Set the field; null clears the saved override so it re-inherits the default. */
341
- showUseCount?: boolean | null
342
- /** Set the field; null clears the saved override so it re-inherits the default. */
343
- showUseTime?: boolean | null
344
- /** Set the field; null clears the saved override so it re-inherits the default. */
345
- showGroupSummary?: boolean | null
346
- /** Set the dot color; null clears the saved override so it re-inherits the default. */
347
- dotModelColor?: string | null
348
- /** Set the dot color; null clears the saved override so it re-inherits the default. */
349
- dotUserColor?: string | null
350
- /** 统计滚动窗口天数(0 = 全部历史);null 清除覆盖回默认。 */
351
- statsWindowDays?: number | null
352
- /** 自动统计扫描间隔(分钟);null 清除覆盖回默认。 */
353
- statsScanMinutes?: number | null
354
- }
355
-
356
- /** One market source: a tracked upstream repo plus its pinned version. */
357
- export interface MarketSourceRecord {
358
- /** Repo slug (owner/repo). */
359
- repo: string
360
- /** Pinned version: release tag, branch name, or custom ref. Absent = not yet pinned. */
361
- ref?: string
362
- /** Commit the pinned ref last resolved to (update-check baseline). */
363
- commitSha?: string
364
- }
365
-
366
- /** GET /api/skill-hub/market — the user's added market sources. */
367
- export interface MarketSourcesResponse {
368
- ok: true
369
- /** Added market sources, in addition order. */
370
- repos: MarketSourceRecord[]
371
- }
372
-
373
- /** POST /api/skill-hub/market/source — add one repo as a market source. */
374
- export interface MarketSourceRequest {
375
- /** owner/repo, owner/repo@ref, or a github.com URL. */
376
- repo: string
377
- }
378
-
379
- /** POST /api/skill-hub/market/source|delete */
380
- export interface MarketSourceResponse {
381
- ok: true
382
- repos: MarketSourceRecord[]
383
- }
384
-
385
- /** POST /api/skill-hub/market/source/ref — pin a market source to an explicit ref. */
386
- export interface MarketSourceRefRequest {
387
- repo: string
388
- /** Release tag or branch name chosen for the repo. */
389
- ref: string
390
- }
391
-
392
- /** GET /api/skill-hub/market/check — update check over market sources. */
393
- export interface MarketCheckResponse {
394
- ok: true
395
- results: Array<{
396
- repo: string
397
- /** Pinned ref, when one is recorded. */
398
- ref?: string
399
- /** Latest release tag on the repo, when it has one. */
400
- latestTag?: string
401
- /** Whether the pinned ref (or the repo) has moved ahead. */
402
- updateAvailable: boolean
403
- /** Latest commit of the checked ref. */
404
- commitSha: string
405
- /** Throttled: the check was skipped within the interval. */
406
- throttled?: boolean
407
- error?: string
408
- }>
409
- }
410
-
411
- /** POST /api/skill-hub/market/source/sync — align a market source to its pinned ref. */
412
- export interface MarketSyncResponse {
413
- ok: true
414
- repo: string
415
- /** The ref the source is now pinned to. */
416
- ref: string
417
- commitSha: string
418
- /** Local skills tracked from this repo (candidates for a batch update). */
419
- skills: string[]
420
- }
421
-
422
- /** A skill discovered in a GitHub repo under any top-level root (e.g. skills/, templates/). */
423
- export interface RepoSkillEntry {
424
- /** Kebab-case skill name (directory basename). */
425
- name: string
426
- /** Root-relative skill directory, e.g. skills/code-review. */
427
- dir: string
428
- /** Root-relative SKILL.md path, e.g. skills/code-review/SKILL.md. */
429
- path: string
430
- /** Repo root the skill lives in. */
431
- root: RepoRoot
432
- /** Collection name recorded as origin after import. */
433
- origin: string
434
- /** Number of files in the skill directory. */
435
- fileCount: number
436
- /** Total bytes across all files in the skill directory. */
437
- totalBytes: number
438
- /** Whether a same-named skill already exists locally. */
439
- existing: boolean
440
- }
441
-
442
- /** Skill root in a GitHub repo: the top-level directory that contains skills (e.g. skills, design-templates, templates). Auto-derived from SKILL.md locations, not hard-coded. */
443
- export type RepoRoot = string
444
-
445
- /** GET /api/skill-hub/repo — discover importable skills in a GitHub repo. */
446
- export interface RepoDiscoverResponse {
447
- ok: true
448
- repo: string
449
- /**
450
- * Ref the discovery ran against (release tag / branch / default branch).
451
- * Null means the repo has no release and no pinned ref — the client must
452
- * ask the user to pick a branch (see `branches`) and pin it first.
453
- */
454
- ref: string | null
455
- /** Branch names to choose from when ref is null (default branch first). */
456
- branches?: string[]
457
- entries: RepoSkillEntry[]
458
- }
459
-
460
- /** POST /api/skill-hub/repo/import — install selected repo skills. */
461
- export interface RepoImportRequest {
462
- repo: string
463
- /** Selected SKILL.md paths from the discover response. */
464
- paths: string[]
465
- /** The ref the discovery ran against; the import must use the same one. */
466
- ref?: string
467
- }
468
-
469
- /** POST /api/skill-hub/repo/import — now creates an async job (B方案) */
470
- export interface RepoImportResponse {
471
- ok: true
472
- jobId: string
473
- total: number
474
- totalBytes: number
475
- }
476
-
477
- /** GET /api/skill-hub/repo/import/progress?jobId=xxx */
478
- export interface RepoImportProgressResponse {
479
- ok: true
480
- jobId: string
481
- status: 'running' | 'done' | 'cancelled' | 'error'
482
- total: number
483
- done: number
484
- /** 当前正在下载的 skill 名,done < total 时有效 */
485
- current?: string
486
- /** 当前正在下载的文件路径(相对 skill dir) */
487
- currentFile?: string
488
- /** 字节级进度 */
489
- totalBytes: number
490
- downloadedBytes: number
491
- /** 下载速度 bytes/sec,running 时有效 */
492
- bytesPerSecond?: number
493
- imported: Array<{ name: string; origin: string; path: string }>
494
- skipped: Array<{ name: string; reason: 'exists' }>
495
- failed: Array<{ name: string; error: string }>
496
- /** error 状态时的原因 */
497
- error?: string
498
- }
499
-
500
- /** POST /api/skill-hub/repo/import/cancel */
501
- export interface RepoImportCancelRequest {
502
- jobId: string
503
- }
504
- export interface RepoImportCancelResponse {
505
- ok: true
506
- jobId: string
507
- status: 'cancelled' | 'done'
508
- }
509
-
510
- /** @deprecated 旧同步响应,保留供类型兼容,实际已由 Progress 代替 */
511
- export interface RepoImportLegacyResponse {
512
- ok: true
513
- imported: Array<{ name: string; origin: string; path: string }>
514
- skipped: Array<{ name: string; reason: 'exists' }>
515
- failed: Array<{ name: string; error: string }>
516
- }
517
-
518
- /** GET /api/skill-hub/update — check the plugin's own latest GitHub release. */
519
- export interface UpdateCheckResponse {
520
- ok: true
521
- /** Installed plugin version (from the bundled host build). */
522
- currentVersion: string
523
- /** Latest release tag, normalized without the leading v; null when unknown. */
524
- latestVersion: string | null
525
- /** True when latestVersion is strictly newer than currentVersion. */
526
- updateAvailable: boolean
527
- /** Release page URL; null when unavailable. */
528
- url: string | null
529
- /** Best-effort message when the check failed or no release exists. */
530
- error?: string
531
- }
532
-
533
- /** 用户自定义 tag 分组:纯组织视图,不改技能文件。 */
534
- export interface SkillTag {
535
- /** 稳定 ID(新建时由宿主生成)。 */
536
- id: string
537
- /** 显示名。 */
538
- name: string
539
- /** 成员技能名(集合技能与独立技能都可加入)。 */
540
- skillNames: string[]
541
- /** 默认场景(「通用」):系统预置、不可删除、新技能自动归入。 */
542
- default?: boolean
543
- }
544
-
545
- /** 系统集合组:按 origin(来源集合标识)自动聚合。 */
546
- export interface CollectionGroup {
547
- /** 集合名(origin 值,如 "superpowers" / "anthropics/skills")。 */
548
- name: string
549
- /** 该集合下的技能名,按名称排序。 */
550
- skillNames: string[]
551
- }
552
-
553
- /** GET /api/skill-hub/groups */
554
- export interface GroupsResponse {
555
- ok: true
556
- /** 用户自定义 tag 分组(按拖拽顺序)。 */
557
- tags: SkillTag[]
558
- /** 系统集合组(按拖拽顺序,兜底按名称)。 */
559
- collections: CollectionGroup[]
560
- /** skillName → 集合名 的完整映射。 */
561
- origins: Record<string, string>
562
- /** 来源分组整体顺序(project / col:xxx / uncategorized-source),用于 SourcesView 顶层排序 */
563
- sourceGroupOrder?: string[]
564
- /** 兼容旧 collectionOrder 字段 */
565
- collectionOrder?: string[]
566
- }
567
-
568
- /** POST /api/skill-hub/tag — 新建(缺省 id)或重命名(带 id)。 */
569
- export interface TagSaveRequest {
570
- /** 已有 tag 的 id;缺省表示新建。 */
571
- id?: string
572
- /** 显示名(去空格后非空)。 */
573
- name: string
574
- }
575
-
576
- /** POST /api/skill-hub/tag */
577
- export interface TagSaveResponse {
578
- ok: true
579
- /** 变更后的全部 tag。 */
580
- tags: SkillTag[]
581
- }
582
-
583
- /** POST /api/skill-hub/tag/delete */
584
- export interface TagDeleteRequest {
585
- id: string
586
- }
587
-
588
- /** POST /api/skill-hub/tag/delete */
589
- export interface TagDeleteResponse {
590
- ok: true
591
- tags: SkillTag[]
592
- }
593
-
594
- /** POST /api/skill-hub/tag/members — 直接设置某 tag 的完整成员列表(幂等)。 */
595
- export interface TagMembersRequest {
596
- id: string
597
- /** 目标成员技能名;后端只保留目录中存在的名字。 */
598
- skillNames: string[]
599
- }
600
-
601
- /** POST /api/skill-hub/tag/members */
602
- export interface TagMembersResponse {
603
- ok: true
604
- tags: SkillTag[]
605
- }
606
-
607
- /** POST /api/skill-hub/tag/reorder — 拖拽重排场景分组 */
608
- export interface TagReorderRequest {
609
- /** 按新顺序排列的 tag id 列表(需包含全部 id) */
610
- orderedIds: string[]
611
- }
612
- /** POST /api/skill-hub/tag/reorder */
613
- export interface TagReorderResponse {
614
- ok: true
615
- tags: SkillTag[]
616
- }
617
-
618
- /** POST /api/skill-hub/collections/reorder — 拖拽重排来源集合 */
619
- export interface CollectionReorderRequest {
620
- /** 按新顺序排列的集合名列表(需包含全部 name) */
621
- orderedNames: string[]
622
- }
623
- /** POST /api/skill-hub/collections/reorder */
624
- export interface CollectionReorderResponse {
625
- ok: true
626
- collections: CollectionGroup[]
627
- order: string[]
628
- }
629
-
630
- /** POST /api/skill-hub/source-groups/reorder — 拖拽重排来源顶层分组(project / collections / personal) */
631
- export interface SourceGroupReorderRequest {
632
- /** 按新顺序排列的顶层分组 key 列表(project / col:xxx / uncategorized-source) */
633
- orderedKeys: string[]
634
- }
635
- export interface SourceGroupReorderResponse {
636
- ok: true
637
- order: string[]
638
- }
639
-
640
- /** 来源跟踪记录:一组来自同一上游仓库根目录的技能。 */
641
- export interface SourceRecord {
642
- /** GitHub owner/repo。 */
643
- repo: string
644
- /** 显式分支/tag;缺省表示默认分支。 */
645
- ref?: string
646
- /** 技能在仓库中的根目录。 */
647
- root: RepoRoot
648
- /** 上次导入/同步时的上游 commit SHA;空 = 尚未核对过。 */
649
- commitSha: string
650
- /** 该来源下的技能名(来源组 = 这些技能)。 */
651
- skills: string[]
652
- /** 仓库内路径 → 文件大小 的基线清单(差异检测用;缺失 = 无基线)。 */
653
- manifest?: Record<string, number>
654
- }
655
-
656
- /** 回收站条目:上游删除后跟进删除(移入 .trash)的技能。 */
657
- export interface TrashEntry {
658
- name: string
659
- /** .trash 下的绝对路径。 */
660
- path: string
661
- /** 移入回收站的时间(epoch ms)。 */
662
- movedAt: number
663
- /** 移入回收站前的原始路径(目录或文件);旧版本条目没有该字段。 */
664
- sourcePath?: string
665
- /**
666
- * 移入回收站前的来源跟踪快照(恢复时用它把技能重新挂回来源记录,
667
- * 否则恢复后的技能会丢失来源归属、变成「个人技能」)。
668
- */
669
- origin?: {
670
- repo: string
671
- root: RepoRoot
672
- ref?: string
673
- commitSha: string
674
- }
675
- /** 移入回收站前所属的场景(tag)ID;恢复时重新加回这些场景。 */
676
- tagIds?: string[]
677
- }
678
-
679
- /** GET /api/skill-hub/sources */
680
- export interface SourcesResponse {
681
- ok: true
682
- /** 全部来源记录(按 repo 排序)。 */
683
- sources: SourceRecord[]
684
- /** skillName → 集合名(由 sources 派生)。 */
685
- origins: Record<string, string>
686
- /** 来源集合组(按 origin 聚合)。 */
687
- collections: CollectionGroup[]
688
- /** 回收站内容。 */
689
- trash: TrashEntry[]
690
- }
691
-
692
- /** POST /api/skill-hub/sources/check — 检查指定(或全部)来源的上游更新。 */
693
- export interface SourceCheckRequest {
694
- /** 仅检查该 repo;缺省检查全部。 */
695
- repo?: string
696
- }
697
-
698
- /** 单个来源的检查结果。 */
699
- export interface SourceCheckResult {
700
- repo: string
701
- ref?: string
702
- /** 检查失败时的原因(如仓库不可达/限流)。 */
703
- error?: string
704
- /** 上游 commit 是否变化。 */
705
- changed: boolean
706
- /** 上游最新 commit SHA(检查成功时)。 */
707
- commitSha?: string
708
- /** 上游有更新的技能名(changed 时经 tree 差异得出)。 */
709
- updated: string[]
710
- /** 上游已删除的技能名(changed 时经 tree 差异得出)。 */
711
- deleted: string[]
712
- /** 节流跳过(距上次检查不足 5 分钟,未访问网络)。 */
713
- throttled?: boolean
714
- /** 该来源此前没有快照(迁移/旧记录),本次已回填 commit,尚未有差异基线。 */
715
- unverified?: boolean
716
- }
717
-
718
- /** POST /api/skill-hub/sources/check */
719
- export interface SourceCheckResponse {
720
- ok: true
721
- results: SourceCheckResult[]
722
- }
723
-
724
- /** POST /api/skill-hub/sources/sync — 按上游重新下载所选技能并更新快照。 */
725
- export interface SourceSyncRequest {
726
- repo: string
727
- /** 要同步的技能名;缺省同步该来源全部技能。 */
728
- skills?: string[]
729
- }
730
-
731
- /** POST /api/skill-hub/sources/sync */
732
- export interface SourceSyncResponse {
733
- ok: true
734
- repo: string
735
- /** 同步后的上游 commit SHA。 */
736
- commitSha: string
737
- /** 成功同步的技能。 */
738
- synced: string[]
739
- /** 失败的技能。 */
740
- failed: Array<{ name: string; error: string }>
741
- }
742
-
743
- /** POST /api/skill-hub/sources/delete — 跟进上游删除,本地移入回收站。 */
744
- export interface SourceDeleteRequest {
745
- repo: string
746
- /** 要删除的技能名(移入 .trash)。 */
747
- skills: string[]
748
- }
749
-
750
- /** POST /api/skill-hub/sources/delete */
751
- export interface SourceDeleteResponse {
752
- ok: true
753
- /** 已移入回收站的技能。 */
754
- trashed: string[]
755
- failed: Array<{ name: string; error: string }>
756
- }
757
-
758
- /** POST /api/skill-hub/sources/restore — 从回收站恢复一个技能。 */
759
- export interface SourceRestoreRequest {
760
- name: string
761
- }
762
-
763
- /** POST /api/skill-hub/sources/restore */
764
- export interface SourceRestoreResponse {
765
- ok: true
766
- name: string
767
- path: string
768
- }
769
-
770
- /** POST /api/skill-hub/sources/trash/clear — 永久删除回收站里的全部技能。 */
771
- export interface SourceTrashClearResponse {
772
- ok: true
773
- /** 已永久删除的技能名。 */
774
- deleted: string[]
775
- /** 未能删除的技能(保留在回收站中)。 */
776
- failed: Array<{ name: string; error: string }>
777
- }
778
-
779
- /** 项目级技能来源(它们有 workspace 归属,不属于「个人」组)。 */
780
- export function isProjectSource(source: string): boolean {
781
- return source === 'project-dsh' || source === 'project-agents'
782
- }
11
+ export { SKILL_HUB_API } from './protocol/api.ts'
12
+ export type {
13
+ WritableRoot,
14
+ HubInvocation,
15
+ CatalogSkill,
16
+ DisabledSkill,
17
+ DiagnosticEntry,
18
+ DiagnosticFixRequest,
19
+ DiagnosticFixResponse,
20
+ CatalogResponse,
21
+ SkillDetail,
22
+ SkillDetailResponse,
23
+ SkillDeleteRequest,
24
+ SkillDeleteResponse,
25
+ ToggleRequest,
26
+ ToggleResponse,
27
+ ToggleBatchRequest,
28
+ ToggleBatchResponse,
29
+ CreateRequest,
30
+ CreateResponse,
31
+ } from './protocol/catalog.ts'
32
+ export type { SkillStat, StatsResponse, SkillStatsCheckpoint } from './protocol/stats.ts'
33
+ export type { ErrorResponse, HubConfig, HubSettingsValue, ConfigResponse, ConfigRequest } from './protocol/config.ts'
34
+ export { HUB_CONFIG_DEFAULTS, HEX_COLOR_RE, GITHUB_TOKEN_RE, resolveHubConfig } from './protocol/config.ts'
35
+ export type {
36
+ MarketSourceRecord,
37
+ MarketSourcesResponse,
38
+ MarketSourceRequest,
39
+ MarketSourceResponse,
40
+ MarketSourceRefRequest,
41
+ MarketSourceVersionsResponse,
42
+ MarketStatsSnapshot,
43
+ MarketStatsResponse,
44
+ MarketCheckResponse,
45
+ MarketSyncResponse,
46
+ } from './protocol/market.ts'
47
+ export type {
48
+ RepoSkillEntry,
49
+ RepoRoot,
50
+ RepoDiscoverResponse,
51
+ RepoImportRequest,
52
+ RepoImportResponse,
53
+ RepoImportProgressResponse,
54
+ RepoImportCancelRequest,
55
+ RepoImportCancelResponse,
56
+ UpdateCheckResponse,
57
+ } from './protocol/repo.ts'
58
+ export type {
59
+ SkillTag,
60
+ CollectionGroup,
61
+ GroupsResponse,
62
+ TagSaveRequest,
63
+ TagSaveResponse,
64
+ TagDeleteRequest,
65
+ TagDeleteResponse,
66
+ TagMembersRequest,
67
+ TagMembersResponse,
68
+ TagReorderRequest,
69
+ TagReorderResponse,
70
+ CollectionReorderRequest,
71
+ CollectionReorderResponse,
72
+ SourceGroupReorderRequest,
73
+ SourceGroupReorderResponse,
74
+ } from './protocol/groups.ts'
75
+ export type {
76
+ SourceRecord,
77
+ TrashEntry,
78
+ SourcesResponse,
79
+ SourceCheckRequest,
80
+ SourceCheckResult,
81
+ SourceCheckResponse,
82
+ SourceSyncRequest,
83
+ SourceSyncResponse,
84
+ SourceDeleteRequest,
85
+ SourceDeleteResponse,
86
+ SourceRestoreRequest,
87
+ SourceRestoreResponse,
88
+ SourceTrashClearResponse,
89
+ } from './protocol/sources.ts'
90
+ export { isProjectSource } from './protocol/sources.ts'