refactor: split monolithic main.py into services/ + ui/ modules (improve-maintainability)
- main.py: 4360 → 146 lines (96.6% reduction), entry layer only - services/: rate_limiter, autostart, persona, connection, profile, hotspot, content, engagement, scheduler, queue_ops (10 business modules) - ui/app.py: all Gradio UI code extracted into build_app(cfg, analytics) - Fix: with gr.Blocks() indented inside build_app function - Fix: cfg.all property (not get_all method) - Fix: STATUS_LABELS, get_persona_keywords, fetch_proactive_notes imports - Fix: queue_ops module-level set_publish_callback moved into configure() - Fix: pub_queue.format_*() wrapped as queue_format_table/calendar helpers - All 14 files syntax-verified, build_app() runtime-verified - 58/58 tasks complete"
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
## ADDED Requirements
|
||||
|
||||
### Requirement: 剩余 Gradio Tab 提取为独立 UI 模块
|
||||
系统 SHALL 将 `main.py` 中除 Tab 1(已完成)之外的 7 个 Gradio Tab 各自提取为 `ui/tab_*.py` 模块文件,每个文件暴露 `build_tab(...)` 函数:
|
||||
|
||||
| 模块文件 | Tab 名称 |
|
||||
|---|---|
|
||||
| `ui/tab_hotspot.py` | 🔥 热点探测 |
|
||||
| `ui/tab_engage.py` | 💬 互动运营 |
|
||||
| `ui/tab_profile.py` | 👤 我的主页 |
|
||||
| `ui/tab_auto.py` | 🤖 自动运营 |
|
||||
| `ui/tab_queue.py` | 📅 内容排期 |
|
||||
| `ui/tab_analytics.py` | 📊 数据分析 |
|
||||
| `ui/tab_settings.py` | ⚙️ 系统设置 |
|
||||
|
||||
#### Scenario: 每个 Tab 模块暴露 build_tab 函数
|
||||
- **WHEN** `main.py` 执行 `from ui.tab_hotspot import build_tab as build_tab_hotspot`
|
||||
- **THEN** 调用 `build_tab_hotspot(fn_*, ...)` 后 SHALL 返回包含需跨 Tab 共享组件的 dict
|
||||
|
||||
#### Scenario: build_tab 接收回调而非直接导入 services
|
||||
- **WHEN** `build_tab(...)` 内部需要调用业务函数时
|
||||
- **THEN** 业务函数 SHALL 通过 `fn_*` 参数传入(与 `tab_create.py` 已有模式一致),不在 `ui/tab_*.py` 内直接 `import services.*`
|
||||
|
||||
#### Scenario: 事件绑定在 build_tab 内完成
|
||||
- **WHEN** `build_tab(...)` 被调用
|
||||
- **THEN** 本 Tab 所有 Gradio 组件的 `.click()`、`.change()` 等事件绑定 SHALL 在函数内完成,`main.py` 不保留本 Tab 的事件绑定代码
|
||||
|
||||
#### Scenario: main.py 成为纯入口层
|
||||
- **WHEN** 所有 11 个 capability 均完成迁移后
|
||||
- **THEN** `main.py` 行数 SHALL 不超过 400 行,且不包含任何业务逻辑(仅含导入、单例初始化、UI 组装、`app.launch()`)
|
||||
Reference in New Issue
Block a user