Files
cmshoppe/docs/current-state.md
T
chengma 26dac2a718 feat: 抽取 Shopee 编辑器模块
新增 app/editor.py,封装商品页打开、登录检测、标题读取写入、封面读取下载、封面上传拖拽、更新按钮点击和 apply_task。

扩展 app/cdp.py 的 host 参数,支持后续按账号端口连接 CDP。

同步任务看板、模块合约、当前状态和进度记录,标记 T-001 完成;记录测试商品标题读写、封面读取与 1_TY030.jpg 上传拖拽验证结果。
2026-06-26 18:02:57 +08:00

98 lines
6.3 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.
# 当前实现状态
> 本文是可覆盖的当前快照,记录代码与任务看板的现实状态。
> 历史执行流水追加到 [`../progress.md`](../progress.md),不在本文重复完整日志。
## 当前快照
- 日期:2026-06-26
- 阶段:V0 单账号 CDP 流程已验证;V1 已完成 T-000 正式代码包结构与 T-001 `app/editor.py` 模块化,下一步开始应用配置。
- 技术栈:Python 3.10+,自研 CDP(websocket-client + requests),SQLite(sqlite3)+ `config.json` + openpyxl + AI(服务商待定),GUI PySide6 5 Tab(已定)。
- 生产代码:已建立 `app/` 包 + 根入口 `main.py`;`app/cdp.py` 为已验证 CDP 底座;`app/editor.py` 已封装标题/封面/采集/更新按钮能力;`app/gui.py` 目前是入口占位,完整 PySide6 主窗口待 T-104。
- 测试:当前以 `compileall` + 测试商品手动 CDP 验证为主;`tests/` 与 `python -m unittest discover -s tests` 由 T-006 建立,T-006 完成前不把缺少 `tests/` 视为验证失败。
- 数据:无 `config.json`、`config/ai_models.json`、`cmshopee.db`、`chrome_user_data_dir/`、`images/`(待 Phase 0/1 建立,均须 gitignore)。
## 既定设计要点(文档已定)
- GUI:**PySide6 5 Tab 流水线**,顺序 ① 导入采集 → ② AI生成 → ③ 更新shopee → ④ 账号管理 → ⑤ 设置;后台任务用 worker/QThread/signal。
- 流水线阶段:imported → collected(采集旧标题/旧封面+下载+回写)→ generated(AI 提示词生成新标题/新封面)→ applied(③ 弹窗批量确认后改 Shopee 并提交)。**无 confirmed、无常驻提交开关。**
- 存储:`config.json`(应用设置)+ `config/ai_models.json`(AI 模型清单与本地明文 Key)+ SQLite `cmshopee.db`(账号/任务/各阶段结果)+ openpyxl(Excel)+ 本地 `images/`(旧/新封面)。
- 多账号隔离:每账号独立 user-data-dir(非 profile)。
- 账号↔任务绑定:以 Excel“别名”列为权威;未匹配略过,结束弹窗汇总。
- 执行:多账号串行、单条失败继续;③ 点击「开始更新」后弹窗确认当前筛选范围和任务数量,确认后逐条点「更新」提交线上。
- AI:服务商待定;生成内容直接用于更新,本地留档+回写 Excel 供追溯。
- 登录:人工登录 + 程序检测,不自动登录;首次未配账号/未登录时 ① ③ 禁用并引导去④。
## 当前目录要点
| 路径 | 状态 | 说明 |
| --- | --- | --- |
| `docs/` | 已有 | 本 harness coding 文档集合 |
| `app/cdp.py` | 已有 | CDP 底座:连接/找 tab/开 tab/执行 JS/拖拽 |
| `prototypes/` | 已有 | 已验证原型/探查脚本(demo/set_title/set_cover/get_title/cookies/inspect_images/grab/1.py),逻辑待并入 `app/editor.py` 后清理;见 `prototypes/README.md` |
| `chrome-remote-debug-lan.md` | 已有 | WSL→Windows CDP 转发排查记录 |
| `app/__init__.py` / `app/__main__.py` / `main.py` | 已有 | 正式包与启动入口;`python main.py` / `python -m app` 可运行占位入口 |
| `app/gui.py` | 已有 | GUI 占位入口;完整 PySide6 主窗口待 T-104 |
| `app/editor.py` | 已有 | T-001 产出:登录检测、打开商品页、读/写标题、读/下载封面、上传拖封面、更新按钮、apply_task |
| `app/appconfig.py` / `app/db.py` / `app/excel.py` / `app/config.py` / `app/chrome.py` / `app/workers.py` | 待建 | Phase 0-3 产出 |
| `config.json` / `config/ai_models.json` / `cmshopee.db` / `chrome_user_data_dir/` / `images/` | 待建 | 含配置、密钥、业务、登录态、图片,须 gitignore |
## 已验证能力(单账号)
- CDP 连接 Chrome、遍历 tab、读取 shopee.tw Cookie。
- 找到/新建商品详情页 tab,等编辑器就绪。
- 改标题:原生 setter + 派发事件,`value` 与 `modelvalue` 双等于新值。
- 换封面:`setFileInputFiles` 上传(`.shopee-image-manager__upload input[type=file]`)→ 等 CDN 链接 → 等 1 秒 → `Input.dispatchMouseEvent` 拖到第一位(落点 `first.left - 0.30*w`);使用 `1_TY030.jpg` 在测试商品验证通过。
- 「更新」按钮:可点才点,禁用态识别;③ 未批量确认前不提交。
## 任务看板状态
任务状态以 [`06-tasks.md`](06-tasks.md) 为准,历史记录见 [`../progress.md`](../progress.md)。
- 已完成:T-000(正式代码包结构)、T-001(`app/editor.py` 模块化)。
- 正在进行:无。
- 下一个可领取任务:**T-002(`app/appconfig.py` + `config.json`)**。虽然 T-003 也依赖满足,但任务领取规则固定为“取 `06-tasks.md` 中第一个 TODO 且依赖均 DONE 的任务”,因此当前不能任选。
## 当前可运行内容
```bash
# 语法检查(T-000 后;本机优先用 py -3)
py -3 -m compileall app main.py
# 当前入口占位
python main.py
py -3 -m app
# 单元测试(T-006 完成且 tests/ 存在后)
python -m unittest discover -s tests
# 单账号闭环(不提交线上)
python prototypes/demo.py # 分步(T-000 后从项目根导入 app.cdp)
set AUTO=1 && python prototypes/demo.py # 自动(cmd)
# 真实提交(谨慎)
set UPDATE=1 && python prototypes/demo.py
```
前置条件:
- Chrome 已用某 user-data-dir 带 `--remote-debugging-port` + `--remote-allow-origins=*` 启动并登录 Shopee。
- 已 `pip install websocket-client requests`。
- PySide6 当前环境已可导入(验证版本 6.5.3);GUI 实现固定使用 PySide6。
- 默认连 `127.0.0.1:9222`(开发期可用 `CDP_HOST` 指向 WSL 转发的 `192.168.0.224:9333`)。
- 本机 `python` 当前指向 `C:\Python37\python.exe`(3.7.9,isolated,不符合 Python 3.10+ 要求且 `python -m app` 不搜索当前目录);开发/验证优先用 `py -3`(当前 3.14.4)或确认 `python` 已指向 3.10+。
## 开始编码前检查
1. 读仓库级 `AGENTS.md` / `CLAUDE.md`(如有)。
2. 读 `docs/00-ai-start-here.md`。
3. 读 `docs/05-coding-rules.md` 与 `docs/04-architecture.md` 第七节。
4. 在 `docs/06-tasks.md` 取第一个 `TODO` 且依赖 `DONE` 的任务。
5. 将该任务状态改为 `DOING`。
## 维护规则
- 新建 `config/chrome/editor/gui/workers` 或改 CDP 选择器后,更新本文与 `04-architecture.md`。
- 任务状态变化同步 [`06-tasks.md`](06-tasks.md);执行记录追加 [`../progress.md`](../progress.md)。
- 本文只保留当前快照,不保留完整历史。