从全局人格到任务执行:构建 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)实践,要使用在自己的项目里面,还需按照自己的项目实际情况修改和丰富,我给的示例只是基础版本罢了。


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

相关推荐
AI视觉网奇6 分钟前
3d 打印模型修复
人工智能·3d
刀法如飞15 分钟前
AI还不是人,AI编程也离不开人
ai编程
“码”力全开17 分钟前
深度解析:基于 Docker 与边缘计算的 AI 视频管理平台架构——打通 GB28181/RTSP 协议与“源码交付”的高效集成方案
人工智能·docker·边缘计算
wangqiaowq21 分钟前
预训练 后预训练 微调
人工智能·深度学习·机器学习
LONGZETECH29 分钟前
架构师实战拆解|无人机智慧实训SaaS中台:断电续考、AI组卷、多端同步核心设计
大数据·人工智能·架构·系统架构·无人机
战族狼魂33 分钟前
集 “自动飞行、智能识别、实时预警、勤务联动” 于一体的高速公路应急车道无人机检测系统方案
java·人工智能·大模型·无人机
月光船幽幽34 分钟前
Helio-Core临界控制:守护拓扑量子稳定
人工智能·科技·动态规划·拓扑学
jkyy201436 分钟前
大模型重构饮食健康服务链路:多维技术赋能膳食管理智能化升级
大数据·人工智能·信息可视化·重构·健康医疗
罗西的思考37 分钟前
【Agentic RL / 强化学习 / OPD】OpenClaw-RL 源码阅读笔记 --- (4)--- 系统架构
人工智能·算法·机器学习
2601_9578885637 分钟前
从关键词到语义网络:生成式引擎优化(GEO)的技术原理解析与工程实践
人工智能·大模型