创建新的智能体终端
在用户要求时生成一个新的智能体终端。新智能体通过 agent-shell 在 Emacs 内部运行,并工作于一个隔离的 Git 工作树中。
步骤
1. 确定参数
- 提示:新智能体应处理什么任务?如果不清楚,询问用户。
- 名称:一个基于任务的简短、kebab-case 格式的工作树名称(例如
refactor-auth、fix-login-bug、add-dark-mode)。 - 智能体:要使用的智能体(例如
claude、codex、opencode)。除非用户另有指定,否则使用当前运行此技能的同一智能体。
2. 创建工作树
在当前仓库的 .agent-shell/worktrees/ 目录内创建一个 Git 工作树,分支命名为 agent/<name>:
git worktree add -b "agent/<name>" ".agent-shell/worktrees/<name>"
3. 运行仓库设置
检查工作树中的设置说明并运行它们。查找以下文件:
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
在工作树目录内运行设置命令:
cd ".agent-shell/worktrees/<name>" && <setup-command>
4. 在 Emacs 中启动智能体
调用 emacsclient 启动新的智能体终端:
emacsclient -e '(my/agent-shell-make
:prompt "<task description>"
:name "<worktree-name>"
:agent "<agent>"
:directory "<absolute-path-to-worktree>")'
示例:
emacsclient -e '(my/agent-shell-make
:prompt "Refactor the auth to use async/await. See @..."
:name "refactor-auth"
:agent "claude"
:directory "/Users/me/projects/my-app/.agent-shell/worktrees/refactor-auth")'
directory 必须使用绝对路径。
5. 向用户报告
告知用户:
- 工作树的路径和分支名称
- 运行了哪些设置(或未运行设置)
- 新智能体已在 Emacs 中启动
规则
- 始终在当前仓库内的
.agent-shell/worktrees/中创建工作树。 - 始终为工作树创建一个名为
agent/<name>的新分支。 :directory必须始终使用绝对路径。- 除非用户另有指定,否则使用与当前运行此技能相同的
:agent。 - 通过 Bash 工具运行所有命令。
- 如果 Emacs 未运行或
emacsclient失败,向用户报告错误以及手动运行的命令。