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,335 @@
|
|
|
1
|
+
"""Plugin manifest parsing and component inventory building for K8s Autopilot."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from pathlib import Path, PureWindowsPath
|
|
7
|
+
import re
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
from opscloud.plugins.models import (
|
|
11
|
+
ComponentInventory,
|
|
12
|
+
JsonObject,
|
|
13
|
+
PluginManifest,
|
|
14
|
+
UnsupportedComponent,
|
|
15
|
+
)
|
|
16
|
+
from opscloud.utils.logger import get_logger
|
|
17
|
+
|
|
18
|
+
logger = get_logger(__name__)
|
|
19
|
+
|
|
20
|
+
_MANIFEST_RELATIVE_PATHS = (
|
|
21
|
+
Path(".claude-plugin") / "plugin.json",
|
|
22
|
+
Path(".opscode-plugin") / "plugin.json",
|
|
23
|
+
Path(".codex-plugin") / "plugin.json",
|
|
24
|
+
Path("plugin.json"),
|
|
25
|
+
)
|
|
26
|
+
_PATH_COMPONENT_FIELDS = {"skills", "mcpServers", "agents", "commands"}
|
|
27
|
+
_UNSUPPORTED_COMPONENT_DIRS: tuple[UnsupportedComponent, ...] = ("hooks",)
|
|
28
|
+
_NAME_RE = re.compile(r"^[^\s]+$")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class PluginManifestError(ValueError):
|
|
32
|
+
"""Raised when a plugin manifest is malformed enough to skip the plugin."""
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def find_manifest_path(root: Path) -> Path | None:
|
|
36
|
+
"""Return the first supported manifest path under `root`, if present."""
|
|
37
|
+
for rel in _MANIFEST_RELATIVE_PATHS:
|
|
38
|
+
path = root / rel
|
|
39
|
+
try:
|
|
40
|
+
if path.is_file():
|
|
41
|
+
return path
|
|
42
|
+
except OSError:
|
|
43
|
+
logger.warning("Could not inspect plugin manifest path %s", path)
|
|
44
|
+
return None
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _validate_name(name: object, *, fallback: str | None = None, allow_at: bool = True) -> str:
|
|
48
|
+
if isinstance(name, str) and name and _NAME_RE.fullmatch(name) and (allow_at or "@" not in name):
|
|
49
|
+
return name
|
|
50
|
+
if fallback and _NAME_RE.fullmatch(fallback) and (allow_at or "@" not in fallback):
|
|
51
|
+
return fallback
|
|
52
|
+
msg = f"Invalid plugin name: {name!r}"
|
|
53
|
+
raise PluginManifestError(msg)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _is_windows_absolute(path: str) -> bool:
|
|
57
|
+
return bool(PureWindowsPath(path).drive or PureWindowsPath(path).root)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _resolve_component_path(
|
|
61
|
+
declaration: str,
|
|
62
|
+
plugin_root: Path,
|
|
63
|
+
field_name: str,
|
|
64
|
+
warnings: list[str],
|
|
65
|
+
) -> Path | None:
|
|
66
|
+
if not declaration.startswith("./"):
|
|
67
|
+
warnings.append(f"ignoring {field_name}: path must start with './' relative to plugin root")
|
|
68
|
+
return None
|
|
69
|
+
relative = declaration[2:]
|
|
70
|
+
if not relative:
|
|
71
|
+
warnings.append(f"ignoring {field_name}: path must not be './'")
|
|
72
|
+
return None
|
|
73
|
+
path = Path(relative)
|
|
74
|
+
if any(part == ".." for part in path.parts):
|
|
75
|
+
warnings.append(f"ignoring {field_name}: path must not contain '..'")
|
|
76
|
+
return None
|
|
77
|
+
if path.is_absolute() or _is_windows_absolute(relative):
|
|
78
|
+
warnings.append(f"ignoring {field_name}: path must stay within the plugin root")
|
|
79
|
+
return None
|
|
80
|
+
try:
|
|
81
|
+
root_resolved = plugin_root.resolve()
|
|
82
|
+
resolved = (plugin_root / path).resolve()
|
|
83
|
+
except OSError as exc:
|
|
84
|
+
warnings.append(f"ignoring {field_name}: could not resolve {declaration!r}: {exc}")
|
|
85
|
+
return None
|
|
86
|
+
if not resolved.is_relative_to(root_resolved):
|
|
87
|
+
warnings.append(f"ignoring {field_name}: path escapes plugin root")
|
|
88
|
+
return None
|
|
89
|
+
return resolved
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _resolve_component_paths(
|
|
93
|
+
declaration: object,
|
|
94
|
+
plugin_root: Path,
|
|
95
|
+
field_name: str,
|
|
96
|
+
warnings: list[str],
|
|
97
|
+
) -> tuple[Path, ...]:
|
|
98
|
+
raw_paths: list[str]
|
|
99
|
+
if isinstance(declaration, str):
|
|
100
|
+
raw_paths = [declaration]
|
|
101
|
+
elif isinstance(declaration, list):
|
|
102
|
+
raw_paths = [item for item in declaration if isinstance(item, str)]
|
|
103
|
+
warnings.extend(
|
|
104
|
+
f"ignoring {field_name}: expected path string, got {type(item).__name__}"
|
|
105
|
+
for item in declaration
|
|
106
|
+
if not isinstance(item, str)
|
|
107
|
+
)
|
|
108
|
+
else:
|
|
109
|
+
warnings.append(f"ignoring {field_name}: expected path string or list of strings")
|
|
110
|
+
return ()
|
|
111
|
+
paths: list[Path] = []
|
|
112
|
+
for raw_path in raw_paths:
|
|
113
|
+
resolved = _resolve_component_path(raw_path, plugin_root, field_name, warnings)
|
|
114
|
+
if resolved is not None:
|
|
115
|
+
paths.append(resolved)
|
|
116
|
+
return tuple(paths)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _inline_mcp(value: object) -> JsonObject:
|
|
120
|
+
if isinstance(value, dict):
|
|
121
|
+
return dict(value)
|
|
122
|
+
if isinstance(value, list):
|
|
123
|
+
merged: JsonObject = {}
|
|
124
|
+
for item in value:
|
|
125
|
+
if isinstance(item, dict):
|
|
126
|
+
merged.update(item)
|
|
127
|
+
return merged
|
|
128
|
+
return {}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def load_manifest(
|
|
132
|
+
root: Path, *, fallback_name: str | None = None
|
|
133
|
+
) -> tuple[PluginManifest | None, Path | None, tuple[str, ...]]:
|
|
134
|
+
"""Load a plugin manifest from known locations."""
|
|
135
|
+
manifest_path = find_manifest_path(root)
|
|
136
|
+
if manifest_path is None:
|
|
137
|
+
return None, None, ()
|
|
138
|
+
try:
|
|
139
|
+
decoded = json.loads(manifest_path.read_text(encoding="utf-8"))
|
|
140
|
+
except json.JSONDecodeError as exc:
|
|
141
|
+
msg = f"Invalid JSON syntax in {manifest_path}: {exc}"
|
|
142
|
+
raise PluginManifestError(msg) from exc
|
|
143
|
+
except OSError as exc:
|
|
144
|
+
msg = f"Could not read plugin manifest {manifest_path}: {exc}"
|
|
145
|
+
raise PluginManifestError(msg) from exc
|
|
146
|
+
if not isinstance(decoded, dict):
|
|
147
|
+
msg = f"Plugin manifest {manifest_path} must be a JSON object"
|
|
148
|
+
raise PluginManifestError(msg)
|
|
149
|
+
raw = decoded
|
|
150
|
+
|
|
151
|
+
warnings: list[str] = []
|
|
152
|
+
name = _validate_name(raw.get("name"), fallback=fallback_name)
|
|
153
|
+
component_paths: dict[str, tuple[Path, ...]] = {}
|
|
154
|
+
for field_name in _PATH_COMPONENT_FIELDS:
|
|
155
|
+
declaration = raw.get(field_name)
|
|
156
|
+
if declaration is None:
|
|
157
|
+
continue
|
|
158
|
+
if field_name == "mcpServers" and isinstance(declaration, dict):
|
|
159
|
+
continue
|
|
160
|
+
paths = _resolve_component_paths(declaration, root, field_name, warnings)
|
|
161
|
+
if paths:
|
|
162
|
+
component_paths[field_name] = paths
|
|
163
|
+
|
|
164
|
+
version_value = raw.get("version")
|
|
165
|
+
version = version_value if isinstance(version_value, str) else "1.0.0"
|
|
166
|
+
display_name_value = raw.get("displayName") or raw.get("display_name")
|
|
167
|
+
description_value = raw.get("description")
|
|
168
|
+
author_value = raw.get("author")
|
|
169
|
+
|
|
170
|
+
skills_dir = root / "skills" if (root / "skills").is_dir() else None
|
|
171
|
+
agents_dir = root / "agents" if (root / "agents").is_dir() else None
|
|
172
|
+
|
|
173
|
+
manifest = PluginManifest(
|
|
174
|
+
name=name,
|
|
175
|
+
version=version,
|
|
176
|
+
component_paths=component_paths,
|
|
177
|
+
inline_mcp=_inline_mcp(raw.get("mcpServers")),
|
|
178
|
+
display_name=(display_name_value if isinstance(display_name_value, str) else None),
|
|
179
|
+
description=(description_value if isinstance(description_value, str) else None),
|
|
180
|
+
author=author_value,
|
|
181
|
+
skills_dir=skills_dir,
|
|
182
|
+
agents_dir=agents_dir,
|
|
183
|
+
)
|
|
184
|
+
return manifest, manifest_path, tuple(warnings)
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def _existing_component_path(path: Path, plugin_root: Path) -> tuple[Path, ...]:
|
|
188
|
+
try:
|
|
189
|
+
if not path.exists():
|
|
190
|
+
return ()
|
|
191
|
+
resolved = path.resolve()
|
|
192
|
+
if not resolved.is_relative_to(plugin_root.resolve()):
|
|
193
|
+
logger.warning("Ignoring plugin component outside plugin root: %s", path)
|
|
194
|
+
return ()
|
|
195
|
+
except OSError:
|
|
196
|
+
logger.warning("Could not inspect plugin component path %s", path)
|
|
197
|
+
return ()
|
|
198
|
+
else:
|
|
199
|
+
return (resolved,)
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def _unsupported_component_dirs(
|
|
203
|
+
plugin_root: Path,
|
|
204
|
+
) -> tuple[UnsupportedComponent, ...]:
|
|
205
|
+
found: list[UnsupportedComponent] = []
|
|
206
|
+
for name in _UNSUPPORTED_COMPONENT_DIRS:
|
|
207
|
+
path = plugin_root / name
|
|
208
|
+
try:
|
|
209
|
+
if path.is_dir():
|
|
210
|
+
found.append(name)
|
|
211
|
+
except OSError:
|
|
212
|
+
logger.warning("Could not inspect plugin component path %s", path)
|
|
213
|
+
return tuple(found)
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def build_inventory(
|
|
217
|
+
plugin_root: Path,
|
|
218
|
+
manifest: PluginManifest | None,
|
|
219
|
+
manifest_warnings: tuple[str, ...] = (),
|
|
220
|
+
) -> ComponentInventory:
|
|
221
|
+
"""Build component inventory for a plugin."""
|
|
222
|
+
plugin_root = plugin_root.resolve()
|
|
223
|
+
warnings = list(manifest_warnings)
|
|
224
|
+
metadata_paths = manifest.component_paths if manifest else {}
|
|
225
|
+
|
|
226
|
+
default_skills = _existing_component_path(plugin_root / "skills", plugin_root)
|
|
227
|
+
root_skill = (
|
|
228
|
+
()
|
|
229
|
+
if default_skills or (manifest and "skills" in manifest.component_paths)
|
|
230
|
+
else _existing_component_path(plugin_root / "SKILL.md", plugin_root)
|
|
231
|
+
)
|
|
232
|
+
skills = (*default_skills, *metadata_paths.get("skills", ()), *root_skill)
|
|
233
|
+
|
|
234
|
+
default_agents = _existing_component_path(plugin_root / "agents", plugin_root)
|
|
235
|
+
agents = (*default_agents, *metadata_paths.get("agents", ()))
|
|
236
|
+
|
|
237
|
+
default_commands = _existing_component_path(plugin_root / "commands", plugin_root)
|
|
238
|
+
commands = (*default_commands, *metadata_paths.get("commands", ()))
|
|
239
|
+
|
|
240
|
+
mcp_files = (
|
|
241
|
+
*_existing_component_path(plugin_root / ".mcp.json", plugin_root),
|
|
242
|
+
*metadata_paths.get("mcpServers", ()),
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
unsupported = _unsupported_component_dirs(plugin_root)
|
|
246
|
+
|
|
247
|
+
return ComponentInventory(
|
|
248
|
+
skills=tuple(dict.fromkeys(skills)),
|
|
249
|
+
mcp_files=tuple(dict.fromkeys(mcp_files)),
|
|
250
|
+
agents=tuple(dict.fromkeys(agents)),
|
|
251
|
+
commands=tuple(dict.fromkeys(commands)),
|
|
252
|
+
unsupported=unsupported,
|
|
253
|
+
warnings=tuple(warnings),
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def inspect_plugin_components(
|
|
258
|
+
plugin_root: Path,
|
|
259
|
+
manifest: PluginManifest | None = None,
|
|
260
|
+
) -> dict[str, Any]:
|
|
261
|
+
"""Inspect a plugin filesystem tree and return exact component names and metadata."""
|
|
262
|
+
plugin_root = plugin_root.resolve()
|
|
263
|
+
|
|
264
|
+
if manifest is None:
|
|
265
|
+
try:
|
|
266
|
+
manifest, _, _ = load_manifest(plugin_root, fallback_name=plugin_root.name)
|
|
267
|
+
except Exception:
|
|
268
|
+
manifest = None
|
|
269
|
+
|
|
270
|
+
# 1. Skills
|
|
271
|
+
skill_names: list[str] = []
|
|
272
|
+
skills_dir = plugin_root / "skills"
|
|
273
|
+
if skills_dir.is_dir():
|
|
274
|
+
for item in sorted(skills_dir.iterdir()):
|
|
275
|
+
if item.is_dir() and (item / "SKILL.md").is_file():
|
|
276
|
+
skill_names.append(item.name)
|
|
277
|
+
elif item.is_file() and item.suffix == ".md" and item.name != "SKILL.md":
|
|
278
|
+
skill_names.append(item.stem)
|
|
279
|
+
if not skill_names and (skills_dir / "SKILL.md").is_file():
|
|
280
|
+
skill_names.append(plugin_root.name)
|
|
281
|
+
elif (plugin_root / "SKILL.md").is_file():
|
|
282
|
+
skill_names.append(plugin_root.name)
|
|
283
|
+
|
|
284
|
+
# 2. MCP Servers
|
|
285
|
+
mcp_server_names: list[str] = []
|
|
286
|
+
mcp_file = plugin_root / ".mcp.json"
|
|
287
|
+
if mcp_file.is_file():
|
|
288
|
+
try:
|
|
289
|
+
data = json.loads(mcp_file.read_text(encoding="utf-8"))
|
|
290
|
+
if isinstance(data, dict):
|
|
291
|
+
servers = data.get("mcpServers")
|
|
292
|
+
if isinstance(servers, dict):
|
|
293
|
+
mcp_server_names.extend(servers.keys())
|
|
294
|
+
elif "mcpServers" not in data:
|
|
295
|
+
mcp_server_names.extend(data.keys())
|
|
296
|
+
except Exception:
|
|
297
|
+
pass
|
|
298
|
+
|
|
299
|
+
if manifest and manifest.inline_mcp:
|
|
300
|
+
for k in manifest.inline_mcp:
|
|
301
|
+
if k not in mcp_server_names:
|
|
302
|
+
mcp_server_names.append(k)
|
|
303
|
+
|
|
304
|
+
# 3. Commands
|
|
305
|
+
command_names: list[str] = []
|
|
306
|
+
commands_dir = plugin_root / "commands"
|
|
307
|
+
if commands_dir.is_dir():
|
|
308
|
+
for item in sorted(commands_dir.glob("*.md")):
|
|
309
|
+
command_names.append(item.stem)
|
|
310
|
+
|
|
311
|
+
# 4. Author string normalization
|
|
312
|
+
raw_author = manifest.author if manifest else None
|
|
313
|
+
author_str = None
|
|
314
|
+
if isinstance(raw_author, dict):
|
|
315
|
+
author_str = raw_author.get("name")
|
|
316
|
+
elif isinstance(raw_author, str):
|
|
317
|
+
if raw_author.strip().startswith("{"):
|
|
318
|
+
try:
|
|
319
|
+
parsed = json.loads(raw_author)
|
|
320
|
+
author_str = parsed.get("name") if isinstance(parsed, dict) else raw_author
|
|
321
|
+
except Exception:
|
|
322
|
+
author_str = raw_author
|
|
323
|
+
else:
|
|
324
|
+
author_str = raw_author
|
|
325
|
+
|
|
326
|
+
return {
|
|
327
|
+
"display_name": manifest.display_name if manifest and manifest.display_name else None,
|
|
328
|
+
"description": manifest.description if manifest and manifest.description else None,
|
|
329
|
+
"version": manifest.version if manifest and manifest.version else "1.0.0",
|
|
330
|
+
"author": author_str,
|
|
331
|
+
"skill_names": skill_names,
|
|
332
|
+
"skill_count": len(skill_names),
|
|
333
|
+
"mcp_server_names": mcp_server_names,
|
|
334
|
+
"command_names": command_names,
|
|
335
|
+
}
|