feat: priority system, batch tasks, action feedback, event daemon

- Priority system: GET /api/state/priorities, POST /api/action/priority_global, POST /api/action/priority_type
- Batch system: POST /api/action/batch with per-action result tracking
- Enhanced action feedback with error codes and AI suggestions:
  cell_occupied, cell_solid, cell_occupied_by_dupe, material_shortage, etc.
- Event stream: GET /api/state/events?since=&limit= for incremental polling
- Event daemon: scripts/event_daemon.py continuously polls events,
  classifies by severity, auto-triggers analysis on critical events
- Games state now reports suffocating/starving/stressed counts
- Cell data includes isDiggable and isSafeForDupe flags
- Added 'events', 'queue', 'batch', 'priority_global', 'priority_type' CLI commands
- Added sample batch plan file
This commit is contained in:
root
2026-05-22 09:01:12 +08:00
parent 4c6a9b882f
commit a4f2062c1a
6 changed files with 1350 additions and 133 deletions

108
SKILL.md
View File

@ -234,6 +234,110 @@ python3 tools/oni_builder.py build spom 42 42
---
## AI 事件驱动工作流
AI 应持续运行事件守护进程形成"事件 分析 操作 反馈"的闭环
```
┌───────────────────────────────────┐
│ Event Daemon │
│ (scripts/event_daemon.py) │
│ polls every 5 seconds │
└──────────┬────────────────────────┘
│ 新事件
┌───────────────────────────────────┐
│ AI Decision Loop │
│ │
│ 1. 收到事件 → 分类严重程度 │
│ 2. 严重 → 立即用 tools 调查状态 │
│ 3. 分析根本原因 │
│ 4. 执行操作dig/build/batch
│ 5. 检查操作反馈success/fail
│ 6. 失败 → 读取错误原因 + 建议 │
│ 7. 调整方案后重试 │
└───────────────────────────────────┘
```
### 事件驱动示例:复制人窒息
```
[EVENT CRITICAL] Cycle 42 @ 14:32:15
Title: suffocating
Entity: Dup1
→ AI 收到此事件后自动执行:
1. python3 tools/oni_api.py duplicants # 查看所有复制人氧气值
2. python3 tools/oni_api.py cell 23 45 # 查看 Dup1 所在格子
3. python3 tools/oni_api.py resources # 检查 O2 + Algae 存量
4. python3 tools/oni_api.py buildings # 是否有电解器/扩散器
5. 根据分析结果:
- 如果无电解器且 Algae < 1t → 紧急建造 SPOM
- 如果有扩散器但无 Algae → 改用电解器
- 如果 Dup1 在 CO2 里 → 挖掘排气通道
6. python3 tools/oni_api.py build Electrolyzer 42 42
7. 读取反馈:成功?材料不足?格子被占?
```
### 操作反馈处理
每次操作后 AI **必须**检查反馈中的 `success` 字段
```json
// 成功
{ "success": true, "result": "build_queued", "buildingId": "Electrolyzer" }
// 失败 — AI 必须读取 error, errorMessage, suggestion
{
"success": false,
"result": "failed",
"error": "cell_occupied",
"errorMessage": "Cell (42,42) already has building 'GasPump'",
"suggestion": "Choose a different location, or deconstruct the existing building first"
}
```
常见错误码
| 错误 | 含义 | AI 应如何处理 |
|------|------|-------------|
| `cell_occupied` | 格子已被建筑占据 | 换位置或先拆除 |
| `cell_solid` | 格子是固体方块未挖掘 | dig build |
| `cell_occupied_by_dupe` | 复制人站在那 | 等待或取消其任务 |
| `material_shortage` | 建造材料不足 | 检查资源并安排生产 |
| `cell_out_of_bounds` | 超出地图范围 | 调整坐标 |
| `unknown_building` | buildingId 错误 | 查询 registry buildings |
| `missing_prerequisites` | 科技未研究 | 先研究前置科技 |
| `no_liquid_at_cell` | 没有液体可清理 | cell 命令检查 |
| `invalid_priority` | 优先级必须是 1-9 | 调整数字 |
### 批量任务示例
AI 可以通过批处理一次性执行一个复杂的建造计划
```bash
# 1. 查看批量计划内容
cat docs/batch_example.json
# 2. 执行批量计划
python3 tools/oni_api.py batch docs/batch_example.json
```
批量反馈会逐个报告每个动作的结果AI 应遍历并处理失败项
### 优先级系统
ONI 优先级范围 1最低~ 9紧急/ alert
```bash
# 设置全局默认
python3 tools/oni_api.py priority_global dig 9
# 查看优先级含义
python3 tools/oni_api.py registry priorities
```
---
## AI 如何表达"在哪个格子做什么"
### 定位语法
@ -270,14 +374,16 @@ AI 在描述操作时应使用以下格式:
| 工具 | 用途 |
|------|------|
| `tools/oni_api.py` | Mod HTTP API 通信所有查询/操作 |
| `tools/oni_api.py` | Mod API 客户端状态/格子/注册表/操作/批量/优先级/事件 |
| `tools/oni_analyzer.py` | 自动分析游戏状态生成预警和建议 |
| `tools/oni_builder.py` | 预置蓝图建造SPOM/农场/养殖等 |
| `scripts/auto_repair.sh` | 诊断 Mod 连接问题 |
| `scripts/auto_analyze.sh` | 一键健康检查+状态+分析 |
| `scripts/watch.sh [秒]` | 循环监控模式 |
| `scripts/setup.sh` | 环境初始化与检查 |
| `scripts/event_daemon.py` | **事件守护进程** 持续轮询事件 AI 输入流 |
| `docs/AI_KNOWLEDGE_BASE.md` | 建筑/元素/科技 ID 注册表和游戏机制参考 |
| `docs/batch_example.json` | 批量任务示例文件 |
---