Nodes/LF Nodes/Extract region from sources
ComfyUI Node

Extract region from sources

Hand an LLM your code one function at a time

By lucafoscili·Created 2 years ago·Updated 2 years ago· 50
Extract region from sources
  • ui_widget
  • regions
  • regions_list
dir
subdirfalse
enable_historytrue
extensionpy

Large language models have context windows, and whole files don't always fit in them - or they fit but the model starts hallucinating about what it can't see. LF_RegionExtractor is the LF Nodes answer: it scans a directory of Python files, slices them into manageable "regions," and hands them out as structured JSON. It exists to feed the pack's LLM documentation pipeline, and it's a lot more useful than its dry name suggests.

The inputs are straightforward. dir is the path to the directory (or a single file) containing the Python files you want to dissect. subdir controls whether it also digs into subdirectories - leave it off for a flat folder, on for a whole project tree. extension defaults to py, so you can point it at .txt or .md files too if that's what you're slicing. The enable_history toggle (on by default) tracks which regions have already been extracted so re-running the workflow doesn't reprocess everything from scratch - the frontend shows this as a history widget, which doubles as a record of what the node has seen.

Output is regions as a JSON object and regions_list as a list of them. Either way, each region is a chunk of source code with enough structure (typically the function/class boundaries and their content) that a downstream LLM can be asked to document exactly that piece. Which is the whole point: regionsLF_MarkdownDocGenerator's prompt input → LF_SaveMarkdown writes the docs. A folder of Python files becomes a documented codebase without leaving ComfyUI, all running against a local model.

The real-world use is narrower than the marketing suggests. This is a code-documentation tool, not a general "read my files" node - its region concept is code-oriented, so point it at Python source, not arbitrary data files. If you're documenting a project you maintain, this is genuinely handy: point it at your source folder, get regions, batch them through the LLM, and save the markdown next to each file. If you were hoping for a generic file reader, look at LF_LoadLocalJSON from the same pack instead.

One tip from experience: use enable_history thoughtfully. It's great for incremental work - extract once, only new regions get reprocessed - but if you change your source files and want a clean re-extraction, you'll want to reset or toggle it off once. Stale history means stale docs.

Install is the usual LF Nodes route - ComfyUI Manager → "LF Nodes", or:

cd ComfyUI/custom_nodes
git clone https://github.com/lucafoscili/comfyui-lf

then restart. No models, no extra deps - it just reads files. And the standing note for this pack: the repo is frozen in legacy mode (fully functional), with active work in lucafoscili/lf-nodes.

Category✨ LF Nodes/IO Operations

Inputs (5)

NameTypeDefaultDescription
dirSTRINGPath to the directory or file containing the Python files.
subdirBOOLEANfalseWhether to load Python files from subdirectories as well.
enable_historyBOOLEANtrueTracks extracted regions to avoid reprocessing.
extensionSTRINGpyExtension of the files that will be read.
ui_widgetoptKUL_HISTORY[object Object]

Outputs (2)

NameTypeDescription
regionsJSON
regions_listJSON