|
| 1 | +"""RovoDev integration — Atlassian Rovo Dev via ``acli rovodev``. |
| 2 | +
|
| 3 | +Extends ``SkillsIntegration`` to generate skill files under |
| 4 | +``.rovodev/skills/`` and additionally generates prompt wrappers |
| 5 | +under ``.rovodev/prompts/`` and a ``prompts.yml`` manifest. |
| 6 | +""" |
| 7 | + |
| 8 | +from __future__ import annotations |
| 9 | + |
| 10 | +import os |
| 11 | +from pathlib import Path |
| 12 | +from typing import Any |
| 13 | + |
| 14 | +import yaml |
| 15 | + |
| 16 | +from ..base import SkillsIntegration |
| 17 | +from ..manifest import IntegrationManifest |
| 18 | + |
| 19 | + |
| 20 | +class RovodevIntegration(SkillsIntegration): |
| 21 | + """Integration for Atlassian Rovo Dev. |
| 22 | +
|
| 23 | + Uses the skills layout (``speckit-<name>/SKILL.md``) and adds |
| 24 | + prompt wrappers plus a ``prompts.yml`` manifest on top. |
| 25 | + Runtime execution dispatches through ``acli rovodev``. |
| 26 | + """ |
| 27 | + |
| 28 | + key = "rovodev" |
| 29 | + config = { |
| 30 | + "name": "RovoDev ACLI", |
| 31 | + "folder": ".rovodev/", |
| 32 | + "commands_subdir": "skills", |
| 33 | + "install_url": "https://www.atlassian.com/software/rovo-dev", |
| 34 | + "requires_cli": True, |
| 35 | + } |
| 36 | + registrar_config = { |
| 37 | + "dir": ".rovodev/skills", |
| 38 | + "format": "markdown", |
| 39 | + "args": "$ARGUMENTS", |
| 40 | + "extension": "/SKILL.md", |
| 41 | + } |
| 42 | + context_file = "AGENTS.md" |
| 43 | + |
| 44 | + # -- CLI dispatch ------------------------------------------------------ |
| 45 | + |
| 46 | + def _resolve_executable(self) -> str: |
| 47 | + """Return the binary to invoke (``acli``). |
| 48 | +
|
| 49 | + RovoDev is invoked as ``acli rovodev …`` — ``acli`` is the executable |
| 50 | + and ``rovodev`` is a subcommand. The base implementation falls back |
| 51 | + to ``self.key`` (``"rovodev"``), which is the wrong binary, so we |
| 52 | + override the fallback to ``"acli"`` while still honouring the |
| 53 | + standard ``SPECKIT_INTEGRATION_ROVODEV_EXECUTABLE`` env-var override. |
| 54 | + """ |
| 55 | + env_name = ( |
| 56 | + f"SPECKIT_INTEGRATION_{self.key.upper().replace('-', '_')}_EXECUTABLE" |
| 57 | + ) |
| 58 | + override = os.environ.get(env_name, "").strip() |
| 59 | + return override if override else "acli" |
| 60 | + |
| 61 | + def build_exec_args( |
| 62 | + self, |
| 63 | + prompt: str, |
| 64 | + *, |
| 65 | + model: str | None = None, |
| 66 | + output_json: bool = True, |
| 67 | + ) -> list[str] | None: |
| 68 | + """Build non-interactive ACLI args for RovoDev. |
| 69 | +
|
| 70 | + RovoDev supports a positional ``message`` for non-interactive runs. |
| 71 | + ``output_json`` maps to ``--output-schema`` so dispatch callers can |
| 72 | + request structured output. |
| 73 | +
|
| 74 | + The integration currently does not apply ``model`` overrides because |
| 75 | + the expected config shape for ``--config-override`` is not yet wired |
| 76 | + in this adapter. |
| 77 | +
|
| 78 | + Honours the standard env-var contract: |
| 79 | + - ``SPECKIT_INTEGRATION_ROVODEV_EXECUTABLE`` overrides ``acli`` |
| 80 | + - ``SPECKIT_INTEGRATION_ROVODEV_EXTRA_ARGS`` injects extra CLI flags |
| 81 | + """ |
| 82 | + _ = model |
| 83 | + args = [self._resolve_executable(), "rovodev", "run", prompt] |
| 84 | + self._apply_extra_args_env_var(args) |
| 85 | + if output_json: |
| 86 | + args.extend([ |
| 87 | + "--output-schema", |
| 88 | + '{"type": "object", "properties": {"result": {"type": "string"}}}', |
| 89 | + ]) |
| 90 | + return args |
| 91 | + |
| 92 | + |
| 93 | + # -- Prompt wrapper + manifest generation ------------------------------ |
| 94 | + |
| 95 | + @staticmethod |
| 96 | + def _render_prompt_wrapper(skill_name: str) -> str: |
| 97 | + return f"use skill {skill_name} $ARGUMENTS\n" |
| 98 | + |
| 99 | + def _generate_prompt_files( |
| 100 | + self, |
| 101 | + project_root: Path, |
| 102 | + manifest: IntegrationManifest, |
| 103 | + skill_paths: list[Path], |
| 104 | + ) -> tuple[list[Path], list[dict[str, str]]]: |
| 105 | + """Create thin prompt wrappers for each SKILL.md. |
| 106 | +
|
| 107 | + Skill name is derived from the parent directory name |
| 108 | + (e.g. ``.rovodev/skills/speckit-plan/SKILL.md`` → ``speckit-plan``). |
| 109 | +
|
| 110 | + Returns (created_files, prompt_entries) where prompt_entries are |
| 111 | + dicts suitable for inclusion in ``prompts.yml``. |
| 112 | + """ |
| 113 | + prompts_dir = project_root / ".rovodev" / "prompts" |
| 114 | + prompts_dir.mkdir(parents=True, exist_ok=True) |
| 115 | + |
| 116 | + created: list[Path] = [] |
| 117 | + prompt_entries: list[dict[str, str]] = [] |
| 118 | + |
| 119 | + for skill_path in skill_paths: |
| 120 | + if skill_path.name != "SKILL.md": |
| 121 | + continue |
| 122 | + |
| 123 | + skill_name = skill_path.parent.name |
| 124 | + if not skill_name: |
| 125 | + continue |
| 126 | + |
| 127 | + prompt_filename = f"{skill_name}.prompt.md" |
| 128 | + prompt_file = self.write_file_and_record( |
| 129 | + self._render_prompt_wrapper(skill_name), |
| 130 | + prompts_dir / prompt_filename, |
| 131 | + project_root, |
| 132 | + manifest, |
| 133 | + ) |
| 134 | + created.append(prompt_file) |
| 135 | + |
| 136 | + prompt_entries.append({ |
| 137 | + "name": skill_name, |
| 138 | + "description": f"Invoke {skill_name} skill", |
| 139 | + "content_file": f"prompts/{prompt_filename}", |
| 140 | + }) |
| 141 | + |
| 142 | + return created, prompt_entries |
| 143 | + |
| 144 | + @staticmethod |
| 145 | + def _read_prompts_yml(path: Path) -> list[dict[str, Any]]: |
| 146 | + """Read prompt entries from an existing ``prompts.yml``. |
| 147 | +
|
| 148 | + Returns an empty list if the file is missing, malformed, or |
| 149 | + contains no valid prompt entries. |
| 150 | + """ |
| 151 | + if not path.exists(): |
| 152 | + return [] |
| 153 | + try: |
| 154 | + data = yaml.safe_load(path.read_text(encoding="utf-8")) |
| 155 | + except (yaml.YAMLError, OSError, UnicodeError): |
| 156 | + return [] |
| 157 | + if not isinstance(data, dict): |
| 158 | + return [] |
| 159 | + prompts = data.get("prompts") |
| 160 | + if not isinstance(prompts, list): |
| 161 | + return [] |
| 162 | + return [dict(item) for item in prompts if isinstance(item, dict)] |
| 163 | + |
| 164 | + @staticmethod |
| 165 | + def _merge_prompt_entries( |
| 166 | + existing: list[dict[str, Any]], |
| 167 | + generated: list[dict[str, Any]], |
| 168 | + ) -> list[dict[str, Any]]: |
| 169 | + """Merge *generated* entries into *existing*, preserving user additions. |
| 170 | +
|
| 171 | + - Existing entries whose ``name`` matches a generated entry are |
| 172 | + replaced in-place (preserving the user's ordering). |
| 173 | + - Generated entries not already present are appended at the end. |
| 174 | + - User-added entries (no matching generated name) are kept as-is. |
| 175 | + """ |
| 176 | + generated_by_name = {e["name"]: e for e in generated if e.get("name")} |
| 177 | + |
| 178 | + merged: list[dict[str, Any]] = [] |
| 179 | + seen: set[str] = set() |
| 180 | + |
| 181 | + for entry in existing: |
| 182 | + name = entry.get("name", "") |
| 183 | + if name in generated_by_name: |
| 184 | + merged.append(generated_by_name[name]) |
| 185 | + seen.add(name) |
| 186 | + else: |
| 187 | + merged.append(entry) |
| 188 | + |
| 189 | + for entry in generated: |
| 190 | + if entry.get("name", "") not in seen: |
| 191 | + merged.append(entry) |
| 192 | + |
| 193 | + return merged |
| 194 | + |
| 195 | + def _merge_prompts_manifest( |
| 196 | + self, |
| 197 | + project_root: Path, |
| 198 | + manifest: IntegrationManifest, |
| 199 | + prompt_entries: list[dict[str, str]], |
| 200 | + ) -> Path | None: |
| 201 | + """Write ``prompts.yml``, merging with any existing user entries.""" |
| 202 | + if not prompt_entries: |
| 203 | + return None |
| 204 | + |
| 205 | + prompts_yml = project_root / ".rovodev" / "prompts.yml" |
| 206 | + existing = self._read_prompts_yml(prompts_yml) |
| 207 | + merged = self._merge_prompt_entries(existing, prompt_entries) |
| 208 | + |
| 209 | + content = yaml.safe_dump( |
| 210 | + {"prompts": merged}, |
| 211 | + default_flow_style=False, |
| 212 | + sort_keys=False, |
| 213 | + allow_unicode=True, |
| 214 | + width=10_000, |
| 215 | + ) |
| 216 | + return self.write_file_and_record( |
| 217 | + content, prompts_yml, project_root, manifest, |
| 218 | + ) |
| 219 | + |
| 220 | + # -- setup() ----------------------------------------------------------- |
| 221 | + |
| 222 | + def setup( |
| 223 | + self, |
| 224 | + project_root: Path, |
| 225 | + manifest: IntegrationManifest, |
| 226 | + parsed_options: dict[str, Any] | None = None, |
| 227 | + **opts: Any, |
| 228 | + ) -> list[Path]: |
| 229 | + """Install RovoDev skills, then generate prompt wrappers and manifest. |
| 230 | +
|
| 231 | + 1. ``SkillsIntegration.setup()`` generates skill files and |
| 232 | + upserts the context section. |
| 233 | + 2. Generates prompt wrappers and ``prompts.yml`` for each skill |
| 234 | + created in step 1. |
| 235 | + """ |
| 236 | + created = super().setup(project_root, manifest, parsed_options, **opts) |
| 237 | + |
| 238 | + # Generate prompt wrappers + merge prompts.yml |
| 239 | + prompt_files, prompt_entries = self._generate_prompt_files( |
| 240 | + project_root, manifest, created |
| 241 | + ) |
| 242 | + created.extend(prompt_files) |
| 243 | + |
| 244 | + manifest_file = self._merge_prompts_manifest( |
| 245 | + project_root, manifest, prompt_entries |
| 246 | + ) |
| 247 | + if manifest_file: |
| 248 | + created.append(manifest_file) |
| 249 | + |
| 250 | + return created |
0 commit comments