From f879c2d09aa2edbab4926d567a333ce1567c4edb Mon Sep 17 00:00:00 2001 From: vladmandic Date: Wed, 4 Mar 2026 12:16:06 +0100 Subject: [PATCH] add copilot-instructions Signed-off-by: vladmandic --- .github/copilot-instructions.md | 44 +++++++++++++++++++++++ .github/instructions/core.instructions.md | 15 ++++++++ .github/instructions/ui.instructions.md | 14 ++++++++ .gitignore | 34 ++++++++---------- 4 files changed, 88 insertions(+), 19 deletions(-) create mode 100644 .github/copilot-instructions.md create mode 100644 .github/instructions/core.instructions.md create mode 100644 .github/instructions/ui.instructions.md diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md new file mode 100644 index 000000000..6fb62bcfe --- /dev/null +++ b/.github/copilot-instructions.md @@ -0,0 +1,44 @@ +# Project Guidelines + +## Tools +- `pyproject.toml` for Python configuration, including linting and type checking settings. +- `venv` for Python environment management, activated with `source venv/bin/activate`. +- `python` 3.10+. +- `eslint` configured for both core and UI code. +- `pnpm` for managing JavaScript dependencies and scripts, with key commands defined in `package.json`. +- `ruff` and `pylint` for Python linting, with configurations in `pyproject.toml` and executed via `pnpm ruff` and `pnpm pylint`. +- `pre-commit` hooks which also check line-endings and other formatting issues, configured in `.pre-commit-config.yaml`. + +## Project Structure +- Entry/startup flow: `webui.sh` -> `launch.py` -> `webui.py` -> modules under `modules/`. +- Core runtime state is centralized in `modules/shared.py` (shared.opts, model state, backend/device state). +- API/server routes are under `modules/api/`. +- Model and pipeline logic is split between `modules/sd_*` and `pipelines/`. +- Additional plug-ins live in `scripts/` and are used only when specified. +- Extensions live in `extensions-builtin/` and `extensions/` and are loaded dynamically. +- Tests and CLI scripts are under `test/` and `cli/`, with some API smoke checks in `test/full-test.sh`. + +## Code Style +- Prefer existing project patterns over strict generic style rules; + this codebase intentionally allows patterns often flagged in default linters such as allowing long lines, etc. + +## Build And Test +- Activate environment: `source venv/bin/activate` (always ensure this is active when working with Python code). +- Test startup: `python launch.py --test` +- Full startup: `python launch.py` +- Full lint sequence: `pnpm lint` +- Python checks individually: `pnpm ruff`, `pnpm pylint` +- JS checks: `pnpm eslint` and `pnpm eslint-ui` + +## Conventions +- Keep PR-ready changes targeted to `dev` branch conventions from `CONTRIBUTING`. +- Do not include unrelated edits or submodule changes when preparing contributions. +- Use existing CLI/API tool patterns in `cli/` and `test/` when adding automation scripts. +- Respect environment-driven behavior (`SD_*` flags and options) instead of hardcoding platform/model assumptions. +- For startup/init edits, preserve error handling and partial-failure tolerance in parallel scans and extension loading. + +## Pitfalls +- Initialization order matters: startup paths in `launch.py` and `webui.py` are sensitive to import/load timing. +- Shared mutable global state can create subtle regressions; prefer narrow, explicit changes. +- Device/backend-specific code paths (CUDA/ROCm/IPEX/DirectML/OpenVINO) should not assume one platform. +- Extension loading is dynamic; failures may appear only when specific extensions or models are present. diff --git a/.github/instructions/core.instructions.md b/.github/instructions/core.instructions.md new file mode 100644 index 000000000..6d40c80bb --- /dev/null +++ b/.github/instructions/core.instructions.md @@ -0,0 +1,15 @@ +--- +description: "Use when editing Python core runtime code, startup flow, model loading, API internals, backend/device logic, or shared state in modules and pipelines." +name: "Core Runtime Guidelines" +applyTo: "launch.py, webui.py, installer.py, modules/**/*.py, pipelines/**/*.py, scripts/**/*.py, extensions-builtin/**/*.py" +--- +# Core Runtime Guidelines + +- Preserve startup ordering and import timing in `launch.py` and `webui.py`; avoid moving initialization steps unless required. +- Treat `modules/shared.py` as the source of truth for global runtime state (`shared.opts`, model references, backend/device flags). +- Prefer narrow changes with explicit side effects; avoid introducing new cross-module mutable globals. +- Keep platform paths neutral: do not assume CUDA-only behavior and preserve ROCm/IPEX/DirectML/OpenVINO compatibility branches. +- Keep extension and script loading resilient: when adding startup scans/hooks, preserve partial-failure tolerance and logging. +- Follow existing API/server patterns under `modules/api/` and reuse shared queue/state helpers rather than ad-hoc request handling. +- Reuse established model-loading and pipeline patterns (`modules/sd_*`, `pipelines/`) instead of creating parallel abstractions. +- For substantial Python changes, run at least relevant checks: `npm run ruff` and `npm run pylint` (or narrower equivalents when appropriate). diff --git a/.github/instructions/ui.instructions.md b/.github/instructions/ui.instructions.md new file mode 100644 index 000000000..6dd45bb78 --- /dev/null +++ b/.github/instructions/ui.instructions.md @@ -0,0 +1,14 @@ +--- +description: "Use when editing frontend UI code, JavaScript, HTML, CSS, localization files, or built-in UI extensions including modernui and kanvas." +name: "UI And Frontend Guidelines" +applyTo: "javascript/**/*.js, html/**/*.html, html/**/*.css, html/**/*.js, extensions-builtin/sdnext-modernui/**/*, extensions-builtin/sdnext-kanvas/**/*" +--- +# UI And Frontend Guidelines + +- Preserve existing UI behavior and wiring between Gradio/Python endpoints and frontend handlers; do not change payload shapes without backend alignment. +- Follow existing project lint and style patterns; prefer consistency with nearby files over introducing new frameworks or architecture. +- Keep localization-friendly UI text changes synchronized with locale resources in `html/locale_*.json` when user-facing strings are added or changed. +- Avoid bundling unrelated visual refactors with functional fixes; keep UI PRs scoped and reviewable. +- For extension UI work, respect each extension's boundaries and avoid cross-extension coupling. +- Validate JavaScript changes with `pnpm eslint`; for modern UI extension changes also run `pnpm eslint-ui`. +- Maintain mobile compatibility when touching layout or interaction behavior. diff --git a/.gitignore b/.gitignore index 5ff03f72c..42a7cf49c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,9 @@ venv/ __pycache__ .ruff_cache +.vscode/ +.idea/ +**/.DS_Store /*.json /*.yaml /params.txt @@ -14,14 +17,9 @@ __pycache__ /data/cache.json /data/themes.json /data/installer.json -config_states node_modules pnpm-lock.yaml package-lock.json -.history -cache -**/.DS_Store -tunableop_results*.csv # all models and temp files *.log @@ -44,31 +42,29 @@ tunableop_results*.csv /*.mp3 /*.lnk /*.swp -!webui.bat -!webui.sh -!package.json -!requirements.txt # all dynamic stuff /extensions/**/* /outputs/**/* -/embeddings/**/* /models/**/* -/interrogate/**/* -/train/log/**/* -/textual_inversion/**/* -/detected_maps/**/* /tmp -/log -/cert -.vscode/ -.idea/ -/localizations .*/ +cache +tunableop_results*.csv # force included +!webui.bat +!webui.sh +!package.json +!requirements.txt !/data !/models/VAE-approx !/models/VAE-approx/model.pt !/models/Reference !/models/Reference/**/* + +# copilot instructions +!/.github/ +!/.github/copilot-instructions.md +!/.github/instructions/ +!/.github/instructions/**/*