|
|
10 jam lalu | |
|---|---|---|
| cmd | 1 hari lalu | |
| docs | 10 jam lalu | |
| firmware | 4 hari lalu | |
| hooks | 1 hari lalu | |
| internal | 10 jam lalu | |
| opencode-plugin | 1 hari lalu | |
| scripts | 3 minggu lalu | |
| .gitignore | 3 minggu lalu | |
| Makefile | 3 minggu lalu | |
| README.md | 1 hari lalu | |
| go.mod | 1 hari lalu | |
| go.sum | 2 minggu lalu |
AI 编程工具状态灯,支持 OpenCode、Claude Code、Codex 等工具,通过 MQTT 或 BLE 蓝牙推送状态到硬件灯。
前端仓库: ai-status-light-web
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ OpenCode │ │ Claude Code │ │ Codex │
│ (插件) │ │ (HTTP Hook) │ │ (Command Hook) │
└────────┬────────┘ └────────┬────────┘ └────────┬────────┘
│ │ │
└───────────────────────┼───────────────────────┘
│
▼
┌─────────────────────────┐
│ AI Status Light │
│ (API 服务) │
└────────────┬────────────┘
│
┌────────────┴────────────┐
│ │
▼ ▼
┌───────────────┐ ┌───────────────┐
│ MQTT │ │ BLE │
└───────┬───────┘ └───────┬───────┘
│ │
▼ ▼
┌───────────────┐ ┌───────────────┐
│ 硬件灯 │ │ 硬件灯 │
└───────────────┘ └───────────────┘
从 dist/ 目录下载对应平台的可执行文件:
ai-status-light-linux-amd64 - Linux x86_64ai-status-light-linux-arm64 - Linux ARM64ai-status-light-windows-amd64.exe - Windows x86_64ai-status-light-darwin-arm64 - macOS Apple Silicon# 克隆项目
git clone <repository-url>
cd ai-status-light
# 当前平台(不含 BLE)
go build -o bin/ai-status-light ./cmd/monitor
# 当前平台(含 BLE 嵌入)
scripts/build.sh --ble # Linux/macOS
scripts\build.bat --ble # Windows
# 所有平台
scripts/build.sh
# 启动 API 服务
./ai-status-light serve --addr :8045
# 启动服务并启用 HTTPS
./ai-status-light serve --addr :8045 --tls
# 一键安装所有 hooks(OpenCode、Claude Code、Codex)
./hooks/install.sh
# 单独安装
./hooks/install.sh --opencode
./hooks/install.sh --claude
./hooks/install.sh --codex
# 自定义服务地址
STATUS_LIGHT_URL=http://192.168.1.100:8045 ./hooks/install.sh
# 配置 MQTT
./ai-status-light config set --broker tcp://192.168.1.100:1883 --topic opencode/status
# 配置 BLE
./ai-status-light config ble set --device AI-Light --service-uuid "b8b7e001-..." --char-uuid "b8b7e002-..."
# 配置设备(通过 MQTT 下发配置到硬件灯)
./ai-status-light config device set --device AI-Light --mqtt-broker 192.168.1.100 --wifi-ssid MyWiFi --wifi-pass MyPassword
启动服务并安装 hooks 后,正常使用 OpenCode、Claude Code 或 Codex,灯会自动响应状态变化。
插件文件:~/.config/opencode/plugins/status-light.ts
配置文件:~/.config/opencode/status-light.json
{
"serviceUrl": "http://localhost:8045"
}
配置文件:~/.claude/settings.json
{
"hooks": {
"Stop": [
{
"hooks": [
{
"type": "http",
"url": "http://localhost:8045/api/event",
"async": true
}
]
}
],
"PostToolUse": [
{
"matcher": "Bash|Edit|Write",
"hooks": [
{
"type": "http",
"url": "http://localhost:8045/api/event",
"async": true
}
]
}
]
}
}
配置文件:~/.codex/hooks.json
{
"hooks": {
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "curl -s -X POST http://localhost:8045/api/event -d '{\"code\":\"idle\"}' &"
}
]
}
]
}
}
POST /api/event
Content-Type: application/json
{
"code": "busy",
"source": "opencode"
}
| code | 说明 |
|---|---|
| idle | 空闲 |
| busy | 工作中 |
| reasoning | 思考中 |
| using_tool | 使用工具中 |
| permission | 等待权限 |
| error | 错误 |
| init | 初始化 |
更多 API 接口详见 API 文档。
./ai-status-light serve [选项]
选项:
--addr string 监听地址 (默认 ":8080")
--db string 数据库路径 (默认 "./data/config.db")
--tls 启用 HTTPS
--tls-cert string TLS 证书文件路径
--tls-key string TLS 私钥文件路径
--log-file string 日志文件路径
--log-level string 日志级别 (debug/info/warn/error)
# 查看 MQTT 配置
./ai-status-light config list
# 设置 MQTT 配置
./ai-status-light config set --broker tcp://127.0.0.1:1883 --topic opencode/status
# 查看 BLE 配置
./ai-status-light config ble list
# 设置 BLE 配置
./ai-status-light config ble set --device AI-Light
# 查看设备配置
./ai-status-light config device list
# 设置设备配置(用于通过 MQTT 下发到硬件灯)
./ai-status-light config device set --device AI-Light --mqtt-broker 192.168.1.100 --wifi-ssid MyWiFi --wifi-pass MyPassword
ai-status-light/
├── cmd/monitor/
│ ├── main.go # 程序入口
│ ├── ble_embed.go # BLE 嵌入声明
│ └── ble_embed_none.go # BLE 空声明
├── internal/
│ ├── api/ # HTTP API 模块
│ ├── database/ # SQLite 数据库模块
│ ├── logger/ # 日志模块
│ ├── mqtt/ # MQTT 客户端模块
│ └── web/ # Web 静态文件
├── hooks/ # AI 工具 hooks 配置
│ ├── install.sh # 一键安装脚本
│ ├── claude-code/ # Claude Code hooks
│ └── codex/ # Codex hooks
├── opencode-plugin/ # OpenCode 插件
│ └── status-light.ts # 插件源码
├── firmware/ # ESP32-C3 硬件固件
├── docs/ # 文档
└── scripts/ # 构建脚本
前端项目: ai-status-light-web (Vue 3 + TypeScript)
# 安装依赖
go mod tidy
# 运行
go run ./cmd/monitor serve --addr :8045
# 构建
go build -o bin/ai-status-light ./cmd/monitor
# 构建(含 BLE)
scripts/build.sh --ble
MIT License