lightfall 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lightfall/__init__.py +8 -0
- lightfall/__main__.py +10 -0
- lightfall/_version.py +24 -0
- lightfall/acquire/__init__.py +74 -0
- lightfall/acquire/buffer.py +363 -0
- lightfall/acquire/device_wrapper.py +416 -0
- lightfall/acquire/engine/__init__.py +155 -0
- lightfall/acquire/engine/base.py +587 -0
- lightfall/acquire/engine/bluesky.py +358 -0
- lightfall/acquire/engine/mock.py +165 -0
- lightfall/acquire/engine/plugins/__init__.py +9 -0
- lightfall/acquire/engine/plugins/bluesky_plugin.py +56 -0
- lightfall/acquire/engine/plugins/mock_plugin.py +55 -0
- lightfall/acquire/engine/protocol.py +145 -0
- lightfall/acquire/engine/registry.py +152 -0
- lightfall/acquire/engine/state.py +32 -0
- lightfall/acquire/engine/waiting_hook.py +225 -0
- lightfall/acquire/nats_bridge.py +62 -0
- lightfall/acquire/plan_ui.py +78 -0
- lightfall/acquire/plans/__init__.py +38 -0
- lightfall/acquire/plans/adaptive.py +288 -0
- lightfall/acquire/plans/example_plans.py +995 -0
- lightfall/acquire/plans/lightfall_plans.py +587 -0
- lightfall/acquire/plans/registry.py +543 -0
- lightfall/acquire/plans/standard_plans.py +186 -0
- lightfall/acquire/plans/user_plans.py +470 -0
- lightfall/acquire/runengine.py +36 -0
- lightfall/acquire/signals.py +452 -0
- lightfall/acquire/triggers/__init__.py +16 -0
- lightfall/acquire/triggers/base.py +25 -0
- lightfall/acquire/triggers/filter.py +37 -0
- lightfall/acquire/triggers/manager.py +73 -0
- lightfall/acquire/triggers/manual.py +36 -0
- lightfall/acquire/triggers/run_end.py +74 -0
- lightfall/acquire/triggers/run_start.py +52 -0
- lightfall/auth/__init__.py +38 -0
- lightfall/auth/policy.py +518 -0
- lightfall/auth/providers/__init__.py +30 -0
- lightfall/auth/providers/base.py +124 -0
- lightfall/auth/providers/keycloak.py +1017 -0
- lightfall/auth/providers/local.py +319 -0
- lightfall/auth/providers/pam.py +250 -0
- lightfall/auth/service_key.py +173 -0
- lightfall/auth/service_key_auth.py +79 -0
- lightfall/auth/session.py +656 -0
- lightfall/claude/__init__.py +52 -0
- lightfall/claude/_internal/__init__.py +1 -0
- lightfall/claude/_internal/serialization.py +195 -0
- lightfall/claude/_internal/threading.py +61 -0
- lightfall/claude/_internal/worker.py +757 -0
- lightfall/claude/_session_assembly.py +124 -0
- lightfall/claude/agent.py +596 -0
- lightfall/claude/lightfall_core_tools.py +410 -0
- lightfall/claude/markdown.py +103 -0
- lightfall/claude/permission_manager.py +588 -0
- lightfall/claude/tools/__init__.py +45 -0
- lightfall/claude/tools/controller.py +143 -0
- lightfall/claude/tools/interaction.py +177 -0
- lightfall/claude/tools/introspection.py +127 -0
- lightfall/claude/tools/logs.py +155 -0
- lightfall/claude/tools/screenshot.py +87 -0
- lightfall/claude/widget.py +851 -0
- lightfall/claude/widgets/__init__.py +5 -0
- lightfall/claude/widgets/permission_request.py +282 -0
- lightfall/claude/widgets/question_request.py +227 -0
- lightfall/claude/widgets/task_card.py +223 -0
- lightfall/config/__init__.py +23 -0
- lightfall/config/layers.py +317 -0
- lightfall/config/manager.py +244 -0
- lightfall/config/schema.py +154 -0
- lightfall/core/__init__.py +23 -0
- lightfall/core/application.py +727 -0
- lightfall/core/services.py +235 -0
- lightfall/devices/__init__.py +53 -0
- lightfall/devices/backends/__init__.py +17 -0
- lightfall/devices/backends/bcs.py +448 -0
- lightfall/devices/backends/happi.py +986 -0
- lightfall/devices/backends/mock.py +646 -0
- lightfall/devices/base.py +338 -0
- lightfall/devices/catalog.py +1039 -0
- lightfall/devices/connection_manager.py +676 -0
- lightfall/devices/model.py +290 -0
- lightfall/devices/monitoring.py +442 -0
- lightfall/devices/sim/__init__.py +26 -0
- lightfall/devices/sim/areadetector.py +436 -0
- lightfall/devices/sim/generators.py +223 -0
- lightfall/devices/sim/plugins.py +116 -0
- lightfall/epics/__init__.py +28 -0
- lightfall/epics/ca/__init__.py +10 -0
- lightfall/epics/ca/context.py +100 -0
- lightfall/epics/ca/pv.py +303 -0
- lightfall/epics/widgets/__init__.py +49 -0
- lightfall/epics/widgets/areadetector/__init__.py +16 -0
- lightfall/epics/widgets/areadetector/areadetector.py +281 -0
- lightfall/epics/widgets/areadetector/controls.py +478 -0
- lightfall/epics/widgets/areadetector/image_view.py +447 -0
- lightfall/epics/widgets/auto.py +319 -0
- lightfall/epics/widgets/base.py +404 -0
- lightfall/epics/widgets/checkbox.py +239 -0
- lightfall/epics/widgets/combobox.py +202 -0
- lightfall/epics/widgets/label.py +176 -0
- lightfall/epics/widgets/lineedit.py +253 -0
- lightfall/epics/widgets/motor.py +694 -0
- lightfall/epics/widgets/ophyd_base.py +469 -0
- lightfall/epics/widgets/ophyd_combobox.py +86 -0
- lightfall/epics/widgets/ophyd_label.py +54 -0
- lightfall/epics/widgets/ophyd_lineedit.py +170 -0
- lightfall/epics/widgets/ophyd_spinbox.py +79 -0
- lightfall/epics/widgets/slider.py +272 -0
- lightfall/epics/widgets/status_indicator.py +98 -0
- lightfall/epics/widgets/style.py +188 -0
- lightfall/exporter/__init__.py +1 -0
- lightfall/exporter/cli.py +67 -0
- lightfall/exporter/converters/__init__.py +26 -0
- lightfall/exporter/converters/base.py +39 -0
- lightfall/exporter/converters/noop.py +39 -0
- lightfall/exporter/converters/nxsas.py +73 -0
- lightfall/exporter/service.py +200 -0
- lightfall/exporter/tiled_utils.py +92 -0
- lightfall/ipc/__init__.py +6 -0
- lightfall/ipc/service.py +701 -0
- lightfall/ipc/trust.py +144 -0
- lightfall/logbook/__init__.py +46 -0
- lightfall/logbook/action_dialog.py +207 -0
- lightfall/logbook/action_logger.py +432 -0
- lightfall/logbook/block_mapper.py +562 -0
- lightfall/logbook/client.py +799 -0
- lightfall/logbook/converter.py +273 -0
- lightfall/logbook/editors/__init__.py +19 -0
- lightfall/logbook/editors/highlighter.py +305 -0
- lightfall/logbook/editors/markdown_editor.py +319 -0
- lightfall/logbook/editors/richtext_editor.py +1397 -0
- lightfall/logbook/entry_widget.py +1065 -0
- lightfall/logbook/event_listener.py +221 -0
- lightfall/logbook/fragment_widgets.py +925 -0
- lightfall/logbook/position_mapper.py +320 -0
- lightfall/logbook/protection.py +402 -0
- lightfall/logbook/style.py +394 -0
- lightfall/logbook/url.py +29 -0
- lightfall/logbook/visual_protection.py +330 -0
- lightfall/logbook/widget.py +680 -0
- lightfall/main.py +1091 -0
- lightfall/pipelines/__init__.py +4 -0
- lightfall/pipelines/client.py +148 -0
- lightfall/plugins/__init__.py +119 -0
- lightfall/plugins/agent_plugin.py +106 -0
- lightfall/plugins/agents/__init__.py +10 -0
- lightfall/plugins/agents/_mcp_helpers.py +52 -0
- lightfall/plugins/agents/alignment.py +94 -0
- lightfall/plugins/agents/autonomous_experiment/__init__.py +12 -0
- lightfall/plugins/agents/autonomous_experiment/nats_tools.py +210 -0
- lightfall/plugins/agents/autonomous_experiment/plugin.py +60 -0
- lightfall/plugins/agents/autonomous_experiment/prompts.py +164 -0
- lightfall/plugins/agents/current_esaf.py +435 -0
- lightfall/plugins/agents/device_tools.py +1043 -0
- lightfall/plugins/agents/engine_tools.py +720 -0
- lightfall/plugins/agents/ipython_tools.py +444 -0
- lightfall/plugins/agents/panel_builder.py +637 -0
- lightfall/plugins/agents/panel_design/references/cross_panel_patterns.md +95 -0
- lightfall/plugins/agents/panel_design/references/panel_design.md +680 -0
- lightfall/plugins/agents/panel_design.py +94 -0
- lightfall/plugins/agents/plan_design/references/plan_design.md +398 -0
- lightfall/plugins/agents/plan_design.py +90 -0
- lightfall/plugins/agents/plan_tools.py +878 -0
- lightfall/plugins/agents/scan_planning.py +101 -0
- lightfall/plugins/builtin_manifest.py +348 -0
- lightfall/plugins/controller_plugin.py +162 -0
- lightfall/plugins/engine_plugin.py +124 -0
- lightfall/plugins/errors.py +104 -0
- lightfall/plugins/info.py +112 -0
- lightfall/plugins/loader.py +878 -0
- lightfall/plugins/manifest.py +150 -0
- lightfall/plugins/panel_plugin.py +119 -0
- lightfall/plugins/plan_plugin.py +163 -0
- lightfall/plugins/registry.py +309 -0
- lightfall/plugins/settings_plugin.py +226 -0
- lightfall/plugins/statusbar_plugin.py +289 -0
- lightfall/plugins/theme_plugin.py +165 -0
- lightfall/plugins/types.py +136 -0
- lightfall/plugins/user_plugins.py +764 -0
- lightfall/project/__init__.py +37 -0
- lightfall/project/model.py +375 -0
- lightfall/project/service.py +427 -0
- lightfall/project/welcome.py +106 -0
- lightfall/resources/__init__.py +126 -0
- lightfall/resources/images/__init__.py +1 -0
- lightfall/resources/images/icon.ico +0 -0
- lightfall/resources/images/icon.png +0 -0
- lightfall/resources/images/logo.png +0 -0
- lightfall/services/__init__.py +33 -0
- lightfall/services/_alshub_client.py +73 -0
- lightfall/services/access_stamper.py +240 -0
- lightfall/services/als_beam_status.py +347 -0
- lightfall/services/ca_tunnel.py +325 -0
- lightfall/services/threaded_tiled_writer.py +174 -0
- lightfall/services/tiled_auth.py +21 -0
- lightfall/services/tiled_service.py +971 -0
- lightfall/services/tiled_writer_patch.py +301 -0
- lightfall/settings/__init__.py +1 -0
- lightfall/settings/image_helpers.py +30 -0
- lightfall/settings/user_settings_client.py +232 -0
- lightfall/ui/__init__.py +28 -0
- lightfall/ui/annotations.py +208 -0
- lightfall/ui/common/__init__.py +7 -0
- lightfall/ui/dialogs/__init__.py +26 -0
- lightfall/ui/dialogs/about_dialog.py +131 -0
- lightfall/ui/dialogs/add_trigger_dialog.py +152 -0
- lightfall/ui/dialogs/base.py +44 -0
- lightfall/ui/dialogs/bug_report_dialog.py +353 -0
- lightfall/ui/dialogs/create_plan_dialog.py +189 -0
- lightfall/ui/dialogs/device_edit_dialog.py +183 -0
- lightfall/ui/dialogs/export_dialog.py +565 -0
- lightfall/ui/dialogs/go_to_position_dialog.py +192 -0
- lightfall/ui/dialogs/login_dialog.py +756 -0
- lightfall/ui/dialogs/oauth_browser_dialog.py +305 -0
- lightfall/ui/dialogs/run_pipeline_dialog.py +131 -0
- lightfall/ui/dialogs/sample_metadata_dialog.py +316 -0
- lightfall/ui/docking/__init__.py +22 -0
- lightfall/ui/docking/icon_sidebar.py +806 -0
- lightfall/ui/docking/manager.py +682 -0
- lightfall/ui/docking/state.py +113 -0
- lightfall/ui/docking/theme.py +399 -0
- lightfall/ui/docking/widget.py +214 -0
- lightfall/ui/events.py +75 -0
- lightfall/ui/mainwindow.py +1006 -0
- lightfall/ui/models/__init__.py +49 -0
- lightfall/ui/models/device_selection.py +389 -0
- lightfall/ui/models/device_tree.py +1095 -0
- lightfall/ui/models/thread_model.py +667 -0
- lightfall/ui/models/tiled_model.py +384 -0
- lightfall/ui/panels/__init__.py +28 -0
- lightfall/ui/panels/base.py +525 -0
- lightfall/ui/panels/bluesky_panel.py +619 -0
- lightfall/ui/panels/claude/__init__.py +9 -0
- lightfall/ui/panels/claude/agent_registry.py +168 -0
- lightfall/ui/panels/claude_panel.py +887 -0
- lightfall/ui/panels/device_panel.py +370 -0
- lightfall/ui/panels/documents_panel.py +166 -0
- lightfall/ui/panels/ipython_panel.py +580 -0
- lightfall/ui/panels/logbook_entries_panel.py +84 -0
- lightfall/ui/panels/logbook_panel.py +627 -0
- lightfall/ui/panels/logging_panel.py +587 -0
- lightfall/ui/panels/pipeline_jobs_panel.py +160 -0
- lightfall/ui/panels/pipeline_triggers_panel.py +170 -0
- lightfall/ui/panels/plugins/__init__.py +34 -0
- lightfall/ui/panels/plugins/bluesky_plugin.py +27 -0
- lightfall/ui/panels/plugins/claude_plugin.py +29 -0
- lightfall/ui/panels/plugins/device_plugin.py +27 -0
- lightfall/ui/panels/plugins/documents_plugin.py +26 -0
- lightfall/ui/panels/plugins/ipython_plugin.py +27 -0
- lightfall/ui/panels/plugins/logbook_entries_plugin.py +23 -0
- lightfall/ui/panels/plugins/logbook_plugin.py +27 -0
- lightfall/ui/panels/plugins/logging_plugin.py +27 -0
- lightfall/ui/panels/plugins/pipeline_jobs_plugin.py +23 -0
- lightfall/ui/panels/plugins/pipeline_triggers_plugin.py +25 -0
- lightfall/ui/panels/plugins/queue_plugin.py +29 -0
- lightfall/ui/panels/plugins/synoptic_plugin.py +38 -0
- lightfall/ui/panels/plugins/threads_plugin.py +27 -0
- lightfall/ui/panels/plugins/tiled_browser_plugin.py +27 -0
- lightfall/ui/panels/plugins/visualization_plugin.py +27 -0
- lightfall/ui/panels/queue.py +754 -0
- lightfall/ui/panels/registry.py +483 -0
- lightfall/ui/panels/synoptic/__init__.py +27 -0
- lightfall/ui/panels/synoptic/editors.py +481 -0
- lightfall/ui/panels/synoptic/items.py +556 -0
- lightfall/ui/panels/synoptic/models.py +336 -0
- lightfall/ui/panels/synoptic/panel.py +889 -0
- lightfall/ui/panels/synoptic/serialization.py +300 -0
- lightfall/ui/panels/synoptic/view.py +504 -0
- lightfall/ui/panels/threads_panel.py +621 -0
- lightfall/ui/panels/tiled_browser_panel.py +854 -0
- lightfall/ui/panels/visualization_panel.py +508 -0
- lightfall/ui/preferences/__init__.py +24 -0
- lightfall/ui/preferences/backend.py +148 -0
- lightfall/ui/preferences/builtin.py +220 -0
- lightfall/ui/preferences/claude_settings.py +762 -0
- lightfall/ui/preferences/device_settings.py +461 -0
- lightfall/ui/preferences/dialog.py +234 -0
- lightfall/ui/preferences/editor_settings.py +227 -0
- lightfall/ui/preferences/ipc_settings.py +226 -0
- lightfall/ui/preferences/logbook_settings.py +232 -0
- lightfall/ui/preferences/login_settings.py +183 -0
- lightfall/ui/preferences/manager.py +562 -0
- lightfall/ui/preferences/plugin_settings.py +392 -0
- lightfall/ui/preferences/proxy_settings.py +561 -0
- lightfall/ui/preferences/skill_settings.py +28 -0
- lightfall/ui/preferences/tiled_settings.py +469 -0
- lightfall/ui/preferences/tool_settings.py +393 -0
- lightfall/ui/preferences/user_portable_backend.py +131 -0
- lightfall/ui/preferences/user_profile_settings.py +316 -0
- lightfall/ui/preferences/visualization_settings.py +159 -0
- lightfall/ui/resources/__init__.py +1 -0
- lightfall/ui/resources/logo.png +0 -0
- lightfall/ui/statusbar/__init__.py +11 -0
- lightfall/ui/statusbar/manager.py +379 -0
- lightfall/ui/statusbar/plugins/__init__.py +28 -0
- lightfall/ui/statusbar/plugins/als_beam_status.py +218 -0
- lightfall/ui/statusbar/plugins/auth_status.py +116 -0
- lightfall/ui/statusbar/plugins/connection_status.py +100 -0
- lightfall/ui/statusbar/plugins/thread_status.py +556 -0
- lightfall/ui/statusbar/plugins/tiled_status.py +179 -0
- lightfall/ui/statusbar/plugins/user_status.py +84 -0
- lightfall/ui/theater/__init__.py +28 -0
- lightfall/ui/theater/manager.py +124 -0
- lightfall/ui/theater/overlay.py +279 -0
- lightfall/ui/theater/proxy.py +111 -0
- lightfall/ui/theme/__init__.py +18 -0
- lightfall/ui/theme/builtin.py +1015 -0
- lightfall/ui/theme/manager.py +875 -0
- lightfall/ui/theme/registry.py +195 -0
- lightfall/ui/toast.py +221 -0
- lightfall/ui/tutorial.py +1100 -0
- lightfall/ui/widgets/__init__.py +110 -0
- lightfall/ui/widgets/base_control.py +259 -0
- lightfall/ui/widgets/camera/__init__.py +36 -0
- lightfall/ui/widgets/camera/base.py +815 -0
- lightfall/ui/widgets/camera/dark_frames.py +213 -0
- lightfall/ui/widgets/camera/image_view.py +649 -0
- lightfall/ui/widgets/camera/panels/__init__.py +14 -0
- lightfall/ui/widgets/camera/panels/cooler.py +320 -0
- lightfall/ui/widgets/camera/panels/temperature.py +192 -0
- lightfall/ui/widgets/camera/plan_based.py +202 -0
- lightfall/ui/widgets/compact_motor.py +522 -0
- lightfall/ui/widgets/controller_matcher.py +278 -0
- lightfall/ui/widgets/controller_registry.py +144 -0
- lightfall/ui/widgets/device_control.py +411 -0
- lightfall/ui/widgets/device_selector.py +438 -0
- lightfall/ui/widgets/device_tree_tab.py +461 -0
- lightfall/ui/widgets/document_stream.py +1028 -0
- lightfall/ui/widgets/favorites_tab.py +191 -0
- lightfall/ui/widgets/motor_control.py +1120 -0
- lightfall/ui/widgets/observers/__init__.py +8 -0
- lightfall/ui/widgets/observers/camera.py +48 -0
- lightfall/ui/widgets/observers/image_view.py +130 -0
- lightfall/ui/widgets/plan_config.py +954 -0
- lightfall/ui/widgets/plan_edit_dialog.py +294 -0
- lightfall/ui/widgets/plan_selector.py +452 -0
- lightfall/ui/widgets/profile_avatar.py +128 -0
- lightfall/ui/widgets/queue_view.py +647 -0
- lightfall/ui/widgets/runengine_control.py +549 -0
- lightfall/ui/widgets/signal_control.py +793 -0
- lightfall/ui/widgets/skill_trigger_button.py +183 -0
- lightfall/ui/widgets/tiled_filter_widget.py +314 -0
- lightfall/ui/widgets/tiled_status.py +149 -0
- lightfall/ui/widgets/warning_banner.py +185 -0
- lightfall/utils/__init__.py +53 -0
- lightfall/utils/crash_diagnostics.py +454 -0
- lightfall/utils/data_migration.py +22 -0
- lightfall/utils/editor_launcher.py +594 -0
- lightfall/utils/error_collector.py +245 -0
- lightfall/utils/git_tracker.py +197 -0
- lightfall/utils/log_buffer.py +233 -0
- lightfall/utils/logging.py +229 -0
- lightfall/utils/module_resolver.py +70 -0
- lightfall/utils/sentry.py +722 -0
- lightfall/utils/threads.py +991 -0
- lightfall/utils/tiled_helpers.py +96 -0
- lightfall/visualization/__init__.py +50 -0
- lightfall/visualization/base.py +5 -0
- lightfall/visualization/base_visualization.py +74 -0
- lightfall/visualization/fitting/__init__.py +24 -0
- lightfall/visualization/fitting/base.py +267 -0
- lightfall/visualization/fitting/fitters.py +325 -0
- lightfall/visualization/fitting/panel.py +265 -0
- lightfall/visualization/memory.py +392 -0
- lightfall/visualization/motor_mixin.py +524 -0
- lightfall/visualization/pg.py +156 -0
- lightfall/visualization/registry.py +144 -0
- lightfall/visualization/spec.py +79 -0
- lightfall/visualization/theme.py +266 -0
- lightfall/visualization/widgets/__init__.py +28 -0
- lightfall/visualization/widgets/adaptive/__init__.py +1 -0
- lightfall/visualization/widgets/adaptive/heatmap.py +655 -0
- lightfall/visualization/widgets/adaptive/plot.py +233 -0
- lightfall/visualization/widgets/heatmap.py +264 -0
- lightfall/visualization/widgets/image_stack.py +316 -0
- lightfall/visualization/widgets/image_view_toolbar.py +227 -0
- lightfall/visualization/widgets/lazy_image_view.py +590 -0
- lightfall/visualization/widgets/plot_1d.py +262 -0
- lightfall/visualization/widgets/scatter.py +247 -0
- lightfall/visualization/widgets/table.py +221 -0
- lightfall/visualization/widgets/time_axis.py +93 -0
- lightfall-0.1.1.dist-info/METADATA +223 -0
- lightfall-0.1.1.dist-info/RECORD +388 -0
- lightfall-0.1.1.dist-info/WHEEL +4 -0
- lightfall-0.1.1.dist-info/entry_points.txt +6 -0
- lightfall-0.1.1.dist-info/licenses/LEGAL.md +13 -0
- lightfall-0.1.1.dist-info/licenses/LICENSE.md +33 -0
|
@@ -0,0 +1,637 @@
|
|
|
1
|
+
"""Panel builder skill plugin with MCP tools.
|
|
2
|
+
|
|
3
|
+
Provides MCP tools for Claude to create and manage user-defined plugins,
|
|
4
|
+
particularly panel plugins. Includes tools for creating, listing, reloading,
|
|
5
|
+
and unloading user plugins.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import re
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
from lightfall.plugins.agent_plugin import AgentPlugin
|
|
14
|
+
from lightfall.plugins.agents._mcp_helpers import mcp_result
|
|
15
|
+
from lightfall.utils.logging import logger
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class PanelBuilderAgent(AgentPlugin):
|
|
19
|
+
"""Skill for building Lightfall plugins via MCP tools.
|
|
20
|
+
|
|
21
|
+
This skill provides Claude with tools to:
|
|
22
|
+
- Create user plugins (persistent or temporary)
|
|
23
|
+
- List user plugins with their status
|
|
24
|
+
- Reload plugins after external edits
|
|
25
|
+
- Unload plugins
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
@property
|
|
29
|
+
def name(self) -> str:
|
|
30
|
+
"""Return unique identifier for this skill."""
|
|
31
|
+
return "panel_builder"
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def display_name(self) -> str:
|
|
35
|
+
"""Return human-readable display name."""
|
|
36
|
+
return "Panel Builder"
|
|
37
|
+
|
|
38
|
+
@property
|
|
39
|
+
def description(self) -> str:
|
|
40
|
+
"""Return description of this skill's capabilities."""
|
|
41
|
+
return "Tools for creating and managing user plugins"
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def category(self) -> str:
|
|
45
|
+
"""Return category for grouping in settings UI."""
|
|
46
|
+
return "development"
|
|
47
|
+
|
|
48
|
+
@property
|
|
49
|
+
def enabled_by_default(self) -> bool:
|
|
50
|
+
"""Return whether this skill is enabled by default."""
|
|
51
|
+
return True
|
|
52
|
+
|
|
53
|
+
@property
|
|
54
|
+
def priority(self) -> int:
|
|
55
|
+
"""Return priority (lower = higher in prompt order)."""
|
|
56
|
+
return 25
|
|
57
|
+
|
|
58
|
+
def get_system_prompt(self) -> str:
|
|
59
|
+
"""Return the system prompt snippet for plugin building."""
|
|
60
|
+
return '''
|
|
61
|
+
## Plugin Building Tools
|
|
62
|
+
|
|
63
|
+
You have access to tools for creating user plugins in Lightfall.
|
|
64
|
+
|
|
65
|
+
### Plugin Kinds
|
|
66
|
+
|
|
67
|
+
Two kinds of user plugins are supported. The kind is inferred from what your
|
|
68
|
+
code defines and registers:
|
|
69
|
+
|
|
70
|
+
- **Panel plugin** — a `BasePanel` subclass with a `panel_metadata` class
|
|
71
|
+
attribute, self-registered at module scope with
|
|
72
|
+
`PanelRegistry.get_instance().register(MyPanel, replace=True)`. This is
|
|
73
|
+
the canonical user-plugin pattern; see the `panel_design` skill for the
|
|
74
|
+
full `BasePanel` API.
|
|
75
|
+
- **Agent plugin** — an `AgentPlugin` subclass that extends the embedded
|
|
76
|
+
Claude agent (skill prompts + MCP tools). Auto-registered via
|
|
77
|
+
`PluginType.__init_subclass__` on module load.
|
|
78
|
+
|
|
79
|
+
### Creating a Plugin
|
|
80
|
+
|
|
81
|
+
Use `lightfall_create_user_plugin` to write a plugin file to ~/lightfall/plugins/.
|
|
82
|
+
The plugin is validated (syntax + exec + at least one panel registration
|
|
83
|
+
or concrete AgentPlugin subclass), written to disk, and loaded immediately.
|
|
84
|
+
|
|
85
|
+
Example workflow:
|
|
86
|
+
1. User asks for a panel with specific functionality.
|
|
87
|
+
2. You generate a `BasePanel` subclass with a `panel_metadata` and a
|
|
88
|
+
trailing `PanelRegistry.get_instance().register(MyPanel, replace=True)`.
|
|
89
|
+
3. You call `lightfall_create_user_plugin` with that source.
|
|
90
|
+
4. The plugin is validated, written to disk, and loaded.
|
|
91
|
+
5. User can open the panel from View > User > [Panel Name].
|
|
92
|
+
|
|
93
|
+
### Quick Prototyping
|
|
94
|
+
|
|
95
|
+
For rapid prototyping, use `lightfall_create_temp_plugin` to create a temporary
|
|
96
|
+
plugin that will be lost on application restart. This is useful for testing
|
|
97
|
+
ideas before committing to a persistent plugin.
|
|
98
|
+
|
|
99
|
+
### Plugin Management
|
|
100
|
+
|
|
101
|
+
- `lightfall_list_user_plugins`: See all loaded user plugins and their status
|
|
102
|
+
- `lightfall_reload_plugin`: Force reload after external edits
|
|
103
|
+
- `lightfall_unload_plugin`: Remove a plugin from the registry
|
|
104
|
+
'''
|
|
105
|
+
|
|
106
|
+
def _validate_plugin_code(
|
|
107
|
+
self,
|
|
108
|
+
code: str,
|
|
109
|
+
name: str,
|
|
110
|
+
) -> tuple[bool, str | None, list[str]]:
|
|
111
|
+
"""Validate user plugin code. Returns (is_valid, error, found_kinds).
|
|
112
|
+
|
|
113
|
+
found_kinds is a list of type_names ("panel", "agent", ...) for
|
|
114
|
+
each registerable plugin class discovered.
|
|
115
|
+
|
|
116
|
+
Performs in-memory validation:
|
|
117
|
+
1. Syntax check via compile()
|
|
118
|
+
2. Execution in isolated namespace to check imports
|
|
119
|
+
3. Discovers either:
|
|
120
|
+
- Concrete `PluginType` subclasses (auto-enqueue path), or
|
|
121
|
+
- `BasePanel` subclasses with `panel_metadata` (self-register path)
|
|
122
|
+
4. Warning for dangerous imports
|
|
123
|
+
"""
|
|
124
|
+
# 1. Syntax check
|
|
125
|
+
try:
|
|
126
|
+
compile(code, f"{name}.py", "exec")
|
|
127
|
+
except SyntaxError as e:
|
|
128
|
+
return False, f"Syntax error at line {e.lineno}: {e.msg}", []
|
|
129
|
+
|
|
130
|
+
# 2. Execute in isolated namespace to check for import errors
|
|
131
|
+
namespace: dict[str, Any] = {"__name__": f"lightfall_user_plugins.{name}"}
|
|
132
|
+
try:
|
|
133
|
+
exec(code, namespace)
|
|
134
|
+
except Exception as e: # noqa: BLE001
|
|
135
|
+
return False, f"Import/exec error: {e}", []
|
|
136
|
+
|
|
137
|
+
# 3. Find registerable plugin classes. Accept either pattern:
|
|
138
|
+
# - Concrete PluginType subclass (auto-enqueued via __init_subclass__).
|
|
139
|
+
# - BasePanel subclass with panel_metadata (self-registered via
|
|
140
|
+
# PanelRegistry.register at module scope — the canonical
|
|
141
|
+
# user-plugin pattern from the panel_design skill).
|
|
142
|
+
from lightfall.plugins.types import PluginType
|
|
143
|
+
from lightfall.ui.panels.base import BasePanel
|
|
144
|
+
|
|
145
|
+
found_kinds: list[str] = []
|
|
146
|
+
for v in namespace.values():
|
|
147
|
+
if not isinstance(v, type):
|
|
148
|
+
continue
|
|
149
|
+
if getattr(v, "__abstractmethods__", None):
|
|
150
|
+
continue
|
|
151
|
+
if issubclass(v, PluginType) and v is not PluginType:
|
|
152
|
+
found_kinds.append(v.type_name)
|
|
153
|
+
elif (
|
|
154
|
+
issubclass(v, BasePanel)
|
|
155
|
+
and v is not BasePanel
|
|
156
|
+
and getattr(v, "panel_metadata", None) is not None
|
|
157
|
+
):
|
|
158
|
+
found_kinds.append("panel")
|
|
159
|
+
|
|
160
|
+
if not found_kinds:
|
|
161
|
+
return False, (
|
|
162
|
+
"No registerable plugin class found. Define either a "
|
|
163
|
+
"BasePanel subclass with `panel_metadata` (and call "
|
|
164
|
+
"PanelRegistry.get_instance().register(...) at module scope), "
|
|
165
|
+
"or a concrete AgentPlugin subclass."
|
|
166
|
+
), []
|
|
167
|
+
|
|
168
|
+
# 4. Warn about dangerous imports (but don't fail)
|
|
169
|
+
dangerous_patterns = [
|
|
170
|
+
(r"\bsubprocess\.", "subprocess module"),
|
|
171
|
+
(r"\bos\.system\b", "os.system"),
|
|
172
|
+
(r"\beval\s*\(", "eval()"),
|
|
173
|
+
(r"\bexec\s*\(", "exec()"),
|
|
174
|
+
]
|
|
175
|
+
warnings = []
|
|
176
|
+
for pattern, description in dangerous_patterns:
|
|
177
|
+
if re.search(pattern, code):
|
|
178
|
+
warnings.append(description)
|
|
179
|
+
|
|
180
|
+
if warnings:
|
|
181
|
+
logger.warning(
|
|
182
|
+
"Plugin '{}' uses potentially dangerous: {}",
|
|
183
|
+
name,
|
|
184
|
+
", ".join(warnings),
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
return True, None, found_kinds
|
|
188
|
+
|
|
189
|
+
def create_tools(self) -> list[Any]:
|
|
190
|
+
"""Create plugin management MCP tools.
|
|
191
|
+
|
|
192
|
+
Returns:
|
|
193
|
+
List of tool functions.
|
|
194
|
+
"""
|
|
195
|
+
try:
|
|
196
|
+
from claude_agent_sdk import tool
|
|
197
|
+
except ImportError:
|
|
198
|
+
logger.warning("claude_agent_sdk not available, panel builder tools disabled")
|
|
199
|
+
return []
|
|
200
|
+
|
|
201
|
+
@tool(
|
|
202
|
+
name="lightfall_create_user_plugin",
|
|
203
|
+
description="""Create a Lightfall user plugin from Python code.
|
|
204
|
+
|
|
205
|
+
The plugin will be written to ~/lightfall/plugins/ and automatically loaded.
|
|
206
|
+
The kind of plugin is inferred from what `code` defines:
|
|
207
|
+
|
|
208
|
+
- A `BasePanel` subclass with `panel_metadata`, self-registered at module
|
|
209
|
+
scope with `PanelRegistry.get_instance().register(MyPanel, replace=True)`,
|
|
210
|
+
contributes a dock panel. This is the canonical user-plugin pattern
|
|
211
|
+
(see the `panel_design` skill for the full `BasePanel` API).
|
|
212
|
+
- A concrete `AgentPlugin` subclass extends the embedded Claude agent
|
|
213
|
+
(skill prompts + MCP tools); it auto-registers via `__init_subclass__`
|
|
214
|
+
on module load.
|
|
215
|
+
|
|
216
|
+
Returns success status, file path, and the discovered plugin kind(s).
|
|
217
|
+
|
|
218
|
+
## Panel Plugin Template
|
|
219
|
+
|
|
220
|
+
```python
|
|
221
|
+
\"\"\"My panel description.\"\"\"
|
|
222
|
+
from __future__ import annotations
|
|
223
|
+
|
|
224
|
+
from typing import Any
|
|
225
|
+
|
|
226
|
+
from PySide6.QtCore import Signal, Qt
|
|
227
|
+
from PySide6.QtWidgets import (
|
|
228
|
+
QLabel, QPushButton, QLineEdit, QVBoxLayout, QHBoxLayout,
|
|
229
|
+
)
|
|
230
|
+
from lightfall.ui.panels.base import BasePanel, PanelMetadata
|
|
231
|
+
from lightfall.ui.panels.registry import PanelRegistry
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
class MyPanel(BasePanel):
|
|
235
|
+
\"\"\"Panel description.\"\"\"
|
|
236
|
+
|
|
237
|
+
panel_metadata = PanelMetadata(
|
|
238
|
+
id="lightfall.panels.user.my_panel",
|
|
239
|
+
name="My Panel",
|
|
240
|
+
description="What this panel does",
|
|
241
|
+
icon="mdi6.icon-name",
|
|
242
|
+
category="User",
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
def _setup_ui(self) -> None:
|
|
246
|
+
\"\"\"Build the panel UI. Use self._layout (inherited QVBoxLayout).\"\"\"
|
|
247
|
+
# DO NOT create a new layout - use the inherited self._layout
|
|
248
|
+
self._layout.setContentsMargins(10, 10, 10, 10)
|
|
249
|
+
|
|
250
|
+
label = QLabel("Hello!")
|
|
251
|
+
self._layout.addWidget(label)
|
|
252
|
+
|
|
253
|
+
btn = QPushButton("Click me")
|
|
254
|
+
btn.clicked.connect(self._on_click)
|
|
255
|
+
self._layout.addWidget(btn)
|
|
256
|
+
|
|
257
|
+
self._layout.addStretch()
|
|
258
|
+
|
|
259
|
+
def _on_click(self) -> None:
|
|
260
|
+
\"\"\"Handle button click.\"\"\"
|
|
261
|
+
pass
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
# Self-register at module load time (REQUIRED for user plugins).
|
|
265
|
+
# `replace=True` is required to support hot-reload of this file.
|
|
266
|
+
PanelRegistry.get_instance().register(MyPanel, replace=True)
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
## Common Mistakes to AVOID:
|
|
270
|
+
- DON'T subclass `PanelPlugin` for a user panel — that's the built-in
|
|
271
|
+
two-layer pattern. User panels subclass `BasePanel` directly and
|
|
272
|
+
self-register.
|
|
273
|
+
- DON'T use `qtpy` imports - use `PySide6` directly
|
|
274
|
+
- DON'T override `__init__` - override `_setup_ui()` instead
|
|
275
|
+
- DON'T create `QVBoxLayout(self)` - use inherited `self._layout`
|
|
276
|
+
- DON'T use `lightfall.panels.base` - use `lightfall.ui.panels.base`
|
|
277
|
+
|
|
278
|
+
## Accessing Devices:
|
|
279
|
+
```python
|
|
280
|
+
from lightfall.devices.catalog import DeviceCatalog
|
|
281
|
+
catalog = DeviceCatalog.get_instance()
|
|
282
|
+
motors = catalog.get_devices_by_category("motor") # Returns DeviceInfo list
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## Running Bluesky Plans:
|
|
286
|
+
```python
|
|
287
|
+
import bluesky.plan_stubs as bps
|
|
288
|
+
from lightfall.acquire import get_engine
|
|
289
|
+
|
|
290
|
+
def my_plan():
|
|
291
|
+
yield from bps.mv(motor, 0)
|
|
292
|
+
|
|
293
|
+
engine = get_engine()
|
|
294
|
+
engine.submit(my_plan(), description="My plan")
|
|
295
|
+
```""",
|
|
296
|
+
input_schema={
|
|
297
|
+
"type": "object",
|
|
298
|
+
"properties": {
|
|
299
|
+
"name": {
|
|
300
|
+
"type": "string",
|
|
301
|
+
"description": "Plugin name (becomes filename, e.g., 'my_panel' -> my_panel.py). Must be a valid Python identifier.",
|
|
302
|
+
},
|
|
303
|
+
"code": {
|
|
304
|
+
"type": "string",
|
|
305
|
+
"description": "Complete Python source code for the plugin file",
|
|
306
|
+
},
|
|
307
|
+
"description": {
|
|
308
|
+
"type": "string",
|
|
309
|
+
"description": "Brief description of what the plugin does (for logging)",
|
|
310
|
+
},
|
|
311
|
+
"overwrite": {
|
|
312
|
+
"type": "boolean",
|
|
313
|
+
"description": "If true, overwrite existing plugin with same name. Default: false",
|
|
314
|
+
"default": False,
|
|
315
|
+
},
|
|
316
|
+
},
|
|
317
|
+
"required": ["name", "code", "description"],
|
|
318
|
+
},
|
|
319
|
+
)
|
|
320
|
+
async def create_user_plugin(args: dict) -> dict[str, Any]:
|
|
321
|
+
"""Create a user plugin from Python code."""
|
|
322
|
+
from lightfall.plugins.user_plugins import UserPluginService
|
|
323
|
+
|
|
324
|
+
name = args["name"]
|
|
325
|
+
code = args["code"]
|
|
326
|
+
description = args["description"]
|
|
327
|
+
overwrite = args.get("overwrite", False)
|
|
328
|
+
|
|
329
|
+
# Validate name is a valid Python identifier
|
|
330
|
+
if not re.match(r"^[a-zA-Z_][a-zA-Z0-9_]*$", name):
|
|
331
|
+
return mcp_result({
|
|
332
|
+
"success": False,
|
|
333
|
+
"error": "Invalid plugin name. Must be a valid Python identifier "
|
|
334
|
+
"(letters, numbers, underscore; must start with letter or underscore).",
|
|
335
|
+
})
|
|
336
|
+
|
|
337
|
+
# Validate code in-memory before writing
|
|
338
|
+
is_valid, error, kinds = self._validate_plugin_code(code, name)
|
|
339
|
+
if not is_valid:
|
|
340
|
+
return mcp_result({
|
|
341
|
+
"success": False,
|
|
342
|
+
"error": error,
|
|
343
|
+
})
|
|
344
|
+
|
|
345
|
+
# Get plugins directory from UserPluginService
|
|
346
|
+
try:
|
|
347
|
+
service = UserPluginService.get_instance()
|
|
348
|
+
plugins_dir = service.get_plugins_directory()
|
|
349
|
+
except Exception as e:
|
|
350
|
+
logger.error("Failed to get UserPluginService: {}", e)
|
|
351
|
+
return mcp_result({
|
|
352
|
+
"success": False,
|
|
353
|
+
"error": f"Failed to access user plugins service: {e}",
|
|
354
|
+
})
|
|
355
|
+
|
|
356
|
+
file_path = plugins_dir / f"{name}.py"
|
|
357
|
+
|
|
358
|
+
# Check for existing file
|
|
359
|
+
if file_path.exists() and not overwrite:
|
|
360
|
+
return mcp_result({
|
|
361
|
+
"success": False,
|
|
362
|
+
"error": f"Plugin '{name}' already exists. Set overwrite=true to replace it.",
|
|
363
|
+
})
|
|
364
|
+
|
|
365
|
+
# Write the file
|
|
366
|
+
try:
|
|
367
|
+
file_path.write_text(code, encoding="utf-8")
|
|
368
|
+
except Exception as e:
|
|
369
|
+
logger.error("Failed to write plugin file {}: {}", file_path, e)
|
|
370
|
+
return mcp_result({
|
|
371
|
+
"success": False,
|
|
372
|
+
"error": f"Failed to write plugin file: {e}",
|
|
373
|
+
})
|
|
374
|
+
|
|
375
|
+
# Verify file was actually written
|
|
376
|
+
if not file_path.exists():
|
|
377
|
+
return mcp_result({
|
|
378
|
+
"success": False,
|
|
379
|
+
"error": f"File write appeared to succeed but file does not exist: {file_path}",
|
|
380
|
+
})
|
|
381
|
+
|
|
382
|
+
# Load the plugin
|
|
383
|
+
try:
|
|
384
|
+
# description is required by input_schema, but the guard handles
|
|
385
|
+
# direct calls (e.g., from unit tests) that may pass ""
|
|
386
|
+
commit_msg = f"agent: {description}" if description else None
|
|
387
|
+
success = service.load_plugin_from_file(file_path, commit_msg=commit_msg)
|
|
388
|
+
if not success:
|
|
389
|
+
info = service.get_plugin_info(file_path)
|
|
390
|
+
error_msg = info.load_error if info and info.load_error else "Unknown load error"
|
|
391
|
+
return mcp_result({
|
|
392
|
+
"success": False,
|
|
393
|
+
"error": f"Plugin file written but failed to load: {error_msg}",
|
|
394
|
+
"path": str(file_path),
|
|
395
|
+
})
|
|
396
|
+
except Exception as e:
|
|
397
|
+
logger.warning("Plugin file written but failed to load: {}", e)
|
|
398
|
+
return mcp_result({
|
|
399
|
+
"success": False,
|
|
400
|
+
"error": f"Plugin file written but failed to load: {e}",
|
|
401
|
+
"path": str(file_path),
|
|
402
|
+
})
|
|
403
|
+
|
|
404
|
+
logger.info(
|
|
405
|
+
"Created user plugin '{}': {} (overwrite={})",
|
|
406
|
+
name,
|
|
407
|
+
description,
|
|
408
|
+
overwrite,
|
|
409
|
+
)
|
|
410
|
+
|
|
411
|
+
return mcp_result({
|
|
412
|
+
"success": True,
|
|
413
|
+
"message": f"Plugin '{name}' created successfully (kinds: {', '.join(sorted(set(kinds)))})",
|
|
414
|
+
"path": str(file_path),
|
|
415
|
+
"description": description,
|
|
416
|
+
})
|
|
417
|
+
|
|
418
|
+
@tool(
|
|
419
|
+
name="lightfall_create_temp_plugin",
|
|
420
|
+
description="""Create a temporary plugin that won't persist across restarts.
|
|
421
|
+
|
|
422
|
+
Useful for quick prototyping. The plugin is loaded immediately but will
|
|
423
|
+
be lost when the application exits.
|
|
424
|
+
|
|
425
|
+
The kind of plugin is determined by the class hierarchy in `code`:
|
|
426
|
+
- Subclass `AgentPlugin` for agent extensions (skill prompts + MCP tools)
|
|
427
|
+
- Subclass `PanelPlugin` for dock panels
|
|
428
|
+
|
|
429
|
+
Returns success status, temporary file path, and the discovered plugin kind(s).
|
|
430
|
+
|
|
431
|
+
IMPORTANT: Use the same imports and patterns as lightfall_create_user_plugin.
|
|
432
|
+
See that tool's description for the required template.""",
|
|
433
|
+
input_schema={
|
|
434
|
+
"type": "object",
|
|
435
|
+
"properties": {
|
|
436
|
+
"name": {
|
|
437
|
+
"type": "string",
|
|
438
|
+
"description": "Plugin name (becomes filename)",
|
|
439
|
+
},
|
|
440
|
+
"code": {
|
|
441
|
+
"type": "string",
|
|
442
|
+
"description": "Complete Python source code for the plugin. The class hierarchy determines the plugin kind.",
|
|
443
|
+
},
|
|
444
|
+
},
|
|
445
|
+
"required": ["name", "code"],
|
|
446
|
+
},
|
|
447
|
+
)
|
|
448
|
+
async def create_temp_plugin(args: dict) -> dict[str, Any]:
|
|
449
|
+
"""Create a temporary plugin."""
|
|
450
|
+
from lightfall.plugins.user_plugins import UserPluginService
|
|
451
|
+
|
|
452
|
+
name = args["name"]
|
|
453
|
+
code = args["code"]
|
|
454
|
+
|
|
455
|
+
# Validate name
|
|
456
|
+
if not re.match(r"^[a-zA-Z_][a-zA-Z0-9_]*$", name):
|
|
457
|
+
return mcp_result({
|
|
458
|
+
"success": False,
|
|
459
|
+
"error": "Invalid plugin name",
|
|
460
|
+
})
|
|
461
|
+
|
|
462
|
+
# Validate code
|
|
463
|
+
is_valid, error, kinds = self._validate_plugin_code(code, name)
|
|
464
|
+
if not is_valid:
|
|
465
|
+
return mcp_result({
|
|
466
|
+
"success": False,
|
|
467
|
+
"error": error,
|
|
468
|
+
})
|
|
469
|
+
|
|
470
|
+
try:
|
|
471
|
+
service = UserPluginService.get_instance()
|
|
472
|
+
file_path = service.create_temp_plugin(name, code)
|
|
473
|
+
|
|
474
|
+
return mcp_result({
|
|
475
|
+
"success": True,
|
|
476
|
+
"message": f"Temporary plugin '{name}' created (kinds: {', '.join(sorted(set(kinds)))})",
|
|
477
|
+
"path": str(file_path),
|
|
478
|
+
"is_temporary": True,
|
|
479
|
+
})
|
|
480
|
+
except Exception as e:
|
|
481
|
+
logger.error("Failed to create temp plugin: {}", e)
|
|
482
|
+
return mcp_result({
|
|
483
|
+
"success": False,
|
|
484
|
+
"error": str(e),
|
|
485
|
+
})
|
|
486
|
+
|
|
487
|
+
@tool(
|
|
488
|
+
name="lightfall_list_user_plugins",
|
|
489
|
+
description="""List all user plugins with their status.
|
|
490
|
+
|
|
491
|
+
Returns information about each loaded plugin including:
|
|
492
|
+
- File path
|
|
493
|
+
- Registration status (what it registered)
|
|
494
|
+
- Any load errors
|
|
495
|
+
- Whether it's temporary""",
|
|
496
|
+
input_schema={
|
|
497
|
+
"type": "object",
|
|
498
|
+
"properties": {},
|
|
499
|
+
},
|
|
500
|
+
)
|
|
501
|
+
async def list_user_plugins(args: dict) -> dict[str, Any]:
|
|
502
|
+
"""List all user plugins."""
|
|
503
|
+
from lightfall.plugins.user_plugins import UserPluginService
|
|
504
|
+
|
|
505
|
+
try:
|
|
506
|
+
service = UserPluginService.get_instance()
|
|
507
|
+
data = service.get_introspection_data()
|
|
508
|
+
|
|
509
|
+
return mcp_result({
|
|
510
|
+
"success": True,
|
|
511
|
+
"plugins_dir": data["plugins_dir"],
|
|
512
|
+
"hot_reload_enabled": data["hot_reload_enabled"],
|
|
513
|
+
"plugins": data["plugins"],
|
|
514
|
+
"total_count": data["loaded_plugin_count"],
|
|
515
|
+
"temp_count": data["temp_plugin_count"],
|
|
516
|
+
})
|
|
517
|
+
except Exception as e:
|
|
518
|
+
logger.error("Failed to list user plugins: {}", e)
|
|
519
|
+
return mcp_result({
|
|
520
|
+
"success": False,
|
|
521
|
+
"error": str(e),
|
|
522
|
+
})
|
|
523
|
+
|
|
524
|
+
@tool(
|
|
525
|
+
name="lightfall_reload_plugin",
|
|
526
|
+
description="""Force reload a user plugin after external edits.
|
|
527
|
+
|
|
528
|
+
Unloads the plugin (unregistering all its components) and reloads it
|
|
529
|
+
from disk. Use this after editing a plugin file externally.
|
|
530
|
+
|
|
531
|
+
Note: Hot-reload may cause instability if panel instances are still open.""",
|
|
532
|
+
input_schema={
|
|
533
|
+
"type": "object",
|
|
534
|
+
"properties": {
|
|
535
|
+
"name": {
|
|
536
|
+
"type": "string",
|
|
537
|
+
"description": "Plugin name (filename without .py extension)",
|
|
538
|
+
},
|
|
539
|
+
},
|
|
540
|
+
"required": ["name"],
|
|
541
|
+
},
|
|
542
|
+
)
|
|
543
|
+
async def reload_plugin(args: dict) -> dict[str, Any]:
|
|
544
|
+
"""Reload a user plugin."""
|
|
545
|
+
from lightfall.plugins.user_plugins import UserPluginService
|
|
546
|
+
|
|
547
|
+
name = args["name"]
|
|
548
|
+
|
|
549
|
+
try:
|
|
550
|
+
service = UserPluginService.get_instance()
|
|
551
|
+
plugins_dir = service.get_plugins_directory()
|
|
552
|
+
file_path = plugins_dir / f"{name}.py"
|
|
553
|
+
|
|
554
|
+
if not file_path.exists():
|
|
555
|
+
return mcp_result({
|
|
556
|
+
"success": False,
|
|
557
|
+
"error": f"Plugin file not found: {file_path}",
|
|
558
|
+
})
|
|
559
|
+
|
|
560
|
+
success = service.reload_plugin(file_path)
|
|
561
|
+
|
|
562
|
+
if success:
|
|
563
|
+
return mcp_result({
|
|
564
|
+
"success": True,
|
|
565
|
+
"message": f"Plugin '{name}' reloaded successfully",
|
|
566
|
+
"path": str(file_path),
|
|
567
|
+
})
|
|
568
|
+
else:
|
|
569
|
+
info = service.get_plugin_info(file_path)
|
|
570
|
+
error = info.load_error if info else "Unknown error"
|
|
571
|
+
return mcp_result({
|
|
572
|
+
"success": False,
|
|
573
|
+
"error": f"Failed to reload: {error}",
|
|
574
|
+
})
|
|
575
|
+
except Exception as e:
|
|
576
|
+
logger.error("Failed to reload plugin: {}", e)
|
|
577
|
+
return mcp_result({
|
|
578
|
+
"success": False,
|
|
579
|
+
"error": str(e),
|
|
580
|
+
})
|
|
581
|
+
|
|
582
|
+
@tool(
|
|
583
|
+
name="lightfall_unload_plugin",
|
|
584
|
+
description="""Unload a user plugin from the registry.
|
|
585
|
+
|
|
586
|
+
Removes the plugin's registrations (panels, skills, tools) without
|
|
587
|
+
deleting the file. The plugin won't be active until reloaded.
|
|
588
|
+
|
|
589
|
+
Note: Open panel instances may become unstable.""",
|
|
590
|
+
input_schema={
|
|
591
|
+
"type": "object",
|
|
592
|
+
"properties": {
|
|
593
|
+
"name": {
|
|
594
|
+
"type": "string",
|
|
595
|
+
"description": "Plugin name (filename without .py extension)",
|
|
596
|
+
},
|
|
597
|
+
},
|
|
598
|
+
"required": ["name"],
|
|
599
|
+
},
|
|
600
|
+
)
|
|
601
|
+
async def unload_plugin(args: dict) -> dict[str, Any]:
|
|
602
|
+
"""Unload a user plugin."""
|
|
603
|
+
from lightfall.plugins.user_plugins import UserPluginService
|
|
604
|
+
|
|
605
|
+
name = args["name"]
|
|
606
|
+
|
|
607
|
+
try:
|
|
608
|
+
service = UserPluginService.get_instance()
|
|
609
|
+
plugins_dir = service.get_plugins_directory()
|
|
610
|
+
file_path = plugins_dir / f"{name}.py"
|
|
611
|
+
|
|
612
|
+
success = service.unload_plugin(file_path)
|
|
613
|
+
|
|
614
|
+
if success:
|
|
615
|
+
return mcp_result({
|
|
616
|
+
"success": True,
|
|
617
|
+
"message": f"Plugin '{name}' unloaded",
|
|
618
|
+
})
|
|
619
|
+
else:
|
|
620
|
+
return mcp_result({
|
|
621
|
+
"success": False,
|
|
622
|
+
"error": f"Plugin '{name}' was not loaded",
|
|
623
|
+
})
|
|
624
|
+
except Exception as e:
|
|
625
|
+
logger.error("Failed to unload plugin: {}", e)
|
|
626
|
+
return mcp_result({
|
|
627
|
+
"success": False,
|
|
628
|
+
"error": str(e),
|
|
629
|
+
})
|
|
630
|
+
|
|
631
|
+
return [
|
|
632
|
+
create_user_plugin,
|
|
633
|
+
create_temp_plugin,
|
|
634
|
+
list_user_plugins,
|
|
635
|
+
reload_plugin,
|
|
636
|
+
unload_plugin,
|
|
637
|
+
]
|