Short rules for keeping VideoSeek maintainable. Architecture overview: architecture.md. How to send a change: ../CONTRIBUTING.md.
- New features go through
src/services/— UI and Agent HTTP only schedule; they do not copy business logic. Reuse what is already there: indexes insrc/storage, inference insrc/core, and the existing HTTP helpers. Do not add a second index, inference stack, or client for one feature. - Do not extend legacy npy / FAISS index paths — Lance is the write/read path. Legacy code is maintenance-only until removed.
- Indexing/search reads are Lance-only —
_load_vectors_from_disk/ search assets do not load*_vectors.npy. Users import npy → Lance from Settings → Paths (not auto on launch); afterlance_migration.completed, startup gates trust that flag and skip vector-dir listdir (sidecar npy may remain). Library details mark npy-only videos asbroken_asset, notready. - Do not import private (
_foo) symbols across packages — if another module needs it, make a public helper or move it. Stage→stagefrom … import _foois a failed split. - Split on stage boundaries, not line quotas — extract a coherent stage / concern when the boundary is clear. ~400–500 lines is a smell / pause, not a hard force-split. Prefer one coherent module over many tiny ones that only exist to game a count.
- Broad
exceptmust not hide a failure —except Exception/ bareexceptthat still returns[]/0/None/""must callnote_swallowed(or log / raise). Narrow parse catches may keep a quiet fallback.tests/test_silent_failure_ratchet.pyfails if a new silent one appears. - Recap stage modules stay out of the runner — knobs and shared match patterns in
recap_constants.py, prompts inrecap_prompts.py, VO timing inrecap_vo_budget.py, match QC inrecap_match.py, captions inrecap_captions.py, cut coalesce/fit/pad/build inrecap_cuts.py/recap_cut_fit.py/recap_cut_pad.py/recap_cut_build.py, sidecar I/O inrecap_io.py, soft focus inrecap_focus.py, rematch helpers+jobs inrecap_rematch.py, motion inrecap_motion.py, OCR/spine inrecap_spine.py, LLM JSON inrecap_llm_json.py, plan cover/acts/gaps/merge/normalize inrecap_plan_*.py, act plan LLM+finalize inrecap_plan_pipeline.py, match waves+prompts inrecap_match_waves.py, VO scrub/draft/units/edit/post/pipeline inrecap_vo_*.py, clocks inrecap_clock.py, caption prompts inrecap_caption_prompt.py, runtime+export inrecap_runtime.py, pack+dialogue inrecap_pack.py;recap_servicere-exports them and keepsgenerate_recap_timeline. LLM stages look upcall_remote_llm/build_recap_pack(and other patch points) on the runner so tests can still patch there. - One sentence per file, and that sentence cannot say "and also" — If one sentence names what the file owns, leave it. Split when the sentence needs a second clause ("and also" / "plus" / "while we're here"). A new file uses the same test before it is added. Library indexing is already three files (
gui_library.py,gui_library_indexing.py,gui_library_index_issues.py). The understanding page is already settings, timeline, generation, dialogue, ASR, and LLM. Preview playback is already the player, the candidate strip, and the export queue (gui_preview.py,gui_preview_strip.py,gui_preview_export.py). Do not split those further by method. Under 100 lines, edit in place. The three storage→services inversions stay until the function itself is edited, then flip that call in the same change:image_gallery_storemust not rank (image_gallery_index),lance_store.import_npy_to_lancemust not take the index lock (indexing_runtime_status),evidence_tags_storemust not decide chunk alignment (load_video_chunks_by_id,chunk_meta_matches_payload). Storage reads and writes; those decisions stay insrc/services. Do not open a separate cleanup for the other two.
AI will keep patching a file until someone stops it. These are required behaviors, not a line-count beauty contest:
| Trigger | Stop and do this instead |
|---|---|
| You are about to append yet another concern into an already mixed module | Extract the stage boundary you need (or stop and ask). Do not keep bolting features onto a god file. |
| A file past ~500 lines keeps growing with no clear stage | Pause and name the boundary before more edits. Split only when the cut is coherent — do not shatter a working orchestration just to undercut 500. |
| A module gains more than 10 top-level magic knobs | Move them to a constants / config module (see rule 7 for recap). |
| A change would add another job to a file that is already one sentence | Stop. Do not bolt a second job onto it, and do not split out a file that cannot fill one sentence. |
You are editing one of the three storage functions that call into src/services for ranking, the index lock, or chunk alignment |
Flip that call in the same change (rule 8). Do not sweep the other two. |
A third fit_X_to_Y / stretch_X_for_Y / similar patch helper appears in the same pipeline |
Redesign the stage boundary; do not add another parameter or sibling helper. |
| You split a module | Define the public surface in the same change (name = _name aliases or a small facade). No new stage→stage from … import _foo (rule 4). |
Facade barrels that mostly re-export (e.g. recap_service) are fine to be long; do not grow their non-import body without reason. Leftover private re-exports on a facade are compatibility debt, not permission for new _ cross-imports.
A touch under 100 lines does not require a new file. A change that adds a second job does. Leave that boundary clearer than you found it — not necessarily fewer lines.
src/utils.py is a compatibility facade. Prefer:
| Concern | Module |
|---|---|
| App / resource paths | src.infra.paths |
| FFmpeg / ffprobe paths | src.infra.ffmpeg_paths |
| Model directory / asset paths | src.infra.model_paths |
| Meta JSON I/O | src.storage.meta_io |
| Library path / video hash | src.storage.video_identity |
| Duration / stream probe | src.media.probe |
| Preview / export clips | src.media.export_clip |
| Sampling FPS rules | src.media.sampling_fps |
| Thumbnails | src.media.thumbnail |
Existing from src.utils import … imports stay valid while callers migrate.
The former monolith src/web/agent_api.py is split into src/web/agent_api/ (health, search, export_ops, service, …). Public imports remain from src.web.agent_api import ….
- Ruff config lives in
pyproject.toml(F+E4/E7/E9;E402ignored for lazy imports). - CI runs
scripts/check_no_bom.py, thenruff check, thenpytest. - No UTF-8 BOM on tracked files — BOM in
pyproject.tomlbreaks tomllib / pip / pytest while Ruff may still pass. Local check:python scripts/check_no_bom.py. - Text encoding / line endings:
.editorconfig(charset = utf-8) and.gitattributes(text=auto eol=lf). Do not save sources as “UTF-8 with BOM”. - Expand Ruff rules gradually; do not dump a repo-wide style rewrite in one PR.
- User-visible copy lives in
src/app/i18n.py(Chinese and English). If that key is also insrc/app/copy_overrides.py, change both. The override is what the UI shows. - Former megafile
tests/test_services.pyis split intotests/test_services_*.py(+services_test_support.py). - MainWindow mixin attrs —
tests/test_gui_mixin_attr_ratchet.pyfreezes how manyself._names are touched from 2+ files underui/windows/gui*.py. Most multi-file names are intentional_sync_*/_refresh_*hooks or a few shared queues/flags; do not “decouple” single-file (A-class) attrs for cosmetics. Whole-repoself._scans overcount and are not a refactor brief.
- Prefer feature-local state. New cross-mixin
self._fields need a reason (quit, busy flag, shared refresh entry). - Sibling splits (
gui_understanding/_asr/_llm, search actions / panel / scope) will share hooks — that is expected, not a crisis. A file that cannot fill one sentence goes back into the sibling that owns that job. Search stays at those three files. - Do not start a “move all shared attrs onto page objects” project; the ratchet is there so coupling does not quietly grow.
- Do not rewrite the PySide6 UI “to clean the codebase.”
- Do not start a second storage format alongside Lance.
- Do not open a “full MainWindow refactor” without a feature-driven reason.