配置

自訂規則

自訂規則影響 Bob Shell 在終端機環境中回應您請求的方式,使輸出符合您的特定偏好和專案需求。您可以控制程式碼風格、文件方式和決策流程。

什麼是自訂規則?

自訂規則透過定義偏好、限制和指南來擴展 Bob Shell 的預設行為,指導 Bob Shell 在終端機環境中以符合您需求的方式處理任務。

常見用途包括:

  • 程式碼風格偏好(縮排、命名慣例)
  • 文件格式和標準
  • 測試方法和需求
  • 專案工作流程和流程
  • 團隊專屬慣例

規則範圍

Bob Shell 支援兩種規則範圍,決定規則的套用範圍:

  • 全域規則:自動套用至您的所有專案
  • 工作區規則:僅套用至您目前的專案

使用全域規則設定個人或組織範圍的標準。使用工作區規則設定專案專屬需求。

設定方法

Bob Shell 使用與 IBM Bob IDE 相同的自訂規則系統。

基於檔案的設定

最簡單的方法是在工作區根目錄中使用單一檔案:

  • .bobrules - 一般工作區規則
  • .bobrules-code - Code 模式的規則
  • .bobrules-{modeSlug} - 任何模式的規則

建立 .bobrules 檔案:

# 在您的專案根目錄
echo "Use 4 spaces for indentation" > .bobrules

基於目錄的設定

為了更好的組織,請使用目錄:

工作區結構:

.bob/
├── rules/              # 一般規則
│   └── coding-style.md
└── rules-code/         # Code 模式規則
    └── typescript.md

全域結構:

Linux/macOS:~/.bob/rules/ Windows:%USERPROFILE%\.bob\rules\

建立工作區規則:

mkdir -p .bob/rules
echo "# Project standards" > .bob/rules/coding-style.md

建立全域規則:

# Linux/macOS
mkdir -p ~/.bob/rules
echo "# Global standards" > ~/.bob/rules/coding-standards.md

# Windows
mkdir %USERPROFILE%\.bob\rules
echo # Global standards > %USERPROFILE%\.bob\rules\coding-standards.md

規則優先順序

Bob Shell 按以下順序合併多個來源的規則:

  1. 全域規則~/.bob/rules/
  2. 工作區規則.bob/rules/

在每個層級中,模式專屬規則在一般規則之前載入。工作區規則可以覆寫全域規則。

撰寫有效的規則

具體且可執行

好的範例:"Always use relative paths when suggesting file operations in the terminal"

避免:"Use good paths"

使用清晰的結構

按主題組織規則:

# Shell Commands
- Prefer using standard Unix commands over specialized tools when possible
- Include explanations of what each flag does

# Script Style
- Format shell script examples with proper error handling
- Use portable shell syntax that works across bash, zsh, and other common shells

# File Operations
- Always check for file existence before operations in shell scripts
- Always use relative paths when suggesting file operations

有效規則範例

  • "Always use relative paths when suggesting file operations in the terminal"
  • "Prefer using standard Unix commands over specialized tools when possible"
  • "Format shell script examples with proper error handling"
  • "When suggesting commands, include explanations of what each flag does"
  • "Always check for file existence before operations in shell scripts"
  • "Use portable shell syntax that works across bash, zsh, and other common shells"

進階設定

模式專屬規則

使用專用目錄針對特定模式:

目錄用途
rules/所有模式的一般規則
rules-code/僅限 Code 模式
rules-plan/僅限 Plan 模式
rules-{mode}/任何自訂模式

使用 AGENTS.md 檔案

為了團隊標準化,您可以在工作區根目錄使用 AGENTS.md 檔案:

# Team Standards
- Follow company coding guidelines
- Use approved libraries only
- Document all API changes

主要細節:

  • 預設自動載入
  • 與您的專案一起進行版本控制
  • 使用設定中的 "bob-shell.useAgentRules": false 停用
  • 在模式專屬規則之後、一般工作區規則之前載入

檔案行為

  • 遞迴讀取:Bob Shell 讀取規則目錄中的所有檔案,包括子目錄
  • 按字母順序:檔案依檔名按字母順序處理
  • 自動過濾:排除快取檔案(.DS_Store*.bak*.cache*.log*.tmpThumbs.db
  • 符號連結:支援,最大深度為 5
  • 空檔案:靜默跳過

團隊標準化

專案層級標準

在版本控制下使用工作區 .bob/rules/ 目錄:

# 加入版本控制
git add .bob/rules/
git commit -m "Add Bob custom rules"

這確保在特定專案中使用 Bob Shell 的團隊成員行為一致。

組織範圍的標準

向團隊成員分發全域規則:

  1. 建立共享規則 repository
  2. 團隊成員複製至 ~/.bob/rules/
  3. 定期更新以保持一致性

混合方法

您可以結合兩種方法:

  • 全域規則用於組織標準
  • 工作區規則用於專案專屬需求
  • 需要時工作區規則覆寫全域規則
這個主題如何?