建立新的 agent-shell
在使用者要求時產生新的 agent-shell。新的代理透過 agent-shell 在 Emacs 內執行,並在隔離的 git worktree 中運作。
步驟
1. 確定參數
- 提示:新代理應該處理什麼任務?如果不清楚,請詢問使用者。
- 名稱:一個簡短、以 kebab-case 格式命名的 worktree 名稱,根據任務而定(例如
refactor-auth、fix-login-bug、add-dark-mode)。 - 代理:要使用的代理(例如
claude、codex、opencode)。除非使用者另行指定,否則應使用目前正在執行此技能的同一代理。
2. 建立 worktree
在目前儲存庫的 .agent-shell/worktrees/ 目錄下建立一個 git worktree,分支名稱為 agent/<name>:
git worktree add -b "agent/<name>" ".agent-shell/worktrees/<name>"
3. 執行儲存庫設定
檢查 worktree 中的設定說明並執行它們。請尋找:
CLAUDE.md、AGENTS.md、README.md— 設定/建置/安裝指令Makefile—make setup或make installpackage.json—npm install/npm ci/pnpm install/yarn installpyproject.toml/requirements.txt—uv sync/pip install -e .Gemfile—bundle installCargo.toml—cargo fetch.env.example— 複製為.env
在 worktree 目錄內執行設定指令:
cd ".agent-shell/worktrees/<name>" && <setup-command>
4. 在 Emacs 中啟動代理
呼叫 emacsclient 啟動新的代理 shell:
emacsclient -e '(my/agent-shell-make
:prompt "<任務描述>"
:name "<worktree-name>"
:agent "<agent>"
:directory "<worktree-的絕對路徑>")'
範例:
emacsclient -e '(my/agent-shell-make
:prompt "將驗證功能重構為使用 async/await。請參閱 @..."
:name "refactor-auth"
:agent "claude"
:directory "/Users/me/projects/my-app/.agent-shell/worktrees/refactor-auth")'
對 :directory 請使用絕對路徑。
5. 回報給使用者
告訴使用者:
- worktree 路徑與分支名稱
- 已執行哪些設定(或無需設定)
- 新的代理已在 Emacs 中啟動
規則
- 始終在目前儲存庫的
.agent-shell/worktrees/內建立 worktree。 - 始終為 worktree 建立名為
agent/<name>的新分支。 - 始終對
:directory使用絕對路徑。 - 除非使用者另行指定,否則使用目前正在執行此技能的同一
:agent。 - 所有指令皆透過 Bash 工具執行。
- 如果 Emacs 未執行或
emacsclient失敗,請將錯誤回報給使用者,並附上可手動執行的指令。