@gluztm/dsh-guard 0.0.0-stage → 2.4.0
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 +674 -0
- package/README.en.md +48 -0
- package/README.md +51 -2
- package/assets/icon.png +0 -0
- package/bin/dsh-guard.mjs +66 -0
- package/cordis.patch.yml +3 -0
- package/lib/client.js +856 -0
- package/lib/index.mjs +283 -0
- package/lib/inspector.mjs +552 -0
- package/package.json +87 -4
package/lib/client.js
ADDED
|
@@ -0,0 +1,856 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client half of @gluztm/dsh-guard — Cross-platform read-only health & snapshot sidebar for DeepSeek Harness.
|
|
3
|
+
*
|
|
4
|
+
* Strictly zero-secret-leak: only renders structural bundle drift, cordis.patch.yml status,
|
|
5
|
+
* masked .credentials.yaml key readiness, pre-change snapshot metadata, and the local Windows DSHGuard bridge.
|
|
6
|
+
*/
|
|
7
|
+
window.__ModuleLoader__.load({
|
|
8
|
+
id: '@gluztm/dsh-guard',
|
|
9
|
+
factory(require) {
|
|
10
|
+
const React = require('react')
|
|
11
|
+
const h = React.createElement
|
|
12
|
+
|
|
13
|
+
const SIDE_ID = 'dsh-guard'
|
|
14
|
+
const API_BASE = 'api/dsh-guard'
|
|
15
|
+
const STYLE_ID = 'dsh-guard-panel-styles'
|
|
16
|
+
const RELEASE_FALLBACK = 'https://github.com/gluztm/DSHGuard/releases/latest'
|
|
17
|
+
|
|
18
|
+
const COPY = {
|
|
19
|
+
zh: {
|
|
20
|
+
brand: 'DSH 守护壳',
|
|
21
|
+
subtitle: '双轨体检 · 脱敏对账 · 快照回望',
|
|
22
|
+
refresh: '重新体检',
|
|
23
|
+
refreshing: '体检中…',
|
|
24
|
+
langSwitch: 'EN',
|
|
25
|
+
healthy: '双轨配置健康',
|
|
26
|
+
unhealthy: (n) => `发现 ${n} 项异常`,
|
|
27
|
+
loading: '正在读取双轨配置文件与快照状态…',
|
|
28
|
+
retry: '重试',
|
|
29
|
+
profilesTitle: 'Web / 桌面双轨对账',
|
|
30
|
+
webTrack: 'Web 版',
|
|
31
|
+
desktopTrack: '桌面版',
|
|
32
|
+
missingDir: '未检测到该端配置目录',
|
|
33
|
+
bundlesLabel: '启用插件',
|
|
34
|
+
depsLabel: '已装依赖',
|
|
35
|
+
patchOk: (n) => (n > 0 ? `Patch 正常 · 禁用 ${n} 项` : 'Patch 结构正常'),
|
|
36
|
+
patchMissing: '未建 cordis.patch.yml',
|
|
37
|
+
patchErr: (e) => `Patch 异常:${e}`,
|
|
38
|
+
pkgErr: 'package.json 解析异常',
|
|
39
|
+
missingInDeps: '清单缺依赖',
|
|
40
|
+
unregisteredDeps: '未登记插件',
|
|
41
|
+
credsTitle: '凭据脱敏就绪度(零秘密读取)',
|
|
42
|
+
credReadyBadge: (nonEmpty, total) => `.credentials.yaml ${nonEmpty}/${total} 非空键`,
|
|
43
|
+
credMissingFile: '未创建 .credentials.yaml',
|
|
44
|
+
credNoRefs: 'cordis.patch.yml 暂未引用任何 apiKeyEnv 环境变量',
|
|
45
|
+
snapshotsTitle: '最近变更前快照',
|
|
46
|
+
snapshotsTotal: (t) => `共 ${t} 份`,
|
|
47
|
+
snapshotsEmpty: '暂无 DSHGuard 存档快照(仅展示桌面端变更前自动/手动快照)',
|
|
48
|
+
snapItems: (n) => `${n} 项`,
|
|
49
|
+
snapNoReason: '日常快照备份',
|
|
50
|
+
guardTitle: 'Windows 进程外守护壳联动',
|
|
51
|
+
openGuard: '唤起 DSHGuard 守护壳',
|
|
52
|
+
openingGuard: '正在唤起…',
|
|
53
|
+
guardReady: (p) => `本机已安装 DSHGuard:${p}`,
|
|
54
|
+
guardNonWin: (plat) => `当前运行环境为 ${plat},已开启跨平台只读体检;完整崩溃恢复与 CC Switch 导入工具运行于 Windows。`,
|
|
55
|
+
guardNotInstalled: '当前仅启用 DSH 内只读体检;需要进程外崩溃救援、快照回滚或 CC Switch 导入时,可安装 Windows 完整版。',
|
|
56
|
+
downloadRelease: '前往 GitHub Releases 下载 Windows 完整版',
|
|
57
|
+
issuesTitle: '诊断建议',
|
|
58
|
+
checkedAt: (t) => `最近体检:${t}`,
|
|
59
|
+
errorRecover: '守护壳面板渲染已自动保护恢复',
|
|
60
|
+
guideDesc: '双端配置体检 · 凭据键就绪状态 · 快照历史 · 唤起 DSHGuard',
|
|
61
|
+
},
|
|
62
|
+
en: {
|
|
63
|
+
brand: 'DSHGuard',
|
|
64
|
+
subtitle: 'Dual-Track Health · Masked Keys · Snapshots',
|
|
65
|
+
refresh: 'Re-check',
|
|
66
|
+
refreshing: 'Checking…',
|
|
67
|
+
langSwitch: '中',
|
|
68
|
+
healthy: 'Dual-Track Healthy',
|
|
69
|
+
unhealthy: (n) => `${n} Issue${n === 1 ? '' : 's'} Found`,
|
|
70
|
+
loading: 'Inspecting DSH profiles and snapshot history…',
|
|
71
|
+
retry: 'Retry',
|
|
72
|
+
profilesTitle: 'Web / Desktop Profile Alignment',
|
|
73
|
+
webTrack: 'Web Track',
|
|
74
|
+
desktopTrack: 'Desktop Track',
|
|
75
|
+
missingDir: 'Profile directory not found',
|
|
76
|
+
bundlesLabel: 'Bundles',
|
|
77
|
+
depsLabel: 'Dependencies',
|
|
78
|
+
patchOk: (n) => (n > 0 ? `Patch OK · ${n} disabled` : 'Patch OK'),
|
|
79
|
+
patchMissing: 'No cordis.patch.yml',
|
|
80
|
+
patchErr: (e) => `Patch error: ${e}`,
|
|
81
|
+
pkgErr: 'Invalid package.json',
|
|
82
|
+
missingInDeps: 'Missing in deps',
|
|
83
|
+
unregisteredDeps: 'Unregistered deps',
|
|
84
|
+
credsTitle: 'Masked Credential Readiness (Zero Secret Read)',
|
|
85
|
+
credReadyBadge: (nonEmpty, total) => `.credentials.yaml ${nonEmpty}/${total} non-empty keys`,
|
|
86
|
+
credMissingFile: '.credentials.yaml not found',
|
|
87
|
+
credNoRefs: 'No apiKeyEnv references found in cordis.patch.yml',
|
|
88
|
+
snapshotsTitle: 'Recent Pre-Change Snapshots',
|
|
89
|
+
snapshotsTotal: (t) => `${t} total`,
|
|
90
|
+
snapshotsEmpty: 'No DSHGuard snapshots found yet',
|
|
91
|
+
snapItems: (n) => `${n} items`,
|
|
92
|
+
snapNoReason: 'Checkpoint',
|
|
93
|
+
guardTitle: 'Windows Out-of-Band Supervisor',
|
|
94
|
+
openGuard: 'Launch DSHGuard App',
|
|
95
|
+
openingGuard: 'Launching…',
|
|
96
|
+
guardReady: (p) => `Installed locally: ${p}`,
|
|
97
|
+
guardNonWin: (plat) => `Running on ${plat} (cross-platform read-only health panel active). The full out-of-band crash supervisor & CC Switch importer runs on Windows.`,
|
|
98
|
+
guardNotInstalled: 'In-app read-only audit active. Install DSHGuard on Windows for out-of-band snapshot rollback & CC Switch import.',
|
|
99
|
+
downloadRelease: 'Download Windows Supervisor on GitHub Releases',
|
|
100
|
+
issuesTitle: 'Diagnostics',
|
|
101
|
+
checkedAt: (t) => `Last check: ${t}`,
|
|
102
|
+
errorRecover: 'Panel recovered by ErrorBoundary',
|
|
103
|
+
guideDesc: 'Web/Desktop drift check · Masked credential readiness · Snapshots · DSHGuard launcher',
|
|
104
|
+
},
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const CSS = `
|
|
108
|
+
.dshg-root {
|
|
109
|
+
--dshg-card: var(--dsw-alias-card-fill, var(--dsw-alias-bg-layer-1, rgba(128, 128, 136, 0.08)));
|
|
110
|
+
--dshg-card-hover: var(--dsw-alias-card-fill-hover, var(--dsw-alias-bg-layer-2, rgba(128, 128, 136, 0.14)));
|
|
111
|
+
--dshg-fill: var(--dsw-alias-fill-l1, var(--dsw-alias-bg-layer-2, rgba(120, 120, 128, 0.15)));
|
|
112
|
+
--dshg-border: var(--dsw-alias-border-l1, rgba(128, 128, 136, 0.17));
|
|
113
|
+
--dshg-border-strong: var(--dsw-alias-border-l2, rgba(128, 128, 136, 0.28));
|
|
114
|
+
--dshg-text: var(--dsw-alias-label-primary, #e4e4e7);
|
|
115
|
+
--dshg-text-2: var(--dsw-alias-label-secondary, rgba(142, 142, 147, 0.92));
|
|
116
|
+
--dshg-text-3: var(--dsw-alias-label-tertiary, rgba(142, 142, 147, 0.65));
|
|
117
|
+
--dshg-accent: var(--dsw-alias-brand-primary, #2563eb);
|
|
118
|
+
color: var(--dshg-text);
|
|
119
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
|
|
120
|
+
display: flex;
|
|
121
|
+
flex-direction: column;
|
|
122
|
+
gap: 10px;
|
|
123
|
+
padding: 12px;
|
|
124
|
+
height: 100%;
|
|
125
|
+
box-sizing: border-box;
|
|
126
|
+
overflow-y: auto;
|
|
127
|
+
}
|
|
128
|
+
.dshg-root[data-variant="main"] {
|
|
129
|
+
max-width: 780px;
|
|
130
|
+
margin: 0 auto;
|
|
131
|
+
padding: 20px 18px;
|
|
132
|
+
}
|
|
133
|
+
.dshg-card {
|
|
134
|
+
border: 1px solid var(--dshg-border);
|
|
135
|
+
background: var(--dshg-card);
|
|
136
|
+
border-radius: 12px;
|
|
137
|
+
padding: 11px 12px;
|
|
138
|
+
display: flex;
|
|
139
|
+
flex-direction: column;
|
|
140
|
+
gap: 8px;
|
|
141
|
+
}
|
|
142
|
+
.dshg-header {
|
|
143
|
+
display: flex;
|
|
144
|
+
align-items: center;
|
|
145
|
+
justify-content: space-between;
|
|
146
|
+
gap: 8px;
|
|
147
|
+
flex-wrap: wrap;
|
|
148
|
+
}
|
|
149
|
+
.dshg-brand {
|
|
150
|
+
display: flex;
|
|
151
|
+
align-items: center;
|
|
152
|
+
gap: 9px;
|
|
153
|
+
min-width: 0;
|
|
154
|
+
}
|
|
155
|
+
.dshg-logo-wrap {
|
|
156
|
+
width: 32px;
|
|
157
|
+
height: 32px;
|
|
158
|
+
border-radius: 9px;
|
|
159
|
+
display: inline-flex;
|
|
160
|
+
align-items: center;
|
|
161
|
+
justify-content: center;
|
|
162
|
+
background: linear-gradient(135deg, rgba(37, 99, 235, 0.18), rgba(14, 165, 233, 0.14));
|
|
163
|
+
border: 1px solid rgba(59, 130, 246, 0.34);
|
|
164
|
+
color: #3b82f6;
|
|
165
|
+
flex-shrink: 0;
|
|
166
|
+
}
|
|
167
|
+
.dshg-title {
|
|
168
|
+
font-size: 13.5px;
|
|
169
|
+
font-weight: 650;
|
|
170
|
+
line-height: 1.2;
|
|
171
|
+
letter-spacing: -0.01em;
|
|
172
|
+
}
|
|
173
|
+
.dshg-sub {
|
|
174
|
+
font-size: 11px;
|
|
175
|
+
color: var(--dshg-text-2);
|
|
176
|
+
margin-top: 2px;
|
|
177
|
+
}
|
|
178
|
+
.dshg-actions {
|
|
179
|
+
display: flex;
|
|
180
|
+
align-items: center;
|
|
181
|
+
gap: 6px;
|
|
182
|
+
flex-shrink: 0;
|
|
183
|
+
}
|
|
184
|
+
.dshg-btn {
|
|
185
|
+
display: inline-flex;
|
|
186
|
+
align-items: center;
|
|
187
|
+
justify-content: center;
|
|
188
|
+
gap: 5px;
|
|
189
|
+
height: 26px;
|
|
190
|
+
padding: 0 9px;
|
|
191
|
+
border-radius: 8px;
|
|
192
|
+
border: 1px solid var(--dshg-border);
|
|
193
|
+
background: var(--dshg-card);
|
|
194
|
+
color: var(--dshg-text);
|
|
195
|
+
font-size: 11.5px;
|
|
196
|
+
font-weight: 500;
|
|
197
|
+
cursor: pointer;
|
|
198
|
+
transition: background 0.15s ease, border-color 0.15s ease;
|
|
199
|
+
text-decoration: none;
|
|
200
|
+
box-sizing: border-box;
|
|
201
|
+
}
|
|
202
|
+
.dshg-btn:hover:not(:disabled) {
|
|
203
|
+
background: var(--dshg-card-hover);
|
|
204
|
+
border-color: var(--dshg-border-strong);
|
|
205
|
+
}
|
|
206
|
+
.dshg-btn:disabled {
|
|
207
|
+
opacity: 0.6;
|
|
208
|
+
cursor: default;
|
|
209
|
+
}
|
|
210
|
+
.dshg-btn-primary {
|
|
211
|
+
background: var(--dshg-accent);
|
|
212
|
+
border-color: transparent;
|
|
213
|
+
color: #ffffff;
|
|
214
|
+
height: 31px;
|
|
215
|
+
padding: 0 12px;
|
|
216
|
+
font-weight: 600;
|
|
217
|
+
width: 100%;
|
|
218
|
+
}
|
|
219
|
+
.dshg-btn-primary:hover:not(:disabled) {
|
|
220
|
+
background: var(--dshg-accent);
|
|
221
|
+
filter: brightness(1.08);
|
|
222
|
+
}
|
|
223
|
+
.dshg-badge {
|
|
224
|
+
display: inline-flex;
|
|
225
|
+
align-items: center;
|
|
226
|
+
gap: 5px;
|
|
227
|
+
padding: 3px 8px;
|
|
228
|
+
border-radius: 99px;
|
|
229
|
+
font-size: 11px;
|
|
230
|
+
font-weight: 600;
|
|
231
|
+
border: 1px solid transparent;
|
|
232
|
+
width: fit-content;
|
|
233
|
+
}
|
|
234
|
+
.dshg-badge[data-tone="ok"] {
|
|
235
|
+
background: rgba(34, 197, 94, 0.14);
|
|
236
|
+
border-color: rgba(34, 197, 94, 0.36);
|
|
237
|
+
color: #22c55e;
|
|
238
|
+
}
|
|
239
|
+
.dshg-badge[data-tone="warn"] {
|
|
240
|
+
background: rgba(245, 158, 11, 0.14);
|
|
241
|
+
border-color: rgba(245, 158, 11, 0.38);
|
|
242
|
+
color: #f59e0b;
|
|
243
|
+
}
|
|
244
|
+
.dshg-badge[data-tone="blue"] {
|
|
245
|
+
background: rgba(59, 130, 246, 0.14);
|
|
246
|
+
border-color: rgba(59, 130, 246, 0.36);
|
|
247
|
+
color: #3b82f6;
|
|
248
|
+
}
|
|
249
|
+
.dshg-badge[data-tone="muted"] {
|
|
250
|
+
background: var(--dshg-fill);
|
|
251
|
+
border-color: var(--dshg-border);
|
|
252
|
+
color: var(--dshg-text-2);
|
|
253
|
+
}
|
|
254
|
+
.dshg-sec-head {
|
|
255
|
+
display: flex;
|
|
256
|
+
align-items: center;
|
|
257
|
+
justify-content: space-between;
|
|
258
|
+
gap: 8px;
|
|
259
|
+
font-size: 11.5px;
|
|
260
|
+
font-weight: 600;
|
|
261
|
+
color: var(--dshg-text-2);
|
|
262
|
+
}
|
|
263
|
+
.dshg-profile-grid {
|
|
264
|
+
display: grid;
|
|
265
|
+
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
|
|
266
|
+
gap: 8px;
|
|
267
|
+
}
|
|
268
|
+
.dshg-subcard {
|
|
269
|
+
border: 1px solid var(--dshg-border);
|
|
270
|
+
border-radius: 9px;
|
|
271
|
+
padding: 9px 10px;
|
|
272
|
+
display: flex;
|
|
273
|
+
flex-direction: column;
|
|
274
|
+
gap: 6px;
|
|
275
|
+
background: rgba(128, 128, 136, 0.04);
|
|
276
|
+
}
|
|
277
|
+
.dshg-row {
|
|
278
|
+
display: flex;
|
|
279
|
+
align-items: center;
|
|
280
|
+
justify-content: space-between;
|
|
281
|
+
gap: 6px;
|
|
282
|
+
font-size: 11.5px;
|
|
283
|
+
}
|
|
284
|
+
.dshg-pills {
|
|
285
|
+
display: flex;
|
|
286
|
+
flex-wrap: wrap;
|
|
287
|
+
gap: 5px;
|
|
288
|
+
}
|
|
289
|
+
.dshg-pill {
|
|
290
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
291
|
+
font-size: 10.5px;
|
|
292
|
+
padding: 2px 7px;
|
|
293
|
+
border-radius: 6px;
|
|
294
|
+
border: 1px solid var(--dshg-border);
|
|
295
|
+
background: var(--dshg-fill);
|
|
296
|
+
color: var(--dshg-text);
|
|
297
|
+
word-break: break-all;
|
|
298
|
+
}
|
|
299
|
+
.dshg-pill[data-tone="ok"] {
|
|
300
|
+
background: rgba(34, 197, 94, 0.12);
|
|
301
|
+
border-color: rgba(34, 197, 94, 0.32);
|
|
302
|
+
color: #22c55e;
|
|
303
|
+
}
|
|
304
|
+
.dshg-pill[data-tone="warn"] {
|
|
305
|
+
background: rgba(245, 158, 11, 0.14);
|
|
306
|
+
border-color: rgba(245, 158, 11, 0.35);
|
|
307
|
+
color: #f59e0b;
|
|
308
|
+
}
|
|
309
|
+
.dshg-snap-list {
|
|
310
|
+
display: flex;
|
|
311
|
+
flex-direction: column;
|
|
312
|
+
gap: 6px;
|
|
313
|
+
}
|
|
314
|
+
.dshg-snap-item {
|
|
315
|
+
border: 1px solid var(--dshg-border);
|
|
316
|
+
border-radius: 8px;
|
|
317
|
+
padding: 7px 9px;
|
|
318
|
+
display: flex;
|
|
319
|
+
flex-direction: column;
|
|
320
|
+
gap: 3px;
|
|
321
|
+
background: rgba(128, 128, 136, 0.04);
|
|
322
|
+
}
|
|
323
|
+
.dshg-mono {
|
|
324
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
325
|
+
font-size: 11px;
|
|
326
|
+
word-break: break-all;
|
|
327
|
+
}
|
|
328
|
+
.dshg-notice {
|
|
329
|
+
padding: 8px 10px;
|
|
330
|
+
border-radius: 9px;
|
|
331
|
+
font-size: 11.5px;
|
|
332
|
+
border: 1px solid rgba(59, 130, 246, 0.35);
|
|
333
|
+
background: rgba(59, 130, 246, 0.12);
|
|
334
|
+
color: var(--dshg-text);
|
|
335
|
+
}
|
|
336
|
+
.dshg-error {
|
|
337
|
+
padding: 8px 10px;
|
|
338
|
+
border-radius: 9px;
|
|
339
|
+
font-size: 11.5px;
|
|
340
|
+
border: 1px solid rgba(239, 68, 68, 0.4);
|
|
341
|
+
background: rgba(239, 68, 68, 0.12);
|
|
342
|
+
color: #f87171;
|
|
343
|
+
}
|
|
344
|
+
`
|
|
345
|
+
|
|
346
|
+
function ensureStyles() {
|
|
347
|
+
if (typeof document === 'undefined' || !document.head) return
|
|
348
|
+
if (document.getElementById(STYLE_ID)) return
|
|
349
|
+
const el = document.createElement('style')
|
|
350
|
+
el.id = STYLE_ID
|
|
351
|
+
el.textContent = CSS
|
|
352
|
+
document.head.appendChild(el)
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const store = {
|
|
356
|
+
lang: 'zh',
|
|
357
|
+
loading: false,
|
|
358
|
+
launching: false,
|
|
359
|
+
error: '',
|
|
360
|
+
notice: '',
|
|
361
|
+
data: null,
|
|
362
|
+
checkedAt: 0,
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
const listeners = new Set()
|
|
366
|
+
|
|
367
|
+
function notify() {
|
|
368
|
+
for (const listener of listeners) {
|
|
369
|
+
try {
|
|
370
|
+
listener()
|
|
371
|
+
} catch {
|
|
372
|
+
// Ignore UI subscriber errors safely.
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function patch(next) {
|
|
378
|
+
Object.assign(store, next)
|
|
379
|
+
notify()
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function useStore() {
|
|
383
|
+
const [, bump] = React.useState(0)
|
|
384
|
+
React.useEffect(() => {
|
|
385
|
+
const fn = () => bump((n) => n + 1)
|
|
386
|
+
listeners.add(fn)
|
|
387
|
+
return () => listeners.delete(fn)
|
|
388
|
+
}, [])
|
|
389
|
+
return store
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
async function fetchOverview() {
|
|
393
|
+
if (store.loading || typeof fetch !== 'function') return
|
|
394
|
+
patch({ loading: true, error: '' })
|
|
395
|
+
try {
|
|
396
|
+
const res = await fetch(`${API_BASE}/overview`, {
|
|
397
|
+
cache: 'no-store',
|
|
398
|
+
credentials: 'same-origin',
|
|
399
|
+
headers: { accept: 'application/json' },
|
|
400
|
+
})
|
|
401
|
+
const json = await res.json()
|
|
402
|
+
if (!res.ok || !json || json.ok === false) {
|
|
403
|
+
throw new Error((json && json.error) || `HTTP ${res.status}`)
|
|
404
|
+
}
|
|
405
|
+
patch({
|
|
406
|
+
data: json,
|
|
407
|
+
checkedAt: json.checkedAt || Date.now(),
|
|
408
|
+
error: '',
|
|
409
|
+
})
|
|
410
|
+
} catch (err) {
|
|
411
|
+
patch({ error: err && err.message ? String(err.message) : 'Failed to inspect DSHGuard status' })
|
|
412
|
+
} finally {
|
|
413
|
+
patch({ loading: false })
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
async function launchDesktopGuard() {
|
|
418
|
+
if (store.launching || typeof fetch !== 'function') return
|
|
419
|
+
patch({ launching: true, notice: '', error: '' })
|
|
420
|
+
try {
|
|
421
|
+
const res = await fetch(`${API_BASE}/open`, {
|
|
422
|
+
method: 'POST',
|
|
423
|
+
cache: 'no-store',
|
|
424
|
+
credentials: 'same-origin',
|
|
425
|
+
headers: { accept: 'application/json' },
|
|
426
|
+
})
|
|
427
|
+
const json = await res.json()
|
|
428
|
+
if (!res.ok || !json || json.ok === false) {
|
|
429
|
+
throw new Error((json && json.error) || `HTTP ${res.status}`)
|
|
430
|
+
}
|
|
431
|
+
patch({ notice: json.message || 'DSHGuard action completed' })
|
|
432
|
+
} catch (err) {
|
|
433
|
+
patch({ error: err && err.message ? String(err.message) : 'Failed to launch DSHGuard' })
|
|
434
|
+
} finally {
|
|
435
|
+
patch({ launching: false })
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
function formatShortTime(value) {
|
|
440
|
+
if (!value) return ''
|
|
441
|
+
const d = new Date(value)
|
|
442
|
+
if (Number.isNaN(d.getTime())) return String(value)
|
|
443
|
+
const p = (n) => String(n).padStart(2, '0')
|
|
444
|
+
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/** Crisp Whale-Shield glyph rendered in currentColor for tabs & rail icons. */
|
|
448
|
+
function GuardIcon(props) {
|
|
449
|
+
const size = props && typeof props.size === 'number' && props.size > 0 ? props.size : 17
|
|
450
|
+
const active = Boolean(props && props.active)
|
|
451
|
+
return h(
|
|
452
|
+
'svg',
|
|
453
|
+
{
|
|
454
|
+
width: size,
|
|
455
|
+
height: size,
|
|
456
|
+
viewBox: '0 0 24 24',
|
|
457
|
+
fill: 'none',
|
|
458
|
+
stroke: 'currentColor',
|
|
459
|
+
strokeWidth: active ? 2.1 : 1.75,
|
|
460
|
+
strokeLinecap: 'round',
|
|
461
|
+
strokeLinejoin: 'round',
|
|
462
|
+
'aria-hidden': true,
|
|
463
|
+
focusable: false,
|
|
464
|
+
style: { display: 'block' },
|
|
465
|
+
},
|
|
466
|
+
h('path', { d: 'M12 2.8 4.8 5.8v5.7c0 4.6 3.1 8.3 7.2 9.7 4.1-1.4 7.2-5.1 7.2-9.7V5.8L12 2.8Z' }),
|
|
467
|
+
h('path', { d: 'M8.5 13c.8-2 2.5-3 4.3-2.6 1.5.3 2.5 1.3 3.2 2.2.8-.6 1.4-1.3 1.7-2.2' }),
|
|
468
|
+
h('circle', { cx: '11', cy: '12.6', r: '0.65', fill: 'currentColor' }),
|
|
469
|
+
)
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
class GuardErrorBoundary extends React.Component {
|
|
473
|
+
constructor(props) {
|
|
474
|
+
super(props)
|
|
475
|
+
this.state = { error: null }
|
|
476
|
+
}
|
|
477
|
+
static getDerivedStateFromError(error) {
|
|
478
|
+
return { error }
|
|
479
|
+
}
|
|
480
|
+
render() {
|
|
481
|
+
if (this.state.error) {
|
|
482
|
+
const t = COPY[store.lang] || COPY.zh
|
|
483
|
+
return h(
|
|
484
|
+
'div',
|
|
485
|
+
{ className: 'dshg-root' },
|
|
486
|
+
h(
|
|
487
|
+
'div',
|
|
488
|
+
{ className: 'dshg-card' },
|
|
489
|
+
h('div', { style: { fontWeight: 600, fontSize: 13 } }, t.errorRecover),
|
|
490
|
+
h(
|
|
491
|
+
'div',
|
|
492
|
+
{ style: { fontSize: 11.5, color: 'var(--dshg-text-2)' } },
|
|
493
|
+
String((this.state.error && this.state.error.message) || this.state.error),
|
|
494
|
+
),
|
|
495
|
+
h(
|
|
496
|
+
'button',
|
|
497
|
+
{
|
|
498
|
+
className: 'dshg-btn',
|
|
499
|
+
onClick: () => {
|
|
500
|
+
this.setState({ error: null })
|
|
501
|
+
void fetchOverview()
|
|
502
|
+
},
|
|
503
|
+
},
|
|
504
|
+
t.retry,
|
|
505
|
+
),
|
|
506
|
+
),
|
|
507
|
+
)
|
|
508
|
+
}
|
|
509
|
+
return this.props.children
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
function ProfileSubcard({ profile, t }) {
|
|
514
|
+
const isWeb = profile.target === 'web'
|
|
515
|
+
const trackName = isWeb ? t.webTrack : t.desktopTrack
|
|
516
|
+
const trackTone = isWeb ? 'blue' : 'ok'
|
|
517
|
+
|
|
518
|
+
if (!profile.exists) {
|
|
519
|
+
return h(
|
|
520
|
+
'div',
|
|
521
|
+
{ className: 'dshg-subcard' },
|
|
522
|
+
h(
|
|
523
|
+
'div',
|
|
524
|
+
{ className: 'dshg-row' },
|
|
525
|
+
h('span', { className: 'dshg-badge', 'data-tone': 'muted' }, trackName),
|
|
526
|
+
),
|
|
527
|
+
h('div', { style: { fontSize: 11, color: 'var(--dshg-text-2)' } }, t.missingDir),
|
|
528
|
+
)
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
const patch = profile.patch || {}
|
|
532
|
+
const patchText = !patch.exists
|
|
533
|
+
? t.patchMissing
|
|
534
|
+
: patch.syntaxOk
|
|
535
|
+
? t.patchOk(patch.disabledCount || 0)
|
|
536
|
+
: t.patchErr(patch.error || 'YAML')
|
|
537
|
+
const patchTone = patch.exists && !patch.syntaxOk ? 'warn' : 'ok'
|
|
538
|
+
|
|
539
|
+
return h(
|
|
540
|
+
'div',
|
|
541
|
+
{ className: 'dshg-subcard' },
|
|
542
|
+
h(
|
|
543
|
+
'div',
|
|
544
|
+
{ className: 'dshg-row' },
|
|
545
|
+
h('span', { className: 'dshg-badge', 'data-tone': trackTone }, trackName),
|
|
546
|
+
h(
|
|
547
|
+
'span',
|
|
548
|
+
{ style: { fontSize: 11, color: 'var(--dshg-text-2)' } },
|
|
549
|
+
`${t.bundlesLabel} ${profile.bundlesCount} / ${t.depsLabel} ${profile.dependenciesCount}`,
|
|
550
|
+
),
|
|
551
|
+
),
|
|
552
|
+
h('div', { className: 'dshg-badge', 'data-tone': patchTone }, patchText),
|
|
553
|
+
!profile.packageJsonOk
|
|
554
|
+
? h('div', { style: { fontSize: 11, color: '#f59e0b' } }, t.pkgErr)
|
|
555
|
+
: null,
|
|
556
|
+
Array.isArray(profile.missingInDeps) && profile.missingInDeps.length > 0
|
|
557
|
+
? h(
|
|
558
|
+
'div',
|
|
559
|
+
{ className: 'dshg-pills' },
|
|
560
|
+
h('span', { style: { fontSize: 10.5, color: '#f59e0b' } }, `${t.missingInDeps}:`),
|
|
561
|
+
...profile.missingInDeps.map((pkg) => h('span', { key: pkg, className: 'dshg-pill', 'data-tone': 'warn' }, pkg)),
|
|
562
|
+
)
|
|
563
|
+
: null,
|
|
564
|
+
Array.isArray(profile.unregisteredDeps) && profile.unregisteredDeps.length > 0
|
|
565
|
+
? h(
|
|
566
|
+
'div',
|
|
567
|
+
{ className: 'dshg-pills' },
|
|
568
|
+
h('span', { style: { fontSize: 10.5, color: '#f59e0b' } }, `${t.unregisteredDeps}:`),
|
|
569
|
+
...profile.unregisteredDeps.map((pkg) => h('span', { key: pkg, className: 'dshg-pill', 'data-tone': 'warn' }, pkg)),
|
|
570
|
+
)
|
|
571
|
+
: null,
|
|
572
|
+
)
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
function GuardPanelInner({ variant }) {
|
|
576
|
+
const snap = useStore()
|
|
577
|
+
const t = COPY[snap.lang] || COPY.zh
|
|
578
|
+
|
|
579
|
+
React.useEffect(() => {
|
|
580
|
+
ensureStyles()
|
|
581
|
+
if (!store.data && !store.loading) {
|
|
582
|
+
void fetchOverview()
|
|
583
|
+
}
|
|
584
|
+
}, [])
|
|
585
|
+
|
|
586
|
+
const data = snap.data
|
|
587
|
+
const health = data && data.health
|
|
588
|
+
const snapshots = data && data.snapshots
|
|
589
|
+
const platform = (data && data.platform) || (health && health.platform) || ''
|
|
590
|
+
const guard = (health && health.guard) || {}
|
|
591
|
+
const releaseUrl = guard.releaseUrl || (snapshots && snapshots.releaseUrl) || RELEASE_FALLBACK
|
|
592
|
+
const creds = (health && health.credentials) || {}
|
|
593
|
+
const refKeys = Array.isArray(creds.referencedKeys) ? creds.referencedKeys : []
|
|
594
|
+
const snapList = snapshots && Array.isArray(snapshots.snapshots) ? snapshots.snapshots : []
|
|
595
|
+
|
|
596
|
+
return h(
|
|
597
|
+
'div',
|
|
598
|
+
{ className: 'dshg-root', 'data-variant': variant || 'dock' },
|
|
599
|
+
// Top header card
|
|
600
|
+
h(
|
|
601
|
+
'div',
|
|
602
|
+
{ className: 'dshg-card' },
|
|
603
|
+
h(
|
|
604
|
+
'div',
|
|
605
|
+
{ className: 'dshg-header' },
|
|
606
|
+
h(
|
|
607
|
+
'div',
|
|
608
|
+
{ className: 'dshg-brand' },
|
|
609
|
+
h('div', { className: 'dshg-logo-wrap' }, h(GuardIcon, { size: 18, active: true })),
|
|
610
|
+
h(
|
|
611
|
+
'div',
|
|
612
|
+
null,
|
|
613
|
+
h('div', { className: 'dshg-title' }, t.brand),
|
|
614
|
+
h('div', { className: 'dshg-sub' }, t.subtitle),
|
|
615
|
+
),
|
|
616
|
+
),
|
|
617
|
+
h(
|
|
618
|
+
'div',
|
|
619
|
+
{ className: 'dshg-actions' },
|
|
620
|
+
h(
|
|
621
|
+
'button',
|
|
622
|
+
{
|
|
623
|
+
className: 'dshg-btn',
|
|
624
|
+
disabled: snap.loading,
|
|
625
|
+
onClick: () => void fetchOverview(),
|
|
626
|
+
},
|
|
627
|
+
snap.loading ? t.refreshing : `↻ ${t.refresh}`,
|
|
628
|
+
),
|
|
629
|
+
h(
|
|
630
|
+
'button',
|
|
631
|
+
{
|
|
632
|
+
className: 'dshg-btn',
|
|
633
|
+
onClick: () => patch({ lang: snap.lang === 'zh' ? 'en' : 'zh' }),
|
|
634
|
+
},
|
|
635
|
+
t.langSwitch,
|
|
636
|
+
),
|
|
637
|
+
),
|
|
638
|
+
),
|
|
639
|
+
health
|
|
640
|
+
? h(
|
|
641
|
+
'div',
|
|
642
|
+
{ className: 'dshg-row' },
|
|
643
|
+
h(
|
|
644
|
+
'span',
|
|
645
|
+
{ className: 'dshg-badge', 'data-tone': health.healthy ? 'ok' : 'warn' },
|
|
646
|
+
health.healthy ? `✓ ${t.healthy}` : `⚠ ${t.unhealthy(health.issuesCount || 0)}`,
|
|
647
|
+
),
|
|
648
|
+
snap.checkedAt
|
|
649
|
+
? h('span', { style: { fontSize: 10.5, color: 'var(--dshg-text-3)' } }, t.checkedAt(formatShortTime(snap.checkedAt)))
|
|
650
|
+
: null,
|
|
651
|
+
)
|
|
652
|
+
: null,
|
|
653
|
+
),
|
|
654
|
+
|
|
655
|
+
snap.error ? h('div', { className: 'dshg-error' }, snap.error) : null,
|
|
656
|
+
snap.notice ? h('div', { className: 'dshg-notice' }, snap.notice) : null,
|
|
657
|
+
|
|
658
|
+
!data && snap.loading
|
|
659
|
+
? h('div', { className: 'dshg-card', style: { fontSize: 12, color: 'var(--dshg-text-2)' } }, t.loading)
|
|
660
|
+
: null,
|
|
661
|
+
|
|
662
|
+
// Profiles comparison
|
|
663
|
+
health && Array.isArray(health.profiles)
|
|
664
|
+
? h(
|
|
665
|
+
'div',
|
|
666
|
+
{ className: 'dshg-card' },
|
|
667
|
+
h('div', { className: 'dshg-sec-head' }, h('span', null, t.profilesTitle)),
|
|
668
|
+
h(
|
|
669
|
+
'div',
|
|
670
|
+
{ className: 'dshg-profile-grid' },
|
|
671
|
+
...health.profiles.map((p) => h(ProfileSubcard, { key: p.target, profile: p, t })),
|
|
672
|
+
),
|
|
673
|
+
)
|
|
674
|
+
: null,
|
|
675
|
+
|
|
676
|
+
// Issues breakdown if unhealthy
|
|
677
|
+
health && Array.isArray(health.issues) && health.issues.length > 0
|
|
678
|
+
? h(
|
|
679
|
+
'div',
|
|
680
|
+
{ className: 'dshg-card' },
|
|
681
|
+
h('div', { className: 'dshg-sec-head' }, h('span', null, t.issuesTitle)),
|
|
682
|
+
...health.issues.map((issue, idx) =>
|
|
683
|
+
h('div', { key: idx, style: { fontSize: 11.5, color: '#f59e0b', wordBreak: 'break-word' } }, `• ${issue}`),
|
|
684
|
+
),
|
|
685
|
+
)
|
|
686
|
+
: null,
|
|
687
|
+
|
|
688
|
+
// Masked credentials readiness
|
|
689
|
+
health
|
|
690
|
+
? h(
|
|
691
|
+
'div',
|
|
692
|
+
{ className: 'dshg-card' },
|
|
693
|
+
h(
|
|
694
|
+
'div',
|
|
695
|
+
{ className: 'dshg-sec-head' },
|
|
696
|
+
h('span', null, t.credsTitle),
|
|
697
|
+
h(
|
|
698
|
+
'span',
|
|
699
|
+
{ className: 'dshg-badge', 'data-tone': creds.fileExists ? 'ok' : 'muted' },
|
|
700
|
+
creds.fileExists
|
|
701
|
+
? t.credReadyBadge(creds.nonEmptyKeysCount || 0, creds.totalKeysCount || 0)
|
|
702
|
+
: t.credMissingFile,
|
|
703
|
+
),
|
|
704
|
+
),
|
|
705
|
+
refKeys.length > 0
|
|
706
|
+
? h(
|
|
707
|
+
'div',
|
|
708
|
+
{ className: 'dshg-pills' },
|
|
709
|
+
...refKeys.map((item) =>
|
|
710
|
+
h(
|
|
711
|
+
'span',
|
|
712
|
+
{ key: item.key, className: 'dshg-pill', 'data-tone': item.ready ? 'ok' : 'warn' },
|
|
713
|
+
`${item.ready ? '✓' : '✗'} ${item.key}`,
|
|
714
|
+
),
|
|
715
|
+
),
|
|
716
|
+
)
|
|
717
|
+
: h('div', { style: { fontSize: 11, color: 'var(--dshg-text-2)' } }, t.credNoRefs),
|
|
718
|
+
)
|
|
719
|
+
: null,
|
|
720
|
+
|
|
721
|
+
// Pre-change snapshots
|
|
722
|
+
snapshots
|
|
723
|
+
? h(
|
|
724
|
+
'div',
|
|
725
|
+
{ className: 'dshg-card' },
|
|
726
|
+
h(
|
|
727
|
+
'div',
|
|
728
|
+
{ className: 'dshg-sec-head' },
|
|
729
|
+
h('span', null, t.snapshotsTitle),
|
|
730
|
+
h('span', { className: 'dshg-badge', 'data-tone': 'muted' }, t.snapshotsTotal(snapshots.total || 0)),
|
|
731
|
+
),
|
|
732
|
+
snapList.length > 0
|
|
733
|
+
? h(
|
|
734
|
+
'div',
|
|
735
|
+
{ className: 'dshg-snap-list' },
|
|
736
|
+
...snapList.slice(0, 8).map((s) =>
|
|
737
|
+
h(
|
|
738
|
+
'div',
|
|
739
|
+
{ key: s.id, className: 'dshg-snap-item' },
|
|
740
|
+
h(
|
|
741
|
+
'div',
|
|
742
|
+
{ className: 'dshg-row' },
|
|
743
|
+
h(
|
|
744
|
+
'span',
|
|
745
|
+
{ className: 'dshg-badge', 'data-tone': s.target === 'desktop' ? 'ok' : 'blue' },
|
|
746
|
+
s.target === 'desktop' ? t.desktopTrack : t.webTrack,
|
|
747
|
+
),
|
|
748
|
+
h('span', { style: { fontSize: 10.5, color: 'var(--dshg-text-3)' } }, `${t.snapItems(s.itemCount || 0)} · ${formatShortTime(s.createdAt)}`),
|
|
749
|
+
),
|
|
750
|
+
h('div', { className: 'dshg-mono' }, s.id),
|
|
751
|
+
h('div', { style: { fontSize: 11, color: 'var(--dshg-text-2)' } }, s.reason || t.snapNoReason),
|
|
752
|
+
),
|
|
753
|
+
),
|
|
754
|
+
)
|
|
755
|
+
: h('div', { style: { fontSize: 11, color: 'var(--dshg-text-2)' } }, t.snapshotsEmpty),
|
|
756
|
+
)
|
|
757
|
+
: null,
|
|
758
|
+
|
|
759
|
+
// Cross-platform DSHGuard supervisor bridge
|
|
760
|
+
data
|
|
761
|
+
? h(
|
|
762
|
+
'div',
|
|
763
|
+
{ className: 'dshg-card' },
|
|
764
|
+
h('div', { className: 'dshg-sec-head' }, h('span', null, t.guardTitle)),
|
|
765
|
+
platform === 'win32' && guard.installed
|
|
766
|
+
? [
|
|
767
|
+
h('div', { key: 'path', className: 'dshg-mono', style: { color: 'var(--dshg-text-2)' } }, t.guardReady(guard.exePath || 'DSHGuard.exe')),
|
|
768
|
+
h(
|
|
769
|
+
'button',
|
|
770
|
+
{
|
|
771
|
+
key: 'launch',
|
|
772
|
+
className: 'dshg-btn dshg-btn-primary',
|
|
773
|
+
disabled: snap.launching,
|
|
774
|
+
onClick: () => void launchDesktopGuard(),
|
|
775
|
+
},
|
|
776
|
+
snap.launching ? t.openingGuard : `🐋 ${t.openGuard}`,
|
|
777
|
+
),
|
|
778
|
+
]
|
|
779
|
+
: [
|
|
780
|
+
h(
|
|
781
|
+
'div',
|
|
782
|
+
{ key: 'note', style: { fontSize: 11.5, color: 'var(--dshg-text-2)', lineHeight: 1.5 } },
|
|
783
|
+
platform && platform !== 'win32' ? t.guardNonWin(platform) : t.guardNotInstalled,
|
|
784
|
+
),
|
|
785
|
+
h(
|
|
786
|
+
'a',
|
|
787
|
+
{
|
|
788
|
+
key: 'dl',
|
|
789
|
+
className: 'dshg-btn',
|
|
790
|
+
href: releaseUrl,
|
|
791
|
+
target: '_blank',
|
|
792
|
+
rel: 'noopener noreferrer',
|
|
793
|
+
},
|
|
794
|
+
`↗ ${t.downloadRelease}`,
|
|
795
|
+
),
|
|
796
|
+
],
|
|
797
|
+
)
|
|
798
|
+
: null,
|
|
799
|
+
)
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
function GuardPanel(props) {
|
|
803
|
+
return h(GuardErrorBoundary, null, h(GuardPanelInner, props || {}))
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
function SidebarGuardTab() {
|
|
807
|
+
return h(GuardPanel, { variant: 'dock' })
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
function MainGuardPage() {
|
|
811
|
+
return h(GuardPanel, { variant: 'main' })
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
return {
|
|
815
|
+
inject: ['slots', 'sidebarRightTabs'],
|
|
816
|
+
apply(ctx) {
|
|
817
|
+
if (ctx && typeof ctx.effect === 'function') {
|
|
818
|
+
ctx.effect(() => {
|
|
819
|
+
const tabs = typeof ctx.get === 'function' ? ctx.get('sidebarRightTabs') : ctx.sidebarRightTabs
|
|
820
|
+
if (!tabs || typeof tabs.register !== 'function') return undefined
|
|
821
|
+
return tabs.register({
|
|
822
|
+
id: SIDE_ID,
|
|
823
|
+
kind: SIDE_ID,
|
|
824
|
+
priority: 'extension',
|
|
825
|
+
title: () => (COPY[store.lang] || COPY.zh).brand,
|
|
826
|
+
guide: [
|
|
827
|
+
{
|
|
828
|
+
id: SIDE_ID,
|
|
829
|
+
order: 60,
|
|
830
|
+
title: () => (COPY[store.lang] || COPY.zh).brand,
|
|
831
|
+
description: () => (COPY[store.lang] || COPY.zh).guideDesc,
|
|
832
|
+
icon: GuardIcon,
|
|
833
|
+
},
|
|
834
|
+
],
|
|
835
|
+
})
|
|
836
|
+
}, 'dsh-guard: right-sidebar tab')
|
|
837
|
+
|
|
838
|
+
if (ctx.slots && typeof ctx.slots.inject === 'function' && typeof ctx.slots.register === 'function') {
|
|
839
|
+
ctx.slots.inject('sidebar.right.pane.tab', () =>
|
|
840
|
+
ctx.slots.register({ name: 'sidebar.right.pane.tab', key: SIDE_ID, order: 120 }, SidebarGuardTab),
|
|
841
|
+
)
|
|
842
|
+
ctx.slots.inject('sidebar.panellist', () =>
|
|
843
|
+
ctx.slots.register(
|
|
844
|
+
{ name: 'sidebar.panellist', id: SIDE_ID, order: 55, label: () => (COPY[store.lang] || COPY.zh).brand },
|
|
845
|
+
GuardIcon,
|
|
846
|
+
),
|
|
847
|
+
)
|
|
848
|
+
ctx.slots.inject('main', () =>
|
|
849
|
+
ctx.slots.register({ name: 'main', key: SIDE_ID, locale: 'zh-CN' }, MainGuardPage),
|
|
850
|
+
)
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
},
|
|
854
|
+
}
|
|
855
|
+
},
|
|
856
|
+
})
|