Skip to content

Commit d061937

Browse files
committed
REFACTOR_PLAN.md: update progress markers through Phase 2-6
Phase 0 + 1a-1 + 1a-2 + 1b-1 through 1b-5 + 1c-1 through 1c-6 + 1d (partial) + 2-1 through 2-6 marked DONE / PARTIAL with commit hashes and remaining work scoped. Adds the cumulative -4,453 LOC mega-file shrink table so the next session can see where the wins landed.
1 parent 68fed4f commit d061937

1 file changed

Lines changed: 47 additions & 20 deletions

File tree

REFACTOR_PLAN.md

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ Branch: `feature/refactor-n-audit` (off v0.7.6).
2222
| Untested route modules | 18 of 21 | manual cross-ref |
2323
| Untested feature tabs | 40 of 42 | manual cross-ref |
2424

25+
## Progress through 2026-05-09 (20 commits on `feature/refactor-n-audit`)
26+
27+
| File | Original | Now | Δ |
28+
|---|---|---|---|
29+
| `state/__init__.py` | 4,418 | 4,273 | -145 |
30+
| `inference/__init__.py` | 3,574 | 1,521 | -2,053 |
31+
| `image_runtime/__init__.py` | 2,097 | 1,366 | -731 |
32+
| `video_runtime/__init__.py` | 2,378 | 2,216 | -162 |
33+
| `routes/setup/__init__.py` | 1,932 | 1,441 | -491 |
34+
| `src/api/index.ts` | 1,430 | 559 | -871 |
35+
| **Mega-file shrink total** | 15,829 | **11,376** | **-4,453 LOC** |
36+
37+
Tests posture across all 20 commits: **1,302 Python pass + 1 skip / 340 TS pass / tsc clean**. Zero regressions; coverage gate (60% Python) holds on every phase.
38+
2539
## Mega-file inventory
2640

2741
### Python (>1,800 LOC)
@@ -62,44 +76,57 @@ Each phase = 1 PR. Tests green at each boundary. No big-bang merge.
6276
### Phase 1 — Python backend split
6377

6478
**1a. `state.py` 4,418 → facade + 5 modules.**
79+
80+
**PARTIAL** (Phase 1a-1, 1a-2; commits `8a26a48`, `879eede`):
81+
- `state/logs.py` — LogManager (log + activity ring buffers + subscribers)
82+
- `state/metrics.py` — cache labels + profile change reasons + metrics payloads (11 pure functions)
83+
84+
state/__init__.py: 4418 → 4273 (-145). Sessions, model_manager, benchmark, settings_state extractions deferred — biggest remaining is the 2k LOC of session/chat methods.
85+
6586
```
6687
backend_service/state/
6788
__init__.py # ChaosEngineState facade — public API unchanged
68-
session_manager.py # chat sessions, history
69-
model_manager.py # model load/unload/discovery state
70-
inference_orchestrator.py
71-
benchmark_state.py
72-
settings_state.py
89+
logs.py # LogManager + ring buffers [done]
90+
metrics.py # cache labels + profile metrics [done]
91+
session_manager.py # chat sessions, history [pending]
92+
model_manager.py # model load/unload/discovery state [pending]
93+
inference_orchestrator.py [pending]
94+
benchmark_state.py [pending]
95+
settings_state.py [pending]
7396
```
7497

