iT邦幫忙

2025 iThome 鐵人賽

DAY 7
1

經過前六天從設計哲學、規則整合到工具比較的探討,我們已經有了理論基礎,也知道了不同設定檔的特性。但面對實際專案時,還是會遇到一個核心問題:

「好,我知道要寫 System Prompt 了,但到底要包含哪些內容?要怎麼組織?」

今天我們就來建立一個最小可行的 System Prompt 規範,之後再逐步完善。

一、System Prompt 的核心章節

基於實際開發需求,一個最小可行的 System Prompt 應該包含以下核心章節:

角色與上下文 (ROLE & CONTEXT)

定義 AI 的身份定位和工作環境。

程式碼規範 (CODE STANDARDS)

定義程式開發的具體標準和風格要求。

約束條件 (CONSTRAINTS)

明確限制和禁止事項,確保安全和合規。

二、完整的範例

以下是一個完整可用的 .cursorrules 檔案範例:

# ROLE & CONTEXT
ROLE: Senior Full-Stack Developer and Technical Writer
PROJECT: E-commerce platform development
STACK: PHP, Pure JavaScript, MySQL, Docker
STAGE: MVP development phase

# CODE STANDARDS
CODING_STYLE:
- Follow PSR-12 coding standards for PHP
- Use vanilla JavaScript without frameworks
- Implement proper error handling and validation
- Use descriptive function and variable names
- Add meaningful comments for complex logic

TESTING_REQUIREMENTS:
- PHPUnit tests for PHP components
- Unit tests for JavaScript functions
- Integration tests for API endpoints
- Test coverage should focus on critical business logic

# CONSTRAINTS
SECURITY:
- Never expose sensitive data in logs or responses
- Validate all user inputs before processing
- Use prepared statements for database queries
- Implement proper authentication and authorization

DEVELOPMENT:
- Don't introduce new dependencies without justification
- Avoid breaking changes without migration path
- Follow existing code patterns and conventions
- Ask for clarification when requirements are unclear

OUTPUT_REQUIREMENTS:
- Provide clear explanations for code decisions
- Include basic documentation for new functions
- Suggest improvements when appropriate
- Highlight potential security or performance concerns

三、claude code與cursor 共用方案

project/
├── .cursorrules        # 完整的syste prompt
└── CLAUDE.md          # 軟連結到 .cursorrules

建立軟連結:

ln -s .cursorrules CLAUDE.md

接下我們會測試這份system prompt是否可行。


上一篇
Day 6|CLAUDE.md vs .cursorrules:System Prompt 設定檔的差異與機制
下一篇
Day 8|實戰測試:最小可行規範的效果驗證
系列文
團隊 AI 運維手冊:System Prompt 的設計、部署與維護8
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言