refactor: improve plugin hook system with default parameter handling

- Add `default` parameter to `call_plugin_hook` function - Return default value instead of None when hooks are not found - Fix hook name in `get_plugin_config` from "save_plugin_config" to "get_plugin_config" - Fix hook name in `get_default_plugin_config` from "save_plugin_config" to "get_default_plugin_config" - Update hook calls to use `default` parameter instead of `result` - Pass default parameter to both sync and async hook

frdel committed Mar 17, 2026 at 06:51 UTC 0983e6457ad4fc66bb785c0b81a77c3efabe978e
1 file changed +10 -12
helpers/plugins.py
+10 -12
@@ -465,17 +465,15 @@ def get_plugin_config(
465 )(files.read_file(file_path))
466
467 # call plugin hook to modify the standard result if needed
468 - new_result = call_plugin_hook(
468 + result = call_plugin_hook(
469 plugin_name,
470 - "save_plugin_config",
471 - result=result,
470 + "get_plugin_config",
471 + default=result,
472 agent=agent,
473 project_name=project_name,
474 agent_profile=agent_profile,
475 )
476
477 - if new_result is not None:
478 - return new_result
477 return result
478
479
@@ -487,7 +485,7 @@ def get_default_plugin_config(plugin_name: str):
485 # call plugin hook to get the result
486 result = call_plugin_hook(
487 plugin_name,
490 - "save_plugin_config",
488 + "get_default_plugin_config",
489 file_path = file_path
490 )
491
@@ -512,7 +510,7 @@ def save_plugin_config(
510 new_settings = call_plugin_hook(
511 plugin_name,
512 "save_plugin_config",
515 - result=None,
513 + default=settings,
514 project_name=project_name,
515 agent_profile=agent_profile,
516 settings=settings,
@@ -712,7 +710,7 @@ def send_frontend_reload_notification(plugin_names: list[str] | None = None):
710 DeferredTask().start_task(_send_later)
711
712
715 -def call_plugin_hook(plugin_name: str, hook_name: str, *args, **kwargs):
713 +def call_plugin_hook(plugin_name: str, hook_name: str, default: Any=None, *args, **kwargs):
714 hooks = None
715
716 # use cached hooks if enabled
@@ -728,13 +726,13 @@ def call_plugin_hook(plugin_name: str, hook_name: str, *args, **kwargs):
726 hooks = cache.get(HOOKS_CACHE_AREA, plugin_name)
727
728 if not hooks:
731 - return
729 + return default
730
731 hook = getattr(hooks, hook_name, None)
732 if not hook:
735 - return
733 + return default
734
735 if asyncio.iscoroutinefunction(hook):
738 - return asyncio.run(hook(*args, **kwargs))
736 + return asyncio.run(hook(*args, **kwargs, default=default))
737
740 - return hook(*args, **kwargs)
738 + return hook(*args, **kwargs, default=default)