自訂模式
您可以建立自訂模式,使 Bob 的行為符合特定任務或工作流程。Bob Shell 中的自訂模式與 Bob IDE 模式的運作方式相似。
為何在 Bob Shell 中使用自訂模式
- Shell 最佳化工作流程:建立專為終端機型開發任務設計的模式
- 命令列安全性:在生產環境中工作時,將模式限制為安全操作
- 環境專屬行為:設定能適應不同 shell 環境的模式
- 自動化友好:設計能在互動式和非互動式工作階段中無縫運作的模式
- 團隊標準化:在團隊中共享 shell 專屬模式以確保一致的工作流程
自訂模式的內容
Bob Shell 中的自訂模式使用與 Bob IDE 模式相同的核心結構:
| 屬性 | 說明 | Shell 專屬考量 |
|---|---|---|
slug | 唯一的內部識別碼 | 用於命令列引數:bob --mode my-mode |
name | UI 中顯示的名稱 | 顯示在互動式模式的模式選擇器中 |
description | 在模式選擇器中顯示的簡短說明 | 簡要說明您模式的用途 |
roleDefinition | 核心身分和專業知識 | 應考慮 shell 上下文和命令列工作流程 |
groups | 允許的工具集和檔案存取 | 在 shell 環境中,命令執行權限至關重要 |
whenToUse | 模式選擇指南 | 幫助 Bob Shell 為任務選擇適當的模式 |
customInstructions | 模式的具體行為指南或規則 | 可參照 Bob Shell 開發模式 |
可用工具
可用的工具群組
read:讀取檔案和目錄edit:修改檔案(可用fileRegex限制)execute:執行終端機命令(command可作為舊版別名使用)browser:擷取公開網頁(實驗性;需要experiments.webFetch)mcp:存取 MCP 伺服器skill:啟用技能todo:更新待辦事項清單subagent:產生 subagentmode:切換模式
建立自訂模式
設定檔
Bob Shell 使用與 Bob IDE 相同的設定格式,支援 YAML(建議)和 JSON 格式。
全域模式
建立或編輯 ~/.bob/settings/custom_modes.yaml,使模式可用於所有專案:
customModes:
- slug: shell-debug
name: 🐛 Shell Debugger
roleDefinition: >-
You are a debugging specialist focused on command-line troubleshooting.
You excel at analyzing shell output, environment variables, and system logs.
whenToUse: Use for debugging shell scripts, command failures, and environment issues.
customInstructions: |-
When debugging:
- Always check environment variables first
- Examine command exit codes
- Review relevant log files
- Test commands in isolation before suggesting fixes
groups:
- read
- execute
- browser專案專屬模式
在您的專案根目錄建立或編輯 .bob/custom_modes.yaml:
customModes:
- slug: deploy-helper
name: 🚀 Deployment Assistant
roleDefinition: You are a deployment specialist for this project's infrastructure.
whenToUse: Use for deployment tasks, infrastructure changes, and release management.
customInstructions: |-
Deployment guidelines:
- Always verify the target environment before running commands
- Check for running processes that might be affected
- Validate configuration files before applying changes
- Create backups before destructive operations
groups:
- read
- - edit
- fileRegex: \.(yaml|yml|sh|env)$
description: Configuration and script files only
- execute命令列模式選擇
啟動 Bob Shell 時指定模式:
# 以特定模式啟動 Bob Shell
bob --mode shell-debug
# 與其他選項結合使用
bob --mode deploy-helper --max-turns 20互動式模式切換
在互動式模式中,輸入 /mode 開啟模式選擇器,然後選取您的自訂模式。自訂模式會與內建的 Agent、Plan 和 Ask 模式一起顯示在選擇器中。
Shell 專屬設定
生產安全模式
為生產環境建立注重安全的模式:
customModes:
- slug: prod-ops
name: 🔒 Production Operations
roleDefinition: >-
You are a production operations specialist with a strong focus on safety.
You never run destructive commands without explicit confirmation.
whenToUse: Use when working with production systems or sensitive environments.
customInstructions: |-
Production safety rules:
- NEVER run destructive commands without explicit user confirmation
- Always verify the target environment before any operation
- Suggest dry-run options when available
- Check for active connections or processes before changes
- Recommend backup procedures before modifications
groups:
- read
- browser
# Note: No edit or execute groups for maximum safety腳本開發模式
建立 shell 腳本開發模式:
customModes:
- slug: script-dev
name: 📜 Script Developer
roleDefinition: >-
You are a shell scripting expert specializing in bash, zsh, and POSIX-compliant scripts.
whenToUse: Use for creating, debugging, or improving shell scripts.
customInstructions: |-
Shell scripting best practices:
- Use shellcheck-compliant syntax
- Include proper error handling with set -e and set -u
- Add usage documentation at the top of scripts
- Quote variables to prevent word splitting
- Provide exit codes for different error conditions
groups:
- read
- - edit
- fileRegex: \.(sh|bash|zsh)$
description: Shell script files only
- execute命令執行權限
限制命令存取
透過省略 execute 群組來控制模式是否可以執行命令:
customModes:
- slug: safe-reviewer
name: 👀 Safe Code Reviewer
roleDefinition: You are a code reviewer focused on analysis, not modification.
whenToUse: Use for code reviews and analysis without making changes.
groups:
- read
- browser
# No execute or edit groups - read-only mode允許特定命令
若要自動核准特定命令,請將 "execute" 新增至 approval.allowed_permissions,並在 ~/.bob/settings/settings.json 中的 approval.allowedExecutors 裡為 execute_command 工具列出這些命令:
{
"approval": {
"allowed_permissions": ["read", "execute"],
"allowedExecutors": [
{
"toolId": "execute_command",
"approvedCommands": ["git status", "git log", "git diff"],
"deniedCommands": []
}
]
}
}設定 allowedExecutors 會取代預設的已核准命令清單,因此請一併列入您想保留的預設命令。如需詳細資訊,請參閱核准設定。
互動式與非互動式行為
為兩種模式設計
建立在互動式和非互動式工作階段中都能良好運作的模式:
customModes:
- slug: test-runner
name: 🧪 Test Runner
roleDefinition: >-
You are a testing specialist who runs and analyzes test suites.
You adapt your output based on the running context.
whenToUse: Use for running tests, analyzing test results, and debugging test failures.
customInstructions: |-
Testing guidelines:
- In interactive mode: Provide detailed explanations and suggestions
- In non-interactive mode: Focus on concise, actionable output
- Always report test results clearly
- Suggest fixes for failing tests
groups:
- read
- execute非互動式用法
在非互動式模式中使用模式:
# 使用為自動化設計的模式
bob run --mode test-runner "Run the test suite and report failures"
# 結合輸出處理
bob run --mode test-runner --format json "Run tests" > results.json透過檔案提供模式專屬指示
基於目錄的指示
在 .bob/rules-{mode-slug}/ 中建立模式專屬指示檔案:
指示檔案範例(.bob/rules-shell-debug/01-environment-checks.md):
# Environment Debugging Checklist
When debugging shell issues, always check:
1. **Environment Variables**: PATH, SHELL, TERM, and application-specific variables
2. **Shell Configuration**: .bashrc, .zshrc, .profile files
3. **System State**: Current working directory, file permissions, disk space
4. **Command Availability**: Use `command -v <cmd>` to verify commands exist設定優先順序
如果兩個模式使用相同的 slug,Bob Shell 會依以下順序使用最先找到的模式:
- 內建模式(
agent、plan、ask) - 使用者層級模式(
~/.bob/settings/custom_modes.yaml) - 專案層級模式(
.bob/custom_modes.yaml)
請為每個自訂模式使用唯一的 slug。--mode 旗標只會選擇要以哪個模式啟動。
從 Bob IDE 移轉模式
主要差異
從 Bob IDE 移轉自訂模式至 Bob Shell 時:
| 面向 | Bob IDE | Bob Shell |
|---|---|---|
| UI 互動 | 帶有面板的視覺介面 | 終端機型介面 |
| 檔案編輯 | 編輯器內 diff 和預覽 | CLI diff 視圖或外部編輯器 |
| 命令執行 | 整合式終端機 | 直接 shell 執行 |
| 模式切換 | 模式選擇器下拉選單 | /mode 選擇器或 --mode CLI 旗標 |
| 設定 | 設定 UI + 檔案 | 僅設定檔 |
調整清單
調整 Bob IDE 模式以適用於 Bob Shell 時:
- 審查
roleDefinition中的 shell 專屬上下文 - 更新
customInstructions以參照命令列工作流程 - 在
groups設定中考慮命令執行安全性 - 在互動式和非互動式工作階段中測試模式
- 確認檔案路徑處理在 shell 上下文中正常運作
移轉範例
原始 Bob IDE 模式:
customModes:
- slug: code-reviewer
name: 👀 Code Reviewer
roleDefinition: You are a code reviewer who provides detailed feedback.
groups:
- read
- browser調整以適用於 Bob Shell:
customModes:
- slug: code-reviewer
name: 👀 Code Reviewer
roleDefinition: >-
You are a code reviewer who provides detailed feedback.
You work efficiently in terminal environments and provide clear, actionable suggestions.
whenToUse: Use for code reviews, pull request analysis, and code quality checks.
customInstructions: |-
Code review guidelines:
- Provide feedback in a structured format suitable for terminal output
- Reference specific line numbers and file paths
- Suggest concrete improvements with examples
- Format output for easy parsing if used in non-interactive mode
groups:
- read
- execute # Added for git operations
- browser