Skip to content
프로젝트

소개

GuardList guard for AI coding agents: 72 cross-language footguns covered by four layers — instruction skill, zero-dependency deterministic detector, post-edit feedback hook, and CI gate (SARIF/GitHub). Works for C, C++, C#, Java, JS/TS, Python, Go and Rust.

개발 도구

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
기록 수집 중
in 15 days
기록 수집 중
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

FootgunGuard

中文 · English

GuardList 守卫:让 AI 在写代码、查代码、读代码、交付汇报时避开 80 条已知 footgun(代码写法 + 交付物质量)。 A GuardList guard that keeps AI coding agents away from 80 known footguns — code patterns and deliverable quality — while writing, reviewing, or reading code.


中文

四层

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

层 是什么 在 FootgunGuard 里
① 指令层 提示词/playbook skill/SKILL.md、skill/reference/*.md、AGENTS.md:可判定的祈使句 + 反例 + 自检顺序
② 测量层 确定性检测器 src/rules/*.js + src/engine/:80 条里 61 条做成规则(19 条确定性 + 42 条启发式),19 条诚实留在人工清单(12 条共通 + 7 条语言特有);零依赖、无 AST、无网络
③ 反馈层 编辑后回灌 src/commands/hook.js + hooks/:hook 把发现以 additionalContext 塞回 agent,永远非阻塞
④ 门禁层 退出码/CI footgun detect 退出码 2、--sarif、--github:模型说什么都不影响合并结果

诚实边界(先读这段,再决定信多少)

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

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

快速开始

node src/cli.js detect .              # 扫当前目录
node src/cli.js detect src/ --json    # 机器可读
node src/cli.js context               # 打印给 agent 的常驻指令块
node src/cli.js list --manual         # 列出没有检测器的条目
node src/cli.js explain c-unsafe-string-fn   # 查一条规则
node src/cli.js doctor                # 自检:规则完整性、hook 接线

退出码:0 干净 / 2 有发现 / 1 有目标无法扫描。

接到 agent 上

DSH:把 AGENTS.md 放进项目根(DSH 会读进首个请求),或安装 hooks/dsh/ 插件拿到编辑后自动提醒。

Claude Code:把 hooks/claude-settings.json 的内容合并进 .claude/settings.json;或把 skill/ 复制到 .claude/skills/footgun-guard/。

一条命令装技能(仓库自带安装器,复制的是自包含的宿主目录):

node scripts/install.mjs --host claude              # 装到 <当前项目>/.claude/skills/footgun-guard
node scripts/install.mjs --host dsh --scope global  # 装到 ~/.dsh/skills/

--host 可用:claude / cursor / dsh / agents / codex / github / gemini / kiro / opencode / pi / omp / qoder / trae / trae-cn / rovodev / vibe / veto / grok / antigravity / hermes / devin。

其它宿主:把 AGENTS.md 放进项目(instruction 层),把 footgun hook 接到该宿主的 post-tool-use 事件。

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 }

2 仍然上传日志(有发现);1(有目标扫不了)会让这一步失败。包尚未发布到 npm,所以这里用仓库内路径;发布后 npx footgun 可替换 node src/cli.js。

需求源:两份 GuardList

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

格式是两级标题 + 固定字段,用一个 for 循环就能解析:

## 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 强制:ID 缺一个、多一个、顺序不同都会红。

为什么分两版而不是一份双语表格:英文版是给英文项目/英文模型的真实输入,不是翻译副产品;两版同构由测试保证,不靠人自觉。

结构

GuardList_cn.txt / GuardList_en.txt   需求源(双语同构,测试强制)
src/                             唯一真源:检测引擎 + 规则
  engine/        掩码器(剥注释与字符串)、上下文、语言判定、扫描
  rules/         9 个规则包,一条一个 detect()
  commands/hook.js  第③层
  cli.js         第④层与命令路由
skill/                           唯一真源:给模型看的文本
  SKILL.md       第①层入口(含 {{cli}} 占位符)
  reference/     各语言条目(由 scripts/gen-docs.mjs 从注册表生成)+ common/review/audit(手写)
scripts/
  build.mjs      把上面两者生成为 20 个宿主目录
  gen-docs.mjs   从规则注册表生成 reference/<lang>.md
  install.mjs    把某个宿主目录复制到项目/全局技能路径
  smoke.mjs      单语言调规则
cli 生成物                        见下节,勿手改
hooks/           Claude Code 设置片段、DSH 插件
fixtures/        每条语言一份"有 footgun"和一份"干净"的样本
tests/           node --test

分发:20 个宿主目录

和 Impeccable 一样的做法——一份源码,生成全部宿主目录,产物提交进仓库,这样 git clone 完就能直接复制用。

node scripts/build.mjs           # 写入 20 个宿主目录 + bundle payload(660 个文件)
node scripts/build.mjs --check   # 校验磁盘与源是否一致,漂移则退出 1

每个宿主目录的形状固定:

<configDir>/skills/footgun-guard/
  SKILL.md           渲染后的技能说明(占位符已替换成该宿主的相对路径)
  reference/*.md     11 份 playbook / 语言条目
  scripts/           检测引擎的副本 + package.json(自包含,不需要另装依赖)

<configDir> 与 Impeccable 的 provider 表一致:

宿主 目录 宿主 目录
Claude Code .claude Qoder .qoder
Cursor .cursor Trae / Trae China .trae / .trae-cn
DeepSeek Harness .dsh Rovo Dev .rovodev
Codex / 通用 .agents Mistral Vibe .vibe
GitHub Copilot .github Veto .veto
Gemini .gemini Grok Build .grok
Kiro .kiro Antigravity .agent
OpenCode .opencode Hermes .hermes
Pi / Oh My Pi .pi / .omp Devin .devin

两处刻意的差异:

  • .agents(Codex)的 frontmatter 只有 name/description——Codex 的校验器会拒绝未知顶层键,其余宿主才带 user-invocable/license。
  • 没有 workspace/(Muse):它只支持用户级安装,没有可生成的仓库内布局。

node scripts/build.mjs --check 被写进了测试(tests/build.test.js),所以手改生成物、或改了 skill//src/ 忘了重跑构建,都会让测试变红。

加一条规则

  1. 需求:在 GuardList_cn.txt 的对应语言段落末尾加一条(### C-13 … + 问题 + 检查),再在 GuardList_en.txt 同样位置加英文版。ID 自己起,但必须唯一且之后不再改。
  2. 实现:在 src/rules/<lang>.js 加一个对象,listNo 填上一步的 ID。
  3. 证据:在 fixtures/<lang>/bad.* 埋一个正例,在 good.* 里确认不误报。
  4. node scripts/gen-docs.mjs && node scripts/build.mjs,然后 node --test "tests/**/*.test.js"。
  5. 如果这条属于"原理上判不出来",tier: 'manual' 并且不写 detect——注册表会拒绝不一致的规则。

