1. 项目概述:为AI助手打造像素风可视化工作台
最近在折腾AI编程助手时,我发现一个特别有意思的现象:当Claude Code这类工具在后台默默工作时,我们只能面对冷冰冰的终端窗口,完全看不到它的"工作状态"。这就像请了个隐形员工,你知道他在干活,但永远不知道他是在认真写代码,还是在摸鱼发呆。
直到我发现了Star Office UI这个开源项目——它用像素风格为AI助手打造了一个可视化办公室。你的AI助手会以可爱的像素形象出现在办公室里,根据当前工作状态在不同区域移动:写代码时坐到工位前,调试时蹲在角落,摸鱼时溜达到休息区...
2. 核心功能解析
2.1 状态可视化系统
这个项目的核心在于状态映射机制。AI助手的工作状态被抽象为6种基本类型:
- 闲置(idle):像素角色站在办公室中央待命
- 写作(writing):移动到办公桌前打字
- 研究(researching):走到书架前翻书
- 执行(executing):站在服务器旁操作
- 同步(syncing):在文件柜前整理文档
- 报错(error):蹲在角落的"bug区"修电脑
每个状态都配有对应的像素动画和气泡提示。最有趣的是"昨日小记"功能,它会自动读取AI助手的工作日志,经过脱敏处理后生成日报展示在办公室公告板上。
2.2 技术实现架构
整个系统采用前后端分离设计:
- 前端:使用Phaser游戏引擎渲染像素办公室
- 后端:Python Flask服务处理状态更新
- 通信:WebSocket实现实时状态推送
状态数据存储在JSON文件中,格式如下:
{ "state": "writing", "detail": "正在生成Python代码", "updated_at": "2023-11-15T14:30:00Z" }3. 安装与配置指南
3.1 基础环境搭建
首先确保系统已安装:
- Python 3.8+
- Git
- Node.js 16+ (仅前端开发需要)
推荐使用conda创建独立环境:
conda create -n office-ui python=3.8 conda activate office-ui3.2 项目部署步骤
- 克隆仓库:
git clone https://github.com/ringhyacinth/Star-Office-UI.git cd Star-Office-UI- 安装Python依赖:
pip install -r backend/requirements.txt- 初始化状态文件:
cp state.sample.json state.json- 启动后端服务:
cd backend python app.py服务默认运行在18791端口,浏览器访问http://localhost:18791即可看到像素办公室。
4. 与OpenClaw集成方案
4.1 直接修改状态文件法
这是最规范的集成方式,需要修改OpenClaw的moltbot源码:
- 定位到agent处理逻辑(通常在
src/agent/目录) - 在任务开始时写入writing状态:
with open('state.json', 'w') as f: json.dump({ 'state': 'writing', 'detail': '正在处理请求', 'updated_at': datetime.now().isoformat() }, f)- 任务完成后更新为idle状态:
with open('state.json', 'w') as f: json.dump({ 'state': 'idle', 'detail': '任务完成', 'updated_at': datetime.now().isoformat() }, f)提示:建议将状态文件路径统一配置为
~/.openclaw/state.json
4.2 日志监听方案(推荐)
如果不想修改moltbot源码,可以使用日志监听方案。新建office-log-monitor.py:
import subprocess import re import requests LOG_PATTERN = re.compile(r'session state: new=(\w+)') def monitor_logs(): proc = subprocess.Popen(['moltbot', 'logs', '--follow'], stdout=subprocess.PIPE) for line in proc.stdout: match = LOG_PATTERN.search(line.decode()) if match: state = match.group(1) update_state(state) def update_state(state): mapping = { 'processing': 'writing', 'failed': 'error', 'completed': 'idle' } requests.post('http://localhost:18791/update', json={ 'state': mapping.get(state, 'idle') }) if __name__ == '__main__': monitor_logs()启动监听器:
python office-log-monitor.py5. 高级定制技巧
5.1 自定义办公室布局
修改frontend/assets/office.json可以调整办公室布局:
{ "regions": { "desk": {"x": 300, "y": 200, "width": 100, "height": 80}, "bookshelf": {"x": 150, "y": 180, "width": 80, "height": 120} } }5.2 添加新状态类型
- 在后端添加状态枚举:
# backend/app.py STATES = ['idle', 'writing', 'researching', 'executing', 'syncing', 'error', 'meeting']- 在前端添加对应动画:
// frontend/src/sprites/agent.js this.anims.create({ key: 'meeting', frames: this.anims.generateFrameNumbers('agent', { start: 24, end: 29 }), frameRate: 6, repeat: -1 });5.3 多AI协同办公
修改状态文件格式支持多个agent:
{ "agents": { "claude": { "state": "writing", "position": {"x": 300, "y": 200} }, "copilot": { "state": "researching", "position": {"x": 150, "y": 180} } } }6. 常见问题排查
6.1 状态更新延迟
可能原因:
- WebSocket连接中断
- 状态文件权限问题
- 后端服务未正常运行
检查步骤:
- 查看浏览器控制台WebSocket连接状态
- 检查state.json文件权限:
ls -l state.json chmod 644 state.json- 重启后端服务:
pkill -f app.py python backend/app.py6.2 像素角色不显示
可能原因:
- 前端资源加载失败
- 角色精灵图路径错误
解决方案:
- 检查浏览器开发者工具Network面板
- 确认frontend/assets目录包含:
- agent.png(角色精灵图)
- office.png(背景图)
- items.png(道具图)
6.3 状态切换不生效
调试方法:
- 直接调用API测试:
curl -X POST http://localhost:18791/update \ -H "Content-Type: application/json" \ -d '{"state":"writing"}'- 检查后端日志:
tail -f backend/logs/app.log7. 创意扩展思路
7.1 集成IDE插件
开发VSCode插件,在编辑器底部显示迷你办公室:
vscode.window.createStatusBarItem( 'ai-office', vscode.StatusBarAlignment.Left ).text = '🦑 正在生成代码...';7.2 添加音效反馈
根据不同状态播放音效:
// frontend/src/sounds.js this.load.audio('writing', 'assets/sounds/keyboard.mp3'); this.load.audio('error', 'assets/sounds/alert.mp3');7.3 物理看板联动
通过Raspberry Pi控制LED矩阵同步显示状态:
import board import neopixel pixels = neopixel.NeoPixel(board.D18, 64) def update_led(state): if state == 'writing': pixels.fill((0, 255, 0)) # 绿色 elif state == 'error': pixels.fill((255, 0, 0)) # 红色这个项目最让我惊喜的是它让AI工作变得可见、可感。当看到像素海星在办公室里忙碌的身影时,我突然觉得这些代码不再是冰冷的指令,而是一个有"工作状态"的伙伴。如果你也在用AI编程助手,强烈建议试试这个可视化方案——毕竟,谁能拒绝一只会写代码的像素海星呢?