@eden_qu/ai-desk-daemon
v1.0.14
Published
AI Desk Daemon - CLI tool for managing the AI Desk daemon service
Readme
AI Desk Desktop
一个类似 Docker Desktop 的桌面应用,用于管理本地 AI CLI 工具的守护进程。
✨ 特性
- 🎯 自动启动 - Web 访问时自动检测并启动守护进程
- 🖥️ 图形化管理 - 系统托盘 + 控制面板,便捷管理
- 🔄 实时监控 - 查看守护进程状态、日志和统计信息
- 🚀 智能启动器 - 多种方式自动唤醒守护进程
- 🔒 安全可靠 - 工作目录白名单、认证支持
- 📦 跨平台 - macOS、Windows、Linux 统一体验
- ⚡ 高性能 - 基于 Tauri,体积小(~15MB)、内存占用低
📦 安装
方式 1: npm 安装(纯 CLI 工具)
适合场景:开发者、服务器环境、CI/CD、命令行用户
# 全局安装
npm install -g @eden_qu/ai-desk-daemon
# 启动 daemon
aidesk start
# 查看状态
aidesk status包含内容:
- ✅ AI Desk Daemon 后台服务
- ✅ CLI 命令行管理工具
- ✅ HTTP API (http://localhost:9527)
不包含:
- ❌ 系统托盘应用 (Tray)
- ❌ 桌面 GUI 应用
可用命令:
aidesk start- 启动守护进程aidesk stop- 停止守护进程aidesk restart- 重启守护进程aidesk status- 查看状态aidesk logs- 查看日志aidesk logs -f- 实时查看日志
📖 详细使用说明:NPM_CLI.md
方式 2: 完整安装(Daemon + Tray)
适合场景:桌面用户、需要系统托盘图标、完整 GUI 体验
macOS
# 下载并安装
curl -fsSL https://github.com/your-repo/ai-desk-desktop/releases/latest/download/install-macos.sh | bash
# 或手动安装
./scripts/install-macos.shLinux
# Ubuntu/Debian
sudo ./scripts/install-linux.sh
# 启用自动启动
systemctl --user enable ai-desk-daemon
systemctl --user start ai-desk-daemonWindows
# 以管理员身份运行 PowerShell
.\scripts\install-windows.ps1🚀 快速开始
1. 启动桌面应用
macOS/Linux:
# 从应用程序菜单启动
open /Applications/AI\ Desk\ Desktop.app
# 或命令行启动
ai-desk-desktopWindows:
- 从开始菜单启动 "AI Desk Desktop"
2. Web 应用集成
在你的 Web 应用中集成智能启动器:
// App.tsx
import DaemonInitializer from './components/common/DaemonInitializer';
function App() {
return (
<DaemonInitializer>
<YourMainApp />
</DaemonInitializer>
);
}启动器会自动:
- ✅ 检测守护进程是否运行
- ✅ 如果未运行,通过多种方式尝试启动
- ✅ 等待守护进程就绪
- ✅ 失败时显示友好的错误提示
3. 使用 Daemon API
import { daemonService } from './services/DaemonService';
// 执行 CLI 命令
const result = await daemonService.executeCLI({
command: 'claude',
args: ['--verbose'],
stdin: 'Your prompt here',
cwd: '/path/to/workspace',
timeout: 300000,
});
// 流式执行
await daemonService.executeStreaming(
{ command: 'claude', args: [], stdin: 'Hello!' },
(chunk) => console.log(chunk), // onChunk
(result) => console.log(result), // onComplete
(error) => console.error(error) // onError
);🏗️ 架构
┌─────────────────────────────────────────────────────┐
│ AI Desk Desktop App │
│ (Tauri Application) │
│ │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ System │ │ Control │ │ Settings │ │
│ │ Tray │ │ Panel │ │ Panel │ │
│ └──────────┘ └──────────┘ └──────────┘ │
│ │ │ │
│ └────────────────┼──────────────────────────┘
│ ▼
│ ┌──────────────────┐
│ │ Daemon Process │
│ │ HTTP Server :9527│
│ └──────────────────┘
│ │
│ ┌────────────────┼────────────────┐
│ ▼ ▼ ▼
│ ┌────────┐ ┌────────┐ ┌────────┐
│ │ Claude │ │ Gemini │ │ Cursor │
│ └────────┘ └────────┘ └────────┘
│
├─────────────────────────────────────────────────────┤
│ Web Application │
│ (React/TypeScript) │
│ │
│ ┌────────────────────────────────────┐ │
│ │ Smart Daemon Starter │ │
│ │ - Auto-detect & Start │ │
│ │ - URL Scheme / Extension / HTTP │ │
│ └────────────────────────────────────┘ │
└─────────────────────────────────────────────────────┘📚 组件说明
1. Daemon(守护进程)
基于 Go 开发的 HTTP/WebSocket 服务器:
功能:
- CLI 检测(claude、gemini、cursor)
- CLI 执行(同步和流式)
- 并发控制和超时管理
- 安全策略(工作目录白名单)
- 日志记录
API 端点:
GET /health- 健康检查GET /api/v1/clis- 检测 CLIPOST /api/v1/execute- 执行 CLI(REST)WS /api/v1/execute/stream- 执行 CLI(WebSocket)POST /api/v1/execute/{id}/cancel- 取消执行
2. Tauri Desktop(桌面应用)
基于 Tauri(Rust + React)的桌面应用:
功能:
- 系统托盘图标和菜单
- 守护进程生命周期管理
- 实时状态监控
- 日志查看
- 设置管理
- URL Scheme 注册
3. Web Integration(Web 集成)
Smart Daemon Starter(智能启动器):
- 自动检测守护进程
- 多种启动方式(URL Scheme、Extension、HTTP)
- 自动重试机制
- 友好的错误提示
Daemon Service(守护进程服务):
- HTTP/WebSocket 通信
- CLI 执行和流式输出
- 错误处理
⚙️ 配置
Daemon 配置
配置文件位置:~/.aidesktop/daemon-config.json
{
"port": 9527,
"max_concurrent_executions": 10,
"execution_timeout": 300,
"allowed_origins": [
"*"
],
"allowed_working_dirs": [
"/path/to/your/home"
],
"require_authentication": false,
"auth_token": "",
"log_level": "INFO"
}说明:9527 是默认端口,实际运行时以 ~/.aidesktop/daemon-config.json 中的 port 为准。
应用配置
配置文件位置:~/.aidesktop/app-config.json
{
"auto_start": true,
"minimize_to_tray": true,
"daemon_port": 9527
}如果你修改了 daemon 配置端口,请保持这里的 daemon_port 与之同步。
🔧 开发
前置要求
- Node.js 18+
- Rust 1.70+
- Go 1.21+ (用于守护进程)
- Tauri CLI 1.5+
构建
# 克隆仓库
git clone https://github.com/your-repo/ai-desk-desktop.git
cd ai-desk-desktop
# 安装依赖
npm install
# 构建所有组件
./scripts/build.sh
# 或分别构建:
# 1. 构建守护进程
cd daemon && go build -o ai-desk-daemon
# 2. 构建前端
npm run build
# 3. 构建 Tauri 应用
npm run tauri build开发模式
# 终端 1: 启动守护进程
cd daemon
go run .
# 终端 2: 启动 Tauri 应用
npm run tauri:dev📖 使用示例
在 Web 应用中显示守护进程状态
import { DaemonStatusIndicator } from './components/common/DaemonStatusBanner';
function Layout() {
return (
<div>
<Header />
<Content />
<DaemonStatusIndicator /> {/* 显示在右下角 */}
</div>
);
}条件渲染(守护进程可用时)
import { useDaemon } from './hooks/useDaemon';
function AgentPanel() {
const { isAvailable, isChecking } = useDaemon();
if (isChecking) {
return <div>Checking daemon...</div>;
}
if (!isAvailable) {
return (
<div>
Daemon not available.
<button onClick={() => window.location.href = 'aidesktop://start'}>
Launch Now
</button>
</div>
);
}
return <YourAgentInterface />;
}🐛 故障排查
macOS Gatekeeper 警告
问题:macOS 阻止运行未签名的应用
解决方案:
# 移除隔离属性
xattr -cr "/Applications/AI Desk Desktop.app"守护进程未启动
检查日志:
tail -f ~/.aidesktop/logs/daemon.log手动启动测试:
/usr/local/bin/ai-desk-daemon --config ~/.aidesktop/daemon-config.jsonWeb 应用无法连接
检查守护进程是否运行:
curl http://localhost:<port>/health检查防火墙设置
确认配置文件中的端口未被占用
📄 许可证
MIT License
🤝 贡献
欢迎提交 Issues 和 Pull Requests!
📧 支持
- GitHub Issues: https://github.com/your-repo/ai-desk-desktop/issues
- 文档: https://docs.aidesktop.com
Version: 1.0.0
Maintained by: AI Desk Team
