配置

自訂模式

您可以建立自訂模式,使 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 commands 切換模式:

# 切換至自訂模式
/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. 預設模式

搭配自訂模式使用 Sandbox

將自訂模式與 Bob Shell 的 sandbox 功能結合,以進行安全實驗:

# 在 sandbox 中啟動自訂模式
bob --chat-mode=script-dev --sandbox

# 搭配 Docker sandbox 使用
bob --chat-mode=deploy-helper --sandbox

從 Bob IDE 移轉模式

主要差異

從 Bob IDE 移轉自訂模式至 Bob Shell 時:

面向Bob IDEBob Shell
UI 互動帶有面板的視覺介面終端機型介面
檔案編輯編輯器內 diff 和預覽CLI diff 視圖或外部編輯器
命令執行整合式終端機直接 shell 執行
模式切換UI 下拉選單或 slash commandsSlash commands 或 CLI 引數
設定設定 UI + 檔案僅設定檔

調整清單

調整 Bob IDE 模式以適用於 Bob Shell 時:

  • 審查 roleDefinition 中的 shell 專屬上下文
  • 更新 customInstructions 以參照命令列工作流程
  • groups 設定中考慮命令執行安全性
  • 在互動式和非互動式工作階段中測試模式
  • 確認檔案路徑處理在 shell 上下文中正常運作
  • 如適用,使用 sandbox 模式測試

移轉範例

原始 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
這個主題如何?