file-generation-safety-rules

file-generation-safety-rules is a cursor rule for coding agents from Mr-chen-05/rules-2.1-optimized. It costs 5,576 tokens per session, scanned A, original, MIT.

Rules that require explicit user confirmation before creating or modifying files. They cover source code, configuration, documentation, project structure, deployment settings, and data files.

In plain words
What is it for?
Apply them before generating or editing code, configuration, documentation, CI/CD files, server settings, monitoring files, or JSON, XML, and YAML data.
Why use it?
They prevent an assistant from writing project files without the user clearly approving that action. The rules also require checking the requested file operation before making changes.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/mr-chen-05/rules-2.1-optimized/file-generation-safety-rules
Clone the repo
git clone --depth 1 https://github.com/Mr-chen-05/rules-2.1-optimized

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for file-generation-safety-rules

README.md
[![agentmods](https://agentmods.dev/badge/rules/mr-chen-05/rules-2.1-optimized/file-generation-safety-rules.svg)](https://agentmods.dev/rules/mr-chen-05/rules-2.1-optimized/file-generation-safety-rules)
Your own site
<a href="https://agentmods.dev/rules/mr-chen-05/rules-2.1-optimized/file-generation-safety-rules"><img src="https://agentmods.dev/badge/rules/mr-chen-05/rules-2.1-optimized/file-generation-safety-rules.svg" alt="Measured on agentmods" height="20"></a>
Per session 5,576 This file is loaded in full into every session.
When invoked 5,576 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.05576 $0.05576
Opus 5 $0.02788 $0.02788
Sonnet 5 $0.01115 $0.01115
Haiku 4.5 $0.00558 $0.00558

Measured 5d ago against content hash d3eff20018a1, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

file-generation-safety-rules scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

global-rules/file-generation-safety-rules.mdc · 674 lines

How it starts

The opening of the file, as written. The whole thing — 674 lines — stays where its author put it; the contents beside it link to each section on GitHub.

🚨 文件生成安全规则(死命令)

⚠️ 核心安全原则

绝对禁止规则:任何AI助手在执行文件生成操作前,必须获得用户明确确认!

这是不可违反的核心安全机制,旨在防止AI助手在未经用户授权的情况下生成或修改文件。

🔒 强制确认的操作类型

📝 所有文件生成操作

以下操作必须先获得用户明确确认,无任何例外:

代码文件
  • .js, .ts, .jsx, .tsx - JavaScript/TypeScript文件
  • .vue, .svelte - 前端框架组件文件
  • .py, .java, .go, .rs, .php, .rb, .cs - 后端代码文件
  • .html, .css, .scss, .sass, .less - 样式和标记文件
  • .sql - 数据库脚本文件
配置文件
  • package.json, yarn.lock, pnpm-lock.yaml - 包管理配置
  • tsconfig.json, jsconfig.json - TypeScript/JavaScript配置
  • vite.config.js, webpack.config.js, rollup.config.js - 构建工具配置
  • eslint.config.js, .prettierrc, stylelint.config.js - 代码规范配置
  • docker-compose.yml, Dockerfile - 容器化配置
  • requirements.txt, pom.xml, Cargo.toml, go.mod - 依赖管理文件
文档文件
  • README.md, CHANGELOG.md, LICENSE - 项目文档
  • API文档, 架构文档, 用户手册 - 技术文档
  • 项目规划, 需求文档, 设计文档 - 项目管理文档
项目结构文件
  • 目录结构创建
  • 脚手架文件生成
  • 模板文件创建
  • 示例代码文件
部署和运维文件
  • CI/CD配置文件 (.github/workflows/, .gitlab-ci.yml)
  • 服务器配置文件 (nginx.conf, apache.conf)
  • 监控配置文件
  • 日志配置文件
数据文件
  • JSON, XML, YAML 数据文件
  • 配置数据文件
  • 测试数据文件
  • 种子数据文件

🛡️ 执行前强制检查机制

检查清单

在调用任何 write_to_file, replace_in_file, 或其他文件操作工具前,AI助手必须确认:

  • 用户明确指令:用户是否明确表达了"开始开发"、"生成代码"、"创建文件"、"开始实现"等指令?
  • 方案确认:技术方案、架构设计、文件结构是否已经过用户确认?
  • 内容说明:即将生成的文件内容和作用是否已向用户详细说明?
  • 影响理解:用户是否理解文件生成对项目的影响?
  • 权限确认:用户是否具有在当前目录生成文件的权限和意愿?

确认方式

AI助手必须通过以下方式之一获得确认:

  1. 直接询问

    "我准备为您生成以下文件:
    - src/components/UserCard.vue (用户卡片组件)
    - src/types/user.ts (用户类型定义)
    - package.json (项目配置文件)
    
    这些文件将实现用户卡片功能。请确认是否开始生成这些文件?"
    
  2. MCP反馈工具

    调用 interactive_feedback_mcp-feedback-enhanced 工具,
    详细说明即将生成的文件和原因,等待用户明确确认。
    
  3. 方案展示

    先展示完整的技术方案和文件结构,
    明确询问用户是否同意开始实现。
    

⛔ 违规处理机制

违规行为定义

以下行为被视为违规:

  • 在未获得用户确认的情况下直接生成文件
  • 假设用户同意而跳过确认步骤
  • 将需求描述误解为开发指令
  • 在讨论阶段就开始生成代码文件

违规处理流程

如果AI助手违反了文件生成安全规则:

  1. 立即停止:停止所有文件生成操作
  2. 承认错误:向用户道歉并说明违规情况
  3. 调用反馈:使用反馈机制重新与用户沟通
  4. 重新确认:详细说明计划并等待明确指令
  5. 记录教训:将此次违规记录到 Recorder;如需语义检索可同步至 Memory(可选),以避免重复

Read the full file on GitHub · 674 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 674 lines · 5,576 tokens per session scan A d3eff20018a1

Subscribe to this mod's changes

file-generation-safety-rules is a cursor rule published in the GitHub repository Mr-chen-05/rules-2.1-optimized (172 stars, last pushed 10mo ago), licensed MIT. It adds 5,576 tokens to every session, about $0.0279 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.