配置

自定义模式

您可以创建自定义模式,将 Bob 的行为定制为特定任务或工作流。Bob Shell 中的自定义模式与 Bob IDE 模式的工作方式类似。

为什么在 Bob Shell 中使用自定义模式

  • Shell 优化工作流:创建专为基于终端的开发任务设计的模式
  • 命令行安全:在生产环境中限制模式仅执行安全操作
  • 环境特定行为:配置能适应不同 shell 环境的模式
  • 自动化友好:设计在交互式和非交互式会话中都能无缝运行的模式
  • 团队规范化:在团队间共享 shell 专属模式,保持一致的工作流

自定义模式包含什么

Bob Shell 中的自定义模式使用与 Bob IDE 模式相同的核心结构:

属性描述Shell 特定注意事项
slug唯一内部标识符用于命令行参数:
bob --chat-mode=my-mode
nameUI 中的显示名称显示在交互模式的模式选择器中
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-debug

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 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}

配置优先级

模式配置按以下顺序应用:

  1. 命令行参数(--chat-mode=mode-slug
  2. 项目级模式(.bob/custom_modes.yaml
  3. 用户级模式(~/.bob/custom_modes.yaml
  4. 系统级模式(平台特定位置)
  5. 默认模式

使用自定义模式进行沙箱化

将自定义模式与 Bob Shell 的沙箱功能结合,用于安全试验:

# 在沙箱中启动自定义模式
bob --chat-mode=script-dev --sandbox

# 与 Docker 沙箱结合使用
bob --chat-mode=deploy-helper --sandbox

从 Bob IDE 迁移模式

主要差异

将自定义模式从 Bob IDE 迁移到 Bob Shell 时:

方面Bob IDEBob 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
这个主题怎么样?