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.
Files changed (309) hide show
  1. opscloud/__init__.py +5 -0
  2. opscloud/__main__.py +6 -0
  3. opscloud/_constants.py +53 -0
  4. opscloud/_debug.py +145 -0
  5. opscloud/_debug_buffer.py +250 -0
  6. opscloud/_textual_patches.py +367 -0
  7. opscloud/_version.py +15 -0
  8. opscloud/agent/__init__.py +27 -0
  9. opscloud/agent/config.py +168 -0
  10. opscloud/agent/factory.py +1103 -0
  11. opscloud/approval_mode.py +44 -0
  12. opscloud/backend/__init__.py +49 -0
  13. opscloud/backend/composite.py +89 -0
  14. opscloud/backend/local.py +183 -0
  15. opscloud/backend/registry.py +79 -0
  16. opscloud/backend/sandbox_config.py +107 -0
  17. opscloud/backend/sandbox_factory.py +432 -0
  18. opscloud/built_in_skills/remember/SKILL.md +124 -0
  19. opscloud/built_in_skills/skill-creator/SKILL.md +348 -0
  20. opscloud/built_in_skills/skill-creator/scripts/init_skill.py +371 -0
  21. opscloud/built_in_skills/skill-creator/scripts/quick_validate.py +165 -0
  22. opscloud/cli/__init__.py +1 -0
  23. opscloud/cli/commands/__init__.py +15 -0
  24. opscloud/cli/commands/auth.py +45 -0
  25. opscloud/cli/commands/doctor.py +100 -0
  26. opscloud/cli/commands/mcp.py +137 -0
  27. opscloud/cli/commands/threads.py +51 -0
  28. opscloud/cli/interactive.py +154 -0
  29. opscloud/cli/main.py +903 -0
  30. opscloud/cli/non_interactive.py +425 -0
  31. opscloud/cli/server_manager.py +58 -0
  32. opscloud/commands/__init__.py +19 -0
  33. opscloud/commands/_base.py +110 -0
  34. opscloud/commands/_guards.py +52 -0
  35. opscloud/commands/_router.py +146 -0
  36. opscloud/commands/_types.py +36 -0
  37. opscloud/commands/core/__init__.py +47 -0
  38. opscloud/commands/core/auth.py +94 -0
  39. opscloud/commands/core/bug.py +46 -0
  40. opscloud/commands/core/clear.py +106 -0
  41. opscloud/commands/core/cloud.py +185 -0
  42. opscloud/commands/core/compact.py +128 -0
  43. opscloud/commands/core/config_cmd.py +120 -0
  44. opscloud/commands/core/context.py +220 -0
  45. opscloud/commands/core/cost.py +44 -0
  46. opscloud/commands/core/doctor.py +535 -0
  47. opscloud/commands/core/effort.py +108 -0
  48. opscloud/commands/core/exit_cmd.py +41 -0
  49. opscloud/commands/core/fast.py +148 -0
  50. opscloud/commands/core/help_cmd.py +94 -0
  51. opscloud/commands/core/mcp.py +134 -0
  52. opscloud/commands/core/model.py +109 -0
  53. opscloud/commands/core/permissions.py +196 -0
  54. opscloud/commands/core/plugins.py +92 -0
  55. opscloud/commands/core/pool.py +108 -0
  56. opscloud/commands/core/resume.py +97 -0
  57. opscloud/commands/core/skills.py +178 -0
  58. opscloud/commands/power/__init__.py +51 -0
  59. opscloud/commands/power/agents.py +98 -0
  60. opscloud/commands/power/btw.py +85 -0
  61. opscloud/commands/power/copy.py +97 -0
  62. opscloud/commands/power/goal.py +548 -0
  63. opscloud/commands/power/loop.py +295 -0
  64. opscloud/commands/power/memory.py +287 -0
  65. opscloud/commands/power/review.py +152 -0
  66. opscloud/commands/power/rubric.py +287 -0
  67. opscloud/commands/power/runtime.py +321 -0
  68. opscloud/commands/power/skill_creator.py +70 -0
  69. opscloud/commands/power/skill_invoke.py +165 -0
  70. opscloud/commands/power/tasks.py +209 -0
  71. opscloud/commands/power/trace.py +117 -0
  72. opscloud/commands/power/ui_toggles.py +135 -0
  73. opscloud/commands/power/version.py +52 -0
  74. opscloud/commands/registry.py +176 -0
  75. opscloud/config/__init__.py +114 -0
  76. opscloud/config/adapters/__init__.py +5 -0
  77. opscloud/config/adapters/postgres.py +776 -0
  78. opscloud/config/adapters/sqlite.py +769 -0
  79. opscloud/config/aws.py +248 -0
  80. opscloud/config/cloud_profiles.py +437 -0
  81. opscloud/config/env_vars.py +81 -0
  82. opscloud/config/langsmith.py +319 -0
  83. opscloud/config/manifest.py +817 -0
  84. opscloud/config/metadata.py +205 -0
  85. opscloud/config/paths.py +604 -0
  86. opscloud/config/plugins.py +130 -0
  87. opscloud/config/settings.py +834 -0
  88. opscloud/config/store.py +453 -0
  89. opscloud/config/store_factory.py +97 -0
  90. opscloud/config/toml_config.py +562 -0
  91. opscloud/editor.py +173 -0
  92. opscloud/exceptions.py +65 -0
  93. opscloud/file_ops.py +217 -0
  94. opscloud/hooks/__init__.py +139 -0
  95. opscloud/hooks/env.py +44 -0
  96. opscloud/hooks/interrupt.py +121 -0
  97. opscloud/hooks/models/__init__.py +109 -0
  98. opscloud/hooks/models/adapters.py +19 -0
  99. opscloud/hooks/models/config.py +79 -0
  100. opscloud/hooks/models/domain.py +434 -0
  101. opscloud/hooks/models/transport.py +37 -0
  102. opscloud/hooks/tools.py +231 -0
  103. opscloud/input.py +48 -0
  104. opscloud/integrations/__init__.py +80 -0
  105. opscloud/integrations/base.py +153 -0
  106. opscloud/integrations/content_filter.py +119 -0
  107. opscloud/integrations/event_bus.py +480 -0
  108. opscloud/integrations/hooks.py +238 -0
  109. opscloud/integrations/identity.py +181 -0
  110. opscloud/integrations/notifications.py +134 -0
  111. opscloud/integrations/stream_bridge.py +397 -0
  112. opscloud/integrations/thread_store.py +81 -0
  113. opscloud/json_types.py +20 -0
  114. opscloud/mcp/__init__.py +57 -0
  115. opscloud/mcp/config.py +203 -0
  116. opscloud/mcp/discovery.py +229 -0
  117. opscloud/mcp/mcp_info.py +109 -0
  118. opscloud/mcp/middleware.py +102 -0
  119. opscloud/mcp/preload.py +505 -0
  120. opscloud/mcp/raw_config.py +149 -0
  121. opscloud/mcp/semantic_profiler.py +305 -0
  122. opscloud/mcp/session_manager.py +727 -0
  123. opscloud/mcp/trust.py +105 -0
  124. opscloud/memory/__init__.py +27 -0
  125. opscloud/memory/branch.py +61 -0
  126. opscloud/memory/guard.py +19 -0
  127. opscloud/memory/onboarding.py +120 -0
  128. opscloud/memory/registry.py +134 -0
  129. opscloud/memory/store.py +223 -0
  130. opscloud/middleware/__init__.py +106 -0
  131. opscloud/middleware/_repository_bounds.py +459 -0
  132. opscloud/middleware/ask_user.py +152 -0
  133. opscloud/middleware/auto_mode.py +60 -0
  134. opscloud/middleware/auto_mode_hitl.py +2434 -0
  135. opscloud/middleware/compaction.py +566 -0
  136. opscloud/middleware/configurable_model.py +233 -0
  137. opscloud/middleware/cost_tracking.py +1021 -0
  138. opscloud/middleware/glm_stall_recovery.py +109 -0
  139. opscloud/middleware/goal_criteria.py +1234 -0
  140. opscloud/middleware/goal_state_notice.py +712 -0
  141. opscloud/middleware/goal_tools.py +407 -0
  142. opscloud/middleware/headless_mcp_guard.py +88 -0
  143. opscloud/middleware/jev_model_router.py +1018 -0
  144. opscloud/middleware/local_context.py +460 -0
  145. opscloud/middleware/mcp_context.py +151 -0
  146. opscloud/middleware/mcp_middleware.py +146 -0
  147. opscloud/middleware/memory_guard.py +393 -0
  148. opscloud/middleware/model_retry.py +205 -0
  149. opscloud/middleware/registry.py +137 -0
  150. opscloud/middleware/reliable_rubric.py +709 -0
  151. opscloud/middleware/resume_state.py +91 -0
  152. opscloud/middleware/server_hooks.py +1189 -0
  153. opscloud/middleware/shell_allow_list.py +90 -0
  154. opscloud/middleware/skills.py +382 -0
  155. opscloud/middleware/subagent_artifacts.py +84 -0
  156. opscloud/middleware/subagent_telemetry.py +261 -0
  157. opscloud/middleware/subagents.py +243 -0
  158. opscloud/middleware/tool_filter.py +384 -0
  159. opscloud/middleware/unified_system_message.py +62 -0
  160. opscloud/model/__init__.py +37 -0
  161. opscloud/model/config.py +2992 -0
  162. opscloud/model/factory.py +477 -0
  163. opscloud/model/pool.py +459 -0
  164. opscloud/model/reasoning.py +282 -0
  165. opscloud/offload.py +173 -0
  166. opscloud/output.py +64 -0
  167. opscloud/plugins/__init__.py +189 -0
  168. opscloud/plugins/_json.py +22 -0
  169. opscloud/plugins/adapters/__init__.py +13 -0
  170. opscloud/plugins/adapters/agents.py +112 -0
  171. opscloud/plugins/adapters/commands.py +190 -0
  172. opscloud/plugins/adapters/mcp.py +363 -0
  173. opscloud/plugins/adapters/skills.py +132 -0
  174. opscloud/plugins/commands_cli.py +541 -0
  175. opscloud/plugins/discovery.py +512 -0
  176. opscloud/plugins/manifest.py +335 -0
  177. opscloud/plugins/marketplace.py +893 -0
  178. opscloud/plugins/models.py +334 -0
  179. opscloud/plugins/project_plugins.py +317 -0
  180. opscloud/plugins/protocol.py +31 -0
  181. opscloud/plugins/store.py +905 -0
  182. opscloud/plugins/substitution.py +122 -0
  183. opscloud/project_utils.py +145 -0
  184. opscloud/prompts/__init__.py +37 -0
  185. opscloud/prompts/system.py +483 -0
  186. opscloud/prompts/templates/system_prompt.md +166 -0
  187. opscloud/prompts/types.py +54 -0
  188. opscloud/rubrics/__init__.py +42 -0
  189. opscloud/rubrics/evaluator.py +404 -0
  190. opscloud/rubrics/evidence_extractor.py +229 -0
  191. opscloud/rubrics/generator.py +239 -0
  192. opscloud/rubrics/jev_compiler.py +175 -0
  193. opscloud/rubrics/jev_grader.py +297 -0
  194. opscloud/rubrics/middleware.py +8 -0
  195. opscloud/schema/__init__.py +107 -0
  196. opscloud/schema/interrupts.py +981 -0
  197. opscloud/security/__init__.py +91 -0
  198. opscloud/security/approval_mode.py +528 -0
  199. opscloud/security/approval_mode_source.py +230 -0
  200. opscloud/security/cli_ast_evaluator.py +552 -0
  201. opscloud/security/jev_classifier.py +651 -0
  202. opscloud/security/shell_safety.py +340 -0
  203. opscloud/security/unicode_security.py +439 -0
  204. opscloud/security/url_validation.py +160 -0
  205. opscloud/server/__init__.py +13 -0
  206. opscloud/server/_server_config.py +158 -0
  207. opscloud/server/server.py +242 -0
  208. opscloud/server/server_graph.py +93 -0
  209. opscloud/skills/__init__.py +91 -0
  210. opscloud/skills/commands.py +1099 -0
  211. opscloud/skills/invocation.py +200 -0
  212. opscloud/skills/load.py +388 -0
  213. opscloud/skills/loader.py +23 -0
  214. opscloud/skills/merge.py +65 -0
  215. opscloud/skills/registry.py +263 -0
  216. opscloud/skills/sources.py +174 -0
  217. opscloud/skills/trust.py +417 -0
  218. opscloud/state/__init__.py +142 -0
  219. opscloud/state/base.py +154 -0
  220. opscloud/state/cloud_context.py +262 -0
  221. opscloud/state/goal_channels.py +124 -0
  222. opscloud/state/goal_state_limits.py +175 -0
  223. opscloud/state/resume_state.py +58 -0
  224. opscloud/state/service_context.py +281 -0
  225. opscloud/state/session.py +957 -0
  226. opscloud/state/state_migration.py +86 -0
  227. opscloud/subagents/__init__.py +30 -0
  228. opscloud/subagents/loader.py +331 -0
  229. opscloud/subagents/subagents_parser.py +117 -0
  230. opscloud/subagents/types.py +25 -0
  231. opscloud/tools/__init__.py +36 -0
  232. opscloud/tools/catalog.py +37 -0
  233. opscloud/tools/display.py +24 -0
  234. opscloud/tools/fetch_url.py +176 -0
  235. opscloud/tools/goal_tools.py +423 -0
  236. opscloud/tools/registry.py +105 -0
  237. opscloud/tools/thread.py +32 -0
  238. opscloud/tools/web_search.py +215 -0
  239. opscloud/ui/__init__.py +119 -0
  240. opscloud/ui/app.py +5400 -0
  241. opscloud/ui/app.tcss +479 -0
  242. opscloud/ui/clipboard.py +147 -0
  243. opscloud/ui/command_registry.py +482 -0
  244. opscloud/ui/message_store.py +152 -0
  245. opscloud/ui/permission_store.py +360 -0
  246. opscloud/ui/preferences.py +113 -0
  247. opscloud/ui/prompt_manager.py +96 -0
  248. opscloud/ui/remote_client.py +505 -0
  249. opscloud/ui/textual_adapter.py +1269 -0
  250. opscloud/ui/theme.py +728 -0
  251. opscloud/ui/ui_help.py +415 -0
  252. opscloud/ui/widgets/__init__.py +383 -0
  253. opscloud/ui/widgets/_ask_user_types.py +81 -0
  254. opscloud/ui/widgets/_copy_spans.py +52 -0
  255. opscloud/ui/widgets/_inline_prompt.py +290 -0
  256. opscloud/ui/widgets/_js_eval_display.py +139 -0
  257. opscloud/ui/widgets/_links.py +175 -0
  258. opscloud/ui/widgets/_tool_stream.py +308 -0
  259. opscloud/ui/widgets/agent_selector.py +297 -0
  260. opscloud/ui/widgets/approval.py +741 -0
  261. opscloud/ui/widgets/ask_user.py +539 -0
  262. opscloud/ui/widgets/auth.py +695 -0
  263. opscloud/ui/widgets/auth_manager.py +214 -0
  264. opscloud/ui/widgets/auto_mode_notice.py +146 -0
  265. opscloud/ui/widgets/autocomplete.py +709 -0
  266. opscloud/ui/widgets/chat_input.py +805 -0
  267. opscloud/ui/widgets/cloud_selector.py +528 -0
  268. opscloud/ui/widgets/config_manager.py +652 -0
  269. opscloud/ui/widgets/debug_console.py +1269 -0
  270. opscloud/ui/widgets/devops_renderers.py +184 -0
  271. opscloud/ui/widgets/diff.py +237 -0
  272. opscloud/ui/widgets/effort_selector.py +166 -0
  273. opscloud/ui/widgets/goal_review.py +612 -0
  274. opscloud/ui/widgets/goal_status.py +57 -0
  275. opscloud/ui/widgets/infra_panel.py +141 -0
  276. opscloud/ui/widgets/install_confirm.py +114 -0
  277. opscloud/ui/widgets/loading.py +170 -0
  278. opscloud/ui/widgets/mcp_viewer.py +1204 -0
  279. opscloud/ui/widgets/messages.py +4461 -0
  280. opscloud/ui/widgets/model_selector.py +863 -0
  281. opscloud/ui/widgets/notification_center.py +108 -0
  282. opscloud/ui/widgets/notification_settings.py +119 -0
  283. opscloud/ui/widgets/operation_card.py +106 -0
  284. opscloud/ui/widgets/permissions_manager.py +667 -0
  285. opscloud/ui/widgets/plugin_manager.py +1212 -0
  286. opscloud/ui/widgets/pool_selector.py +376 -0
  287. opscloud/ui/widgets/preamble.py +53 -0
  288. opscloud/ui/widgets/skills_viewer.py +432 -0
  289. opscloud/ui/widgets/status.py +1037 -0
  290. opscloud/ui/widgets/subagent_panel.py +927 -0
  291. opscloud/ui/widgets/theme_selector.py +232 -0
  292. opscloud/ui/widgets/thread_selector.py +358 -0
  293. opscloud/ui/widgets/toast.py +31 -0
  294. opscloud/ui/widgets/tool_display.py +325 -0
  295. opscloud/ui/widgets/tool_renderers.py +234 -0
  296. opscloud/ui/widgets/tool_widgets.py +278 -0
  297. opscloud/ui/widgets/welcome.py +421 -0
  298. opscloud/ui/widgets/welcome_popup.py +102 -0
  299. opscloud/utils/__init__.py +24 -0
  300. opscloud/utils/cost_estimation.py +169 -0
  301. opscloud/utils/git.py +390 -0
  302. opscloud/utils/logger.py +571 -0
  303. opscloud/utils/session_stats.py +115 -0
  304. opscloud/utils/startup_error.py +37 -0
  305. talkops_opscloud-0.3.0b1.dist-info/METADATA +449 -0
  306. talkops_opscloud-0.3.0b1.dist-info/RECORD +309 -0
  307. talkops_opscloud-0.3.0b1.dist-info/WHEEL +4 -0
  308. talkops_opscloud-0.3.0b1.dist-info/entry_points.txt +2 -0
  309. talkops_opscloud-0.3.0b1.dist-info/licenses/LICENSE +175 -0
