dsh-barricade
Barricade: 编码 agent 的破坏性命令拦截闸门。在 rm -rf、git reset --hard 等命令真正落地前解析、判定并要求确认。dsh 插件 + 通用 CLI。
安装
npx -p @deepseek-ai/dsh dsh plugin --profile web add github:JohnXu22786/safety-net说明文档
阅读完整 README ↗作为命令行工具使用(可选)
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 }
}
| Field | Description |
|---|---|
level | relaxed (medium allowed) / balanced (medium asks) / vigilant (+ unparseable input asks as needed) |
failClosed | require confirmation even when a command cannot be parsed |
allowlist | prefix allowlist (git status allows git status --porcelain) |
overrides | adjust per-rule-id actions: allow / ask / deny / off; fatal rules cannot be downgraded |
rules | custom rules: command + optional subcommand + any arg match (short-flag unbinding supported) |
confirmation.timeoutSeconds | interactive confirmation timeout (seconds); timeout counts as deny; 0 means no timeout |
Environment variables (raise-only, never lower):
| Variable | Description |
|---|---|
BARRICADE_HOME | data directory (policy, audit logs), default ~/.barricade |
BARRICADE_POLICY | specify a user policy file path |
BARRICADE_LEVEL | raise the level (only takes effect when higher than the file level) |
BARRICADE_FAIL_CLOSED=1 | enable fail-closed |
BARRICADE_CONFIRM_TIMEOUT | confirmation timeout seconds |
BARRICADE_TOOLS | comma-separated list of tools the dsh plugin intercepts |
BARRICADE_NO_COLOR / NO_COLOR | disable colored output |