@gluztm/dsh-guard 2.4.1 → 2.4.4

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/lib/index.mjs CHANGED
@@ -3,12 +3,31 @@ import {
3
3
  PACKAGE_VERSION,
4
4
  RELEASE_URL,
5
5
  REPO_URL,
6
+ createSnapshot,
7
+ detectActiveProfile,
8
+ discoverProfiles,
9
+ formatContextAuditText,
6
10
  formatHealthText,
11
+ formatMcpProbeText,
7
12
  formatSnapshotsText,
13
+ inspectContextAudit,
8
14
  inspectHealth,
15
+ inspectSkills,
9
16
  inspectSnapshots,
10
17
  locateGuardInstallation,
18
+ normalizeProfileTarget,
11
19
  openGuard,
20
+ pinSnapshot,
21
+ probeMcpServers,
22
+ readAuditLog,
23
+ repairBrokenModuleLinks,
24
+ resolveDshHome,
25
+ restoreSnapshotConfig,
26
+ togglePatchEntry,
27
+ toggleSkillVisibility,
28
+ updateMcpTimeout,
29
+ upsertCredentialKey,
30
+ validateProfileName,
12
31
  } from './inspector.mjs'
13
32
 
14
33
  let defineTool = (def) => def
@@ -23,6 +42,7 @@ try {
23
42
 
24
43
  const name = 'dsh-guard'
25
44
  const API_BASE = '/api/dsh-guard'
45
+ const MAX_JSON_BYTES = 32768
26
46
 
27
47
  function sendJson(res, status, value) {
28
48
  const body = JSON.stringify(value)
@@ -51,7 +71,101 @@ function isRequestAllowed(ctx, req, res) {
51
71
  return true
52
72
  }
53
73
 
54
- function buildRouteTable(ctx) {
74
+ async function readJsonBody(req, maxBytes = MAX_JSON_BYTES) {
75
+ if (req && req.body && typeof req.body === 'object' && !Buffer.isBuffer(req.body)) {
76
+ return req.body
77
+ }
78
+ if (!req || typeof req.on !== 'function') {
79
+ return {}
80
+ }
81
+ return await new Promise((resolve, reject) => {
82
+ const chunks = []
83
+ let total = 0
84
+ let finished = false
85
+ req.on('data', (chunk) => {
86
+ if (finished) return
87
+ const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk), 'utf8')
88
+ total += buf.length
89
+ if (total > maxBytes) {
90
+ finished = true
91
+ reject(Object.assign(new Error('payload_too_large'), { status: 413 }))
92
+ return
93
+ }
94
+ chunks.push(buf)
95
+ })
96
+ req.on('end', () => {
97
+ if (finished) return
98
+ finished = true
99
+ const raw = Buffer.concat(chunks).toString('utf8').trim()
100
+ if (!raw) {
101
+ resolve({})
102
+ return
103
+ }
104
+ try {
105
+ const parsed = JSON.parse(raw)
106
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
107
+ reject(Object.assign(new Error('invalid_json_object'), { status: 400 }))
108
+ return
109
+ }
110
+ resolve(parsed)
111
+ } catch {
112
+ reject(Object.assign(new Error('invalid_json'), { status: 400 }))
113
+ }
114
+ })
115
+ req.on('error', (err) => {
116
+ if (finished) return
117
+ finished = true
118
+ reject(err)
119
+ })
120
+ })
121
+ }
122
+
123
+ function makePostRoute(ctx, routePath, handler) {
124
+ return {
125
+ path: `${API_BASE}${routePath}`,
126
+ handler: async (req, res) => {
127
+ if (!isRequestAllowed(ctx, req, res)) return
128
+ const method = String((req && req.method) || '').toUpperCase()
129
+ if (method !== 'POST') {
130
+ sendJson(res, 405, { ok: false, error: 'method_not_allowed' })
131
+ return
132
+ }
133
+ let body
134
+ try {
135
+ body = await readJsonBody(req)
136
+ } catch (err) {
137
+ sendJson(res, err && err.status ? err.status : 400, {
138
+ ok: false,
139
+ error: err && err.message ? String(err.message) : 'invalid_request_body',
140
+ })
141
+ return
142
+ }
143
+ try {
144
+ const result = await handler(body)
145
+ if (result && result.ok === false) {
146
+ sendJson(res, 400, result)
147
+ return
148
+ }
149
+ sendJson(res, 200, { ok: true, ...(result || {}) })
150
+ } catch (err) {
151
+ sendJson(res, 500, {
152
+ ok: false,
153
+ error: err && err.message ? String(err.message) : 'internal_error',
154
+ })
155
+ }
156
+ },
157
+ }
158
+ }
159
+
160
+ function resolveRouteTarget(rawTarget, defaultProfile) {
161
+ if (rawTarget === undefined || rawTarget === null || rawTarget === '' || rawTarget === 'all') {
162
+ return defaultProfile
163
+ }
164
+ return normalizeProfileTarget(String(rawTarget), null)
165
+ }
166
+
167
+ function buildRouteTable(ctx, activeProfile = detectActiveProfile({ ctx })) {
168
+ const hostProfile = normalizeProfileTarget(activeProfile) || 'web'
55
169
  return [
56
170
  {
57
171
  path: `${API_BASE}/overview`,
@@ -63,14 +177,16 @@ function buildRouteTable(ctx) {
63
177
  return
64
178
  }
65
179
  try {
66
- // Server-side env vars only (DSH_HOME / DSHGUARD_HOME); never accept path traversal params from HTTP requests.
67
- const health = inspectHealth({ target: 'all' })
68
- const snapshots = inspectSnapshots({ target: 'all', limit: 15 })
180
+ // Server-side env vars only (DSH_HOME / DSHGUARD_HOME); never accept path params from HTTP requests.
181
+ const health = inspectHealth({ activeProfile: hostProfile, ctx })
182
+ const snapshots = inspectSnapshots({ target: hostProfile, limit: 25 })
69
183
  sendJson(res, 200, {
70
184
  ok: true,
71
185
  version: PACKAGE_VERSION,
186
+ activeProfile: health.activeProfile,
72
187
  platform: process.platform,
73
188
  installerUrl: INSTALLER_URL,
189
+ releaseUrl: RELEASE_URL,
74
190
  repoUrl: REPO_URL,
75
191
  health,
76
192
  snapshots,
@@ -84,46 +200,102 @@ function buildRouteTable(ctx) {
84
200
  }
85
201
  },
86
202
  },
87
- {
88
- path: `${API_BASE}/open`,
89
- handler: async (req, res) => {
90
- if (!isRequestAllowed(ctx, req, res)) return
91
- const method = String((req && req.method) || '').toUpperCase()
92
- if (method !== 'POST') {
93
- sendJson(res, 405, { ok: false, error: 'method_not_allowed' })
94
- return
95
- }
96
- try {
97
- const result = openGuard({ launch: true })
98
- sendJson(res, 200, {
99
- ok: true,
100
- platform: process.platform,
101
- ...result,
102
- })
103
- } catch (err) {
104
- sendJson(res, 500, {
105
- ok: false,
106
- error: err && err.message ? String(err.message) : 'internal_error',
107
- })
108
- }
109
- },
110
- },
203
+
204
+ makePostRoute(ctx, '/open', async () => {
205
+ const res = openGuard({ launch: true })
206
+ return {
207
+ ok: true,
208
+ platform: process.platform,
209
+ ...res,
210
+ }
211
+ }),
212
+
213
+ makePostRoute(ctx, '/snapshots/create', async (body) => {
214
+ const target = resolveRouteTarget(body.target, hostProfile)
215
+ if (!target) return { ok: false, error: '仅支持 web 或 desktop 档案' }
216
+ const reason = typeof body.reason === 'string' ? body.reason.slice(0, 120) : ''
217
+ return createSnapshot(resolveDshHome(), target, 'manual', reason)
218
+ }),
219
+
220
+ makePostRoute(ctx, '/snapshots/restore-config', async (body) => {
221
+ const snapshotId = typeof body.snapshotId === 'string' ? body.snapshotId.trim() : ''
222
+ return restoreSnapshotConfig(resolveDshHome(), locateGuardInstallation(), snapshotId)
223
+ }),
224
+
225
+ makePostRoute(ctx, '/snapshots/pin', async (body) => {
226
+ const snapshotId = typeof body.snapshotId === 'string' ? body.snapshotId.trim() : ''
227
+ const pinned = Boolean(body.pinned)
228
+ const pinLabel = typeof body.pinLabel === 'string' ? body.pinLabel : ''
229
+ return pinSnapshot(resolveDshHome(), snapshotId, pinned, pinLabel)
230
+ }),
231
+
232
+ makePostRoute(ctx, '/toggle-entry', async (body) => {
233
+ const target = resolveRouteTarget(body.target, hostProfile)
234
+ if (!target) return { ok: false, error: '仅支持 web 或 desktop 档案' }
235
+ const id = typeof body.id === 'string' ? body.id.trim() : ''
236
+ const disabled = Boolean(body.disabled)
237
+ return togglePatchEntry(resolveDshHome(), target, id, disabled, locateGuardInstallation())
238
+ }),
239
+
240
+ makePostRoute(ctx, '/repair-links', async (body) => {
241
+ const target = resolveRouteTarget(body.target, hostProfile)
242
+ if (!target) return { ok: false, error: '仅支持 web 或 desktop 档案' }
243
+ return repairBrokenModuleLinks(resolveDshHome(), target)
244
+ }),
245
+
246
+ makePostRoute(ctx, '/mcp/probe', async (body) => {
247
+ const target = resolveRouteTarget(body.target, hostProfile)
248
+ if (!target) return { ok: false, error: '仅支持 web 或 desktop 档案' }
249
+ const health = inspectHealth({ activeProfile: target, ctx })
250
+ return await probeMcpServers(resolveDshHome(), health.extensions, target)
251
+ }),
252
+
253
+ makePostRoute(ctx, '/mcp/timeout', async (body) => {
254
+ const target = resolveRouteTarget(body.target, hostProfile)
255
+ if (!target) return { ok: false, error: '仅支持 web 或 desktop 档案' }
256
+ const id = typeof body.id === 'string' ? body.id.trim() : ''
257
+ return updateMcpTimeout(resolveDshHome(), target, id, body.timeoutMs, locateGuardInstallation())
258
+ }),
259
+
260
+ makePostRoute(ctx, '/skills/toggle', async (body) => {
261
+ const skillId = typeof body.skillId === 'string' ? body.skillId.trim() : ''
262
+ const changes = {}
263
+ if (typeof body.modelVisible === 'boolean') changes.modelVisible = body.modelVisible
264
+ if (typeof body.userInvocable === 'boolean') changes.userInvocable = body.userInvocable
265
+ const expectedFingerprint = typeof body.fingerprint === 'string' ? body.fingerprint : undefined
266
+ return toggleSkillVisibility(resolveDshHome(), skillId, changes, { expectedFingerprint, activeProfile: hostProfile })
267
+ }),
268
+
269
+ makePostRoute(ctx, '/credential-key', async (body) => {
270
+ const key = typeof body.key === 'string' ? body.key : ''
271
+ const value = typeof body.value === 'string' ? body.value : ''
272
+ const res = upsertCredentialKey(resolveDshHome(), key, value)
273
+ if (!res.ok) return res
274
+ // Strict one-way write: never echo secret value or partial characters back over HTTP.
275
+ return {
276
+ ok: true,
277
+ key: res.key,
278
+ path: res.path,
279
+ created: Boolean(res.created),
280
+ }
281
+ }),
111
282
  ]
112
283
  }
113
284
 
114
- function buildToolDefinitions() {
285
+ function buildToolDefinitions(ctx, activeProfile = detectActiveProfile({ ctx })) {
286
+ const hostProfile = normalizeProfileTarget(activeProfile) || 'web'
115
287
  return [
116
288
  defineTool({
117
289
  name: 'dsh_guard_status',
118
290
  description:
119
- 'Read-only health check for DSH Web and Desktop profiles: checks package.json bundle/dependency drift, '
120
- + 'cordis.patch.yml structural integrity, masked .credentials.yaml key readiness (never reads or exposes secret values), '
121
- + 'and local Windows DSHGuard supervisor installation status.',
291
+ 'Check the active DSH profile (Desktop or Web) in-process: checks package.json dependency drift, broken module links, '
292
+ + 'cordis.patch.yml plugins/MCP/llm-pi-ai readiness, masked .credentials.yaml key readiness (never exposes secret values), '
293
+ + 'startup context load summary, and local snapshot availability.',
122
294
  parameters: {
123
295
  target: {
124
296
  type: 'string',
125
- enum: ['all', 'web', 'desktop'],
126
- description: 'Which DSH profile track to inspect (default: all).',
297
+ enum: ['web', 'desktop'],
298
+ description: 'Optional profile track override ("web" or "desktop"). Defaults to the active runtime track.',
127
299
  },
128
300
  },
129
301
  output: {
@@ -141,7 +313,8 @@ function buildToolDefinitions() {
141
313
  render: (_args, value) => [{ type: 'text', text: value.summary }],
142
314
  },
143
315
  async execute(args = {}) {
144
- const report = inspectHealth({ target: args.target })
316
+ const t = normalizeProfileTarget(args.target) || hostProfile
317
+ const report = inspectHealth({ activeProfile: t, ctx })
145
318
  return {
146
319
  healthy: report.healthy,
147
320
  issuesCount: report.issuesCount,
@@ -152,16 +325,94 @@ function buildToolDefinitions() {
152
325
  },
153
326
  }),
154
327
 
328
+ defineTool({
329
+ name: 'dsh_guard_context_audit',
330
+ description:
331
+ 'Read-only L0 audit of startup context footprint for the active DSH profile: counts active MCP servers, '
332
+ + 'model-visible Skills (~/.dsh/skills, ~/.agents/skills, plugin skills), and permanent prompt file sizes.',
333
+ parameters: {
334
+ target: {
335
+ type: 'string',
336
+ enum: ['web', 'desktop'],
337
+ description: 'Optional profile override ("web" or "desktop"). Defaults to the active runtime track.',
338
+ },
339
+ },
340
+ output: {
341
+ schema: {
342
+ type: 'object',
343
+ additionalProperties: false,
344
+ properties: {
345
+ level: { type: 'string', required: true },
346
+ estimatedBaseTokens: { type: 'integer', required: true },
347
+ recommendations: { type: 'array', required: true, items: { type: 'string' } },
348
+ summary: { type: 'string', required: true },
349
+ },
350
+ },
351
+ render: (_args, value) => [{ type: 'text', text: value.summary }],
352
+ },
353
+ async execute(args = {}) {
354
+ const dshHome = resolveDshHome()
355
+ const t = normalizeProfileTarget(args.target) || hostProfile
356
+ const health = inspectHealth({ dshHome, activeProfile: t, ctx })
357
+ const audit = inspectContextAudit(dshHome, health, t)
358
+ const p = audit.profile || audit.profiles[0] || { level: 'light', estimatedBaseTokens: 0 }
359
+ return {
360
+ level: p.level,
361
+ estimatedBaseTokens: p.estimatedBaseTokens,
362
+ recommendations: audit.recommendations,
363
+ summary: formatContextAuditText(audit),
364
+ }
365
+ },
366
+ }),
367
+
368
+ defineTool({
369
+ name: 'dsh_guard_mcp_probe',
370
+ description:
371
+ 'Read-only L0 probe for configured MCP servers on the active DSH profile: checks loopback TCP reachability '
372
+ + '(localhost/127.0.0.1/::1 only, SSRF-safe) for HTTP/SSE servers and verifies executable/script paths on disk for stdio servers.',
373
+ parameters: {
374
+ target: {
375
+ type: 'string',
376
+ enum: ['web', 'desktop'],
377
+ description: 'Optional profile override ("web" or "desktop"). Defaults to the active runtime track.',
378
+ },
379
+ },
380
+ output: {
381
+ schema: {
382
+ type: 'object',
383
+ additionalProperties: false,
384
+ properties: {
385
+ total: { type: 'integer', required: true },
386
+ activeCount: { type: 'integer', required: true },
387
+ unhealthyCount: { type: 'integer', required: true },
388
+ summary: { type: 'string', required: true },
389
+ },
390
+ },
391
+ render: (_args, value) => [{ type: 'text', text: value.summary }],
392
+ },
393
+ async execute(args = {}) {
394
+ const dshHome = resolveDshHome()
395
+ const t = normalizeProfileTarget(args.target) || hostProfile
396
+ const health = inspectHealth({ dshHome, activeProfile: t, ctx })
397
+ const probe = await probeMcpServers(dshHome, health.extensions, t)
398
+ return {
399
+ total: probe.total,
400
+ activeCount: probe.activeCount,
401
+ unhealthyCount: probe.unhealthyCount,
402
+ summary: formatMcpProbeText(probe),
403
+ }
404
+ },
405
+ }),
406
+
155
407
  defineTool({
156
408
  name: 'dsh_guard_snapshots',
157
409
  description:
158
- 'Read-only list of pre-change DSHGuard configuration and plugin snapshots stored on this Windows machine '
159
- + '(separated by Web and Desktop tracks).',
410
+ 'List local DSH configuration snapshots for the active profile track with live diff and pin status.',
160
411
  parameters: {
161
412
  target: {
162
413
  type: 'string',
163
- enum: ['all', 'web', 'desktop'],
164
- description: 'Filter snapshots by track (default: all).',
414
+ enum: ['web', 'desktop'],
415
+ description: 'Optional profile filter ("web" or "desktop"). Defaults to the active runtime track.',
165
416
  },
166
417
  limit: {
167
418
  type: 'integer',
@@ -182,7 +433,8 @@ function buildToolDefinitions() {
182
433
  render: (_args, value) => [{ type: 'text', text: value.summary }],
183
434
  },
184
435
  async execute(args = {}) {
185
- const report = inspectSnapshots({ target: args.target, limit: args.limit })
436
+ const t = normalizeProfileTarget(args.target) || hostProfile
437
+ const report = inspectSnapshots({ target: t, limit: args.limit })
186
438
  return {
187
439
  guardInstalled: report.guardInstalled,
188
440
  total: report.total,
@@ -192,11 +444,54 @@ function buildToolDefinitions() {
192
444
  },
193
445
  }),
194
446
 
447
+ defineTool({
448
+ name: 'dsh_guard_backup',
449
+ description:
450
+ 'Create a safe configuration snapshot (cordis.patch.yml, cordis.yml, package.json, settings.yaml; never copies .credentials.yaml) directly inside the companion plugin.',
451
+ parameters: {
452
+ target: {
453
+ type: 'string',
454
+ enum: ['web', 'desktop'],
455
+ description: 'Which standard profile config files to back up ("web" or "desktop"). Defaults to active runtime track.',
456
+ },
457
+ reason: {
458
+ type: 'string',
459
+ description: 'Short label for this manual backup snapshot.',
460
+ },
461
+ },
462
+ output: {
463
+ schema: {
464
+ type: 'object',
465
+ additionalProperties: false,
466
+ properties: {
467
+ ok: { type: 'boolean', required: true },
468
+ snapshotId: { type: 'string', required: true },
469
+ itemCount: { type: 'integer', required: true },
470
+ summary: { type: 'string', required: true },
471
+ },
472
+ },
473
+ render: (_args, value) => [{ type: 'text', text: value.summary }],
474
+ },
475
+ async execute(args = {}) {
476
+ const rawTarget = typeof args.target === 'string' ? args.target.trim() : ''
477
+ const target = rawTarget ? normalizeProfileTarget(rawTarget) : hostProfile
478
+ if (!target) {
479
+ return { ok: false, snapshotId: '', itemCount: 0, summary: '仅支持 web 或 desktop 标准档案,无法创建快照。' }
480
+ }
481
+ const res = createSnapshot(resolveDshHome(), target, 'manual', args.reason || 'Agent 手动配置备份')
482
+ return {
483
+ ok: Boolean(res.ok),
484
+ snapshotId: res.snapshot.id,
485
+ itemCount: res.snapshot.itemCount,
486
+ summary: `已生成配置快照 ${res.snapshot.id}(${res.snapshot.target} · ${res.snapshot.itemCount} 个配置文件,已自动排除 .credentials.yaml)。`,
487
+ }
488
+ },
489
+ }),
490
+
195
491
  defineTool({
196
492
  name: 'dsh_guard_open',
197
493
  description:
198
- 'Locate the local Windows out-of-band DSHGuard desktop supervisor executable or return its official release download link. '
199
- + 'Pass launch=true only when the user asks to open the DSHGuard GUI window for snapshot rollback, credential vault, or CC Switch import.',
494
+ 'Locate or launch the optional Windows out-of-band DSHGuard desktop supervisor when process isolation, Windows DPAPI vault, or running-bundle rollback is needed.',
200
495
  parameters: {
201
496
  launch: {
202
497
  type: 'boolean',
@@ -217,7 +512,7 @@ function buildToolDefinitions() {
217
512
  },
218
513
  render: (_args, value) => [{
219
514
  type: 'text',
220
- text: value.message + (value.installed ? '' : `\n安装包直链:${value.installerUrl}\n发布页:${value.releaseUrl}`),
515
+ text: value.message + (value.installed ? '' : `\n安装包:${value.installerUrl}\n发布页:${value.releaseUrl}`),
221
516
  }],
222
517
  },
223
518
  async execute(args = {}) {
@@ -235,8 +530,15 @@ function buildToolDefinitions() {
235
530
  }
236
531
 
237
532
  export function apply(ctx) {
533
+ let activeProfile = 'web'
534
+ try {
535
+ activeProfile = detectActiveProfile({ ctx })
536
+ } catch {
537
+ activeProfile = detectActiveProfile()
538
+ }
539
+
238
540
  ctx.inject(['tools'], (toolsCtx) => {
239
- const definitions = buildToolDefinitions()
541
+ const definitions = buildToolDefinitions(ctx, activeProfile)
240
542
  const disposers = definitions.map((def) => toolsCtx.tools.register(def))
241
543
  toolsCtx.effect(() => () => {
242
544
  for (const dispose of disposers) {
@@ -248,21 +550,44 @@ export function apply(ctx) {
248
550
  ctx.inject(['commands'], (cmdCtx) => {
249
551
  const dispose = cmdCtx.commands.register({
250
552
  name: 'guard',
251
- description: 'DSH 守护壳伴生命令:/guard [status|snapshots|open]',
252
- input: { hint: '[status|snapshots|open]' },
553
+ description: 'DSH 守护伴生命令:/guard [status|context|mcp|snapshots|backup [web|desktop]|open]',
554
+ input: { hint: '[status|context|mcp|snapshots|backup|open]' },
253
555
  async handler(invocation) {
254
- const sub = String((invocation && invocation.rawInput) || '').trim().toLowerCase()
556
+ const raw = String((invocation && invocation.rawInput) || '').trim()
557
+ const parts = raw ? raw.toLowerCase().split(/\s+/) : []
558
+ const sub = parts[0] || ''
559
+ if (sub === 'context' || sub === 'ctx') {
560
+ const dshHome = resolveDshHome()
561
+ const target = normalizeProfileTarget(parts[1]) || activeProfile
562
+ const health = inspectHealth({ dshHome, activeProfile: target, ctx })
563
+ return { kind: 'success', text: formatContextAuditText(inspectContextAudit(dshHome, health, target)) }
564
+ }
565
+ if (sub === 'mcp' || sub === 'probe') {
566
+ const dshHome = resolveDshHome()
567
+ const target = normalizeProfileTarget(parts[1]) || activeProfile
568
+ const health = inspectHealth({ dshHome, activeProfile: target, ctx })
569
+ const probe = await probeMcpServers(dshHome, health.extensions, target)
570
+ return { kind: 'success', text: formatMcpProbeText(probe) }
571
+ }
255
572
  if (sub === 'snapshots' || sub === 'snap') {
256
- return { kind: 'success', text: formatSnapshotsText(inspectSnapshots({})) }
573
+ return { kind: 'success', text: formatSnapshotsText(inspectSnapshots({ target: activeProfile })) }
574
+ }
575
+ if (sub === 'backup') {
576
+ const t = normalizeProfileTarget(parts[1]) || activeProfile
577
+ const res = createSnapshot(resolveDshHome(), t, 'manual', '命令 /guard backup 创建')
578
+ return {
579
+ kind: 'success',
580
+ text: `已创建配置快照 ${res.snapshot.id}(${res.snapshot.target} · ${res.snapshot.itemCount} 个文件,已自动跳过 .credentials.yaml)`,
581
+ }
257
582
  }
258
583
  if (sub === 'open') {
259
584
  const res = openGuard({ launch: true })
260
585
  return {
261
586
  kind: 'success',
262
- text: res.message + (res.installed ? '' : `\n安装包直链:${res.installerUrl || INSTALLER_URL}\n发布页:${res.releaseUrl}`),
587
+ text: res.message + (res.installed ? '' : `\n安装包:${res.installerUrl || INSTALLER_URL}\n发布页:${res.releaseUrl}`),
263
588
  }
264
589
  }
265
- return { kind: 'success', text: formatHealthText(inspectHealth({})) }
590
+ return { kind: 'success', text: formatHealthText(inspectHealth({ activeProfile, ctx })) }
266
591
  },
267
592
  })
268
593
  if (typeof cmdCtx.effect === 'function' && typeof dispose === 'function') {
@@ -272,7 +597,7 @@ export function apply(ctx) {
272
597
 
273
598
  ctx.inject(['webServer'], (webCtx) => {
274
599
  if (!webCtx || !webCtx.webServer || typeof webCtx.webServer.register !== 'function') return
275
- for (const route of buildRouteTable(ctx)) {
600
+ for (const route of buildRouteTable(ctx, activeProfile)) {
276
601
  if (typeof webCtx.effect === 'function') {
277
602
  webCtx.effect(() => webCtx.webServer.register(route), `dsh-guard: route ${route.path}`)
278
603
  } else {
@@ -285,10 +610,28 @@ export function apply(ctx) {
285
610
  export {
286
611
  apply as default,
287
612
  name,
613
+ createSnapshot,
614
+ detectActiveProfile,
615
+ discoverProfiles,
616
+ formatContextAuditText,
617
+ formatHealthText,
618
+ formatMcpProbeText,
619
+ formatSnapshotsText,
620
+ inspectContextAudit,
288
621
  inspectHealth,
622
+ inspectSkills,
289
623
  inspectSnapshots,
290
624
  locateGuardInstallation,
625
+ normalizeProfileTarget,
291
626
  openGuard,
292
- formatHealthText,
293
- formatSnapshotsText,
627
+ pinSnapshot,
628
+ probeMcpServers,
629
+ readAuditLog,
630
+ repairBrokenModuleLinks,
631
+ restoreSnapshotConfig,
632
+ togglePatchEntry,
633
+ toggleSkillVisibility,
634
+ updateMcpTimeout,
635
+ upsertCredentialKey,
636
+ validateProfileName,
294
637
  }