Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
e768378
chore: open 0.7.0-alpha.1 on develop
dkackman Oct 1, 2026
b420f6b
docs(stabilization): Phase 4 plan, stage 4a hot zone
dkackman Oct 1, 2026
d285971
refactor(workflow): delete the 8 one-line delegators; callers call th…
dkackman Oct 1, 2026
0c1a61f
refactor(library): one sub-workflow path resolver for every site
dkackman Oct 1, 2026
aad0bc4
refactor(library): the sub-workflow resolver takes base_dir; tests as…
dkackman Oct 1, 2026
8c7f5eb
fix: reset the run directory per run, sort kernels variant lines in d…
dkackman Oct 1, 2026
7f68454
docs(schema): argument_template is read only outside a sub-workflow run
dkackman Oct 1, 2026
31463f5
fix(audio): gain_audio rounds a frame region once; joins refuse a tra…
dkackman Oct 1, 2026
18053f5
fix(audio): the unrated-track refusal names a remedy that works
dkackman Oct 1, 2026
aa9cc04
metrics: add prefix_handling ratchet (baseline 82)
dkackman Oct 1, 2026
a531a8c
metrics: prefix_handling's fragment rule needs a whole prefix
dkackman Oct 1, 2026
f0fb678
refactor(references): every prefix is read and built through referenc…
dkackman Oct 1, 2026
f4e80d9
refactor(references): prose messages stay literal, skip-set test, dro…
dkackman Oct 1, 2026
3975e8d
chore(stabilization): stage 4a merge prep
dkackman Oct 1, 2026
4bb997c
Merge stage 4a: carried code (Phase 4)
dkackman Oct 1, 2026
3bf93a0
docs(stabilization): stage 4b detail and hot zone
dkackman Oct 1, 2026
1366052
feat(arch): module-size warn band; rename modules_over_1000_lines to …
dkackman Oct 1, 2026
e546e4e
ci: run the architecture ratchet; scope ruff to the Python packages a…
dkackman Oct 1, 2026
fe7acd1
probe: empty module to trip the ratchet (reverted next)
dkackman Oct 1, 2026
0f928e3
Revert "probe: empty module to trip the ratchet (reverted next)"
dkackman Oct 1, 2026
ccbde37
chore(stabilization): stage 4b merge prep
dkackman Oct 1, 2026
edb6e44
Merge stage 4b: guardrails in dw (Phase 4)
dkackman Oct 1, 2026
2270d73
docs(stabilization): stage 4c detail and hot zone
dkackman Oct 1, 2026
91b39c2
docs(stabilization): 4c CLAUDE.md triage table (221 rows, reviewed)
dkackman Oct 1, 2026
dcfc933
docs(stabilization): 4c hot zone adds the docstring destinations
dkackman Oct 1, 2026
0a1876c
docs(stabilization): 4c hot zone adds the docstring destinations
dkackman Oct 1, 2026
5f4e6d3
docs: the seam map, docs/ARCHITECTURE.md, and its path test
dkackman Oct 1, 2026
265a47b
docs: seam map review fixes; the map test checks owner names and ratc…
dkackman Oct 1, 2026
5c09974
docs(stabilization): move the docstring-verdict CLAUDE.md rules into …
dkackman Oct 1, 2026
cddb1e4
docs(docstrings): subfolder depth counts path segments; _not_found's …
dkackman Oct 1, 2026
1781680
docs(claude-md): cut the root CLAUDE.md to a map (674 -> 108 lines)
dkackman Oct 1, 2026
eb45d44
docs: 4c review fixes - dangling CLAUDE.md pointers, map gaps
dkackman Oct 1, 2026
1a492e5
docs: apply the CLAUDE.md triage to the sub-files; copilot-instructio…
dkackman Oct 1, 2026
eff9406
chore(stabilization): stage 4c merge prep
dkackman Oct 1, 2026
fa3cf10
Merge stage 4c: seam map and context diet (Phase 4)
dkackman Oct 1, 2026
003e88c
chore(stabilization): hot zone back to the standing entries after 4c
dkackman Oct 1, 2026
1b2f816
docs(stabilization): stage 4d detail and the harness stage C prompt
dkackman Oct 1, 2026
f865c55
docs(stabilization): stage C prompt and 4d fixes (advisor)
dkackman Oct 1, 2026
be3e7f6
docs(stabilization): ROADMAP - 4d waits on harness stage C
dkackman Oct 1, 2026
5623dd0
chore(stabilization): lift the freeze (gate 4, Task 2)
dkackman Oct 1, 2026
a5bced6
docs(stabilization): gate 4 report
dkackman Oct 1, 2026
c49683c
docs(stabilization): gate 4 lem smoke
dkackman Oct 2, 2026
d885df7
docs(stabilization): Phase 4 done - ROADMAP row and ASSESSMENT outcome
dkackman Oct 2, 2026
4a445f0
docs(release): 0.7.0 notes - developer-facing Phase 4 changes
dkackman Oct 2, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 4 additions & 112 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -1,115 +1,7 @@
# AI Coding Instructions for diffusers-workflow

