配置
忽略檔案
透過在您的專案中建立 `.bobignore` 檔案來控制 Bob Shell 可以存取的檔案。
概覽
| 功能 | 說明 | 優點 |
|---|---|---|
| 路徑排除 | 防止 Bob Shell 存取特定檔案或目錄 | 保護敏感資訊 |
| 模式比對 | 使用 glob 模式比對多個檔案 | 有效排除檔案類型 |
| 否定支援 | 覆寫特定檔案的排除規則 | 精細控制 |
| 專案專屬 | 每個專案可以有自己的排除規則 | 根據專案需求客製化 |
為何使用 .bobignore?
- 隱私保護: 將 API key 和憑證等敏感檔案設為私有
- 效能改善: 排除會拖慢操作速度的大型二進位檔案或目錄
- 降低雜訊: 從 Bob Shell 的上下文中移除不相關的檔案
- 聚焦控制: 將 Bob Shell 的注意力導向您程式碼庫中最相關的部分
.bobignore 的運作方式
.bobignore 控制 Bob Shell 的檔案工具可以存取哪些檔案。如果檔案符合被忽略的模式,Bob Shell 的檔案工具就無法讀取、寫入或刪除它,且該檔案會從列出和搜尋結果中排除。透過 execute_command 執行的 shell 命令不受 .bobignore 篩選;shell 命令仍可在作業系統允許的任何位置讀取或修改檔案。
當您將路徑加入 .bobignore 檔案時,遵守此檔案的 Bob Shell 工具將自動從其操作中排除符合的檔案和目錄。例如,read_file、grep、glob 和 list_files 會跳過符合的路徑,檔案寫入工具也無法修改它們。
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ │ │ │ │ │
│ Your project │────▶│ .bobignore │────▶│ Files Bob Shell │
│ files │ │ filter │ │ can access │
│ │ │ │ │ │
└─────────────────┘ └─────────────────┘ └─────────────────┘Bob Shell 會自動重新讀取您的 .bobignore 檔案,因此變更會在約 30 秒內生效,無需重新啟動。
模式語法
.bobignore 檔案遵循與 .gitignore 相同的模式語法:
| 模式 | 說明 | 範例 |
|---|---|---|
file.txt | 比對特定檔案 | apikeys.txt |
*.ext | 比對所有具有該副檔名的檔案 | *.log |
/dir/ | 比對目錄 | /node_modules/ |
/path/to/file | 將路徑錨定至根目錄 | /src/config/secrets.json |
!pattern | 否定先前的模式 | !important.md |
# | 注釋行 | # API credentials |
快速入門
建立 .bobignore 檔案
- 在您的專案根目錄建立名為
.bobignore的檔案 - 加入您要排除的檔案和目錄的模式
- 儲存檔案。變更會在約 30 秒內生效。
# 從您的專案根目錄
touch .bobignore
echo "# Files to ignore" > .bobignore
echo "secrets/" >> .bobignore常見排除模式
以下是一些您可能想加入 .bobignore 檔案的常見模式:
# Sensitive information
.env
secrets/
*password*
*credential*
*apikey*
# Large directories
node_modules/
.git/
dist/
build/
# Binary and media files
*.zip
*.tar.gz
*.mp4
*.jpg
*.png
# Log files
*.log
logs/模式範例
排除特定目錄
排除整個目錄及其內容:
# Exclude the packages directory and all its contents
/packages/
# Exclude all node_modules directories anywhere in the project
**/node_modules/
# Exclude the dist directory but only at the root level
/dist/使用萬用字元
萬用字元讓您可以用相似的模式比對多個檔案:
# Exclude all markdown files
*.md
# Exclude all JavaScript files in the src directory
/src/**/*.js
# Exclude all files with "test" in their name
*test*使用否定
您可以覆寫特定檔案的排除規則:
# Exclude all markdown files
*.md
# But include README.md
!README.md
# And include all markdown files in the docs directory
!docs/*.md進階用法
組合模式
您可以組合模式建立複雜的排除規則:
# Exclude all JavaScript files
*.js
# But include all files in the src directory
!src/**/*.js
# Except for test files in the src directory
src/**/*.test.js除錯您的 .bobignore 檔案
如果 Bob Shell 似乎忽略了您想讓它存取的檔案,或存取了您想讓它忽略的檔案:
- 檢查您的
.bobignore檔案是否有衝突的模式 - 記住更具體的模式(例如否定模式)應放在一般模式之後
- 變更後請等待約 30 秒讓變更生效
- 撰寫模式時,請使用相對於包含
.bobignore檔案之目錄的路徑,與.gitignore相同
最佳實踐
- 從簡單開始: 從幾個基本模式開始,根據需要增加更多
- 為模式加注釋: 加入注釋說明為何排除某些檔案
- 具體說明: 使用精確的模式,避免意外排除重要檔案
- 考慮安全性: 始終排除包含敏感資訊的檔案
- 定期維護: 隨著專案演進更新您的
.bobignore檔案
這個主題如何?