配置
自定义模式
您可以创建自定义模式,将 Bob 的行为定制为特定任务或工作流。Bob Shell 中的自定义模式与 Bob IDE 模式的工作方式类似。
为什么在 Bob Shell 中使用自定义模式
- Shell 优化工作流:创建专为基于终端的开发任务设计的模式
- 命令行安全:在生产环境中限制模式仅执行安全操作
- 环境特定行为:配置能适应不同 shell 环境的模式
- 自动化友好:设计在交互式和非交互式会话中都能无缝运行的模式
- 团队规范化:在团队间共享 shell 专属模式,保持一致的工作流
自定义模式包含什么
Bob Shell 中的自定义模式使用与 Bob IDE 模式相同的核心结构:
| 属性 | 描述 | Shell 特定注意事项 |
|---|---|---|
slug | 唯一内部标识符 | 用于命令行参数:bob --chat-mode=my-mode |
name | UI 中的显示名称 | 显示在交互模式的模式选择器中 |
description | 模式选择器中显示的简短描述 | 简要说明模式用途 |
roleDefinition | 核心身份和专业知识 | 应考虑 shell 上下文和命令行工作流 |
groups | 允许的工具集和文件访问权限 | 命令运行权限在 shell 环境中至关重要 |
whenToUse | 模式选择指导 | 帮助 Bob Shell 为任务选择合适的模式 |
customInstructions | 特定行为指南或模式规则 | 可引用 Bob Shell 开发模式 |
可用工具
可用工具组
read:读取文件和目录edit:修改文件(可使用fileRegex限制)browser:使用浏览器自动化command:执行终端命令mcp:访问 MCP 服务器
创建自定义模式
配置文件
Bob Shell 使用与 Bob IDE 相同的配置格式,支持 YAML(推荐)和 JSON 格式。
全局模式
创建或编辑 ~/.bob/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
- command
- 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
- command命令行模式选择
启动 Bob Shell 时指定模式:
# 以指定模式启动 Bob Shell
bob --chat-mode=shell-debug
# 与其他选项组合
bob --chat-mode=deploy-helper --sandbox交互式模式切换
在交互模式下,使用 slash 命令切换模式:
# 切换到自定义模式
/mode shell-debug
# 或直接使用模式的 slug
/shell-debugShell 特定配置
生产安全模式
为生产环境创建注重安全的模式:
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 command 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
- command命令运行权限
限制命令访问
通过省略 command 组来控制模式可以运行的命令:
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 command or edit groups - read-only mode允许特定命令
在设置文件中使用 Bob Shell 的 allowed 工具配置与自定义模式结合:
{
"tools": {
"allowed": [
"run_shell_command(git status)",
"run_shell_command(git log)",
"run_shell_command(git diff)"
]
}
}交互式与非交互式行为
为两种模式设计
创建在交互式和非交互式会话中都能良好运行的模式:
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
- command非交互式使用
在非交互模式下使用模式:
# 使用为自动化设计的模式
bob --chat-mode=test-runner -p "Run the test suite and report failures"
# 与输出处理结合
bob --chat-mode=test-runner -p "Run tests" --hide-intermediary-output > results.txt通过文件提供模式专属指令
基于目录的指令
在 .bob/rules-{mode-slug}/ 中创建模式专属指令文件:
01-environment-checks.md
02-common-issues.md
03-debugging-steps.md
custom_modes.yaml
示例指令文件(.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单文件指令(备选)
或者,在工作区根目录中使用单个文件 .bobrules-{mode-slug}。
配置优先级
模式配置按以下顺序应用:
- 命令行参数(
--chat-mode=mode-slug) - 项目级模式(
.bob/custom_modes.yaml) - 用户级模式(
~/.bob/custom_modes.yaml) - 系统级模式(平台特定位置)
- 默认模式
使用自定义模式进行沙箱化
将自定义模式与 Bob Shell 的沙箱功能结合,用于安全试验:
# 在沙箱中启动自定义模式
bob --chat-mode=script-dev --sandbox
# 与 Docker 沙箱结合使用
bob --chat-mode=deploy-helper --sandbox从 Bob IDE 迁移模式
主要差异
将自定义模式从 Bob IDE 迁移到 Bob Shell 时:
| 方面 | Bob IDE | Bob Shell |
|---|---|---|
| UI 交互 | 带面板的可视化界面 | 基于终端的界面 |
| 文件编辑 | 编辑器内 diff 和预览 | CLI diff 视图或外部编辑器 |
| 命令运行 | 集成终端 | 直接 shell 运行 |
| 模式切换 | UI 下拉或 slash 命令 | Slash 命令或 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
- command # Added for git operations
- browser这个主题怎么样?