Upvotes
0
Upvotes: 0codex的工作樹何時使用, 如何使用?
Codex 的「工作樹(worktree)」是建立一份與目前專案隔離的 Git 工作副本,讓 Codex 修改程式碼時,不會直接碰到你正在使用的目錄與分支。
最常見的是以下情況:
例如你目前在:
sha3-project/
└── main branch
你正在手動分析 RTL,同時想讓 Codex:
這時可以讓 Codex 使用工作樹。Codex 會在另一份隔離的目錄中修改,不會弄亂你目前尚未 commit 的內容。
例如:
每個任務使用自己的工作樹:
repo-main/ # 你目前使用的版本
codex-task-a/ # Verilator 修正
codex-task-b/ # EQY 分析
codex-task-c/ # synthesis script
因此三個 Codex agent 可以同時修改同一個 repository,而不會彼此覆蓋。這也是 Codex App 內建工作樹的主要目的。
例如:
如果結果不好,可以直接丟棄整個工作樹,你原本的專案不受影響。
以下情況直接在目前工作目錄執行通常比較方便:
特別要注意:新的 Git worktree 通常基於某個已存在的 commit 或 branch。
因此你目前目錄裡「尚未 commit」的修改,不一定會自動出現在新工作樹中。假如 Codex 必須看到這些修改,可以先 commit、建立 temporary branch,或者直接讓 Codex 在目前工作目錄處理。
一般流程如下:
Analyze the EQY equivalence failures between
keccak_f1600.sv and keccak_f1600.v.
Make changes only in this worktree.
Run the available tests and summarize every RTL modification.
Codex App 可讓你直接查看 agent 產生的 diff、留下修改意見,或在編輯器中手動調整;工作期間也不需要改變你原本 repository 的 Git 狀態。
工作樹和 branch 不完全相同:
一個 worktree 通常會 checkout 一個獨立 branch:
main working directory
└── branch: main
Codex worktree
└── branch: codex/fix-keccak-equivalence
兩個目錄共用同一份 Git object database,所以不像完整 git clone 那麼浪費空間,但各自有:
假設你目前在:
cd ~/project/sha3
建立新的 branch 與工作樹:
git worktree add -b codex/fix-eqy ../sha3-fix-eqy main
意思是:
git worktree add
新增工作樹。
-b codex/fix-eqy
建立名為 codex/fix-eqy 的 branch。
../sha3-fix-eqy
新工作目錄的位置。
main
以 main branch 為起點。
建立後:
cd ../sha3-fix-eqy
就會進入獨立工作樹。
查看目前所有工作樹:
git worktree list
可能顯示:
/home/edmund/sha3 a1b2c3d [main]
/home/edmund/sha3-fix-eqy d4e5f6g [codex/fix-eqy]
完成並合併:
cd ~/project/sha3
git merge codex/fix-eqy
移除工作樹:
git worktree remove ../sha3-fix-eqy
刪除已不需要的 branch:
git branch -d codex/fix-eqy
你可以把工作樹用在「讓 Codex實際修改與測試」,而不是單純問問題。
例如主目錄保留目前可運作版本:
sha3/
另外建立:
sha3-eqy-debug/
sha3-verilator-fix/
sha3-slang-compatible/
分別讓 Codex:
EQY debug:
Compare the SystemVerilog and generated Verilog implementations.
Do not change module interfaces.
Run EQY after each meaningful change.
Verilator cleanup:
Resolve actionable Verilator warnings without changing cycle-level behavior.
Separate testbench warnings from synthesizable RTL warnings.
Slang compatibility:
Make the RTL compatible with read_slang and Yosys while preserving behavior.
Run lint and synthesis checks.
這樣即使其中一個 Codex 任務進行了錯誤的大規模修改,你的主要工作目錄仍然安全。OpenAI 官方也將工作樹定位為多個 agent 平行處理同一 repository、探索不同修改方向而不互相衝突的方式。
Comments
Login to add a comment.
No comments yet.