dsh-version-manager 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +234 -2
- package/cordis.patch.yml +12 -0
- package/docs/baseline.md +224 -0
- package/lib/client.js +2367 -0
- package/lib/host/compat.js +303 -0
- package/lib/host/git-routes.js +376 -0
- package/lib/host/git-skill.js +1133 -0
- package/lib/host/inventory.js +231 -0
- package/lib/host/locate.js +169 -0
- package/lib/host/lockfile.js +124 -0
- package/lib/host/operations.js +185 -0
- package/lib/host/routes.js +1336 -0
- package/lib/host/skill-restore.js +346 -0
- package/lib/host/skills.js +327 -0
- package/lib/host/snapshot-store.js +335 -0
- package/lib/host/spec.js +274 -0
- package/lib/index.js +49 -0
- package/package.json +60 -4
package/lib/client.js
ADDED
|
@@ -0,0 +1,2367 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The browser half.
|
|
3
|
+
*
|
|
4
|
+
* Loaded by the DSH client as a module bundle: the wrapper below is the protocol
|
|
5
|
+
* the host's module loader reads, and `apply`/`inject` are the two exports it
|
|
6
|
+
* looks for. Everything this file needs is either `react` or the host UI
|
|
7
|
+
* primitives package — both live in the client's static module table, so nothing
|
|
8
|
+
* is fetched from the network at runtime.
|
|
9
|
+
*
|
|
10
|
+
* The panel never reads the filesystem and never runs a package manager. It asks
|
|
11
|
+
* the host for a described state, draws it, and turns a click into one request
|
|
12
|
+
* that names exactly what will change.
|
|
13
|
+
*/
|
|
14
|
+
window.__ModuleLoader__.load({
|
|
15
|
+
id: 'dsh-version-manager',
|
|
16
|
+
factory: (require) => {
|
|
17
|
+
var module = { exports: {} }
|
|
18
|
+
var exports = module.exports
|
|
19
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
20
|
+
|
|
21
|
+
// `react` is the one module this file needs, and it is in the client's static
|
|
22
|
+
// module table. Pulling in a UI package would add a second thing that can be
|
|
23
|
+
// missing from a host version this plugin has not seen.
|
|
24
|
+
const React = require('react')
|
|
25
|
+
|
|
26
|
+
const h = React.createElement
|
|
27
|
+
const { useCallback, useEffect, useMemo, useRef, useState } = React
|
|
28
|
+
|
|
29
|
+
const PANEL_ID = 'dsh-version-manager'
|
|
30
|
+
const ROUTE_BASE = '/dsh-version-manager'
|
|
31
|
+
|
|
32
|
+
// ---------------------------------------------------------------- language
|
|
33
|
+
|
|
34
|
+
const COLORS = {
|
|
35
|
+
pass: '#0d7f4f',
|
|
36
|
+
warn: '#a86000',
|
|
37
|
+
fail: '#b3261e',
|
|
38
|
+
unknown: '#5b6470',
|
|
39
|
+
idle: '#8a929c',
|
|
40
|
+
// Mid grey rather than black-with-alpha: the same separator has to be
|
|
41
|
+
// visible on the light and the dark surface without a theme query.
|
|
42
|
+
line: 'rgba(128,128,128,0.32)',
|
|
43
|
+
soft: 'rgba(128,128,128,0.10)',
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const TEXT = {
|
|
47
|
+
zh: {
|
|
48
|
+
panel: '版本管理',
|
|
49
|
+
title: '插件与 Skill 版本管理',
|
|
50
|
+
subtitle: '查看当前 profile 的安装事实、检查更新、预览并执行单项更新、留快照',
|
|
51
|
+
refresh: '刷新',
|
|
52
|
+
refreshing: '正在读取…',
|
|
53
|
+
profile: 'Profile',
|
|
54
|
+
host: '宿主版本',
|
|
55
|
+
observed: '读取时间',
|
|
56
|
+
unknown: '未知',
|
|
57
|
+
notAvailable: '不可获取',
|
|
58
|
+
counts: (total, writable, official, unsatisfied, unknownCompat) => {
|
|
59
|
+
const base = `${total} 个条目,${writable} 个可写入,${official} 个官方内置`
|
|
60
|
+
const parts = []
|
|
61
|
+
if (unsatisfied > 0) parts.push(`${unsatisfied} 个与当前宿主版本不匹配`)
|
|
62
|
+
if (unknownCompat > 0) parts.push(`${unknownCompat} 个兼容性未能判定`)
|
|
63
|
+
return parts.length === 0 ? base : `${base},${parts.join(',')}`
|
|
64
|
+
},
|
|
65
|
+
filterAll: '全部',
|
|
66
|
+
filterWritable: '可写入',
|
|
67
|
+
filterReadOnly: '只读',
|
|
68
|
+
search: '按名称过滤',
|
|
69
|
+
colName: '包',
|
|
70
|
+
colVersion: '已装版本',
|
|
71
|
+
colSource: '来源',
|
|
72
|
+
colLoad: '加载状态',
|
|
73
|
+
colCompat: '兼容性',
|
|
74
|
+
colActions: '操作',
|
|
75
|
+
checkVersions: '检查更新',
|
|
76
|
+
checking: '检查中…',
|
|
77
|
+
takeSnapshot: '拍快照',
|
|
78
|
+
snapshotting: '快照中…',
|
|
79
|
+
details: '详情',
|
|
80
|
+
hide: '收起',
|
|
81
|
+
declared: '安装声明',
|
|
82
|
+
declaredObserved: 'profile 中记录',
|
|
83
|
+
declaredMatches: '一致',
|
|
84
|
+
declaredDiffers: '不一致',
|
|
85
|
+
registry: 'registry',
|
|
86
|
+
registryUnknown: '快照外无法确认',
|
|
87
|
+
official: '官方',
|
|
88
|
+
readOnly: '只读',
|
|
89
|
+
noDeclaredSpec: '无安装声明',
|
|
90
|
+
builtinSource: '随 DSH 提供',
|
|
91
|
+
unknownSource: '来源未识别',
|
|
92
|
+
installationSource: '随 DSH 安装提供',
|
|
93
|
+
refusal: {
|
|
94
|
+
'official-bundle': '随 DSH 提供,插件不替换。',
|
|
95
|
+
'not-installed-here': '当前 profile 未安装该 bundle。',
|
|
96
|
+
'not-installed': '未安装。',
|
|
97
|
+
'no-declared-spec': '宿主没有记录安装声明。',
|
|
98
|
+
'alias-substitution': '声明用别名指向另一个包,替换等于换包。',
|
|
99
|
+
'name-substitution': '声明指向另一个包名,替换等于换包。',
|
|
100
|
+
'range-with-scheme': '声明不是普通版本范围。',
|
|
101
|
+
'no-installed-version': '读不到已安装版本。',
|
|
102
|
+
},
|
|
103
|
+
noNewerVersions: '没有更新的版本',
|
|
104
|
+
notRegistrySource: (kind) => `来源是 ${kind},插件不会替换。`,
|
|
105
|
+
stable: '正式版',
|
|
106
|
+
prerelease: '预发布',
|
|
107
|
+
published: '发布于',
|
|
108
|
+
deprecated: '已废弃',
|
|
109
|
+
versionListRefused: '宿主要求只读,不提供更新',
|
|
110
|
+
updateTo: '更新到',
|
|
111
|
+
confirmTitle: '确认这次更新',
|
|
112
|
+
confirmBody: (name, from, to) =>
|
|
113
|
+
`将把 ${name} 从 ${from} 更新到 ${to}。宿主会先移除再安装,中间会有一次完整重装。`,
|
|
114
|
+
confirmNotes: [
|
|
115
|
+
'更新前会自动拍一份快照,并在执行前回读校验。',
|
|
116
|
+
'宿主会把依赖保存为精确版本,原来若是版本范围则会被替换。',
|
|
117
|
+
'不会恢复配置、依赖树或 agent preset。',
|
|
118
|
+
'不会自动重启宿主。',
|
|
119
|
+
],
|
|
120
|
+
cancel: '取消',
|
|
121
|
+
confirm: '确认更新',
|
|
122
|
+
updating: '更新中…',
|
|
123
|
+
updateOk: '更新完成',
|
|
124
|
+
updateFailed: '更新未完成',
|
|
125
|
+
alreadyLatest: '已是最新版本',
|
|
126
|
+
snapshots: '快照',
|
|
127
|
+
noSnapshots: '还没有快照',
|
|
128
|
+
restore: '恢复此版本',
|
|
129
|
+
restoreConfirm: (v) => `将把版本恢复到 ${v}。只恢复版本,不恢复配置。`,
|
|
130
|
+
restoring: '恢复中…',
|
|
131
|
+
restoreRefused: '无法安全恢复',
|
|
132
|
+
restoreOk: '已恢复到',
|
|
133
|
+
restoreObserved: (version) => `当前实际版本 ${version ?? '未知'}`,
|
|
134
|
+
restoreFilesMatched: '文件与快照记录的一致,没有发生变化。',
|
|
135
|
+
operations: '最近操作',
|
|
136
|
+
noOperations: '还没有操作记录',
|
|
137
|
+
unresolved: '有未收尾的操作',
|
|
138
|
+
loadActive: '已加载',
|
|
139
|
+
loadFailed: '加载失败',
|
|
140
|
+
loadPending: '待加载',
|
|
141
|
+
loadLoading: '加载中',
|
|
142
|
+
loadUnloading: '卸载中',
|
|
143
|
+
loadUnknown: '未知',
|
|
144
|
+
loadNoEntry: 'loader 里没有以这个包名注册的条目:bundle 是以 patch 方式展开成多个插件行的,行名不一定等于包名。这不代表它加载失败。',
|
|
145
|
+
loadUnavailable: '这个进程里读不到 loader,所以无法判断加载状态。',
|
|
146
|
+
compatOk: '满足',
|
|
147
|
+
compatFail: '不满足',
|
|
148
|
+
compatUnknown: '未知',
|
|
149
|
+
compatNoRequirement: '未声明要求',
|
|
150
|
+
compatExempted: '已豁免',
|
|
151
|
+
compatUnmet: (requirements, runtime) => `当前宿主 ${runtime} 不满足:${requirements}`,
|
|
152
|
+
compatMet: (requirements, runtime) => `当前宿主 ${runtime} 满足:${requirements}`,
|
|
153
|
+
compatExemptedDetail: (runtime) => `版本不匹配(宿主 ${runtime}),但 profile 里有精确版本豁免`,
|
|
154
|
+
compatNoClaim: '该包未声明 DSH 版本要求',
|
|
155
|
+
runtimeSource: (source) => `来源:${source}`,
|
|
156
|
+
errorLabel: '错误',
|
|
157
|
+
notStarted: '尚未读取',
|
|
158
|
+
started: '开始读取',
|
|
159
|
+
requestFailed: (status) => `请求失败(HTTP ${status})`,
|
|
160
|
+
networkFailed: '无法连接到宿主接口',
|
|
161
|
+
staleWarning: '这些数据来自上一次读取,可能已经过期',
|
|
162
|
+
tabPlugins: '插件',
|
|
163
|
+
tabSkills: 'Skill',
|
|
164
|
+
skillsTitle: 'Skill 目录',
|
|
165
|
+
skillsSubtitle: '宿主实际扫描到的 Skill;快照记录文件指纹与 Git 版本,Skill 本身没有版本号',
|
|
166
|
+
skillsUnavailable: '这个宿主进程没有 skills 服务,因此无法列出 Skill。',
|
|
167
|
+
skillsEmpty: '没有发现 Skill。',
|
|
168
|
+
skillsIncomplete: '发现尚未完成,这个列表可能不完整。',
|
|
169
|
+
skillsProvider: (provider) => `provider:${provider}`,
|
|
170
|
+
skillColName: 'Skill',
|
|
171
|
+
skillColSource: '来源',
|
|
172
|
+
skillColFiles: '文件',
|
|
173
|
+
skillColGit: 'Git',
|
|
174
|
+
skillColSnapshots: '快照',
|
|
175
|
+
skillColActions: '操作',
|
|
176
|
+
skillSnapshot: '拍快照',
|
|
177
|
+
skillSnapshotDone: (digest) => `已保存快照,指纹 ${digest}`,
|
|
178
|
+
skillNoDirectory: '单文件 Skill,没有目录可复制',
|
|
179
|
+
skillNoGit: '不在 Git 检出内',
|
|
180
|
+
skillDirty: (count) => `${count} 处未提交改动`,
|
|
181
|
+
skillClean: '无本地改动',
|
|
182
|
+
skillSnapshotCount: (count) => `${count} 份`,
|
|
183
|
+
skillRestore: '恢复',
|
|
184
|
+
skillNoSnapshots: '还没有这个 Skill 的快照',
|
|
185
|
+
skillUndoLabel: '撤销点',
|
|
186
|
+
snapshotUnreadable: '读不出来',
|
|
187
|
+
collapse: '收起',
|
|
188
|
+
skillRestoreConfirm: '恢复这个快照?',
|
|
189
|
+
skillRestoreBody: (name, taken) => `会把 ${name} 的目录内容替换成 ${taken} 那份快照记录的字节。`,
|
|
190
|
+
skillRestoreNotes: [
|
|
191
|
+
'替换前会先给当前目录拍一份快照,可以再恢复回来。',
|
|
192
|
+
'只动这个 Skill 目录,不执行任何 Git 命令,也不改仓库其它内容。',
|
|
193
|
+
'快照里没有的文件会被移走;这一步不能撤销,只能靠撤销快照再恢复。',
|
|
194
|
+
],
|
|
195
|
+
skillRestoreDone: (taken) => `已恢复到 ${taken} 的快照`,
|
|
196
|
+
skillRestorePreviewFailed: (reason) => `这个快照不能用来恢复:${reason}`,
|
|
197
|
+
skillRestoreSameFiles: '目录内容与这份快照已经一致。',
|
|
198
|
+
skillRestoreMoved: '目录内容已被改动,恢复会覆盖这些改动。',
|
|
199
|
+
skillRestoreRefusals: {
|
|
200
|
+
'no-directory': '单文件 Skill,没有目录可恢复。',
|
|
201
|
+
'system-skill': '位于 .system 下,插件不写。',
|
|
202
|
+
'inside-git-checkout': '位于 Git 检出内,插件不写。',
|
|
203
|
+
'bundled-skill': '随 DSH 提供,插件不写。',
|
|
204
|
+
'snapshot-unreadable': '快照文件读不出来。',
|
|
205
|
+
'snapshot-mismatch': '快照记录的 Skill 不是这一个。',
|
|
206
|
+
'snapshot-copy-missing': '快照的副本目录已不存在。',
|
|
207
|
+
'snapshot-directory-mismatch': '快照记录的是另一个目录。',
|
|
208
|
+
'snapshot-copy-corrupt': '快照副本的内容与指纹不符,不能作为基线。',
|
|
209
|
+
'undo-snapshot-failed': '替换前的撤销快照没有拍成,已中止。',
|
|
210
|
+
'staging-failed': '无法在同一个卷上准备新目录。',
|
|
211
|
+
'staged-copy-corrupt': '准备出来的目录与快照不符,已中止。',
|
|
212
|
+
'swap-failed': '目录替换失败,已尽量还原。',
|
|
213
|
+
'verification-failed': '替换后校验不一致。',
|
|
214
|
+
'bad-snapshot-file': '快照文件名不合法。',
|
|
215
|
+
'not-a-directory': '目标不是目录。',
|
|
216
|
+
},
|
|
217
|
+
skillFilesTruncated: '超过上限,未数完',
|
|
218
|
+
skillSourceLabels: {
|
|
219
|
+
'project-dsh': '项目 .dsh/skills',
|
|
220
|
+
'project-agents': '项目 .agents/skills',
|
|
221
|
+
custom: '自定义目录',
|
|
222
|
+
'user-dsh': '用户 .dsh/skills',
|
|
223
|
+
'user-agents': '用户 .agents/skills',
|
|
224
|
+
bundled: '随 DSH 提供',
|
|
225
|
+
},
|
|
226
|
+
skillSourceUnknown: (value) => `来源未识别(${value})`,
|
|
227
|
+
skillsSoon: 'Skill 版本管理在下一阶段提供;当前面板只处理插件。',
|
|
228
|
+
gitTitle: 'Git 受管的 Skill',
|
|
229
|
+
gitSubtitle:
|
|
230
|
+
'登记一个远程仓库和它在仓库里的确切子路径,之后就能把某个 commit 的内容装进这个 Skill 目录。插件用自己的缓存读 Git,不在你的检出里跑任何命令。',
|
|
231
|
+
gitEmpty: '还没有登记任何 Git 来源。',
|
|
232
|
+
gitName: 'Skill 名',
|
|
233
|
+
gitRemote: '仓库',
|
|
234
|
+
gitSubpath: '仓库内子路径',
|
|
235
|
+
gitRef: '分支或 tag',
|
|
236
|
+
gitRegister: '登记',
|
|
237
|
+
gitRegistering: '登记中…',
|
|
238
|
+
gitRegisterNote: '登记只记录来源并钉住一个 commit,不改动目录里的文件。第一次更新才会把内容装进去。',
|
|
239
|
+
gitNeedName: '先填 Skill 名',
|
|
240
|
+
gitNeedRemote: '先填仓库地址',
|
|
241
|
+
gitCreateHint: '宿主目录里没有这个 Skill 时,勾选后由插件创建 skills/<名字>。',
|
|
242
|
+
gitCreate: '目录不存在时创建',
|
|
243
|
+
gitRegisteredAt: (when) => `登记于 ${when}`,
|
|
244
|
+
gitRevisionCurrent: '当前版本',
|
|
245
|
+
gitPopulated: '已装入内容',
|
|
246
|
+
gitNotPopulated: '尚未装入(目录还是空的)',
|
|
247
|
+
gitLocalModifications: '目录里有登记之后的改动,更新会被拒绝',
|
|
248
|
+
gitInCheckout: '目录在 Git 检出内,插件不写',
|
|
249
|
+
gitHistory: '历史',
|
|
250
|
+
gitPreview: '看看会变成什么',
|
|
251
|
+
gitPreviewing: '读取中…',
|
|
252
|
+
gitUpdate: '更新到最新',
|
|
253
|
+
gitUpdating: '更新中…',
|
|
254
|
+
gitRemove: '注销',
|
|
255
|
+
gitRemoving: '注销中…',
|
|
256
|
+
gitUpdateDone: (from, to) => `已更新 ${from} → ${to}`,
|
|
257
|
+
gitRestoreTo: '回到这个 commit',
|
|
258
|
+
gitRestored: (revision) => `已回到 ${revision}`,
|
|
259
|
+
gitAlreadyAt: '已经是最新的 commit 了',
|
|
260
|
+
gitChanges: (count) => `${count} 个文件会变`,
|
|
261
|
+
gitNoChanges: '没有文件差异',
|
|
262
|
+
gitUndoSnapshot: '替换前会先给当前目录拍快照,可以再回来。',
|
|
263
|
+
gitUpdateConfirm: '把这个 Skill 更新到这个 commit?',
|
|
264
|
+
gitUpdateBody: (name, from, to) => `会把 ${name} 的目录内容替换成 ${to}。当前是 ${from}。`,
|
|
265
|
+
gitUpdateNotes: [
|
|
266
|
+
'替换前先拍快照,可撤销。',
|
|
267
|
+
'目录里不在这个 commit 中的文件会被移走。',
|
|
268
|
+
'不执行 checkout、reset、clean,也不碰仓库本身。',
|
|
269
|
+
],
|
|
270
|
+
gitRestoreConfirm: '把这个 Skill 退回这个 commit?',
|
|
271
|
+
gitRestoreBody: (name, revision) => `会把 ${name} 的目录内容替换成 ${revision} 的树。`,
|
|
272
|
+
gitGitRefusals: {
|
|
273
|
+
'not-registered': '这个 Skill 没有登记 Git 来源。',
|
|
274
|
+
'unsupported-remote': '这个仓库地址不是插件支持的传输方式。',
|
|
275
|
+
'bad-subpath': '子路径不合法(不能是绝对路径、不能含 .. 或 .git)。',
|
|
276
|
+
'no-directory': '单文件 Skill,没有目录可写。',
|
|
277
|
+
'system-skill': '位于 .system 下,插件不写。',
|
|
278
|
+
'inside-git-checkout': '目录在 Git 检出内,插件不写。',
|
|
279
|
+
'local-modifications': '目录里有登记之后的改动,先处理这些改动再更新。',
|
|
280
|
+
'baseline-unknown': '目录里已有的文件与这个 commit 的树不一致,无法给出诚实的基线。',
|
|
281
|
+
'already-registered': '这个 Skill 已经登记了另一个来源;先注销再登记。',
|
|
282
|
+
'missing-name': '缺少 Skill 名。',
|
|
283
|
+
'bad-name': 'Skill 名只能包含字母、数字、点、横线和下划线。',
|
|
284
|
+
'git-not-found': '找不到 git 命令。',
|
|
285
|
+
'git-timeout': 'Git 命令超时。',
|
|
286
|
+
'fetch-failed': '拉取仓库失败,检查地址和网络。',
|
|
287
|
+
'ref-unresolved': '这个分支或 tag 解析不出 commit。',
|
|
288
|
+
'revision-not-in-cache': '缓存里没有这个 commit,插件不猜。',
|
|
289
|
+
'unsupported-entry': '这个 commit 里有符号链接或子模块,插件不写。',
|
|
290
|
+
'already-at-revision': '已经在这个 commit 上。',
|
|
291
|
+
'undo-snapshot-failed': '替换前的快照没有拍成,已中止。',
|
|
292
|
+
'bad-revision': 'commit 号不合法。',
|
|
293
|
+
},
|
|
294
|
+
},
|
|
295
|
+
en: {
|
|
296
|
+
panel: 'Versions',
|
|
297
|
+
title: 'Plugin and Skill versions',
|
|
298
|
+
subtitle:
|
|
299
|
+
'What this profile actually has installed, which updates exist, and one change at a time',
|
|
300
|
+
refresh: 'Refresh',
|
|
301
|
+
refreshing: 'Reading…',
|
|
302
|
+
profile: 'Profile',
|
|
303
|
+
host: 'Host version',
|
|
304
|
+
observed: 'Observed',
|
|
305
|
+
unknown: 'unknown',
|
|
306
|
+
notAvailable: 'not available',
|
|
307
|
+
counts: (total, writable, official, unsatisfied, unknownCompat) => {
|
|
308
|
+
const base = `${total} entries, ${writable} writable, ${official} official`
|
|
309
|
+
const parts = []
|
|
310
|
+
if (unsatisfied > 0) parts.push(`${unsatisfied} incompatible with this host`)
|
|
311
|
+
if (unknownCompat > 0) parts.push(`${unknownCompat} with undecidable compatibility`)
|
|
312
|
+
return parts.length === 0 ? base : `${base}, ${parts.join(', ')}`
|
|
313
|
+
},
|
|
314
|
+
filterAll: 'All',
|
|
315
|
+
filterWritable: 'Writable',
|
|
316
|
+
filterReadOnly: 'Read-only',
|
|
317
|
+
search: 'Filter by name',
|
|
318
|
+
colName: 'Package',
|
|
319
|
+
colVersion: 'Installed',
|
|
320
|
+
colSource: 'Source',
|
|
321
|
+
colLoad: 'Load state',
|
|
322
|
+
colCompat: 'Compatibility',
|
|
323
|
+
colActions: 'Actions',
|
|
324
|
+
checkVersions: 'Check versions',
|
|
325
|
+
checking: 'Checking…',
|
|
326
|
+
takeSnapshot: 'Snapshot',
|
|
327
|
+
snapshotting: 'Snapshotting…',
|
|
328
|
+
details: 'Details',
|
|
329
|
+
hide: 'Collapse',
|
|
330
|
+
declared: 'Declared spec',
|
|
331
|
+
declaredObserved: 'Recorded in profile',
|
|
332
|
+
declaredMatches: 'matches',
|
|
333
|
+
declaredDiffers: 'differs',
|
|
334
|
+
registry: 'registry',
|
|
335
|
+
registryUnknown: 'not confirmable from here',
|
|
336
|
+
official: 'official',
|
|
337
|
+
readOnly: 'read-only',
|
|
338
|
+
noDeclaredSpec: 'no declared spec',
|
|
339
|
+
builtinSource: 'ships with DSH',
|
|
340
|
+
unknownSource: 'source not recognised',
|
|
341
|
+
installationSource: 'from the DSH installation',
|
|
342
|
+
refusal: {
|
|
343
|
+
'official-bundle': 'Ships with DSH, so this panel never replaces it.',
|
|
344
|
+
'not-installed-here': 'Not installed in this profile.',
|
|
345
|
+
'not-installed': 'Not installed.',
|
|
346
|
+
'no-declared-spec': 'The host records no declared spec.',
|
|
347
|
+
'alias-substitution': 'The spec aliases another package, so replacing it would swap packages.',
|
|
348
|
+
'name-substitution': 'The spec names another package, so replacing it would swap packages.',
|
|
349
|
+
'range-with-scheme': 'The spec is not a plain version range.',
|
|
350
|
+
'no-installed-version': 'The installed version could not be read.',
|
|
351
|
+
},
|
|
352
|
+
noNewerVersions: 'No newer versions',
|
|
353
|
+
notRegistrySource: (kind) => `Installed from a ${kind} source, so this panel never replaces it.`,
|
|
354
|
+
stable: 'Stable',
|
|
355
|
+
prerelease: 'Prerelease',
|
|
356
|
+
published: 'published',
|
|
357
|
+
deprecated: 'deprecated',
|
|
358
|
+
versionListRefused: 'The host keeps this entry read-only, so no update is offered',
|
|
359
|
+
updateTo: 'Update to',
|
|
360
|
+
confirmTitle: 'Confirm this update',
|
|
361
|
+
confirmBody: (name, from, to) =>
|
|
362
|
+
`Update ${name} from ${from} to ${to}. The host removes then installs, so this is a full reinstall.`,
|
|
363
|
+
confirmNotes: [
|
|
364
|
+
'A snapshot is taken first and read back before anything changes.',
|
|
365
|
+
'The host saves an exact version; a range in the profile is replaced.',
|
|
366
|
+
'Configuration, the dependency tree and agent presets are not restored.',
|
|
367
|
+
'The host is not restarted.',
|
|
368
|
+
],
|
|
369
|
+
cancel: 'Cancel',
|
|
370
|
+
confirm: 'Update',
|
|
371
|
+
updating: 'Updating…',
|
|
372
|
+
updateOk: 'Update finished',
|
|
373
|
+
updateFailed: 'Update did not finish',
|
|
374
|
+
alreadyLatest: 'Already at the newest version',
|
|
375
|
+
snapshots: 'Snapshots',
|
|
376
|
+
noSnapshots: 'No snapshots yet',
|
|
377
|
+
restore: 'Restore this version',
|
|
378
|
+
restoreConfirm: (v) => `Restore the version to ${v}. Only the version is restored.`,
|
|
379
|
+
restoring: 'Restoring…',
|
|
380
|
+
restoreRefused: 'Cannot restore safely',
|
|
381
|
+
restoreOk: 'Restored to',
|
|
382
|
+
restoreObserved: (version) => `now on disk: ${version ?? 'unknown'}`,
|
|
383
|
+
restoreFilesMatched: 'The files still match what the snapshot recorded.',
|
|
384
|
+
operations: 'Recent operations',
|
|
385
|
+
noOperations: 'No operations recorded',
|
|
386
|
+
unresolved: 'An operation has not settled',
|
|
387
|
+
loadActive: 'active',
|
|
388
|
+
loadFailed: 'failed',
|
|
389
|
+
loadPending: 'pending',
|
|
390
|
+
loadLoading: 'loading',
|
|
391
|
+
loadUnloading: 'unloading',
|
|
392
|
+
loadUnknown: 'unknown',
|
|
393
|
+
loadNoEntry: 'No loader entry is registered under this package name: a bundle expands into plugin rows through its patch, so a row name need not equal the package name. That is not a load failure.',
|
|
394
|
+
loadUnavailable: 'The loader cannot be read in this process, so the load state is unknown.',
|
|
395
|
+
compatOk: 'met',
|
|
396
|
+
compatFail: 'not met',
|
|
397
|
+
compatUnknown: 'unknown',
|
|
398
|
+
compatNoRequirement: 'no requirement',
|
|
399
|
+
compatExempted: 'exempted',
|
|
400
|
+
compatUnmet: (requirements, runtime) => `Host ${runtime} does not satisfy ${requirements}`,
|
|
401
|
+
compatMet: (requirements, runtime) => `Host ${runtime} satisfies ${requirements}`,
|
|
402
|
+
compatExemptedDetail: (runtime) => `Version mismatch (host ${runtime}), but the profile has an exact-version exemption`,
|
|
403
|
+
compatNoClaim: 'This package declares no DSH version requirement',
|
|
404
|
+
runtimeSource: (source) => `from ${source}`,
|
|
405
|
+
errorLabel: 'Error',
|
|
406
|
+
notStarted: 'Not read yet',
|
|
407
|
+
started: 'Read started',
|
|
408
|
+
requestFailed: (status) => `Request failed (HTTP ${status})`,
|
|
409
|
+
networkFailed: 'Could not reach the host route',
|
|
410
|
+
staleWarning: 'This data came from an earlier read and may be out of date',
|
|
411
|
+
tabPlugins: 'Plugins',
|
|
412
|
+
tabSkills: 'Skills',
|
|
413
|
+
skillsTitle: 'Skill directories',
|
|
414
|
+
skillsSubtitle:
|
|
415
|
+
'The skills this host actually scanned; a snapshot records file fingerprints and a Git revision, because a skill has no version number',
|
|
416
|
+
skillsUnavailable: 'This host process has no skills service, so skills cannot be listed.',
|
|
417
|
+
skillsEmpty: 'No skills were found.',
|
|
418
|
+
skillsIncomplete: 'Discovery has not finished, so this list may be incomplete.',
|
|
419
|
+
skillsProvider: (provider) => `provider: ${provider}`,
|
|
420
|
+
skillColName: 'Skill',
|
|
421
|
+
skillColSource: 'Source',
|
|
422
|
+
skillColFiles: 'Files',
|
|
423
|
+
skillColGit: 'Git',
|
|
424
|
+
skillColSnapshots: 'Snapshots',
|
|
425
|
+
skillColActions: 'Actions',
|
|
426
|
+
skillSnapshot: 'Snapshot',
|
|
427
|
+
skillSnapshotDone: (digest) => `Snapshot saved, fingerprint ${digest}`,
|
|
428
|
+
skillNoDirectory: 'A single-file skill has no directory to copy',
|
|
429
|
+
skillNoGit: 'Not inside a Git checkout',
|
|
430
|
+
skillDirty: (count) => `${count} uncommitted changes`,
|
|
431
|
+
skillClean: 'No local changes',
|
|
432
|
+
skillSnapshotCount: (count) => `${count}`,
|
|
433
|
+
skillRestore: 'Restore',
|
|
434
|
+
skillNoSnapshots: 'No snapshot of this skill yet',
|
|
435
|
+
skillUndoLabel: 'undo point',
|
|
436
|
+
snapshotUnreadable: 'unreadable',
|
|
437
|
+
collapse: 'Collapse',
|
|
438
|
+
skillRestoreConfirm: 'Restore this snapshot?',
|
|
439
|
+
skillRestoreBody: (name, taken) =>
|
|
440
|
+
`The ${name} directory is replaced with the exact bytes recorded in the ${taken} snapshot.`,
|
|
441
|
+
skillRestoreNotes: [
|
|
442
|
+
'The current directory is snapshotted first, so this step can itself be undone.',
|
|
443
|
+
'Only that skill directory is touched. No Git command runs and the rest of the repository is left alone.',
|
|
444
|
+
'Files that were added after the snapshot are removed. That is not reversible except by restoring the undo snapshot.',
|
|
445
|
+
],
|
|
446
|
+
skillRestoreDone: (taken) => `Restored to the snapshot from ${taken}`,
|
|
447
|
+
skillRestorePreviewFailed: (reason) => `This snapshot cannot be used to restore: ${reason}`,
|
|
448
|
+
skillRestoreSameFiles: 'The directory already matches this snapshot.',
|
|
449
|
+
skillRestoreMoved: 'The directory changed since this snapshot; a restore would replace those changes.',
|
|
450
|
+
skillRestoreRefusals: {
|
|
451
|
+
'no-directory': 'This is a single-file skill, so there is no directory to restore.',
|
|
452
|
+
'system-skill': 'It lives under .system, which this plugin never writes.',
|
|
453
|
+
'inside-git-checkout': 'It lives inside a Git checkout, which this plugin never writes.',
|
|
454
|
+
'bundled-skill': 'It ships with DSH, which this plugin never writes.',
|
|
455
|
+
'snapshot-unreadable': 'The snapshot file could not be read.',
|
|
456
|
+
'snapshot-mismatch': 'The snapshot records a different skill.',
|
|
457
|
+
'snapshot-copy-missing': 'The stored copy is gone.',
|
|
458
|
+
'snapshot-directory-mismatch': 'The snapshot records a different directory.',
|
|
459
|
+
'snapshot-copy-corrupt': 'The stored copy no longer matches its fingerprint, so it is not a baseline.',
|
|
460
|
+
'undo-snapshot-failed': 'The undo snapshot could not be taken, so nothing was replaced.',
|
|
461
|
+
'staging-failed': 'A staging directory could not be prepared on the same volume.',
|
|
462
|
+
'staged-copy-corrupt': 'The staged copy did not match the snapshot, so nothing was swapped in.',
|
|
463
|
+
'swap-failed': 'The directory swap failed and the original was put back where possible.',
|
|
464
|
+
'verification-failed': 'The directory did not match the snapshot after the swap.',
|
|
465
|
+
'bad-snapshot-file': 'That snapshot file name is not valid.',
|
|
466
|
+
'not-a-directory': 'The target is not a directory.',
|
|
467
|
+
},
|
|
468
|
+
skillFilesTruncated: 'over the limit, not counted to the end',
|
|
469
|
+
skillSourceLabels: {
|
|
470
|
+
'project-dsh': 'project .dsh/skills',
|
|
471
|
+
'project-agents': 'project .agents/skills',
|
|
472
|
+
custom: 'custom directories',
|
|
473
|
+
'user-dsh': 'user .dsh/skills',
|
|
474
|
+
'user-agents': 'user .agents/skills',
|
|
475
|
+
bundled: 'bundled with DSH',
|
|
476
|
+
},
|
|
477
|
+
skillSourceUnknown: (value) => `unrecognised source (${value})`,
|
|
478
|
+
skillsSoon:
|
|
479
|
+
'Skill version management comes in the next stage; this panel handles plugins only.',
|
|
480
|
+
gitTitle: 'Git-managed Skills',
|
|
481
|
+
gitSubtitle:
|
|
482
|
+
'Register a remote repository and the exact subpath inside it, and this Skill can then be filled from a commit. The plugin reads Git through its own cache and never runs a command inside your checkout.',
|
|
483
|
+
gitEmpty: 'No Git source is registered yet.',
|
|
484
|
+
gitName: 'Skill name',
|
|
485
|
+
gitRemote: 'Repository',
|
|
486
|
+
gitSubpath: 'Subpath in the repository',
|
|
487
|
+
gitRef: 'Branch or tag',
|
|
488
|
+
gitRegister: 'Register',
|
|
489
|
+
gitRegistering: 'Registering…',
|
|
490
|
+
gitRegisterNote:
|
|
491
|
+
'Registering records the source and pins one commit; it does not touch the files. The first update is what writes them.',
|
|
492
|
+
gitNeedName: 'Enter a Skill name first',
|
|
493
|
+
gitNeedRemote: 'Enter a repository first',
|
|
494
|
+
gitCreateHint: 'When the host catalog has no such Skill, this lets the plugin create skills/<name>.',
|
|
495
|
+
gitCreate: 'Create the directory when missing',
|
|
496
|
+
gitRegisteredAt: (when) => `registered ${when}`,
|
|
497
|
+
gitRevisionCurrent: 'Current revision',
|
|
498
|
+
gitPopulated: 'Content is installed',
|
|
499
|
+
gitNotPopulated: 'Nothing installed yet (the directory is empty)',
|
|
500
|
+
gitLocalModifications: 'The directory changed since registration, so an update is refused',
|
|
501
|
+
gitInCheckout: 'The directory is inside a Git checkout, which this plugin never writes',
|
|
502
|
+
gitHistory: 'History',
|
|
503
|
+
gitPreview: 'Preview the change',
|
|
504
|
+
gitPreviewing: 'Reading…',
|
|
505
|
+
gitUpdate: 'Update to latest',
|
|
506
|
+
gitUpdating: 'Updating…',
|
|
507
|
+
gitRemove: 'Unregister',
|
|
508
|
+
gitRemoving: 'Unregistering…',
|
|
509
|
+
gitUpdateDone: (from, to) => `Updated ${from} → ${to}`,
|
|
510
|
+
gitRestoreTo: 'Go back to this commit',
|
|
511
|
+
gitRestored: (revision) => `Back at ${revision}`,
|
|
512
|
+
gitAlreadyAt: 'Already at the newest commit',
|
|
513
|
+
gitChanges: (count) => `${count} file${count === 1 ? '' : 's'} would change`,
|
|
514
|
+
gitNoChanges: 'No file differences',
|
|
515
|
+
gitUndoSnapshot: 'The current directory is snapshotted first, so this can be undone.',
|
|
516
|
+
gitUpdateConfirm: 'Update this Skill to that commit?',
|
|
517
|
+
gitUpdateBody: (name, from, to) => `The ${name} directory is replaced with ${to}. It is at ${from} now.`,
|
|
518
|
+
gitUpdateNotes: [
|
|
519
|
+
'A snapshot of the current directory is taken first, so this can be undone.',
|
|
520
|
+
'Files that are not in that commit are removed from the directory.',
|
|
521
|
+
'No checkout, reset or clean runs, and the repository itself is not touched.',
|
|
522
|
+
],
|
|
523
|
+
gitRestoreConfirm: 'Put this Skill back at that commit?',
|
|
524
|
+
gitRestoreBody: (name, revision) => `The ${name} directory is replaced with the tree of ${revision}.`,
|
|
525
|
+
gitGitRefusals: {
|
|
526
|
+
'not-registered': 'This Skill has no registered Git source.',
|
|
527
|
+
'unsupported-remote': 'That repository address uses a transport this plugin does not support.',
|
|
528
|
+
'bad-subpath': 'That subpath is not valid (no absolute path, no .. and no .git).',
|
|
529
|
+
'no-directory': 'A single-file skill has no directory to write.',
|
|
530
|
+
'system-skill': 'It lives under .system, which this plugin never writes.',
|
|
531
|
+
'inside-git-checkout': 'The directory is inside a Git checkout, which this plugin never writes.',
|
|
532
|
+
'local-modifications': 'The directory changed after registration; settle those changes before updating.',
|
|
533
|
+
'baseline-unknown': 'What is in the directory does not match that commit tree, so there is no honest baseline.',
|
|
534
|
+
'already-registered': 'This Skill is already registered to another source; unregister it first.',
|
|
535
|
+
'missing-name': 'A Skill name is required.',
|
|
536
|
+
'bad-name': 'A Skill name may only contain letters, digits, dot, dash and underscore.',
|
|
537
|
+
'git-not-found': 'The git command was not found.',
|
|
538
|
+
'git-timeout': 'A Git command timed out.',
|
|
539
|
+
'fetch-failed': 'Fetching the repository failed; check the address and the network.',
|
|
540
|
+
'ref-unresolved': 'That branch or tag does not resolve to a commit.',
|
|
541
|
+
'revision-not-in-cache': 'That commit is not in the cache, and this plugin does not guess.',
|
|
542
|
+
'unsupported-entry': 'That commit contains a symlink or a submodule, which this plugin does not write.',
|
|
543
|
+
'already-at-revision': 'It is already at that commit.',
|
|
544
|
+
'undo-snapshot-failed': 'The undo snapshot could not be taken, so nothing was replaced.',
|
|
545
|
+
'bad-revision': 'That commit id is not valid.',
|
|
546
|
+
},
|
|
547
|
+
},
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* Pick a language once per mount. There is no language switcher here on
|
|
552
|
+
* purpose: DSH already has one, and a second source of truth would drift.
|
|
553
|
+
*/
|
|
554
|
+
function pickLanguage() {
|
|
555
|
+
const candidates = []
|
|
556
|
+
try {
|
|
557
|
+
candidates.push(window.navigator?.language ?? '')
|
|
558
|
+
candidates.push(...(window.navigator?.languages ?? []))
|
|
559
|
+
} catch {
|
|
560
|
+
// A browser that refuses to answer gets English, which is always safe.
|
|
561
|
+
}
|
|
562
|
+
for (const value of candidates) {
|
|
563
|
+
if (typeof value === 'string' && value.toLowerCase().startsWith('zh')) return 'zh'
|
|
564
|
+
}
|
|
565
|
+
return 'en'
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
// ------------------------------------------------------------------ fetch
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* @param {string} path
|
|
572
|
+
* @param {{ method?: string, body?: unknown, signal?: AbortSignal }} options
|
|
573
|
+
*/
|
|
574
|
+
async function request(path, options = {}) {
|
|
575
|
+
const method = options.method ?? 'GET'
|
|
576
|
+
const init = {
|
|
577
|
+
method,
|
|
578
|
+
credentials: 'same-origin',
|
|
579
|
+
headers: { accept: 'application/json' },
|
|
580
|
+
signal: options.signal,
|
|
581
|
+
}
|
|
582
|
+
if (options.body !== undefined) {
|
|
583
|
+
init.headers['content-type'] = 'application/json'
|
|
584
|
+
init.body = JSON.stringify(options.body)
|
|
585
|
+
}
|
|
586
|
+
let response
|
|
587
|
+
try {
|
|
588
|
+
response = await fetch(`${ROUTE_BASE}${path}`, init)
|
|
589
|
+
} catch (error) {
|
|
590
|
+
if (error?.name === 'AbortError') throw error
|
|
591
|
+
const failure = new Error('network')
|
|
592
|
+
failure.kind = 'network'
|
|
593
|
+
failure.cause = error
|
|
594
|
+
throw failure
|
|
595
|
+
}
|
|
596
|
+
let body = null
|
|
597
|
+
try {
|
|
598
|
+
body = await response.json()
|
|
599
|
+
} catch {
|
|
600
|
+
body = null
|
|
601
|
+
}
|
|
602
|
+
if (!response.ok) {
|
|
603
|
+
const failure = new Error(body?.message ?? body?.error ?? `HTTP ${response.status}`)
|
|
604
|
+
failure.kind = 'http'
|
|
605
|
+
failure.status = response.status
|
|
606
|
+
failure.body = body
|
|
607
|
+
throw failure
|
|
608
|
+
}
|
|
609
|
+
return body
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
// ------------------------------------------------------------------- time
|
|
613
|
+
|
|
614
|
+
function formatTime(value, language) {
|
|
615
|
+
if (typeof value !== 'string' || value === '') return ''
|
|
616
|
+
const date = new Date(value)
|
|
617
|
+
if (Number.isNaN(date.getTime())) return value
|
|
618
|
+
const locale = language === 'zh' ? 'zh-CN' : 'en-US'
|
|
619
|
+
return new Intl.DateTimeFormat(locale, {
|
|
620
|
+
month: 'short',
|
|
621
|
+
day: 'numeric',
|
|
622
|
+
hour: '2-digit',
|
|
623
|
+
minute: '2-digit',
|
|
624
|
+
}).format(date)
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
// ------------------------------------------------------------------ atoms
|
|
628
|
+
|
|
629
|
+
function Dot(props) {
|
|
630
|
+
const color = props.tone === 'pass' ? COLORS.pass : props.tone === 'warn' ? COLORS.warn : props.tone === 'fail' ? COLORS.fail : COLORS.idle
|
|
631
|
+
return h('span', {
|
|
632
|
+
'aria-hidden': 'true',
|
|
633
|
+
style: {
|
|
634
|
+
display: 'inline-block',
|
|
635
|
+
width: 7,
|
|
636
|
+
height: 7,
|
|
637
|
+
borderRadius: 999,
|
|
638
|
+
background: color,
|
|
639
|
+
marginRight: 6,
|
|
640
|
+
flex: '0 0 auto',
|
|
641
|
+
},
|
|
642
|
+
})
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
function Badge(props) {
|
|
646
|
+
return h(
|
|
647
|
+
'span',
|
|
648
|
+
{
|
|
649
|
+
style: {
|
|
650
|
+
display: 'inline-flex',
|
|
651
|
+
alignItems: 'center',
|
|
652
|
+
gap: 4,
|
|
653
|
+
padding: '1px 7px',
|
|
654
|
+
borderRadius: 999,
|
|
655
|
+
border: `1px solid ${COLORS.line}`,
|
|
656
|
+
background: COLORS.soft,
|
|
657
|
+
fontSize: 11,
|
|
658
|
+
lineHeight: 1.6,
|
|
659
|
+
whiteSpace: 'nowrap',
|
|
660
|
+
},
|
|
661
|
+
},
|
|
662
|
+
props.children,
|
|
663
|
+
)
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
function Button(props) {
|
|
667
|
+
return h(
|
|
668
|
+
'button',
|
|
669
|
+
{
|
|
670
|
+
type: 'button',
|
|
671
|
+
onClick: props.onClick,
|
|
672
|
+
disabled: props.disabled === true,
|
|
673
|
+
title: props.title,
|
|
674
|
+
'aria-label': props.ariaLabel ?? props.children,
|
|
675
|
+
style: {
|
|
676
|
+
font: 'inherit',
|
|
677
|
+
fontSize: 12,
|
|
678
|
+
padding: '3px 9px',
|
|
679
|
+
borderRadius: 6,
|
|
680
|
+
border: `1px solid ${COLORS.line}`,
|
|
681
|
+
background: props.primary === true ? '#1f6feb' : 'transparent',
|
|
682
|
+
color: props.primary === true ? '#fff' : 'inherit',
|
|
683
|
+
cursor: props.disabled === true ? 'default' : 'pointer',
|
|
684
|
+
opacity: props.disabled === true ? 0.5 : 1,
|
|
685
|
+
whiteSpace: 'nowrap',
|
|
686
|
+
},
|
|
687
|
+
},
|
|
688
|
+
props.children,
|
|
689
|
+
)
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
function Notice(props) {
|
|
693
|
+
const tone = props.tone ?? 'warn'
|
|
694
|
+
const color = tone === 'fail' ? COLORS.fail : tone === 'pass' ? COLORS.pass : COLORS.warn
|
|
695
|
+
return h(
|
|
696
|
+
'div',
|
|
697
|
+
{
|
|
698
|
+
role: props.role ?? 'status',
|
|
699
|
+
style: {
|
|
700
|
+
display: 'flex',
|
|
701
|
+
gap: 8,
|
|
702
|
+
alignItems: 'flex-start',
|
|
703
|
+
borderLeft: `3px solid ${color}`,
|
|
704
|
+
background: COLORS.soft,
|
|
705
|
+
padding: '6px 10px',
|
|
706
|
+
borderRadius: 4,
|
|
707
|
+
fontSize: 12,
|
|
708
|
+
margin: '6px 0',
|
|
709
|
+
},
|
|
710
|
+
},
|
|
711
|
+
h(
|
|
712
|
+
'div',
|
|
713
|
+
{ style: { flex: '1 1 auto', minWidth: 0 } },
|
|
714
|
+
h('div', { style: { fontWeight: 600 } }, props.title),
|
|
715
|
+
props.children === undefined
|
|
716
|
+
? null
|
|
717
|
+
: h('div', { style: { opacity: 0.85, marginTop: 2, wordBreak: 'break-word' } }, props.children),
|
|
718
|
+
),
|
|
719
|
+
)
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
function Field(props) {
|
|
723
|
+
return h(
|
|
724
|
+
'div',
|
|
725
|
+
{ style: { display: 'flex', gap: 6, fontSize: 12, marginTop: 3, flexWrap: 'wrap' } },
|
|
726
|
+
h('span', { style: { opacity: 0.6, minWidth: 96 } }, props.label),
|
|
727
|
+
h('span', { style: { wordBreak: 'break-all' } }, props.value === null || props.value === undefined || props.value === '' ? '—' : props.value),
|
|
728
|
+
)
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
// ------------------------------------------------------------- presentation
|
|
732
|
+
|
|
733
|
+
function loadTone(row) {
|
|
734
|
+
if (row.loadStateAvailable !== true) return 'idle'
|
|
735
|
+
if (row.loadState === 'failed') return 'fail'
|
|
736
|
+
if (row.loadState === 'active') return 'pass'
|
|
737
|
+
if (row.loadState === 'unloading') return 'warn'
|
|
738
|
+
return 'idle'
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
function loadLabel(row, t) {
|
|
742
|
+
if (row.loadStateAvailable !== true) return t.loadUnknown
|
|
743
|
+
switch (row.loadState) {
|
|
744
|
+
case 'active':
|
|
745
|
+
return t.loadActive
|
|
746
|
+
case 'failed':
|
|
747
|
+
return t.loadFailed
|
|
748
|
+
case 'pending':
|
|
749
|
+
return t.loadPending
|
|
750
|
+
case 'loading':
|
|
751
|
+
return t.loadLoading
|
|
752
|
+
case 'unloading':
|
|
753
|
+
return t.loadUnloading
|
|
754
|
+
default:
|
|
755
|
+
return t.loadUnknown
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
/**
|
|
760
|
+
* The sentence behind a load badge.
|
|
761
|
+
*
|
|
762
|
+
* A bundle is applied as a patch, so the loader tracks the plugin entries it
|
|
763
|
+
* installs rather than the bundle name. "No phase" therefore means "this
|
|
764
|
+
* composition is not an entry", which is not the same as "the loader could
|
|
765
|
+
* not be read", and neither means the plugin is broken.
|
|
766
|
+
*/
|
|
767
|
+
function loadDetail(row, t) {
|
|
768
|
+
if (row.loadState === 'failed') return row.loadError ?? null
|
|
769
|
+
if (row.loadStateReason === 'no-loader-entry') return t.loadNoEntry
|
|
770
|
+
if (row.loadStateAvailable !== true) return t.loadUnavailable
|
|
771
|
+
if (row.loadState === null || row.loadState === undefined) return t.loadNoEntry
|
|
772
|
+
return null
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
function compatLabel(row, t) {
|
|
776
|
+
const compat = row.compatibility ?? {}
|
|
777
|
+
const verdict = compat.verdict
|
|
778
|
+
if (verdict === undefined || verdict === null || verdict === 'unknown') return t.compatUnknown
|
|
779
|
+
if (verdict === 'exempted') return t.compatExempted
|
|
780
|
+
if (verdict === 'satisfied' || verdict === 'met' || verdict === 'ok') {
|
|
781
|
+
// "satisfied" with no requirement means the package asked for nothing,
|
|
782
|
+
// which is not the same as the host having checked it.
|
|
783
|
+
const declared = Array.isArray(compat.requirements) && compat.requirements.length > 0
|
|
784
|
+
return declared ? t.compatOk : t.compatNoRequirement
|
|
785
|
+
}
|
|
786
|
+
return t.compatFail
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
function compatTone(row) {
|
|
790
|
+
const compat = row.compatibility ?? {}
|
|
791
|
+
const verdict = compat.verdict
|
|
792
|
+
if (verdict === 'satisfied' || verdict === 'met' || verdict === 'ok') {
|
|
793
|
+
// Nothing was declared, so nothing was verified: a neutral dot, never a
|
|
794
|
+
// green one, keeps the badge from implying a check that never happened.
|
|
795
|
+
const declared = Array.isArray(compat.requirements) && compat.requirements.length > 0
|
|
796
|
+
return declared ? 'pass' : 'idle'
|
|
797
|
+
}
|
|
798
|
+
if (verdict === 'exempted') return 'warn'
|
|
799
|
+
if (verdict === undefined || verdict === null || verdict === 'unknown') return 'idle'
|
|
800
|
+
return 'fail'
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* The sentence behind a compatibility badge.
|
|
805
|
+
*
|
|
806
|
+
* A badge is a claim, so it always has a reason attached: the requirement
|
|
807
|
+
* that failed, the range this panel could not read, or the fact that the
|
|
808
|
+
* running DSH version was not observable at all.
|
|
809
|
+
*/
|
|
810
|
+
function compatDetail(row, t) {
|
|
811
|
+
const compat = row.compatibility ?? {}
|
|
812
|
+
if (compat.verdict === 'unsatisfied' && Array.isArray(compat.unmet) && compat.unmet.length > 0) {
|
|
813
|
+
const parts = compat.unmet.map((item) => `${item.field} ${item.range}`)
|
|
814
|
+
return t.compatUnmet(parts.join('; '), compat.runtimeVersion ?? t.unknown)
|
|
815
|
+
}
|
|
816
|
+
if (compat.verdict === 'exempted') return t.compatExemptedDetail(compat.runtimeVersion ?? t.unknown)
|
|
817
|
+
if (compat.reason) return String(compat.reason)
|
|
818
|
+
if (Array.isArray(compat.requirements) && compat.requirements.length > 0) {
|
|
819
|
+
const parts = compat.requirements.map((item) => `${item.field} ${item.range}`)
|
|
820
|
+
return t.compatMet(parts.join('; '), compat.runtimeVersion ?? t.unknown)
|
|
821
|
+
}
|
|
822
|
+
return t.compatNoClaim
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
function sourceLabel(row, t) {
|
|
826
|
+
const source = row.source ?? {}
|
|
827
|
+
if (source.kind === 'builtin') return t.builtinSource
|
|
828
|
+
if (row.availability === 'installation') return t.installationSource
|
|
829
|
+
if (source.kind === 'unknown') return t.unknownSource
|
|
830
|
+
if (typeof source.detail === 'string' && source.detail !== '') return source.detail
|
|
831
|
+
if (source.kind === 'registry') return source.registryName ?? t.unknown
|
|
832
|
+
return source.kind ?? t.unknown
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
// Refusals arrive as reason codes so the sentence can be written here, in
|
|
836
|
+
// the reader's language, instead of being rendered in English.
|
|
837
|
+
function refusalLabel(reason, t) {
|
|
838
|
+
if (typeof reason !== 'string') return null
|
|
839
|
+
if (reason.startsWith('read-only:')) return `${t.readOnly} (${reason.slice('read-only:'.length)})`
|
|
840
|
+
if (reason.startsWith('not-registry:')) {
|
|
841
|
+
return t.notRegistrySource(reason.slice('not-registry:'.length))
|
|
842
|
+
}
|
|
843
|
+
return t.refusal[reason] ?? reason
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
function VersionPicker(props) {
|
|
847
|
+
const { t, language, data, onPick, busyVersion, installed } = props
|
|
848
|
+
if (data === null) return null
|
|
849
|
+
if (data.status !== 'ok') {
|
|
850
|
+
return h(
|
|
851
|
+
Notice,
|
|
852
|
+
{ tone: 'warn', title: t.versionListRefused },
|
|
853
|
+
data.message ?? data.reason ?? data.status,
|
|
854
|
+
)
|
|
855
|
+
}
|
|
856
|
+
if (data.versions.length === 0) {
|
|
857
|
+
return h('div', { style: { fontSize: 12, opacity: 0.7, margin: '6px 0' } }, t.noNewerVersions)
|
|
858
|
+
}
|
|
859
|
+
const renderGroup = (label, items) =>
|
|
860
|
+
items.length === 0
|
|
861
|
+
? null
|
|
862
|
+
: h(
|
|
863
|
+
'div',
|
|
864
|
+
{ style: { marginTop: 6 } },
|
|
865
|
+
h('div', { style: { fontSize: 11, opacity: 0.6, textTransform: 'uppercase', letterSpacing: 0.4 } }, label),
|
|
866
|
+
h(
|
|
867
|
+
'ul',
|
|
868
|
+
{ style: { listStyle: 'none', margin: '4px 0 0', padding: 0 } },
|
|
869
|
+
items.map((item) =>
|
|
870
|
+
h(
|
|
871
|
+
'li',
|
|
872
|
+
{
|
|
873
|
+
key: item.version,
|
|
874
|
+
style: {
|
|
875
|
+
display: 'flex',
|
|
876
|
+
gap: 8,
|
|
877
|
+
alignItems: 'center',
|
|
878
|
+
padding: '3px 0',
|
|
879
|
+
borderTop: `1px solid ${COLORS.line}`,
|
|
880
|
+
fontSize: 12,
|
|
881
|
+
},
|
|
882
|
+
},
|
|
883
|
+
h('code', { style: { fontFamily: 'ui-monospace, monospace' } }, item.version),
|
|
884
|
+
item.version === installed ? h(Badge, null, t.colVersion) : null,
|
|
885
|
+
item.deprecated !== null && item.deprecated !== undefined ? h(Badge, null, t.deprecated) : null,
|
|
886
|
+
item.isBundle === false ? h(Badge, null, 'not a bundle') : null,
|
|
887
|
+
item.compatibility !== null && item.compatibility !== undefined && item.compatibility.exempted !== true
|
|
888
|
+
? h(Badge, null, item.compatibility.requirements ? t.compatFail : t.compatOk)
|
|
889
|
+
: null,
|
|
890
|
+
h('span', { style: { opacity: 0.6, marginLeft: 'auto' } },
|
|
891
|
+
item.publishedAt === null ? '' : `${t.published} ${formatTime(item.publishedAt, language)}`),
|
|
892
|
+
h(
|
|
893
|
+
Button,
|
|
894
|
+
{
|
|
895
|
+
onClick: () => onPick(item),
|
|
896
|
+
disabled: busyVersion !== null,
|
|
897
|
+
primary: false,
|
|
898
|
+
ariaLabel: `${t.updateTo} ${item.version}`,
|
|
899
|
+
},
|
|
900
|
+
busyVersion === item.version ? t.updating : t.updateTo,
|
|
901
|
+
),
|
|
902
|
+
),
|
|
903
|
+
),
|
|
904
|
+
),
|
|
905
|
+
)
|
|
906
|
+
return h(
|
|
907
|
+
'div',
|
|
908
|
+
null,
|
|
909
|
+
renderGroup(t.stable, data.stable),
|
|
910
|
+
renderGroup(t.prerelease, data.prerelease),
|
|
911
|
+
)
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
function SnapshotList(props) {
|
|
915
|
+
const { t, language, snapshots, installed, onRestore, busy } = props
|
|
916
|
+
if (snapshots.length === 0) {
|
|
917
|
+
return h('div', { style: { fontSize: 12, opacity: 0.7, marginTop: 4 } }, t.noSnapshots)
|
|
918
|
+
}
|
|
919
|
+
return h(
|
|
920
|
+
'ul',
|
|
921
|
+
{ style: { listStyle: 'none', margin: '4px 0 0', padding: 0 } },
|
|
922
|
+
snapshots
|
|
923
|
+
.slice()
|
|
924
|
+
.reverse()
|
|
925
|
+
.map((snapshot) =>
|
|
926
|
+
h(
|
|
927
|
+
'li',
|
|
928
|
+
{
|
|
929
|
+
key: snapshot.id,
|
|
930
|
+
style: {
|
|
931
|
+
display: 'flex',
|
|
932
|
+
gap: 8,
|
|
933
|
+
alignItems: 'center',
|
|
934
|
+
fontSize: 12,
|
|
935
|
+
padding: '3px 0',
|
|
936
|
+
borderTop: `1px solid ${COLORS.line}`,
|
|
937
|
+
},
|
|
938
|
+
},
|
|
939
|
+
h('code', { style: { fontFamily: 'ui-monospace, monospace' } }, snapshot.installedVersion ?? '—'),
|
|
940
|
+
h('span', { style: { opacity: 0.65 } }, formatTime(snapshot.takenAt, language)),
|
|
941
|
+
snapshot.reason === 'unreadable' ? h(Badge, null, snapshot.reason) : null,
|
|
942
|
+
snapshot.installedVersion === installed ? h(Badge, null, t.colVersion) : null,
|
|
943
|
+
h(
|
|
944
|
+
'span',
|
|
945
|
+
{ style: { marginLeft: 'auto' } },
|
|
946
|
+
h(
|
|
947
|
+
Button,
|
|
948
|
+
{
|
|
949
|
+
onClick: () => onRestore(snapshot),
|
|
950
|
+
disabled: busy !== null || snapshot.reason === 'unreadable',
|
|
951
|
+
ariaLabel: `${t.restore} ${snapshot.installedVersion ?? ''}`,
|
|
952
|
+
},
|
|
953
|
+
t.restore,
|
|
954
|
+
),
|
|
955
|
+
),
|
|
956
|
+
),
|
|
957
|
+
),
|
|
958
|
+
)
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
function ConfirmBar(props) {
|
|
962
|
+
const { t, title, body, notes, onCancel, onConfirm, busy, confirmLabel } = props
|
|
963
|
+
return h(
|
|
964
|
+
'div',
|
|
965
|
+
{
|
|
966
|
+
role: 'group',
|
|
967
|
+
'aria-label': title,
|
|
968
|
+
style: {
|
|
969
|
+
border: `1px solid ${COLORS.line}`,
|
|
970
|
+
borderRadius: 8,
|
|
971
|
+
padding: '8px 10px',
|
|
972
|
+
marginTop: 8,
|
|
973
|
+
background: COLORS.soft,
|
|
974
|
+
},
|
|
975
|
+
},
|
|
976
|
+
h('div', { style: { fontSize: 12, fontWeight: 600 } }, title),
|
|
977
|
+
body === null ? null : h('div', { style: { fontSize: 12, marginTop: 4 } }, body),
|
|
978
|
+
notes === null || notes === undefined
|
|
979
|
+
? null
|
|
980
|
+
: h(
|
|
981
|
+
'ul',
|
|
982
|
+
{ style: { margin: '6px 0 0', paddingLeft: 18, fontSize: 11.5, opacity: 0.8 } },
|
|
983
|
+
notes.map((note, index) => h('li', { key: index }, note)),
|
|
984
|
+
),
|
|
985
|
+
h(
|
|
986
|
+
'div',
|
|
987
|
+
{ style: { display: 'flex', gap: 8, marginTop: 8 } },
|
|
988
|
+
h(Button, { onClick: onCancel, disabled: busy }, t.cancel),
|
|
989
|
+
h(Button, { onClick: onConfirm, disabled: busy, primary: true }, busy ? '…' : confirmLabel ?? t.confirm),
|
|
990
|
+
),
|
|
991
|
+
)
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
function Row(props) {
|
|
995
|
+
const { row, t, language, expanded, onToggle, onRefresh } = props
|
|
996
|
+
const [versions, setVersions] = useState(null)
|
|
997
|
+
const [versionsBusy, setVersionsBusy] = useState(false)
|
|
998
|
+
const [versionsError, setVersionsError] = useState(null)
|
|
999
|
+
const [pendingUpdate, setPendingUpdate] = useState(null)
|
|
1000
|
+
const [updateBusy, setUpdateBusy] = useState(false)
|
|
1001
|
+
const [result, setResult] = useState(null)
|
|
1002
|
+
const [snapshotBusy, setSnapshotBusy] = useState(false)
|
|
1003
|
+
const [pendingRestore, setPendingRestore] = useState(null)
|
|
1004
|
+
const [restoreBusy, setRestoreBusy] = useState(false)
|
|
1005
|
+
|
|
1006
|
+
const loadVersions = useCallback(async () => {
|
|
1007
|
+
setVersionsBusy(true)
|
|
1008
|
+
setVersionsError(null)
|
|
1009
|
+
try {
|
|
1010
|
+
setVersions(await request(`/versions?target=${encodeURIComponent(row.targetId)}`))
|
|
1011
|
+
} catch (error) {
|
|
1012
|
+
setVersionsError(error)
|
|
1013
|
+
} finally {
|
|
1014
|
+
setVersionsBusy(false)
|
|
1015
|
+
}
|
|
1016
|
+
}, [row.targetId])
|
|
1017
|
+
|
|
1018
|
+
const takeSnapshot = useCallback(async () => {
|
|
1019
|
+
setSnapshotBusy(true)
|
|
1020
|
+
setResult(null)
|
|
1021
|
+
try {
|
|
1022
|
+
const body = await request('/snapshot', {
|
|
1023
|
+
method: 'POST',
|
|
1024
|
+
body: { targetId: row.targetId, reason: 'manual', confirm: true },
|
|
1025
|
+
})
|
|
1026
|
+
setResult({ ok: true, message: `${t.snapshots}: ${body.snapshot.id.slice(0, 8)}` })
|
|
1027
|
+
await onRefresh()
|
|
1028
|
+
} catch (error) {
|
|
1029
|
+
setResult({ ok: false, message: describeError(error, t) })
|
|
1030
|
+
} finally {
|
|
1031
|
+
setSnapshotBusy(false)
|
|
1032
|
+
}
|
|
1033
|
+
}, [row.targetId, onRefresh, t])
|
|
1034
|
+
|
|
1035
|
+
const runUpdate = useCallback(async () => {
|
|
1036
|
+
if (pendingUpdate === null) return
|
|
1037
|
+
setUpdateBusy(true)
|
|
1038
|
+
try {
|
|
1039
|
+
const body = await request('/update', {
|
|
1040
|
+
method: 'POST',
|
|
1041
|
+
body: {
|
|
1042
|
+
targetId: row.targetId,
|
|
1043
|
+
toVersion: pendingUpdate.version,
|
|
1044
|
+
allowPrerelease: pendingUpdate.prerelease === true,
|
|
1045
|
+
confirm: true,
|
|
1046
|
+
},
|
|
1047
|
+
})
|
|
1048
|
+
setResult({
|
|
1049
|
+
ok: body.ok === true,
|
|
1050
|
+
message:
|
|
1051
|
+
body.ok === true
|
|
1052
|
+
? `${t.updateOk}: ${body.fromVersion} → ${body.observedVersion ?? body.toVersion}`
|
|
1053
|
+
: `${t.updateFailed}: ${body.message ?? ''}`,
|
|
1054
|
+
})
|
|
1055
|
+
setPendingUpdate(null)
|
|
1056
|
+
await onRefresh()
|
|
1057
|
+
} catch (error) {
|
|
1058
|
+
setResult({ ok: false, message: describeError(error, t) })
|
|
1059
|
+
} finally {
|
|
1060
|
+
setUpdateBusy(false)
|
|
1061
|
+
}
|
|
1062
|
+
}, [pendingUpdate, row.targetId, onRefresh, t])
|
|
1063
|
+
|
|
1064
|
+
const runRestore = useCallback(async () => {
|
|
1065
|
+
if (pendingRestore === null) return
|
|
1066
|
+
setRestoreBusy(true)
|
|
1067
|
+
try {
|
|
1068
|
+
const body = await request('/restore', {
|
|
1069
|
+
method: 'POST',
|
|
1070
|
+
body: { targetId: row.targetId, snapshotId: pendingRestore.id, confirm: true },
|
|
1071
|
+
})
|
|
1072
|
+
// A restore is a different fact from an update: it reinstalls the
|
|
1073
|
+
// version the snapshot recorded. Saying "updated" here would be a
|
|
1074
|
+
// wrong verb for what happened.
|
|
1075
|
+
const moved = body.evidence?.filesMatch === false
|
|
1076
|
+
setResult({
|
|
1077
|
+
ok: body.ok === true,
|
|
1078
|
+
message:
|
|
1079
|
+
body.ok === true
|
|
1080
|
+
? `${t.restoreOk}: ${body.fromVersion ?? ''}${body.fromVersion ? ' → ' : ''}${body.restoredVersion}(${t.restoreObserved(body.observedVersion)})${moved ? '' : ` ${t.restoreFilesMatched}`}`
|
|
1081
|
+
: `${t.updateFailed}: ${body.message ?? ''}`,
|
|
1082
|
+
})
|
|
1083
|
+
setPendingRestore(null)
|
|
1084
|
+
await onRefresh()
|
|
1085
|
+
} catch (error) {
|
|
1086
|
+
const failure = describeError(error, t)
|
|
1087
|
+
setResult({
|
|
1088
|
+
ok: false,
|
|
1089
|
+
message: error?.body?.error === 'files-changed' || error?.status === 409 ? `${t.restoreRefused}: ${failure}` : failure,
|
|
1090
|
+
})
|
|
1091
|
+
} finally {
|
|
1092
|
+
setRestoreBusy(false)
|
|
1093
|
+
}
|
|
1094
|
+
}, [pendingRestore, row.targetId, onRefresh, t])
|
|
1095
|
+
|
|
1096
|
+
// Not "updatable": the host accepting a write says nothing about whether
|
|
1097
|
+
// a newer version exists. Only the version check answers that.
|
|
1098
|
+
const writable = row.updateRefusal === null
|
|
1099
|
+
|
|
1100
|
+
const summaryRow = h(
|
|
1101
|
+
'tr',
|
|
1102
|
+
{ style: { borderTop: `1px solid ${COLORS.line}` } },
|
|
1103
|
+
h(
|
|
1104
|
+
'td',
|
|
1105
|
+
{ style: { padding: '6px 8px', verticalAlign: 'top' } },
|
|
1106
|
+
h('button', {
|
|
1107
|
+
type: 'button',
|
|
1108
|
+
onClick: onToggle,
|
|
1109
|
+
'aria-expanded': expanded,
|
|
1110
|
+
style: {
|
|
1111
|
+
font: 'inherit',
|
|
1112
|
+
background: 'none',
|
|
1113
|
+
border: 'none',
|
|
1114
|
+
padding: 0,
|
|
1115
|
+
color: 'inherit',
|
|
1116
|
+
cursor: 'pointer',
|
|
1117
|
+
textAlign: 'left',
|
|
1118
|
+
},
|
|
1119
|
+
},
|
|
1120
|
+
h('span', { style: { marginRight: 6, opacity: 0.6 } }, expanded ? '▾' : '▸'),
|
|
1121
|
+
h(
|
|
1122
|
+
'span',
|
|
1123
|
+
{ style: { fontWeight: 500, wordBreak: 'break-word' } },
|
|
1124
|
+
row.targetId,
|
|
1125
|
+
),
|
|
1126
|
+
),
|
|
1127
|
+
h(
|
|
1128
|
+
'div',
|
|
1129
|
+
{ style: { display: 'flex', gap: 4, marginTop: 3, flexWrap: 'wrap' } },
|
|
1130
|
+
row.official === true ? h(Badge, null, t.official) : null,
|
|
1131
|
+
writable ? null : h(Badge, null, t.readOnly),
|
|
1132
|
+
row.prerelease === true ? h(Badge, null, t.prerelease) : null,
|
|
1133
|
+
),
|
|
1134
|
+
),
|
|
1135
|
+
h(
|
|
1136
|
+
'td',
|
|
1137
|
+
{ style: { padding: '6px 8px', verticalAlign: 'top', fontFamily: 'ui-monospace, monospace', fontSize: 12 } },
|
|
1138
|
+
row.installedVersion ?? t.unknown,
|
|
1139
|
+
),
|
|
1140
|
+
h('td', { style: { padding: '6px 8px', verticalAlign: 'top', fontSize: 12, wordBreak: 'break-word' } }, sourceLabel(row, t)),
|
|
1141
|
+
h(
|
|
1142
|
+
'td',
|
|
1143
|
+
{ style: { padding: '6px 8px', verticalAlign: 'top', fontSize: 12, whiteSpace: 'nowrap' } },
|
|
1144
|
+
h(Dot, { tone: loadTone(row) }),
|
|
1145
|
+
loadLabel(row, t),
|
|
1146
|
+
),
|
|
1147
|
+
h(
|
|
1148
|
+
'td',
|
|
1149
|
+
{ style: { padding: '6px 8px', verticalAlign: 'top', fontSize: 12, whiteSpace: 'nowrap' } },
|
|
1150
|
+
h(Dot, { tone: compatTone(row) }),
|
|
1151
|
+
compatLabel(row, t),
|
|
1152
|
+
),
|
|
1153
|
+
h(
|
|
1154
|
+
'td',
|
|
1155
|
+
{ style: { padding: '6px 8px', verticalAlign: 'top', whiteSpace: 'nowrap' } },
|
|
1156
|
+
h(
|
|
1157
|
+
'div',
|
|
1158
|
+
{ style: { display: 'flex', gap: 6, flexWrap: 'nowrap' } },
|
|
1159
|
+
h(
|
|
1160
|
+
Button,
|
|
1161
|
+
{
|
|
1162
|
+
onClick: loadVersions,
|
|
1163
|
+
disabled: !writable || versionsBusy,
|
|
1164
|
+
title: writable ? undefined : refusalLabel(row.updateRefusal, t) ?? '',
|
|
1165
|
+
},
|
|
1166
|
+
versionsBusy ? t.checking : t.checkVersions,
|
|
1167
|
+
),
|
|
1168
|
+
h(Button, { onClick: takeSnapshot, disabled: snapshotBusy || row.loadState === 'failed' }, snapshotBusy ? t.snapshotting : t.takeSnapshot),
|
|
1169
|
+
),
|
|
1170
|
+
),
|
|
1171
|
+
)
|
|
1172
|
+
|
|
1173
|
+
const details = !expanded
|
|
1174
|
+
? null
|
|
1175
|
+
: h(
|
|
1176
|
+
'tr',
|
|
1177
|
+
null,
|
|
1178
|
+
h(
|
|
1179
|
+
'td',
|
|
1180
|
+
{ colSpan: 6, style: { padding: '4px 8px 12px 26px', background: COLORS.soft } },
|
|
1181
|
+
h(Field, { label: t.declared, value: row.declaredSpec }),
|
|
1182
|
+
h(Field, {
|
|
1183
|
+
label: t.declaredObserved,
|
|
1184
|
+
value:
|
|
1185
|
+
row.declaredSpecObserved === null
|
|
1186
|
+
? null
|
|
1187
|
+
: `${row.declaredSpecObserved} (${row.declaredSpecMatchesManifest ? t.declaredMatches : t.declaredDiffers})`,
|
|
1188
|
+
}),
|
|
1189
|
+
h(Field, { label: t.registry, value: row.source?.registry ?? `${t.unknown} — ${row.source?.registryReason ?? t.registryUnknown}` }),
|
|
1190
|
+
h(Field, {
|
|
1191
|
+
// The badge says "unknown" for an entry the loader never had; the
|
|
1192
|
+
// sentence has to say why, or the user reads it as broken.
|
|
1193
|
+
label: t.colLoad,
|
|
1194
|
+
value: loadDetail(row, t) === null ? loadLabel(row, t) : `${loadLabel(row, t)} — ${loadDetail(row, t)}`,
|
|
1195
|
+
}),
|
|
1196
|
+
row.loadError === null || row.loadError === undefined
|
|
1197
|
+
? null
|
|
1198
|
+
: h(Field, { label: t.errorLabel, value: row.loadError }),
|
|
1199
|
+
h(Field, {
|
|
1200
|
+
// The compatibility badge is a claim, so the row carries the
|
|
1201
|
+
// sentence behind it: which requirement failed, or why this
|
|
1202
|
+
// panel could not decide.
|
|
1203
|
+
label: t.colCompat,
|
|
1204
|
+
value: compatDetail(row, t),
|
|
1205
|
+
}),
|
|
1206
|
+
row.updateRefusal === null
|
|
1207
|
+
? null
|
|
1208
|
+
: h(Field, { label: t.readOnly, value: refusalLabel(row.updateRefusal, t) }),
|
|
1209
|
+
|
|
1210
|
+
h('div', { style: { marginTop: 10 } }, h('div', { style: { fontSize: 12, fontWeight: 600 } }, t.snapshots),
|
|
1211
|
+
h(SnapshotList, {
|
|
1212
|
+
t,
|
|
1213
|
+
language,
|
|
1214
|
+
snapshots: row.snapshots ?? [],
|
|
1215
|
+
installed: row.installedVersion,
|
|
1216
|
+
busy: restoreBusy ? 'x' : null,
|
|
1217
|
+
onRestore: (snapshot) => setPendingRestore(snapshot),
|
|
1218
|
+
}),
|
|
1219
|
+
),
|
|
1220
|
+
|
|
1221
|
+
versionsError === null ? null : h(Notice, { tone: 'fail', title: t.networkFailed }, describeError(versionsError, t)),
|
|
1222
|
+
h(VersionPicker, {
|
|
1223
|
+
t,
|
|
1224
|
+
language,
|
|
1225
|
+
data: versions,
|
|
1226
|
+
installed: row.installedVersion,
|
|
1227
|
+
busyVersion: updateBusy ? pendingUpdate?.version ?? null : null,
|
|
1228
|
+
onPick: (item) => setPendingUpdate({ version: item.version, prerelease: item.prerelease }),
|
|
1229
|
+
}),
|
|
1230
|
+
|
|
1231
|
+
pendingUpdate === null
|
|
1232
|
+
? null
|
|
1233
|
+
: h(ConfirmBar, {
|
|
1234
|
+
t,
|
|
1235
|
+
title: t.confirmTitle,
|
|
1236
|
+
body: t.confirmBody(row.targetId, row.installedVersion ?? t.unknown, pendingUpdate.version),
|
|
1237
|
+
notes: t.confirmNotes,
|
|
1238
|
+
busy: updateBusy,
|
|
1239
|
+
onCancel: () => setPendingUpdate(null),
|
|
1240
|
+
onConfirm: runUpdate,
|
|
1241
|
+
}),
|
|
1242
|
+
|
|
1243
|
+
pendingRestore === null
|
|
1244
|
+
? null
|
|
1245
|
+
: h(ConfirmBar, {
|
|
1246
|
+
t,
|
|
1247
|
+
title: t.confirmTitle,
|
|
1248
|
+
body: t.restoreConfirm(pendingRestore.installedVersion),
|
|
1249
|
+
notes: null,
|
|
1250
|
+
busy: restoreBusy,
|
|
1251
|
+
onCancel: () => setPendingRestore(null),
|
|
1252
|
+
onConfirm: runRestore,
|
|
1253
|
+
}),
|
|
1254
|
+
|
|
1255
|
+
result === null
|
|
1256
|
+
? null
|
|
1257
|
+
: h(Notice, { tone: result.ok ? 'pass' : 'fail', title: result.message }, null),
|
|
1258
|
+
),
|
|
1259
|
+
)
|
|
1260
|
+
|
|
1261
|
+
return h(React.Fragment, null, summaryRow, details)
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
/**
|
|
1265
|
+
* Turn a failure into one sentence a person can act on.
|
|
1266
|
+
*
|
|
1267
|
+
* @param {any} error
|
|
1268
|
+
* @param {any} t
|
|
1269
|
+
* @returns {string}
|
|
1270
|
+
*/
|
|
1271
|
+
function describeError(error, t) {
|
|
1272
|
+
if (error === null || error === undefined) return t.unknown
|
|
1273
|
+
if (error.kind === 'network') return t.networkFailed
|
|
1274
|
+
if (error.kind === 'http') return t.requestFailed(error.status)
|
|
1275
|
+
return String(error.message ?? error)
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
function OperationsList(props) {
|
|
1279
|
+
const { t, language, operations } = props
|
|
1280
|
+
if (operations.length === 0) {
|
|
1281
|
+
return h('div', { style: { fontSize: 12, opacity: 0.7 } }, t.noOperations)
|
|
1282
|
+
}
|
|
1283
|
+
const toneOf = (state) =>
|
|
1284
|
+
state === 'succeeded' ? 'pass' : state === 'recovery_required' ? 'fail' : state === 'failed' ? 'fail' : 'warn'
|
|
1285
|
+
return h(
|
|
1286
|
+
'ul',
|
|
1287
|
+
{ style: { listStyle: 'none', margin: 0, padding: 0 } },
|
|
1288
|
+
operations.map((operation) =>
|
|
1289
|
+
h(
|
|
1290
|
+
'li',
|
|
1291
|
+
{
|
|
1292
|
+
key: operation.id,
|
|
1293
|
+
style: { display: 'flex', gap: 8, alignItems: 'baseline', fontSize: 12, padding: '3px 0', borderTop: `1px solid ${COLORS.line}` },
|
|
1294
|
+
},
|
|
1295
|
+
h(Dot, { tone: toneOf(operation.state) }),
|
|
1296
|
+
h('span', { style: { fontWeight: 500 } }, operation.state),
|
|
1297
|
+
h('code', { style: { fontFamily: 'ui-monospace, monospace' } }, operation.targetId ?? '—'),
|
|
1298
|
+
operation.fromVersion === null
|
|
1299
|
+
? null
|
|
1300
|
+
: h('span', { style: { opacity: 0.7 } }, `${operation.fromVersion} → ${operation.toVersion ?? '?'}`),
|
|
1301
|
+
h('span', { style: { marginLeft: 'auto', opacity: 0.6 } }, formatTime(operation.startedAt, language)),
|
|
1302
|
+
),
|
|
1303
|
+
),
|
|
1304
|
+
)
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
function skillSourceLabel(source, t) {
|
|
1308
|
+
if (source === null || source === undefined) return t.unknown
|
|
1309
|
+
const known = t.skillSourceLabels?.[source]
|
|
1310
|
+
return known ?? t.skillSourceUnknown(source)
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
function skillGitLabel(skill, t) {
|
|
1314
|
+
const git = skill.git
|
|
1315
|
+
if (git === null || git === undefined) return t.skillNoGit
|
|
1316
|
+
if (git.managed !== true) return t.skillNoGit
|
|
1317
|
+
const parts = []
|
|
1318
|
+
if (git.revision) parts.push(git.revision)
|
|
1319
|
+
if (git.dirty === true) parts.push(t.skillDirty(git.changes ?? 0))
|
|
1320
|
+
else if (git.dirty === false) parts.push(t.skillClean)
|
|
1321
|
+
return parts.length === 0 ? t.skillNoGit : parts.join(' · ')
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
/**
|
|
1325
|
+
* One stored snapshot as a row the user can act on: preview it, then restore
|
|
1326
|
+
* it. The preview runs before the confirmation bar so a refusal is read while
|
|
1327
|
+
* choosing, not after committing.
|
|
1328
|
+
*/
|
|
1329
|
+
function SkillSnapshotList(props) {
|
|
1330
|
+
const { skill, t, language, onTake } = props
|
|
1331
|
+
const snapshots = skill.snapshots ?? []
|
|
1332
|
+
const [openFile, setOpenFile] = useState(null)
|
|
1333
|
+
const [preview, setPreview] = useState(null)
|
|
1334
|
+
const [previewError, setPreviewError] = useState(null)
|
|
1335
|
+
const [busy, setBusy] = useState(false)
|
|
1336
|
+
const [done, setDone] = useState(null)
|
|
1337
|
+
const refusal = skill.restoreRefusal ?? null
|
|
1338
|
+
|
|
1339
|
+
if (snapshots.length === 0) return h('div', { style: { fontSize: 11, opacity: 0.65 } }, t.skillNoSnapshots)
|
|
1340
|
+
|
|
1341
|
+
const openPreview = async (snapshot) => {
|
|
1342
|
+
setOpenFile(snapshot.file)
|
|
1343
|
+
setPreview(null)
|
|
1344
|
+
setPreviewError(null)
|
|
1345
|
+
setDone(null)
|
|
1346
|
+
try {
|
|
1347
|
+
const result = await request(
|
|
1348
|
+
`/skills/restore-preview?name=${encodeURIComponent(skill.name)}&file=${encodeURIComponent(snapshot.file)}`,
|
|
1349
|
+
)
|
|
1350
|
+
setPreview(result)
|
|
1351
|
+
} catch (failure) {
|
|
1352
|
+
setPreviewError(describeError(failure, t))
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
const runRestore = async (snapshot) => {
|
|
1357
|
+
setBusy(true)
|
|
1358
|
+
setPreviewError(null)
|
|
1359
|
+
try {
|
|
1360
|
+
const result = await request('/skills/restore', {
|
|
1361
|
+
method: 'POST',
|
|
1362
|
+
body: { name: skill.name, file: snapshot.file, confirm: true },
|
|
1363
|
+
})
|
|
1364
|
+
setDone(t.skillRestoreDone(formatTime(result.restoredTo, language)))
|
|
1365
|
+
setOpenFile(null)
|
|
1366
|
+
setPreview(null)
|
|
1367
|
+
if (typeof onTake === 'function') onTake()
|
|
1368
|
+
} catch (failure) {
|
|
1369
|
+
setPreviewError(describeError(failure, t))
|
|
1370
|
+
} finally {
|
|
1371
|
+
setBusy(false)
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1375
|
+
const describe = (reason) =>
|
|
1376
|
+
t.skillRestoreRefusals[String(reason)] ?? String(reason ?? '')
|
|
1377
|
+
|
|
1378
|
+
return h(
|
|
1379
|
+
'div',
|
|
1380
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 4, marginTop: 2 } },
|
|
1381
|
+
snapshots.slice(0, 5).map((snapshot) =>
|
|
1382
|
+
h(
|
|
1383
|
+
'div',
|
|
1384
|
+
{ key: snapshot.file, style: { display: 'flex', gap: 6, alignItems: 'center', flexWrap: 'wrap' } },
|
|
1385
|
+
h(
|
|
1386
|
+
'span',
|
|
1387
|
+
{ style: { fontSize: 11.5, opacity: 0.8 } },
|
|
1388
|
+
formatTime(snapshot.takenAt, language),
|
|
1389
|
+
snapshot.reason === 'before-restore' ? h(Badge, null, t.skillUndoLabel) : null,
|
|
1390
|
+
snapshot.unreadable === true ? h(Badge, null, t.snapshotUnreadable) : null,
|
|
1391
|
+
),
|
|
1392
|
+
snapshot.unreadable === true || snapshot.digest === null
|
|
1393
|
+
? null
|
|
1394
|
+
: h(
|
|
1395
|
+
Button,
|
|
1396
|
+
{
|
|
1397
|
+
onClick: () => (openFile === snapshot.file ? setOpenFile(null) : openPreview(snapshot)),
|
|
1398
|
+
disabled: refusal !== null || busy,
|
|
1399
|
+
title: refusal === null ? undefined : describe(refusal),
|
|
1400
|
+
small: true,
|
|
1401
|
+
},
|
|
1402
|
+
openFile === snapshot.file ? t.collapse : t.skillRestore,
|
|
1403
|
+
),
|
|
1404
|
+
),
|
|
1405
|
+
),
|
|
1406
|
+
done === null ? null : h('div', { style: { fontSize: 11.5 } }, done),
|
|
1407
|
+
previewError === null
|
|
1408
|
+
? null
|
|
1409
|
+
: h('div', { role: 'alert', style: { fontSize: 11.5 } }, previewError),
|
|
1410
|
+
openFile === null
|
|
1411
|
+
? null
|
|
1412
|
+
: preview === null
|
|
1413
|
+
? h('div', { style: { fontSize: 11.5, opacity: 0.7 } }, t.loading)
|
|
1414
|
+
: preview.ok !== true
|
|
1415
|
+
? h(
|
|
1416
|
+
'div',
|
|
1417
|
+
{ role: 'alert', style: { fontSize: 11.5 } },
|
|
1418
|
+
t.skillRestorePreviewFailed(describe(preview.reason)),
|
|
1419
|
+
)
|
|
1420
|
+
: h(
|
|
1421
|
+
'div',
|
|
1422
|
+
{ style: { marginTop: 2 } },
|
|
1423
|
+
h(
|
|
1424
|
+
'div',
|
|
1425
|
+
{ style: { fontSize: 11.5, opacity: 0.8 } },
|
|
1426
|
+
preview.detail?.sameFiles === true ? t.skillRestoreSameFiles : t.skillRestoreMoved,
|
|
1427
|
+
),
|
|
1428
|
+
h(ConfirmBar, {
|
|
1429
|
+
t,
|
|
1430
|
+
title: t.skillRestoreConfirm,
|
|
1431
|
+
body: t.skillRestoreBody(
|
|
1432
|
+
skill.name,
|
|
1433
|
+
formatTime(preview.detail?.takenAt ?? null, language),
|
|
1434
|
+
),
|
|
1435
|
+
notes: t.skillRestoreNotes,
|
|
1436
|
+
busy,
|
|
1437
|
+
confirmLabel: t.skillRestore,
|
|
1438
|
+
onCancel: () => setOpenFile(null),
|
|
1439
|
+
onConfirm: () => runRestore(snapshots.find((entry) => entry.file === openFile)),
|
|
1440
|
+
}),
|
|
1441
|
+
),
|
|
1442
|
+
)
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
function SkillRow(props) {
|
|
1446
|
+
const { skill, t, language, onTake } = props
|
|
1447
|
+
const [pending, setPending] = useState(false)
|
|
1448
|
+
const [message, setMessage] = useState(null)
|
|
1449
|
+
const [error, setError] = useState(null)
|
|
1450
|
+
const [expanded, setExpanded] = useState(false)
|
|
1451
|
+
const snapshots = skill.snapshots ?? []
|
|
1452
|
+
const refusal = skill.restoreRefusal ?? null
|
|
1453
|
+
|
|
1454
|
+
const runSnapshot = async () => {
|
|
1455
|
+
setPending(true)
|
|
1456
|
+
setError(null)
|
|
1457
|
+
setMessage(null)
|
|
1458
|
+
try {
|
|
1459
|
+
const result = await request('/skills/snapshot', {
|
|
1460
|
+
method: 'POST',
|
|
1461
|
+
body: { name: skill.name, confirm: true },
|
|
1462
|
+
})
|
|
1463
|
+
const digest = String(result.snapshot?.digest ?? '').slice(0, 12)
|
|
1464
|
+
setMessage(t.skillSnapshotDone(digest))
|
|
1465
|
+
if (typeof onTake === 'function') onTake()
|
|
1466
|
+
} catch (failure) {
|
|
1467
|
+
setError(describeError(failure, t))
|
|
1468
|
+
} finally {
|
|
1469
|
+
setPending(false)
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
|
|
1473
|
+
return h(
|
|
1474
|
+
'tr',
|
|
1475
|
+
{ style: { borderTop: `1px solid ${COLORS.line}`, verticalAlign: 'top' } },
|
|
1476
|
+
h(
|
|
1477
|
+
'td',
|
|
1478
|
+
{ style: { padding: '6px 8px' } },
|
|
1479
|
+
h('div', { style: { fontWeight: 500 } }, skill.name),
|
|
1480
|
+
skill.description === null
|
|
1481
|
+
? null
|
|
1482
|
+
: h(
|
|
1483
|
+
'div',
|
|
1484
|
+
{ style: { fontSize: 11, opacity: 0.65, maxWidth: 520, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } },
|
|
1485
|
+
skill.description,
|
|
1486
|
+
),
|
|
1487
|
+
message === null ? null : h('div', { style: { fontSize: 11, marginTop: 2 } }, message),
|
|
1488
|
+
error === null ? null : h('div', { role: 'alert', style: { fontSize: 11, marginTop: 2 } }, error),
|
|
1489
|
+
expanded === true
|
|
1490
|
+
? h(SkillSnapshotList, { skill, t, language, onTake })
|
|
1491
|
+
: null,
|
|
1492
|
+
),
|
|
1493
|
+
h('td', { style: { padding: '6px 8px', fontSize: 12 } }, skillSourceLabel(skill.source, t)),
|
|
1494
|
+
h(
|
|
1495
|
+
'td',
|
|
1496
|
+
{ style: { padding: '6px 8px', fontSize: 12, whiteSpace: 'nowrap' } },
|
|
1497
|
+
skill.fileCount === null ? '—' : String(skill.fileCount),
|
|
1498
|
+
skill.fileCountTruncated === true ? h(Badge, null, t.skillFilesTruncated) : null,
|
|
1499
|
+
),
|
|
1500
|
+
h(
|
|
1501
|
+
'td',
|
|
1502
|
+
{ style: { padding: '6px 8px', fontSize: 12, whiteSpace: 'nowrap' } },
|
|
1503
|
+
skillGitLabel(skill, t),
|
|
1504
|
+
),
|
|
1505
|
+
h(
|
|
1506
|
+
'td',
|
|
1507
|
+
{ style: { padding: '6px 8px', fontSize: 12, whiteSpace: 'nowrap' } },
|
|
1508
|
+
snapshots.length === 0
|
|
1509
|
+
? '—'
|
|
1510
|
+
: h(
|
|
1511
|
+
Button,
|
|
1512
|
+
{ onClick: () => setExpanded(!expanded), small: true },
|
|
1513
|
+
t.skillSnapshotCount(snapshots.length),
|
|
1514
|
+
expanded === true ? ' ▲' : ' ▼',
|
|
1515
|
+
),
|
|
1516
|
+
snapshots.length === 0
|
|
1517
|
+
? null
|
|
1518
|
+
: h(
|
|
1519
|
+
'div',
|
|
1520
|
+
{ style: { fontSize: 11, opacity: 0.65 } },
|
|
1521
|
+
formatTime(snapshots[0].takenAt, language),
|
|
1522
|
+
),
|
|
1523
|
+
),
|
|
1524
|
+
h(
|
|
1525
|
+
'td',
|
|
1526
|
+
{ style: { padding: '6px 8px', whiteSpace: 'nowrap' } },
|
|
1527
|
+
h(
|
|
1528
|
+
Button,
|
|
1529
|
+
{
|
|
1530
|
+
onClick: runSnapshot,
|
|
1531
|
+
disabled: pending === true || skill.directory === null,
|
|
1532
|
+
title: skill.directory === null ? t.skillNoDirectory : refusal === null ? undefined : t.skillRestoreRefusals[refusal] ?? refusal,
|
|
1533
|
+
},
|
|
1534
|
+
pending ? t.refreshing : t.skillSnapshot,
|
|
1535
|
+
),
|
|
1536
|
+
),
|
|
1537
|
+
)
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1540
|
+
function gitRefusalLabel(reason, t) {
|
|
1541
|
+
if (reason === null || reason === undefined) return ''
|
|
1542
|
+
return t.gitGitRefusals[String(reason)] ?? String(reason)
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1545
|
+
/**
|
|
1546
|
+
* A refusal from the Git half arrives as an HTTP error with a reason code in
|
|
1547
|
+
* the body. Showing "HTTP 409" would hide the only part the reader can act
|
|
1548
|
+
* on, so the code is translated first and the generic text is the fallback.
|
|
1549
|
+
*/
|
|
1550
|
+
function describeGitFailure(error, t) {
|
|
1551
|
+
const code = error?.body?.error
|
|
1552
|
+
if (typeof code === 'string' && t.gitGitRefusals[code] !== undefined) {
|
|
1553
|
+
return t.gitGitRefusals[code]
|
|
1554
|
+
}
|
|
1555
|
+
return describeError(error, t)
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
/**
|
|
1559
|
+
* The form that records where a Skill comes from.
|
|
1560
|
+
*
|
|
1561
|
+
* Registering writes one line to a registry file. It deliberately does not
|
|
1562
|
+
* download anything: a claim about intent should not be able to destroy
|
|
1563
|
+
* content, so the files move only when the user asks for an update.
|
|
1564
|
+
*/
|
|
1565
|
+
function GitRegisterForm(props) {
|
|
1566
|
+
const { t, onRegistered } = props
|
|
1567
|
+
const [name, setName] = useState('')
|
|
1568
|
+
const [remote, setRemote] = useState('')
|
|
1569
|
+
const [subpath, setSubpath] = useState('')
|
|
1570
|
+
const [ref, setRef] = useState('')
|
|
1571
|
+
const [create, setCreate] = useState(false)
|
|
1572
|
+
const [busy, setBusy] = useState(false)
|
|
1573
|
+
const [error, setError] = useState(null)
|
|
1574
|
+
|
|
1575
|
+
const submit = async (event) => {
|
|
1576
|
+
if (event !== undefined && typeof event.preventDefault === 'function') event.preventDefault()
|
|
1577
|
+
if (name.trim() === '') {
|
|
1578
|
+
setError(t.gitNeedName)
|
|
1579
|
+
return
|
|
1580
|
+
}
|
|
1581
|
+
if (remote.trim() === '') {
|
|
1582
|
+
setError(t.gitNeedRemote)
|
|
1583
|
+
return
|
|
1584
|
+
}
|
|
1585
|
+
setBusy(true)
|
|
1586
|
+
setError(null)
|
|
1587
|
+
try {
|
|
1588
|
+
await request('/skills/git/register', {
|
|
1589
|
+
method: 'POST',
|
|
1590
|
+
body: {
|
|
1591
|
+
name: name.trim(),
|
|
1592
|
+
remote: remote.trim(),
|
|
1593
|
+
subpath: subpath.trim(),
|
|
1594
|
+
ref: ref.trim(),
|
|
1595
|
+
create,
|
|
1596
|
+
confirm: true,
|
|
1597
|
+
},
|
|
1598
|
+
})
|
|
1599
|
+
setName('')
|
|
1600
|
+
setRemote('')
|
|
1601
|
+
setSubpath('')
|
|
1602
|
+
setRef('')
|
|
1603
|
+
setCreate(false)
|
|
1604
|
+
if (typeof onRegistered === 'function') onRegistered()
|
|
1605
|
+
} catch (failure) {
|
|
1606
|
+
setError(describeGitFailure(failure, t))
|
|
1607
|
+
} finally {
|
|
1608
|
+
setBusy(false)
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1612
|
+
const input = (value, onChange, placeholder) =>
|
|
1613
|
+
h('input', {
|
|
1614
|
+
type: 'text',
|
|
1615
|
+
value,
|
|
1616
|
+
placeholder,
|
|
1617
|
+
'aria-label': placeholder,
|
|
1618
|
+
onChange: (event) => onChange(event.target.value),
|
|
1619
|
+
style: {
|
|
1620
|
+
font: 'inherit',
|
|
1621
|
+
fontSize: 12,
|
|
1622
|
+
padding: '3px 8px',
|
|
1623
|
+
borderRadius: 6,
|
|
1624
|
+
border: `1px solid ${COLORS.line}`,
|
|
1625
|
+
background: 'transparent',
|
|
1626
|
+
color: 'inherit',
|
|
1627
|
+
minWidth: 150,
|
|
1628
|
+
flex: '1 1 150px',
|
|
1629
|
+
},
|
|
1630
|
+
})
|
|
1631
|
+
|
|
1632
|
+
return h(
|
|
1633
|
+
'form',
|
|
1634
|
+
{ onSubmit: submit, style: { marginTop: 10 } },
|
|
1635
|
+
h('div', { style: { fontSize: 13, fontWeight: 600 } }, t.gitTitle),
|
|
1636
|
+
h('div', { style: { fontSize: 12, opacity: 0.7, marginTop: 2, maxWidth: 720 } }, t.gitSubtitle),
|
|
1637
|
+
h(
|
|
1638
|
+
'div',
|
|
1639
|
+
{ style: { display: 'flex', gap: 8, marginTop: 8, flexWrap: 'wrap', alignItems: 'center' } },
|
|
1640
|
+
input(name, setName, t.gitName),
|
|
1641
|
+
input(remote, setRemote, t.gitRemote),
|
|
1642
|
+
input(subpath, setSubpath, t.gitSubpath),
|
|
1643
|
+
input(ref, setRef, t.gitRef),
|
|
1644
|
+
h(Button, { onClick: submit, disabled: busy === true, primary: true }, busy === true ? t.gitRegistering : t.gitRegister),
|
|
1645
|
+
),
|
|
1646
|
+
h(
|
|
1647
|
+
'label',
|
|
1648
|
+
{ style: { display: 'flex', gap: 6, alignItems: 'center', fontSize: 11.5, marginTop: 6, opacity: 0.8 } },
|
|
1649
|
+
h('input', { type: 'checkbox', checked: create, onChange: (event) => setCreate(event.target.checked) }),
|
|
1650
|
+
t.gitCreate,
|
|
1651
|
+
h('span', { style: { opacity: 0.7 } }, `— ${t.gitCreateHint}`),
|
|
1652
|
+
),
|
|
1653
|
+
h('div', { style: { fontSize: 11.5, opacity: 0.65, marginTop: 4, maxWidth: 720 } }, t.gitRegisterNote),
|
|
1654
|
+
error === null ? null : h('div', { role: 'alert', style: { fontSize: 11.5, marginTop: 4 } }, error),
|
|
1655
|
+
)
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1658
|
+
/**
|
|
1659
|
+
* One registered Skill: where it comes from, what it is at, and the three
|
|
1660
|
+
* things a user may do — look, move forward, move back.
|
|
1661
|
+
*/
|
|
1662
|
+
function GitSkillRow(props) {
|
|
1663
|
+
const { row, t, language, onChanged } = props
|
|
1664
|
+
const [preview, setPreview] = useState(null)
|
|
1665
|
+
const [previewBusy, setPreviewBusy] = useState(false)
|
|
1666
|
+
const [pending, setPending] = useState(null)
|
|
1667
|
+
const [busyKind, setBusyKind] = useState(null)
|
|
1668
|
+
const [message, setMessage] = useState(null)
|
|
1669
|
+
const [error, setError] = useState(null)
|
|
1670
|
+
const [showHistory, setShowHistory] = useState(false)
|
|
1671
|
+
|
|
1672
|
+
const history = row.history ?? []
|
|
1673
|
+
const refusal = row.refusal ?? null
|
|
1674
|
+
const restoreRefusal = row.restoreRefusal ?? null
|
|
1675
|
+
|
|
1676
|
+
const runPreview = async () => {
|
|
1677
|
+
setPreviewBusy(true)
|
|
1678
|
+
setError(null)
|
|
1679
|
+
setMessage(null)
|
|
1680
|
+
try {
|
|
1681
|
+
const body = await request('/skills/git/preview', {
|
|
1682
|
+
method: 'POST',
|
|
1683
|
+
body: { name: row.name, confirm: true },
|
|
1684
|
+
})
|
|
1685
|
+
setPreview(body)
|
|
1686
|
+
if (body.ok !== true) setError(gitRefusalLabel(body.reason, t))
|
|
1687
|
+
return body
|
|
1688
|
+
} catch (failure) {
|
|
1689
|
+
setError(describeGitFailure(failure, t))
|
|
1690
|
+
return null
|
|
1691
|
+
} finally {
|
|
1692
|
+
setPreviewBusy(false)
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
const apply = async (kind, revision) => {
|
|
1697
|
+
setBusyKind(kind)
|
|
1698
|
+
setError(null)
|
|
1699
|
+
setMessage(null)
|
|
1700
|
+
try {
|
|
1701
|
+
const path = kind === 'update' ? '/skills/git/update' : '/skills/git/restore'
|
|
1702
|
+
const body = await request(path, {
|
|
1703
|
+
method: 'POST',
|
|
1704
|
+
body: revision === null ? { name: row.name, confirm: true } : { name: row.name, revision, confirm: true },
|
|
1705
|
+
})
|
|
1706
|
+
if (body.ok === true) {
|
|
1707
|
+
setMessage(
|
|
1708
|
+
kind === 'update'
|
|
1709
|
+
? t.gitUpdateDone(String(body.fromRevision ?? '').slice(0, 7), String(body.toRevision ?? '').slice(0, 7))
|
|
1710
|
+
: t.gitRestored(String(body.toRevision ?? '').slice(0, 7)),
|
|
1711
|
+
)
|
|
1712
|
+
} else if (body.error === 'already-at-revision') {
|
|
1713
|
+
setMessage(t.gitAlreadyAt)
|
|
1714
|
+
} else {
|
|
1715
|
+
setError(gitRefusalLabel(body.error, t))
|
|
1716
|
+
}
|
|
1717
|
+
setPending(null)
|
|
1718
|
+
setPreview(null)
|
|
1719
|
+
if (typeof onChanged === 'function') onChanged()
|
|
1720
|
+
} catch (failure) {
|
|
1721
|
+
setError(describeGitFailure(failure, t))
|
|
1722
|
+
setPending(null)
|
|
1723
|
+
} finally {
|
|
1724
|
+
setBusyKind(null)
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
|
|
1728
|
+
const remove = async () => {
|
|
1729
|
+
setBusyKind('remove')
|
|
1730
|
+
setError(null)
|
|
1731
|
+
setMessage(null)
|
|
1732
|
+
try {
|
|
1733
|
+
await request('/skills/git/remove', { method: 'POST', body: { name: row.name, confirm: true } })
|
|
1734
|
+
if (typeof onChanged === 'function') onChanged()
|
|
1735
|
+
} catch (failure) {
|
|
1736
|
+
setError(describeGitFailure(failure, t))
|
|
1737
|
+
} finally {
|
|
1738
|
+
setBusyKind(null)
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1742
|
+
const stateBadge =
|
|
1743
|
+
row.localModifications === true
|
|
1744
|
+
? h(Badge, null, t.gitLocalModifications)
|
|
1745
|
+
: row.inCheckout === true
|
|
1746
|
+
? h(Badge, null, t.gitInCheckout)
|
|
1747
|
+
: row.populated === false
|
|
1748
|
+
? h(Badge, null, t.gitNotPopulated)
|
|
1749
|
+
: h(Badge, null, t.gitPopulated)
|
|
1750
|
+
|
|
1751
|
+
const revisionLine = h(
|
|
1752
|
+
'div',
|
|
1753
|
+
{ style: { fontSize: 11.5, opacity: 0.75, marginTop: 2, wordBreak: 'break-all' } },
|
|
1754
|
+
`${t.gitRevisionCurrent}: `,
|
|
1755
|
+
h('code', { style: { fontFamily: 'ui-monospace, monospace' } }, String(row.revision ?? '').slice(0, 12) || '—'),
|
|
1756
|
+
row.revisionSubject === null || row.revisionSubject === undefined ? '' : ` · ${row.revisionSubject}`,
|
|
1757
|
+
)
|
|
1758
|
+
|
|
1759
|
+
const sourceLine = h(
|
|
1760
|
+
'div',
|
|
1761
|
+
{ style: { fontSize: 11, opacity: 0.65, marginTop: 2, wordBreak: 'break-all' } },
|
|
1762
|
+
`${row.remote}${row.subpath === '' ? '' : `#${row.subpath}`} · ${row.ref}`,
|
|
1763
|
+
row.registeredAt === null ? '' : ` · ${t.gitRegisteredAt(formatTime(row.registeredAt, language))}`,
|
|
1764
|
+
)
|
|
1765
|
+
|
|
1766
|
+
return h(
|
|
1767
|
+
'div',
|
|
1768
|
+
{ style: { borderTop: `1px solid ${COLORS.line}`, padding: '8px 0' } },
|
|
1769
|
+
h(
|
|
1770
|
+
'div',
|
|
1771
|
+
{ style: { display: 'flex', gap: 8, alignItems: 'baseline', flexWrap: 'wrap' } },
|
|
1772
|
+
h('span', { style: { fontWeight: 500 } }, row.name),
|
|
1773
|
+
stateBadge,
|
|
1774
|
+
refusal === null ? null : h(Badge, null, gitRefusalLabel(refusal, t)),
|
|
1775
|
+
),
|
|
1776
|
+
revisionLine,
|
|
1777
|
+
sourceLine,
|
|
1778
|
+
message === null ? null : h('div', { style: { fontSize: 11.5, marginTop: 3 } }, message),
|
|
1779
|
+
error === null ? null : h('div', { role: 'alert', style: { fontSize: 11.5, marginTop: 3 } }, error),
|
|
1780
|
+
h(
|
|
1781
|
+
'div',
|
|
1782
|
+
{ style: { display: 'flex', gap: 6, marginTop: 6, flexWrap: 'wrap' } },
|
|
1783
|
+
h(
|
|
1784
|
+
Button,
|
|
1785
|
+
{ onClick: runPreview, disabled: previewBusy === true || busyKind !== null, small: true },
|
|
1786
|
+
previewBusy === true ? t.gitPreviewing : t.gitPreview,
|
|
1787
|
+
),
|
|
1788
|
+
h(
|
|
1789
|
+
Button,
|
|
1790
|
+
{
|
|
1791
|
+
// The confirmation names the commit it will move to, so the preview
|
|
1792
|
+
// is fetched first and the bar only appears when there is something
|
|
1793
|
+
// to apply. The server re-checks before writing, so this is about
|
|
1794
|
+
// saying the right thing, not about trusting the client.
|
|
1795
|
+
onClick: async () => {
|
|
1796
|
+
const body = await runPreview()
|
|
1797
|
+
if (body?.ok === true && body.detail?.alreadyAtRevision !== true) {
|
|
1798
|
+
setPending({ kind: 'update' })
|
|
1799
|
+
}
|
|
1800
|
+
},
|
|
1801
|
+
disabled: busyKind !== null || refusal !== null,
|
|
1802
|
+
title: refusal === null ? undefined : gitRefusalLabel(refusal, t),
|
|
1803
|
+
small: true,
|
|
1804
|
+
},
|
|
1805
|
+
busyKind === 'update' ? t.gitUpdating : t.gitUpdate,
|
|
1806
|
+
),
|
|
1807
|
+
history.length === 0
|
|
1808
|
+
? null
|
|
1809
|
+
: h(
|
|
1810
|
+
Button,
|
|
1811
|
+
{ onClick: () => setShowHistory(!showHistory), small: true },
|
|
1812
|
+
`${t.gitHistory} (${history.length})`,
|
|
1813
|
+
showHistory === true ? ' ▲' : ' ▼',
|
|
1814
|
+
),
|
|
1815
|
+
h(
|
|
1816
|
+
Button,
|
|
1817
|
+
{ onClick: remove, disabled: busyKind !== null, small: true },
|
|
1818
|
+
busyKind === 'remove' ? t.gitRemoving : t.gitRemove,
|
|
1819
|
+
),
|
|
1820
|
+
),
|
|
1821
|
+
showHistory === true
|
|
1822
|
+
? h(
|
|
1823
|
+
'div',
|
|
1824
|
+
{ style: { marginTop: 6 } },
|
|
1825
|
+
history.map((item) =>
|
|
1826
|
+
h(
|
|
1827
|
+
'div',
|
|
1828
|
+
{
|
|
1829
|
+
key: item.revision,
|
|
1830
|
+
style: { display: 'flex', gap: 8, alignItems: 'baseline', fontSize: 11.5, padding: '2px 0' },
|
|
1831
|
+
},
|
|
1832
|
+
h('code', { style: { fontFamily: 'ui-monospace, monospace' } }, item.revision.slice(0, 7)),
|
|
1833
|
+
h('span', { style: { opacity: 0.75 } }, item.subject ?? ''),
|
|
1834
|
+
item.revision === row.revision ? h(Badge, null, t.gitRevisionCurrent) : null,
|
|
1835
|
+
h('span', { style: { opacity: 0.6 } }, formatTime(item.at, language)),
|
|
1836
|
+
item.revision === row.revision
|
|
1837
|
+
? null
|
|
1838
|
+
: h(
|
|
1839
|
+
'span',
|
|
1840
|
+
{ style: { marginLeft: 'auto' } },
|
|
1841
|
+
h(
|
|
1842
|
+
Button,
|
|
1843
|
+
{
|
|
1844
|
+
onClick: () => setPending({ kind: 'restore', revision: item.revision }),
|
|
1845
|
+
// A restore snapshots first and then replaces the tree,
|
|
1846
|
+
// so it stays available when the directory was edited
|
|
1847
|
+
// by hand -- that is exactly when it is needed. Its own
|
|
1848
|
+
// narrower refusal decides (see restoreRefusal).
|
|
1849
|
+
disabled: busyKind !== null || restoreRefusal !== null,
|
|
1850
|
+
title: restoreRefusal === null ? undefined : gitRefusalLabel(restoreRefusal, t),
|
|
1851
|
+
small: true,
|
|
1852
|
+
},
|
|
1853
|
+
t.gitRestoreTo,
|
|
1854
|
+
),
|
|
1855
|
+
),
|
|
1856
|
+
),
|
|
1857
|
+
),
|
|
1858
|
+
)
|
|
1859
|
+
: null,
|
|
1860
|
+
preview === null
|
|
1861
|
+
? null
|
|
1862
|
+
: preview.ok !== true
|
|
1863
|
+
? h('div', { role: 'alert', style: { fontSize: 11.5, marginTop: 4 } }, gitRefusalLabel(preview.reason, t))
|
|
1864
|
+
: h(
|
|
1865
|
+
'div',
|
|
1866
|
+
{ style: { marginTop: 4, fontSize: 11.5 } },
|
|
1867
|
+
h(
|
|
1868
|
+
'div',
|
|
1869
|
+
{ style: { opacity: 0.8 } },
|
|
1870
|
+
preview.detail?.alreadyAtRevision === true
|
|
1871
|
+
? t.gitAlreadyAt
|
|
1872
|
+
: preview.detail?.changeCount === 0
|
|
1873
|
+
? t.gitNoChanges
|
|
1874
|
+
: t.gitChanges(preview.detail?.changeCount ?? 0),
|
|
1875
|
+
),
|
|
1876
|
+
(preview.detail?.changes ?? []).slice(0, 12).map((change) =>
|
|
1877
|
+
h(
|
|
1878
|
+
'div',
|
|
1879
|
+
{ key: `${change.status} ${change.path}`, style: { display: 'flex', gap: 6, opacity: 0.75 } },
|
|
1880
|
+
h('span', { style: { fontFamily: 'ui-monospace, monospace', minWidth: 18 } }, change.status),
|
|
1881
|
+
h('span', { style: { wordBreak: 'break-all' } }, change.path),
|
|
1882
|
+
),
|
|
1883
|
+
),
|
|
1884
|
+
),
|
|
1885
|
+
pending === null
|
|
1886
|
+
? null
|
|
1887
|
+
: h(ConfirmBar, {
|
|
1888
|
+
t,
|
|
1889
|
+
title: pending.kind === 'update' ? t.gitUpdateConfirm : t.gitRestoreConfirm,
|
|
1890
|
+
body:
|
|
1891
|
+
pending.kind === 'update'
|
|
1892
|
+
? t.gitUpdateBody(
|
|
1893
|
+
row.name,
|
|
1894
|
+
String(preview?.detail?.from?.revision ?? row.revision ?? '').slice(0, 7),
|
|
1895
|
+
String(preview?.detail?.to?.revision ?? '').slice(0, 7) || '—',
|
|
1896
|
+
)
|
|
1897
|
+
: t.gitRestoreBody(row.name, pending.revision.slice(0, 7)),
|
|
1898
|
+
notes: pending.kind === 'update' ? t.gitUpdateNotes : [t.gitUndoSnapshot],
|
|
1899
|
+
busy: busyKind !== null,
|
|
1900
|
+
confirmLabel: pending.kind === 'update' ? t.gitUpdate : t.gitRestoreTo,
|
|
1901
|
+
onCancel: () => setPending(null),
|
|
1902
|
+
onConfirm: () => apply(pending.kind, pending.revision ?? null),
|
|
1903
|
+
}),
|
|
1904
|
+
)
|
|
1905
|
+
}
|
|
1906
|
+
|
|
1907
|
+
/**
|
|
1908
|
+
* The Git half of the Skills tab.
|
|
1909
|
+
*
|
|
1910
|
+
* Kept beside the catalog table rather than inside a row because a
|
|
1911
|
+
* registration is about a source, not about a directory the host happened to
|
|
1912
|
+
* scan: the host may not know the Skill yet at all.
|
|
1913
|
+
*/
|
|
1914
|
+
function GitSkillsView(props) {
|
|
1915
|
+
const { t, language, rows, onChanged } = props
|
|
1916
|
+
return h(
|
|
1917
|
+
'div',
|
|
1918
|
+
{ style: { marginTop: 22, paddingTop: 12, borderTop: `1px solid ${COLORS.line}` } },
|
|
1919
|
+
h(GitRegisterForm, { t, onRegistered: onChanged }),
|
|
1920
|
+
rows.length === 0
|
|
1921
|
+
? h('div', { style: { fontSize: 12, opacity: 0.7, padding: '10px 0' } }, t.gitEmpty)
|
|
1922
|
+
: h(
|
|
1923
|
+
'div',
|
|
1924
|
+
{ style: { marginTop: 10 } },
|
|
1925
|
+
rows.map((row) => h(GitSkillRow, { key: row.name, row, t, language, onChanged })),
|
|
1926
|
+
),
|
|
1927
|
+
)
|
|
1928
|
+
}
|
|
1929
|
+
|
|
1930
|
+
function SkillsView(props) {
|
|
1931
|
+
const { t, language, state, onReload, loading } = props
|
|
1932
|
+
const data = state
|
|
1933
|
+
const skills = data?.skills ?? []
|
|
1934
|
+
const header = h(
|
|
1935
|
+
'div',
|
|
1936
|
+
{ style: { display: 'flex', gap: 12, alignItems: 'flex-start', flexWrap: 'wrap', marginTop: 4 } },
|
|
1937
|
+
h(
|
|
1938
|
+
'div',
|
|
1939
|
+
{ style: { flex: '1 1 320px', minWidth: 0 } },
|
|
1940
|
+
h('div', { style: { fontSize: 13, fontWeight: 600 } }, t.skillsTitle),
|
|
1941
|
+
h('div', { style: { fontSize: 12, opacity: 0.7, marginTop: 2 } }, t.skillsSubtitle),
|
|
1942
|
+
),
|
|
1943
|
+
h(Button, { onClick: onReload, disabled: loading === true }, loading === true ? t.refreshing : t.refresh),
|
|
1944
|
+
)
|
|
1945
|
+
|
|
1946
|
+
if (data === null) {
|
|
1947
|
+
return h('div', null, header, h('div', { style: { fontSize: 12, opacity: 0.7, marginTop: 10 } }, t.started))
|
|
1948
|
+
}
|
|
1949
|
+
if (data.available !== true) {
|
|
1950
|
+
return h(
|
|
1951
|
+
'div',
|
|
1952
|
+
null,
|
|
1953
|
+
header,
|
|
1954
|
+
h(Notice, { tone: 'warn', title: t.errorLabel }, data.reason ?? t.skillsUnavailable),
|
|
1955
|
+
// A Skill this plugin keeps in step with a Git tree does not need the
|
|
1956
|
+
// host's catalog to be written, so the form stays available here.
|
|
1957
|
+
h(GitSkillsView, { t, language, rows: data.git?.skills ?? [], onChanged: onReload }),
|
|
1958
|
+
)
|
|
1959
|
+
}
|
|
1960
|
+
|
|
1961
|
+
const table = h(
|
|
1962
|
+
'table',
|
|
1963
|
+
{ style: { width: '100%', borderCollapse: 'collapse', fontSize: 13, marginTop: 10 } },
|
|
1964
|
+
h(
|
|
1965
|
+
'thead',
|
|
1966
|
+
null,
|
|
1967
|
+
h(
|
|
1968
|
+
'tr',
|
|
1969
|
+
{ style: { textAlign: 'left', fontSize: 11, textTransform: 'uppercase', letterSpacing: 0.5, opacity: 0.6 } },
|
|
1970
|
+
h('th', { scope: 'col', style: { padding: '4px 8px', fontWeight: 500 } }, t.skillColName),
|
|
1971
|
+
h('th', { scope: 'col', style: { padding: '4px 8px', fontWeight: 500 } }, t.skillColSource),
|
|
1972
|
+
h('th', { scope: 'col', style: { padding: '4px 8px', fontWeight: 500 } }, t.skillColFiles),
|
|
1973
|
+
h('th', { scope: 'col', style: { padding: '4px 8px', fontWeight: 500 } }, t.skillColGit),
|
|
1974
|
+
h('th', { scope: 'col', style: { padding: '4px 8px', fontWeight: 500 } }, t.skillColSnapshots),
|
|
1975
|
+
h('th', { scope: 'col', style: { padding: '4px 8px', fontWeight: 500 } }, t.skillColActions),
|
|
1976
|
+
),
|
|
1977
|
+
),
|
|
1978
|
+
h(
|
|
1979
|
+
'tbody',
|
|
1980
|
+
null,
|
|
1981
|
+
skills.map((skill) => h(SkillRow, { key: skill.name, skill, t, language, onTake: onReload })),
|
|
1982
|
+
),
|
|
1983
|
+
)
|
|
1984
|
+
|
|
1985
|
+
return h(
|
|
1986
|
+
'div',
|
|
1987
|
+
null,
|
|
1988
|
+
header,
|
|
1989
|
+
data.complete === false ? h(Notice, { tone: 'warn', title: t.errorLabel }, t.skillsIncomplete) : null,
|
|
1990
|
+
data.provider === null ? null : h('div', { style: { fontSize: 11, opacity: 0.6, marginTop: 6 } }, t.skillsProvider(data.provider)),
|
|
1991
|
+
skills.length === 0
|
|
1992
|
+
? h('div', { style: { fontSize: 12, opacity: 0.7, padding: '12px 0' } }, t.skillsEmpty)
|
|
1993
|
+
: table,
|
|
1994
|
+
// The Git section is shown even when the catalog is empty: a Skill this
|
|
1995
|
+
// plugin manages may not have been scanned yet, and the form is the way
|
|
1996
|
+
// to stop relying on that.
|
|
1997
|
+
h(GitSkillsView, { t, language, rows: data.git?.skills ?? [], onChanged: onReload }),
|
|
1998
|
+
)
|
|
1999
|
+
}
|
|
2000
|
+
|
|
2001
|
+
function Panel() {
|
|
2002
|
+
const language = useMemo(pickLanguage, [])
|
|
2003
|
+
const t = TEXT[language]
|
|
2004
|
+
const [state, setState] = useState({ status: 'idle', data: null, error: null })
|
|
2005
|
+
const [filter, setFilter] = useState('all')
|
|
2006
|
+
const [query, setQuery] = useState('')
|
|
2007
|
+
const [expanded, setExpanded] = useState(null)
|
|
2008
|
+
const [tab, setTab] = useState('plugins')
|
|
2009
|
+
const [skills, setSkills] = useState({ status: 'idle', data: null, error: null })
|
|
2010
|
+
const abortRef = useRef(null)
|
|
2011
|
+
const skillsAbortRef = useRef(null)
|
|
2012
|
+
|
|
2013
|
+
const refresh = useCallback(async () => {
|
|
2014
|
+
abortRef.current?.abort()
|
|
2015
|
+
const controller = new AbortController()
|
|
2016
|
+
abortRef.current = controller
|
|
2017
|
+
setState((previous) => ({ ...previous, status: 'loading' }))
|
|
2018
|
+
try {
|
|
2019
|
+
const data = await request('/overview', { signal: controller.signal })
|
|
2020
|
+
setState({ status: 'ready', data, error: null })
|
|
2021
|
+
} catch (error) {
|
|
2022
|
+
if (error?.name === 'AbortError') return
|
|
2023
|
+
setState((previous) => ({
|
|
2024
|
+
status: 'failed',
|
|
2025
|
+
// Keep the previous document on screen: an old list is still useful,
|
|
2026
|
+
// and the banner says it may be out of date.
|
|
2027
|
+
data: previous.data,
|
|
2028
|
+
error,
|
|
2029
|
+
}))
|
|
2030
|
+
}
|
|
2031
|
+
}, [])
|
|
2032
|
+
|
|
2033
|
+
const loadSkills = useCallback(async () => {
|
|
2034
|
+
skillsAbortRef.current?.abort()
|
|
2035
|
+
const controller = new AbortController()
|
|
2036
|
+
skillsAbortRef.current = controller
|
|
2037
|
+
setSkills((previous) => ({ ...previous, status: 'loading' }))
|
|
2038
|
+
try {
|
|
2039
|
+
const data = await request('/skills', { signal: controller.signal })
|
|
2040
|
+
setSkills({ status: 'ready', data, error: null })
|
|
2041
|
+
} catch (error) {
|
|
2042
|
+
if (error?.name === 'AbortError') return
|
|
2043
|
+
setSkills((previous) => ({ status: 'failed', data: previous.data, error }))
|
|
2044
|
+
}
|
|
2045
|
+
}, [])
|
|
2046
|
+
|
|
2047
|
+
useEffect(() => {
|
|
2048
|
+
refresh()
|
|
2049
|
+
return () => abortRef.current?.abort()
|
|
2050
|
+
}, [refresh])
|
|
2051
|
+
|
|
2052
|
+
// The skills catalog is loaded when its tab is first opened: nothing on the
|
|
2053
|
+
// plugin list needs it, and reading it walks directories on the host.
|
|
2054
|
+
useEffect(() => {
|
|
2055
|
+
if (tab !== 'skills') return undefined
|
|
2056
|
+
if (skills.status !== 'idle') return undefined
|
|
2057
|
+
loadSkills()
|
|
2058
|
+
return undefined
|
|
2059
|
+
}, [tab, skills.status, loadSkills])
|
|
2060
|
+
|
|
2061
|
+
useEffect(() => () => skillsAbortRef.current?.abort(), [])
|
|
2062
|
+
|
|
2063
|
+
const rows = state.data?.plugins ?? []
|
|
2064
|
+
const visible = useMemo(() => {
|
|
2065
|
+
const needle = query.trim().toLowerCase()
|
|
2066
|
+
return rows.filter((row) => {
|
|
2067
|
+
if (filter === 'writable' && row.updateRefusal !== null) return false
|
|
2068
|
+
if (filter === 'readonly' && row.updateRefusal === null) return false
|
|
2069
|
+
if (needle !== '' && !String(row.targetId).toLowerCase().includes(needle)) return false
|
|
2070
|
+
return true
|
|
2071
|
+
})
|
|
2072
|
+
}, [rows, filter, query])
|
|
2073
|
+
|
|
2074
|
+
const header = h(
|
|
2075
|
+
'div',
|
|
2076
|
+
{ style: { display: 'flex', gap: 12, alignItems: 'flex-start', flexWrap: 'wrap' } },
|
|
2077
|
+
h(
|
|
2078
|
+
'div',
|
|
2079
|
+
{ style: { flex: '1 1 320px', minWidth: 0 } },
|
|
2080
|
+
h('div', { style: { fontSize: 15, fontWeight: 600 } }, t.title),
|
|
2081
|
+
h('div', { style: { fontSize: 12, opacity: 0.7, marginTop: 2 } }, t.subtitle),
|
|
2082
|
+
h(
|
|
2083
|
+
'div',
|
|
2084
|
+
{ style: { display: 'flex', gap: 14, marginTop: 6, fontSize: 12, flexWrap: 'wrap', opacity: 0.85 } },
|
|
2085
|
+
h('span', null, `${t.profile}: ${state.data?.profile?.id ?? t.notStarted}`),
|
|
2086
|
+
h(
|
|
2087
|
+
'span',
|
|
2088
|
+
null,
|
|
2089
|
+
`${t.host}: ${state.data?.host?.runtimeVersion ?? t.unknown}`,
|
|
2090
|
+
state.data?.host?.runtimeVersion && state.data?.host?.runtimeSource
|
|
2091
|
+
? ` (${t.runtimeSource(state.data.host.runtimeSource)})`
|
|
2092
|
+
: '',
|
|
2093
|
+
),
|
|
2094
|
+
h('span', null, `${t.observed}: ${state.data === null ? '—' : formatTime(state.data.observedAt, language)}`),
|
|
2095
|
+
),
|
|
2096
|
+
),
|
|
2097
|
+
h(
|
|
2098
|
+
'div',
|
|
2099
|
+
{ style: { display: 'flex', gap: 8, alignItems: 'center' } },
|
|
2100
|
+
h(Button, { onClick: refresh, disabled: state.status === 'loading' }, state.status === 'loading' ? t.refreshing : t.refresh),
|
|
2101
|
+
),
|
|
2102
|
+
)
|
|
2103
|
+
|
|
2104
|
+
const toolbar = h(
|
|
2105
|
+
'div',
|
|
2106
|
+
{ style: { display: 'flex', gap: 8, alignItems: 'center', margin: '10px 0 6px', flexWrap: 'wrap' } },
|
|
2107
|
+
h(
|
|
2108
|
+
'div',
|
|
2109
|
+
{ role: 'group', 'aria-label': t.filterAll, style: { display: 'inline-flex', gap: 4 } },
|
|
2110
|
+
[
|
|
2111
|
+
['all', t.filterAll],
|
|
2112
|
+
['writable', t.filterWritable],
|
|
2113
|
+
['readonly', t.filterReadOnly],
|
|
2114
|
+
].map(([key, label]) =>
|
|
2115
|
+
h(
|
|
2116
|
+
Button,
|
|
2117
|
+
{
|
|
2118
|
+
key,
|
|
2119
|
+
onClick: () => setFilter(key),
|
|
2120
|
+
primary: filter === key,
|
|
2121
|
+
},
|
|
2122
|
+
label,
|
|
2123
|
+
),
|
|
2124
|
+
),
|
|
2125
|
+
),
|
|
2126
|
+
h('input', {
|
|
2127
|
+
type: 'search',
|
|
2128
|
+
value: query,
|
|
2129
|
+
onChange: (event) => setQuery(event.target.value),
|
|
2130
|
+
placeholder: t.search,
|
|
2131
|
+
'aria-label': t.search,
|
|
2132
|
+
style: {
|
|
2133
|
+
font: 'inherit',
|
|
2134
|
+
fontSize: 12,
|
|
2135
|
+
padding: '3px 8px',
|
|
2136
|
+
borderRadius: 6,
|
|
2137
|
+
border: `1px solid ${COLORS.line}`,
|
|
2138
|
+
background: 'transparent',
|
|
2139
|
+
color: 'inherit',
|
|
2140
|
+
minWidth: 180,
|
|
2141
|
+
},
|
|
2142
|
+
}),
|
|
2143
|
+
state.data === null
|
|
2144
|
+
? null
|
|
2145
|
+
: h('span', { style: { fontSize: 12, opacity: 0.7 } }, t.counts(
|
|
2146
|
+
state.data.counts.total,
|
|
2147
|
+
state.data.counts.writable,
|
|
2148
|
+
state.data.counts.official,
|
|
2149
|
+
state.data.counts.unsatisfied ?? 0,
|
|
2150
|
+
state.data.counts.unknownCompatibility ?? 0,
|
|
2151
|
+
)),
|
|
2152
|
+
)
|
|
2153
|
+
|
|
2154
|
+
const table = h(
|
|
2155
|
+
'table',
|
|
2156
|
+
{ style: { width: '100%', borderCollapse: 'collapse', fontSize: 13 } },
|
|
2157
|
+
h(
|
|
2158
|
+
'thead',
|
|
2159
|
+
null,
|
|
2160
|
+
h(
|
|
2161
|
+
'tr',
|
|
2162
|
+
{ style: { textAlign: 'left', fontSize: 11, textTransform: 'uppercase', letterSpacing: 0.5, opacity: 0.6 } },
|
|
2163
|
+
h('th', { scope: 'col', style: { padding: '4px 8px', fontWeight: 500 } }, t.colName),
|
|
2164
|
+
h('th', { scope: 'col', style: { padding: '4px 8px', fontWeight: 500 } }, t.colVersion),
|
|
2165
|
+
h('th', { scope: 'col', style: { padding: '4px 8px', fontWeight: 500 } }, t.colSource),
|
|
2166
|
+
h('th', { scope: 'col', style: { padding: '4px 8px', fontWeight: 500 } }, t.colLoad),
|
|
2167
|
+
h('th', { scope: 'col', style: { padding: '4px 8px', fontWeight: 500 } }, t.colCompat),
|
|
2168
|
+
h('th', { scope: 'col', style: { padding: '4px 8px', fontWeight: 500 } }, t.colActions),
|
|
2169
|
+
),
|
|
2170
|
+
),
|
|
2171
|
+
h(
|
|
2172
|
+
'tbody',
|
|
2173
|
+
null,
|
|
2174
|
+
visible.map((row) =>
|
|
2175
|
+
h(Row, {
|
|
2176
|
+
key: row.targetId,
|
|
2177
|
+
row,
|
|
2178
|
+
t,
|
|
2179
|
+
language,
|
|
2180
|
+
expanded: expanded === row.targetId,
|
|
2181
|
+
onToggle: () => setExpanded((current) => (current === row.targetId ? null : row.targetId)),
|
|
2182
|
+
onRefresh: refresh,
|
|
2183
|
+
}),
|
|
2184
|
+
),
|
|
2185
|
+
),
|
|
2186
|
+
)
|
|
2187
|
+
|
|
2188
|
+
return h(
|
|
2189
|
+
'div',
|
|
2190
|
+
{ style: { padding: '18px 20px 32px', maxWidth: 1100, margin: '0 auto' } },
|
|
2191
|
+
header,
|
|
2192
|
+
state.error === null
|
|
2193
|
+
? null
|
|
2194
|
+
: h(
|
|
2195
|
+
Notice,
|
|
2196
|
+
{ tone: 'fail', title: state.data === null ? t.networkFailed : t.staleWarning },
|
|
2197
|
+
describeError(state.error, t),
|
|
2198
|
+
),
|
|
2199
|
+
state.data?.error === null || state.data?.error === undefined
|
|
2200
|
+
? null
|
|
2201
|
+
: h(Notice, { tone: 'fail', title: t.errorLabel }, state.data.error),
|
|
2202
|
+
state.data?.unresolved?.length
|
|
2203
|
+
? h(Notice, { tone: 'warn', title: t.unresolved }, state.data.unresolved.join(', '))
|
|
2204
|
+
: null,
|
|
2205
|
+
state.status === 'idle' ? h('div', { style: { fontSize: 12, opacity: 0.7 } }, t.started) : null,
|
|
2206
|
+
h(
|
|
2207
|
+
'div',
|
|
2208
|
+
{ style: { display: 'flex', gap: 6, marginTop: 12, borderBottom: `1px solid ${COLORS.line}` }, role: 'tablist' },
|
|
2209
|
+
...[
|
|
2210
|
+
['plugins', t.tabPlugins],
|
|
2211
|
+
['skills', t.tabSkills],
|
|
2212
|
+
].map(([key, label]) =>
|
|
2213
|
+
h(
|
|
2214
|
+
'button',
|
|
2215
|
+
{
|
|
2216
|
+
key,
|
|
2217
|
+
type: 'button',
|
|
2218
|
+
role: 'tab',
|
|
2219
|
+
'aria-selected': tab === key ? 'true' : 'false',
|
|
2220
|
+
onClick: () => setTab(key),
|
|
2221
|
+
style: {
|
|
2222
|
+
font: 'inherit',
|
|
2223
|
+
fontSize: 12,
|
|
2224
|
+
padding: '5px 10px',
|
|
2225
|
+
border: 'none',
|
|
2226
|
+
borderBottom: `2px solid ${tab === key ? 'currentColor' : 'transparent'}`,
|
|
2227
|
+
background: 'transparent',
|
|
2228
|
+
color: 'inherit',
|
|
2229
|
+
cursor: 'pointer',
|
|
2230
|
+
opacity: tab === key ? 1 : 0.65,
|
|
2231
|
+
},
|
|
2232
|
+
},
|
|
2233
|
+
label,
|
|
2234
|
+
),
|
|
2235
|
+
),
|
|
2236
|
+
),
|
|
2237
|
+
tab === 'skills'
|
|
2238
|
+
? h(SkillsView, {
|
|
2239
|
+
t,
|
|
2240
|
+
language,
|
|
2241
|
+
state: skills.data,
|
|
2242
|
+
loading: skills.status === 'loading',
|
|
2243
|
+
onReload: loadSkills,
|
|
2244
|
+
})
|
|
2245
|
+
: toolbar,
|
|
2246
|
+
tab !== 'plugins'
|
|
2247
|
+
? skills.error === null
|
|
2248
|
+
? null
|
|
2249
|
+
: h(Notice, { tone: 'fail', title: t.errorLabel }, describeError(skills.error, t))
|
|
2250
|
+
: state.data === null
|
|
2251
|
+
? null
|
|
2252
|
+
: visible.length === 0
|
|
2253
|
+
? h('div', { style: { fontSize: 12, opacity: 0.7, padding: '12px 0' } }, t.noNewerVersions)
|
|
2254
|
+
: table,
|
|
2255
|
+
tab !== 'plugins' || state.data === null
|
|
2256
|
+
? null
|
|
2257
|
+
: h(
|
|
2258
|
+
'div',
|
|
2259
|
+
{ style: { marginTop: 18 } },
|
|
2260
|
+
h('div', { style: { fontSize: 12, fontWeight: 600, marginBottom: 4 } }, t.operations),
|
|
2261
|
+
h(OperationsList, { t, language, operations: state.data.operations ?? [] }),
|
|
2262
|
+
),
|
|
2263
|
+
)
|
|
2264
|
+
}
|
|
2265
|
+
|
|
2266
|
+
// --------------------------------------------------------------- register
|
|
2267
|
+
|
|
2268
|
+
function Icon(props) {
|
|
2269
|
+
const size = typeof props?.size === 'number' ? props.size : 18
|
|
2270
|
+
const active = props?.active === true
|
|
2271
|
+
return h(
|
|
2272
|
+
'svg',
|
|
2273
|
+
{
|
|
2274
|
+
width: size,
|
|
2275
|
+
height: size,
|
|
2276
|
+
viewBox: '0 0 24 24',
|
|
2277
|
+
fill: 'none',
|
|
2278
|
+
stroke: 'currentColor',
|
|
2279
|
+
strokeWidth: active ? 2 : 1.7,
|
|
2280
|
+
strokeLinecap: 'round',
|
|
2281
|
+
strokeLinejoin: 'round',
|
|
2282
|
+
'aria-hidden': 'true',
|
|
2283
|
+
focusable: 'false',
|
|
2284
|
+
},
|
|
2285
|
+
// Three stacked bars: the shape of a list of versions, readable at 16px.
|
|
2286
|
+
h('path', { d: 'M4 6h16' }),
|
|
2287
|
+
h('path', { d: 'M4 12h16' }),
|
|
2288
|
+
h('path', { d: 'M4 18h10' }),
|
|
2289
|
+
h('circle', { cx: 19, cy: 18, r: 2.2 }),
|
|
2290
|
+
)
|
|
2291
|
+
}
|
|
2292
|
+
|
|
2293
|
+
/**
|
|
2294
|
+
* @param {any} ctx
|
|
2295
|
+
*/
|
|
2296
|
+
function apply(ctx) {
|
|
2297
|
+
let locale = null
|
|
2298
|
+
try {
|
|
2299
|
+
locale = ctx.get('locale')
|
|
2300
|
+
} catch {
|
|
2301
|
+
locale = null
|
|
2302
|
+
}
|
|
2303
|
+
|
|
2304
|
+
const label = () => {
|
|
2305
|
+
const language = pickLanguage()
|
|
2306
|
+
return TEXT[language].panel
|
|
2307
|
+
}
|
|
2308
|
+
|
|
2309
|
+
try {
|
|
2310
|
+
if (locale !== null && locale !== undefined && typeof locale.register === 'function') {
|
|
2311
|
+
// Registering the namespace is optional: the panel ships its own
|
|
2312
|
+
// strings, and this only lets the host re-render on language change.
|
|
2313
|
+
ctx.effect(
|
|
2314
|
+
() => locale.register(PANEL_ID, { zh: { panel: TEXT.zh.panel }, en: { panel: TEXT.en.panel } }),
|
|
2315
|
+
'dsh-version-manager: locale',
|
|
2316
|
+
)
|
|
2317
|
+
}
|
|
2318
|
+
} catch (error) {
|
|
2319
|
+
console.error('dsh-version-manager: locale registration failed', error)
|
|
2320
|
+
}
|
|
2321
|
+
|
|
2322
|
+
// Each slot is an independent extension point: the host only lets a plugin
|
|
2323
|
+
// register into a slot it has explicitly injected. Registering two slots
|
|
2324
|
+
// therefore needs two injections, not one injection and two registers.
|
|
2325
|
+
ctx.slots.inject('main', () => {
|
|
2326
|
+
const stopMain = ctx.slots.register(
|
|
2327
|
+
{
|
|
2328
|
+
name: 'main',
|
|
2329
|
+
key: PANEL_ID,
|
|
2330
|
+
inject: () => ({}),
|
|
2331
|
+
},
|
|
2332
|
+
Panel,
|
|
2333
|
+
)
|
|
2334
|
+
return () => {
|
|
2335
|
+
try {
|
|
2336
|
+
if (typeof stopMain === 'function') stopMain()
|
|
2337
|
+
} catch (error) {
|
|
2338
|
+
console.error('dsh-version-manager: panel cleanup failed', error)
|
|
2339
|
+
}
|
|
2340
|
+
}
|
|
2341
|
+
})
|
|
2342
|
+
|
|
2343
|
+
ctx.slots.inject('sidebar.panellist', () => {
|
|
2344
|
+
const stopIcon = ctx.slots.register(
|
|
2345
|
+
{
|
|
2346
|
+
name: 'sidebar.panellist',
|
|
2347
|
+
id: PANEL_ID,
|
|
2348
|
+
order: 60,
|
|
2349
|
+
label,
|
|
2350
|
+
},
|
|
2351
|
+
Icon,
|
|
2352
|
+
)
|
|
2353
|
+
return () => {
|
|
2354
|
+
try {
|
|
2355
|
+
if (typeof stopIcon === 'function') stopIcon()
|
|
2356
|
+
} catch (error) {
|
|
2357
|
+
console.error('dsh-version-manager: sidebar cleanup failed', error)
|
|
2358
|
+
}
|
|
2359
|
+
}
|
|
2360
|
+
})
|
|
2361
|
+
}
|
|
2362
|
+
|
|
2363
|
+
exports.apply = apply
|
|
2364
|
+
exports.inject = ['slots']
|
|
2365
|
+
return module.exports
|
|
2366
|
+
},
|
|
2367
|
+
})
|