Ayle5678/dsh-auto-guard ↗★ 1

dsh-auto-guard

DSH Auto Guard: a Claude Code Auto Mode-like command approval mechanism that adds an LLM safety net on top of full access, with rules, caches, file tracker, and sensitive path gates. 适合需要在高权限模式下增加安全审计、敏感路径拦截和规则过滤的用户。

패키지
dsh-auto-guard
호환성
미검증
Harness peer 범위
^0.1.1-rc.2
Cordis peer 범위
^4.0.1
버전
0.1.3
라이선스
MIT
최근 업데이트
2026. 8. 26.

설치

$npx -p @deepseek-ai/dsh dsh plugin --profile web add github:Ayle5678/dsh-auto-guard

配置与界面

  • 启停即权限预设:对话框权限选择器选 auto-guard 预设即启用,选其他预设即停用,所有配置走设置页。
  • DSH 设置页:设置栏新增 “DSH Auto Guard” 页面,配置分组折叠展示,每个字段带说明;读写 ~/.dsh/settings.yaml 配置源。
  • 设置页维护动作:设置页提供“立即分析 / 查看规则 / 回滚 / 状态 / 清理审计日志 / 统计”按钮(Typert Remote)。
  • 直连审查端点 + API Key 管理:支持 apiBase 直连 OpenAI 兼容 chat/completions;API Key 解析顺序为环境变量 > 本地 secret 存储;设置页管理端点/模型/Key,UI 只显示打码值。
  • 无 UI 兜底:没有审批 UI 时,DSH 本身会把“需要确认(ask)”退化为拒绝(fail-closed)。
  • 规则可维护:默认规则存放在用户 .dsh 目录,用户可直接修改;用户覆盖规则与默认规则分层合并。
  • 裁决可见性:allow 通知只显示在页面、不进入上下文;规则放行(白名单 / 预授权)即使配置 notifyAllow: context 也强制只走页面;deny / ask 保留注入上下文;均可配置。

配置

配置以 DSH 设置体系为主:~/.dsh/settings.yaml 中 auto-guard: 命名空间;旧的 ~/.dsh/auto-guard/config.json 会在首次启动时一次性迁移,之后 settings.yaml 为唯一来源。DSH 设置栏的 “DSH Auto Guard” 页面可编辑全部用户配置字段。

auto-guard:
  # 启停由对话框权限选择器的 auto-guard 预设决定
  apiBase: ''                # 直连 OpenAI 兼容端点,留空走 DSH 内置模型路由
  apiKeyEnv: DEEPSEEK_API_KEY
  apiKey: ''                 # 本地 secret 存储,UI 只显示打码值
  apiKeyMasked: ''           # 非 secret 展示字段,服务端根据 apiKey 自动生成(如 sk-123*****321),不要手改
  provider: deepseek-official
  model: deepseek-v4-flash
  reasoningEffort: off
  fallbackProvider: deepseek-official
  fallbackModel: deepseek-v4-flash
  timeoutMs: 15000
  lowRiskTtlDays: 30
  mediumRiskTtlDays: 7
  onTimeout: deny            # deny | ask
  notifyCacheHit: true
  notifyLlmDecision: true
  notifyAllow: page          # page | context | off
  notifyDeny: context        # page | context | off
  notifyAsk: context         # page | context | off
  fileTrackerDefault: ask    # ask | deny
  fileTrackerWindowSec: 5
  sessionCacheSize: 256
  alwaysReviewCacheTtlMinutes: 30
  examineEnabled: false      # 审查日志开关
  auditPassword: ''          # 审计密码(secret,开启审查日志前必须设置)
  historyEnabled: false      # 运行时历史层开关
  autoAnalyzeEnabled: false  # 自动分析开关
  historyDays: 60            # 历史窗口(天)
  historyMinTotal: 4         # 历史命中最少总 allow
  historyMinLlm: 1           # 历史命中最少真实 LLM allow
  learnedCacheableMinTotal: 8     # 学习 cacheable 最少总 allow
  analyzeIntervalDays: 15    # 自动分析间隔(天)

rulesPath、defaultRulesPath、cachePath、auditDbPath、learnedRulesPath、learnedBackupPath、analyzeStatePath 属于内部路径,默认在 ~/.dsh/auto-guard/。若 DSH settings 服务不可用,插件会回退读写 config.json。

启停与配置入口

DSH 端控制走两处:

  1. 启停:对话框输入框的权限选择器 — 选 Auto Guard 预设启用(danger-full-access + ask),选其他预设停用。
  2. 配置:设置栏 → “DSH Auto Guard” 页面(端点、模型、API Key、通知路由、文件追踪、缓存 TTL、审查日志、历史/学习规则、维护按钮与统计)。

审查日志开启后写入 ~/.dsh/auto-guard/audit.db,查询用 sqlite3 直接读库;开启前需在设置页设置审计密码。

使用示例

普通复合命令

git status; git branch --show-current; git log --oneline -5

拆成子命令后,已白名单 / 已缓存的直接过;未匹配的子命令单独 LLM 审查,通过后进入缓存。

状态改变命令

高风险状态改变(export、alias、source、exec、trap、git config 等):

export PATH=/tmp/evil:$PATH && ls

因为出现 export,整条命令交给 LLM 审查,不会因为 ls 在白名单里就直接放行。

低风险目录导航(cd / pushd / popd):

cd /tmp && ls

只有所有子命令都是普通白名单、且无命令替换/管道/重定向/危险内容(含引号内)时才免审;否则仍整条交给 LLM。

目录删除

第一次执行:

rm -rf ./dist

会被拒绝并提示:

Directory deletion requires a reason. Reply with [删除理由] , then retry the same command.

重试时附带理由:

[删除理由] 清理构建产物

插件提取理由后,将“命令 + 理由”交给 reasoningEffort: low 的 LLM 复核一次;只有 allow 才放行,其余结果统一转人工确认。