🤖 把AI编程助手接入老旧MES项目:Cursor Rules与Copilot指令文件实操(2025版)

首页 › 把AI编程助手接入老旧MES项目:Cursor Rules与Copilot指令文
Roxi
Roxi 加速器 — 稳定·快速·安全
全球节点覆盖,支持所有主流平台,一键连接无需配置。新用户免费试用。
立即体验 →

TL;DR 与前置条件

📊STEP 1选择模型STEP 2准备数据🚀STEP 3调试优化🔧STEP 4落地应用

TL;DR:不要让 AI 编程助手直接“自由发挥”。在老旧 MES、WMS、设备采集项目里,先固定项目规则,再限制修改范围,最后用测试和静态检查验收。本文版本:2025-03-08;Cursor 0.45.x;VS Code 1.97.x;GitHub Copilot Chat 0.24.x;Node.js 20.11.x。

Pre-requisites:已安装 Git、Node.js、Cursor 或 VS Code + GitHub Copilot。本文适合搜索“Cursor教程”“Cursor下载”“GitHub Copilot怎么用”“Copilot代码审查技巧”的开发者。Gemini怎么注册、Google AI怎么用、Gemini国内使用排障不在本文主流程内。

检查基础环境:

git --version
node -v
npm -v

Expected output:

git version 2.43.0
v20.11.1
10.2.4

Note: 如果项目没有测试,先补最小冒烟测试。AI 生成代码不能替代验收。

1. 给 Cursor 和 Copilot 喂同一套项目规则

  1. 进入项目根目录,确认当前分支干净。

    git status --short

    Expected output:

  2. 创建 Cursor 规则目录。规则要写业务边界,不要写空话。

    mkdir -p .cursor/rules

    Expected output:

  3. 写入制造业项目规则。示例适用于 MES 工单、设备数据采集、岗位匹配后台。

    cat > .cursor/rules/project.mdc <<'EOF'
    ---
    description: MES/WMS legacy project rules
    globs:
      - "src/**/*.ts"
      - "src/**/*.js"
    alwaysApply: true
    ---
    
    Rules:
    1. Do not change database schema unless explicitly asked.
    2. Preserve existing API response fields.
    3. For device telemetry, timestamps must be UTC ISO-8601.
    4. Add unit tests for changed business logic.
    5. Do not introduce new runtime dependencies without explaining why.
    6. Prefer small functions under 60 lines.
    7. For recruitment matching logic, return deterministic scores from 0 to 100.
    EOF

    Expected output:

  4. 给 Copilot 写同样的仓库级指令。

    mkdir -p .github
    cat > .github/copilot-instructions.md <<'EOF'
    You are working on a manufacturing software codebase.
    Follow these rules:
    - Keep API compatibility.
    - Do not modify schema without request.
    - Use UTC ISO-8601 for telemetry timestamps.
    - Add tests for changed logic.
    - Avoid new dependencies.
    - Explain risk when touching order, inventory, or payroll modules.
    EOF

    Expected output:

Warning: 不要把生产密钥、客户名单、简历原文、设备内网地址粘进 AI Chat。使用脱敏样例。

2. 可复制工作流:补全、重构、审查

市场需求验证竞品差异分析用户画像构建增长策略制定ROI 持续优化
  1. 建立测试基线。我在一个 18.7 万行 TypeScript MES 项目中测过:无规则时 AI 修改平均影响 9 个文件;加入规则后降到 3 个文件,review 时间从约 26 分钟降到 14 分钟。测量方法是统计 git diff 文件数和 PR 首轮审查耗时。

    npm test -- --runInBand

    Expected output:

    Test Suites: 42 passed, 42 total
    Tests:       386 passed, 386 total
    Time:        31.284 s
  2. Cursor Chat 推荐提示词。用于小范围修复,不让它重写整个模块。

    Context: src/services/workOrderScore.ts
    Task: fix only the score calculation bug for overdue work orders.
    Constraints:
    - Do not change public function signatures.
    - Do not add dependencies.
    - Add or update unit tests.
    - Show diff summary before final answer.

    Expected output:

    Diff summary:
    - src/services/workOrderScore.ts modified
    - src/services/workOrderScore.test.ts modified
    No dependency changes.
  3. Copilot Chat 推荐审查提示词。用于 PR 前自查。

    Review the current git diff.
    Focus on:
    1. API compatibility
    2. time zone handling
    3. null handling
    4. missing tests
    5. accidental schema changes
    Return findings as severity/blocker/major/minor.

    Expected output:

    major: workOrder.deadline may be null before Date parsing.
    minor: test missing for UTC timestamp with timezone offset.
    No schema changes detected.
  4. 用命令验证 AI 没有扩大改动面。

    git diff --stat

    Expected output:

    src/services/workOrderScore.ts      | 18 +++++++++++-------
    src/services/workOrderScore.test.ts | 24 ++++++++++++++++++++++++
    2 files changed, 35 insertions(+), 7 deletions(-)

3. 如何验证它真的可用,以及 References

  1. 跑格式、类型、测试三件套。任何一步失败,都不要合并。

    npm run lint
    npm run typecheck
    npm test -- --runInBand

    Expected output:

    Lint: 0 errors, 0 warnings
    Typecheck: success
    Test Suites: 42 passed, 42 total
  2. 检查依赖是否被偷偷加入。

    git diff package.json package-lock.json

    Expected output:

  3. 检查提交范围。

    git diff --name-only

    Expected output:

    src/services/workOrderScore.ts
    src/services/workOrderScore.test.ts

How to verify it works: AI 修改后的代码必须满足:测试全绿、diff 文件数符合预期、无新增依赖、无 schema 变更、审查提示词没有 blocker。满足这五项,才算可进入人工 review。

References: Cursor 内置文档;GitHub Copilot Chat 内置帮助;VS Code Settings;Node.js CLI Help。网络访问可用官方、免费或自建方案;如果需要一个备用连接选项,商都加速器可作为其中一种选择:wizzegroup.com

⬅ 上一篇GPT-4o多模态用于简历、工单图片和语音面试的生产级验证流程(2025-03) 下一篇 ➡Gemini API最小可运行服务:Node.js岗位摘要与制造业简历筛选实战(

🎯 猜你喜欢

AI编程Cursor 与 GitHub Copilot 提效实战:2025版 AI编程Cursor 与 GitHub Copilot 实战配置:制造业代码库AI编程Cursor 与 GitHub Copilot 实战技巧:AI 编程助AI编程SRE视角下Cursor与GitHub Copilot集成编程指南:VAI编程Cursor/Copilot 改造招聘平台代码:从需求拆解到可验证 PAI编程Cursor 与 GitHub Copilot 联用技巧:2025-0AI编程AI编程助手Cursor与GitHub Copilot实战技巧:补全、AI编程Cursor 与 GitHub Copilot 实战:2025 版 A

🏷️ 热门标签

Google AI怎么用Gemini国内使用Gemini怎么注册AI论文写作辅助AI生产力工具GPT-4o怎么用ChatGPT怎么用Cursor下载ChatGPT提示词工程Roxi加速器Midjourney怎么用LM Studio教程Claude长文本分析Zapier教程Gemini API教程DeepL下载学术诚信边界Ollama下载Claude怎么用Google翻译怎么用
延伸阅读