Files
xianyu-hunter-hermes-skill/skill/xianyu-hunter-monitor/references/web-ai-fallback-and-auto-analysis-2026-05.md
T

105 lines
4.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Web AI Optimize Fallback and Automatic Hermes Analysis — 2026-05
## Context
BOSS reported two UX problems in the local xianyu-hunter Web UI:
1. 新建任务/任务编辑里的“AI 润色/AI 优化”提示 `AI不可用`,容易误以为功能坏了。
2. Hermes 分析需要手动点“执行分析”,BOSS 希望采集完成后自动分析、自动通知。
## Root Cause
The local fork intentionally runs in Hermes-main-control mode and does not require project-level AI API configuration. `/api/tasks/optimize` already caught `chatCompletion()` failures and returned a local fallback task, but the frontend text said `AI不可用,已用本地规则优化`, which surfaced the expected no-AI state as an error.
Hermes analysis existed as `POST /api/tasks/:id/analyze`, but `TaskManager.startTask()` ended after local detail collection. No automatic analysis/report/notification was triggered from the normal run pipeline.
## Implemented Shape
- Rename Web copy from “AI 优化” to “任务智能润色”.
- Keep `/api/tasks/optimize` API compatible, but treat local fallback as a successful no-configuration path.
- Frontend fallback text: `已用本地规则优化(无需配置 AI`.
- Add task config flags:
- `autoAnalyze: true` by default.
- `autoNotify: true` by default.
- Add visible task form checkboxes:
- `采集完成后自动执行 Hermes 分析`
- `分析后按通知设置自动推送`
- After `_runPipeline()` completes and task is not stopped, call `_runAutoAnalysis()` before setting stage to `completed`.
- `_runAutoAnalysis()`:
1. Skips if `autoAnalyze === false`.
2. Skips if no `products.fineFiltered` candidates.
3. Calls `analyzeTask()` with `limit=maxItems`.
4. Calls `renderAnalysisMarkdown()` and persists `summary.reportPath`.
5. Calls `sendNotifications()` unless `autoNotify === false`.
6. Logs success/skip/failure into task logs.
## Files Touched
```text
server.mjs
lib/task.mjs
public/app.js
public/index.html
```
## Verification Commands
```bash
cd /Users/chick/.Hermes/workspace/research/xianyu-hunter
node --check server.mjs
node --check lib/task.mjs
node --check public/app.js
```
Restart stale port manually if needed:
```bash
lsof -nP -iTCP:3000 -sTCP:LISTEN
kill -9 <pid>
PORT=3000 node server.mjs
```
API fallback smoke test:
```bash
curl -sS http://127.0.0.1:3000/api/tasks/optimize \
-H 'Content-Type: application/json' \
-d '{"product":"e3-1245v3 cpu","budget":"150","currentRequirements":"价格150左右,能正常点亮,排除坏件维修配件"}'
```
Expected response can be `source: local-fallback`; this is OK. It should include `task.autoAnalyze: true` and `task.autoNotify: true`.
Task create smoke test should persist config flags:
```bash
curl -sS http://127.0.0.1:3000/api/tasks \
-H 'Content-Type: application/json' \
-d '{"name":"验证自动分析任务","queries":["test"],"autoStart":false,"autoAnalyze":true,"autoNotify":true}'
```
Unit-style auto-analysis check without starting scheduler:
```bash
XIANHU_DISABLE_SCHEDULER=1 node --input-type=module <<'JS'
import { TaskManager } from './lib/task.mjs';
const tm = new TaskManager(() => {});
const task = tm.createTask({ name: '自动分析单元验证', queries: ['e3-1245v3 cpu'], maxItems: 2, autoAnalyze: true, autoNotify: false, autoStart: false });
const full = tm.getTaskFull(task.id);
full.products.fineFiltered = [
{ id:'unit-1', title:'Intel Xeon E3 1245 V3 CPU 正常使用', price:'¥150', detailPrice:'¥150', sellerLocation:'广东', description:'自用拆机,能正常点亮,不是维修件', href:'https://example.com/1' },
{ id:'unit-2', title:'E3 CPU 坏件维修练手', price:'¥50', detailPrice:'¥50', sellerLocation:'广东', description:'坏件', href:'https://example.com/2' },
];
const logs=[];
await tm._runAutoAnalysis(full, msg => logs.push(msg));
console.log(tm.getTaskFull(task.id).hermesAnalysis);
tm.deleteTask(task.id);
JS
```
## Pitfalls
- If API tests still show missing `autoAnalyze/autoNotify`, the old server process is still listening. `tools/xianyu_ops.mjs stop` may say `no-recorded-server`; use `lsof` and kill the actual PID.
- `source: local-fallback` from `/api/tasks/optimize` is not a failure in Hermes mode.
- Do not reintroduce project-level AI API gating for task creation or collection.
- Do not automatically contact sellers; this automation only performs collect → local prefilter → Hermes analysis → notification.