配置

自定义规则

自定义规则影响 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. 创建共享规则仓库
  2. 团队成员克隆到 ~/.bob/rules/
  3. 定期更新以保持一致性

混合方式

您可以结合使用两种方式:

  • 全局规则用于组织标准
  • 工作区规则用于项目特定要求
  • 必要时工作区规则覆盖全局规则
这个主题怎么样?