@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
|
@@ -0,0 +1,552 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
|
|
2
|
+
import { execFileSync, spawn } from 'node:child_process'
|
|
3
|
+
import { homedir } from 'node:os'
|
|
4
|
+
import { basename, join, resolve } from 'node:path'
|
|
5
|
+
|
|
6
|
+
export const RELEASE_URL = 'https://github.com/gluztm/DSHGuard/releases/latest'
|
|
7
|
+
|
|
8
|
+
const REG_POINTER_KEY = 'HKCU\\Software\\DSHGuard'
|
|
9
|
+
const REG_UNINSTALL_KEY = 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{9E1F7C34-5B2A-4D18-9C77-6A0E5D3B21F4}_is1'
|
|
10
|
+
|
|
11
|
+
export function resolveDshHome(overrideHome) {
|
|
12
|
+
if (overrideHome && String(overrideHome).trim()) {
|
|
13
|
+
return resolve(String(overrideHome).trim())
|
|
14
|
+
}
|
|
15
|
+
if (process.env.DSH_HOME && process.env.DSH_HOME.trim()) {
|
|
16
|
+
return resolve(process.env.DSH_HOME.trim())
|
|
17
|
+
}
|
|
18
|
+
return join(homedir(), '.dsh')
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function queryRegInstallLocation(keyPath, valueName) {
|
|
22
|
+
if (process.platform !== 'win32') return null
|
|
23
|
+
try {
|
|
24
|
+
const out = execFileSync('reg.exe', ['query', keyPath, '/v', valueName], {
|
|
25
|
+
encoding: 'utf8',
|
|
26
|
+
timeout: 2000,
|
|
27
|
+
windowsHide: true,
|
|
28
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
29
|
+
})
|
|
30
|
+
for (const rawLine of out.split(/\r?\n/)) {
|
|
31
|
+
const m = rawLine.trim().match(new RegExp(`^${valueName}\\s+REG_\\w+\\s+(.+)$`, 'i'))
|
|
32
|
+
if (m && m[1]) return m[1].trim()
|
|
33
|
+
}
|
|
34
|
+
} catch {
|
|
35
|
+
return null
|
|
36
|
+
}
|
|
37
|
+
return null
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Locate local DSHGuard out-of-band installation (strictly read-only).
|
|
42
|
+
*/
|
|
43
|
+
export function locateGuardInstallation(options = {}) {
|
|
44
|
+
const candidates = []
|
|
45
|
+
if (options.guardHome && String(options.guardHome).trim()) {
|
|
46
|
+
candidates.push(resolve(String(options.guardHome).trim()))
|
|
47
|
+
} else {
|
|
48
|
+
if (process.env.DSHGUARD_HOME && process.env.DSHGUARD_HOME.trim()) {
|
|
49
|
+
candidates.push(resolve(process.env.DSHGUARD_HOME.trim()))
|
|
50
|
+
}
|
|
51
|
+
const ptrDir = queryRegInstallLocation(REG_POINTER_KEY, 'InstallLocation')
|
|
52
|
+
|| queryRegInstallLocation(REG_POINTER_KEY, 'InstallDir')
|
|
53
|
+
if (ptrDir) candidates.push(resolve(ptrDir))
|
|
54
|
+
|
|
55
|
+
const uninstDir = queryRegInstallLocation(REG_UNINSTALL_KEY, 'InstallLocation')
|
|
56
|
+
if (uninstDir) candidates.push(resolve(uninstDir))
|
|
57
|
+
|
|
58
|
+
const localAppData = process.env.LOCALAPPDATA
|
|
59
|
+
if (localAppData) {
|
|
60
|
+
candidates.push(join(localAppData, 'Programs', 'DSHGuard'))
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let matchedHome = null
|
|
65
|
+
let matchedExe = null
|
|
66
|
+
let matchedSnapshots = null
|
|
67
|
+
|
|
68
|
+
for (const dir of candidates) {
|
|
69
|
+
if (!dir || !existsSync(dir)) continue
|
|
70
|
+
const exeCandidate = join(dir, 'DSHGuard.exe')
|
|
71
|
+
const snapCandidate = options.snapshotsDir ? resolve(String(options.snapshotsDir)) : join(dir, 'Snapshots')
|
|
72
|
+
if (existsSync(exeCandidate) || existsSync(snapCandidate)) {
|
|
73
|
+
matchedHome = dir
|
|
74
|
+
if (existsSync(exeCandidate)) matchedExe = exeCandidate
|
|
75
|
+
if (existsSync(snapCandidate)) matchedSnapshots = snapCandidate
|
|
76
|
+
break
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (!matchedSnapshots && options.snapshotsDir && existsSync(resolve(String(options.snapshotsDir)))) {
|
|
81
|
+
matchedSnapshots = resolve(String(options.snapshotsDir))
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
installed: Boolean(matchedExe),
|
|
86
|
+
guardHome: matchedHome,
|
|
87
|
+
exePath: matchedExe,
|
|
88
|
+
snapshotsDir: matchedSnapshots,
|
|
89
|
+
releaseUrl: RELEASE_URL,
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function readJsonSafe(filePath) {
|
|
94
|
+
try {
|
|
95
|
+
const raw = readFileSync(filePath, 'utf8')
|
|
96
|
+
return { ok: true, data: JSON.parse(raw), error: null }
|
|
97
|
+
} catch (err) {
|
|
98
|
+
return { ok: false, data: null, error: err && err.message ? err.message : String(err) }
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function extractBundleIds(bundlesField) {
|
|
103
|
+
if (Array.isArray(bundlesField)) {
|
|
104
|
+
return bundlesField.map((item) => String(item || '').trim()).filter(Boolean)
|
|
105
|
+
}
|
|
106
|
+
if (bundlesField && typeof bundlesField === 'object') {
|
|
107
|
+
return Object.keys(bundlesField).map((k) => k.trim()).filter(Boolean)
|
|
108
|
+
}
|
|
109
|
+
return []
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function scanCordisPatch(patchPath) {
|
|
113
|
+
if (!existsSync(patchPath)) {
|
|
114
|
+
return {
|
|
115
|
+
exists: false,
|
|
116
|
+
readable: false,
|
|
117
|
+
syntaxOk: true,
|
|
118
|
+
hasTabIndent: false,
|
|
119
|
+
disabledCount: 0,
|
|
120
|
+
apiKeyEnvKeys: [],
|
|
121
|
+
mcpEntriesCount: 0,
|
|
122
|
+
error: null,
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
try {
|
|
126
|
+
const raw = readFileSync(patchPath, 'utf8')
|
|
127
|
+
const lines = raw.split(/\r?\n/)
|
|
128
|
+
let hasTabIndent = false
|
|
129
|
+
let disabledCount = 0
|
|
130
|
+
let mcpEntriesCount = 0
|
|
131
|
+
const envSet = new Set()
|
|
132
|
+
let hasStructuredToken = false
|
|
133
|
+
|
|
134
|
+
for (const line of lines) {
|
|
135
|
+
if (/^\t+/.test(line)) hasTabIndent = true
|
|
136
|
+
const trimmed = line.trim()
|
|
137
|
+
if (!trimmed || trimmed.startsWith('#')) continue
|
|
138
|
+
if (trimmed.startsWith('- ') || /^[A-Za-z0-9_.-]+\s*:/.test(trimmed)) {
|
|
139
|
+
hasStructuredToken = true
|
|
140
|
+
}
|
|
141
|
+
if (/^enabled\s*:\s*false\b/i.test(trimmed)) {
|
|
142
|
+
disabledCount += 1
|
|
143
|
+
}
|
|
144
|
+
const envMatch = trimmed.match(/^apiKeyEnv\s*:\s*['"]?([A-Za-z0-9_]+)['"]?/i)
|
|
145
|
+
if (envMatch && envMatch[1]) {
|
|
146
|
+
envSet.add(envMatch[1])
|
|
147
|
+
}
|
|
148
|
+
if (/\bmcpServers\b|id\s*:\s*['"]?mcp\b/i.test(trimmed)) {
|
|
149
|
+
mcpEntriesCount += 1
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const nonEmpty = lines.some((l) => l.trim() && !l.trim().startsWith('#'))
|
|
154
|
+
const syntaxOk = !hasTabIndent && (!nonEmpty || hasStructuredToken)
|
|
155
|
+
|
|
156
|
+
return {
|
|
157
|
+
exists: true,
|
|
158
|
+
readable: true,
|
|
159
|
+
syntaxOk,
|
|
160
|
+
hasTabIndent,
|
|
161
|
+
disabledCount,
|
|
162
|
+
apiKeyEnvKeys: Array.from(envSet).sort(),
|
|
163
|
+
mcpEntriesCount,
|
|
164
|
+
error: syntaxOk ? null : (hasTabIndent ? 'Tab indentation detected in YAML' : 'Unrecognized YAML structure'),
|
|
165
|
+
}
|
|
166
|
+
} catch (err) {
|
|
167
|
+
return {
|
|
168
|
+
exists: true,
|
|
169
|
+
readable: false,
|
|
170
|
+
syntaxOk: false,
|
|
171
|
+
hasTabIndent: false,
|
|
172
|
+
disabledCount: 0,
|
|
173
|
+
apiKeyEnvKeys: [],
|
|
174
|
+
mcpEntriesCount: 0,
|
|
175
|
+
error: err && err.message ? err.message : String(err),
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Read-only health inspection of a single DSH profile ('web' or 'desktop').
|
|
182
|
+
*/
|
|
183
|
+
export function inspectProfile(profileDir, targetName) {
|
|
184
|
+
const exists = existsSync(profileDir)
|
|
185
|
+
const pkgPath = join(profileDir, 'package.json')
|
|
186
|
+
const patchPath = join(profileDir, 'cordis.patch.yml')
|
|
187
|
+
|
|
188
|
+
if (!exists) {
|
|
189
|
+
return {
|
|
190
|
+
target: targetName,
|
|
191
|
+
profileDir,
|
|
192
|
+
exists: false,
|
|
193
|
+
packageJsonOk: false,
|
|
194
|
+
dependenciesCount: 0,
|
|
195
|
+
bundlesCount: 0,
|
|
196
|
+
missingInDeps: [],
|
|
197
|
+
unregisteredDeps: [],
|
|
198
|
+
patch: scanCordisPatch(patchPath),
|
|
199
|
+
issues: [],
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const pkgRes = existsSync(pkgPath)
|
|
204
|
+
? readJsonSafe(pkgPath)
|
|
205
|
+
: { ok: false, data: null, error: 'package.json not found' }
|
|
206
|
+
|
|
207
|
+
const depsObj = pkgRes.ok && pkgRes.data && typeof pkgRes.data.dependencies === 'object' && pkgRes.data.dependencies
|
|
208
|
+
? pkgRes.data.dependencies
|
|
209
|
+
: {}
|
|
210
|
+
const depNames = Object.keys(depsObj)
|
|
211
|
+
const depSet = new Set(depNames)
|
|
212
|
+
|
|
213
|
+
const bundles = pkgRes.ok && pkgRes.data && pkgRes.data.dsh
|
|
214
|
+
? extractBundleIds(pkgRes.data.dsh.bundles ?? (pkgRes.data.dsh.profile && pkgRes.data.dsh.profile.bundles))
|
|
215
|
+
: []
|
|
216
|
+
const bundleSet = new Set(bundles)
|
|
217
|
+
|
|
218
|
+
const missingInDeps = bundles.filter((b) => !depSet.has(b))
|
|
219
|
+
const unregisteredDeps = depNames.filter((d) => {
|
|
220
|
+
if (bundleSet.has(d)) return false
|
|
221
|
+
return d.startsWith('dsh-') || d.includes('/dsh-')
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
const patch = scanCordisPatch(patchPath)
|
|
225
|
+
const issues = []
|
|
226
|
+
if (!pkgRes.ok) {
|
|
227
|
+
issues.push(`${targetName} package.json error: ${pkgRes.error}`)
|
|
228
|
+
}
|
|
229
|
+
if (missingInDeps.length > 0) {
|
|
230
|
+
issues.push(`${targetName} manifest drift: ${missingInDeps.length} bundle(s) missing in dependencies (${missingInDeps.join(', ')})`)
|
|
231
|
+
}
|
|
232
|
+
if (unregisteredDeps.length > 0) {
|
|
233
|
+
issues.push(`${targetName} manifest drift: ${unregisteredDeps.length} plugin dep(s) not listed in bundles (${unregisteredDeps.join(', ')})`)
|
|
234
|
+
}
|
|
235
|
+
if (patch.exists && !patch.syntaxOk) {
|
|
236
|
+
issues.push(`${targetName} cordis.patch.yml warning: ${patch.error}`)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return {
|
|
240
|
+
target: targetName,
|
|
241
|
+
profileDir,
|
|
242
|
+
exists: true,
|
|
243
|
+
packageJsonOk: pkgRes.ok,
|
|
244
|
+
dependenciesCount: depNames.length,
|
|
245
|
+
bundlesCount: bundles.length,
|
|
246
|
+
missingInDeps,
|
|
247
|
+
unregisteredDeps,
|
|
248
|
+
patch,
|
|
249
|
+
issues,
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Strictly masked credential readiness check: NEVER reads, slices, or returns secret values.
|
|
255
|
+
*/
|
|
256
|
+
export function inspectCredentialKeysMasked(dshHome, referencedEnvKeys = []) {
|
|
257
|
+
const credPath = join(dshHome, '.credentials.yaml')
|
|
258
|
+
const nonEmptyKeys = new Set()
|
|
259
|
+
let totalKeysCount = 0
|
|
260
|
+
let fileExists = false
|
|
261
|
+
|
|
262
|
+
if (existsSync(credPath)) {
|
|
263
|
+
fileExists = true
|
|
264
|
+
try {
|
|
265
|
+
const raw = readFileSync(credPath, 'utf8')
|
|
266
|
+
for (const rawLine of raw.split(/\r?\n/)) {
|
|
267
|
+
const line = rawLine.trimEnd()
|
|
268
|
+
if (!line || line.trim().startsWith('#') || /^\s/.test(line)) continue
|
|
269
|
+
const m = line.match(/^([A-Za-z0-9_.-]+)\s*:\s*(.*)$/)
|
|
270
|
+
if (!m) continue
|
|
271
|
+
totalKeysCount += 1
|
|
272
|
+
const keyName = m[1].trim()
|
|
273
|
+
const rawVal = m[2].trim()
|
|
274
|
+
const stripped = rawVal.replace(/^(['"])(.*)\1$/, '$2').trim()
|
|
275
|
+
const isEmpty = !stripped || stripped === '~' || stripped.toLowerCase() === 'null'
|
|
276
|
+
if (!isEmpty) {
|
|
277
|
+
nonEmptyKeys.add(keyName)
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
} catch {
|
|
281
|
+
// Unreadable file stays nonEmptyKeys empty; never leak raw error internals with secrets.
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const uniqueRefs = Array.from(new Set(referencedEnvKeys.filter(Boolean))).sort()
|
|
286
|
+
const referencedKeys = uniqueRefs.map((key) => ({
|
|
287
|
+
key,
|
|
288
|
+
ready: nonEmptyKeys.has(key),
|
|
289
|
+
}))
|
|
290
|
+
const missingReferencedKeys = referencedKeys.filter((item) => !item.ready).map((item) => item.key)
|
|
291
|
+
|
|
292
|
+
return {
|
|
293
|
+
fileExists,
|
|
294
|
+
totalKeysCount,
|
|
295
|
+
nonEmptyKeysCount: nonEmptyKeys.size,
|
|
296
|
+
referencedKeys,
|
|
297
|
+
missingReferencedKeys,
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Full read-only health report across Web & Desktop profiles, masked credentials, and DSHGuard.
|
|
303
|
+
*/
|
|
304
|
+
export function inspectHealth(options = {}) {
|
|
305
|
+
const dshHome = resolveDshHome(options.dshHome)
|
|
306
|
+
const target = options.target && ['all', 'web', 'desktop'].includes(options.target)
|
|
307
|
+
? options.target
|
|
308
|
+
: 'all'
|
|
309
|
+
|
|
310
|
+
const profiles = []
|
|
311
|
+
if (target === 'all' || target === 'web') {
|
|
312
|
+
profiles.push(inspectProfile(join(dshHome, 'profiles', 'web'), 'web'))
|
|
313
|
+
}
|
|
314
|
+
if (target === 'all' || target === 'desktop') {
|
|
315
|
+
profiles.push(inspectProfile(join(dshHome, 'profiles', 'desktop'), 'desktop'))
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const referencedEnvKeys = profiles.flatMap((p) => (p.patch ? p.patch.apiKeyEnvKeys : []))
|
|
319
|
+
const credentials = inspectCredentialKeysMasked(dshHome, referencedEnvKeys)
|
|
320
|
+
const guard = locateGuardInstallation(options)
|
|
321
|
+
|
|
322
|
+
const issues = profiles.flatMap((p) => p.issues)
|
|
323
|
+
if (credentials.missingReferencedKeys.length > 0) {
|
|
324
|
+
issues.push(`Missing credential key(s) in .credentials.yaml: ${credentials.missingReferencedKeys.join(', ')}`)
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const healthy = issues.length === 0
|
|
328
|
+
|
|
329
|
+
return {
|
|
330
|
+
platform: process.platform,
|
|
331
|
+
dshHome,
|
|
332
|
+
target,
|
|
333
|
+
healthy,
|
|
334
|
+
issuesCount: issues.length,
|
|
335
|
+
issues,
|
|
336
|
+
profiles,
|
|
337
|
+
credentials,
|
|
338
|
+
guard,
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function classifySnapshotEntry(dirPath, name) {
|
|
343
|
+
let target = 'web'
|
|
344
|
+
let reason = ''
|
|
345
|
+
let itemCount = 0
|
|
346
|
+
let createdAt = ''
|
|
347
|
+
|
|
348
|
+
const manifestPath = join(dirPath, 'manifest.json')
|
|
349
|
+
if (existsSync(manifestPath)) {
|
|
350
|
+
const res = readJsonSafe(manifestPath)
|
|
351
|
+
if (res.ok && res.data) {
|
|
352
|
+
if (typeof res.data.target === 'string' && res.data.target.toLowerCase().includes('desktop')) {
|
|
353
|
+
target = 'desktop'
|
|
354
|
+
} else if (typeof res.data.scope === 'string' && res.data.scope.toLowerCase().includes('desktop')) {
|
|
355
|
+
target = 'desktop'
|
|
356
|
+
}
|
|
357
|
+
if (typeof res.data.reason === 'string') reason = res.data.reason
|
|
358
|
+
if (typeof res.data.createdAt === 'string') createdAt = res.data.createdAt
|
|
359
|
+
if (Array.isArray(res.data.files)) itemCount = res.data.files.length
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (target === 'web' && /desktop/i.test(name)) {
|
|
364
|
+
target = 'desktop'
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
try {
|
|
368
|
+
const entries = readdirSync(dirPath)
|
|
369
|
+
if (itemCount === 0) {
|
|
370
|
+
itemCount = entries.filter((e) => e !== 'manifest.json').length
|
|
371
|
+
}
|
|
372
|
+
if (!createdAt) {
|
|
373
|
+
createdAt = new Date(statSync(dirPath).mtimeMs).toISOString()
|
|
374
|
+
}
|
|
375
|
+
} catch {
|
|
376
|
+
// Ignore stat errors on individual directories
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
return {
|
|
380
|
+
id: name,
|
|
381
|
+
target,
|
|
382
|
+
reason,
|
|
383
|
+
itemCount,
|
|
384
|
+
createdAt,
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* List saved DSHGuard snapshots (strictly read-only).
|
|
390
|
+
*/
|
|
391
|
+
export function inspectSnapshots(options = {}) {
|
|
392
|
+
const guard = locateGuardInstallation(options)
|
|
393
|
+
const limit = Math.max(1, Math.min(50, Number(options.limit) || 20))
|
|
394
|
+
const targetFilter = options.target && ['all', 'web', 'desktop'].includes(options.target)
|
|
395
|
+
? options.target
|
|
396
|
+
: 'all'
|
|
397
|
+
|
|
398
|
+
if (!guard.snapshotsDir || !existsSync(guard.snapshotsDir)) {
|
|
399
|
+
return {
|
|
400
|
+
snapshotsDir: guard.snapshotsDir,
|
|
401
|
+
guardInstalled: guard.installed,
|
|
402
|
+
total: 0,
|
|
403
|
+
snapshots: [],
|
|
404
|
+
releaseUrl: RELEASE_URL,
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
let items = []
|
|
409
|
+
try {
|
|
410
|
+
const entries = readdirSync(guard.snapshotsDir, { withFileTypes: true })
|
|
411
|
+
for (const ent of entries) {
|
|
412
|
+
if (!ent.isDirectory()) continue
|
|
413
|
+
const full = join(guard.snapshotsDir, ent.name)
|
|
414
|
+
const parsed = classifySnapshotEntry(full, ent.name)
|
|
415
|
+
if (targetFilter === 'all' || parsed.target === targetFilter) {
|
|
416
|
+
items.push(parsed)
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
} catch {
|
|
420
|
+
items = []
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
items.sort((a, b) => String(b.createdAt).localeCompare(String(a.createdAt)))
|
|
424
|
+
|
|
425
|
+
return {
|
|
426
|
+
snapshotsDir: guard.snapshotsDir,
|
|
427
|
+
guardInstalled: guard.installed,
|
|
428
|
+
total: items.length,
|
|
429
|
+
snapshots: items.slice(0, limit),
|
|
430
|
+
releaseUrl: RELEASE_URL,
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Locate or optionally launch the local Windows DSHGuard desktop supervisor.
|
|
436
|
+
*/
|
|
437
|
+
export function openGuard(options = {}) {
|
|
438
|
+
const guard = locateGuardInstallation(options)
|
|
439
|
+
if (!guard.installed || !guard.exePath) {
|
|
440
|
+
return {
|
|
441
|
+
installed: false,
|
|
442
|
+
launched: false,
|
|
443
|
+
exePath: null,
|
|
444
|
+
guardHome: guard.guardHome,
|
|
445
|
+
releaseUrl: RELEASE_URL,
|
|
446
|
+
message: '未检测到本地安装的 DSHGuard 守护壳,可前往 GitHub Releases 下载官方 Windows 安装包。',
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
if (options.launch === true) {
|
|
451
|
+
if (process.platform !== 'win32') {
|
|
452
|
+
return {
|
|
453
|
+
installed: true,
|
|
454
|
+
launched: false,
|
|
455
|
+
exePath: guard.exePath,
|
|
456
|
+
guardHome: guard.guardHome,
|
|
457
|
+
releaseUrl: RELEASE_URL,
|
|
458
|
+
message: '当前非 Windows 环境,无法直接拉起桌面端 DSHGuard.exe。',
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
try {
|
|
462
|
+
const child = spawn(guard.exePath, [], {
|
|
463
|
+
detached: true,
|
|
464
|
+
stdio: 'ignore',
|
|
465
|
+
windowsHide: false,
|
|
466
|
+
})
|
|
467
|
+
if (typeof child.on === 'function') {
|
|
468
|
+
child.on('error', () => {})
|
|
469
|
+
}
|
|
470
|
+
child.unref()
|
|
471
|
+
return {
|
|
472
|
+
installed: true,
|
|
473
|
+
launched: true,
|
|
474
|
+
exePath: guard.exePath,
|
|
475
|
+
guardHome: guard.guardHome,
|
|
476
|
+
releaseUrl: RELEASE_URL,
|
|
477
|
+
message: `已在桌面拉起 DSHGuard 守护壳(${basename(guard.exePath)})。`,
|
|
478
|
+
}
|
|
479
|
+
} catch (err) {
|
|
480
|
+
return {
|
|
481
|
+
installed: true,
|
|
482
|
+
launched: false,
|
|
483
|
+
exePath: guard.exePath,
|
|
484
|
+
guardHome: guard.guardHome,
|
|
485
|
+
releaseUrl: RELEASE_URL,
|
|
486
|
+
message: `拉起 DSHGuard 守护壳失败:${err && err.message ? err.message : String(err)}`,
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
return {
|
|
492
|
+
installed: true,
|
|
493
|
+
launched: false,
|
|
494
|
+
exePath: guard.exePath,
|
|
495
|
+
guardHome: guard.guardHome,
|
|
496
|
+
releaseUrl: RELEASE_URL,
|
|
497
|
+
message: `已定位本机 DSHGuard 守护壳:${guard.exePath}`,
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
export function formatHealthText(report) {
|
|
502
|
+
const lines = []
|
|
503
|
+
lines.push(`DSH 守护壳伴生体检(状态:${report.healthy ? '正常' : `发现 ${report.issuesCount} 项异常`})`)
|
|
504
|
+
for (const p of report.profiles) {
|
|
505
|
+
if (!p.exists) {
|
|
506
|
+
lines.push(`- [${p.target}] 未检测到配置目录`)
|
|
507
|
+
continue
|
|
508
|
+
}
|
|
509
|
+
const patchNote = p.patch.exists
|
|
510
|
+
? (p.patch.syntaxOk ? `patch 正常(禁用 ${p.patch.disabledCount} 项)` : `patch 异常(${p.patch.error})`)
|
|
511
|
+
: '无 cordis.patch.yml'
|
|
512
|
+
lines.push(
|
|
513
|
+
`- [${p.target}] bundles=${p.bundlesCount} / deps=${p.dependenciesCount} | ${patchNote}`
|
|
514
|
+
+ (p.missingInDeps.length ? ` | 缺依赖: ${p.missingInDeps.join(', ')}` : '')
|
|
515
|
+
+ (p.unregisteredDeps.length ? ` | 未登记: ${p.unregisteredDeps.join(', ')}` : '')
|
|
516
|
+
)
|
|
517
|
+
}
|
|
518
|
+
const cred = report.credentials
|
|
519
|
+
const refTotal = cred.referencedKeys.length
|
|
520
|
+
const refReady = cred.referencedKeys.filter((r) => r.ready).length
|
|
521
|
+
lines.push(
|
|
522
|
+
`- [凭据脱敏对账] .credentials.yaml ${cred.fileExists ? `已存在(非空键 ${cred.nonEmptyKeysCount}/${cred.totalKeysCount})` : '未创建'}`
|
|
523
|
+
+ (refTotal > 0 ? ` | patch 引用键就绪 ${refReady}/${refTotal}` : '')
|
|
524
|
+
+ (cred.missingReferencedKeys.length ? ` | 缺失: ${cred.missingReferencedKeys.join(', ')}` : '')
|
|
525
|
+
)
|
|
526
|
+
lines.push(
|
|
527
|
+
report.guard.installed
|
|
528
|
+
? `- [本机 DSHGuard] 已安装(${report.guard.exePath})`
|
|
529
|
+
: `- [本机 DSHGuard] 未安装,官方下载:${report.guard.releaseUrl}`
|
|
530
|
+
)
|
|
531
|
+
if (report.issues.length > 0) {
|
|
532
|
+
lines.push('诊断建议:')
|
|
533
|
+
for (const issue of report.issues) {
|
|
534
|
+
lines.push(` ! ${issue}`)
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
return lines.join('\n')
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
export function formatSnapshotsText(report) {
|
|
541
|
+
if (!report.snapshotsDir || report.total === 0) {
|
|
542
|
+
return report.guardInstalled
|
|
543
|
+
? '本机 DSHGuard 尚无快照存档(Snapshots 目录为空或不存在)。'
|
|
544
|
+
: `未定位到本机 DSHGuard 快照目录;可在 Windows 安装 DSHGuard 后自动存档:${report.releaseUrl}`
|
|
545
|
+
}
|
|
546
|
+
const lines = [`已找到 ${report.total} 份守护壳快照(展示最近 ${report.snapshots.length} 份):`]
|
|
547
|
+
for (const snap of report.snapshots) {
|
|
548
|
+
const meta = [snap.target, `${snap.itemCount} 项`, snap.createdAt].filter(Boolean).join(' · ')
|
|
549
|
+
lines.push(`- ${snap.id}(${meta})${snap.reason ? ` — ${snap.reason}` : ''}`)
|
|
550
|
+
}
|
|
551
|
+
return lines.join('\n')
|
|
552
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,89 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gluztm/dsh-guard",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "2.4.0",
|
|
4
|
+
"description": "Cross-platform read-only companion plugin & Web UI sidebar inspector for DSHGuard: inspects Web/Desktop bundle drift, cordis.patch.yml structure, masked .credentials.yaml key readiness, pre-change snapshots, and opens DSHGuard.exe on Windows (3 dsh_guard_* tools + /guard command + Web UI panel).",
|
|
5
|
+
"icon": "./assets/icon.png",
|
|
6
|
+
"license": "GPL-3.0-only",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./lib/index.mjs",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./lib/index.mjs",
|
|
11
|
+
"./client": "./lib/client.js",
|
|
12
|
+
"./inspector": "./lib/inspector.mjs",
|
|
13
|
+
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
14
|
+
"./package.json": "./package.json",
|
|
15
|
+
"./icon": "./assets/icon.png"
|
|
16
|
+
},
|
|
17
|
+
"bin": {
|
|
18
|
+
"dsh-guard": "./bin/dsh-guard.mjs"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"assets",
|
|
22
|
+
"bin",
|
|
23
|
+
"lib",
|
|
24
|
+
"cordis.patch.yml",
|
|
25
|
+
"README.md",
|
|
26
|
+
"README.en.md",
|
|
27
|
+
"LICENSE"
|
|
28
|
+
],
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/gluztm/DSHGuard.git",
|
|
32
|
+
"directory": "packages/dsh-guard"
|
|
33
|
+
},
|
|
34
|
+
"homepage": "https://github.com/gluztm/DSHGuard#readme",
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/gluztm/DSHGuard/issues"
|
|
37
|
+
},
|
|
38
|
+
"dsh": {
|
|
39
|
+
"bundle": {
|
|
40
|
+
"patch": "./cordis.patch.yml"
|
|
41
|
+
},
|
|
42
|
+
"client": {
|
|
43
|
+
"platform": "web",
|
|
44
|
+
"immediately": true,
|
|
45
|
+
"inject": []
|
|
46
|
+
},
|
|
47
|
+
"compatibility": {
|
|
48
|
+
"dsh": ">=0.1.5-rc.1 <0.3.0-0"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"@deepseek-ai/cordis": "^4.0.1",
|
|
53
|
+
"@deepseek-ai/dsh": ">=0.1.5-rc.1",
|
|
54
|
+
"@deepseek-ai/dsh-tools": ">=0.1.0-rc.6 <0.3.0"
|
|
55
|
+
},
|
|
56
|
+
"peerDependenciesMeta": {
|
|
57
|
+
"@deepseek-ai/cordis": {
|
|
58
|
+
"optional": true
|
|
59
|
+
},
|
|
60
|
+
"@deepseek-ai/dsh": {
|
|
61
|
+
"optional": true
|
|
62
|
+
},
|
|
63
|
+
"@deepseek-ai/dsh-tools": {
|
|
64
|
+
"optional": true
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
"keywords": [
|
|
68
|
+
"deepseek-harness",
|
|
69
|
+
"dsh-plugin",
|
|
70
|
+
"dsh",
|
|
71
|
+
"dshguard",
|
|
72
|
+
"client-plugin",
|
|
73
|
+
"health-check",
|
|
74
|
+
"snapshot",
|
|
75
|
+
"rollback",
|
|
76
|
+
"credentials",
|
|
77
|
+
"cc-switch",
|
|
78
|
+
"sidebar",
|
|
79
|
+
"cross-platform"
|
|
80
|
+
],
|
|
81
|
+
"os": [
|
|
82
|
+
"darwin",
|
|
83
|
+
"linux",
|
|
84
|
+
"win32"
|
|
85
|
+
],
|
|
86
|
+
"engines": {
|
|
87
|
+
"node": ">=18.0.0"
|
|
88
|
+
}
|
|
89
|
+
}
|