support kwargs in prompt var plugins

frdel committed Nov 18, 2025 at 10:39 UTC f12b32ee286928ec0d991dd71591c8ec57687898
1 file changed +5 -5
python/helpers/files.py
+5 -5
@@ -19,12 +19,12 @@ import mimetypes
19
20 class VariablesPlugin(ABC):
21 @abstractmethod
22 - def get_variables(self, file: str, backup_dirs: list[str] | None = None) -> dict[str, Any]: # type: ignore
22 + def get_variables(self, file: str, backup_dirs: list[str] | None = None, **kwargs) -> dict[str, Any]: # type: ignore
23 pass
24
25
26 def load_plugin_variables(
27 - file: str, backup_dirs: list[str] | None = None
27 + file: str, backup_dirs: list[str] | None = None, **kwargs
28 ) -> dict[str, Any]:
29 if not file.endswith(".md"):
30 return {}
@@ -48,7 +48,7 @@ def load_plugin_variables(
48 plugin_file, VariablesPlugin, one_per_file=False
49 )
50 for cls in classes:
51 - return cls().get_variables(file, backup_dirs) # type: ignore < abstract class here is ok, it is always a subclass
51 + return cls().get_variables(file, backup_dirs, **kwargs) # type: ignore < abstract class here is ok, it is always a subclass
52
53 # load python code and extract variables variables from it
54 # module = None
@@ -96,7 +96,7 @@ def parse_file(
96
97 is_json = is_full_json_template(content)
98 content = remove_code_fences(content)
99 - variables = load_plugin_variables(absolute_path, _directories) or {} # type: ignore
99 + variables = load_plugin_variables(absolute_path, _directories, **kwargs) or {} # type: ignore
100 variables.update(kwargs)
101 if is_json:
102 content = replace_placeholders_json(content, **variables)
@@ -135,7 +135,7 @@ def read_prompt_file(
135 # content = remove_code_fences(f.read())
136 content = f.read()
137
138 - variables = load_plugin_variables(_file, _directories) or {} # type: ignore
138 + variables = load_plugin_variables(_file, _directories, **kwargs) or {} # type: ignore
139 variables.update(kwargs)
140
141 # Replace placeholders with values from kwargs