talkops-opscloud 0.3.0b1__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.
- opscloud/__init__.py +5 -0
- opscloud/__main__.py +6 -0
- opscloud/_constants.py +53 -0
- opscloud/_debug.py +145 -0
- opscloud/_debug_buffer.py +250 -0
- opscloud/_textual_patches.py +367 -0
- opscloud/_version.py +15 -0
- opscloud/agent/__init__.py +27 -0
- opscloud/agent/config.py +168 -0
- opscloud/agent/factory.py +1103 -0
- opscloud/approval_mode.py +44 -0
- opscloud/backend/__init__.py +49 -0
- opscloud/backend/composite.py +89 -0
- opscloud/backend/local.py +183 -0
- opscloud/backend/registry.py +79 -0
- opscloud/backend/sandbox_config.py +107 -0
- opscloud/backend/sandbox_factory.py +432 -0
- opscloud/built_in_skills/remember/SKILL.md +124 -0
- opscloud/built_in_skills/skill-creator/SKILL.md +348 -0
- opscloud/built_in_skills/skill-creator/scripts/init_skill.py +371 -0
- opscloud/built_in_skills/skill-creator/scripts/quick_validate.py +165 -0
- opscloud/cli/__init__.py +1 -0
- opscloud/cli/commands/__init__.py +15 -0
- opscloud/cli/commands/auth.py +45 -0
- opscloud/cli/commands/doctor.py +100 -0
- opscloud/cli/commands/mcp.py +137 -0
- opscloud/cli/commands/threads.py +51 -0
- opscloud/cli/interactive.py +154 -0
- opscloud/cli/main.py +903 -0
- opscloud/cli/non_interactive.py +425 -0
- opscloud/cli/server_manager.py +58 -0
- opscloud/commands/__init__.py +19 -0
- opscloud/commands/_base.py +110 -0
- opscloud/commands/_guards.py +52 -0
- opscloud/commands/_router.py +146 -0
- opscloud/commands/_types.py +36 -0
- opscloud/commands/core/__init__.py +47 -0
- opscloud/commands/core/auth.py +94 -0
- opscloud/commands/core/bug.py +46 -0
- opscloud/commands/core/clear.py +106 -0
- opscloud/commands/core/cloud.py +185 -0
- opscloud/commands/core/compact.py +128 -0
- opscloud/commands/core/config_cmd.py +120 -0
- opscloud/commands/core/context.py +220 -0
- opscloud/commands/core/cost.py +44 -0
- opscloud/commands/core/doctor.py +535 -0
- opscloud/commands/core/effort.py +108 -0
- opscloud/commands/core/exit_cmd.py +41 -0
- opscloud/commands/core/fast.py +148 -0
- opscloud/commands/core/help_cmd.py +94 -0
- opscloud/commands/core/mcp.py +134 -0
- opscloud/commands/core/model.py +109 -0
- opscloud/commands/core/permissions.py +196 -0
- opscloud/commands/core/plugins.py +92 -0
- opscloud/commands/core/pool.py +108 -0
- opscloud/commands/core/resume.py +97 -0
- opscloud/commands/core/skills.py +178 -0
- opscloud/commands/power/__init__.py +51 -0
- opscloud/commands/power/agents.py +98 -0
- opscloud/commands/power/btw.py +85 -0
- opscloud/commands/power/copy.py +97 -0
- opscloud/commands/power/goal.py +548 -0
- opscloud/commands/power/loop.py +295 -0
- opscloud/commands/power/memory.py +287 -0
- opscloud/commands/power/review.py +152 -0
- opscloud/commands/power/rubric.py +287 -0
- opscloud/commands/power/runtime.py +321 -0
- opscloud/commands/power/skill_creator.py +70 -0
- opscloud/commands/power/skill_invoke.py +165 -0
- opscloud/commands/power/tasks.py +209 -0
- opscloud/commands/power/trace.py +117 -0
- opscloud/commands/power/ui_toggles.py +135 -0
- opscloud/commands/power/version.py +52 -0
- opscloud/commands/registry.py +176 -0
- opscloud/config/__init__.py +114 -0
- opscloud/config/adapters/__init__.py +5 -0
- opscloud/config/adapters/postgres.py +776 -0
- opscloud/config/adapters/sqlite.py +769 -0
- opscloud/config/aws.py +248 -0
- opscloud/config/cloud_profiles.py +437 -0
- opscloud/config/env_vars.py +81 -0
- opscloud/config/langsmith.py +319 -0
- opscloud/config/manifest.py +817 -0
- opscloud/config/metadata.py +205 -0
- opscloud/config/paths.py +604 -0
- opscloud/config/plugins.py +130 -0
- opscloud/config/settings.py +834 -0
- opscloud/config/store.py +453 -0
- opscloud/config/store_factory.py +97 -0
- opscloud/config/toml_config.py +562 -0
- opscloud/editor.py +173 -0
- opscloud/exceptions.py +65 -0
- opscloud/file_ops.py +217 -0
- opscloud/hooks/__init__.py +139 -0
- opscloud/hooks/env.py +44 -0
- opscloud/hooks/interrupt.py +121 -0
- opscloud/hooks/models/__init__.py +109 -0
- opscloud/hooks/models/adapters.py +19 -0
- opscloud/hooks/models/config.py +79 -0
- opscloud/hooks/models/domain.py +434 -0
- opscloud/hooks/models/transport.py +37 -0
- opscloud/hooks/tools.py +231 -0
- opscloud/input.py +48 -0
- opscloud/integrations/__init__.py +80 -0
- opscloud/integrations/base.py +153 -0
- opscloud/integrations/content_filter.py +119 -0
- opscloud/integrations/event_bus.py +480 -0
- opscloud/integrations/hooks.py +238 -0
- opscloud/integrations/identity.py +181 -0
- opscloud/integrations/notifications.py +134 -0
- opscloud/integrations/stream_bridge.py +397 -0
- opscloud/integrations/thread_store.py +81 -0
- opscloud/json_types.py +20 -0
- opscloud/mcp/__init__.py +57 -0
- opscloud/mcp/config.py +203 -0
- opscloud/mcp/discovery.py +229 -0
- opscloud/mcp/mcp_info.py +109 -0
- opscloud/mcp/middleware.py +102 -0
- opscloud/mcp/preload.py +505 -0
- opscloud/mcp/raw_config.py +149 -0
- opscloud/mcp/semantic_profiler.py +305 -0
- opscloud/mcp/session_manager.py +727 -0
- opscloud/mcp/trust.py +105 -0
- opscloud/memory/__init__.py +27 -0
- opscloud/memory/branch.py +61 -0
- opscloud/memory/guard.py +19 -0
- opscloud/memory/onboarding.py +120 -0
- opscloud/memory/registry.py +134 -0
- opscloud/memory/store.py +223 -0
- opscloud/middleware/__init__.py +106 -0
- opscloud/middleware/_repository_bounds.py +459 -0
- opscloud/middleware/ask_user.py +152 -0
- opscloud/middleware/auto_mode.py +60 -0
- opscloud/middleware/auto_mode_hitl.py +2434 -0
- opscloud/middleware/compaction.py +566 -0
- opscloud/middleware/configurable_model.py +233 -0
- opscloud/middleware/cost_tracking.py +1021 -0
- opscloud/middleware/glm_stall_recovery.py +109 -0
- opscloud/middleware/goal_criteria.py +1234 -0
- opscloud/middleware/goal_state_notice.py +712 -0
- opscloud/middleware/goal_tools.py +407 -0
- opscloud/middleware/headless_mcp_guard.py +88 -0
- opscloud/middleware/jev_model_router.py +1018 -0
- opscloud/middleware/local_context.py +460 -0
- opscloud/middleware/mcp_context.py +151 -0
- opscloud/middleware/mcp_middleware.py +146 -0
- opscloud/middleware/memory_guard.py +393 -0
- opscloud/middleware/model_retry.py +205 -0
- opscloud/middleware/registry.py +137 -0
- opscloud/middleware/reliable_rubric.py +709 -0
- opscloud/middleware/resume_state.py +91 -0
- opscloud/middleware/server_hooks.py +1189 -0
- opscloud/middleware/shell_allow_list.py +90 -0
- opscloud/middleware/skills.py +382 -0
- opscloud/middleware/subagent_artifacts.py +84 -0
- opscloud/middleware/subagent_telemetry.py +261 -0
- opscloud/middleware/subagents.py +243 -0
- opscloud/middleware/tool_filter.py +384 -0
- opscloud/middleware/unified_system_message.py +62 -0
- opscloud/model/__init__.py +37 -0
- opscloud/model/config.py +2992 -0
- opscloud/model/factory.py +477 -0
- opscloud/model/pool.py +459 -0
- opscloud/model/reasoning.py +282 -0
- opscloud/offload.py +173 -0
- opscloud/output.py +64 -0
- opscloud/plugins/__init__.py +189 -0
- opscloud/plugins/_json.py +22 -0
- opscloud/plugins/adapters/__init__.py +13 -0
- opscloud/plugins/adapters/agents.py +112 -0
- opscloud/plugins/adapters/commands.py +190 -0
- opscloud/plugins/adapters/mcp.py +363 -0
- opscloud/plugins/adapters/skills.py +132 -0
- opscloud/plugins/commands_cli.py +541 -0
- opscloud/plugins/discovery.py +512 -0
- opscloud/plugins/manifest.py +335 -0
- opscloud/plugins/marketplace.py +893 -0
- opscloud/plugins/models.py +334 -0
- opscloud/plugins/project_plugins.py +317 -0
- opscloud/plugins/protocol.py +31 -0
- opscloud/plugins/store.py +905 -0
- opscloud/plugins/substitution.py +122 -0
- opscloud/project_utils.py +145 -0
- opscloud/prompts/__init__.py +37 -0
- opscloud/prompts/system.py +483 -0
- opscloud/prompts/templates/system_prompt.md +166 -0
- opscloud/prompts/types.py +54 -0
- opscloud/rubrics/__init__.py +42 -0
- opscloud/rubrics/evaluator.py +404 -0
- opscloud/rubrics/evidence_extractor.py +229 -0
- opscloud/rubrics/generator.py +239 -0
- opscloud/rubrics/jev_compiler.py +175 -0
- opscloud/rubrics/jev_grader.py +297 -0
- opscloud/rubrics/middleware.py +8 -0
- opscloud/schema/__init__.py +107 -0
- opscloud/schema/interrupts.py +981 -0
- opscloud/security/__init__.py +91 -0
- opscloud/security/approval_mode.py +528 -0
- opscloud/security/approval_mode_source.py +230 -0
- opscloud/security/cli_ast_evaluator.py +552 -0
- opscloud/security/jev_classifier.py +651 -0
- opscloud/security/shell_safety.py +340 -0
- opscloud/security/unicode_security.py +439 -0
- opscloud/security/url_validation.py +160 -0
- opscloud/server/__init__.py +13 -0
- opscloud/server/_server_config.py +158 -0
- opscloud/server/server.py +242 -0
- opscloud/server/server_graph.py +93 -0
- opscloud/skills/__init__.py +91 -0
- opscloud/skills/commands.py +1099 -0
- opscloud/skills/invocation.py +200 -0
- opscloud/skills/load.py +388 -0
- opscloud/skills/loader.py +23 -0
- opscloud/skills/merge.py +65 -0
- opscloud/skills/registry.py +263 -0
- opscloud/skills/sources.py +174 -0
- opscloud/skills/trust.py +417 -0
- opscloud/state/__init__.py +142 -0
- opscloud/state/base.py +154 -0
- opscloud/state/cloud_context.py +262 -0
- opscloud/state/goal_channels.py +124 -0
- opscloud/state/goal_state_limits.py +175 -0
- opscloud/state/resume_state.py +58 -0
- opscloud/state/service_context.py +281 -0
- opscloud/state/session.py +957 -0
- opscloud/state/state_migration.py +86 -0
- opscloud/subagents/__init__.py +30 -0
- opscloud/subagents/loader.py +331 -0
- opscloud/subagents/subagents_parser.py +117 -0
- opscloud/subagents/types.py +25 -0
- opscloud/tools/__init__.py +36 -0
- opscloud/tools/catalog.py +37 -0
- opscloud/tools/display.py +24 -0
- opscloud/tools/fetch_url.py +176 -0
- opscloud/tools/goal_tools.py +423 -0
- opscloud/tools/registry.py +105 -0
- opscloud/tools/thread.py +32 -0
- opscloud/tools/web_search.py +215 -0
- opscloud/ui/__init__.py +119 -0
- opscloud/ui/app.py +5400 -0
- opscloud/ui/app.tcss +479 -0
- opscloud/ui/clipboard.py +147 -0
- opscloud/ui/command_registry.py +482 -0
- opscloud/ui/message_store.py +152 -0
- opscloud/ui/permission_store.py +360 -0
- opscloud/ui/preferences.py +113 -0
- opscloud/ui/prompt_manager.py +96 -0
- opscloud/ui/remote_client.py +505 -0
- opscloud/ui/textual_adapter.py +1269 -0
- opscloud/ui/theme.py +728 -0
- opscloud/ui/ui_help.py +415 -0
- opscloud/ui/widgets/__init__.py +383 -0
- opscloud/ui/widgets/_ask_user_types.py +81 -0
- opscloud/ui/widgets/_copy_spans.py +52 -0
- opscloud/ui/widgets/_inline_prompt.py +290 -0
- opscloud/ui/widgets/_js_eval_display.py +139 -0
- opscloud/ui/widgets/_links.py +175 -0
- opscloud/ui/widgets/_tool_stream.py +308 -0
- opscloud/ui/widgets/agent_selector.py +297 -0
- opscloud/ui/widgets/approval.py +741 -0
- opscloud/ui/widgets/ask_user.py +539 -0
- opscloud/ui/widgets/auth.py +695 -0
- opscloud/ui/widgets/auth_manager.py +214 -0
- opscloud/ui/widgets/auto_mode_notice.py +146 -0
- opscloud/ui/widgets/autocomplete.py +709 -0
- opscloud/ui/widgets/chat_input.py +805 -0
- opscloud/ui/widgets/cloud_selector.py +528 -0
- opscloud/ui/widgets/config_manager.py +652 -0
- opscloud/ui/widgets/debug_console.py +1269 -0
- opscloud/ui/widgets/devops_renderers.py +184 -0
- opscloud/ui/widgets/diff.py +237 -0
- opscloud/ui/widgets/effort_selector.py +166 -0
- opscloud/ui/widgets/goal_review.py +612 -0
- opscloud/ui/widgets/goal_status.py +57 -0
- opscloud/ui/widgets/infra_panel.py +141 -0
- opscloud/ui/widgets/install_confirm.py +114 -0
- opscloud/ui/widgets/loading.py +170 -0
- opscloud/ui/widgets/mcp_viewer.py +1204 -0
- opscloud/ui/widgets/messages.py +4461 -0
- opscloud/ui/widgets/model_selector.py +863 -0
- opscloud/ui/widgets/notification_center.py +108 -0
- opscloud/ui/widgets/notification_settings.py +119 -0
- opscloud/ui/widgets/operation_card.py +106 -0
- opscloud/ui/widgets/permissions_manager.py +667 -0
- opscloud/ui/widgets/plugin_manager.py +1212 -0
- opscloud/ui/widgets/pool_selector.py +376 -0
- opscloud/ui/widgets/preamble.py +53 -0
- opscloud/ui/widgets/skills_viewer.py +432 -0
- opscloud/ui/widgets/status.py +1037 -0
- opscloud/ui/widgets/subagent_panel.py +927 -0
- opscloud/ui/widgets/theme_selector.py +232 -0
- opscloud/ui/widgets/thread_selector.py +358 -0
- opscloud/ui/widgets/toast.py +31 -0
- opscloud/ui/widgets/tool_display.py +325 -0
- opscloud/ui/widgets/tool_renderers.py +234 -0
- opscloud/ui/widgets/tool_widgets.py +278 -0
- opscloud/ui/widgets/welcome.py +421 -0
- opscloud/ui/widgets/welcome_popup.py +102 -0
- opscloud/utils/__init__.py +24 -0
- opscloud/utils/cost_estimation.py +169 -0
- opscloud/utils/git.py +390 -0
- opscloud/utils/logger.py +571 -0
- opscloud/utils/session_stats.py +115 -0
- opscloud/utils/startup_error.py +37 -0
- talkops_opscloud-0.3.0b1.dist-info/METADATA +449 -0
- talkops_opscloud-0.3.0b1.dist-info/RECORD +309 -0
- talkops_opscloud-0.3.0b1.dist-info/WHEEL +4 -0
- talkops_opscloud-0.3.0b1.dist-info/entry_points.txt +2 -0
- talkops_opscloud-0.3.0b1.dist-info/licenses/LICENSE +175 -0
|
@@ -0,0 +1,1212 @@
|
|
|
1
|
+
"""Interactive plugin manager modal screen for /plugins.
|
|
2
|
+
|
|
3
|
+
Full-screen modal for browsing, installing, enabling/disabling, and managing
|
|
4
|
+
plugins and marketplaces in OpsCloud.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import asyncio
|
|
10
|
+
from opscloud.utils.logger import get_logger
|
|
11
|
+
from dataclasses import dataclass
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from collections.abc import Sequence, Set as AbstractSet
|
|
14
|
+
from typing import TYPE_CHECKING, ClassVar, Literal
|
|
15
|
+
|
|
16
|
+
from textual.binding import Binding, BindingType
|
|
17
|
+
from textual.containers import Horizontal, Vertical
|
|
18
|
+
from textual.content import Content
|
|
19
|
+
from textual.css.query import NoMatches
|
|
20
|
+
from textual.events import Key
|
|
21
|
+
from textual.message import Message
|
|
22
|
+
from textual.screen import ModalScreen
|
|
23
|
+
from textual.widgets import Input, OptionList, Rule, Static
|
|
24
|
+
from textual.widgets.option_list import Option
|
|
25
|
+
|
|
26
|
+
from opscloud.config.settings import get_glyphs, is_ascii_mode
|
|
27
|
+
from opscloud.plugins import (
|
|
28
|
+
add_marketplace_source,
|
|
29
|
+
discover_marketplace_plugins,
|
|
30
|
+
install_plugin,
|
|
31
|
+
remove_marketplace,
|
|
32
|
+
set_installed_plugin_enabled,
|
|
33
|
+
uninstall_plugin,
|
|
34
|
+
)
|
|
35
|
+
from opscloud.plugins.manifest import (
|
|
36
|
+
UnsupportedComponent,
|
|
37
|
+
)
|
|
38
|
+
from opscloud.plugins.marketplace import (
|
|
39
|
+
MarketplaceError,
|
|
40
|
+
load_marketplace_location,
|
|
41
|
+
materialize_plugin_source,
|
|
42
|
+
redact_marketplace_source,
|
|
43
|
+
redact_urls_in_text,
|
|
44
|
+
)
|
|
45
|
+
from opscloud.plugins.models import InstallScope
|
|
46
|
+
from opscloud.plugins.store import (
|
|
47
|
+
load_all_enabled_plugin_ids,
|
|
48
|
+
load_installed_plugin_entries,
|
|
49
|
+
load_installed_plugins,
|
|
50
|
+
load_marketplace_records,
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
if TYPE_CHECKING:
|
|
54
|
+
from textual.app import ComposeResult
|
|
55
|
+
from opscloud.mcp.mcp_info import MCPServerInfo
|
|
56
|
+
|
|
57
|
+
logger = get_logger(__name__)
|
|
58
|
+
|
|
59
|
+
PluginTab = Literal["discover", "installed", "marketplaces", "errors"]
|
|
60
|
+
PluginManagerView = Literal[
|
|
61
|
+
"list",
|
|
62
|
+
"add_marketplace",
|
|
63
|
+
"plugin_details",
|
|
64
|
+
"installed_details",
|
|
65
|
+
"marketplace_details",
|
|
66
|
+
"confirm_remove_marketplace",
|
|
67
|
+
]
|
|
68
|
+
PluginLoadState = Literal["disabled", "pending_reload", "enabled", "error"]
|
|
69
|
+
|
|
70
|
+
TAB_LABELS: dict[PluginTab, str] = {
|
|
71
|
+
"discover": "Discover",
|
|
72
|
+
"installed": "Installed",
|
|
73
|
+
"marketplaces": "Marketplaces",
|
|
74
|
+
"errors": "Errors",
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
@dataclass(frozen=True, slots=True, kw_only=True)
|
|
79
|
+
class _PluginRow:
|
|
80
|
+
plugin_id: str
|
|
81
|
+
description: str
|
|
82
|
+
enabled: bool
|
|
83
|
+
version: str | None
|
|
84
|
+
author: str | None
|
|
85
|
+
display_name: str = ""
|
|
86
|
+
skill_count: int | None = None
|
|
87
|
+
skill_names: tuple[str, ...] = ()
|
|
88
|
+
mcp_connected: bool | None = None
|
|
89
|
+
mcp_server_names: tuple[str, ...] = ()
|
|
90
|
+
mcp_login_servers: tuple[str, ...] = ()
|
|
91
|
+
unsupported_components: tuple[UnsupportedComponent, ...] = ()
|
|
92
|
+
session_loaded: bool = False
|
|
93
|
+
load_error: str | None = None
|
|
94
|
+
scope: InstallScope | None = None
|
|
95
|
+
|
|
96
|
+
@property
|
|
97
|
+
def load_state(self) -> PluginLoadState:
|
|
98
|
+
if self.load_error:
|
|
99
|
+
return "error"
|
|
100
|
+
if self.enabled != self.session_loaded:
|
|
101
|
+
return "pending_reload"
|
|
102
|
+
if self.enabled:
|
|
103
|
+
return "enabled"
|
|
104
|
+
return "disabled"
|
|
105
|
+
|
|
106
|
+
@property
|
|
107
|
+
def label(self) -> str:
|
|
108
|
+
if self.display_name:
|
|
109
|
+
return self.display_name
|
|
110
|
+
return self.plugin_id.partition("@")[0]
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
@dataclass(frozen=True, slots=True)
|
|
114
|
+
class _MarketplaceRow:
|
|
115
|
+
name: str
|
|
116
|
+
source: str
|
|
117
|
+
plugin_count: int | None
|
|
118
|
+
installed_count: int
|
|
119
|
+
error: str | None = None
|
|
120
|
+
|
|
121
|
+
@property
|
|
122
|
+
def has_error(self) -> bool:
|
|
123
|
+
return self.error is not None
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
@dataclass(frozen=True, slots=True)
|
|
127
|
+
class _ManagerState:
|
|
128
|
+
available_plugins: tuple[_PluginRow, ...]
|
|
129
|
+
installed_plugins: tuple[_PluginRow, ...]
|
|
130
|
+
marketplaces: tuple[_MarketplaceRow, ...]
|
|
131
|
+
errors: tuple[str, ...]
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
# ── Content Formatters ────────────────────────────────────
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def _plugin_options(
|
|
138
|
+
rows: tuple[_PluginRow, ...],
|
|
139
|
+
*,
|
|
140
|
+
action: Literal["detail", "installed"],
|
|
141
|
+
status: str | None,
|
|
142
|
+
) -> list[Option]:
|
|
143
|
+
options: list[Option] = []
|
|
144
|
+
for index, row in enumerate(rows):
|
|
145
|
+
if index > 0:
|
|
146
|
+
options.append(Option(" ", id=f"spacer:{index}", disabled=True))
|
|
147
|
+
options.append(
|
|
148
|
+
Option(_plugin_prompt(row, status=status), id=f"{action}:{row.plugin_id}")
|
|
149
|
+
)
|
|
150
|
+
return options
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def _load_state_label(row: _PluginRow) -> str | None:
|
|
154
|
+
glyphs = get_glyphs()
|
|
155
|
+
if row.load_state == "error":
|
|
156
|
+
return "error"
|
|
157
|
+
if row.load_state == "pending_reload":
|
|
158
|
+
return "pending /reload"
|
|
159
|
+
if row.load_state == "enabled":
|
|
160
|
+
return f"{glyphs.checkmark} enabled"
|
|
161
|
+
return None
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def _plugin_prompt(row: _PluginRow, *, status: str | None) -> Content:
|
|
165
|
+
glyphs = get_glyphs()
|
|
166
|
+
_, _, marketplace = row.plugin_id.partition("@")
|
|
167
|
+
meta_parts = [Content.styled("Plugin", "dim"), Content.styled(marketplace, "dim")]
|
|
168
|
+
load_label = _load_state_label(row)
|
|
169
|
+
if load_label:
|
|
170
|
+
if row.load_state == "enabled":
|
|
171
|
+
meta_parts.append(Content.styled(load_label, "bold"))
|
|
172
|
+
elif row.load_state == "error":
|
|
173
|
+
meta_parts.append(Content.styled(load_label, "bold $error"))
|
|
174
|
+
else:
|
|
175
|
+
meta_parts.append(Content.styled(load_label, "dim"))
|
|
176
|
+
if row.skill_count:
|
|
177
|
+
skill_label = "skill" if row.skill_count == 1 else "skills"
|
|
178
|
+
meta_parts.append(Content.styled(f"{row.skill_count} {skill_label}", "dim"))
|
|
179
|
+
if row.load_state == "enabled":
|
|
180
|
+
if row.mcp_connected is True:
|
|
181
|
+
meta_parts.append(Content.styled(f"{glyphs.checkmark} connected", "dim"))
|
|
182
|
+
elif row.mcp_connected is False:
|
|
183
|
+
meta_parts.append(Content.styled("run /reload to connect", "bold $warning"))
|
|
184
|
+
elif (
|
|
185
|
+
row.load_state == "pending_reload"
|
|
186
|
+
and row.session_loaded
|
|
187
|
+
and row.mcp_connected is True
|
|
188
|
+
):
|
|
189
|
+
meta_parts.append(Content.styled(f"{glyphs.checkmark} connected", "dim"))
|
|
190
|
+
if status:
|
|
191
|
+
meta_parts.append(Content.styled(status, "dim"))
|
|
192
|
+
separator = Content.styled(" · ", "dim")
|
|
193
|
+
return Content.assemble(
|
|
194
|
+
row.label,
|
|
195
|
+
separator,
|
|
196
|
+
separator.join(meta_parts),
|
|
197
|
+
"\n ",
|
|
198
|
+
Content.styled(row.description or "No description provided.", "dim"),
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def _install_details_options(*, has_project: bool) -> list[Option]:
|
|
203
|
+
options = [
|
|
204
|
+
Option("Install for you", id="action:install-user"),
|
|
205
|
+
]
|
|
206
|
+
if has_project:
|
|
207
|
+
options.extend([
|
|
208
|
+
Option(
|
|
209
|
+
"Install for all collaborators on this repository",
|
|
210
|
+
id="action:install-project",
|
|
211
|
+
),
|
|
212
|
+
Option(
|
|
213
|
+
"Install for you, in this repo only",
|
|
214
|
+
id="action:install-local",
|
|
215
|
+
),
|
|
216
|
+
])
|
|
217
|
+
options.append(Option("Back to plugin list", id="details-back"))
|
|
218
|
+
return options
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def _installed_details_options(row: _PluginRow, *, divider_width: int) -> list[Option]:
|
|
222
|
+
glyphs = get_glyphs()
|
|
223
|
+
return [
|
|
224
|
+
Option(
|
|
225
|
+
"Disable plugin" if row.enabled else "Enable plugin",
|
|
226
|
+
id="action:toggle-enabled",
|
|
227
|
+
),
|
|
228
|
+
Option(Content.styled("Uninstall", "bold"), id="action:uninstall"),
|
|
229
|
+
Option(
|
|
230
|
+
Content.styled(glyphs.box_horizontal * divider_width, "dim"),
|
|
231
|
+
id="details-divider",
|
|
232
|
+
disabled=True,
|
|
233
|
+
),
|
|
234
|
+
Option("Back to plugin list", id="details-back"),
|
|
235
|
+
]
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def _component_summary_lines(row: _PluginRow) -> list[str]:
|
|
239
|
+
lines: list[str] = []
|
|
240
|
+
if row.skill_names:
|
|
241
|
+
lines.append(f"Skills: {', '.join(row.skill_names)}")
|
|
242
|
+
elif row.skill_count:
|
|
243
|
+
lines.append(f"Skills: {row.skill_count}")
|
|
244
|
+
if row.mcp_server_names:
|
|
245
|
+
lines.append(f"MCP: {', '.join(row.mcp_server_names)}")
|
|
246
|
+
if row.unsupported_components:
|
|
247
|
+
names = ", ".join(f"{name}/" for name in row.unsupported_components)
|
|
248
|
+
lines.append(f"Unsupported (not loaded): {names}")
|
|
249
|
+
return lines
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def _plugin_details_content(row: _PluginRow) -> Content:
|
|
253
|
+
_, _, marketplace = row.plugin_id.partition("@")
|
|
254
|
+
parts: list[Content | str] = [
|
|
255
|
+
Content.styled("Plugin details", "bold"),
|
|
256
|
+
"\n\n",
|
|
257
|
+
Content.styled(row.label, "bold"),
|
|
258
|
+
"\n",
|
|
259
|
+
Content.styled(f"from {marketplace}", "dim"),
|
|
260
|
+
]
|
|
261
|
+
if row.version:
|
|
262
|
+
parts.extend(["\n", Content.styled(f"Version: {row.version}", "dim")])
|
|
263
|
+
if row.description:
|
|
264
|
+
parts.extend(["\n\n", row.description])
|
|
265
|
+
if row.author:
|
|
266
|
+
parts.extend(["\n\n", Content.styled(f"By: {row.author}", "dim")])
|
|
267
|
+
parts.extend(["\n\n", Content.styled("Will install:", "bold")])
|
|
268
|
+
summary_lines = _component_summary_lines(row) or ["Skills and MCP servers if present."]
|
|
269
|
+
for line in summary_lines:
|
|
270
|
+
parts.extend(["\n ", Content.styled(line, "dim")])
|
|
271
|
+
parts.extend(
|
|
272
|
+
[
|
|
273
|
+
"\n\n",
|
|
274
|
+
Content.styled(
|
|
275
|
+
"Make sure you trust a plugin before installing or using it.",
|
|
276
|
+
"dim",
|
|
277
|
+
),
|
|
278
|
+
]
|
|
279
|
+
)
|
|
280
|
+
return Content.assemble(*parts)
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def _installed_plugin_details_content(row: _PluginRow) -> Content:
|
|
284
|
+
_, _, marketplace = row.plugin_id.partition("@")
|
|
285
|
+
parts: list[Content | str] = [
|
|
286
|
+
Content.styled(f"{row.label} @ {marketplace}", "bold")
|
|
287
|
+
]
|
|
288
|
+
if row.version:
|
|
289
|
+
parts.extend(["\n", Content.styled(f"Version: {row.version}", "dim")])
|
|
290
|
+
if row.description:
|
|
291
|
+
parts.extend(["\n\n", row.description])
|
|
292
|
+
if row.author:
|
|
293
|
+
parts.extend(["\n\n", Content.styled(f"Author: {row.author}", "dim")])
|
|
294
|
+
parts.extend(["\n\n"])
|
|
295
|
+
glyphs = get_glyphs()
|
|
296
|
+
if row.load_state == "enabled":
|
|
297
|
+
parts.append(Content.styled(f"Status: {glyphs.checkmark} Enabled", "$success"))
|
|
298
|
+
elif row.load_state == "disabled":
|
|
299
|
+
parts.append(Content.styled("Status: Disabled", "dim"))
|
|
300
|
+
elif row.load_state == "error":
|
|
301
|
+
parts.append(Content.styled(f"Status: Error — {row.load_error}", "$error"))
|
|
302
|
+
else:
|
|
303
|
+
parts.append(Content.styled("Status: Pending reload", "dim"))
|
|
304
|
+
|
|
305
|
+
parts.extend(["\n\n", Content.styled("Installed components:", "bold")])
|
|
306
|
+
summary_lines = _component_summary_lines(row) or ["No components found."]
|
|
307
|
+
for line in summary_lines:
|
|
308
|
+
parts.extend(["\n ", Content.styled(line, "dim")])
|
|
309
|
+
return Content.assemble(*parts)
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
def _marketplace_label(row: _MarketplaceRow) -> Content:
|
|
313
|
+
glyphs = get_glyphs()
|
|
314
|
+
prefix = f"{row.name} {glyphs.bullet} {row.source} {glyphs.bullet} "
|
|
315
|
+
if row.has_error:
|
|
316
|
+
return Content.assemble(
|
|
317
|
+
prefix,
|
|
318
|
+
Content.styled(f"{glyphs.error} Error", "$error"),
|
|
319
|
+
)
|
|
320
|
+
return Content.assemble(prefix, f"{row.plugin_count} available")
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
def _marketplace_details_options() -> list[Option]:
|
|
324
|
+
return [
|
|
325
|
+
Option(
|
|
326
|
+
Content.styled("Refresh marketplace", "bold"), id="action:refresh-marketplace"
|
|
327
|
+
),
|
|
328
|
+
Option(
|
|
329
|
+
Content.styled("Remove marketplace", "bold"), id="action:remove-marketplace"
|
|
330
|
+
),
|
|
331
|
+
Option("Back to marketplace list", id="details-back"),
|
|
332
|
+
]
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def _confirm_marketplace_removal_options(row: _MarketplaceRow) -> list[Option]:
|
|
336
|
+
label = "installed plugin" if row.installed_count == 1 else "installed plugins"
|
|
337
|
+
return [
|
|
338
|
+
Option(
|
|
339
|
+
Content.styled(
|
|
340
|
+
f"Remove marketplace and {row.installed_count} {label}", "bold"
|
|
341
|
+
),
|
|
342
|
+
id="action:confirm-remove-marketplace",
|
|
343
|
+
),
|
|
344
|
+
Option("Cancel", id="details-back"),
|
|
345
|
+
]
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
def _marketplace_details_content(row: _MarketplaceRow) -> Content:
|
|
349
|
+
available = "Unavailable" if row.has_error else f"{row.plugin_count} available"
|
|
350
|
+
return Content.assemble(
|
|
351
|
+
Content.styled(row.name, "bold"),
|
|
352
|
+
"\n",
|
|
353
|
+
Content.styled(f"Source: {row.source}", "dim"),
|
|
354
|
+
"\n",
|
|
355
|
+
Content.styled(f"Plugins: {available}", "dim"),
|
|
356
|
+
"\n",
|
|
357
|
+
Content.styled(f"Installed: {row.installed_count}", "dim"),
|
|
358
|
+
)
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
def _marketplace_removal_content(row: _MarketplaceRow) -> Content:
|
|
362
|
+
suffix = "s" if row.installed_count != 1 else ""
|
|
363
|
+
if row.installed_count:
|
|
364
|
+
detail = (
|
|
365
|
+
f"This removes the marketplace and uninstalls {row.installed_count} "
|
|
366
|
+
f"plugin{suffix} from it."
|
|
367
|
+
)
|
|
368
|
+
else:
|
|
369
|
+
detail = "This removes the marketplace from your installed list."
|
|
370
|
+
return Content.assemble(
|
|
371
|
+
Content.styled(f"Remove marketplace {row.name}?", "bold"),
|
|
372
|
+
"\n\n",
|
|
373
|
+
Content.styled(detail, "dim"),
|
|
374
|
+
)
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
# ── State Loader ──────────────────────────────────────────
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
def _load_manager_state(
|
|
381
|
+
mcp_server_info: Sequence[MCPServerInfo] = (),
|
|
382
|
+
*,
|
|
383
|
+
loaded_plugin_ids: AbstractSet[str] = frozenset(),
|
|
384
|
+
project_root: Path | None = None,
|
|
385
|
+
) -> _ManagerState:
|
|
386
|
+
records = load_marketplace_records(project_root=project_root)
|
|
387
|
+
enabled = load_all_enabled_plugin_ids(project_root=project_root)
|
|
388
|
+
installed = load_installed_plugins()
|
|
389
|
+
all_entries = load_installed_plugin_entries()
|
|
390
|
+
from opscloud.plugins.store import load_all_disabled_plugin_ids
|
|
391
|
+
|
|
392
|
+
disabled = load_all_disabled_plugin_ids(project_root=project_root)
|
|
393
|
+
errors: list[str] = []
|
|
394
|
+
plugin_result = discover_marketplace_plugins(project_root=project_root)
|
|
395
|
+
errors.extend(plugin_result.warnings)
|
|
396
|
+
discovered = {instance.plugin_id: instance for instance in plugin_result.plugins}
|
|
397
|
+
available_plugins: list[_PluginRow] = []
|
|
398
|
+
installed_plugins: list[_PluginRow] = []
|
|
399
|
+
marketplaces: list[_MarketplaceRow] = []
|
|
400
|
+
|
|
401
|
+
for name, record in sorted(records.items()):
|
|
402
|
+
try:
|
|
403
|
+
marketplace = load_marketplace_location(Path(record.install_location))
|
|
404
|
+
except MarketplaceError as exc:
|
|
405
|
+
detail = redact_urls_in_text(str(exc))
|
|
406
|
+
if record.source_type not in {"directory", "file"}:
|
|
407
|
+
detail = detail.replace(record.install_location, "<managed cache>")
|
|
408
|
+
errors.append(f"{name}: {detail}")
|
|
409
|
+
marketplaces.append(
|
|
410
|
+
_MarketplaceRow(
|
|
411
|
+
name,
|
|
412
|
+
redact_marketplace_source(record.source),
|
|
413
|
+
None,
|
|
414
|
+
sum(plugin_id.endswith(f"@{name}") for plugin_id in installed),
|
|
415
|
+
detail,
|
|
416
|
+
)
|
|
417
|
+
)
|
|
418
|
+
continue
|
|
419
|
+
|
|
420
|
+
is_project_marketplace = record.is_project
|
|
421
|
+
|
|
422
|
+
installed_cnt = (
|
|
423
|
+
len([p for p in marketplace.plugins if f"{p.name}@{marketplace.name}" not in disabled])
|
|
424
|
+
if is_project_marketplace
|
|
425
|
+
else sum(
|
|
426
|
+
plugin_id.endswith(f"@{marketplace.name}")
|
|
427
|
+
for plugin_id in installed
|
|
428
|
+
)
|
|
429
|
+
)
|
|
430
|
+
marketplaces.append(
|
|
431
|
+
_MarketplaceRow(
|
|
432
|
+
marketplace.name,
|
|
433
|
+
redact_marketplace_source(record.source),
|
|
434
|
+
len(marketplace.plugins),
|
|
435
|
+
installed_cnt,
|
|
436
|
+
)
|
|
437
|
+
)
|
|
438
|
+
errors.extend(
|
|
439
|
+
f"{marketplace.name}: {warning}" for warning in marketplace.warnings
|
|
440
|
+
)
|
|
441
|
+
for plugin in marketplace.plugins:
|
|
442
|
+
plugin_id = f"{plugin.name}@{marketplace.name}"
|
|
443
|
+
is_disabled = plugin_id in disabled
|
|
444
|
+
is_enabled = plugin_id in enabled or (is_project_marketplace and not is_disabled)
|
|
445
|
+
is_installed = plugin_id in installed or (is_project_marketplace and not is_disabled)
|
|
446
|
+
instance = discovered.get(plugin_id)
|
|
447
|
+
|
|
448
|
+
if instance is None and is_project_marketplace:
|
|
449
|
+
source_root = materialize_plugin_source(marketplace, plugin)
|
|
450
|
+
if source_root is not None:
|
|
451
|
+
from opscloud.plugins.project_plugins import _build_plugin_instance
|
|
452
|
+
|
|
453
|
+
instance, _ = _build_plugin_instance(
|
|
454
|
+
plugin.name, marketplace.name, source_root, plugin.name
|
|
455
|
+
)
|
|
456
|
+
|
|
457
|
+
display_name = (
|
|
458
|
+
plugin.display_name
|
|
459
|
+
or (instance.manifest.display_name if instance and instance.manifest else None)
|
|
460
|
+
or plugin.name
|
|
461
|
+
)
|
|
462
|
+
author = (
|
|
463
|
+
plugin.author.get("name") if isinstance(plugin.author, dict) else plugin.author
|
|
464
|
+
)
|
|
465
|
+
# Determine scope from install entries
|
|
466
|
+
entry_list = all_entries.get(plugin_id, [])
|
|
467
|
+
scope: InstallScope | None = (
|
|
468
|
+
entry_list[0].scope
|
|
469
|
+
if entry_list
|
|
470
|
+
else ("project" if is_project_marketplace else None)
|
|
471
|
+
)
|
|
472
|
+
row = _PluginRow(
|
|
473
|
+
plugin_id=plugin_id,
|
|
474
|
+
description=plugin.description or "",
|
|
475
|
+
enabled=is_enabled,
|
|
476
|
+
version=instance.version if instance else getattr(plugin, "version", None),
|
|
477
|
+
author=author,
|
|
478
|
+
display_name=display_name,
|
|
479
|
+
skill_count=len(instance.inventory.skills) if instance else None,
|
|
480
|
+
skill_names=tuple(p.stem for p in instance.inventory.skills) if instance else (),
|
|
481
|
+
mcp_connected=None,
|
|
482
|
+
mcp_server_names=(),
|
|
483
|
+
unsupported_components=instance.inventory.unsupported if instance else (),
|
|
484
|
+
session_loaded=plugin_id in loaded_plugin_ids,
|
|
485
|
+
scope=scope if is_installed else None,
|
|
486
|
+
)
|
|
487
|
+
(installed_plugins if is_installed else available_plugins).append(row)
|
|
488
|
+
|
|
489
|
+
return _ManagerState(
|
|
490
|
+
tuple(available_plugins),
|
|
491
|
+
tuple(installed_plugins),
|
|
492
|
+
tuple(marketplaces),
|
|
493
|
+
tuple(dict.fromkeys(errors)),
|
|
494
|
+
)
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
# ── UI Components ─────────────────────────────────────────
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
class PluginTabSelected(Message):
|
|
501
|
+
"""Message sent when a plugin tab label is clicked."""
|
|
502
|
+
|
|
503
|
+
def __init__(self, tab: PluginTab) -> None:
|
|
504
|
+
super().__init__()
|
|
505
|
+
self.tab: PluginTab = tab
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
class PluginTabLabel(Static):
|
|
509
|
+
"""Clickable tab label header widget."""
|
|
510
|
+
|
|
511
|
+
def __init__(self, tab: PluginTab, label: str) -> None:
|
|
512
|
+
self.tab: PluginTab = tab
|
|
513
|
+
self._label = label
|
|
514
|
+
super().__init__(f" {label} ", id=f"plugin-tab-{tab}", classes="plugin-tab-label")
|
|
515
|
+
|
|
516
|
+
def set_active(self, active: bool) -> None:
|
|
517
|
+
self.update(f"> {self._label} <" if active else f" {self._label} ")
|
|
518
|
+
if active:
|
|
519
|
+
self.add_class("plugin-tab-active")
|
|
520
|
+
else:
|
|
521
|
+
self.remove_class("plugin-tab-active")
|
|
522
|
+
|
|
523
|
+
def on_click(self) -> None:
|
|
524
|
+
self.post_message(PluginTabSelected(self.tab))
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
# ── Main Screen ───────────────────────────────────────────
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
class PluginManagerScreen(ModalScreen[None]):
|
|
531
|
+
"""Interactive modal screen for /plugins command."""
|
|
532
|
+
|
|
533
|
+
BINDINGS: ClassVar[list[BindingType]] = [
|
|
534
|
+
Binding("escape", "cancel", "Close", show=False, priority=True),
|
|
535
|
+
Binding("left", "arrow_previous_tab", "Previous tab", show=False, priority=True),
|
|
536
|
+
Binding("right", "arrow_next_tab", "Next tab", show=False, priority=True),
|
|
537
|
+
Binding("tab", "next_tab", "Next tab", show=False, priority=True),
|
|
538
|
+
Binding("shift+tab", "previous_tab", "Previous tab", show=False, priority=True),
|
|
539
|
+
Binding("up", "cursor_up", "Up", show=False, priority=True),
|
|
540
|
+
Binding("down", "cursor_down", "Down", show=False, priority=True),
|
|
541
|
+
Binding("/", "focus_search", "Search", show=False, priority=True),
|
|
542
|
+
]
|
|
543
|
+
|
|
544
|
+
CSS = """
|
|
545
|
+
PluginManagerScreen {
|
|
546
|
+
align: center middle;
|
|
547
|
+
background: $background 70%;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
PluginManagerScreen > Vertical {
|
|
551
|
+
width: 88;
|
|
552
|
+
max-width: 94%;
|
|
553
|
+
height: 90%;
|
|
554
|
+
min-height: 24;
|
|
555
|
+
background: $surface;
|
|
556
|
+
border: solid $primary;
|
|
557
|
+
padding: 1 2;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
PluginManagerScreen .plugin-manager-title {
|
|
561
|
+
text-style: bold;
|
|
562
|
+
color: $primary;
|
|
563
|
+
text-align: center;
|
|
564
|
+
margin-bottom: 1;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
PluginManagerScreen .plugin-manager-tabs {
|
|
568
|
+
height: 1;
|
|
569
|
+
width: 100%;
|
|
570
|
+
margin-bottom: 0;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
PluginManagerScreen .plugin-tab-label {
|
|
574
|
+
width: 1fr;
|
|
575
|
+
height: 1;
|
|
576
|
+
color: $text-muted;
|
|
577
|
+
text-align: center;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
PluginManagerScreen .plugin-tab-label:hover {
|
|
581
|
+
color: $text;
|
|
582
|
+
background: $surface-lighten-1;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
PluginManagerScreen .plugin-tab-label.plugin-tab-active {
|
|
586
|
+
color: $text;
|
|
587
|
+
text-style: bold;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
PluginManagerScreen #plugin-manager-search {
|
|
591
|
+
margin-bottom: 1;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
PluginManagerScreen #plugin-manager-options {
|
|
595
|
+
height: 1fr;
|
|
596
|
+
min-height: 5;
|
|
597
|
+
background: $background;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
PluginManagerScreen #plugin-marketplace-source {
|
|
601
|
+
margin-bottom: 1;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
PluginManagerScreen .plugin-manager-status {
|
|
605
|
+
color: $text-muted;
|
|
606
|
+
margin-bottom: 1;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
PluginManagerScreen .plugin-manager-error {
|
|
610
|
+
color: $error;
|
|
611
|
+
margin-bottom: 1;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
PluginManagerScreen .plugin-manager-help {
|
|
615
|
+
height: auto;
|
|
616
|
+
color: $text-muted;
|
|
617
|
+
text-style: italic;
|
|
618
|
+
margin-top: 1;
|
|
619
|
+
text-align: center;
|
|
620
|
+
}
|
|
621
|
+
"""
|
|
622
|
+
|
|
623
|
+
AUTO_FOCUS = "#plugin-manager-options"
|
|
624
|
+
_DIVIDER_FALLBACK_WIDTH: ClassVar[int] = 72
|
|
625
|
+
|
|
626
|
+
_tabs: ClassVar[tuple[PluginTab, ...]] = (
|
|
627
|
+
"discover",
|
|
628
|
+
"installed",
|
|
629
|
+
"marketplaces",
|
|
630
|
+
"errors",
|
|
631
|
+
)
|
|
632
|
+
|
|
633
|
+
def __init__(
|
|
634
|
+
self,
|
|
635
|
+
*,
|
|
636
|
+
mcp_server_info: Sequence[MCPServerInfo] = (),
|
|
637
|
+
loaded_plugin_ids: AbstractSet[str] | None = None,
|
|
638
|
+
project_root: Path | None = None,
|
|
639
|
+
) -> None:
|
|
640
|
+
super().__init__()
|
|
641
|
+
self._tab: PluginTab = "discover"
|
|
642
|
+
self._mode: PluginManagerView = "list"
|
|
643
|
+
self._mcp_server_info = mcp_server_info
|
|
644
|
+
self._loaded_plugin_ids: frozenset[str] = frozenset(loaded_plugin_ids or ())
|
|
645
|
+
self._project_root = project_root
|
|
646
|
+
self._state = _ManagerState((), (), (), ())
|
|
647
|
+
self._status: str | None = None
|
|
648
|
+
self._error: str | None = None
|
|
649
|
+
self._selected_plugin: _PluginRow | None = None
|
|
650
|
+
self._selected_marketplace: _MarketplaceRow | None = None
|
|
651
|
+
self._search_query = ""
|
|
652
|
+
|
|
653
|
+
def compose(self) -> ComposeResult:
|
|
654
|
+
with Vertical():
|
|
655
|
+
yield Static("Plugins", id="plugin-manager-title", classes="plugin-manager-title")
|
|
656
|
+
with Horizontal(id="plugin-manager-tabs", classes="plugin-manager-tabs"):
|
|
657
|
+
for tab in self._tabs:
|
|
658
|
+
yield PluginTabLabel(tab, TAB_LABELS[tab])
|
|
659
|
+
|
|
660
|
+
yield Rule(
|
|
661
|
+
line_style="heavy" if not is_ascii_mode() else "ascii",
|
|
662
|
+
id="plugin-manager-divider",
|
|
663
|
+
)
|
|
664
|
+
yield Static("", id="plugin-manager-status", classes="plugin-manager-status")
|
|
665
|
+
yield Static("", id="plugin-manager-error", classes="plugin-manager-error")
|
|
666
|
+
yield Input(placeholder="Search plugins...", id="plugin-manager-search")
|
|
667
|
+
yield OptionList(id="plugin-manager-options")
|
|
668
|
+
yield Input(placeholder="", id="plugin-marketplace-source")
|
|
669
|
+
yield Static("", id="plugin-manager-help", classes="plugin-manager-help")
|
|
670
|
+
|
|
671
|
+
async def on_mount(self) -> None:
|
|
672
|
+
self._status = "Loading plugins..."
|
|
673
|
+
self._refresh_view()
|
|
674
|
+
await self._refresh_state()
|
|
675
|
+
if self._status == "Loading plugins...":
|
|
676
|
+
self._status = None
|
|
677
|
+
self._refresh_view()
|
|
678
|
+
|
|
679
|
+
def _update_tab_labels(self) -> None:
|
|
680
|
+
for tab in self._tabs:
|
|
681
|
+
try:
|
|
682
|
+
self.query_one(f"#plugin-tab-{tab}", PluginTabLabel).set_active(
|
|
683
|
+
tab == self._tab
|
|
684
|
+
)
|
|
685
|
+
except NoMatches:
|
|
686
|
+
pass
|
|
687
|
+
|
|
688
|
+
def _select_tab(self, tab: PluginTab) -> None:
|
|
689
|
+
if self._mode == "add_marketplace":
|
|
690
|
+
return
|
|
691
|
+
if self._details_mode_active():
|
|
692
|
+
self._mode = "list"
|
|
693
|
+
self._selected_plugin = None
|
|
694
|
+
self._selected_marketplace = None
|
|
695
|
+
if tab != self._tab:
|
|
696
|
+
self._search_query = ""
|
|
697
|
+
self._tab = tab
|
|
698
|
+
self._error = None
|
|
699
|
+
self._refresh_view()
|
|
700
|
+
|
|
701
|
+
def _search_available(self) -> bool:
|
|
702
|
+
if self._mode != "list":
|
|
703
|
+
return False
|
|
704
|
+
if self._tab == "discover":
|
|
705
|
+
return bool(self._state.marketplaces and self._state.available_plugins)
|
|
706
|
+
if self._tab == "installed":
|
|
707
|
+
return bool(self._state.installed_plugins)
|
|
708
|
+
return False
|
|
709
|
+
|
|
710
|
+
def _filtered_plugins(self, rows: Sequence[_PluginRow]) -> tuple[_PluginRow, ...]:
|
|
711
|
+
query = self._search_query.strip().casefold()
|
|
712
|
+
if not query:
|
|
713
|
+
return tuple(rows)
|
|
714
|
+
return tuple(
|
|
715
|
+
row
|
|
716
|
+
for row in rows
|
|
717
|
+
if query in row.plugin_id.casefold()
|
|
718
|
+
or query in row.label.casefold()
|
|
719
|
+
or query in row.description.casefold()
|
|
720
|
+
or (row.author and query in row.author.casefold())
|
|
721
|
+
or any(query in s.casefold() for s in row.skill_names)
|
|
722
|
+
or any(query in s.casefold() for s in row.mcp_server_names)
|
|
723
|
+
)
|
|
724
|
+
|
|
725
|
+
def _current_options(self) -> list[Option]:
|
|
726
|
+
glyphs = get_glyphs()
|
|
727
|
+
if self._tab == "discover":
|
|
728
|
+
if not self._state.marketplaces:
|
|
729
|
+
return [
|
|
730
|
+
Option("No marketplaces installed. Add one to discover plugins.", id="empty", disabled=True),
|
|
731
|
+
Option("+ Add marketplace", id="add-marketplace"),
|
|
732
|
+
]
|
|
733
|
+
if not self._state.available_plugins:
|
|
734
|
+
return [Option("All available plugins are installed.", id="empty")]
|
|
735
|
+
rows = self._filtered_plugins(self._state.available_plugins)
|
|
736
|
+
if not rows:
|
|
737
|
+
return [Option("No plugins match your search.", id="empty", disabled=True)]
|
|
738
|
+
return _plugin_options(rows, action="detail", status=None)
|
|
739
|
+
if self._tab == "installed":
|
|
740
|
+
if not self._state.installed_plugins:
|
|
741
|
+
return [Option("No plugins installed.", id="empty")]
|
|
742
|
+
rows = self._filtered_plugins(self._state.installed_plugins)
|
|
743
|
+
if not rows:
|
|
744
|
+
return [Option("No installed plugins match your search.", id="empty", disabled=True)]
|
|
745
|
+
return _plugin_options(rows, action="installed", status=None)
|
|
746
|
+
if self._tab == "marketplaces":
|
|
747
|
+
options = [
|
|
748
|
+
Option("+ Add marketplace", id="add-marketplace"),
|
|
749
|
+
Option("⟳ Refresh all marketplaces", id="refresh-all-marketplaces"),
|
|
750
|
+
]
|
|
751
|
+
if self._state.marketplaces:
|
|
752
|
+
options.append(
|
|
753
|
+
Option(
|
|
754
|
+
Content.styled(glyphs.box_horizontal * self._divider_width(), "dim"),
|
|
755
|
+
id="marketplace-divider",
|
|
756
|
+
disabled=True,
|
|
757
|
+
)
|
|
758
|
+
)
|
|
759
|
+
for index, row in enumerate(self._state.marketplaces):
|
|
760
|
+
if index > 0:
|
|
761
|
+
options.append(Option(" ", id=f"marketplace-spacer:{index}", disabled=True))
|
|
762
|
+
options.append(
|
|
763
|
+
Option(
|
|
764
|
+
_marketplace_label(row),
|
|
765
|
+
id=f"marketplace:{row.name}",
|
|
766
|
+
)
|
|
767
|
+
)
|
|
768
|
+
return options
|
|
769
|
+
if not self._state.errors:
|
|
770
|
+
return [Option("No plugin errors.", id="empty")]
|
|
771
|
+
return [Option(Content(error), id="empty") for error in self._state.errors]
|
|
772
|
+
|
|
773
|
+
def _divider_width(self) -> int:
|
|
774
|
+
try:
|
|
775
|
+
width = self.query_one("#plugin-manager-options", OptionList).content_size.width
|
|
776
|
+
except NoMatches:
|
|
777
|
+
return self._DIVIDER_FALLBACK_WIDTH
|
|
778
|
+
return width if width > 0 else self._DIVIDER_FALLBACK_WIDTH
|
|
779
|
+
|
|
780
|
+
@staticmethod
|
|
781
|
+
def _nearest_enabled_index(options: OptionList, candidate: int) -> int | None:
|
|
782
|
+
"""Return the nearest selectable option index to candidate."""
|
|
783
|
+
if not options.option_count:
|
|
784
|
+
return None
|
|
785
|
+
if not options.get_option_at_index(candidate).disabled:
|
|
786
|
+
return candidate
|
|
787
|
+
for index in range(candidate + 1, options.option_count):
|
|
788
|
+
if not options.get_option_at_index(index).disabled:
|
|
789
|
+
return index
|
|
790
|
+
for index in range(candidate - 1, -1, -1):
|
|
791
|
+
if not options.get_option_at_index(index).disabled:
|
|
792
|
+
return index
|
|
793
|
+
return None
|
|
794
|
+
|
|
795
|
+
def _details_mode_active(self) -> bool:
|
|
796
|
+
return self._mode in {
|
|
797
|
+
"plugin_details",
|
|
798
|
+
"installed_details",
|
|
799
|
+
"marketplace_details",
|
|
800
|
+
"confirm_remove_marketplace",
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
def _refresh_view(self) -> None:
|
|
804
|
+
title = self.query_one("#plugin-manager-title", Static)
|
|
805
|
+
tabs = self.query_one("#plugin-manager-tabs", Horizontal)
|
|
806
|
+
divider = self.query_one("#plugin-manager-divider", Rule)
|
|
807
|
+
self._update_tab_labels()
|
|
808
|
+
|
|
809
|
+
status_widget = self.query_one("#plugin-manager-status", Static)
|
|
810
|
+
if self._mode == "plugin_details" and self._selected_plugin is not None:
|
|
811
|
+
status_widget.update(_plugin_details_content(self._selected_plugin))
|
|
812
|
+
elif self._mode == "installed_details" and self._selected_plugin is not None:
|
|
813
|
+
status_widget.update(_installed_plugin_details_content(self._selected_plugin))
|
|
814
|
+
elif self._mode == "marketplace_details" and self._selected_marketplace is not None:
|
|
815
|
+
status_widget.update(_marketplace_details_content(self._selected_marketplace))
|
|
816
|
+
elif self._mode == "confirm_remove_marketplace" and self._selected_marketplace is not None:
|
|
817
|
+
status_widget.update(_marketplace_removal_content(self._selected_marketplace))
|
|
818
|
+
else:
|
|
819
|
+
status_widget.update(self._status or "")
|
|
820
|
+
|
|
821
|
+
self.query_one("#plugin-manager-error", Static).update(self._error or "")
|
|
822
|
+
|
|
823
|
+
options = self.query_one("#plugin-manager-options", OptionList)
|
|
824
|
+
search_input = self.query_one("#plugin-manager-search", Input)
|
|
825
|
+
source_input = self.query_one("#plugin-marketplace-source", Input)
|
|
826
|
+
help_text = self.query_one("#plugin-manager-help", Static)
|
|
827
|
+
glyphs = get_glyphs()
|
|
828
|
+
|
|
829
|
+
if self._mode == "add_marketplace":
|
|
830
|
+
title.update("Add Marketplace")
|
|
831
|
+
tabs.display = False
|
|
832
|
+
divider.display = False
|
|
833
|
+
if self._status is None:
|
|
834
|
+
status_widget.update(
|
|
835
|
+
"Enter marketplace source:\n"
|
|
836
|
+
"Examples:\n"
|
|
837
|
+
f" {glyphs.bullet} owner/repo (GitHub)\n"
|
|
838
|
+
f" {glyphs.bullet} https://example.com/marketplace.json\n"
|
|
839
|
+
f" {glyphs.bullet} ./path/to/marketplace"
|
|
840
|
+
)
|
|
841
|
+
options.display = False
|
|
842
|
+
search_input.display = False
|
|
843
|
+
source_input.display = True
|
|
844
|
+
source_input.focus()
|
|
845
|
+
help_text.update(f"Enter to add {glyphs.bullet} Esc to cancel")
|
|
846
|
+
return
|
|
847
|
+
|
|
848
|
+
title.update("Plugins")
|
|
849
|
+
tabs.display = True
|
|
850
|
+
divider.display = True
|
|
851
|
+
|
|
852
|
+
if self._details_mode_active():
|
|
853
|
+
search_input.display = False
|
|
854
|
+
source_input.display = False
|
|
855
|
+
options.display = True
|
|
856
|
+
options.clear_options()
|
|
857
|
+
for option in self._active_details_options():
|
|
858
|
+
options.add_option(option)
|
|
859
|
+
options.focus()
|
|
860
|
+
help_text.update(
|
|
861
|
+
f"{glyphs.arrow_up}/{glyphs.arrow_down} select {glyphs.bullet} Enter choose {glyphs.bullet} Esc back"
|
|
862
|
+
)
|
|
863
|
+
return
|
|
864
|
+
|
|
865
|
+
source_input.display = False
|
|
866
|
+
options.display = True
|
|
867
|
+
search_input.display = self._search_available()
|
|
868
|
+
if search_input.display and search_input.value != self._search_query:
|
|
869
|
+
search_input.value = self._search_query
|
|
870
|
+
highlighted = options.highlighted
|
|
871
|
+
options.clear_options()
|
|
872
|
+
for option in self._current_options():
|
|
873
|
+
options.add_option(option)
|
|
874
|
+
if options.option_count:
|
|
875
|
+
candidate = 0 if highlighted is None else min(highlighted, options.option_count - 1)
|
|
876
|
+
options.highlighted = self._nearest_enabled_index(options, candidate)
|
|
877
|
+
if not search_input.has_focus:
|
|
878
|
+
options.focus()
|
|
879
|
+
|
|
880
|
+
search_hint = f"/ search {glyphs.bullet} " if self._search_available() else ""
|
|
881
|
+
help_text.update(
|
|
882
|
+
f"{glyphs.arrow_up}/{glyphs.arrow_down} select {glyphs.bullet} Enter choose {glyphs.bullet} {search_hint}Left/Right tabs {glyphs.bullet} Esc close"
|
|
883
|
+
)
|
|
884
|
+
|
|
885
|
+
def _active_details_options(self) -> list[Option]:
|
|
886
|
+
if self._mode == "plugin_details":
|
|
887
|
+
return _install_details_options(has_project=self._project_root is not None)
|
|
888
|
+
if self._mode == "installed_details" and self._selected_plugin is not None:
|
|
889
|
+
return _installed_details_options(
|
|
890
|
+
self._selected_plugin, divider_width=self._divider_width()
|
|
891
|
+
)
|
|
892
|
+
if self._mode == "marketplace_details" and self._selected_marketplace is not None:
|
|
893
|
+
return _marketplace_details_options()
|
|
894
|
+
if self._mode == "confirm_remove_marketplace" and self._selected_marketplace is not None:
|
|
895
|
+
return _confirm_marketplace_removal_options(self._selected_marketplace)
|
|
896
|
+
return [Option("Back to plugin list", id="details-back")]
|
|
897
|
+
|
|
898
|
+
async def _refresh_state(self) -> None:
|
|
899
|
+
self._search_query = ""
|
|
900
|
+
self._state = await asyncio.to_thread(
|
|
901
|
+
_load_manager_state,
|
|
902
|
+
self._mcp_server_info,
|
|
903
|
+
loaded_plugin_ids=self._loaded_plugin_ids,
|
|
904
|
+
project_root=self._project_root,
|
|
905
|
+
)
|
|
906
|
+
if self._selected_marketplace is not None:
|
|
907
|
+
updated_mp = next(
|
|
908
|
+
(m for m in self._state.marketplaces if m.name == self._selected_marketplace.name),
|
|
909
|
+
None,
|
|
910
|
+
)
|
|
911
|
+
if updated_mp:
|
|
912
|
+
self._selected_marketplace = updated_mp
|
|
913
|
+
self._refresh_view()
|
|
914
|
+
|
|
915
|
+
def check_action(
|
|
916
|
+
self,
|
|
917
|
+
action: str,
|
|
918
|
+
parameters: tuple[object, ...],
|
|
919
|
+
) -> bool | None:
|
|
920
|
+
"""Gate priority bindings that would otherwise steal Input keystrokes."""
|
|
921
|
+
if action in {"arrow_previous_tab", "arrow_next_tab"}:
|
|
922
|
+
focused = self.focused
|
|
923
|
+
return not (isinstance(focused, Input) and bool(focused.value))
|
|
924
|
+
if action == "focus_search":
|
|
925
|
+
if not self._search_available():
|
|
926
|
+
return False
|
|
927
|
+
try:
|
|
928
|
+
return not self.query_one("#plugin-manager-search", Input).has_focus
|
|
929
|
+
except NoMatches:
|
|
930
|
+
return True
|
|
931
|
+
return True
|
|
932
|
+
|
|
933
|
+
def on_key(self, event: Key) -> None:
|
|
934
|
+
"""Focus plugin search when a letter is typed from another control."""
|
|
935
|
+
if not self._search_available():
|
|
936
|
+
return
|
|
937
|
+
|
|
938
|
+
search_input = self.query_one("#plugin-manager-search", Input)
|
|
939
|
+
if search_input.has_focus:
|
|
940
|
+
return
|
|
941
|
+
|
|
942
|
+
character = event.character
|
|
943
|
+
if not character or not character.isalpha():
|
|
944
|
+
return
|
|
945
|
+
|
|
946
|
+
new_value = f"{search_input.value}{character}"
|
|
947
|
+
search_input.value = new_value
|
|
948
|
+
search_input.selection = type(search_input.selection).cursor(len(new_value))
|
|
949
|
+
search_input.focus()
|
|
950
|
+
event.stop()
|
|
951
|
+
|
|
952
|
+
def on_plugin_tab_selected(self, event: PluginTabSelected) -> None:
|
|
953
|
+
self._select_tab(event.tab)
|
|
954
|
+
|
|
955
|
+
def action_cancel(self) -> None:
|
|
956
|
+
search_input = self.query_one("#plugin-manager-search", Input)
|
|
957
|
+
if search_input.has_focus:
|
|
958
|
+
if self._search_query:
|
|
959
|
+
self._search_query = ""
|
|
960
|
+
search_input.value = ""
|
|
961
|
+
self._refresh_view()
|
|
962
|
+
search_input.focus()
|
|
963
|
+
else:
|
|
964
|
+
self.query_one("#plugin-manager-options", OptionList).focus()
|
|
965
|
+
return
|
|
966
|
+
if self._mode == "add_marketplace":
|
|
967
|
+
self._mode = "list"
|
|
968
|
+
self._error = None
|
|
969
|
+
self._refresh_view()
|
|
970
|
+
return
|
|
971
|
+
if self._details_mode_active():
|
|
972
|
+
if self._mode == "confirm_remove_marketplace":
|
|
973
|
+
self._mode = "marketplace_details"
|
|
974
|
+
self._error = None
|
|
975
|
+
self._refresh_view()
|
|
976
|
+
return
|
|
977
|
+
self._mode = "list"
|
|
978
|
+
self._selected_plugin = None
|
|
979
|
+
self._selected_marketplace = None
|
|
980
|
+
self._error = None
|
|
981
|
+
self._refresh_view()
|
|
982
|
+
return
|
|
983
|
+
self.dismiss(None)
|
|
984
|
+
|
|
985
|
+
def action_focus_search(self) -> None:
|
|
986
|
+
if self._search_available():
|
|
987
|
+
self.query_one("#plugin-manager-search", Input).focus()
|
|
988
|
+
|
|
989
|
+
def action_next_tab(self) -> None:
|
|
990
|
+
if self._details_mode_active():
|
|
991
|
+
return
|
|
992
|
+
index = self._tabs.index(self._tab)
|
|
993
|
+
next_tab = self._tabs[(index + 1) % len(self._tabs)]
|
|
994
|
+
self._select_tab(next_tab)
|
|
995
|
+
|
|
996
|
+
def action_previous_tab(self) -> None:
|
|
997
|
+
if self._details_mode_active():
|
|
998
|
+
return
|
|
999
|
+
index = self._tabs.index(self._tab)
|
|
1000
|
+
prev_tab = self._tabs[(index - 1) % len(self._tabs)]
|
|
1001
|
+
self._select_tab(prev_tab)
|
|
1002
|
+
|
|
1003
|
+
def action_arrow_next_tab(self) -> None:
|
|
1004
|
+
self.action_next_tab()
|
|
1005
|
+
|
|
1006
|
+
def action_arrow_previous_tab(self) -> None:
|
|
1007
|
+
self.action_previous_tab()
|
|
1008
|
+
|
|
1009
|
+
def action_cursor_down(self) -> None:
|
|
1010
|
+
self.query_one("#plugin-manager-options", OptionList).action_cursor_down()
|
|
1011
|
+
|
|
1012
|
+
def action_cursor_up(self) -> None:
|
|
1013
|
+
self.query_one("#plugin-manager-options", OptionList).action_cursor_up()
|
|
1014
|
+
|
|
1015
|
+
def on_input_changed(self, event: Input.Changed) -> None:
|
|
1016
|
+
"""Filter the current plugin list as the search query changes."""
|
|
1017
|
+
if event.input.id != "plugin-manager-search":
|
|
1018
|
+
return
|
|
1019
|
+
self._search_query = event.value
|
|
1020
|
+
self._refresh_view()
|
|
1021
|
+
|
|
1022
|
+
async def on_input_submitted(self, event: Input.Submitted) -> None:
|
|
1023
|
+
if event.input.id == "plugin-manager-search":
|
|
1024
|
+
event.stop()
|
|
1025
|
+
options = self.query_one("#plugin-manager-options", OptionList)
|
|
1026
|
+
highlighted = options.highlighted
|
|
1027
|
+
if highlighted is None:
|
|
1028
|
+
return
|
|
1029
|
+
option_id = options.get_option_at_index(highlighted).id
|
|
1030
|
+
if option_id is None or not option_id.startswith(("detail:", "installed:")):
|
|
1031
|
+
return
|
|
1032
|
+
options.focus()
|
|
1033
|
+
options.action_select()
|
|
1034
|
+
return
|
|
1035
|
+
if event.input.id == "plugin-marketplace-source":
|
|
1036
|
+
source = event.value.strip()
|
|
1037
|
+
if not source:
|
|
1038
|
+
return
|
|
1039
|
+
self._status = "Adding marketplace..."
|
|
1040
|
+
self._refresh_view()
|
|
1041
|
+
try:
|
|
1042
|
+
await asyncio.to_thread(add_marketplace_source, source)
|
|
1043
|
+
self._mode = "list"
|
|
1044
|
+
self._tab = "discover"
|
|
1045
|
+
self._status = "Marketplace added."
|
|
1046
|
+
await self._refresh_state()
|
|
1047
|
+
except Exception as exc:
|
|
1048
|
+
self._status = None
|
|
1049
|
+
self._error = str(exc)
|
|
1050
|
+
self._refresh_view()
|
|
1051
|
+
|
|
1052
|
+
async def on_option_list_option_selected(self, event: OptionList.OptionSelected) -> None:
|
|
1053
|
+
option_id = event.option.id
|
|
1054
|
+
if option_id is None or option_id == "empty":
|
|
1055
|
+
return
|
|
1056
|
+
if option_id == "add-marketplace":
|
|
1057
|
+
self._mode = "add_marketplace"
|
|
1058
|
+
self._status = None
|
|
1059
|
+
self._error = None
|
|
1060
|
+
self._refresh_view()
|
|
1061
|
+
return
|
|
1062
|
+
if option_id == "refresh-all-marketplaces":
|
|
1063
|
+
self._status = "Refreshing all marketplaces..."
|
|
1064
|
+
self._refresh_view()
|
|
1065
|
+
try:
|
|
1066
|
+
from opscloud.plugins.discovery import refresh_all_marketplaces
|
|
1067
|
+
|
|
1068
|
+
await asyncio.to_thread(
|
|
1069
|
+
refresh_all_marketplaces,
|
|
1070
|
+
project_root=self._project_root,
|
|
1071
|
+
)
|
|
1072
|
+
self._status = "All marketplaces refreshed."
|
|
1073
|
+
await self._refresh_state()
|
|
1074
|
+
except Exception as exc:
|
|
1075
|
+
self._status = None
|
|
1076
|
+
self._error = str(exc)
|
|
1077
|
+
self._refresh_view()
|
|
1078
|
+
return
|
|
1079
|
+
if option_id.startswith("marketplace:"):
|
|
1080
|
+
name = option_id.removeprefix("marketplace:")
|
|
1081
|
+
row = next((r for r in self._state.marketplaces if r.name == name), None)
|
|
1082
|
+
if row:
|
|
1083
|
+
self._selected_marketplace = row
|
|
1084
|
+
self._mode = "marketplace_details"
|
|
1085
|
+
self._refresh_view()
|
|
1086
|
+
return
|
|
1087
|
+
if option_id.startswith("detail:"):
|
|
1088
|
+
plugin_id = option_id.removeprefix("detail:")
|
|
1089
|
+
row = next((r for r in self._state.available_plugins if r.plugin_id == plugin_id), None)
|
|
1090
|
+
if row:
|
|
1091
|
+
self._selected_plugin = row
|
|
1092
|
+
self._mode = "plugin_details"
|
|
1093
|
+
self._refresh_view()
|
|
1094
|
+
return
|
|
1095
|
+
if option_id.startswith("installed:"):
|
|
1096
|
+
plugin_id = option_id.removeprefix("installed:")
|
|
1097
|
+
row = next((r for r in self._state.installed_plugins if r.plugin_id == plugin_id), None)
|
|
1098
|
+
if row:
|
|
1099
|
+
self._selected_plugin = row
|
|
1100
|
+
self._mode = "installed_details"
|
|
1101
|
+
self._refresh_view()
|
|
1102
|
+
return
|
|
1103
|
+
if option_id in ("action:install-user", "action:install-project", "action:install-local"):
|
|
1104
|
+
if self._selected_plugin:
|
|
1105
|
+
scope_map: dict[str, InstallScope] = {
|
|
1106
|
+
"action:install-user": "user",
|
|
1107
|
+
"action:install-project": "project",
|
|
1108
|
+
"action:install-local": "local",
|
|
1109
|
+
}
|
|
1110
|
+
scope = scope_map[option_id]
|
|
1111
|
+
self._status = f"Installing {self._selected_plugin.label}..."
|
|
1112
|
+
self._refresh_view()
|
|
1113
|
+
try:
|
|
1114
|
+
await asyncio.to_thread(
|
|
1115
|
+
install_plugin,
|
|
1116
|
+
self._selected_plugin.plugin_id,
|
|
1117
|
+
scope=scope,
|
|
1118
|
+
project_root=self._project_root,
|
|
1119
|
+
)
|
|
1120
|
+
self._mode = "list"
|
|
1121
|
+
self._tab = "installed"
|
|
1122
|
+
scope_labels = {"user": "for you", "project": "for all collaborators", "local": "for you in this repo"}
|
|
1123
|
+
self._status = f"Installed {self._selected_plugin.label} ({scope_labels[scope]})."
|
|
1124
|
+
await self._refresh_state()
|
|
1125
|
+
except Exception as exc:
|
|
1126
|
+
self._status = None
|
|
1127
|
+
self._error = str(exc)
|
|
1128
|
+
self._refresh_view()
|
|
1129
|
+
return
|
|
1130
|
+
if option_id == "action:toggle-enabled":
|
|
1131
|
+
if self._selected_plugin:
|
|
1132
|
+
new_state = not self._selected_plugin.enabled
|
|
1133
|
+
try:
|
|
1134
|
+
await asyncio.to_thread(
|
|
1135
|
+
set_installed_plugin_enabled, self._selected_plugin.plugin_id, enabled=new_state
|
|
1136
|
+
)
|
|
1137
|
+
await self._refresh_state()
|
|
1138
|
+
except Exception as exc:
|
|
1139
|
+
self._error = str(exc)
|
|
1140
|
+
self._refresh_view()
|
|
1141
|
+
return
|
|
1142
|
+
if option_id == "action:uninstall":
|
|
1143
|
+
if self._selected_plugin:
|
|
1144
|
+
self._status = f"Uninstalling {self._selected_plugin.label}..."
|
|
1145
|
+
self._refresh_view()
|
|
1146
|
+
try:
|
|
1147
|
+
await asyncio.to_thread(
|
|
1148
|
+
uninstall_plugin,
|
|
1149
|
+
self._selected_plugin.plugin_id,
|
|
1150
|
+
scope=self._selected_plugin.scope,
|
|
1151
|
+
project_root=self._project_root,
|
|
1152
|
+
)
|
|
1153
|
+
self._mode = "list"
|
|
1154
|
+
self._selected_plugin = None
|
|
1155
|
+
self._status = "Plugin uninstalled."
|
|
1156
|
+
await self._refresh_state()
|
|
1157
|
+
except Exception as exc:
|
|
1158
|
+
self._status = None
|
|
1159
|
+
self._error = str(exc)
|
|
1160
|
+
self._refresh_view()
|
|
1161
|
+
return
|
|
1162
|
+
if option_id == "action:refresh-marketplace":
|
|
1163
|
+
if self._selected_marketplace:
|
|
1164
|
+
self._status = f"Refreshing marketplace {self._selected_marketplace.name}..."
|
|
1165
|
+
self._refresh_view()
|
|
1166
|
+
try:
|
|
1167
|
+
from opscloud.plugins.discovery import refresh_marketplace
|
|
1168
|
+
|
|
1169
|
+
mp = await asyncio.to_thread(
|
|
1170
|
+
refresh_marketplace,
|
|
1171
|
+
self._selected_marketplace.name,
|
|
1172
|
+
project_root=self._project_root,
|
|
1173
|
+
)
|
|
1174
|
+
self._status = f"Marketplace refreshed ({len(mp.plugins)} available)."
|
|
1175
|
+
await self._refresh_state()
|
|
1176
|
+
except Exception as exc:
|
|
1177
|
+
self._status = None
|
|
1178
|
+
self._error = str(exc)
|
|
1179
|
+
self._refresh_view()
|
|
1180
|
+
return
|
|
1181
|
+
if option_id == "action:remove-marketplace":
|
|
1182
|
+
self._mode = "confirm_remove_marketplace"
|
|
1183
|
+
self._refresh_view()
|
|
1184
|
+
return
|
|
1185
|
+
if option_id == "action:confirm-remove-marketplace":
|
|
1186
|
+
if self._selected_marketplace:
|
|
1187
|
+
self._status = f"Removing marketplace {self._selected_marketplace.name}..."
|
|
1188
|
+
self._refresh_view()
|
|
1189
|
+
try:
|
|
1190
|
+
await asyncio.to_thread(remove_marketplace, self._selected_marketplace.name)
|
|
1191
|
+
self._mode = "list"
|
|
1192
|
+
self._selected_marketplace = None
|
|
1193
|
+
self._status = "Marketplace removed."
|
|
1194
|
+
await self._refresh_state()
|
|
1195
|
+
except Exception as exc:
|
|
1196
|
+
self._status = None
|
|
1197
|
+
self._error = str(exc)
|
|
1198
|
+
self._refresh_view()
|
|
1199
|
+
return
|
|
1200
|
+
if option_id == "details-back":
|
|
1201
|
+
self._mode = "list"
|
|
1202
|
+
self._selected_plugin = None
|
|
1203
|
+
self._selected_marketplace = None
|
|
1204
|
+
self._refresh_view()
|
|
1205
|
+
|
|
1206
|
+
|
|
1207
|
+
__all__ = [
|
|
1208
|
+
"PluginManagerScreen",
|
|
1209
|
+
"PluginTabLabel",
|
|
1210
|
+
"PluginTabSelected",
|
|
1211
|
+
"_install_details_options",
|
|
1212
|
+
]
|