# 良渚阿里妈妈 / 万相台投放报表导出 CLI

本项目是 CLI-Anything 风格的本地命令行封装，用于从用户授权提供的阿里妈妈 / 万相台 HAR 中提取本地会话凭证、生成投放报表下载任务，并轮询异步任务直到拿到 Excel。

## 安全边界

- 原始 HAR、Cookie、CSRF、loginPointId 等凭证只保存在 bot1 IT profile 本地 secrets 目录；不写入 NAS 项目目录，不在聊天中展示。
- 当前版本只做读取/导出报表，不修改计划、预算、投放配置、cron、数据库或正式日报流程。
- 下载任务是平台正常的报表异步生成任务，可能需要等待；CLI 会轮询 `getDownloadUrl` 直到拿到 Excel 或超时。

## 本地凭证目录

```text
/Users/bot1/.hermes/profiles/it/secrets/alimama-exporter/
```

## 常用命令

```bash
# 查看帮助
./bin/alimama-export --help

# 环境检查
./bin/alimama-export doctor

# 扫描 HAR，生成无敏感 manifest
./bin/alimama-export scan-har /path/to/one.alimama.com.har --out deliverables/manifest.json

# 从 HAR 保存本地凭证，并与千牛凭证做安全对比
./bin/alimama-export extract-credentials /path/to/one.alimama.com.har \
  --store liangzhu_flagship \
  --compare-qianniu-dir /Users/bot1/.hermes/profiles/it/secrets/qianniu-exporter

# 从 HAR 构建下载模板
./bin/alimama-export build-downloads /path/to/one.alimama.com.har --out deliverables/download_manifest.json

# 预演导出，不创建任务；同一个 common manifest 可配不同店铺凭证
./bin/alimama-export export-month --month 2026-05 \
  --store liangzhu_flagship \
  --manifest deliverables/common_download_manifest.json \
  --reports campaign,scene,bidword \
  --out-dir deliverables/alimama_202605_flagship \
  --dry-run

# 真实导出：创建任务，轮询直到下载 Excel
./bin/alimama-export export-month --month 2026-05 \
  --store wenchuang \
  --manifest deliverables/common_download_manifest.json \
  --reports campaign,scene,bidword \
  --out-dir deliverables/alimama_202605_wenchuang_common_daily \
  --split-type day \
  --poll-attempts 80 --poll-seconds 5
```

说明：`--split-type day` 是默认值，用自然月日粒度导出，后续月报构建器再聚合，避免平台 `month` 粒度返回滚动 30 天区间。

## 首版建议报表

必选：

1. 计划报表 `campaign`：推广总计主口径。
2. 营销场景报表 `scene/account`：推广分场景明细。
3. 关键词报表 `bidword`：关键词推广明细。

备选：

- 商品报表 `item_promotion`
- 人群报表 `crowd`

暂缓：

- 创意报表 `creative`
- 地域报表 `area`
