結構化 Context
經過篩選的目錄樹搭配清楚的檔案區塊,讓 AI 同時掌握專案結構與程式碼。也能為目錄樹設定獨立的篩選規則。
<file path="src/main.rs">專為開發者打造
OneSource 是在本機執行的命令列工具,將程式碼專案整理成單一 .onesource 檔案。從目錄結構到選取的檔案內容,提供清楚、可重複使用的 AI Context,並顯示預估 token 數。
Token 數僅供參考,實際用量依模型與 tokenizer 而異。
經過篩選的目錄樹搭配清楚的檔案區塊,讓 AI 同時掌握專案結構與程式碼。也能為目錄樹設定獨立的篩選規則。
<file path="src/main.rs">在本機整理檔案,預設遵守 .gitignore 等規則,略過常見敏感檔案、產生檔與依賴目錄。分享前仍需審查輸出內容。
.gitignore · local將常用掃描設定儲存在 .onesourcerc,透過具名 Profile 重複使用;需要調整時,再以命令列選項覆寫。
.onesourcerc02 / 輸出內容
執行 onesource 後,產生的檔案先列出目錄樹,再接上每個選取檔案的內容。檔案路徑清楚標示,方便將專案背景交給 AI,討論問題或修改方向。
my-project/
├── Cargo.toml
└── src/
└── main.rs
<file path="Cargo.toml">
[package]
name = "my-project"
</file>
<file path="src/main.rs">
fn main() {
println!("Hello!");
}
</file>03 / 控制你的 CONTEXT
用 include 指定檔案類型,exclude 排除不需要的路徑。排除規則優先;目錄樹也能使用自己的篩選設定。
onesource -i "*.rs,*.toml" -x "legacy/"dry-run 列出選取檔案與完整輸出的 token 估算,不建立檔案。確定內容後,也能直接將 Context 複製到剪貼簿。
onesource --dry-run
onesource --copy為不同工作儲存具名 Profile。設定依「命令列選項 → 選取的 Profile → 內建預設值」的順序套用。
onesource profile create backend -i "src/**"
onesource -p backendexplain 分別顯示檔案內容與目錄樹的判斷原因,包含 ignore、篩選規則、大小與二進位檔等。傳入實際路徑即可檢查。
onesource explain ./target
No 'default' profile in .onesourcerc, using CLI defaults.
════════════════════════════════════════
Path 1/1: ./target
Content:
Result: blocked by blacklist
Rule: blacklist = target
Tree:
Result: blocked by blacklist
Rule: blacklist = target
════════════════════════════════════════04 / 更多細節
預設略過大於 500 KiB 的檔案,以及常見的 .env、私鑰、node_modules、target 等路徑。檔案大小與二進位判斷會影響內容是否附上,但不會因此移除目錄樹中的路徑。
預設篩選有助於略過常見敏感路徑,仍需確認輸出是否包含秘密或不適合分享的內容。檔案區塊是方便 AI 閱讀的格式,不是安全邊界。
閱讀完整文件 ↗05 / 開始使用
已安裝 Rust 時,可以使用 Cargo 安裝免費、採 MIT 授權的 OneSource 命令列工具。
cargo install onesource安裝程式會下載最新版本至 /usr/local/bin,過程可能需要 sudo 權限。
curl -sSL https://raw.githubusercontent.com/TW-RF54732/onesource/main/install.sh | bash在 PowerShell 執行安裝指令,完成後重新開啟終端機以更新 PATH。
irm https://raw.githubusercontent.com/TW-RF54732/onesource/main/install.ps1 | iex在專案目錄執行以下指令。先預覽選取的檔案,再產生 .onesource 檔案或將 Context 複製到剪貼簿。分享給 AI 前,請確認輸出內容。
打包在本機執行,不會上傳程式碼。Token 數僅為估算。
下載免安裝執行檔 ↗onesource --dry-run
onesource
onesource --copy