7598
**1b. `inference.py` 3,574 → engines/ subpackage.**
76-
```
77-
backend_service/inference/
78-
__init__.py
79-
controller.py # RuntimeController
80-
engines/
81-
base.py
82-
llama_cpp.py
83-
mlx_worker.py
84-
vllm.py
85-
jsonrpc.py
86-
```
99+
100+
**MOSTLY DONE** (Phase 1b-1 through 1b-5; commits `cb1aed3``25ecbdf`):
101+
- `inference/_constants.py` — 5 timeout / workspace constants
102+
- `inference/_utils.py` — 9 shared helpers (_now_label, _normalize_message_content, _read_text_tail, _append_runtime_note, _http_json, _find_open_port, _resolve_gguf_path, _is_local_target, _looks_like_gguf)
103+
- `inference/base.py` — 4 dataclasses + RepeatedLineGuard + BaseInferenceEngine
104+
- `inference/jsonrpc.py` — JsonRpcProcess subprocess bridge
105+
- `inference/simple_engines.py` — RemoteOpenAIEngine + MockInferenceEngine
106+
- `inference/mlx_engine.py` — MLXWorkerEngine
107+
- `inference/llama_cpp_engine.py` — LlamaCppEngine + 8 llama-specific helpers + 4 constants
108+
109+
inference/__init__.py: 3574 → 1521 (-2053). RuntimeController (~1050 LOC) is the only big class still inline; deferred — its helper graph is the most cross-cutting in the package.
87110

88111
**1c. `video_runtime.py` + `image_runtime.py` → runtimes/{image,video}/.**
89112

90-
Extract shared pipeline-loader logic (LoRA fuse, distill swap, nunchaku, fp8, preview-VAE) into `runtimes/common/` — currently duplicated.
113+
**PARTIAL** (Phase 1c-1 through 1c-6, commits `b5ea526``af06a1d`):
114+
- `image_runtime/` package landed: types + repos + snapshot + device + placeholder_engine + mflux_engine extracted (image/__init__.py: 2097 → 1366).
115+
- `video_runtime/` package landed: types extracted (video/__init__.py: 2378 → 2216).
116+
117+
**Remaining**: extract `DiffusersTextToImageEngine` (1112 LOC inside image/__init__) + `DiffusersVideoEngine` (1335 LOC inside video/__init__). Both classes use the same pipeline-loader pattern (LoRA fuse, distill swap, nunchaku, fp8, preview-VAE) — extract into `runtimes/common/` after both engines move out of their respective __init__.py files.
91118

92-
**1d. `routes/setup.py` 1,932 → setup/{detect,install_pip,install_brew,install_runtimes,status}.py.**
119+
**1d. `routes/setup.py` 1,932 → setup/{longlive,wan_install}.py + main __init__.** **PARTIAL** (commit `6181c1b`). LongLive + Wan installers extracted. GPU bundle install (~700 LOC) still in main `__init__.py` because its helpers (`_extras_site_packages`, `_cleanup_mlx_video_shadow_metadata`, `_run_pip_install`) are shared with the regular pip-install path. Full split deferred — needs to first move shared helpers into a `setup/_install_helpers.py` module.
93120

94121
**1e. helpers/ regrouping into media/ models/ system/ ui/ storage/ inference/ finetune/ remote/ filter/ subpackages. Public re-exports preserve call sites.**
95122

96123
**Verify each step:** `pytest`, live smoke gens (text + image + video), `python -c "from backend_service.app import build_app; build_app()"` clean import.
97124

98125
### Phase 2 — Frontend split
99126

100-
**2a. `api.ts` 1,430 → src/api/{chat,image,video,models,setup,server,shared}.ts.**
127+
**2a. `api.ts` 1,430 → src/api/{chat,image,video,models,setup,admin}.ts.** **DONE** (Phase 2-1 through 2-6, commits `dea6a54``68fed4f`). 6 commits, 4,453 LOC across 6 domain modules. Live-binding circular re-exports preserve call sites.
101128

102-
**2b. `types.ts` 1,378 → src/types/{chat,image,video,models,setup,shared}.ts.**
129+
**2b. `types.ts` 1,378 → src/types/{chat,image,video,models,setup,shared}.ts.** Stub barrel + 3 sub-files exist already with per-domain UI types (ChatModelOption, ImageGalleryRuntimeFilter, VideoDiscoverTaskFilter); main types.ts content needs careful migration since most types reference each other. Defer to dedicated session.
103130

104131
**2c. Mega-hooks → 3-way splits each.**
105132
- `useChat``useChatStreaming` + `useChatHistory` + `useChatInput`

0 commit comments

Comments
 (0)