从全局人格到任务执行:构建 AI 协作的四层约束体系(Skill Layers)

"AI 开发不等于'盲目生成',真正的效率来自于对模型行为的确定性约束。"

在 AI 辅助编程(如 Trae, Cursor, Claude 等)的语境下,"Skill" 实质上是结构化的指令集。

为了达到最佳的协作效果,通常会将 Skill 分为以下 4 种维度。它们像洋葱一样层层嵌套,从底层架构到具体的业务逻辑对 AI 进行约束。

为了让 AI 协作达到"工业级"水准,我将这四个维度拆解为四个独立的 Markdown 配置文件。可以根据需要,分别将它们放入 IDE 全局设置、项目根目录、任务启动指令或特定业务文档中。

1. 基础环境级 (Global / Personality Skill)

建议位置: IDE 全局设置(如 Trae Rules for AI / Cursor General Rules)。

作用: 塑造 AI 的基础人格,确保沟通高效、不废话、懂规矩。

javascript 复制代码
# Role: Expert Senior Full-Stack Engineer

## 🤖 Interaction Protocol
- **Language**: Always reply in Chinese, but keep technical terms in English (e.g., Props, Hooks, Middleware).
- **Conciseness**: Skip polite filler phrases. Go straight to the solution or code.
- **Thinking Process**: Before providing complex code, briefly state your plan in 1-2 sentences.

## 🛠 Coding Standard
- **Language**: TypeScript is mandatory. Avoid `any` at all costs; use generics or unknown if necessary.
- **Modernity**: Use ES6+ features (optional chaining, destructuring, arrow functions).
- **Naming**: Use camelCase for variables/functions, PascalCase for components/classes, and PascalCase for TS types/interfaces.

## 🚫 Critical Constraints
- **Zero Deletion**: Never remove existing comments or unrelated business logic.
- **Comment Policy**: Only add comments for complex logic. Use JSDoc for function headers.
- **Security**: Never hardcode API keys, secrets, or sensitive credentials.

2. 项目架构级 (Architectural / Tech Stack Skill)

建议位置: 项目根目录 .cursorrules 或 .ai_rules。

作用: 针对 Vue3 + Antd 的深度约束,防止架构污染。

javascript 复制代码
# Project Context: Vue3 + Ant Design Vue + Tailwind

## 🏗 Directory Structure (Strict)
- `@/components/`: Shared UI components.
- `@/views/`: Page-level components.
- `@/hooks/`: Reusable Composition API logic.
- `@/utils/`: Pure utility functions (No Vue APIs here).
- `@/api/`: Axios/Request definitions.
- `@/store/`: Pinia store modules.

## 🎨 Frontend Standard
- **Component Style**: <script setup> + TypeScript.
- **UI Component**: Always use `ant-design-vue` components (`a-` prefix). 
- **Style Priority**: Tailwind CSS > Antd Tokens > Scoped CSS.
- **Global CSS**: Do not modify `global.css` or `App.vue` styles without permission.

## ⚙️ Build & Config
- **Path Alias**: Use `@/` for all absolute imports.
- **Icons**: Use `@ant-design/icons-vue` only.
- **Props/Emits**: Use macro `defineProps<{...}>()` and `defineEmits(['...'])`.

3. 业务逻辑级 (Domain / Business Logic Skill)

建议位置: 任务对话框开头(作为 Context)或子模块说明文档。

作用: 确保 AI 理解特定的业务潜规则,防止生成不可用的逻辑。

javascript 复制代码
# Domain Logic: Data Visualization & State Management

## 📊 Graph Rendering (Sigma.js/AntV G6)
- **Data Integrity**: When processing graph data, always maintain the `{ nodes: [], edges: [] }` structure.
- **Performance**: Use `shallowRef` or `markRaw` for large graph instances (e.g., 80k nodes) to prevent Vue reactivity overhead.
- **Interaction**: Ensure drag-and-drop events do not trigger full-page re-renders.

## 🔄 Async & State
- **Pinia**: Use `storeToRefs` when destructuring state in components.
- **API Response**: Assume all API responses follow the format `{ code: number, data: any, message: string }`.
- **Loading States**: Every async action must toggle a `loading` variable.

## 🧪 Error Handling
- Use `try-catch` for all API calls. 
- Use Antd `message.error()` for user-facing error feedback.

4. 任务操作级 (Task / Workflow Skill)

建议位置: 每次开启 Build Mode 或新任务时的前置指令。

作用: 限制 AI 的修改行为,防止"过度修改"和"重复造轮子"。

javascript 复制代码
# Workflow: Iterative Development Mode

## 🔍 Pre-Action Search
- **Reusability**: Before creating ANY utility function, search the `@/utils` directory. 
- **Inheritance**: Read the existing file's style and use the same patterns (e.g., function declaration vs arrow functions).

## ✍️ Modification Rules
- **Diff Only**: Only output the modified sections of code. Do not rewrite the entire file unless it's a new file.
- **No Inline Styles**: Strictly forbidden to use `style="..."`. Use Tailwind classes instead.
- **Minimal Impact**: Avoid changing variable names or refactoring code that is outside the scope of the current task.

## ✅ Verification
- **TS Check**: Ensure no TypeScript errors are introduced.
- **Antd Consistency**: Ensure new UI elements align with the current theme's Design Tokens.

如何组合使用?

配置全局人格:把第一份放入 Trae 的全局 Rules。

锁死技术栈:把第二份保存为项目根目录的 .cursorrules。

开启新任务:当你需要 AI 迭代功能时,直接在对话框粘贴: "使用第 3 和第 4 类 Skill 模式执行以下任务:[描述需求]。"

复制代码
这样,AI 就会在懂规矩(Global)、不乱写架构(Arch)的前提下,遵循业务逻辑(Domain)并以最高效的修改方式(Task)完成工作。

以上是基于Vue3 + Ant Design 项目中的 AI 约束指令(Skills)实践,要使用在自己的项目里面,还需按照自己的项目实际情况修改和丰富,我给的示例只是基础版本罢了。


朋友们健身时都有别名吗,我叫-不要耸肩-

相关推荐
TEC_INO1 小时前
Linux49:rockx读取单张图片并检测图片内人脸的矩形
人工智能
xcbrand1 小时前
新零售品牌策划公司有哪些
大数据·人工智能·python·零售
掘金安东尼1 小时前
Claude Code 团队工程师:我为什么放弃 Markdown,全面转向 HTML
人工智能
码农的神经元1 小时前
2026 年数维杯A 题:抱轨式磁浮列车的悬浮电磁铁故障检测问题
人工智能·算法·数学建模
python零基础入门小白1 小时前
驾驭智能体风暴:企业技术管理范式重构与落地实战指南
人工智能·学习·大模型·agent·产品经理·ai大模型·大模型学习
国产化创客1 小时前
ESP-Claw与MimiClaw:ESP32端侧AI智能体的两种实现路径
人工智能·物联网·开源·智能硬件
互联网志1 小时前
规划聚焦人工智能 赋能产业高质量发展
人工智能
QD_ANJING1 小时前
普及一下五月AI前端面试需要达到的强度....
前端·javascript·vue.js·人工智能·面试·职场和发展
AI自动化工坊1 小时前
Chrome DevTools MCP:让AI编码代理获得浏览器调试能力
前端·人工智能·chrome devtools