diff --git a/README.md b/README.md index 103afd4..1f397f2 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ agy plugin install ./bmad-plugins/plugins/bmad ## Maintainers -Requires Python 3.11+ (stdlib only); metadata lives in `catalog.toml`: +Requires Python 3.11+ (stdlib only); metadata lives in `catalog.toml`. The build rewrites each skill's own `bmod.toml` sources to `plugin:`, and each `required_skills` / `recommended_skills` source to the plugin that ships that skill (`plugins/bmad` points at itself); `--validate` enforces both: ```bash # Rebuild all 7 modular plugins + portal bundle from upstream default branches (main) diff --git a/plugins/bmad-loop/skills/bmod-bmad-loop/bmod.toml b/plugins/bmad-loop/skills/bmod-bmad-loop/bmod.toml index 2f3a2aa..425ac3f 100644 --- a/plugins/bmad-loop/skills/bmod-bmad-loop/bmod.toml +++ b/plugins/bmad-loop/skills/bmod-bmad-loop/bmod.toml @@ -4,12 +4,12 @@ version = "0.13.2" update_source = "plugin:bmad-loop" skills = ["bmad-loop-setup", "bmad-loop-resolve", "bmad-loop-sweep"] required_skills = [ - { skill = "bmad", version = "6.13.0", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }, - { skill = "bmad-build-auto", version = "6.13.0", source = "github:bmad-code-org/BMAD-METHOD/skills/method" }, + { skill = "bmad", version = "6.13.0", source = "plugin:bmad-core-tools" }, + { skill = "bmad-build-auto", version = "6.13.0", source = "plugin:bmad-method" }, ] recommended_skills = [ - { skill = "bmad-agent-po", source = "github:bmad-code-org/BMAD-METHOD/skills/method" }, - { skill = "bmad-retrospective", source = "github:bmad-code-org/BMAD-METHOD/skills/method" }, + { skill = "bmad-agent-po", source = "plugin:bmad-method" }, + { skill = "bmad-retrospective", source = "plugin:bmad-method" }, ] pre_install_message = "" post_install_message = """BMAD Loop skills are installed. diff --git a/plugins/bmad/skills/bmad-agent-architect/bmod.toml b/plugins/bmad/skills/bmad-agent-architect/bmod.toml index fed1972..41decf7 100644 --- a/plugins/bmad/skills/bmad-agent-architect/bmod.toml +++ b/plugins/bmad/skills/bmad-agent-architect/bmod.toml @@ -2,14 +2,14 @@ bmod = "bmod-method" source = "plugin:bmad" required_skills = [ - { skill = "bmad-facilitate", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }, + { skill = "bmad-facilitate", source = "plugin:bmad" }, ] recommended_skills = [ "bmad-agent-po", "bmad-agent-pm", "bmad-project-context", - { skill = "bmad-party-mode", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }, - { skill = "bmad-advanced-elicitation", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }, + { skill = "bmad-party-mode", source = "plugin:bmad" }, + { skill = "bmad-advanced-elicitation", source = "plugin:bmad" }, ] [skill.help] diff --git a/plugins/bmad/skills/bmad-agent-ux-designer/bmod.toml b/plugins/bmad/skills/bmad-agent-ux-designer/bmod.toml index de8ff2c..a847c5a 100644 --- a/plugins/bmad/skills/bmad-agent-ux-designer/bmod.toml +++ b/plugins/bmad/skills/bmad-agent-ux-designer/bmod.toml @@ -2,14 +2,14 @@ bmod = "bmod-method" source = "plugin:bmad" required_skills = [ - { skill = "bmad-facilitate", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }, + { skill = "bmad-facilitate", source = "plugin:bmad" }, ] recommended_skills = [ "bmad-agent-po", "bmad-agent-pm", "bmad-agent-architect", - { skill = "bmad-party-mode", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }, - { skill = "bmad-advanced-elicitation", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }, + { skill = "bmad-party-mode", source = "plugin:bmad" }, + { skill = "bmad-advanced-elicitation", source = "plugin:bmad" }, ] [skill.help] diff --git a/plugins/bmad/skills/bmad-toolsmith/bmod.toml b/plugins/bmad/skills/bmad-toolsmith/bmod.toml index ad834ae..bbe867e 100644 --- a/plugins/bmad/skills/bmad-toolsmith/bmod.toml +++ b/plugins/bmad/skills/bmad-toolsmith/bmod.toml @@ -1,7 +1,7 @@ [skill] bmod = "bmod-toolsmith" source = "plugin:bmad" -required_skills = ["bmad-eval", { skill = "bmad-facilitate", version = "7.0.0", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }] +required_skills = ["bmad-eval", { skill = "bmad-facilitate", version = "7.0.0", source = "plugin:bmad" }] [skill.help] persona = "Smithy, Toolsmith" diff --git a/plugins/bmad/skills/bmod-method/bmod.toml b/plugins/bmad/skills/bmod-method/bmod.toml index 55096eb..d4126f4 100644 --- a/plugins/bmad/skills/bmod-method/bmod.toml +++ b/plugins/bmad/skills/bmod-method/bmod.toml @@ -17,7 +17,7 @@ skills = [ "bmad-retrospective", "bmad-walkthrough", ] -required_skills = [{ skill = "bmad", version = "7.0.0", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }] +required_skills = [{ skill = "bmad", version = "7.0.0", source = "plugin:bmad" }] scripts = ["scripts/tickets.py"] pre_install_message = "" post_install_message = ''' diff --git a/plugins/bmad/skills/bmod-toolsmith/bmod.toml b/plugins/bmad/skills/bmod-toolsmith/bmod.toml index 3d4f66a..ea66eef 100644 --- a/plugins/bmad/skills/bmod-toolsmith/bmod.toml +++ b/plugins/bmad/skills/bmod-toolsmith/bmod.toml @@ -3,7 +3,7 @@ code = "toolsmith" version = "7.1.0" update_source = "plugin:bmad" skills = ["bmad-toolsmith", "bmad-eval"] -required_skills = [{ skill = "bmad", version = "7.0.0", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }] +required_skills = [{ skill = "bmad", version = "7.0.0", source = "plugin:bmad" }] pre_install_message = "" post_install_message = """Toolsmith is installed. Ask for Smithy to create BMad or standalone skills, workflows, agents, or distributable BMOD modules (ideal for packaging organizational customizations and context), optimize external skills for your specific model or harness, and integrate them into the BMad ecosystem. diff --git a/plugins/creative/skills/bmad-creative-agent-director/bmod.toml b/plugins/creative/skills/bmad-creative-agent-director/bmod.toml index 8f4d6fe..62b855f 100644 --- a/plugins/creative/skills/bmad-creative-agent-director/bmod.toml +++ b/plugins/creative/skills/bmad-creative-agent-director/bmod.toml @@ -3,8 +3,8 @@ code = "creative" version = "7.1.0" update_source = "plugin:bmad-creative" required_skills = [ - { skill = "bmad", version = "7.0.0", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }, - { skill = "bmad-facilitate", version = "7.0.0", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }, + { skill = "bmad", version = "7.0.0", source = "plugin:bmad-core-tools" }, + { skill = "bmad-facilitate", version = "7.0.0", source = "plugin:bmad-core-tools" }, ] pre_install_message = "" post_install_message = """Creative is installed. @@ -28,12 +28,12 @@ scope = "user" [skill] recommended_skills = [ - { skill = "bmad-brainstorming", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }, - { skill = "bmad-forge-idea", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }, - { skill = "bmad-deep-recon", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }, - { skill = "bmad-party-mode", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }, - { skill = "bmad-advanced-elicitation", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }, - { skill = "bmad-review", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }, + { skill = "bmad-brainstorming", source = "plugin:bmad-core-tools" }, + { skill = "bmad-forge-idea", source = "plugin:bmad-core-tools" }, + { skill = "bmad-deep-recon", source = "plugin:bmad-core-tools" }, + { skill = "bmad-party-mode", source = "plugin:bmad-core-tools" }, + { skill = "bmad-advanced-elicitation", source = "plugin:bmad-core-tools" }, + { skill = "bmad-review", source = "plugin:bmad-core-tools" }, ] [skill.help] diff --git a/plugins/founder/skills/bmad-founder-agent-advisor/bmod.toml b/plugins/founder/skills/bmad-founder-agent-advisor/bmod.toml index 6ee2936..f33d133 100644 --- a/plugins/founder/skills/bmad-founder-agent-advisor/bmod.toml +++ b/plugins/founder/skills/bmad-founder-agent-advisor/bmod.toml @@ -3,8 +3,8 @@ code = "founder" version = "7.1.0" update_source = "plugin:bmad-founder" required_skills = [ - { skill = "bmad", version = "7.0.0", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }, - { skill = "bmad-facilitate", version = "7.0.0", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }, + { skill = "bmad", version = "7.0.0", source = "plugin:bmad-core-tools" }, + { skill = "bmad-facilitate", version = "7.0.0", source = "plugin:bmad-core-tools" }, ] pre_install_message = "" post_install_message = """Founder is installed. @@ -22,10 +22,10 @@ default = "{project-root}/company" [skill] recommended_skills = [ - { skill = "bmad-brainstorming", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }, - { skill = "bmad-deep-recon", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }, - { skill = "bmad-forge-idea", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }, - { skill = "bmad-party-mode", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }, + { skill = "bmad-brainstorming", source = "plugin:bmad-core-tools" }, + { skill = "bmad-deep-recon", source = "plugin:bmad-core-tools" }, + { skill = "bmad-forge-idea", source = "plugin:bmad-core-tools" }, + { skill = "bmad-party-mode", source = "plugin:bmad-core-tools" }, ] [skill.help] diff --git a/plugins/method/skills/bmad-agent-architect/bmod.toml b/plugins/method/skills/bmad-agent-architect/bmod.toml index 7a30be4..a2502df 100644 --- a/plugins/method/skills/bmad-agent-architect/bmod.toml +++ b/plugins/method/skills/bmad-agent-architect/bmod.toml @@ -2,14 +2,14 @@ bmod = "bmod-method" source = "plugin:bmad-method" required_skills = [ - { skill = "bmad-facilitate", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }, + { skill = "bmad-facilitate", source = "plugin:bmad-core-tools" }, ] recommended_skills = [ "bmad-agent-po", "bmad-agent-pm", "bmad-project-context", - { skill = "bmad-party-mode", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }, - { skill = "bmad-advanced-elicitation", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }, + { skill = "bmad-party-mode", source = "plugin:bmad-core-tools" }, + { skill = "bmad-advanced-elicitation", source = "plugin:bmad-core-tools" }, ] [skill.help] diff --git a/plugins/method/skills/bmad-agent-ux-designer/bmod.toml b/plugins/method/skills/bmad-agent-ux-designer/bmod.toml index 01b4804..4787b76 100644 --- a/plugins/method/skills/bmad-agent-ux-designer/bmod.toml +++ b/plugins/method/skills/bmad-agent-ux-designer/bmod.toml @@ -2,14 +2,14 @@ bmod = "bmod-method" source = "plugin:bmad-method" required_skills = [ - { skill = "bmad-facilitate", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }, + { skill = "bmad-facilitate", source = "plugin:bmad-core-tools" }, ] recommended_skills = [ "bmad-agent-po", "bmad-agent-pm", "bmad-agent-architect", - { skill = "bmad-party-mode", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }, - { skill = "bmad-advanced-elicitation", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }, + { skill = "bmad-party-mode", source = "plugin:bmad-core-tools" }, + { skill = "bmad-advanced-elicitation", source = "plugin:bmad-core-tools" }, ] [skill.help] diff --git a/plugins/method/skills/bmod-method/bmod.toml b/plugins/method/skills/bmod-method/bmod.toml index 651e45c..749aa6e 100644 --- a/plugins/method/skills/bmod-method/bmod.toml +++ b/plugins/method/skills/bmod-method/bmod.toml @@ -17,7 +17,7 @@ skills = [ "bmad-retrospective", "bmad-walkthrough", ] -required_skills = [{ skill = "bmad", version = "7.0.0", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }] +required_skills = [{ skill = "bmad", version = "7.0.0", source = "plugin:bmad-core-tools" }] scripts = ["scripts/tickets.py"] pre_install_message = "" post_install_message = ''' diff --git a/plugins/tea/skills/bmod-tea/bmod.toml b/plugins/tea/skills/bmod-tea/bmod.toml index 5afd87c..a33fe8b 100644 --- a/plugins/tea/skills/bmod-tea/bmod.toml +++ b/plugins/tea/skills/bmod-tea/bmod.toml @@ -15,7 +15,7 @@ skills = [ "bmad-tea-test-review", "bmad-tea-trace", ] -required_skills = [{ skill = "bmad", version = "7.0.2", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }] +required_skills = [{ skill = "bmad", version = "7.0.2", source = "plugin:bmad-core-tools" }] pre_install_message = "" post_install_message = ''' TEA is ready with its recommended defaults (stored under `[modules.tea]` in `_bmad/config.toml`). Talk to Murat (`bmad-tea`) or start with Test Design (`bmad-tea-test-design`), and ask the BMad Agent anytime to view or change your TEA settings. diff --git a/plugins/toolsmith/skills/bmad-toolsmith/bmod.toml b/plugins/toolsmith/skills/bmad-toolsmith/bmod.toml index 48ed3c1..30b56e6 100644 --- a/plugins/toolsmith/skills/bmad-toolsmith/bmod.toml +++ b/plugins/toolsmith/skills/bmad-toolsmith/bmod.toml @@ -1,7 +1,7 @@ [skill] bmod = "bmod-toolsmith" source = "plugin:bmad-toolsmith" -required_skills = ["bmad-eval", { skill = "bmad-facilitate", version = "7.0.0", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }] +required_skills = ["bmad-eval", { skill = "bmad-facilitate", version = "7.0.0", source = "plugin:bmad-core-tools" }] [skill.help] persona = "Smithy, Toolsmith" diff --git a/plugins/toolsmith/skills/bmod-toolsmith/bmod.toml b/plugins/toolsmith/skills/bmod-toolsmith/bmod.toml index e6c44a0..0fa1abb 100644 --- a/plugins/toolsmith/skills/bmod-toolsmith/bmod.toml +++ b/plugins/toolsmith/skills/bmod-toolsmith/bmod.toml @@ -3,7 +3,7 @@ code = "toolsmith" version = "7.1.0" update_source = "plugin:bmad-toolsmith" skills = ["bmad-toolsmith", "bmad-eval"] -required_skills = [{ skill = "bmad", version = "7.0.0", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }] +required_skills = [{ skill = "bmad", version = "7.0.0", source = "plugin:bmad-core-tools" }] pre_install_message = "" post_install_message = """Toolsmith is installed. Ask for Smithy to create BMad or standalone skills, workflows, agents, or distributable BMOD modules (ideal for packaging organizational customizations and context), optimize external skills for your specific model or harness, and integrate them into the BMad ecosystem. diff --git a/release.py b/release.py index 85dc522..77ad6f3 100644 --- a/release.py +++ b/release.py @@ -3,8 +3,9 @@ Clones (or reads locally via `--source`) each skill source repository, discovers v7 modules from their `bmod.toml` records, copies each plugin's skill folders -with `[bmod].update_source` and `[skill].source` rewritten to `plugin:`, -stamps per-platform manifests (Claude Code, OpenAI Codex, Cursor, Antigravity), +with `[bmod].update_source` and `[skill].source` rewritten to `plugin:` +and each `required_skills` / `recommended_skills` source rewritten to the +plugin that ships that skill (the bundle itself for skills it carries), stamps per-platform manifests (Claude Code, OpenAI Codex, Cursor, Antigravity), updates the three root marketplace indexes, and optionally exports and validates clean rootless `.zip` archives under `dist/` for OpenAI Plugin Portal uploads. @@ -80,6 +81,13 @@ MAX_PROMPT_LEN = 128 MAX_PROMPTS = 3 +REQUIREMENT_TABLES = ("bmod", "skill") +REQUIREMENT_FIELDS = ("required_skills", "recommended_skills") +_REQUIREMENT_KEY_RE = re.compile(r"(required_skills|recommended_skills)[ \t]*=") +_ROOT_REQUIREMENT_KEY_RE = re.compile(r"(bmod|skill)[ \t]*\.[ \t]*(required_skills|recommended_skills)[ \t]*=") +_SOURCE_KEY_RE = re.compile(r"(? str: - """Rewrite `[bmod].update_source` and `[skill].source` to `plugin:` preserving comments.""" +def _starts_requirement_array(line: str, current_table: str | None, *, at_root: bool) -> bool: + """True when `line` assigns `required_skills` or `recommended_skills` of `[bmod]` or `[skill]`.""" + stripped = line.lstrip(" \t") + if current_table in REQUIREMENT_TABLES and _REQUIREMENT_KEY_RE.match(stripped): + return True + return at_root and _ROOT_REQUIREMENT_KEY_RE.match(stripped) is not None + + +def _rewrite_requirement_sources(line: str, targets: dict[str, str]) -> tuple[str, int]: + """Rewrite each bare `source = ""` key outside strings and comments in one line of a requirement array.""" + out: list[str] = [] + rewrites = 0 + i = 0 + n = len(line) + while i < n: + ch = line[i] + if ch == "#" or line.startswith('"""', i) or line.startswith("'''", i): + # Comments and multiline strings run past this line; leave the remainder untouched. + out.append(line[i:]) + break + if ch in "\"'": + end = _string_literal_end(line[i:]) + if end is None: + out.append(line[i:]) + break + out.append(line[i : i + end]) + i += end + continue + match = _SOURCE_KEY_RE.match(line, i) + if match is not None: + value_start = match.end() + end = _string_literal_end(line[value_start:]) + if end is not None: + literal = line[value_start : value_start + end] + value = tomllib.loads(f"v = {literal}\n")["v"] + out.append(line[i:value_start]) + if value in targets: + out.append(f'"plugin:{targets[value]}"') + rewrites += 1 + else: + out.append(literal) + i = value_start + end + continue + out.append(ch) + i += 1 + return "".join(out), rewrites + + +def requirement_entries(data: dict[str, Any]) -> list[tuple[str, dict[str, Any]]]: + """Every `required_skills` / `recommended_skills` inline table that carries a `source`, with its field path.""" + entries: list[tuple[str, dict[str, Any]]] = [] + for table_name in REQUIREMENT_TABLES: + table = data.get(table_name) + if not isinstance(table, dict): + continue + for field in REQUIREMENT_FIELDS: + value = table.get(field) + if not isinstance(value, list): + continue + for index, entry in enumerate(value): + if isinstance(entry, dict) and "source" in entry: + entries.append((f"[{table_name}].{field}[{index}]", entry)) + return entries + + +def rewrite_bmod_toml( + original: str, + plugin_name: str, + expected_source: str, + label: str = "bmod.toml", + requirement_targets: dict[str, str] | None = None, +) -> str: + """Rewrite own sources to `plugin:` and requirement sources via `requirement_targets`. + + `[bmod].update_source` and `[skill].source` become `plugin:`. Each + `required_skills` / `recommended_skills` entry source becomes `plugin:` for the + plugin `requirement_targets` maps it to; a source it does not map fails the build. + Comments and layout are preserved, and the result is proven to change nothing else. + """ + targets = requirement_targets or {} original = original.removeprefix("\ufeff") try: orig_data = tomllib.loads(original) @@ -551,10 +637,27 @@ def rewrite_bmod_toml(original: str, plugin_name: str, expected_source: str, lab at_root = True triple_quote: str | None = None bracket_depth = 0 - counts = {"bmod": 0, "skill": 0} + counts = {"bmod": 0, "skill": 0, "requirement": 0} + in_requirements = False for line in original.splitlines(keepends=True): + if in_requirements and triple_quote is None: + line, rewrites = _rewrite_requirement_sources(line, targets) + counts["requirement"] += rewrites + triple_quote, bracket_depth = _scan_toml_line_state(line, triple_quote, bracket_depth) + in_requirements = bracket_depth > 0 + out.append(line) + continue if triple_quote is None and bracket_depth == 0: + if _starts_requirement_array(line, current_table, at_root=at_root): + eq_idx = line.find("=") + head, rewrites = _rewrite_requirement_sources(line[eq_idx + 1 :], targets) + line = line[: eq_idx + 1] + head + counts["requirement"] += rewrites + triple_quote, bracket_depth = _scan_toml_line_state(line, triple_quote, bracket_depth) + in_requirements = bracket_depth > 0 + out.append(line) + continue if line.lstrip(" \t").startswith("["): at_root = False current_table = _decode_table_header(line) @@ -585,6 +688,16 @@ def rewrite_bmod_toml(original: str, plugin_name: str, expected_source: str, lab if orig_data["skill"]["source"] != expected_source or counts["skill"] != 1: fail(f"{label}: expected exactly one [skill].source = {expected_source!r}") expected["skill"]["source"] = target + expected_rewrites = 0 + for where, entry in requirement_entries(expected): + source = entry["source"] + mapped = targets.get(source) if isinstance(source, str) else None + if mapped is None: + fail(f"{label}: {where} source {source!r} is not shipped by any plugin in catalog.toml") + entry["source"] = f"plugin:{mapped}" + expected_rewrites += 1 + if counts["requirement"] != expected_rewrites: + fail(f"{label}: rewrote {counts['requirement']} requirement source(s), expected {expected_rewrites}") if new_data != expected: fail(f"{label}: rewriting bmod.toml changed unexpected keys") @@ -748,12 +861,46 @@ def _write_plugin_manifests( (plugin_root / "README.md").write_text(_render_repo_plugin_readme(spec, version, skill_names), encoding="utf-8") +def requirement_targets( + spec: PluginSpec, catalog: Catalog, all_modules: dict[str, DiscoveredModule] +) -> dict[str, str]: + """Map each discovered module's GitHub source to the plugin `spec` should point its requirements at. + + A module `spec` ships maps to `spec` itself (so the portal bundle points at itself); + any other module maps to the marketplace plugin that ships it. + """ + owners = {code: plugin.name for plugin in catalog.plugins for code in plugin.modules} + targets: dict[str, str] = {} + for code, mod in sorted(all_modules.items()): + target = spec.name if code in spec.modules else owners.get(code) + if target is None: + continue + prior = targets.setdefault(mod.expected_source, target) + if prior != target: + fail(f"source {mod.expected_source!r} is shipped by both {prior!r} and {target!r}") + return targets + + +def requirement_source_slugs(modules: list[DiscoveredModule]) -> set[str]: + """GitHub `owner/repo` slugs named by requirement sources in these modules' skills.""" + slugs: set[str] = set() + for mod in modules: + for skill_dir in mod.skill_dirs: + data = _load_toml(skill_dir / "bmod.toml", f"{mod.source_slug}/{skill_dir.name}") + for _, entry in requirement_entries(data): + match = _GITHUB_SLUG_RE.match(str(entry["source"])) + if match: + slugs.add(match.group(1)) + return slugs + + def _stage_plugin( dest_dir: Path, repo_root: Path, spec: PluginSpec, all_modules: dict[str, DiscoveredModule], meta: dict[str, str], + catalog: Catalog, ) -> str: icon_src = repo_root / ICON_REL license_src = repo_root / LICENSE_REL @@ -771,6 +918,8 @@ def _stage_plugin( discovered = [all_modules[code] for code in spec.modules] version = _resolve_bundle_version(discovered) + targets = requirement_targets(spec, catalog, all_modules) + dest_dir.mkdir(parents=True) skills_dest = dest_dir / "skills" skills_dest.mkdir() @@ -790,6 +939,7 @@ def _stage_plugin( spec.name, mod.expected_source, label=f"plugins/{spec.dir_name}/skills/{skill_dir.name}/bmod.toml", + requirement_targets=targets, ) bmod_path.write_text(rewritten, encoding="utf-8") copied_names.append(skill_dir.name) @@ -1164,6 +1314,35 @@ def _validate_plugin_manifests( return plugin_version +def _validate_requirement_sources( + refs: list[tuple[PluginSpec, Path, str, dict[str, Any]]], + cat: Catalog, + plugin_skill_sets: dict[str, set[str]], +) -> None: + """Each requirement source must be `plugin:` for the plugin that ships the skill. + + That is the declaring plugin itself when it carries the skill (the portal bundle), + otherwise the one marketplace plugin whose skills include it. + """ + marketplace_names = {p.name for p in cat.plugins} + for spec, skill_dir, where, entry in refs: + label = f"{skill_dir / 'bmod.toml'}: {where}" + skill = entry.get("skill") + source = entry.get("source") + if not isinstance(source, str) or not source.startswith("plugin:"): + fail(f"{label} source must be a plugin: source, got {source!r}") + named = source.removeprefix("plugin:") + if skill in plugin_skill_sets[spec.name]: + expected = spec.name + else: + owners = [name for name in sorted(marketplace_names) if skill in plugin_skill_sets.get(name, set())] + if len(owners) != 1: + fail(f"{label} skill {skill!r} is shipped by no marketplace plugin") + expected = owners[0] + if named != expected: + fail(f"{label} source must be 'plugin:{expected}' (the plugin that ships {skill!r}), got {source!r}") + + def validate_repo(repo_root: Path, catalog: Catalog | None = None) -> None: """Validate assets, directory hygiene, manifests, skill records, and marketplaces offline.""" cat = catalog or load_catalog(repo_root / CATALOG_REL) @@ -1187,6 +1366,7 @@ def validate_repo(repo_root: Path, catalog: Catalog | None = None) -> None: seen_marketplace_skills: dict[str, str] = {} plugin_skill_sets: dict[str, set[str]] = {} plugin_module_versions: dict[str, dict[str, str]] = {} + requirement_refs: list[tuple[PluginSpec, Path, str, dict[str, Any]]] = [] for spec in cat.all_specs: plugin_root = plugins_dir / spec.dir_name @@ -1217,6 +1397,8 @@ def validate_repo(repo_root: Path, catalog: Catalog | None = None) -> None: for skill_dir in skill_folders: _validate_skill_frontmatter(skill_dir / "SKILL.md", skill_dir.name) bmod_data = _load_toml(skill_dir / "bmod.toml", f"plugins/{spec.dir_name}/skills/{skill_dir.name}") + for where, entry in requirement_entries(bmod_data): + requirement_refs.append((spec, skill_dir, where, entry)) bmod_tbl = bmod_data.get("bmod") skill_tbl = bmod_data.get("skill") if not isinstance(bmod_tbl, dict) and not isinstance(skill_tbl, dict): @@ -1265,6 +1447,8 @@ def validate_repo(repo_root: Path, catalog: Catalog | None = None) -> None: if claimed_members != skill_names: fail(f"plugins/{spec.dir_name}: unclaimed skills {sorted(skill_names - claimed_members)}") + _validate_requirement_sources(requirement_refs, cat, plugin_skill_sets) + modular_by_code = {p.modules[0]: p for p in cat.plugins if len(p.modules) == 1} for bundle in cat.portal_bundles: expected_union: set[str] = set() @@ -1401,6 +1585,15 @@ def main(argv: list[str] | None = None, *, repo_root: Path | None = None) -> int for src_spec in needed_sources: checkout = _resolve_source_repo(stage_root, src_spec.slug, overrides.get(src_spec.slug)) all_modules.update(collect_modules(checkout, src_spec)) + # Requirement sources are resolved to plugins through the modules that ship them, + # so also read any source repository a selected module depends on. + selected_mods = [all_modules[code] for code in needed_modules if code in all_modules] + dep_slugs = requirement_source_slugs(selected_mods) + for src_spec in catalog.sources: + if src_spec in needed_sources or src_spec.slug not in dep_slugs: + continue + checkout = _resolve_source_repo(stage_root, src_spec.slug, overrides.get(src_spec.slug)) + all_modules.update(collect_modules(checkout, src_spec)) # Assemble complete target tree inside temporary staging dir and validate BEFORE mutating repo_root. target_view = stage_root / "repo" @@ -1418,7 +1611,7 @@ def main(argv: list[str] | None = None, *, repo_root: Path | None = None) -> int staged_plugins.mkdir() for spec in all_specs: if spec.name in selected_names: - ver = _stage_plugin(staged_plugins / spec.dir_name, root, spec, all_modules, catalog.meta) + ver = _stage_plugin(staged_plugins / spec.dir_name, root, spec, all_modules, catalog.meta, catalog) built_versions[spec.name] = ver all_versions[spec.name] = ver else: diff --git a/test_release.py b/test_release.py index 2c5892b..77e2c99 100644 --- a/test_release.py +++ b/test_release.py @@ -129,7 +129,12 @@ def _build_synthetic_sources(root: Path) -> dict[str, Path]: "bmod-bmad-loop", '[bmod]\ncode = "bmad-loop"\nversion = "0.13.2"\n' 'update_source = "github:bmad-code-org/bmad-loop/skills"\n' - 'skills = ["bmad-loop-setup"]\n', + 'skills = ["bmad-loop-setup"]\n' + 'required_skills = [\n' + ' { skill = "bmad", version = "7.0.0", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" },\n' + ' # the build skill ships in method\n' + ' { skill = "bmad-build", source = "github:bmad-code-org/BMAD-METHOD/skills/method" },\n' + ']\n', ) _write_skill( loop_repo, @@ -152,6 +157,14 @@ def _init_plugins_repo(root: Path) -> Path: return repo +TARGET_CORE = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" +TARGETS = { + TARGET_CORE: "bmad-core-tools", + "github:bmad-code-org/BMAD-METHOD/skills/method": "bmad-method", + "github:bmad-code-org/bmad-method-test-architecture-enterprise/skills": "bmad-tea", +} + + class TomlRewriterTests(unittest.TestCase): def test_rewrite_handles_single_triple_bom_escaped_four_quotes_and_inline_arrays(self) -> None: original = ( @@ -181,22 +194,98 @@ def test_rewrite_handles_single_triple_bom_escaped_four_quotes_and_inline_arrays original, "bmad-method", "github:bmad-code-org/BMAD-METHOD/skills/method", + requirement_targets=TARGETS, ) data = tomllib.loads(rewritten) self.assertEqual(data["bmod"]["update_source"], "plugin:bmad-method") - self.assertEqual( - data["bmod"]["required_skills"][0]["source"], - "github:bmad-code-org/BMAD-METHOD/skills/core-tools", - ) + self.assertEqual(data["bmod"]["required_skills"][0]["source"], "plugin:bmad-core-tools") self.assertEqual(data["skill"]["source"], "plugin:bmad-method") - self.assertEqual( - data["skill"]["recommended_skills"][0]["source"], - "github:bmad-code-org/bmad-method-test-architecture-enterprise/skills", - ) + self.assertEqual(data["skill"]["recommended_skills"][0]["source"], "plugin:bmad-tea") self.assertEqual(data["other"]["a[b]"]["source"], "github:bmad-code-org/BMAD-METHOD/skills/method") self.assertEqual(data["bmod_extra"][0]["update_source"], "github:bmad-code-org/BMAD-METHOD/skills/method") self.assertIn("# single quotes", rewritten) + def test_rewrite_requirement_sources_in_every_shape_and_nothing_else(self) -> None: + original = ( + "[bmod]\n" + 'code = "founder"\n' + 'update_source = "github:bmad-code-org/BMAD-METHOD/skills/founder"\n' + "required_skills = [ # trailing comment, source = 'github:x/y'\n" + ' "bmod-founder-helper",\n' + ' { skill = "bmad", version = "7.0.0", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" },\n' + " # { skill = 'commented', source = 'github:bmad-code-org/BMAD-METHOD/skills/core-tools' },\n" + " {skill='bmad-facilitate',source='github:bmad-code-org/BMAD-METHOD/skills/core-tools'}\n" + "]\n" + 'recommended_skills = [{ skill = "source", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }]\n' + 'post_install_message = """source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" stays"""\n\n' + "[skill]\n" + "required_skills = []\n" + "recommended_skills = [\n" + ' { skill = "bmad-tea", source = "github:bmad-code-org/bmad-method-test-architecture-enterprise/skills" },\n' + "]\n\n" + "[skill.help]\n" + 'required_skills = [{ skill = "bmad", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }]\n' + ) + rewritten = release.rewrite_bmod_toml( + original, + "bmad-founder", + "github:bmad-code-org/BMAD-METHOD/skills/founder", + requirement_targets=TARGETS, + ) + data = tomllib.loads(rewritten) + required = data["bmod"]["required_skills"] + self.assertEqual(required[0], "bmod-founder-helper") + self.assertEqual(required[1]["source"], "plugin:bmad-core-tools") + self.assertEqual(required[2]["source"], "plugin:bmad-core-tools") + self.assertEqual(data["bmod"]["recommended_skills"][0], {"skill": "source", "source": "plugin:bmad-core-tools"}) + self.assertEqual(data["skill"]["recommended_skills"][0]["source"], "plugin:bmad-tea") + self.assertIn('stays"""', rewritten) + self.assertEqual(data["bmod"]["post_install_message"].count("github:"), 1) + # [skill.help] is not a requirement table, so its look-alike key is left alone. + self.assertEqual(data["skill"]["help"]["required_skills"][0]["source"], TARGET_CORE) + self.assertIn("# trailing comment, source = 'github:x/y'", rewritten) + self.assertIn("# { skill = 'commented', source = '" + TARGET_CORE + "' },", rewritten) + self.assertIn("{skill='bmad-facilitate',source=\"plugin:bmad-core-tools\"}", rewritten) + + dotted = release.rewrite_bmod_toml( + 'bmod.update_source = "github:o/r/skills/a"\n' + 'bmod.required_skills = [{ skill = "x", source = "github:o/r/skills/b" }]\n', + "plug-a", + "github:o/r/skills/a", + requirement_targets={"github:o/r/skills/b": "plug-b"}, + ) + self.assertEqual(tomllib.loads(dotted)["bmod"]["required_skills"][0]["source"], "plugin:plug-b") + + def test_rewrite_rejects_unmapped_or_unrewritable_requirement_sources(self) -> None: + unmapped = ( + '[bmod]\nupdate_source = "github:o/r/skills/a"\n' + 'required_skills = [{ skill = "x", source = "github:other/repo/skills" }]\n' + ) + with self.assertRaises(SystemExit): + release.rewrite_bmod_toml(unmapped, "p", "github:o/r/skills/a", requirement_targets={"github:o/r/skills/b": "q"}) + quoted_key = ( + '[bmod]\nupdate_source = "github:o/r/skills/a"\n' + 'required_skills = [{ skill = "x", "source" = "github:o/r/skills/b" }]\n' + ) + with self.assertRaises(SystemExit): + release.rewrite_bmod_toml(quoted_key, "p", "github:o/r/skills/a", requirement_targets={"github:o/r/skills/b": "q"}) + + def test_requirement_targets_point_bundle_at_itself_and_modules_at_owners(self) -> None: + catalog = release.load_catalog(REPO_ROOT / "catalog.toml") + d = Path(".") + mods = { + code: release.DiscoveredModule(code, "7.0.0", "bmad-code-org/BMAD-METHOD", f"github:bmad-code-org/BMAD-METHOD/skills/{code}", d, ()) + for code in ("core-tools", "method", "toolsmith", "founder") + } + by_name = {spec.name: spec for spec in catalog.all_specs} + founder = release.requirement_targets(by_name["bmad-founder"], catalog, mods) + self.assertEqual(founder[TARGET_CORE], "bmad-core-tools") + self.assertEqual(founder["github:bmad-code-org/BMAD-METHOD/skills/founder"], "bmad-founder") + bundle = release.requirement_targets(by_name["bmad"], catalog, mods) + self.assertEqual(bundle[TARGET_CORE], "bmad") + self.assertEqual(bundle["github:bmad-code-org/BMAD-METHOD/skills/method"], "bmad") + self.assertEqual(bundle["github:bmad-code-org/BMAD-METHOD/skills/founder"], "bmad-founder") + def test_rewrite_root_dotted_keys_and_ignores_nested_bmod_dotted_under_other_table(self) -> None: original = ( 'bmod.update_source = "github:org/repo/skills"\n' @@ -328,6 +417,21 @@ def test_full_cli_only_bundle_sync_zip_schema_and_negative_checks(self) -> None: self.assertFalse((repo / "plugins/toolbox").exists()) self.assertFalse((repo / "plugins/core-tools/skills/bmad/UNTRACKED_DIRTY.txt").exists()) + # Requirement sources point at the plugin that ships the skill; the bundle points at itself. + def req_sources(rel: str, table: str, field: str) -> list[str]: + data = tomllib.loads((repo / "plugins" / rel / "bmod.toml").read_text()) + return [entry["source"] for entry in data[table][field]] + + self.assertEqual(req_sources("method/skills/bmod-method", "bmod", "required_skills"), ["plugin:bmad-core-tools"]) + self.assertEqual(req_sources("method/skills/bmad-build", "skill", "recommended_skills"), ["plugin:bmad-tea"]) + self.assertEqual(req_sources("bmad/skills/bmod-method", "bmod", "required_skills"), ["plugin:bmad"]) + self.assertEqual(req_sources("bmad/skills/bmad-build", "skill", "recommended_skills"), ["plugin:bmad-tea"]) + self.assertEqual( + req_sources("bmad-loop/skills/bmod-bmad-loop", "bmod", "required_skills"), + ["plugin:bmad-core-tools", "plugin:bmad-method"], + ) + self.assertIn("# the build skill ships in method", (repo / "plugins/bmad-loop/skills/bmod-bmad-loop/bmod.toml").read_text()) + # Verify closed Agent Plugins 1.0 schema (no "skills"), composerIcon, neutral README bmad_dir_out = repo / "plugins/bmad" self.assertTrue((bmad_dir_out / "TRADEMARK.md").is_file()) @@ -369,18 +473,36 @@ def test_full_cli_only_bundle_sync_zip_schema_and_negative_checks(self) -> None: "bmod-method", '[bmod]\ncode = "method"\nversion = "7.0.1"\n' 'update_source = "github:bmad-code-org/BMAD-METHOD/skills/method"\n' - 'skills = ["bmad-build"]\n', + 'skills = ["bmad-build"]\n' + 'required_skills = [{ skill = "bmad", version = "7.0.0", source = "github:bmad-code-org/BMAD-METHOD/skills/core-tools" }]\n', ) subprocess.run(["git", "add", "-A"], cwd=bmad_dir, check=True) subprocess.run(["git", "commit", "-q", "-m", "bump method"], cwd=bmad_dir, check=True) + tea_arg = f"--source=bmad-code-org/bmad-method-test-architecture-enterprise={sources['bmad-code-org/bmad-method-test-architecture-enterprise']}" self.assertEqual( release.main( - [f"--source=bmad-code-org/BMAD-METHOD={bmad_dir}", "--only=bmad-method"], + [f"--source=bmad-code-org/BMAD-METHOD={bmad_dir}", tea_arg, "--only=bmad-method"], repo_root=repo, ), 0, ) + # bmad-loop's requirements live in BMAD-METHOD, which --only must also read to resolve them. + self.assertEqual( + release.main( + [ + f"--source=bmad-code-org/BMAD-METHOD={bmad_dir}", + f"--source=bmad-code-org/bmad-loop={sources['bmad-code-org/bmad-loop']}", + "--only=bmad-loop", + ], + repo_root=repo, + ), + 0, + ) + self.assertEqual( + req_sources("bmad-loop/skills/bmod-bmad-loop", "bmod", "required_skills"), + ["plugin:bmad-core-tools", "plugin:bmad-method"], + ) self.assertEqual(json.loads((repo / "plugins/method/.claude-plugin/plugin.json").read_text())["version"], "7.0.1") self.assertEqual(json.loads((repo / "plugins/bmad/.claude-plugin/plugin.json").read_text())["version"], "7.0.1") self.assertTrue((repo / ".agents/plugins/marketplace.json").is_file()) @@ -394,7 +516,11 @@ def test_full_cli_only_bundle_sync_zip_schema_and_negative_checks(self) -> None: ["--only=,"], ["--only=nonexistent"], ["--source=bmad-code-org/bmad-loop="], - [f"--source=bmad-code-org/bmad-loop={root / 'missing-dir'}"], + [ + f"--source=bmad-code-org/BMAD-METHOD={bmad_dir}", + tea_arg, + f"--source=bmad-code-org/bmad-loop={root / 'missing-dir'}", + ], ): with self.assertRaises(SystemExit): release.main(bad_argv, repo_root=repo) @@ -419,6 +545,23 @@ def test_full_cli_only_bundle_sync_zip_schema_and_negative_checks(self) -> None: release.validate_repo(repo) founder_bmod.write_text(orig_fb) + method_bmod = repo / "plugins/method/skills/bmod-method/bmod.toml" + orig_mb = method_bmod.read_text() + for bad_source in (TARGET_CORE, "plugin:bmad-method", "plugin:bmad", "plugin:bmad-missing"): + self.assertIn('"plugin:bmad-core-tools"', orig_mb) + method_bmod.write_text(orig_mb.replace('"plugin:bmad-core-tools"', f'"{bad_source}"')) + with self.assertRaises(SystemExit): + release.validate_repo(repo) + method_bmod.write_text(orig_mb) + bundle_bmod = repo / "plugins/bmad/skills/bmod-method/bmod.toml" + orig_bb = bundle_bmod.read_text() + self.assertIn('source = "plugin:bmad" }', orig_bb) + bundle_bmod.write_text(orig_bb.replace('source = "plugin:bmad" }', 'source = "plugin:bmad-core-tools" }')) + with self.assertRaises(SystemExit): + release.validate_repo(repo) + bundle_bmod.write_text(orig_bb) + release.validate_repo(repo) + dup_dir = repo / "plugins/founder/skills/bmad" _write_skill( repo / "plugins/founder",