dcg · pre-execution shell hook · three real intercepts
rm -rf / git reset --hard / DROP TABLE,dcg 在执行前挡住下面三张卡片来自同一次 dcg 0.6.6 官方二进制真实运行:三条不同类别的破坏命令通过 Claude Code / Codex CLI / Cursor 的 PreToolUse Bash hook 送进 dcg,全部在执行前被拦下,agent 收到 deny 后重新规划出安全替代。core.git / core.filesystem 一装完就在拦;database.postgresql 属于 opt-in pack,DROP TABLE 之前先 dcg init 把它加进 [packs] enabled。stderr 面板长度按规则变——有的规则把 EXPLANATION + Safer alternatives 一起印在里面,有的只印 Pattern / Pack / Regex;每张卡忠实分开标注 stderr、hook JSON、dcg explain 三种来源。
Agent 试图执行
$ git reset --hard HEAD~5dcg 面板 · stderr verbatim (EXPLANATION + Safer alternatives 直接印在面板里)
+----------------------------------------------------------------------------+ | | +----------------------------------------------------------------------------+ | git reset --hard HEAD~5 | | ^^^^^^^^^^^^^^^^ | | | | EXPLANATION: | | git reset --hard discards ALL uncommitted changes in your working | | directory AND staging area. This is one of the most dangerous git | | commands because changes that were never committed cannot be recovered | | by any means. | | | | Safer alternatives: | | - git reset --soft <ref>: Move HEAD but keep all changes staged | | - git reset --mixed <ref>: Move HEAD, unstage changes, keep working dir | | - git stash: Save changes before resetting | | | | | | | +----------------------------------------------------------------------------+
git stash push -m "wip" 存下未提交改动,再 git reset --soft HEAD~5 只挪 HEAD、保留 staging;跑之前先 git status && git diff 确认不会丢东西。
Agent 试图执行
$ rm -rf ./srcdcg 面板 · stderr verbatim (此规则不打 EXPLANATION,只印 Pattern / Pack / Regex — 与其他富规则不同)
+----------------------------------------------------------------------------+ | | +----------------------------------------------------------------------------+ | rm -rf ./src | | ^^^ | | | | | | | | | | | +----------------------------------------------------------------------------+ Learn more: $ dcg explain "rm -rf ./src" $ dcg allowlist add core.filesystem:rm-rf-general --project
hook JSON · agent 真读到的 (stdout permissionDecisionReason, 与 stderr 无关,一定有 Reason)
rm -rf is destructive and requires human approval. Explain what you want to delete and why, then ask the user to run the command manually. Matched destructive pattern core.filesystem:rm-rf-general. No additional explanation is available yet. See pack documentation for details. core.filesystem:rm-rf-general rm -rf ./src
dcg explain · 独立命令 (Suggestions 段, 比 stderr 面板更完整)
• Preview first: List contents first with `ls -la` to verify target
• Safer alternative: Use `rm -ri` for interactive confirmation of each file
$ rm -ri path/
• Workflow fix: Move to trash instead: `mv path ~/.local/share/Trash/`./src 是本仓库的应用源码目录、有 12 个已跟踪文件、无未提交改动),改用 rm -ri ./src 逐个确认;或 mv ./src ~/.local/share/Trash/ 走回收站;仍然想清空就请用户手动跑一次 rm -rf。
Agent 试图执行
$ psql -c "DROP TABLE users;"dcg 面板 · stderr verbatim (EXPLANATION + Safer alternatives 直接印在面板里)
+----------------------------------------------------------------------------+ | | +----------------------------------------------------------------------------+ | psql -c "DROP TABLE users;" | | ^^^^^^^^^^ | | | | EXPLANATION: | | DROP TABLE removes the table structure and ALL data: | | | | - All rows are deleted | | - Indexes, constraints, triggers are removed | | - Foreign keys referencing this table may fail | | - CASCADE drops dependent objects too | | | | IF EXISTS only prevents errors - it still drops the table! | | | | Backup table first: | | pg_dump -t tablename dbname > table_backup.sql | | | | | | | +----------------------------------------------------------------------------+
pg_dump -t users mydb > users_backup.sql;把行数与外键报回给用户(SELECT COUNT(*) FROM users),得到明确同意后由用户手动跑 DROP,或改用 TRUNCATE users RESTART IDENTITY + 保留 schema 的方案。