TF Tokens Combine
Set operations for the parts you paint separately
- a
- b
- tokens
- info
Most real edits aren't one clean stroke - they're "all of that region, except the corner I overpainted" or "this part plus that part." TF Tokens Combine is the glue node that turns multiple TF_TOKENS selections into one, with proper set operations: union, intersect, difference, and invert. It's small and it's exactly the kind of node you don't miss until the moment you desperately need it.
Inputs are a, operation, and optional b. operation is the dropdown: union (a plus b), intersect (only where both agree), difference (a minus b), and invert - which uses only a, flipping your selection to everything you didn't pick. The tooltip is explicit that invert needs no b, which is a nice honesty about how the two inputs are treated asymmetrically. Outputs are the combined tokens and an info string describing what came out.
The concrete cases are where this earns its place. You build a region from several separate strokes that don't touch - paint the head, paint the torso, union them into one selection. You overpainted into the background - difference the extra bits back out. You want "everything except the dog" - invert. You want the overlap of two region-snapped selections because only the shared tokens are a safe edit target - intersect. Each of those is a normal step in a real editing session, and without set operations you'd be re-painting until the selection was right, which on a 16×16 grid is a lot of wasted token-precision effort.
Two design details are worth knowing. First, selections remember which level's regions they were snapped to (when they came from a region-wired source), and combine refuses two selections from different token grids - "both must come from the same token grid" is the error if you mix a 16×16 selection with something else. That's the pack's invariant system doing its job: levels all share the same 16×16 grid, so a mismatch is almost always a real bug, not a technicality. Second, if a and b disagree on which level they belong to, the tooltip on _combined_level in the source says both must come from the same token grid - selections built against different levels' region maps are still interchangeable at the token level, but the pack checks the grid first.
Where people overreach: combining isn't editing. TF Tokens Combine only builds a selection; nothing happens to the image until you feed the result into an edit node (TF Feature Edit or TF Shape Edit) and then propagate it with TF Resume From Level. It's also worth checking the info output after a difference - if you subtract the wrong selection you can empty the set entirely, and an empty selection is the classic "my edit did nothing" cause this pack's troubleshooting keeps pointing back to. Use TF Level Canvas with a highlight wire (or TF Tokens Preview) to confirm what the combination resolved to before you commit a costly resume.
Install
Pack-standard again: Manager → search Trajectory Forcing, or git clone https://github.com/korayulusan/ComfyUI-TrajectoryForcing into custom_nodes/. This is a pure-logic node - no GPU work, no model call - so it works fine the moment the pack registers, but registration itself still depends on the pack's JAX/CUDA-12 environment story: requirements.txt is empty on purpose, install.py adds the JAX stack or declines with a reason, and the README's env/setup.sh is the fallback for the separate Python 3.11 venv. Quick check:
cd ComfyUI/custom_nodes/ComfyUI-TrajectoryForcing
python -m tf_nodes.doctor
If you find yourself combining the same two regions repeatedly, that's usually a sign the region map's cosine_threshold should move - a threshold that merges those regions in the first place beats re-unioning them every session.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| a | TF_TOKENS | — | |
| operation | COMBO | 'invert' uses only input a. | |
| bopt | TF_TOKENS | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| tokens | TF_TOKENS | — |
| info | STRING | — |