Files
claw/docs/superpowers/specs/2026-04-13-expected-domain-arg-fix.md
木炎 4d1070dff0 docs: add expected_domain arg fix spec
🤖 Generated with [Qoder][https://qoder.com]
2026-04-13 17:13:53 +08:00

56 lines
1.7 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.
# 修复 Browser Script Skill Tool expected_domain 参数丢失问题
## 问题描述
`tq-lineloss-report.collect_lineloss` skill 执行时返回 `status=blocked row=0 reasons=missing_expected_domain` 错误。
## 根本原因
`src/compat/browser_script_skill_tool.rs``execute_browser_script_impl` 函数:
```rust
// 第 183 行:从 args 中移除 expected_domain
let raw_expected_domain = match args.remove("expected_domain") {
Some(Value::String(value)) if !value.trim().is_empty() => value,
// ...
};
// 第 200 行:规范化域名(去掉 scheme、port 等)
let expected_domain = match normalize_domain_like(&raw_expected_domain) {
Some(value) => value,
// ...
};
// 第 234 行包装脚本时args 中已经没有 expected_domain 了!
let wrapped_script = wrap_browser_script(&script_body, &Value::Object(args.clone()));
```
`args.remove()` 会从 HashMap 中删除键值对,后续 `wrap_browser_script()` 传入的 args 不包含 `expected_domain`,导致 JS 脚本中 `const args = {...}` 缺少该字段。
## 解决方案
在规范化域名后,将 `expected_domain` 重新插入 args。
### 修改位置
文件:`src/compat/browser_script_skill_tool.rs`
行号:第 209 行后(`expected_domain` 赋值之后、`for required_arg` 循环之前)
### 修改内容
```rust
// 第 209 行后添加:
args.insert("expected_domain".to_string(), Value::String(expected_domain.clone()));
```
## 影响范围
- 只影响 `browser_script_skill_tool.rs`
- 所有使用 `expected_domain` 的 browser_script skill 都会受益
- 无破坏性变更
## 验证方法
1. 运行现有测试:`cargo test browser_script_skill_tool`
2. 内网验证:执行 `tq-lineloss-report.collect_lineloss` skill