@@ -0,0 +1,189 @@
1
+ """OpsCloud Plugin System.
2
+
3
+ Provides plugin discovery, marketplace management, and plugin protocol
4
+ for extending OpsCloud with new skills, subagents, MCP servers, and capabilities.
5
+ All state is stored purely in the local filesystem (~/.opscloud/ and .opscloud/).
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import importlib.metadata
11
+ from typing import Any, Protocol
12
+
13
+ from opscloud.utils.logger import get_logger
14
+
15
+ from opscloud.plugins.adapters.skills import (
16
+ namespaced_skill_name,
17
+ plugin_skill_roots,
18
+ plugin_skill_sources,
19
+ )
20
+ from opscloud.plugins.commands_cli import (
21
+ execute_plugin_command,
22
+ setup_plugin_parser,
23
+ )
24
+ from opscloud.config import (
25
+ DEFAULT_MARKETPLACE_CONFIGS,
26
+ DefaultMarketplaceConfig,
27
+ fetch_marketplace_manifest,
28
+ get_default_marketplace_config,
29
+ is_default_marketplace,
30
+ )
31
+ from opscloud.plugins.discovery import (
32
+ add_local_marketplace,
33
+ add_marketplace_source,
34
+ discover_plugins as discover_marketplace_plugins,
35
+ install_plugin,
36
+ list_available_plugins,
37
+ list_installed_plugin_ids,
38
+ refresh_all_marketplaces,
39
+ refresh_marketplace,
40
+ remove_marketplace,
41
+ set_installed_plugin_enabled,
42
+ uninstall_plugin,
43
+ )
44
+ from opscloud.plugins.manifest import (
45
+ PluginManifestError,
46
+ build_inventory,
47
+ find_manifest_path,
48
+ load_manifest,
49
+ )
50
+ from opscloud.plugins.marketplace import (
51
+ MarketplaceError,
52
+ find_marketplace_manifest,
53
+ load_marketplace,
54
+ load_marketplace_location,
55
+ materialize_marketplace_source,
56
+ materialize_plugin_source,
57
+ parse_marketplace_source,
58
+ )
59
+ from opscloud.plugins.models import (
60
+ ComponentInventory,
61
+ InstalledPluginEntry,
62
+ MarketplacePluginEntry,
63
+ MarketplaceRecord,
64
+ PluginDiscoveryResult,
65
+ PluginInstance,
66
+ PluginManifest,
67
+ PluginMarketplace,
68
+ PluginSource,
69
+ split_plugin_id,
70
+ )
71
+ from opscloud.plugins.store import (
72
+ cache_and_register_plugin,
73
+ load_all_enabled_plugin_ids,
74
+ load_installed_plugins,
75
+ load_marketplace_records,
76
+ versioned_cache_path,
77
+ )
78
+
79
+ logger = get_logger(__name__)
80
+
81
+
82
+ class OpsCloudPlugin(Protocol):
83
+ """Protocol interface that external python plugins may implement."""
84
+
85
+ name: str
86
+
87
+ def register_commands(self) -> list[Any]:
88
+ """Return custom slash commands registered by this plugin."""
89
+ ...
90
+
91
+ def register_tools(self) -> list[Any]:
92
+ """Return custom tools registered by this plugin."""
93
+ ...
94
+
95
+ def register_renderers(self) -> dict[str, Any]:
96
+ """Return custom tool renderers registered by this plugin."""
97
+ ...
98
+
99
+ def get_theme_overrides(self) -> dict[str, str] | None:
100
+ """Return custom theme overrides if provided."""
101
+ ...
102
+
103
+
104
+ class TerraformPlugin:
105
+ """Built-in plugin for Terraform infrastructure tooling."""
106
+
107
+ name = "terraform"
108
+
109
+ def register_commands(self) -> list[Any]:
110
+ return []
111
+
112
+ def register_tools(self) -> list[Any]:
113
+ return []
114
+
115
+ def register_renderers(self) -> dict[str, Any]:
116
+ return {}
117
+
118
+ def get_theme_overrides(self) -> dict[str, str] | None:
119
+ return None
120
+
121
+
122
+ def discover_plugins() -> list[OpsCloudPlugin]:
123
+ """Discover and return all active Python plugins (built-in + entrypoints)."""
124
+ plugins: list[OpsCloudPlugin] = [TerraformPlugin()]
125
+ try:
126
+ eps = importlib.metadata.entry_points(group="opscloud.plugins")
127
+ for ep in eps:
128
+ try:
129
+ plugin_cls = ep.load()
130
+ plugins.append(plugin_cls())
131
+ except Exception as e:
132
+ logger.warning("Failed to load plugin entry point %s: %s", ep.name, e)
133
+ except Exception:
134
+ pass
135
+ return plugins
136
+
137
+
138
+ __all__ = [
139
+ "ComponentInventory",
140
+ "DEFAULT_MARKETPLACE_CONFIGS",
141
+ "DefaultMarketplaceConfig",
142
+ "InstalledPluginEntry",
143
+ "MarketplaceError",
144
+ "MarketplacePluginEntry",
145
+ "MarketplaceRecord",
146
+ "OpsCloudPlugin",
147
+ "PluginDiscoveryResult",
148
+ "PluginInstance",
149
+ "PluginManifest",
150
+ "PluginManifestError",
151
+ "PluginMarketplace",
152
+ "PluginSource",
153
+ "TerraformPlugin",
154
+ "add_local_marketplace",
155
+ "add_marketplace_source",
156
+ "build_inventory",
157
+ "cache_and_register_plugin",
158
+ "discover_marketplace_plugins",
159
+ "discover_plugins",
160
+ "execute_plugin_command",
161
+ "fetch_marketplace_manifest",
162
+ "find_manifest_path",
163
+ "find_marketplace_manifest",
164
+ "get_default_marketplace_config",
165
+ "install_plugin",
166
+ "is_default_marketplace",
167
+ "list_available_plugins",
168
+ "list_installed_plugin_ids",
169
+ "load_all_enabled_plugin_ids",
170
+ "load_installed_plugins",
171
+ "load_manifest",
172
+ "load_marketplace",
173
+ "load_marketplace_location",
174
+ "load_marketplace_records",
175
+ "materialize_marketplace_source",
176
+ "materialize_plugin_source",
177
+ "namespaced_skill_name",
178
+ "parse_marketplace_source",
179
+ "plugin_skill_roots",
180
+ "plugin_skill_sources",
181
+ "refresh_all_marketplaces",
182
+ "refresh_marketplace",
183
+ "remove_marketplace",
184
+ "set_installed_plugin_enabled",
185
+ "setup_plugin_parser",
186
+ "split_plugin_id",
187
+ "uninstall_plugin",
188
+ "versioned_cache_path",
189
+ ]
@@ -0,0 +1,22 @@
1
+ """JSON parsing utilities for plugins."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from pathlib import Path
7
+ from typing import Any
8
+
9
+
10
+ def json_object(value: Any) -> dict[str, Any]:
11
+ if isinstance(value, dict):
12
+ return value
13
+ return {}
14
+
15
+
16
+ def load_json_file(path: Path) -> dict[str, Any] | None:
17
+ if not path.is_file():
18
+ return None
19
+ try:
20
+ return json.loads(path.read_text(encoding="utf-8"))
21
+ except Exception:
22
+ return None
@@ -0,0 +1,13 @@
1
+ """Plugin adapters package for K8s Autopilot."""
2
+
3
+ from opscloud.plugins.adapters.skills import (
4
+ namespaced_skill_name,
5
+ plugin_skill_roots,
6
+ plugin_skill_sources,
7
+ )
8
+
9
+ __all__ = [
10
+ "namespaced_skill_name",
11
+ "plugin_skill_roots",
12
+ "plugin_skill_sources",
13
+ ]
@@ -0,0 +1,112 @@
1
+ """Adapter from discovered plugins to K8s Autopilot subagent metadata."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+ from typing import TYPE_CHECKING, Any
7
+
8
+ if TYPE_CHECKING:
9
+ from collections.abc import Mapping
10
+ from opscloud.plugins.models import PluginInstance
11
+ from opscloud.subagents.types import SubagentMetadata
12
+
13
+ from opscloud.utils.logger import get_logger
14
+
15
+ logger = get_logger(__name__)
16
+
17
+
18
+ def _enrich_plugin_subagent(meta: SubagentMetadata, plugin: PluginInstance) -> SubagentMetadata:
19
+ p_id = plugin.plugin_id
20
+ raw_name = meta.get("name", "")
21
+
22
+ if not raw_name or raw_name == plugin.name or p_id.startswith(f"{raw_name}@"):
23
+ meta["name"] = p_id
24
+ elif not raw_name.startswith(f"{p_id}:"):
25
+ meta["name"] = f"{p_id}:{raw_name}"
26
+
27
+ meta["source"] = f"plugin:{p_id}"
28
+ meta["plugin_id"] = p_id
29
+ meta["bundle_dir"] = str(plugin.root)
30
+
31
+ skills_dir = plugin.root / "skills"
32
+ if skills_dir.is_dir():
33
+ meta["skills_dir"] = str(skills_dir)
34
+
35
+ # Attach default plugin skill wildcard if no skills explicitly set
36
+ if not meta.get("skills"):
37
+ meta["skills"] = [f"{p_id}:*"]
38
+
39
+ # Attach plugin MCP files or inline config if subagent doesn't specify own
40
+ if "mcp_config" not in meta and "mcp_files" not in meta:
41
+ if plugin.inventory.mcp_files:
42
+ meta["mcp_files"] = [str(p) for p in plugin.inventory.mcp_files]
43
+ elif plugin.manifest and plugin.manifest.inline_mcp:
44
+ meta["mcp_config"] = {"mcpServers": plugin.manifest.inline_mcp}
45
+
46
+ return meta
47
+
48
+
49
+ def get_subagent_bundle_dir(subagent_meta: SubagentMetadata | Mapping[str, Any]) -> Path | None:
50
+ """Return the plugin or bundle root directory for a subagent."""
51
+ if "bundle_dir" in subagent_meta and subagent_meta["bundle_dir"]:
52
+ return Path(str(subagent_meta["bundle_dir"]))
53
+ path = subagent_meta.get("path")
54
+ if not path:
55
+ return None
56
+ p = Path(path)
57
+ return p.parent.parent if p.parent.name == "agents" else p.parent
58
+
59
+
60
+ def get_subagent_skills_source(subagent_meta: SubagentMetadata | Mapping[str, Any]) -> tuple[str, str] | None:
61
+ """Return the skill source tuple for a subagent's bundled skills, if any."""
62
+ subagent_name = subagent_meta.get("name", "subagent")
63
+ skills_dir_str = subagent_meta.get("skills_dir")
64
+ if skills_dir_str and Path(skills_dir_str).is_dir():
65
+ return (skills_dir_str, f"Subagent ({subagent_name})")
66
+ bundle_dir = get_subagent_bundle_dir(subagent_meta)
67
+ if bundle_dir and (bundle_dir / "skills").is_dir():
68
+ return (str(bundle_dir / "skills"), f"Subagent ({subagent_name})")
69
+ return None
70
+
71
+
72
+ def plugin_subagents(plugins: tuple[PluginInstance, ...] | list[PluginInstance]) -> list[SubagentMetadata]:
73
+ """Discover and parse subagents from enabled plugins."""
74
+ from opscloud.subagents.loader import parse_subagent_file
75
+
76
+ subagents: list[SubagentMetadata] = []
77
+
78
+ for plugin in plugins:
79
+ for agent_path in plugin.inventory.agents:
80
+ if not agent_path.exists():
81
+ continue
82
+ if agent_path.is_dir():
83
+ # Scan for .md files or AGENTS.md in subdirectory
84
+ for entry in agent_path.iterdir():
85
+ if entry.is_file() and entry.suffix == ".md":
86
+ meta = parse_subagent_file(entry, fallback_name=entry.stem)
87
+ if meta:
88
+ subagents.append(_enrich_plugin_subagent(meta, plugin))
89
+ elif entry.is_dir():
90
+ sub_agents_file = entry / "AGENTS.md"
91
+ if sub_agents_file.is_file():
92
+ meta = parse_subagent_file(sub_agents_file, fallback_name=entry.name)
93
+ if meta:
94
+ subagents.append(_enrich_plugin_subagent(meta, plugin))
95
+ elif agent_path.is_file() and agent_path.suffix == ".md":
96
+ meta = parse_subagent_file(agent_path, fallback_name=agent_path.stem)
97
+ if meta:
98
+ subagents.append(_enrich_plugin_subagent(meta, plugin))
99
+
100
+ return subagents
101
+
102
+
103
+ def discover_plugin_subagents(project_root: Path | None = None, store: Any = None) -> list[SubagentMetadata]:
104
+ """Discover subagent definitions across all enabled marketplace and project plugins."""
105
+ try:
106
+ from opscloud.plugins.discovery import discover_plugins
107
+
108
+ plugins = discover_plugins(project_root=project_root, store=store).plugins
109
+ return plugin_subagents(plugins)
110
+ except Exception as exc:
111
+ logger.warning("Could not discover plugin subagents: %s", exc)
112
+ return []
@@ -0,0 +1,190 @@
1
+ """Adapter from discovered plugins to OpsCloud slash commands."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+ from pathlib import Path
7
+ from typing import TYPE_CHECKING
8
+
9
+ from opscloud.commands._base import BaseCommandHandler, CommandContext, CommandResult
10
+ from opscloud.commands._types import BypassTier, CommandCategory, SafetyLevel
11
+ from opscloud.utils.logger import get_logger
12
+
13
+ if TYPE_CHECKING:
14
+ from opscloud.plugins.models import PluginInstance
15
+
16
+ logger = get_logger(__name__)
17
+
18
+
19
+ class PluginCommandHandler(BaseCommandHandler):
20
+ """Command handler for plugin-contributed slash command workflow files."""
21
+
22
+ def __init__(
23
+ self,
24
+ *,
25
+ command_name: str,
26
+ description: str,
27
+ instructions: str,
28
+ plugin_id: str,
29
+ aliases: tuple[str, ...] = (),
30
+ ) -> None:
31
+ self._name = command_name if command_name.startswith("/") else f"/{command_name}"
32
+ self._description = description
33
+ self._instructions = instructions
34
+ self._plugin_id = plugin_id
35
+ self._aliases = aliases
36
+
37
+ @property
38
+ def name(self) -> str:
39
+ return self._name
40
+
41
+ @property
42
+ def aliases(self) -> tuple[str, ...]:
43
+ return self._aliases
44
+
45
+ @property
46
+ def category(self) -> CommandCategory:
47
+ return CommandCategory.AUTOMATION
48
+
49
+ @property
50
+ def safety_level(self) -> SafetyLevel:
51
+ return SafetyLevel.READ_ONLY
52
+
53
+ @property
54
+ def bypass_tier(self) -> BypassTier:
55
+ return BypassTier.QUEUED
56
+
57
+ @property
58
+ def description(self) -> str:
59
+ return self._description
60
+
61
+ async def execute(self, ctx: CommandContext) -> CommandResult:
62
+ # Build prompt message combining plugin command instructions and user arguments
63
+ user_input = ctx.args.strip()
64
+ combined_prompt = (
65
+ f"### Plugin Command Execution: {self._name} (from {self._plugin_id})\n\n"
66
+ f"{self._instructions}"
67
+ )
68
+ if user_input:
69
+ combined_prompt += f"\n\n**User Input / Target Arguments**:\n{user_input}"
70
+
71
+ return CommandResult(
72
+ success=True,
73
+ message=combined_prompt,
74
+ mount_as_app_message=True,
75
+ notify=f"Triggered plugin command {self._name}",
76
+ )
77
+
78
+
79
+ def _parse_command_file(path: Path) -> tuple[str, str] | None:
80
+ """Read a markdown command file and return (description, body)."""
81
+ try:
82
+ content = path.read_text(encoding="utf-8")
83
+ except OSError as exc:
84
+ logger.warning("Could not read plugin command file %s: %s", path, exc)
85
+ return None
86
+
87
+ # Check for optional YAML frontmatter
88
+ match = re.match(r"^---\s*\n(.*?)\n---\s*\n?(.*)$", content, re.DOTALL)
89
+ if match:
90
+ body = match.group(2).strip()
91
+ description = "Plugin slash command"
92
+ try:
93
+ import yaml
94
+
95
+ fm = yaml.safe_load(match.group(1))
96
+ if isinstance(fm, dict) and isinstance(fm.get("description"), str):
97
+ description = fm["description"]
98
+ except Exception:
99
+ pass
100
+ return description, body
101
+
102
+ first_line = content.splitlines()[0] if content.splitlines() else "Plugin command"
103
+ desc = first_line.lstrip("#").strip() or "Plugin command"
104
+ return desc, content.strip()
105
+
106
+
107
+ def plugin_commands(
108
+ plugins: tuple[PluginInstance, ...] | list[PluginInstance],
109
+ ) -> list[BaseCommandHandler]:
110
+ """Discover and instantiate command handlers for enabled plugins."""
111
+ handlers: list[BaseCommandHandler] = []
112
+
113
+ for plugin in plugins:
114
+ p_id = plugin.plugin_id
115
+ p_name = plugin.name
116
+ for cmd_path in plugin.inventory.commands:
117
+ if not cmd_path.exists():
118
+ continue
119
+ cmd_files: list[Path] = []
120
+ if cmd_path.is_dir():
121
+ cmd_files.extend(sorted(cmd_path.glob("*.md")))
122
+ elif cmd_path.is_file() and cmd_path.suffix == ".md":
123
+ cmd_files.append(cmd_path)
124
+
125
+ for file in cmd_files:
126
+ parsed = _parse_command_file(file)
127
+ if not parsed:
128
+ continue
129
+ desc, instructions = parsed
130
+ stem = file.stem.lower().strip()
131
+
132
+ primary_name = f"/{stem}"
133
+ namespaced_alias = f"/{p_name}:{stem}"
134
+ full_scoped_alias = f"/{p_id}:{stem}"
135
+
136
+ handler = PluginCommandHandler(
137
+ command_name=primary_name,
138
+ description=desc,
139
+ instructions=instructions,
140
+ plugin_id=p_id,
141
+ aliases=(namespaced_alias, full_scoped_alias),
142
+ )
143
+ handlers.append(handler)
144
+
145
+ return handlers
146
+
147
+
148
+ def discover_plugin_commands(
149
+ project_root: Path | None = None,
150
+ ) -> list[BaseCommandHandler]:
151
+ """Discover command handlers across all enabled marketplace and project plugins."""
152
+ try:
153
+ from opscloud.plugins.discovery import discover_plugins
154
+ from opscloud.plugins.project_plugins import load_project_plugins
155
+
156
+ handlers: list[BaseCommandHandler] = []
157
+
158
+ # 1. Enabled marketplace plugins
159
+ plugins = discover_plugins(project_root=project_root).plugins
160
+ handlers.extend(plugin_commands(plugins))
161
+
162
+ # 2. Project-local marketplace plugins
163
+ if project_root is not None:
164
+ proj_res = load_project_plugins(project_root)
165
+ for cmd_path in proj_res.main_commands:
166
+ cmd_files: list[Path] = []
167
+ if cmd_path.is_dir():
168
+ cmd_files.extend(sorted(cmd_path.glob("*.md")))
169
+ elif cmd_path.is_file() and cmd_path.suffix == ".md":
170
+ cmd_files.append(cmd_path)
171
+
172
+ for file in cmd_files:
173
+ parsed = _parse_command_file(file)
174
+ if not parsed:
175
+ continue
176
+ desc, instructions = parsed
177
+ stem = file.stem.lower().strip()
178
+ primary_name = f"/{stem}"
179
+ handler = PluginCommandHandler(
180
+ command_name=primary_name,
181
+ description=desc,
182
+ instructions=instructions,
183
+ plugin_id="project",
184
+ )
185
+ handlers.append(handler)
186
+
187
+ return handlers
188
+ except Exception as exc:
189
+ logger.warning("Could not discover plugin commands: %s", exc)
190
+ return []