🧟 亡灵
一个用于OpenAI兼容API的最小CLI聊天客户端,支持工作区和MCP。
安装
Arch Linux(AUR)
您可以安装 undead 从AUR使用您最喜欢的助手:```bash
yay -S undead
or
paru -S undead
### 来源```bash
cargo build --release
用法```bash
Basic usage
./undead
With custom endpoint
./undead --endpoint http://localhost:11434/v1 --model llama2
With OpenAI API
./undead --endpoint https://api.openai.com/v1 --api-key sk-your-key --model gpt-4
With workspace (file operations)
./undead --workspace ./my-project
With MCP servers
./undead --mcp ./mcp.json
With MCP servers amd workspace
./undead --endpoint http://localhost:8080/v1 --mcp ./mcp.json --workspace ./my-project
## 选项
|选项|默认值|环境|描述|
|--------|---------|-----|-------------|
| `-e, --endpoint` | `http://localhost:8080/v1` | `UNDEAD_ENDPOINT` |API终点|
| `-m, --model` | `local-model` | `UNDEAD_MODEL` |型号名称|
| `-k, --api-key` | - | `UNDEAD_API_KEY` |API密钥|
| `-s, --system` | `You are a helpful assistant.` | `UNDEAD_SYSTEM` |系统提示|
| `-t, --temperature` | `0.7` | `UNDEAD_TEMPERATURE` |温度(0.0-2.0)|
| `-T, --max-tokens` | `2048` | `UNDEAD_MAX_TOKENS` |最大令牌数|
| `-w, --workspace` | - | `UNDEAD_WORKSPACE` |工作区目录|
| `-c, --mcp` | - | `UNDEAD_MCP` |MCP配置文件|
| `-C, --config` | - | `UNDEAD_CONFIG` |配置文件路径|
| `-p, --preset` | - | `UNDEAD_PRESET` |预设名称|
## 配置和预设
使用配置文件管理多个API配置:```bash
# Use config with preset
./undead -C ./config.yml -p mylocal
# Use config without preset (uses global values)
./undead -C ./config.yml
配置文件格式(config.yml):```yaml
Global defaults
UNDEAD_ENDPOINT: "https://openrouter.ai/api/v1"
UNDEAD_MODEL: "x-ai/grok-4-fast"
UNDEAD_API_KEY: ""
UNDEAD_SYSTEM: ""
UNDEAD_TEMPERATURE: ""
UNDEAD_MAX_TOKENS: ""
UNDEAD_WORKSPACE: ""
UNDEAD_MCP: ""
UNDEAD_CONFIG: ""
UNDEAD_PRESET: ""
presets:
"mylocal":
UNDEAD_ENDPOINT: "http://192.168.0.124:8888/v1"
UNDEAD_MODEL: "local-model"
"openrouter":
UNDEAD_ENDPOINT: "https://openrouter.ai/api/v1"
UNDEAD_MODEL: "x-ai/grok-4-fast"
**优先:** CLI参数>配置预设>配置全局>环境变量>默认值
## 工作区
在目录中启用文件操作:```bash
./undead --workspace ./src
可用工具:
read_file-读取文件内容write_file-写入/创建文件edit_file-使用精确的字符串替换编辑文件create_directory-创建目录delete_file-删除文件delete_directory-删除目录list_directory-列出目录内容execute-在工作区中执行shell命令
所有操作都被沙盒化到工作区目录中。
注: 这 execute 该工具在运行任何命令之前都需要用户确认。系统将提示您 Run? (y/N): 并且必须键入 y 继续。
代理目录
配置工作区后,亡灵生物会自动读取所有内容 *.md 文件来自 .agent/ 目录以自定义代理的行为。如果目录不存在,将创建它。```bash
./undead --workspace ./my-project
Reads from ./my-project/.agent/*.md or creates the directory
**示例 `.agent/` 目录:**```
my-project/
├── .agent/
│ ├── persona.md # "You are a senior Rust developer"
│ ├── skills.md # "Code review, refactoring, documentation"
│ └── context.md # "This is a CLI tool for AI chat"
└── src/
└── ...
全部 *.md 当工作区处于活动状态时,文件会自动加载并附加到系统提示中。每个文件都成为一个以文件名为标题的部分。
主控程序
连接到模型上下文协议服务器以扩展功能:json
{
"mcp_servers": {
"city": {
"type": "remote",
"url": "https://mcp.example.com/mcp?key=sk_5af",
"enabled": true
},
"context7": {
"command": "bunx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "ctx7sk-..."],
"enabled": true
},
}
}
本地服务器:
type: "local", command, args, env\
远程服务器:
type: "remote", url
交互式命令
exit,quit,q-退出clear-清除历史记录\e-打开编辑器进行多行输入Ctrl+C-取消当前生成Ctrl+D-退出
类型 \e 打开默认编辑器,您可以在其中编写多行消息。保存并关闭编辑器时,内容将发送到LLM。
编辑器选择优先级:
$EDITOR环境变量$VISUAL环境变量- 平台默认值:
vim(macOS),nano(Linux),notepad(Windows)
兼容的API
与任何与OpenAI兼容的API配合使用:
- llama.cpp
- 奥拉玛
- vLLM
- LocalAI
- 开放人工智能
- Azure OpenAI
许可证
麻省理工学院
