Skip to main content
P

dsh-footgun-guard

penglinchina/dsh-footgun-guard

A GuardList guard shipped as a DeepSeek Harness plugin: bundles 80 known footguns — code patterns and deliverable quality — as a skill, scans edited files and feeds findings back to the model, and can block writes that still contain error-level findings.

Install

dsh plugin --profile web add github:penglinchina/dsh-footgun-guard

README

FootgunGuard · DSH plugin

中文 · English

GuardList 守卫,以 DeepSeek Harness 插件的形式分发:把 80 条已知 footgun(代码写法 + 交付物质量)打包成技能注入会话,编辑代码后自动扫描并把发现回灌给模型,可选在写入前拦截。 A GuardList guard shipped as a DeepSeek Harness plugin: bundles 80 known footguns — code patterns and deliverable quality — as a skill, scans edited files and feeds findings back to the model, and can block writes that still contain error-level findings.

Base repository / 基础仓库: https://github.com/PenglinChina/footgun-guard


中文

它是什么

不是一份"注意事项"清单,而是四层结构——能判定的交给机器,判不了的交给流程,每一层都诚实说明自己覆盖不到什么。

层是什么在插件里的位置
① 指令层技能(SKILL.md + reference/*.md)插件激活时通过 ctx.skills.register() 注入会话
② 测量层确定性检测器(80 条里 61 条:19 mechanical + 42 heuristic)src/rules/*.js + src/engine/,零依赖、无 AST、无网络
③ 反馈层编辑后回灌index.js 监听 tools/post-execute,发现折进 additionalContexts,永远非阻塞
④ 门禁层可选写入前拦截 + CI 退出码tools/pre-execute(默认关);footgun detect 退出码 2、--sarif、--github

安装

DSH Plugins 页 → Add plugin → 选本目录(或 plugin_manager install_bundle,target 为本目录绝对路径)。装好后:

  • 会话技能目录里出现 footgun-guard,模型可随时加载;
  • 用 write / edit / apply_patch / str_replace_editor 改完代码,发现会被自动推回上下文。

本地开发时也可以直接把本目录 link 进 profile 的 node_modules 并在 package.json 的 dsh.profile.bundles 里加上 dsh-footgun-guard。

发布到 npm 后(本文档写作时尚未发布),install_bundle 的 target 可以只写包名 dsh-footgun-guard。

配置

在 profile 的 cordis.patch.yml 里覆盖插件行(patch 整体替换 config,要写全):

- id: footgun-guard
  name: dsh-footgun-guard
  config:
    gate: true
    gateSeverity: error
字段默认含义
gatefalse写入前是否拦截 error 级发现
gateSeverityerror拦截哪种严重度

门禁默认关闭:让 agent 无法完成合法修改,比漏报一次更糟。

快速开始

node src/cli.js detect .                  # 扫当前目录(0 干净 / 2 有发现 / 1 无法扫描)
node src/cli.js detect src/ --json        # 机器可读
node src/cli.js context                   # 常驻指令块(第①层)
node src/cli.js list --manual             # 列出没有检测器的条目
node src/cli.js explain c-unsafe-string-fn
node src/cli.js doctor                    # 规则完整性、技能包、安装状态

诚实边界

  • 80 条里 19 条无法机械判定:4 条代码层共通项(幻觉 API、伪安全防御、边界条件省略、测试同源偏差)需要读需求、读注释意图、核对真实 API 签名;8 条交付物层共通项(目标替换、语义漂移、静默接受、伪修复、架构失配、范围蔓延、过度自信、未验证降级)需要对照任务目标与汇报;7 条语言特有项要么依赖编译器(RUST-1~3 由 rustc 编译期拦截),要么需要跨语句语义(C-9/CPP-7 有符号溢出 UB、CS-11 P/Invoke 封送、JAVA-3 泛型擦除)。
  • Rust 的 6 条大多已被 rustc 在编译期强制,检测器只补 3 条运行时语义(自引用结构体、RefCell 重复借用、Drop 中 panic)。
  • 已知漏报:注释/字符串里的代码(被掩码)、宏展开、跨文件类型推断、.h 一律按 C 处理。
  • 已知假阳性:所有 tier: 'heuristic' 的规则,宁可少报。
  • 插件只是"把事实放到模型眼前",不保证模型一定修。

detect 的输出会明说"发现是不完全统计,不是健康证明"。

需求源:两份 GuardList

文件作用
GuardList_cn.txt中文需求:每条 footgun 的"问题"与"检查"
GuardList_en.txt英文同构版:同样的 ID、同样的顺序

格式是两级标题 + 固定字段:

## c · C

### C-8 strcpy 与 \0
- 问题:`strcpy`/`strcat`/`sprintf` 不看目标容量,多一个字节就是缓冲区溢出。
- 检查:改用 `snprintf`/`strlcpy`,并显式保证容量够放结尾的 \0。
  • ## <语言> 的键必须与 src/engine/lang.js 一致;
  • ### <ID> <标题> 的 ID 是稳定标识(C-8、CS-3、RUST-5),规则用它对应,改名等于断链;
  • 每条必须有"问题"和"检查"两行;英文版用 - Problem: / - Check:;
  • 两版必须同构,由 tests/guardlist.test.js 强制。

结构

dsh-footgun-guard/
  package.json                 DSH bundle manifest(dsh.bundle.patch + exports)
  cordis.patch.yml             插件行(id: footgun-guard)
  index.js                     插件入口:技能注册 + post-execute + 可选 pre-execute
  locale/{zh,en}.json          插件展示元数据
  icon.svg                     插件图标
  docs/DETAIL.md               Plugins 页的详情文档
  src/                         唯一真源:检测引擎 + 规则 + CLI
    engine/                    掩码器、上下文、语言判定、扫描
    rules/                     9 个规则包
    commands/hook.js           宿主钩子的文本渲染(footgun hook 命令)
    cli.js                     命令路由与第④层
  skill/                       唯一真源:给模型看的文本
    SKILL.md                   模板(含 {{rules}} / {{manual}} / {{cli}} 占位符)
    reference/                 各语言条目(gen-docs 生成)+ common/review/audit(手写)
    bundle/footgun-guard/      ← 生成物:插件实际注册的技能包(勿手改)
  GuardList_cn.txt / _en.txt   需求源(双语同构,测试强制)
  fixtures/                    每语言"有 footgun"与"干净"的样本
  tests/                       node --test
  scripts/                     build.mjs / gen-docs.mjs / test.mjs / smoke.mjs

开发

node scripts/gen-docs.mjs    # 从规则注册表生成 skill/reference/<lang>.md
node scripts/build.mjs       # 渲染并打包 skill/bundle/footgun-guard/
node scripts/build.mjs --check
node scripts/test.mjs        # 93 passed
node src/cli.js detect src   # 自扫应 0 发现

改规则改 src/rules/,改技能文本改 skill/SKILL.md,然后重跑 gen-docs + build;build --check 会拦住"改了源没重建"的漂移。

CI

- run: node src/cli.js detect --sarif src/ > footgun.sarif || test $? -eq 2
- uses: github/codeql-action/upload-sarif@v3
  with: { sarif_file: footgun.sarif, category: footgun-guard }

English

What it is

Not a checklist of reminders but a four-layer guard — machine-checkable patterns go to the detector, judgment calls go to the playbook, and every layer states what it cannot cover.

LayerWhatWhere
① Instructionsskill (SKILL.md + reference/*.md)registered into the session via ctx.skills.register() on activation
② Measurementdeterministic detector (61 of 80: 19 mechanical + 42 heuristic)src/rules/*.js + src/engine/, zero deps, no AST, no network
③ Feedbackpost-edit findingsindex.js on tools/post-execute folds findings into additionalContexts; never blocks
④ Gateoptional pre-write blocking + CI exit codetools/pre-execute (off by default); footgun detect exits 2, --sarif, --github

Install

DSH Plugins → Add plugin → pick this directory (or plugin_manager install_bundle with its absolute path). Afterwards the footgun-guard skill appears in the session catalog, and edits made with write / edit / apply_patch / str_replace_editor get findings fed back automatically.

For local development you can also link this directory into the profile's node_modules and add dsh-footgun-guard to dsh.profile.bundles.

Once published to npm (not yet at the time of writing), install_bundle accepts the bare package name dsh-footgun-guard as its target.

Configuration

Override the plugin row in the profile's cordis.patch.yml (a patch replaces the whole config, so restate every key):

- id: footgun-guard
  name: dsh-footgun-guard
  config:
    gate: true
    gateSeverity: error
FieldDefaultMeaning
gatefalseblock writes whose target still has error-severity findings
gateSeverityerrorseverity to block

The gate is off by default: breaking a legitimate edit is worse than missing one finding.

Quick start

node src/cli.js detect .                  # 0 clean / 2 findings / 1 unscannable target
node src/cli.js detect src/ --json
node src/cli.js context                   # always-on directive block (layer ①)
node src/cli.js list --manual             # items without a detector
node src/cli.js explain c-unsafe-string-fn
node src/cli.js doctor                    # rule coverage, skill bundle, install state

Honest limits

  • 19 of the 80 rules cannot be decided mechanically: 4 code-level common items (hallucinated APIs, fake defenses, omitted edge cases, tests mirroring the implementation) need the requirements, comment intent, and real API signatures; 8 deliverable-level common items (goal substitution, semantic drift, silent acceptance, fake fix, architecture mismatch, scope creep, overconfident completion, silent downgrade of "unverified") need the task goal and the report; 7 language-specific items either depend on the compiler (RUST-1~3 are enforced by rustc) or need cross-statement semantics (C-9/CPP-7 signed-overflow UB, CS-11 P/Invoke marshaling, JAVA-3 type erasure).
  • Most Rust rules are already enforced by rustc; the detector only adds 3 runtime semantics (self-referential structs, RefCell double borrow, panic in Drop).
  • Known misses: code in comments/strings (masked), macro expansion, cross-file type inference, .h treated as C.
  • Known false positives: every tier: 'heuristic' rule; they prefer missing to crying wolf.
  • The plugin puts facts in front of the model; it does not guarantee the model fixes them.

Requirement source: two GuardLists

FileRole
GuardList_cn.txtChinese requirements: "problem" and "check" per footgun
GuardList_en.txtIsomorphic English version: same IDs, same order

The format is two heading levels plus fixed fields; the parser is a single loop. ## <lang> keys must match src/engine/lang.js; ### <ID> <title> IDs are stable (C-8, CS-3, RUST-5); every item needs a problem and a check line (- Problem: / - Check: in English); the two files must stay isomorphic, enforced by tests/guardlist.test.js.

Layout

dsh-footgun-guard/
  package.json                 DSH bundle manifest (dsh.bundle.patch + exports)
  cordis.patch.yml             plugin row (id: footgun-guard)
  index.js                     entry: skill registration + post-execute + optional pre-execute
  locale/{zh,en}.json          display metadata
  icon.svg                     plugin icon
  docs/DETAIL.md               detail document shown in Plugins
  src/                         single source of truth: engine + rules + CLI
  skill/                       single source of truth for model-facing text
    SKILL.md                   template ({{rules}} / {{manual}} / {{cli}})
    reference/                 per-language items (gen-docs) + common/review/audit (hand-written)
    bundle/footgun-guard/      generated skill package the plugin registers (do not edit)
  GuardList_cn.txt / _en.txt   requirement source
  fixtures/                    one "bad" and one "clean" sample per language
  tests/                       node --test
  scripts/                     build.mjs / gen-docs.mjs / test.mjs / smoke.mjs

Development

node scripts/gen-docs.mjs    # regenerate skill/reference/<lang>.md from the registry
node scripts/build.mjs       # render and package skill/bundle/footgun-guard/
node scripts/build.mjs --check
node scripts/test.mjs        # 93 passed
node src/cli.js detect src   # self-scan should stay clean

Change rules in src/rules/, skill prose in skill/SKILL.md, then rerun gen-docs + build; build --check catches "edited the source but did not rebuild" drift.

CI

- run: node src/cli.js detect --sarif src/ > footgun.sarif || test $? -eq 2
- uses: github/codeql-action/upload-sarif@v3
  with: { sarif_file: footgun.sarif, category: footgun-guard }

Related plugins