JohnXu22786/safety-net0

dsh-barricade

Barricade: 编码 agent 的破坏性命令拦截闸门。在 rm -rf、git reset --hard 等命令真正落地前解析、判定并要求确认。dsh 插件 + 通用 CLI。

包名
dsh-barricade
版本
0.1.0
许可证
MIT
最近更新
2026年8月16日

安装

$npx -p @deepseek-ai/dsh dsh plugin --profile web add github:JohnXu22786/safety-net

作为命令行工具使用(可选)

npm link # 之后可直接使用 barricade 命令


## Integrating with dsh (DeepSeek Harness)

This repository is a valid dsh bundle: `package.json` declares `dsh.bundle`, `cordis.patch.yml` is the config-layer patch, and `plugin.js` is the plugin entry point.

### Installing in DSH

```bash
dsh plugin --profile demo add github:JohnXu22786/safety-net

Loading


## CLI Usage

barricade [选项]

analyze [--json] 分析并输出判定(不执行;退出码恒 0) check [--json] [--quiet] 判定;放行退出 0,拦截退出 1 gate -- 分析 + 交互确认 + 执行 hook 见上文 stdin-hook 契约 policy --show [--json] 显示合并后的策略 policy --validate [--policy F] 校验策略文件 rules [--json] 列出内置规则 audit [--tail N] 查看审计记录

-c, --command --stdin 命令输入方式 --level --policy 临时等级 / 指定策略文件 --json --quiet --exit-on-block -h, --help -v, --version --tail


Examples:

```bash
barricade check -c "rm -rf /"                 # 退出 1,打印拦截原因
barricade analyze --json -c "git reset --hard"
barricade gate -- "npm run build"             # 终端下交互确认

Policy Configuration

Config files: user-level ~/.barricade/barricade.json (BARRICADE_HOME to change), project-level .barricade.json (current directory, takes precedence over user-level). Both are JSON; missing/corrupt fields rescue-fall back to defaults with a warning — a policy file can never interrupt your workflow.

{
  "version": 1,
  "level": "balanced",
  "failClosed": false,
  "allowlist": ["git status", "git log", "ls -la"],
  "overrides": { "git/tag-delete": "allow" },
  "rules": [
    {
      "id": "custom/dropdb-force",
      "command": "dropdb",
      "args": ["--force"],
      "severity": "high",
      "reason": "强制删除数据库不可恢复"
    }
  ],
  "confirmation": { "sessionMemory": true, "timeoutSeconds": 0 }
}
FieldDescription
levelrelaxed (medium allowed) / balanced (medium asks) / vigilant (+ unparseable input asks as needed)
failClosedrequire confirmation even when a command cannot be parsed
allowlistprefix allowlist (git status allows git status --porcelain)
overridesadjust per-rule-id actions: allow / ask / deny / off; fatal rules cannot be downgraded
rulescustom rules: command + optional subcommand + any arg match (short-flag unbinding supported)
confirmation.timeoutSecondsinteractive confirmation timeout (seconds); timeout counts as deny; 0 means no timeout

Environment variables (raise-only, never lower):

VariableDescription
BARRICADE_HOMEdata directory (policy, audit logs), default ~/.barricade
BARRICADE_POLICYspecify a user policy file path
BARRICADE_LEVELraise the level (only takes effect when higher than the file level)
BARRICADE_FAIL_CLOSED=1enable fail-closed
BARRICADE_CONFIRM_TIMEOUTconfirmation timeout seconds
BARRICADE_TOOLScomma-separated list of tools the dsh plugin intercepts
BARRICADE_NO_COLOR / NO_COLORdisable colored output