docs: 规划正式代码包结构
将正式代码目标结构统一为 app/ 包和根目录 main.py,区分 app/ 正式代码与 prototypes/ 原型参照。 新增 T-000 作为首个实现任务:创建 app 包、迁移 cdp.py、补 app/__main__.py 与 main.py、修正 prototypes/demo.py 导入。 更新模块合约、技术栈、编码规则和 current-state:后续模块路径改为 app/editor.py、app/appconfig.py、app/db.py 等,启动方式为 python main.py 或 python -m app。
This commit is contained in:
+26
-10
@@ -9,7 +9,7 @@
|
||||
- 凭证:登录态在 user-data-dir;密码、AI Key 本地明文存于 config/DB;`config.json`、`config/ai_models.json`、`cmshopee.db`、`chrome_user_data_dir/`、`images/` 必须 gitignore;UI 打码显示,不出现在日志/导出。
|
||||
- 失败处理:抛带中文说明的异常或返回状态字段;GUI 负责提示,不静默吞错。
|
||||
|
||||
## appconfig 模块(`appconfig.py`,待建)
|
||||
## appconfig 模块(`app/appconfig.py`,待建)
|
||||
|
||||
读写 `config.json`(schema 见 [架构 5.1](04-architecture.md))。
|
||||
|
||||
@@ -33,7 +33,7 @@ test_ai_model(name) -> dict # 「测试连接」:用 key/url
|
||||
get_model(name) -> dict # 返回模型定义,含 api_key(调用方不得写日志)
|
||||
```
|
||||
|
||||
## db 模块(`db.py`,待建)
|
||||
## db 模块(`app/db.py`,待建)
|
||||
|
||||
SQLite 读写,表见 [架构 5.2](04-architecture.md)。
|
||||
|
||||
@@ -69,7 +69,7 @@ SQLite 连接规则:
|
||||
- `connect()` 必须设置 `PRAGMA foreign_keys=ON`、`journal_mode=WAL`、`busy_timeout=5000`、`synchronous=NORMAL`。
|
||||
- DB 写入短事务、单条提交;Excel 回写失败不回滚 DB。
|
||||
|
||||
## excel 模块(`excel.py`,待建,依赖 openpyxl)
|
||||
## excel 模块(`app/excel.py`,待建,依赖 openpyxl)
|
||||
|
||||
```python
|
||||
import_tasks(file_paths: list[str]) -> dict
|
||||
@@ -91,14 +91,14 @@ export_copy(batch_id, out_dir_or_path) -> dict # 退路:另存新结果
|
||||
|
||||
列模板见 [架构 5.3](04-architecture.md);别名以“别名”列为权威。
|
||||
|
||||
## config 模块(`config.py`,待建)
|
||||
## config 模块(`app/config.py`,待建)
|
||||
|
||||
```python
|
||||
make_slug(alias) -> str # 别名→唯一 slug [a-z0-9_]
|
||||
ensure_user_data_dir(slug) -> str # chrome_user_data_dir/<slug> 绝对路径,按需创建
|
||||
```
|
||||
|
||||
## chrome 模块(`chrome.py`,待建)
|
||||
## chrome 模块(`app/chrome.py`,待建)
|
||||
|
||||
```python
|
||||
build_launch_args(account) -> list[str] # chrome + --remote-debugging-port + --remote-allow-origins=* + --user-data-dir
|
||||
@@ -108,7 +108,7 @@ is_running(port) -> bool
|
||||
create_shortcut(account, dest_dir=None) -> str # 可选 .lnk,PowerShell WScript.Shell
|
||||
```
|
||||
|
||||
## cdp 模块(`cdp.py`,已实现)
|
||||
## cdp 模块(`app/cdp.py`,T-000 由根目录 `cdp.py` 迁入)
|
||||
|
||||
```python
|
||||
CDP_HOST: str
|
||||
@@ -116,7 +116,7 @@ http_get(path); find_product_tab(item_id); create_tab(url)
|
||||
class CDP: send/ev/val/object_id/drag/close # suppress_origin、trust_env=False
|
||||
```
|
||||
|
||||
## editor 模块(`editor.py`,待建,重构自现有脚本)
|
||||
## editor 模块(`app/editor.py`,待建,重构自现有脚本)
|
||||
|
||||
```python
|
||||
is_logged_in(account) -> bool # 重定向登录页或缺 SPC_ST → False
|
||||
@@ -136,7 +136,7 @@ apply_task(account, task) -> dict # 对已生成任务:换标题+
|
||||
# -> {committed, error}
|
||||
```
|
||||
|
||||
## ai 模块(`ai.py`,待建,外部 AI,服务商待定)
|
||||
## ai 模块(`app/ai.py`,待建,外部 AI,服务商待定)
|
||||
|
||||
```python
|
||||
gen_title(title_prompt, old_title, retry=2) -> str
|
||||
@@ -160,7 +160,7 @@ generate_batch(tasks, prompts, ai_cfg, on_progress, should_stop) -> None
|
||||
- 调用有成本与失败可能:超时、限流、内容安全拒绝都要返回明确错误。
|
||||
- 生成结果**直接进入 ③ 更新候选**;③ 点击「开始更新」后弹窗批量确认,确认后提交线上。本地留档 + 回写 Excel 供追溯。
|
||||
|
||||
## prompts 模块(`prompts.py`,待建)
|
||||
## prompts 模块(`app/prompts.py`,待建)
|
||||
|
||||
```python
|
||||
# 标题提示词:单文件
|
||||
@@ -185,7 +185,7 @@ render_prompt(template_text, task) -> str
|
||||
- 生成封面时 `gen_cover` 的 prompt = `render_prompt(当前封面模板, task)`。
|
||||
- 模板与 `title_prompt.txt` 均为可手改的纯文本文件。
|
||||
|
||||
## gui / workers 模块(`gui.py` / `workers.py`,待建,PySide6)
|
||||
## gui / workers 模块(`app/gui.py` / `app/workers.py`,待建,PySide6)
|
||||
|
||||
```python
|
||||
# GUI 入口
|
||||
@@ -212,6 +212,22 @@ run_worker(worker: BaseWorker) -> QThread # 绑定 signals、启动、收尾 d
|
||||
- 每个 worker/线程按需创建自己的 SQLite connection,不跨线程共享连接。
|
||||
- ③ 的批量确认弹窗在 GUI 主线程完成;用户确认后才创建 `ApplyWorker`。
|
||||
|
||||
## 启动入口
|
||||
|
||||
```python
|
||||
# main.py
|
||||
from app.gui import main
|
||||
|
||||
raise SystemExit(main())
|
||||
|
||||
# app/__main__.py
|
||||
from .gui import main
|
||||
|
||||
raise SystemExit(main())
|
||||
```
|
||||
|
||||
正式运行入口:`python main.py`;开发/包入口:`python -m app`。
|
||||
|
||||
## CLI / 触发合约(现有脚本,过渡期保留)
|
||||
|
||||
```bash
|
||||
|
||||
Reference in New Issue
Block a user