This is a declarative workflow engine for the HuggingFace Diffusers library that executes AI model pipelines via JSON configuration files.
A declarative workflow engine for HuggingFace Diffusers: image, video and audio pipelines defined in JSON.

## Worker Architecture

`dw.serve` uses a **persistent worker subprocess** for workflow execution to maintain GPU model cache:
- Worker keeps models loaded in GPU across multiple runs
- Automatic workflow file change detection (SHA256 hash)
- Aggressive memory cleanup between runs (gc.collect + torch.cuda.empty_cache)
- Full cleanup on workflow change or `clear` command
- 5-minute execution timeout with graceful shutdown
- Memory monitoring with growth warnings (>500MB)

**Key modules:**
- `dw/worker.py` - Worker process with command loop and memory management
- `dw/worker_manager.py` - Worker lifecycle (start/stop/restart) for `JobManager`
- Communication via `multiprocessing.Queue` (command_queue, result_queue)

**Worker commands:** execute, cancel, shutdown, clear_memory, memory_status, probe_cache (typed messages in `dw/worker_protocol.py`; request/reply commands carry a `request_id`)

## Architecture Overview

**Core Components:**
- `dw/workflow.py`: Main orchestrator - loads JSON workflows, handles variable substitution, manages step execution (the run's phases live in `dw/workflow_run.py`, validation in `dw/validation.py`)
- `dw/step.py`: Individual workflow step executor - runs pipelines/tasks/sub-workflows
- `dw/pipeline_processors/pipeline.py`: The `Pipeline` class - HuggingFace pipeline loading and shared components (placement, component loading, adapters and progress reporting are beside it in `placement.py`, `components.py`, `adapters.py`, `progress.py`)
- `dw/tasks/task.py`: Executes utility tasks (image processing, QR codes, data gathering)
- `dw/previous_results.py`: Handles cross-step data flow using cartesian products of previous results

**Key Data Flow:**
1. JSON workflow loaded → validated against `workflow_schema.json`
2. Variables processed (`variable:name` → actual values)
3. Steps executed sequentially, each can reference `previous_result:step_name`
4. Results saved to output directory with naming pattern `{workflow_id}-{step_name}.{index}`

## Critical Patterns

**Variable System:** Use `"variable:name"` in JSON to reference workflow variables. Variables can be set via command line (`prompt="a cat"`) or in workflow definition.

**Result References:** Use `"previous_result:step_name"` to pipe outputs between steps. System automatically generates all combinations when multiple results exist.

**Constant References:** Use `"constant:module.NAME"` to read a value declared in Python instead of copying it into JSON.

**Prompt References:** Use `"prompt:name"` or `"prompt:folder/name"` to load a stored prompt's text from the `prompts/` library at run time (see `dw/prompts.py`).

**Pipeline Configuration:**
```json
{
"pipeline": {
"configuration": {"component_type": "FluxPipeline", "offload": "sequential"},
"from_pretrained_arguments": {"model_name": "black-forest-labs/FLUX.1-dev"},
"arguments": {"prompt": "variable:prompt", "num_inference_steps": 25}
}
}
```

**Task Execution:**
```json
{
"task": {
"command": "resize_center_crop",
"arguments": {"image": "previous_result:step1", "height": 768, "width": 768}
}
}
```

## Development Workflows

**Testing:** Run `python -m dw.test` for basic validation or `pytest -v` for full test suite
**Validation:** Use `python -m dw.validate workflow.json` to check schema compliance
**Execution:** `python -m dw.run workflow.json variable1=value1`

**Adding New Tasks:** Register a handler function in `dw/tasks/task.py` with the `@register_command("name")` decorator; `Task.run()` dispatches to the registry (falling back to image/video processor lookups for unregistered names)
**Adding Pipeline Types:** Update `workflow_schema.json` and ensure proper component loading in `pipeline_processors/components.py`

## Project-Specific Conventions

- All file paths in workflows are relative to the workflow file location
- Built-in workflows use `"builtin:filename.json"` and live in `dw/workflows/`
- Model offloading patterns: `"sequential"`, `"model"`, or component-specific configurations
- Quantization configs follow BitsAndBytesConfig pattern for 4-bit/8-bit loading
- Image results default to JPEG, videos to MP4 unless overridden in `result.content_type`

## Key Integration Points

**HuggingFace Diffusers:** Direct pipeline instantiation via `component_type` field
**Transformers:** Used for LLM-based prompt augmentation and text generation tasks
**External Models:** Support for ControlNet, LoRA adapters, custom community pipelines
**Device Management:** Automatic CUDA detection with fallback, memory optimization via offloading

## Security

**Critical security modules**: `dw/security.py` provides comprehensive input validation and protection, and `dw/trust.py` gates the trust model for untrusted workflows:
- **Path validation**: Prevents traversal attacks, validates file extensions, enforces directory restrictions
- **Input sanitization**: Validates variable names (alphanumeric + underscore/hyphen only), string lengths, control characters
- **Command safety**: Sanitizes subprocess arguments, blocks shell metacharacters, enforces `shell=False`
- **URL validation**: Restricts to http/https schemes only
- **Workflow trust**: Controls what untrusted workflows may import (`dw/trust.py`)

All entry points (run.py, validate.py, serve.py) use security validation. When adding features:
- Always validate paths with `validate_path()` or `validate_workflow_path()`
- Use `validate_variable_name()` for user-provided variable names
- Sanitize URLs with `validate_url()` before remote loading
- Use `sanitize_command_args()` before subprocess calls
- Never use `eval()`, `exec()`, or `shell=True`

## Common Gotchas

- Schema validation happens before variable substitution - use exact JSON types in schema
- `previous_result` generates cartesian products - be aware of exponential combinations
- Pipeline component sharing requires exact key matching in `reused_components`
- Built-in workflows inherit parent variable scope but need explicit argument mapping
- Variable names must match `^[a-zA-Z_][a-zA-Z0-9_-]*$` pattern for security
- File paths with `../` are blocked - use absolute or safe relative paths only
- Read `CLAUDE.md` (root) and `docs/ARCHITECTURE.md` first; the conventions for workflow JSON are in `docs/WORKFLOW_GUIDE.md`.
- Security: route every path, URL, variable name and subprocess argument through the validators in `dw/security.py` (`dw/trust.py` is the trust gate), and never use `eval()`, `exec()` or `shell=True`. See `docs/SECURITY.md`.
- Tests: see `docs/TESTING.md`.
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ jobs:
pip install -r requirements.txt -r requirements-test.txt
pip install git+https://github.com/huggingface/diffusers
- name: Format check
run: ruff format --check dw dw_mcp tests
run: ruff format --check dw dw_mcp tests scripts
- name: Lint
run: ruff check dw dw_mcp tests
run: ruff check dw dw_mcp tests scripts
- name: Tests
run: pytest -q
# Guards the architecture metrics against drifting past the committed
# baseline (modules, size ceiling, cycles); see docs/stabilization/
- name: Architecture ratchet
run: python scripts/arch_metrics.py --check docs/stabilization/baseline.json

ui:
runs-on: ubuntu-latest
Expand Down
Loading
Loading