自定义模式
您可以创建自定义模式,将 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 中为 execute_command 工具在 approval.allowedExecutors 中列出这些命令:
{
"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