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,627 @@
|
|
|
1
|
+
"""Fragment-based logbook panel for Lightfall.
|
|
2
|
+
|
|
3
|
+
Split-pane layout: entry list (sidebar) + EntryWidget (fragment view),
|
|
4
|
+
backed by the offline-first ``LogbookClient`` (synchronous SQLite).
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import getpass
|
|
10
|
+
import json
|
|
11
|
+
from datetime import datetime
|
|
12
|
+
from typing import Any, ClassVar
|
|
13
|
+
|
|
14
|
+
from PySide6.QtCore import QEvent, QTimer, Signal, Slot
|
|
15
|
+
from PySide6.QtGui import QKeyEvent, QKeySequence
|
|
16
|
+
from PySide6.QtWidgets import (
|
|
17
|
+
QApplication,
|
|
18
|
+
QFileDialog,
|
|
19
|
+
QFrame,
|
|
20
|
+
QHBoxLayout,
|
|
21
|
+
QLabel,
|
|
22
|
+
QPushButton,
|
|
23
|
+
QWidget,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
from lightfall.logbook.client import LogbookClient
|
|
27
|
+
from lightfall.logbook.entry_widget import EntryData, EntryWidget
|
|
28
|
+
from lightfall.logbook.fragment_widgets import FragmentData, FragmentType
|
|
29
|
+
from lightfall.ui.panels.base import BasePanel, PanelMetadata
|
|
30
|
+
from lightfall.utils.logging import logger
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class LogbookPanel(BasePanel):
|
|
34
|
+
"""Panel displaying the fragment-based logbook.
|
|
35
|
+
|
|
36
|
+
Layout::
|
|
37
|
+
|
|
38
|
+
┌──────────┬──────────────────────┐
|
|
39
|
+
│ Entry │ │
|
|
40
|
+
│ List │ EntryWidget │
|
|
41
|
+
│ (sidebar)│ (fragment view) │
|
|
42
|
+
│ │ │
|
|
43
|
+
└──────────┴──────────────────────┘
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
panel_metadata: ClassVar[PanelMetadata] = PanelMetadata(
|
|
47
|
+
id="lightfall.panels.logbook",
|
|
48
|
+
name="Logbook",
|
|
49
|
+
description="Experiment logbook for recording notes and viewing system events",
|
|
50
|
+
icon="book-open",
|
|
51
|
+
category="Core",
|
|
52
|
+
required_permission=None,
|
|
53
|
+
singleton=True,
|
|
54
|
+
closable=False,
|
|
55
|
+
keywords=["log", "notes", "experiment", "journal", "record"],
|
|
56
|
+
default_area="center",
|
|
57
|
+
sidebar_group="top",
|
|
58
|
+
auto_hide=False,
|
|
59
|
+
sidebar_order=0,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
note_added = Signal(str)
|
|
63
|
+
|
|
64
|
+
def __init__(self, parent: QWidget | None = None) -> None:
|
|
65
|
+
self._client: LogbookClient | None = None
|
|
66
|
+
self._logbook_id: str | None = None
|
|
67
|
+
self._current_entry_id: str | None = None
|
|
68
|
+
self._entries: dict[str, EntryData] = {}
|
|
69
|
+
super().__init__(parent)
|
|
70
|
+
|
|
71
|
+
# Deferred init (after widget is shown)
|
|
72
|
+
QTimer.singleShot(0, self._deferred_init)
|
|
73
|
+
|
|
74
|
+
def _setup_ui(self) -> None:
|
|
75
|
+
self._entry_widget = EntryWidget(EntryData())
|
|
76
|
+
self._entries_panel = None # Resolved in _deferred_init
|
|
77
|
+
|
|
78
|
+
# Warning banner (guest mode / connection issues)
|
|
79
|
+
self._warning_banner = QFrame(self)
|
|
80
|
+
self._warning_banner.setObjectName("logbookWarningBanner")
|
|
81
|
+
self._warning_banner.setStyleSheet(
|
|
82
|
+
"#logbookWarningBanner {"
|
|
83
|
+
" border: 1px solid #ffc107; border-radius: 4px;"
|
|
84
|
+
" padding: 2px 8px;"
|
|
85
|
+
"}"
|
|
86
|
+
)
|
|
87
|
+
self._warning_banner.setFixedHeight(28)
|
|
88
|
+
banner_layout = QHBoxLayout(self._warning_banner)
|
|
89
|
+
banner_layout.setContentsMargins(8, 2, 8, 2)
|
|
90
|
+
self._warning_label = QLabel()
|
|
91
|
+
self._warning_label.setStyleSheet("background: transparent; border: none;")
|
|
92
|
+
banner_layout.addWidget(self._warning_label)
|
|
93
|
+
self._warning_banner.hide()
|
|
94
|
+
self._layout.addWidget(self._warning_banner)
|
|
95
|
+
self._is_guest = False
|
|
96
|
+
self._is_disconnected = False
|
|
97
|
+
|
|
98
|
+
# Image button toolbar
|
|
99
|
+
try:
|
|
100
|
+
import qtawesome as qta
|
|
101
|
+
self._add_image_btn = QPushButton()
|
|
102
|
+
self._add_image_btn.setIcon(qta.icon("fa5s.image", color="#aaa"))
|
|
103
|
+
self._add_image_btn.setToolTip("Add image to entry")
|
|
104
|
+
self._add_image_btn.setFixedSize(28, 28)
|
|
105
|
+
self._add_image_btn.clicked.connect(self._on_add_image_clicked)
|
|
106
|
+
self._layout.addWidget(self._add_image_btn)
|
|
107
|
+
except ImportError:
|
|
108
|
+
logger.debug("qtawesome not available, skipping image button")
|
|
109
|
+
|
|
110
|
+
self._layout.addWidget(self._entry_widget)
|
|
111
|
+
|
|
112
|
+
# Install event filter on QApplication to catch Ctrl+V with image data
|
|
113
|
+
# (child widgets consume key events before parent event filters see them)
|
|
114
|
+
QApplication.instance().installEventFilter(self)
|
|
115
|
+
|
|
116
|
+
# Entry widget signals
|
|
117
|
+
self._entry_widget.fragment_added.connect(self._on_fragment_added)
|
|
118
|
+
self._entry_widget.fragment_changed.connect(self._on_fragment_changed)
|
|
119
|
+
self._entry_widget.fragment_deleted.connect(self._on_fragment_deleted)
|
|
120
|
+
self._entry_widget.fragment_reordered.connect(self._on_fragment_reordered)
|
|
121
|
+
self._entry_widget.claude_requested.connect(self._on_claude_requested)
|
|
122
|
+
self._entry_widget.title_changed.connect(self._on_title_changed)
|
|
123
|
+
self._entry_widget.tags_changed.connect(self._on_tags_changed)
|
|
124
|
+
|
|
125
|
+
# ── Init ──────────────────────────────────────────────────────
|
|
126
|
+
|
|
127
|
+
def _deferred_init(self) -> None:
|
|
128
|
+
try:
|
|
129
|
+
self._client = LogbookClient.get_instance()
|
|
130
|
+
self._client.init()
|
|
131
|
+
|
|
132
|
+
user = getpass.getuser()
|
|
133
|
+
self._logbook_id = self._client.get_or_create_logbook(user)
|
|
134
|
+
|
|
135
|
+
# Connect to the LogbookEntriesPanel sidebar
|
|
136
|
+
self._connect_entries_panel()
|
|
137
|
+
|
|
138
|
+
# Show/hide guest warning based on current and future auth state
|
|
139
|
+
try:
|
|
140
|
+
from lightfall.auth.session import SessionManager
|
|
141
|
+
sm = SessionManager.get_instance()
|
|
142
|
+
self._update_guest_banner(sm.current_user)
|
|
143
|
+
sm.user_changed.connect(self._update_guest_banner)
|
|
144
|
+
except Exception:
|
|
145
|
+
pass
|
|
146
|
+
|
|
147
|
+
# Monitor sync connection status
|
|
148
|
+
self._client._on_sync_error_callback = lambda: self._set_disconnected(True)
|
|
149
|
+
self._client._on_sync_restored_callback = lambda: self._set_disconnected(False)
|
|
150
|
+
self._client.set_on_entry_created_callback(self._on_ipc_entry_created)
|
|
151
|
+
|
|
152
|
+
self._load_entries()
|
|
153
|
+
self._start_event_listener()
|
|
154
|
+
|
|
155
|
+
# Background sync after 10s
|
|
156
|
+
QTimer.singleShot(10_000, self._try_sync)
|
|
157
|
+
|
|
158
|
+
logger.info("LogbookPanel initialised (logbook={})", self._logbook_id)
|
|
159
|
+
except Exception as e:
|
|
160
|
+
logger.error("LogbookPanel init failed: {}", e)
|
|
161
|
+
|
|
162
|
+
def _connect_entries_panel(self) -> None:
|
|
163
|
+
"""Find and connect to the LogbookEntriesPanel sidebar."""
|
|
164
|
+
try:
|
|
165
|
+
from lightfall.ui.panels.registry import PanelRegistry
|
|
166
|
+
|
|
167
|
+
registry = PanelRegistry.get_instance()
|
|
168
|
+
panel = registry.create("lightfall.panels.logbook_entries")
|
|
169
|
+
if panel is not None:
|
|
170
|
+
self._entries_panel = panel
|
|
171
|
+
panel.entry_selected.connect(self._on_entry_selected)
|
|
172
|
+
panel.entry_delete_requested.connect(self._on_entry_deleted)
|
|
173
|
+
panel.new_entry_requested.connect(self._on_new_entry_requested)
|
|
174
|
+
logger.debug("Connected to LogbookEntriesPanel")
|
|
175
|
+
else:
|
|
176
|
+
logger.warning("LogbookEntriesPanel not found in registry")
|
|
177
|
+
except Exception as e:
|
|
178
|
+
logger.warning("Could not connect to LogbookEntriesPanel: {}", e)
|
|
179
|
+
|
|
180
|
+
def _update_guest_banner(self, user: Any) -> None:
|
|
181
|
+
"""Update guest state and refresh the warning banner."""
|
|
182
|
+
try:
|
|
183
|
+
from lightfall.auth.policy import Role
|
|
184
|
+
self._is_guest = user.highest_role == Role.GUEST
|
|
185
|
+
except Exception:
|
|
186
|
+
self._is_guest = True
|
|
187
|
+
self._update_warning_banner()
|
|
188
|
+
|
|
189
|
+
def _set_disconnected(self, disconnected: bool) -> None:
|
|
190
|
+
"""Update connection state and refresh the warning banner."""
|
|
191
|
+
self._is_disconnected = disconnected
|
|
192
|
+
self._update_warning_banner()
|
|
193
|
+
|
|
194
|
+
def _update_warning_banner(self) -> None:
|
|
195
|
+
"""Show/hide warning banner based on guest and connection state."""
|
|
196
|
+
if self._is_disconnected:
|
|
197
|
+
self._warning_label.setText(
|
|
198
|
+
"⚠️ Logbook server unreachable — changes may result in sync conflicts."
|
|
199
|
+
)
|
|
200
|
+
self._warning_banner.show()
|
|
201
|
+
elif self._is_guest:
|
|
202
|
+
self._warning_label.setText(
|
|
203
|
+
"⚠️ Guest mode — logbook changes may result in sync conflicts."
|
|
204
|
+
)
|
|
205
|
+
self._warning_banner.show()
|
|
206
|
+
else:
|
|
207
|
+
self._warning_banner.hide()
|
|
208
|
+
|
|
209
|
+
def _load_entries(self) -> None:
|
|
210
|
+
if not self._client or not self._logbook_id:
|
|
211
|
+
return
|
|
212
|
+
|
|
213
|
+
rows = self._client.list_entries(self._logbook_id)
|
|
214
|
+
entry_datas: list[EntryData] = []
|
|
215
|
+
for row in rows:
|
|
216
|
+
ed = self._row_to_entry_data(row)
|
|
217
|
+
self._entries[ed.id] = ed
|
|
218
|
+
entry_datas.append(ed)
|
|
219
|
+
|
|
220
|
+
if self._entries_panel:
|
|
221
|
+
self._entries_panel.set_entries(entry_datas)
|
|
222
|
+
|
|
223
|
+
if entry_datas:
|
|
224
|
+
first = entry_datas[0]
|
|
225
|
+
if self._entries_panel:
|
|
226
|
+
self._entries_panel.select_entry(first.id)
|
|
227
|
+
self._select_entry(first.id)
|
|
228
|
+
|
|
229
|
+
def _row_to_entry_data(self, row: dict[str, Any]) -> EntryData:
|
|
230
|
+
tags = row.get("tags", "[]")
|
|
231
|
+
if isinstance(tags, str):
|
|
232
|
+
try:
|
|
233
|
+
tags = json.loads(tags)
|
|
234
|
+
except (json.JSONDecodeError, TypeError):
|
|
235
|
+
tags = []
|
|
236
|
+
created = row.get("created_at", "")
|
|
237
|
+
if isinstance(created, str) and created:
|
|
238
|
+
try:
|
|
239
|
+
created_dt = datetime.fromisoformat(created)
|
|
240
|
+
except ValueError:
|
|
241
|
+
created_dt = datetime.now()
|
|
242
|
+
else:
|
|
243
|
+
created_dt = datetime.now()
|
|
244
|
+
return EntryData(
|
|
245
|
+
id=row["id"],
|
|
246
|
+
title=row.get("title") or "",
|
|
247
|
+
tags=tags,
|
|
248
|
+
created_at=created_dt,
|
|
249
|
+
updated_at=created_dt,
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
def _start_event_listener(self) -> None:
|
|
253
|
+
try:
|
|
254
|
+
from lightfall.logbook.event_listener import EventListener
|
|
255
|
+
listener = EventListener.get_instance()
|
|
256
|
+
listener.current_entry_id = self._current_entry_id
|
|
257
|
+
listener.fragment_injected.connect(self._on_fragment_injected)
|
|
258
|
+
listener.start()
|
|
259
|
+
except Exception as e:
|
|
260
|
+
logger.debug("Could not start event listener: {}", e)
|
|
261
|
+
|
|
262
|
+
# ── Entry selection ───────────────────────────────────────────
|
|
263
|
+
|
|
264
|
+
def _select_entry(self, entry_id: str) -> None:
|
|
265
|
+
if not self._client:
|
|
266
|
+
return
|
|
267
|
+
|
|
268
|
+
self._current_entry_id = entry_id
|
|
269
|
+
|
|
270
|
+
# Update event listener
|
|
271
|
+
try:
|
|
272
|
+
from lightfall.logbook.event_listener import EventListener
|
|
273
|
+
EventListener.get_instance().current_entry_id = entry_id
|
|
274
|
+
except Exception:
|
|
275
|
+
pass
|
|
276
|
+
|
|
277
|
+
# Load fragments
|
|
278
|
+
frag_rows = self._client.list_fragments(entry_id)
|
|
279
|
+
fragments: list[FragmentData] = []
|
|
280
|
+
for fr in frag_rows:
|
|
281
|
+
data_raw = fr.get("data")
|
|
282
|
+
if isinstance(data_raw, str):
|
|
283
|
+
try:
|
|
284
|
+
data_raw = json.loads(data_raw)
|
|
285
|
+
except (json.JSONDecodeError, TypeError):
|
|
286
|
+
data_raw = {}
|
|
287
|
+
kind = fr.get("kind", "text")
|
|
288
|
+
ftype_map = {"text": FragmentType.TEXT, "readonly": FragmentType.READONLY, "image": FragmentType.IMAGE}
|
|
289
|
+
ftype = ftype_map.get(kind, FragmentType.TEXT)
|
|
290
|
+
fragments.append(FragmentData(
|
|
291
|
+
id=fr["id"],
|
|
292
|
+
fragment_type=ftype,
|
|
293
|
+
content=fr.get("content", ""),
|
|
294
|
+
subtype=fr.get("subtype", ""),
|
|
295
|
+
metadata=data_raw or {},
|
|
296
|
+
))
|
|
297
|
+
|
|
298
|
+
entry_data = self._entries.get(entry_id, EntryData(id=entry_id))
|
|
299
|
+
entry_data.fragments = fragments
|
|
300
|
+
self._entry_widget.set_entry(entry_data)
|
|
301
|
+
|
|
302
|
+
# ── Slots ─────────────────────────────────────────────────────
|
|
303
|
+
|
|
304
|
+
@Slot(str)
|
|
305
|
+
def _on_entry_selected(self, entry_id: str) -> None:
|
|
306
|
+
self._select_entry(entry_id)
|
|
307
|
+
|
|
308
|
+
@Slot()
|
|
309
|
+
def _on_new_entry_requested(self) -> None:
|
|
310
|
+
if not self._client or not self._logbook_id:
|
|
311
|
+
return
|
|
312
|
+
try:
|
|
313
|
+
entry_id = self._client.create_entry(self._logbook_id, title="")
|
|
314
|
+
ed = EntryData(id=entry_id, title="")
|
|
315
|
+
self._entries[entry_id] = ed
|
|
316
|
+
if self._entries_panel:
|
|
317
|
+
self._entries_panel.add_entry(ed)
|
|
318
|
+
self._entries_panel.select_entry(entry_id)
|
|
319
|
+
self._select_entry(entry_id)
|
|
320
|
+
logger.info("Created new entry {}", entry_id)
|
|
321
|
+
except Exception as e:
|
|
322
|
+
logger.error("Failed to create entry: {}", e)
|
|
323
|
+
|
|
324
|
+
def _on_ipc_entry_created(self, entry_id: str, logbook_id: str) -> None:
|
|
325
|
+
"""Handle an entry created outside the panel (e.g. via IPC)."""
|
|
326
|
+
if entry_id in self._entries:
|
|
327
|
+
return # Already known (manual creation path)
|
|
328
|
+
row = self._client.get_entry(entry_id) if self._client else None
|
|
329
|
+
if not row:
|
|
330
|
+
return
|
|
331
|
+
ed = self._row_to_entry_data(row)
|
|
332
|
+
self._entries[entry_id] = ed
|
|
333
|
+
if self._entries_panel:
|
|
334
|
+
self._entries_panel.add_entry(ed)
|
|
335
|
+
|
|
336
|
+
@Slot(str, str)
|
|
337
|
+
def _on_fragment_added(self, entry_id: str, fragment_id: str) -> None:
|
|
338
|
+
if not self._client:
|
|
339
|
+
return
|
|
340
|
+
try:
|
|
341
|
+
self._client.add_fragment(entry_id, kind="text", fragment_id=fragment_id)
|
|
342
|
+
except Exception as e:
|
|
343
|
+
logger.error("Failed to persist fragment: {}", e)
|
|
344
|
+
|
|
345
|
+
@Slot(str, str, str)
|
|
346
|
+
def _on_fragment_changed(self, entry_id: str, fragment_id: str, content: str) -> None:
|
|
347
|
+
if not self._client:
|
|
348
|
+
return
|
|
349
|
+
try:
|
|
350
|
+
self._client.update_fragment(fragment_id, content=content)
|
|
351
|
+
except Exception as e:
|
|
352
|
+
logger.error("Failed to update fragment: {}", e)
|
|
353
|
+
|
|
354
|
+
@Slot(str)
|
|
355
|
+
def _on_fragment_injected(self, entry_id: str) -> None:
|
|
356
|
+
"""Refresh the entry view when the EventListener injects a fragment."""
|
|
357
|
+
if entry_id == self._current_entry_id:
|
|
358
|
+
self._select_entry(entry_id)
|
|
359
|
+
|
|
360
|
+
@Slot(str, str)
|
|
361
|
+
def _on_title_changed(self, entry_id: str, new_title: str) -> None:
|
|
362
|
+
if not self._client:
|
|
363
|
+
return
|
|
364
|
+
if entry_id in self._entries:
|
|
365
|
+
self._entries[entry_id].title = new_title
|
|
366
|
+
try:
|
|
367
|
+
self._client.update_entry(entry_id, title=new_title)
|
|
368
|
+
except Exception as e:
|
|
369
|
+
logger.error("Failed to update title: {}", e)
|
|
370
|
+
if self._entries_panel:
|
|
371
|
+
self._entries_panel.set_entries(list(self._entries.values()))
|
|
372
|
+
|
|
373
|
+
@Slot(str, list)
|
|
374
|
+
def _on_tags_changed(self, entry_id: str, tags: list[str]) -> None:
|
|
375
|
+
if not self._client:
|
|
376
|
+
return
|
|
377
|
+
if entry_id in self._entries:
|
|
378
|
+
self._entries[entry_id].tags = tags
|
|
379
|
+
try:
|
|
380
|
+
self._client.update_entry(entry_id, tags=tags)
|
|
381
|
+
except Exception as e:
|
|
382
|
+
logger.error("Failed to update tags: {}", e)
|
|
383
|
+
if self._entries_panel:
|
|
384
|
+
self._entries_panel.set_entries(list(self._entries.values()))
|
|
385
|
+
|
|
386
|
+
@Slot(str)
|
|
387
|
+
def _on_entry_deleted(self, entry_id: str) -> None:
|
|
388
|
+
if not self._client:
|
|
389
|
+
return
|
|
390
|
+
try:
|
|
391
|
+
self._client.delete_entry(entry_id)
|
|
392
|
+
self._entries.pop(entry_id, None)
|
|
393
|
+
logger.info("Deleted entry {}", entry_id)
|
|
394
|
+
# If we deleted the current entry, select another
|
|
395
|
+
if self._current_entry_id == entry_id:
|
|
396
|
+
if self._entries:
|
|
397
|
+
next_id = next(iter(self._entries))
|
|
398
|
+
self._select_entry(next_id)
|
|
399
|
+
if self._entries_panel:
|
|
400
|
+
self._entries_panel.select_entry(next_id)
|
|
401
|
+
else:
|
|
402
|
+
self._current_entry_id = None
|
|
403
|
+
self._entry_widget.set_entry(EntryData())
|
|
404
|
+
except Exception as e:
|
|
405
|
+
logger.error("Failed to delete entry: {}", e)
|
|
406
|
+
|
|
407
|
+
@Slot(str, list)
|
|
408
|
+
def _on_fragment_reordered(self, entry_id: str, fragment_ids: list[str]) -> None:
|
|
409
|
+
if not self._client:
|
|
410
|
+
return
|
|
411
|
+
try:
|
|
412
|
+
self._client.reorder_fragments(entry_id, fragment_ids)
|
|
413
|
+
except Exception as e:
|
|
414
|
+
logger.error("Failed to reorder fragments: {}", e)
|
|
415
|
+
|
|
416
|
+
@Slot(str, str)
|
|
417
|
+
def _on_fragment_deleted(self, entry_id: str, fragment_id: str) -> None:
|
|
418
|
+
if not self._client:
|
|
419
|
+
return
|
|
420
|
+
try:
|
|
421
|
+
self._client.delete_fragment(fragment_id)
|
|
422
|
+
logger.info("Deleted fragment {} from entry {}", fragment_id, entry_id)
|
|
423
|
+
except Exception as e:
|
|
424
|
+
logger.error("Failed to delete fragment: {}", e)
|
|
425
|
+
|
|
426
|
+
@Slot(str, str)
|
|
427
|
+
def _on_claude_requested(self, entry_id: str, fragment_id: str) -> None:
|
|
428
|
+
"""Send a fragment's content to Claude and append the response."""
|
|
429
|
+
# Find the fragment content
|
|
430
|
+
entry = self._entries.get(entry_id)
|
|
431
|
+
if not entry:
|
|
432
|
+
return
|
|
433
|
+
frag = next((f for f in entry.fragments if f.id == fragment_id), None)
|
|
434
|
+
if not frag:
|
|
435
|
+
return
|
|
436
|
+
|
|
437
|
+
# Build the prompt from fragment content
|
|
438
|
+
content = frag.content or json.dumps(frag.metadata, indent=2, default=str)
|
|
439
|
+
prompt = (
|
|
440
|
+
f"{content}"
|
|
441
|
+
)
|
|
442
|
+
|
|
443
|
+
# Try to send to the Claude panel
|
|
444
|
+
try:
|
|
445
|
+
self._send_to_claude(entry_id, prompt)
|
|
446
|
+
except Exception as e:
|
|
447
|
+
logger.error("Failed to send to Claude: {}", e)
|
|
448
|
+
|
|
449
|
+
def _get_claude_panel(self):
|
|
450
|
+
"""Find or open the Claude panel. Returns (panel, agent) or (None, None)."""
|
|
451
|
+
try:
|
|
452
|
+
from lightfall.ui.panels.registry import PanelRegistry
|
|
453
|
+
|
|
454
|
+
registry = PanelRegistry.get_instance()
|
|
455
|
+
panel = registry.create("lightfall.panels.claude")
|
|
456
|
+
|
|
457
|
+
if panel and getattr(panel, "_claude_widget", None) and hasattr(panel._claude_widget, "agent"):
|
|
458
|
+
return panel, panel._claude_widget.agent
|
|
459
|
+
except Exception as e:
|
|
460
|
+
logger.error("Could not get Claude panel: {}", e)
|
|
461
|
+
return None, None
|
|
462
|
+
|
|
463
|
+
def _send_to_claude(self, entry_id: str, prompt: str) -> None:
|
|
464
|
+
"""Send prompt to Claude and collect the response into a fragment."""
|
|
465
|
+
panel, agent = self._get_claude_panel()
|
|
466
|
+
if not agent:
|
|
467
|
+
logger.warning("Claude panel/agent not available")
|
|
468
|
+
return
|
|
469
|
+
|
|
470
|
+
if agent.is_busy():
|
|
471
|
+
logger.warning("Claude is busy, cannot send logbook request")
|
|
472
|
+
return
|
|
473
|
+
|
|
474
|
+
# Track pending response
|
|
475
|
+
self._pending_claude_entry = entry_id
|
|
476
|
+
self._pending_claude_messages: list[str] = []
|
|
477
|
+
|
|
478
|
+
# Connect to agent signals
|
|
479
|
+
agent.message_received.connect(self._on_claude_message)
|
|
480
|
+
agent.query_completed.connect(self._on_claude_complete)
|
|
481
|
+
|
|
482
|
+
# Send via the widget (shows in chat UI too)
|
|
483
|
+
panel.action_send_message(prompt)
|
|
484
|
+
logger.info("Sent logbook fragment to Claude for entry {}", entry_id)
|
|
485
|
+
|
|
486
|
+
@Slot(str)
|
|
487
|
+
def _on_claude_message(self, message: str) -> None:
|
|
488
|
+
"""Collect Claude message chunks."""
|
|
489
|
+
if hasattr(self, "_pending_claude_messages"):
|
|
490
|
+
self._pending_claude_messages.append(message)
|
|
491
|
+
|
|
492
|
+
@Slot()
|
|
493
|
+
def _on_claude_complete(self) -> None:
|
|
494
|
+
"""Claude finished responding — inject the response as a fragment."""
|
|
495
|
+
entry_id = getattr(self, "_pending_claude_entry", None)
|
|
496
|
+
messages = getattr(self, "_pending_claude_messages", [])
|
|
497
|
+
|
|
498
|
+
# Disconnect signals
|
|
499
|
+
try:
|
|
500
|
+
_, agent = self._get_claude_panel()
|
|
501
|
+
if agent:
|
|
502
|
+
agent.message_received.disconnect(self._on_claude_message)
|
|
503
|
+
agent.query_completed.disconnect(self._on_claude_complete)
|
|
504
|
+
except (RuntimeError, TypeError):
|
|
505
|
+
pass
|
|
506
|
+
|
|
507
|
+
if not entry_id or not messages or not self._client:
|
|
508
|
+
self._pending_claude_entry = None
|
|
509
|
+
self._pending_claude_messages = []
|
|
510
|
+
return
|
|
511
|
+
|
|
512
|
+
response_text = "\n\n".join(messages)
|
|
513
|
+
|
|
514
|
+
try:
|
|
515
|
+
frag_id = self._client.add_fragment(
|
|
516
|
+
entry_id,
|
|
517
|
+
kind="readonly",
|
|
518
|
+
subtype="claude_response",
|
|
519
|
+
content=response_text,
|
|
520
|
+
)
|
|
521
|
+
logger.info("Injected Claude response fragment {} into entry {}", frag_id, entry_id)
|
|
522
|
+
# Refresh the view
|
|
523
|
+
if entry_id == self._current_entry_id:
|
|
524
|
+
self._select_entry(entry_id)
|
|
525
|
+
except Exception as e:
|
|
526
|
+
logger.error("Failed to inject Claude response: {}", e)
|
|
527
|
+
finally:
|
|
528
|
+
self._pending_claude_entry = None
|
|
529
|
+
self._pending_claude_messages = []
|
|
530
|
+
|
|
531
|
+
# ── Image support ──────────────────────────────────────────────
|
|
532
|
+
|
|
533
|
+
@Slot()
|
|
534
|
+
def _on_add_image_clicked(self) -> None:
|
|
535
|
+
"""Open file dialog, add selected image as a fragment."""
|
|
536
|
+
if not self._current_entry_id or not self._client:
|
|
537
|
+
return
|
|
538
|
+
|
|
539
|
+
path, _ = QFileDialog.getOpenFileName(
|
|
540
|
+
self,
|
|
541
|
+
"Select Image",
|
|
542
|
+
"",
|
|
543
|
+
"Images (*.png *.jpg *.jpeg *.gif);;All Files (*)",
|
|
544
|
+
)
|
|
545
|
+
if not path:
|
|
546
|
+
return
|
|
547
|
+
|
|
548
|
+
from pathlib import Path as P
|
|
549
|
+
file_path = P(path)
|
|
550
|
+
if file_path.stat().st_size > 20 * 1024 * 1024:
|
|
551
|
+
logger.warning("Image too large: {}", file_path)
|
|
552
|
+
return
|
|
553
|
+
|
|
554
|
+
try:
|
|
555
|
+
self._client.add_image(
|
|
556
|
+
image=path,
|
|
557
|
+
caption="",
|
|
558
|
+
subtype="clipboard",
|
|
559
|
+
entry_id=self._current_entry_id,
|
|
560
|
+
)
|
|
561
|
+
self._select_entry(self._current_entry_id)
|
|
562
|
+
except Exception as e:
|
|
563
|
+
logger.error("Failed to add image: {}", e)
|
|
564
|
+
|
|
565
|
+
def eventFilter(self, obj, event) -> bool:
|
|
566
|
+
"""Intercept Ctrl+V when clipboard has an image and focus is in the entry widget."""
|
|
567
|
+
if (
|
|
568
|
+
isinstance(event, QKeyEvent)
|
|
569
|
+
and event.type() == QEvent.Type.KeyPress
|
|
570
|
+
and event.matches(QKeySequence.StandardKey.Paste)
|
|
571
|
+
):
|
|
572
|
+
# Check if focused widget is inside our entry widget
|
|
573
|
+
focus = QApplication.focusWidget()
|
|
574
|
+
if focus is not None and self._entry_widget.isAncestorOf(focus):
|
|
575
|
+
clipboard = QApplication.clipboard()
|
|
576
|
+
mime = clipboard.mimeData()
|
|
577
|
+
if mime and mime.hasImage():
|
|
578
|
+
self._paste_image_from_clipboard()
|
|
579
|
+
return True
|
|
580
|
+
return super().eventFilter(obj, event)
|
|
581
|
+
|
|
582
|
+
def _paste_image_from_clipboard(self) -> None:
|
|
583
|
+
"""Grab image from clipboard, add as fragment."""
|
|
584
|
+
if not self._current_entry_id or not self._client:
|
|
585
|
+
return
|
|
586
|
+
|
|
587
|
+
clipboard = QApplication.clipboard()
|
|
588
|
+
qimage = clipboard.image()
|
|
589
|
+
if qimage.isNull():
|
|
590
|
+
return
|
|
591
|
+
|
|
592
|
+
try:
|
|
593
|
+
self._client.add_image(
|
|
594
|
+
image=qimage,
|
|
595
|
+
caption="",
|
|
596
|
+
subtype="clipboard",
|
|
597
|
+
entry_id=self._current_entry_id,
|
|
598
|
+
)
|
|
599
|
+
self._select_entry(self._current_entry_id)
|
|
600
|
+
except Exception as e:
|
|
601
|
+
logger.error("Failed to paste image: {}", e)
|
|
602
|
+
|
|
603
|
+
def _try_sync(self) -> None:
|
|
604
|
+
if self._client:
|
|
605
|
+
self._client.schedule_sync()
|
|
606
|
+
|
|
607
|
+
# ── Introspection ─────────────────────────────────────────────
|
|
608
|
+
|
|
609
|
+
def _get_specific_introspection_data(self) -> dict[str, Any]:
|
|
610
|
+
return {
|
|
611
|
+
"logbook_id": self._logbook_id,
|
|
612
|
+
"current_entry_id": self._current_entry_id,
|
|
613
|
+
"entry_count": len(self._entries),
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
def _get_available_actions(self) -> list[dict[str, Any]]:
|
|
617
|
+
actions = super()._get_available_actions()
|
|
618
|
+
actions.append({
|
|
619
|
+
"name": "new_entry",
|
|
620
|
+
"description": "Create a new logbook entry",
|
|
621
|
+
"method": "action_new_entry",
|
|
622
|
+
})
|
|
623
|
+
return actions
|
|
624
|
+
|
|
625
|
+
def action_new_entry(self) -> bool:
|
|
626
|
+
self._on_new_entry_requested()
|
|
627
|
+
return True
|