使用 explain 診斷

診斷遺漏檔案、判讀 Content/Tree/Rule、修正原因並重新預覽。

從預期卻沒出現的檔案開始

預覽或打包缺少檔案、想知道原因時,使用 explain,避免盲目嘗試不相關旗標。它逐路徑報告 Content 與 Tree 判斷,不產生打包檔。先準備以下獨立示範專案:

用文字編輯器在新的 demo 資料夾建立以下檔案。檔名後方是內容;每個 ↵ 代表換行。請只使用示範值。接著在 demo 開啟終端機,不要沿用已有 .onesourcerc 的資料夾。

  • README.md: # Demo
  • src/main.rs: fn main() {}
  • .gitignore: notes.txt
  • notes.txt: Local notes
  • .env: EXAMPLE_KEY=demo-only

需先能執行 onesource;尚未安裝請先看 安裝教學。除非步驟另有說明,本頁所有指令都從此資料夾執行。

1. 指定真正的路徑與當次設定

先預覽被 .gitignore 隱藏的筆記:

指令
onesource --no-config -i "notes.txt" --dry-run

預期處理數為零。診斷時帶相同 include 與 no-config 設定,把目標放在 explain 後:

指令
onesource explain notes.txt --no-config -i "notes.txt"

預期輸出/節錄
════════════════════════════════════════
Path 1/1: notes.txt
  Content:
    Result: blocked by ignore filters
  Tree:
    Result: blocked by ignore filters
════════════════════════════════════════

Content 回答文字是否會附加;Tree 回答路徑是否被樹選取。本例兩者都阻擋。ignore 沒有 Rule 行,因為此診斷只回報 ignore 層,不指出 .gitignore 的精確行號。

若掃描另一個根目錄,放在 explain 前;相對目標以該根目錄為準:

指令
onesource /path/to/project explain src/main.rs --no-config

請把示範根目錄換成實際資料夾。explain 後可列多個目標;應使用與被調查執行相同的 profile/選項。若已有 review profile,可用 onesource explain src/main.rs -p review。

2. 調整對應規則,再次預覽

報告原因是 ignore,因此改 include 或 tree-include 不會解決。若筆記通常仍應忽略,可只為這次刻意選取略過 ignore:

指令
onesource explain notes.txt --no-config -i "notes.txt" --no-ignore

兩部分應顯示 included。接著驗證整體選取,不只一個路徑:

指令
onesource --no-config -i "notes.txt" --no-ignore --dry-run

預期 notes.txt 與 Files Processed: 1。若想讓它每次正常執行都收錄,則應刻意修改 ignore 規則、再跑原本預覽。explain 不會編輯 ignore 或設定。

3. 閱讀 Rule,區分樹與內容

檔案可以刻意只顯示在地圖、不附加文字。用不同內容/樹 include 調查 README:

指令
onesource explain README.md --no-config -i "*.rs" --ti "*.md"

預期輸出/節錄
════════════════════════════════════════
Path 1/1: README.md
  Content:
    Result: not included by include
    Rule: include = *.rs
  Tree:
    Result: included
════════════════════════════════════════

Rule 告訴你哪個 include 未匹配:*.rs 不符合 README.md。若要一併附加 README,把內容 include 改為逗號聯集:

指令
onesource explain README.md --no-config -i "*.rs,README.md" --ti "*.md"

兩部分應回報 included,再驗證整體選取:

指令
onesource --no-config -i "*.rs,README.md" --ti "*.md" --dry-run

預期內容包含 README 與 main.rs,但樹只有 README。若要內容路徑也全部顯示在地圖,移除獨立的 --ti 覆寫。黑名單可用 onesource explain .env --no-config 診斷;Rule 指出 .env,include 無法恢復它。真正機密仍應保持排除。

各結果的意思與下一步

先讀結果,再改旗標。下表將每種診斷字串對應到原因與下一個合理檢查。阻擋結果仍是成功的診斷,不一定是指令執行錯誤。

結果原因與下一步
included通過此部分檢查;再用 dry-run 驗證完整選取。
included with lossy UTF-8 replacement characters非 UTF-8 文字已替代轉換;檢閱替代字元,或先將原檔轉為 UTF-8。
not found確認拼字與相對根目錄的位置,再建立或選取存在路徑。
outside the scan root解析目標在根目錄外;改選適當根目錄,或維持外部內容排除。
excluded because it is the current output file該路徑是 -o/預設輸出;若刻意要將它當輸入,請換輸出路徑。
not a content file (directory or special path)目錄沒有附加文字;改診斷目錄內的檔案,不要打包裝置或管線。
disabled by --no-tree樹已停用;需要地圖時用 --no-tree=false 恢復。
blocked by blacklist從 Rule 確認內建項目。機密維持排除;只有刻意檢閱過的輸入才略過。
blocked by ignore filters檢查專案/父層 ignore,或刻意用 --no-ignore 暫時略過。
blocked by exclude移除或限縮指出的 exclude;新增 include 無法勝過 exclude。
not included by include擴大指出的 include、加逗號模式,或用空字串清除限制。
skipped by max-size比對 Rule 實際位元組與 KiB 上限;內容預算允許時才提高 -m。
skipped because binary file找到 NUL 位元組;省略二進位內容,或從原工具匯出文字。
skipped because unreadable閱讀 Rule 的 metadata/讀取錯誤;確認權限、檔案存在與連結是否損壞,再重試。

接受的選項與診斷限制

必須提供至少一個路徑;相對路徑以掃描根目錄為準,也接受絕對路徑。根目錄是 explain 前的頂層 PATH。explain 後接受所有 profile 選項,以及 -p/--profile、--no-config 和相容旗標 --dry-run、--save、--replace、-c/--copy、--show-arg。explain 後的選項優先於頂層選項。--desc 與相容動作旗標不會儲存、取代、複製、產生打包檔或印出解析參數;explain 在一般執行前即返回。它可能讀取與檢查檔案。

explain 檢查當下檔案系統,可能讀取內容並遍歷 ignore。不存在的路徑只回報 Content;解析/權限錯誤可能中止診斷。符號連結正規化與 ignore 遍歷可能和完整掃描不同,兩次執行間檔案也可能改變,所以最後用 dry-run 確認選取。動作旗標只是為相容而接受,explain --save --copy --replace 不會做這些動作。