Files
claw/docs/superpowers/plans/2026-04-13-lineloss-requesturl-fix.md
2026-04-13 14:34:35 +08:00

164 lines
4.9 KiB
Markdown

# 台区线损 requesturl 快速修复 实现计划
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:**`derive_request_url_from_instruction` 中添加台区线损 URL 映射,使 `sgHideBrowerserOpenPage` 命令能正确执行。
**Architecture:** 在现有知乎 URL 映射模式后追加台区线损场景的硬编码映射。
**Tech Stack:** Rust
---
### Task 1: 添加测试用例
**Files:**
- Modify: `src/service/server.rs:828` (tests 模块)
- [ ] **Step 1: 在 tests 模块中添加台区线损 URL 映射测试**
`initial_request_url_falls_back_to_zhihu_origin_for_generated_article_publish_routes` 测试后添加新测试:
```rust
#[test]
fn initial_request_url_falls_back_to_lineloss_origin_for_lineloss_instructions() {
let request = SubmitTaskRequest {
instruction: "兰州公司 台区线损大数据 月累计线损率统计分析。。。".to_string(),
..SubmitTaskRequest::default()
};
assert_eq!(
initial_request_url_for_submit_task(&request),
"http://20.76.57.61:18080"
);
}
```
- [ ] **Step 2: 运行测试验证失败**
Run: `cargo test initial_request_url_falls_back_to_lineloss_origin_for_lineloss_instructions -- --nocapture`
Expected: FAIL - 测试应该失败,因为还未实现映射逻辑
- [ ] **Step 3: 提交测试文件**
```bash
git add src/service/server.rs
git commit -m "test: add lineloss requesturl mapping test"
```
---
### Task 2: 实现台区线损 URL 映射
**Files:**
- Modify: `src/service/server.rs:354-382` (derive_request_url_from_instruction 函数)
- [ ] **Step 1: 在 derive_request_url_from_instruction 中添加台区线损映射**
在第二个知乎判断块后、`None` 之前添加:
```rust
// 台区线损相关
// TODO: 临时方案,后续应从 skill 配置或 deterministic_submit 解析结果中获取
if instruction.contains("线损") || instruction.contains("lineloss") {
return Some("http://20.76.57.61:18080".to_string());
}
None
```
完整函数应为:
```rust
fn derive_request_url_from_instruction(instruction: &str) -> Option<String> {
if crate::compat::workflow_executor::detect_route(instruction, None, None)
.is_some_and(|route| {
matches!(
route,
crate::compat::workflow_executor::WorkflowRoute::ZhihuHotlistExportXlsx
| crate::compat::workflow_executor::WorkflowRoute::ZhihuHotlistScreen
| crate::compat::workflow_executor::WorkflowRoute::ZhihuArticleEntry
| crate::compat::workflow_executor::WorkflowRoute::ZhihuArticleAutoPublishGenerated
)
})
{
return Some("https://www.zhihu.com".to_string());
}
if crate::compat::workflow_executor::detect_route(instruction, None, None)
.is_some_and(|route| {
matches!(
route,
crate::compat::workflow_executor::WorkflowRoute::ZhihuArticleDraft
| crate::compat::workflow_executor::WorkflowRoute::ZhihuArticlePublish
)
})
{
return Some("https://zhuanlan.zhihu.com".to_string());
}
// 台区线损相关
// TODO: 临时方案,后续应从 skill 配置或 deterministic_submit 解析结果中获取
if instruction.contains("线损") || instruction.contains("lineloss") {
return Some("http://20.76.57.61:18080".to_string());
}
None
}
```
- [ ] **Step 2: 运行测试验证通过**
Run: `cargo test initial_request_url_falls_back_to_lineloss_origin_for_lineloss_instructions -- --nocapture`
Expected: PASS
- [ ] **Step 3: 运行所有相关测试**
Run: `cargo test initial_request_url -- --nocapture`
Expected: 所有测试通过
- [ ] **Step 4: 构建项目**
Run: `cargo build`
Expected: 编译成功,无错误
- [ ] **Step 5: 提交实现**
```bash
git add src/service/server.rs
git commit -m "feat: add lineloss URL mapping in derive_request_url_from_instruction
临时方案:检测指令中包含'线损'或'lineloss'时返回台区线损平台 URL
🤖 Generated with [Qoder][https://qoder.com]"
```
---
### Task 3: 端到端验证
**Files:**
- 无文件修改,仅运行验证
- [ ] **Step 1: 停止现有 sgclaw 进程**
确保没有 `sg_claw.exe` 在运行
- [ ] **Step 2: 启动 sgclaw 服务**
Run: `target\debug\sg_claw.exe --config-path ..\sgclaw_config.json service`
- [ ] **Step 3: 在 service console 发送测试指令**
指令: `兰州公司 台区线损大数据 月累计线损率统计分析。。。`
Expected: 日志显示 `bootstrap_url=http://20.76.57.61:18080`,而非 `about:blank`
- [ ] **Step 4: 验证 helper page 打开成功**
Expected: 日志显示 `helper_loaded=true, ready=true`,不再超时