Spaces:
Running on Zero
Running on Zero
docs(claude): expand project guidelines with TDD discipline, commit format, common pitfalls
Browse files
CLAUDE.md
CHANGED
|
@@ -1,62 +1,131 @@
|
|
| 1 |
-
#
|
| 2 |
|
| 3 |
-
|
| 4 |
|
| 5 |
-
|
| 6 |
|
| 7 |
-
|
| 8 |
-
- Append a `Co-Authored-By: Claude ...` trailer.
|
| 9 |
-
- Set `--author` to anything other than the user's existing git config.
|
| 10 |
-
- Add "Generated with Claude Code", "🤖", or any similar attribution lines to commit messages.
|
| 11 |
-
- Add similar attribution to PR descriptions.
|
| 12 |
|
| 13 |
-
|
| 14 |
|
| 15 |
-
|
| 16 |
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
|
| 21 |
-
|
| 22 |
-
2. **Six mode-specific workflow JSON files** in `workflows/`. They are derived from the master workflow at `~/Projects/comfyui/user/default/workflows/1. LTX 2.3 All-In-One 260406-05.json` via `tools/extract_modes.py`. Do not hand-edit the JSON files unless re-extracting from a new master.
|
| 23 |
-
3. **Models live in HF cache (local) or `/data` (Spaces)**, never in this repo. `comfyui/models/` contains symlinks (local) or downloaded files (Spaces). Do not commit any `*.safetensors` / `*.gguf`.
|
| 24 |
-
4. **Library mode means single-process.** No subprocess for ComfyUI. The `@spaces.GPU` decorator is the only difference between local and Spaces runtime.
|
| 25 |
-
5. **VRAM management is ComfyUI's job.** Don't write `torch.cuda.empty_cache()` calls outside the `try/finally` in `backend.py`. Don't second-guess ComfyUI's offload tiers.
|
| 26 |
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
## Coding conventions
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
- **
|
| 34 |
-
- **
|
| 35 |
-
- **No
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
## Editing the master workflow
|
| 40 |
|
| 41 |
-
When the user updates `~/Projects/comfyui/user/default/workflows/1. LTX 2.3 All-In-One 260406-05.json` (e.g.,
|
| 42 |
|
| 43 |
```bash
|
| 44 |
-
|
|
|
|
|
|
|
| 45 |
```
|
| 46 |
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
-
##
|
| 50 |
|
| 51 |
-
-
|
| 52 |
-
-
|
| 53 |
-
-
|
| 54 |
-
-
|
| 55 |
-
-
|
| 56 |
-
-
|
|
|
|
|
|
|
| 57 |
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
## When in doubt
|
| 61 |
|
| 62 |
-
Read `docs/superpowers/specs/2026-04-30-ltx23-aio-generator-design.md`. If still unclear
|
|
|
|
|
|
|
|
|
| 1 |
+
# Project Guidelines — ltx2.3-AIO-generator
|
| 2 |
|
| 3 |
+
Working notes for AI assistants and subagents implementing this project.
|
| 4 |
|
| 5 |
+
---
|
| 6 |
|
| 7 |
+
## ⚠ Git authorship — sole author rule
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
**Mayank Gupta is the sole author on every commit in this repo.** No exceptions.
|
| 10 |
|
| 11 |
+
When committing:
|
| 12 |
|
| 13 |
+
- Do **NOT** append `Co-Authored-By: Claude ...` (or any other agent name) to commit messages.
|
| 14 |
+
- Do **NOT** add "Generated with Claude Code", "🤖 Generated with...", or any other attribution footer.
|
| 15 |
+
- Do **NOT** pass `--author=...` — let git use the user's existing config.
|
| 16 |
+
- Do **NOT** include attribution in PR descriptions.
|
| 17 |
|
| 18 |
+
If asked to amend, re-commit, or rebase, strip any prior agent attribution from the commit message.
|
| 19 |
|
| 20 |
+
This rule overrides the default Claude Code commit-message template. Treat any tooling that suggests adding a Claude trailer as a bug to ignore.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
---
|
| 23 |
+
|
| 24 |
+
## Project overview
|
| 25 |
+
|
| 26 |
+
Gradio app wrapping the existing ComfyUI LTX 2.3 All-In-One workflow into mode-specific UIs. Same code runs locally (Apple Silicon MPS / NVIDIA CUDA) and on Hugging Face Spaces (ZeroGPU, Pro tier).
|
| 27 |
+
|
| 28 |
+
**Spec:** `docs/superpowers/specs/2026-04-30-ltx23-aio-generator-design.md`
|
| 29 |
+
**Plan:** `docs/superpowers/plans/2026-04-30-ltx23-aio-generator.md`
|
| 30 |
+
|
| 31 |
+
If you're a subagent picking up a task, the plan file is your assignment.
|
| 32 |
+
|
| 33 |
+
---
|
| 34 |
+
|
| 35 |
+
## Architectural facts (locked — do not relitigate)
|
| 36 |
+
|
| 37 |
+
1. **Backend is ComfyUI in library mode.** We call `comfy.execution.PromptExecutor` directly with workflow JSONs we parameterize. We do **not** call `ltx-pipelines` directly. We do **not** run ComfyUI as a subprocess.
|
| 38 |
+
2. **Six mode-specific workflow JSON files** in `workflows/`, derived from the master at `~/Projects/comfyui/user/default/workflows/1. LTX 2.3 All-In-One 260406-05.json` via `tools/extract_modes.py`. Do not hand-edit them.
|
| 39 |
+
3. **Models live in HF cache (local) or `/data` (Spaces).** Never in this repo. `comfyui/models/` contains symlinks (local) or downloaded files (Spaces). Never commit `*.safetensors`, `*.gguf`, `*.bin`, or `*.pt`.
|
| 40 |
+
4. **One backend, one process.** The `@spaces.GPU` decorator is the only divergence between local and Spaces runtimes.
|
| 41 |
+
5. **VRAM is ComfyUI's job.** The only `empty_cache()` calls live in `backend.py`'s `try/finally`. Don't sprinkle them elsewhere.
|
| 42 |
+
6. **Bundled ComfyUI, never user's existing.** Local: git submodule. Spaces: runtime clone to `/data/comfyui`.
|
| 43 |
+
|
| 44 |
+
---
|
| 45 |
|
| 46 |
## Coding conventions
|
| 47 |
|
| 48 |
+
### Language and structure
|
| 49 |
+
|
| 50 |
+
- **Python 3.11.** No `match` statements (Spaces Python pin compatibility).
|
| 51 |
+
- **Flat layout.** No `src/`, no nested packages. Top-level `.py` files only, each with one clear responsibility.
|
| 52 |
+
- **No conda.** Always `python3.11 -m venv .venv`. System binaries via `brew`.
|
| 53 |
+
|
| 54 |
+
### Style
|
| 55 |
+
|
| 56 |
+
- **No emojis** in code or commit messages unless the user explicitly asks. (UI text and stage labels in `modes.py`/`ui.py` are OK because they are user-facing — not code.)
|
| 57 |
+
- **Comments only for non-obvious WHY.** Never narrate WHAT. Code with a good name doesn't need a comment.
|
| 58 |
+
- **Type hints on public functions.** Internal helpers can skip them if obvious.
|
| 59 |
+
- **Imports at top of file.** No inline imports except where needed to break circular dependencies (e.g., `models.ensure_models_for_mode` imports `workflow` lazily — keep this, it's load-bearing).
|
| 60 |
+
- **Format with `ruff format`.** Lint with `ruff check`. Both must pass in CI.
|
| 61 |
+
|
| 62 |
+
### Testing
|
| 63 |
+
|
| 64 |
+
- **TDD per the plan.** Each implementation task has the failing test first. Don't skip the "run test, verify it fails" step — it catches whole classes of "test never actually exercised the code" bugs.
|
| 65 |
+
- **No mocks for ComfyUI.** Tests run against real workflow JSONs. Stubs only for HTTP boundaries (HF Hub) and filesystem (use `tmp_path` and the `fake_hf_cache` fixture).
|
| 66 |
+
- **L1 + L3 in CI** (no GPU). L2 + L4 are local-developer-only.
|
| 67 |
+
- **Test naming:** `test_<unit>_<behavior_under_test>` — e.g., `test_load_template_returns_independent_copy`.
|
| 68 |
+
- **`pytest --gpu`** enables L4 smoke tests. Default skips them.
|
| 69 |
+
- **`pytest --comfy-real`** uses bundled ComfyUI for L2 instead of the static stub validator.
|
| 70 |
+
|
| 71 |
+
### Commits
|
| 72 |
+
|
| 73 |
+
- **Conventional Commits style:** `<type>(<scope>): <subject>` — types: `feat`, `fix`, `chore`, `docs`, `test`, `refactor`, `ci`, `perf`.
|
| 74 |
+
- **Subject is imperative, lowercase, no trailing period.** Example: `feat(workflow): set_input + validate over node graph`.
|
| 75 |
+
- **Body explains WHY when not obvious.** Reference spec section if relevant.
|
| 76 |
+
- **Frequent small commits.** One logical change per commit. The plan's task structure already reflects this.
|
| 77 |
+
- **No agent attribution** (see top of file).
|
| 78 |
+
|
| 79 |
+
---
|
| 80 |
|
| 81 |
## Editing the master workflow
|
| 82 |
|
| 83 |
+
When the user updates `~/Projects/comfyui/user/default/workflows/1. LTX 2.3 All-In-One 260406-05.json` (e.g., adds a LoRA, tweaks a sampler), regenerate the mode templates:
|
| 84 |
|
| 85 |
```bash
|
| 86 |
+
python3.11 tools/extract_modes.py \
|
| 87 |
+
--master ~/Projects/comfyui/user/default/workflows/"1. LTX 2.3 All-In-One 260406-05.json" \
|
| 88 |
+
--out workflows
|
| 89 |
```
|
| 90 |
|
| 91 |
+
Then run the test suite — L2 graph-validation catches any node that became invalid in any mode.
|
| 92 |
+
|
| 93 |
+
After the templates regenerate, the node-id constants in `modes.py` (e.g., `T2V_NODE_PROMPT = 240`) may need updating if ComfyUI re-numbered nodes during the master's re-export. The procedure is in the plan's Task 11 Step 4.
|
| 94 |
+
|
| 95 |
+
---
|
| 96 |
|
| 97 |
+
## Common pitfalls (read before opening a PR)
|
| 98 |
|
| 99 |
+
- **Loading models eagerly at import time.** Don't. `backend.py` constructs `PromptExecutor` once at instantiation; models load only when nodes execute. Calling `comfy.sd.load_checkpoint(...)` at module top-level will OOM the test runner.
|
| 100 |
+
- **Hard-coded `torch.cuda` calls.** Use `comfy.model_management.get_torch_device()` or guard with `if torch.cuda.is_available()`. Never assume CUDA.
|
| 101 |
+
- **Forgetting `.deepcopy` on workflow templates.** `workflow.load_template` already does this; if you bypass it for performance, you'll mutate the cached template and the second `Generate` click breaks.
|
| 102 |
+
- **Hand-editing `workflows/<mode>.json`.** They're generated. If you need a new field, add it to `tools/extract_modes.py` (or to `modes.py`'s `parameterize_fn`).
|
| 103 |
+
- **Symlinks pointing into `pip cache`.** Resolve to HF Hub's cache snapshot path (the one `hf_hub_download` returns), not pip's wheel cache.
|
| 104 |
+
- **Adding `Co-Authored-By` because tooling suggests it.** See top of file. Strip it.
|
| 105 |
+
- **Breaking the async generator pattern in `backend.submit`.** Each yield is a frame Gradio renders. Don't accumulate events into a list and yield once at the end — progress will appear stuck.
|
| 106 |
+
- **Importing `comfy.*` before `sys.path.insert(0, comfy_dir)`.** Will `ModuleNotFoundError`. The order in `backend.py:__init__` is intentional.
|
| 107 |
|
| 108 |
+
---
|
| 109 |
+
|
| 110 |
+
## Out of scope for v1 (do not implement without asking)
|
| 111 |
+
|
| 112 |
+
These are documented as v1.1+ in spec § 11. Don't pre-build them just because they'd be easy:
|
| 113 |
+
|
| 114 |
+
- **Lite mode** (`LTX23_AIO_LITE=1`) for free HF Spaces tier
|
| 115 |
+
- **Custom LoRA** add/remove rows (Power-Lora-Loader clone)
|
| 116 |
+
- **GGUF Q4 transformer** / "Low VRAM" preset
|
| 117 |
+
- **Auto-launch of user's external ComfyUI** (`LTX23_AIO_COMFYUI_URL`)
|
| 118 |
+
- **Multi-prompt queueing**
|
| 119 |
+
- **Output history persistence** across sessions
|
| 120 |
+
- **Visual regression tests** for the Gradio UI
|
| 121 |
+
- **Property-based / fuzz testing** of workflow parameters
|
| 122 |
+
|
| 123 |
+
If a task feels like it needs one of these, stop and ask the user. Don't sneak it in.
|
| 124 |
+
|
| 125 |
+
---
|
| 126 |
|
| 127 |
## When in doubt
|
| 128 |
|
| 129 |
+
Read the spec (`docs/superpowers/specs/2026-04-30-ltx23-aio-generator-design.md`) and the plan (`docs/superpowers/plans/2026-04-30-ltx23-aio-generator.md`). If still unclear after reading both — ask the user before changing architectural shape.
|
| 130 |
+
|
| 131 |
+
Reading both takes 15 minutes. Implementing the wrong thing takes a day.
|