Metadata-Version: 2.4
Name: redbeacon
Version: 0.1.0
Summary: RedBeacon — 小红书自动化 CLI（生成 / 审核 / 发布 / 多账号）
Author: djw
License: MIT
Project-URL: Homepage, https://github.com/jidouqie/redbeacon
Project-URL: Issues, https://github.com/jidouqie/redbeacon/issues
Keywords: xiaohongshu,redbook,automation,cli,claude-code,skill
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pydantic>=2.0.0
Requires-Dist: cryptography>=42.0.0
Requires-Dist: requests>=2.31.0
Requires-Dist: httpx>=0.27.0
Requires-Dist: openai>=1.30.0
Requires-Dist: playwright>=1.44.0
Requires-Dist: cloakbrowser>=0.3.30
Requires-Dist: markdown>=3.6
Requires-Dist: pyyaml>=6.0
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Dynamic: license-file

# redbeacon — 小红书自动化 CLI

把"选好题"以外的事全部交给 CLI：AI 生成文案 + 渲图 / 出图 → 审核 → 多账号发布 → 排期 → 选题库管理。所有命令都是 JSON in / JSON out，方便接入任何 agent、脚本、CI。

主要被 [`redbeacon-skill`](https://github.com/jidouqie/redbeacon-skill)（Claude Code skill 封装）调用，但完全可以独立用。

---

## 安装

```bash
# 推荐：pipx 隔离环境
pipx install redbeacon

# 或者直接 pip
pip install redbeacon

# Playwright 渲图引擎（图文卡片用）
playwright install chromium

# 校验
redbeacon --version
```

> CloakBrowser 的 stealth Chromium 在首次跑 `redbeacon login start` 时自动下载到 `~/.cloakbrowser/`（约 200MB），不用手动装。

依赖：Python ≥ 3.11。

---

## 30 秒看懂

```bash
redbeacon readiness                   # 入口：看现在缺什么配
redbeacon config set ai_api_key sk-…  # 配 AI Key
redbeacon accounts create             # 建第 1 个小红书账号（id=1）
redbeacon login start --account-id 1  # 阻塞 + 弹浏览器扫码
redbeacon generate --account-id 1 --image-mode cards   # 生成一篇
redbeacon content list --account-id 1 --status pending_review
redbeacon content approve --account-id 1 --id 1        # 本地审核
redbeacon publish --account-id 1                       # 发布
```

每个命令成功 → exit 0 + stdout 一行 JSON；失败 → exit ≠0 + stderr `{"error", "next"}`。

---

## 命令总览

| 子命令 | 说明 |
|---|---|
| `redbeacon readiness` | 配置完整度 + 引导下一步 |
| `redbeacon status` | 账号 / 内容计数 / 路径总览 |
| `redbeacon accounts <list\|get\|create\|delete\|patch>` | 账号 CRUD |
| `redbeacon login <start\|verify\|status\|delete>` | 小红书登录（CloakBrowser） |
| `redbeacon config <list\|get\|set\|models\|test-ai\|test-feishu\|feishu-users>` | 配置管理 |
| `redbeacon strategy <get\|patch>` | 账号定位 / 调性 / 提示词 |
| `redbeacon topics <list\|add\|batch\|inspire\|stats\|reset\|types\|types-init>` | 选题库 |
| `redbeacon content <list\|get\|approve\|reject\|edit\|feishu-push>` | 内容审核 |
| `redbeacon generate --account-id N [--topic …] [--image-mode cards\|ai\|both]` | AI 生成（阻塞） |
| `redbeacon publish --account-id N` | 发布（飞书源 / 本地源自动判断，阻塞） |
| `redbeacon feishu <sync\|setup\|test>` | 飞书多维表格 |
| `redbeacon logs [--tail 150]` | 看日志 |

`redbeacon --help` / `redbeacon <子命令> --help` 看完整参数。

---

## 数据位置

| 路径 | 内容 |
|---|---|
| `~/.redbeacon/data/redbeacon.db` | SQLite 主库 |
| `~/.redbeacon/data/cb_profiles/{id}/` | 每账号 CloakBrowser profile（含 cookie） |
| `~/.redbeacon/data/images/` | 生成的图片 |
| `~/.redbeacon/logs/redbeacon.log` | 运行日志 |
| `~/.cloakbrowser/chromium-*/` | stealth Chromium |

环境变量覆盖：`REDBEACON_DATA_DIR` / `REDBEACON_LOG_DIR`。

跑 `redbeacon status` 看当前实际路径。

---

## 输出契约

- 默认：`{"key": "value", ...}` 一行 JSON
- TTY 下自动 indent=2 可读；强制覆盖：`REDBEACON_OUT=pretty` / `REDBEACON_OUT=compact`
- 错误：stderr `{"error": "...", "next": "redbeacon <修复命令>"}`

完整 schema 定义在 `src/redbeacon/schemas.py`（TypedDict）。

---

## 开发

```bash
git clone https://github.com/jidouqie/redbeacon-cli.git
cd redbeacon-cli

pip install -e .[dev]

# 测试
pytest tests/

# 本地跑
redbeacon --version
REDBEACON_DATA_DIR=/tmp/rb_dev redbeacon readiness
```

代码结构：

```
src/redbeacon/
├── cli.py            # argparse 入口 + dispatch
├── config.py         # settings 表读写（加密支持）
├── config_keys.py    # 所有 settings key 集中定义
├── database.py       # SQLite 初始化 + migrate
├── schemas.py        # 输出 TypedDict
├── render_xhs_v2.py  # 图文卡片渲染（Playwright）
├── routers/          # 子命令处理（accounts / login / config / publish ...）
├── services/
│   ├── xhs/          # CloakBrowser 集成（session/login/publish）
│   ├── feishu_api.py
│   ├── image_gen.py
│   └── proxy_service.py
├── tasks/            # 复杂业务编排（generate / publish / feishu_sync）
└── utils/            # logger / crypto / paths
```

加新命令：在 `routers/` 下加文件 + 在 `cli.py:_build_parser` 和 `_DISPATCH` 注册即可。

---

## License

MIT。详见 [LICENSE](LICENSE)。
