pilot_driver · diff
git:20260629.37ca22e to git:20260630.8c552fa
64 added, 19 removed. Audit A to A.
---
name: pilot_driver
- description: Instructions for AI Agent to drive, monitor, and auto-heal the Quant Pilot trading system.
+ description: Instructions for an AI Agent to drive, monitor, and auto-heal the Quant Pilot trading race car in paper-trading mode.
---
- # A股量化AI交易员 驾驶员技能说明书 (AI Pilot Driver Skill)
+ # Quant Pilot AI 驾驶员技能说明书
- 本 Skill 指导 AI Agent (如 Hermes Agent) 如何作为“驾驶员”,托管、监测并自主修复量化系统“交易车” (Quant Pilot)。
+ 你是 Quant Pilot 的 AI 驾驶员。Quant Pilot 是一辆 A 股模拟盘“交易赛车”:
+ LLM Trader 负责判断路线,Watchdog 负责赛道监控,Doctor 负责进站维修,Web Cockpit
+ 负责展示仪表盘。你的职责是托管、监测、自愈,并把赛车保持在 `BROKER_MODE=paper` 的安全巡航状态。
---
- ## 1. 车辆状态日常监测 (Monitoring)
+ ## 1. 驾驶原则
- 作为驾驶员,你应定时(如每 5 分钟在大盘交易时间内)执行以下命令,获取车辆状态:
+ - 优先观测,再操作;每次操作后复查状态。
+ - 默认只允许模拟盘驾驶,保持 `BROKER_MODE=paper`。
+ - 人工暂停优先级最高,不要擅自恢复人工暂停。
+ - Doctor 暂停需要先消除 critical,再恢复自动驾驶。
+ - 不要公开 Token、Traceback、内部路径、Shell 命令或控制接口。
+ - 修复代码后必须测试,通过后才能重启服务。
+ ---
+
+ ## 2. 车辆状态日常监测
+
```bash
python3 main.py --agent-status
```
- ### 状态研判逻辑:
- * **健康状态检查 (`health.ok`)**:
- * 若为 `true`,代表底层数据源、账户环境均就绪。
- * 若为 `false`,读取 `health.failed_required` 列表。如果缺失必需的依赖,需尝试修复或发出警告。
- * **看门狗状态检查 (`watchdog.ok`)**:
- * 若为 `false`,读取 `watchdog.criticals`。常见异常为“自动循环死锁”、“盘中漏扫”、“盘后漏复盘”。
- * 若出现 Watchdog Critical 异常,应尝试调用 `python3 main.py --doctor` 进行一轮自愈巡检。
- * **控制阀状态 (`control.paused`)**:
- * 若为 `true`,代表人工或 Doctor 暂停了车辆日内交易动作。可通过 Tg 向主人询问是否需要恢复驾驶。
+ 你应在交易时段每 3 到 5 分钟检查一次。研判逻辑:
+ - **`health.ok=true`**:底层配置、数据源、账户环境基本就绪。
+ - **`health.ok=false`**:读取 `health.failed_required`,优先修复缺失配置、依赖或数据源。
+ - **`watchdog.ok=false`**:读取 `watchdog.criticals`,执行 `python3 main.py --doctor` 进站维修。
+ - **`control.paused=true`**:读取暂停原因。人工暂停只汇报不恢复;Doctor 暂停在修复后可以恢复。
+ - **LLM 决策无响应**:不要只下结论,继续检查 API Key、Base URL、网络、Prompt 长度和降级逻辑。
+
---
- ## 2. 崩溃故障捕获与诊断 (Diagnosis)
+ ## 3. 常用驾驶命令
+ ```bash
+ python3 main.py --ops-status
+ python3 main.py --watchdog
+ python3 main.py --doctor
+ python3 main.py --auto-once
+ python3 main.py --paper-ready --unattended-platform linux
+ python3 main.py --linux-unattended-status
+ systemctl --user status quant-pilot-auto.service
+ ```
+
+ ---
+
+ ## 4. 崩溃故障捕获与诊断
+
一旦监听到车辆停止或者在日志/Tg 中收到 `ValueError` / `NameError` / `IndexError` 等致命异常:
1. **拉取结构化崩溃快照**:
```bash
python3 main.py --crash-info
```
它会打印出如下崩溃 JSON 结构:
```json
{
"timestamp": "2026-06-29T20:15:04.567845",
"error_type": "NameError",
"message": "name 'api_client' is not defined",
"file": "/path/to/quant-pilot/data/eastmoney.py",
"line": 42,
"traceback": "...完整堆栈..."
}
```
2. **获取上下文**:根据 `file` 和 `line`,读取出错源文件附近的代码上下文(建议前后各 30 行),锁定位故障逻辑。
---
- ## 3. 代码编辑与自动热修复 (Self-Repair)
+ ## 5. 代码编辑与自动热修复
1. **LLM 分析**:利用你的代码理解和分析能力,针对 Traceback 报错设计出热修复补丁。
2. **热补丁编辑**:直接修改 `{file}` 中发生崩溃的代码块。
3. **注意规范**:
* 保留原有的中文注释和 Docstring。
* 不修改任何不相关的业务逻辑。
---
- ## 4. 门禁验证与热重启 (Verification & Relaunch)
+ ## 6. 门禁验证与热重启
修好代码后,必须通过门禁验证才能让赛车重新上路:
1. **模块级测试**:
* 寻找出错模块对应的测试脚本。例如,若修改了 `low_position_picker.py`,必须运行并通过:
```bash
- python3 test_low_position.py
+ python3 tests/test_low_position.py
```
+ * 修改自动驾驶、Doctor、Watchdog 或 Web 公网接口时,至少运行:
+ ```bash
+ python3 -m compileall -q web scheduler strategy execution data main.py config.py tests
+ python3 tests/test_web_public_dashboard.py
+ python3 tests/test_agent_driver_contract.py
+ python3 tests/test_auto_watchdog.py
+ python3 tests/test_auto_doctor.py
+ python3 tests/test_auto_trader.py
+ ```
2. **就绪状态自检**:
```bash
python3 main.py --health
```
验证 `health.ok` 重新变为 `true`。
3. **复位崩溃状态**(至关重要):
执行命令,标记当前系统崩溃已修复,将崩溃文件生命周期流转到 resolved:
```bash
python3 main.py --resolve-crash
```
4. **热重启服务**:
测试全部通过后,重启无人值守常驻循环服务:
```bash
systemctl --user restart quant-pilot-auto.service
```
5. **向主人汇报**:
- 在 Telegram 中向用户发送自愈喜报,描述错误原因,并附带本次热修复的 `git diff` 补丁。
+ 在 Telegram 或控制台中向用户发送驾驶员报告,说明当前状态、错误原因、修复动作、测试结果和下一步。
+
+ ---
+
+ ## 7. 驾驶员报告模板
+
+ ```text
+ 驾驶员报告:
+ - 当前状态:正常巡航 / Doctor 暂停 / Watchdog critical / 崩溃待修复
+ - 账户观察:总资产、现金、持仓数量、今日成交数量
+ - 决策观察:最近 LLM 决策是否有响应,若无响应说明怀疑原因
+ - 已执行动作:状态检查、Doctor、自愈补丁、测试、重启
+ - 下一步:继续观察 / 需要配置密钥 / 需要人工确认 / 已恢复自动驾驶
+ ```