漏掉任何一步都会在测试里报出来:需求多于规则、规则多于需求、双语不同构、正例没覆盖、生成物漂移。

验证

node scripts/test.mjs                  # 93 passed(跨 Node 版本可用)
node scripts/smoke.mjs c             # 单语言:bad 全命中 / good 零发现
node src/cli.js detect fixtures      # 67 条发现,退出码 2
node src/cli.js detect src           # 自扫:19 个文件,0 findings
node src/cli.js doctor               # 80/80 条编号覆盖,hook 接线状态
node scripts/build.mjs --check       # 20 个宿主目录与源一致

tests/fixtures.test.js 断言的是 GuardList 编号(C8、Java2…),不是规则 id:每个语言的正例样本必须命中该语言全部可检测条目,反例样本必须零发现。加规则时不能靠改断言过关。

License

MIT


English

The four layers

This is not a checklist of "things to be careful about" but a four-layer structure — the same layering as Impeccable: what can be decided by a machine goes to the machine, what cannot goes to process, and every layer is explicit about what it does not cover.

Layer What it is In FootgunGuard
① Instructions prompt / playbook skill/SKILL.md, skill/reference/*.md, AGENTS.md: checkable imperatives + counter-examples + self-check order
② Measurement deterministic detector src/rules/*.js + src/engine/: 61 of the 80 rules (19 mechanical + 42 heuristic); the other 19 stay in an explicit manual list (12 common + 7 language-specific). Zero dependencies, no AST, no network
③ Feedback post-edit injection src/commands/hook.js + hooks/: findings go back to the agent as additionalContext; never blocking
④ Gate exit codes / CI footgun detect exit 2, --sarif, --github: what the model says cannot change the merge result

Honest boundaries (read this before trusting it)

  • 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) require reading the requirements, the intent of comments, 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") require comparing 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). They are marked tier: 'manual' and handled by layer ① and /footgun review in layer ③.
  • Most of Rust's 6 items are already enforced by rustc at compile time. The detectors only add 3 runtime-semantic checks (self-referential struct, RefCell double borrow, panic in Drop). "detect is clean" does not mean Rust is safe.
  • Known misses: code inside comments/strings (masked out), macro expansion, cross-file type inference, and .h always treated as C.
  • Known false positives: every tier: 'heuristic' rule. They prefer under-reporting, but you still have to judge.

detect output explicitly says the findings are an undercount, not a clean bill of health.

Quick start

node src/cli.js detect .              # scan the current directory
node src/cli.js detect src/ --json    # machine-readable
node src/cli.js context               # print the always-on instruction block for agents
node src/cli.js list --manual         # list items without a detector
node src/cli.js explain c-unsafe-string-fn   # look up one rule
node src/cli.js doctor                # self-check: rule completeness, hook wiring

Exit codes: 0 clean / 2 findings / 1 some target could not be scanned.

Wiring it into an agent

DSH: put AGENTS.md in the project root (DSH reads it on the first request), or install the hooks/dsh/ plugin to get post-edit reminders.

Claude Code: merge the contents of hooks/claude-settings.json into .claude/settings.json; or copy skill/ to .claude/skills/footgun-guard/.

One-command install (ships a self-contained host directory):

node scripts/install.mjs --host claude              # into <project>/.claude/skills/footgun-guard
node scripts/install.mjs --host dsh --scope global  # into ~/.dsh/skills/

--host accepts: claude / cursor / dsh / agents / codex / github / gemini / kiro / opencode / pi / omp / qoder / trae / trae-cn / rovodev / vibe / veto / grok / antigravity / hermes / devin.

Other hosts: put AGENTS.md in the project (instruction layer) and wire footgun hook to that host's post-tool-use event.

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 }

2 still uploads the report (findings); 1 (a target could not be scanned) fails the step. The package is not published to npm yet, so this uses the in-repo path; once published, npx footgun replaces node src/cli.js.

The requirement source: two GuardLists

File Purpose
GuardList_cn.txt Chinese requirements: the "problem" and the "check" for every footgun
GuardList_en.txt Structurally identical English version: same IDs, same order

The format is two heading levels plus fixed fields, parseable with a single for loop:

## c · C

### C-8 strcpy and \0
- Problem: `strcpy`/`strcat`/`sprintf` ignore the destination capacity; one extra byte is a buffer overflow.
- Check: use `snprintf`/`strlcpy` and explicitly guarantee room for the trailing \0.

Rules:

  • The key in ## <language> must match src/engine/lang.js, otherwise the parser fails immediately.
  • The ID in ### <ID> <title> is a stable identifier (C-8, CS-3, RUST-5); rules map to it, so renaming breaks the link.
  • Every item needs a problem line and a check line; the English file uses - Problem: / - Check:.
  • The two files must stay isomorphic; tests/guardlist.test.js enforces it: one missing ID, one extra, or a different order turns the test red.

Why two files instead of one bilingual table: the English version is real input for English projects and English models, not a translation by-product; isomorphism is enforced by tests, not by discipline.

Layout

GuardList_cn.txt / GuardList_en.txt   requirement source (bilingual, test-enforced)
src/                             single source of truth: engine + rules
  engine/        masker (strips comments and strings), context, language detection, scanning
  rules/         9 rule packs, one detect() per rule
  commands/hook.js  layer ③
  cli.js         layer ④ and command routing
skill/                           single source of truth: text for the model
  SKILL.md       layer ① entry point (contains the {{cli}} placeholder)
  reference/     per-language items (generated from the registry by scripts/gen-docs.mjs) + handwritten common/review/audit
scripts/
  build.mjs      renders the two sources into 20 host directories
  gen-docs.mjs   generates reference/<lang>.md from the rule registry
  install.mjs    copies a host directory into a project or global skill path
  smoke.mjs      run one language pack's rules
generated CLI artifacts          see the next section; do not edit by hand
hooks/           Claude Code settings snippet, DSH plugin
fixtures/        one "with footguns" and one "clean" sample per language
tests/           node --test

Distribution: 20 host directories

The same approach as Impeccable: one source, generate every host directory, commit the artifacts — so a clone is immediately usable.

node scripts/build.mjs           # write 20 host directories + bundle payload (660 files)
node scripts/build.mjs --check   # verify disk matches source; exit 1 on drift

Every host directory has the same shape:

<configDir>/skills/footgun-guard/
  SKILL.md           rendered skill description (placeholders replaced with host-relative paths)
  reference/*.md     11 playbooks / language item files
  scripts/           a copy of the detection engine + package.json (self-contained, no extra installs)

<configDir> follows Impeccable's provider table:

Host Directory Host Directory
Claude Code .claude Qoder .qoder
Cursor .cursor Trae / Trae China .trae / .trae-cn
DeepSeek Harness .dsh Rovo Dev .rovodev
Codex / generic .agents Mistral Vibe .vibe
GitHub Copilot .github Veto .veto
Gemini .gemini Grok Build .grok
Kiro .kiro Antigravity .agent
OpenCode .opencode Hermes .hermes
Pi / Oh My Pi .pi / .omp Devin .devin

Two deliberate differences:

  • .agents (Codex) frontmatter only has name/description — Codex's validator rejects unknown top-level keys; other hosts also get user-invocable/license.
  • No workspace/ (Muse): it only supports user-level installation, so there is no repository layout to generate.

node scripts/build.mjs --check is part of the test suite (tests/build.test.js), so hand-editing a generated file — or changing skill//src/ and forgetting to rebuild — turns the build test red.

Adding a rule

  1. Requirement: add an item at the end of the matching language section in GuardList_cn.txt (### C-13 … + problem + check), then add the English version at the same position in GuardList_en.txt. Pick a unique ID; it must never change afterwards.
  2. Implementation: add an object in src/rules/<lang>.js and set listNo to the ID from step 1.
  3. Evidence: plant a positive case in fixtures/<lang>/bad.* and confirm no false positive in good.*.
  4. Run node scripts/gen-docs.mjs && node scripts/build.mjs, then node --test "tests/**/*.test.js".
  5. If the item is undecidable in principle, use tier: 'manual' and do not write detect — the registry rejects inconsistent rules.

Missing any step turns a test red: more requirements than rules, more rules than requirements, the two languages diverging, an uncovered positive case, or generated artifacts drifting.

Verification

node scripts/test.mjs                  # 93 passed (works across Node versions)
node scripts/smoke.mjs c               # one language: bad all hit / good zero findings
node src/cli.js detect fixtures        # 67 findings, exit code 2
node src/cli.js detect src             # self-scan: 19 files, 0 findings
node src/cli.js doctor                 # 80/80 IDs covered, hook wiring status
node scripts/build.mjs --check         # 20 host directories match the source

tests/fixtures.test.js asserts on GuardList IDs (C8, Java2, …), not rule ids: every language's positive fixture must hit all of that language's detectable items, and the negative fixture must stay at zero. You cannot pass by editing assertions when adding a rule.

License

MIT

관련 프로젝트 살펴보기

불러오는 중…