# 京东/商智自助分析报表导出 CLI（jd-export）

本项目是本地 CLI-Anything 风格 harness，用于从京东商智自助分析页面的 HAR 中识别报表列表接口和导出接口，并在已有登录态 Cookie 下批量导出报表 ZIP/XLS。

入口命令：

```bash
jd-export --help
jd-export doctor
```

核心流程：

```bash
# 1. 扫描 HAR，生成不含 Cookie 的 manifest
jd-export scan-har /path/to/京东.har --out deliverables/jd_manifest.json

# 2. 从 HAR 提取本地凭证（Cookie 只写本机 secrets，不入项目/NAS）
jd-export extract-credentials /path/to/京东.har \
  --out-dir /Users/bot1/.hermes/profiles/it/secrets/jd-report-exporter

# 3. 用凭证重放报表列表
jd-export fetch-list deliverables/jd_manifest.json \
  --credential-dir /Users/bot1/.hermes/profiles/it/secrets/jd-report-exporter \
  --out deliverables/jd_report_list.json

# 4. 预览、小批量验证、全量导出
jd-export export-all deliverables/jd_report_list.json \
  --credential-dir /Users/bot1/.hermes/profiles/it/secrets/jd-report-exporter \
  --out-dir deliverables/jd_exports --dry-run

jd-export export-all deliverables/jd_report_list.json \
  --credential-dir /Users/bot1/.hermes/profiles/it/secrets/jd-report-exporter \
  --out-dir deliverables/jd_exports --limit 1
```

安全边界：不要把 HAR Cookie/登录态贴到聊天里；凭证目录必须是本机 profile secrets。

## 京东月报补充：交易概况 / 退款字段

用于月报的京东交易概况（含退款/售后汇总）已固定成直接导出命令：

```bash
# 从包含交易概况导出的 HAR 中提取 lowcode 请求头/Cookie 到本机 secrets
jd-export extract-lowcode-credentials /path/to/6.har \
  --out-dir /Users/bot1/.hermes/profiles/it/secrets/jd-report-exporter

# 导出自然月交易概况 XLSX，含成交、访客、下单、退款字段
jd-export export-trade-summary-month \
  --month 2026-05 \
  --out deliverables/har_20260603_6/jd_trade_summary_202605.xlsx \
  --manifest-out deliverables/har_20260603_6/jd_trade_summary_202605_manifest.json
```

已验证 2026-05 输出包含：成交金额、店铺访客数、商品访客数、退款金额、退款商品件数、退款单量、已收货-退货退款金额。