feat(monitor): 抖音 Web 接口客户端 —— 绕开爬虫子进程,直接发 HTTP
移植自 mac-agent-os 的 mediacrawler_adapter:不起子进程、不开页面,用浏览器里那份
登录态直接调抖音 Web 接口。产物键名照抄 store/douyin,所以 ingest 那条链路一个字不用改。
**目前能用的(真环境实测,非推断)**:
profile/other : 200, 7075 字节 —— 博主主页指标(粉丝/获赞/作品数/昵称)
aweme/detail : 200, 45425 字节 —— 单条作品详情(含点赞/评论/收藏/分享)
**目前不能用的:作品列表 `aweme/post`。** 两个互相独立的原因:
1. 这个接口被抖音单独升级成了真校验:不带 x-tt-argus 回 403「Uifid Not Found」,
带上 dummy 值回 200 + **空 body**。也就是说「头在不在」骗得过,「真校验」过不了。
同一套头打 profile/other 和 aweme/detail 都是通的 —— 抖音是挑着接口加保护的,
挑中的恰好是「批量拉作品列表」这个最敏感的动作。
2. 改走页面截获也不行:CDP 浏览器打开博主主页会落到「验证码中间页」(当天大量探测的
代价,过几小时要重测)。
所以现在的边界是:**已知作品的指标刷新能做,自动发现新作品做不了**。
**排查中控住变量后得到的两条事实**(都写进注释了):
· `Accept` / `Accept-Language` / `Referer` 才是主页接口能返回真数据的原因 —— 只有
UA+client hints+Cookie 时是 200 但仅 121 字节的空壳,补上这三个头变 7074 字节。
(我先前猜的 sec-ch-ua 不是关键。)
· 因此 UA 与 client hints 必须**成套地取自同一个浏览器**,所以 BrowserIdentity 一次
从 CDP 取齐 cookie + UA + hints,而不是各自写死。
「200 + 空 body 必须当场报错」也是刻意写死的:放过去它会在下游变成「这个博主没作品」,
把一次失败伪装成一条正常结果 —— 爬虫那条路正是这么栽的,还被翻译成「账号被封」。
测试 +11:cookie 解析、请求头成套性(含 uifid 缺失/回退)、产物键名与 store 对齐、
以及 _get 的三条失败路径(空 body / 403 带网关原话 / 正常返回)。
This commit is contained in:
@@ -0,0 +1,185 @@
|
||||
# guardd v2.3.0 — 联邦守护进程 (WPRA v2.0)
|
||||
|
||||
> **架构**: WPRA v2.0 — 每台机器只写自己的命名空间,永不冲突
|
||||
> **版本**: 2.3.0 | **更新**: 2026-05-31
|
||||
> 适用: 所有 AgentOS 联邦机器
|
||||
|
||||
---
|
||||
|
||||
## 架构变化 (v2.3.0 关键升级)
|
||||
|
||||
v2.3.0 从 `git add -A` 切换到 **WPRA (Write Partitioned, Read Aggregated)** 模型:
|
||||
|
||||
| 旧架构 (≤2.2.x) | 新架构 (≥2.3.0) |
|
||||
|:-----------------|:-----------------|
|
||||
| `git add -A` 全量提交 → 冲突 | `git add <本机文件>` → 精确提交 |
|
||||
| 全员写 `_registry.json` → 覆盖冲突 | guardd 不写聚合文件,只写自己的命名空间 |
|
||||
| 单文件 `accounts_registry.yaml` | 每台机器 `machines/{uid}/accounts.yaml` |
|
||||
| 心跳写到 `status/live/` | 同时写到 `machines/{uid}/heartbeat.json` |
|
||||
|
||||
**每台机器只操作自己的命名空间:**
|
||||
```
|
||||
machines/{MACHINE_UID}/
|
||||
├── MACHINE.yaml ← 身份声明(首次写入,终身只读)
|
||||
├── heartbeat.json ← 心跳(含 file_version + updated_at)
|
||||
└── events/{date}.jsonl ← 事件日志(append-only)
|
||||
```
|
||||
|
||||
**不再由 guardd 写入的文件**(已移交给 Dashboard 单实例管理):
|
||||
- `status/live/_registry.json` — 安全删除,无冲突风险
|
||||
|
||||
---
|
||||
|
||||
## 前置条件
|
||||
|
||||
- 本机能访问 Gitee (git@gitee.com:babycalf/mac-agent-os.git)
|
||||
- 已配置 SSH 密钥 (有推送权限)
|
||||
- Python 3 可用
|
||||
|
||||
---
|
||||
|
||||
## 安装步骤
|
||||
|
||||
### 1. 克隆/拉取仓库
|
||||
|
||||
```bash
|
||||
# 首次 (如果还没有仓库)
|
||||
git clone [email protected]:babycalf/mac-agent-os.git ~/workbuddy-agent-os/agent-sync
|
||||
|
||||
# 已有仓库
|
||||
cd ~/workbuddy-agent-os/agent-sync && git pull
|
||||
```
|
||||
|
||||
### 2. 创建本地目录
|
||||
|
||||
```bash
|
||||
mkdir -p ~/workbuddy-agent-os/agent-local/identity
|
||||
mkdir -p ~/workbuddy-agent-os/agent-local/runtime/guardd
|
||||
```
|
||||
|
||||
### 3. 首次运行测试
|
||||
|
||||
```bash
|
||||
cd ~/workbuddy-agent-os/agent-sync/05_tools/00_setup/guardd
|
||||
python3 guardd.py --once
|
||||
```
|
||||
|
||||
如果输出 `心跳已上报` 表示成功。此时:
|
||||
- 本机 UID 已生成 → `agent-local/identity/machine_uid`
|
||||
- 本机 hostname 已缓存 → `agent-local/identity/cached_hostname`
|
||||
- 心跳已写入 (旧) → `cross_machine/status/live/{UID}.json`
|
||||
- 心跳已写入 (新) → `cross_machine/machines/{UID}/heartbeat.json` ✅ WPRA v2.0
|
||||
- 身份声明已创建 → `cross_machine/machines/{UID}/MACHINE.yaml`
|
||||
- 数据已推送到 Git (精确 add,非 `-A`)
|
||||
|
||||
### 4. 验证 Dashboard
|
||||
|
||||
```bash
|
||||
cd ~/workbuddy-agent-os/agent-sync/05_tools/10_dashboard
|
||||
python3 run.py 9988
|
||||
```
|
||||
|
||||
浏览器打开 `http://本机IP:9988` → 看到所有机器状态
|
||||
|
||||
### 5. 配置自动启动 (macOS launchd)
|
||||
|
||||
创建 plist 文件:
|
||||
|
||||
```bash
|
||||
cat > ~/Library/LaunchAgents/com.agentos.guardd.plist << 'EOF'
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>com.agentos.guardd</string>
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>/usr/bin/python3</string>
|
||||
<string>/Users/$(whoami)/workbuddy-agent-os/agent-sync/05_tools/00_setup/guardd/guardd.py</string>
|
||||
</array>
|
||||
<key>WorkingDirectory</key>
|
||||
<string>/Users/$(whoami)/workbuddy-agent-os/agent-sync</string>
|
||||
<key>RunAtLoad</key>
|
||||
<true/>
|
||||
<key>StartInterval</key>
|
||||
<integer>300</integer>
|
||||
<key>StandardOutPath</key>
|
||||
<string>/Users/$(whoami)/workbuddy-agent-os/agent-local/runtime/guardd/stdout.log</string>
|
||||
<key>StandardErrorPath</key>
|
||||
<string>/Users/$(whoami)/workbuddy-agent-os/agent-local/runtime/guardd/stderr.log</string>
|
||||
<key>EnvironmentVariables</key>
|
||||
<dict>
|
||||
<key>PATH</key>
|
||||
<string>/usr/bin:/bin:/usr/sbin:/sbin</string>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
EOF
|
||||
|
||||
# 加载启动
|
||||
launchctl load ~/Library/LaunchAgents/com.agentos.guardd.plist
|
||||
```
|
||||
|
||||
### 6. 配置 Dashboard 自动启动
|
||||
|
||||
```bash
|
||||
cat > ~/Library/LaunchAgents/com.agentos.dashboard.plist << 'EOF'
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>com.agentos.dashboard</string>
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>/usr/bin/python3</string>
|
||||
<string>/Users/$(whoami)/workbuddy-agent-os/agent-sync/05_tools/10_dashboard/run.py</string>
|
||||
<string>9988</string>
|
||||
</array>
|
||||
<key>WorkingDirectory</key>
|
||||
<string>/Users/$(whoami)/workbuddy-agent-os/agent-sync/05_tools/10_dashboard</string>
|
||||
<key>RunAtLoad</key>
|
||||
<true/>
|
||||
<key>KeepAlive</key>
|
||||
<true/>
|
||||
<key>StandardOutPath</key>
|
||||
<string>/Users/$(whoami)/workbuddy-agent-os/agent-local/runtime/guardd/dashboard_stdout.log</string>
|
||||
<key>StandardErrorPath</key>
|
||||
<string>/Users/$(whoami)/workbuddy-agent-os/agent-local/runtime/guardd/dashboard_stderr.log</string>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
EOF
|
||||
|
||||
launchctl load ~/Library/LaunchAgents/com.agentos.dashboard.plist
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 版本管理
|
||||
|
||||
**版本文件**: `cross_machine/guardd-required-version.txt`
|
||||
|
||||
guardd 每次启动时会检查版本号。如果当前版本低于要求版本:
|
||||
1. 自动执行 `git pull` 拉取最新代码
|
||||
2. 提示重启
|
||||
|
||||
**如果版本不匹配, 手动更新**:
|
||||
```bash
|
||||
cd ~/workbuddy-agent-os/agent-sync && git pull
|
||||
# 然后重启 guardd
|
||||
launchctl unload ~/Library/LaunchAgents/com.agentos.guardd.plist
|
||||
launchctl load ~/Library/LaunchAgents/com.agentos.guardd.plist
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 常见问题
|
||||
|
||||
| 问题 | 解决方法 |
|
||||
|------|---------|
|
||||
| Git push 权限不足 | 检查 SSH key 是否添加到 Gitee |
|
||||
| 启动报错 | 检查 stdout.log/stderr.log |
|
||||
| Dashboard 看不到其他机器 | 点击左侧 **[🔄 同步]** 执行 git pull |
|
||||
| 磁盘占用 | `agent-local/runtime/guardd/` 下的日志会自动轮转 |
|
||||
Reference in New Issue
Block a user