-
-
Notifications
You must be signed in to change notification settings - Fork 11
feat(skills): add TOML-based skill customization system #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bf06f2c
feat(skills): add TOML-based skill customization system
bmadcode 506b900
fix: narrow exception handler in resolve-customization.py
bmadcode fbcae64
refactor(agents): read persona from customization instead of hardcoding
bmadcode 94c29ac
style(skills): follow agentskills.io script conventions
bmadcode bf3189a
fix: address review findings from code review
bmadcode 96a8bdb
fix: harden resolve script type hint + improve inject prompt wording
bmadcode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/skills/bmad-cis-agent-brainstorming-coach/customize.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # ────────────────────────────────────────────────────────────────── | ||
| # Customization Defaults: bmad-cis-agent-brainstorming-coach | ||
| # This file defines all customizable fields for this skill. | ||
| # DO NOT EDIT THIS FILE -- it is overwritten on every update. | ||
| # | ||
| # HOW TO CUSTOMIZE: | ||
| # 1. Create an override file with only the fields you want to change: | ||
| # _bmad/customizations/bmad-cis-agent-brainstorming-coach.toml (team/org, committed to git) | ||
| # _bmad/customizations/bmad-cis-agent-brainstorming-coach.user.toml (personal, gitignored) | ||
| # 2. Copy just the fields you want to override into your file. | ||
| # Unmentioned fields inherit from this defaults file. | ||
| # 3. For array fields (like additional_resources), include the | ||
| # complete array you want -- arrays replace, not append. | ||
| # ────────────────────────────────────────────────────────────────── | ||
|
|
||
| # Additional resource files loaded into agent context on activation. | ||
| # Paths are relative to {project-root}. | ||
| additional_resources = [] | ||
|
|
||
| # ────────────────────────────────────────────────────────────────── | ||
| # Skill metadata - used by the installer for manifest generation. | ||
| # ────────────────────────────────────────────────────────────────── | ||
| [metadata] | ||
| type = "agent" | ||
| name = "bmad-cis-agent-brainstorming-coach" | ||
| module = "cis" | ||
| role = "Master Brainstorming Facilitator + Innovation Catalyst" | ||
| capabilities = "brainstorming facilitation, creative techniques, systematic innovation" | ||
|
|
||
| # ────────────────────────────────────────────────────────────────── | ||
| # Agent persona | ||
| # ────────────────────────────────────────────────────────────────── | ||
| [persona] | ||
| displayName = "Carson" | ||
| title = "Elite Brainstorming Specialist" | ||
| icon = "🧠" | ||
|
|
||
| identity = """\ | ||
| Elite facilitator with 20+ years leading breakthrough sessions. Expert in creative techniques, group dynamics, and systematic innovation.""" | ||
|
|
||
| communicationStyle = """\ | ||
| Talks like an enthusiastic improv coach - high energy, builds on ideas with YES AND, celebrates wild thinking""" | ||
|
|
||
| principles = """\ | ||
| Psychological safety unlocks breakthroughs. Wild ideas today become innovations tomorrow. Humor and play are serious innovation tools.""" | ||
|
|
||
| # ────────────────────────────────────────────────────────────────── | ||
| # Menu customization docs (commented example) | ||
| # ────────────────────────────────────────────────────────────────── | ||
|
|
||
| # ────────────────────────────────────────────────────────────────── | ||
| # Injected prompts | ||
| # ────────────────────────────────────────────────────────────────── | ||
| [inject] | ||
| before = "" |
183 changes: 183 additions & 0 deletions
183
src/skills/bmad-cis-agent-brainstorming-coach/scripts/resolve-customization.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| #!/usr/bin/env python3 | ||
| # /// script | ||
| # requires-python = ">=3.11" | ||
| # /// | ||
| """Resolve customization for a BMad skill using three-layer TOML merge. | ||
|
|
||
| Reads customization from three layers (highest priority first): | ||
| 1. {project-root}/_bmad/customizations/{name}.user.toml (personal, gitignored) | ||
| 2. {project-root}/_bmad/customizations/{name}.toml (team/org, committed) | ||
| 3. ./customize.toml (skill defaults) | ||
|
|
||
| Outputs merged JSON to stdout. Errors go to stderr. | ||
|
|
||
| Usage: | ||
| python ./scripts/resolve-customization.py {skill-name} | ||
| python ./scripts/resolve-customization.py {skill-name} --key persona | ||
| python ./scripts/resolve-customization.py {skill-name} --key persona.displayName --key inject | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import json | ||
| import sys | ||
| import tomllib | ||
| from pathlib import Path | ||
| from typing import Any | ||
|
|
||
|
|
||
| def find_project_root(start: Path) -> Path | None: | ||
| """Walk up from *start* looking for a directory containing ``_bmad/`` or ``.git``.""" | ||
| current = start.resolve() | ||
| while True: | ||
| if (current / "_bmad").is_dir() or (current / ".git").exists(): | ||
| return current | ||
| parent = current.parent | ||
| if parent == current: | ||
| return None | ||
| current = parent | ||
|
|
||
|
|
||
| def load_toml(path: Path) -> dict[str, Any]: | ||
| """Return parsed TOML or empty dict if the file doesn't exist.""" | ||
| if not path.is_file(): | ||
| return {} | ||
| try: | ||
| with open(path, "rb") as f: | ||
| return tomllib.load(f) | ||
| except (tomllib.TOMLDecodeError, OSError) as exc: | ||
| print(f"warning: failed to parse {path}: {exc}", file=sys.stderr) | ||
| return {} | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Merge helpers | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| def _is_menu_array(value: Any) -> bool: | ||
| """True when *value* is a non-empty list where ALL items are dicts with a ``code`` key.""" | ||
| return ( | ||
| isinstance(value, list) | ||
| and len(value) > 0 | ||
| and all(isinstance(item, dict) and "code" in item for item in value) | ||
| ) | ||
|
|
||
|
|
||
| def merge_menu(base: list[dict], override: list[dict]) -> list[dict]: | ||
| """Merge-by-code: matching codes replace; new codes append.""" | ||
| result_by_code: dict[str, dict] = {item["code"]: dict(item) for item in base if "code" in item} | ||
| for item in override: | ||
| if "code" not in item: | ||
| print(f"warning: menu item missing 'code' key, skipping: {item}", file=sys.stderr) | ||
| continue | ||
| result_by_code[item["code"]] = dict(item) | ||
| return list(result_by_code.values()) | ||
|
|
||
|
|
||
| def deep_merge(base: dict[str, Any], override: dict[str, Any]) -> dict[str, Any]: | ||
| """Recursively merge *override* into *base*. | ||
|
|
||
| Rules: | ||
| - Tables (dicts): sparse override -- recurse, unmentioned keys kept. | ||
| - ``[[menu]]`` arrays (items with ``code`` key): merge-by-code. | ||
| - All other arrays: atomic replace. | ||
| - Scalars: override wins. | ||
| """ | ||
| merged = dict(base) | ||
| for key, over_val in override.items(): | ||
| base_val = merged.get(key) | ||
|
|
||
| if isinstance(over_val, dict) and isinstance(base_val, dict): | ||
| merged[key] = deep_merge(base_val, over_val) | ||
| elif _is_menu_array(over_val) and _is_menu_array(base_val): | ||
| merged[key] = merge_menu(base_val, over_val) # type: ignore[arg-type] | ||
| else: | ||
| merged[key] = over_val | ||
|
|
||
| return merged | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Key extraction | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| def extract_key(data: dict[str, Any], dotted_key: str) -> Any: | ||
| """Retrieve a value by dotted path (e.g. ``persona.displayName``).""" | ||
| parts = dotted_key.split(".") | ||
| current: Any = data | ||
| for part in parts: | ||
| if isinstance(current, dict) and part in current: | ||
| current = current[part] | ||
| else: | ||
| return None | ||
| return current | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Main | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| def main() -> None: | ||
| parser = argparse.ArgumentParser( | ||
| description="Resolve BMad skill customization (three-layer TOML merge).", | ||
| epilog=( | ||
| "Resolution priority: user.toml > team.toml > skill defaults.\n" | ||
| "Output is JSON. Use --key to request specific fields (JIT resolution)." | ||
| ), | ||
| ) | ||
| parser.add_argument( | ||
| "skill_name", | ||
| help="Skill identifier (e.g. bmad-agent-pm, bmad-product-brief)", | ||
| ) | ||
| parser.add_argument( | ||
| "--key", | ||
| action="append", | ||
| dest="keys", | ||
| metavar="FIELD", | ||
| help="Dotted field path to resolve (repeatable). Omit for full dump.", | ||
| ) | ||
| args = parser.parse_args() | ||
|
|
||
| # Locate the skill's own customize.toml (one level up from scripts/) | ||
| script_dir = Path(__file__).resolve().parent | ||
| skill_dir = script_dir.parent | ||
| defaults_path = skill_dir / "customize.toml" | ||
|
|
||
| # Locate project root for override files | ||
| project_root = find_project_root(Path.cwd()) | ||
| if project_root is None: | ||
| # Try from the skill directory as fallback | ||
| project_root = find_project_root(skill_dir) | ||
|
|
||
| # Load three layers (lowest priority first, then merge upward) | ||
| defaults = load_toml(defaults_path) | ||
|
|
||
| team: dict[str, Any] = {} | ||
| user: dict[str, Any] = {} | ||
| if project_root is not None: | ||
| customizations_dir = project_root / "_bmad" / "customizations" | ||
| team = load_toml(customizations_dir / f"{args.skill_name}.toml") | ||
| user = load_toml(customizations_dir / f"{args.skill_name}.user.toml") | ||
|
|
||
| # Merge: defaults <- team <- user | ||
| merged = deep_merge(defaults, team) | ||
| merged = deep_merge(merged, user) | ||
|
|
||
| # Output | ||
| if args.keys: | ||
| result = {} | ||
| for key in args.keys: | ||
| value = extract_key(merged, key) | ||
| if value is not None: | ||
| result[key] = value | ||
| json.dump(result, sys.stdout, indent=2, ensure_ascii=False) | ||
| else: | ||
| json.dump(merged, sys.stdout, indent=2, ensure_ascii=False) | ||
|
|
||
| # Ensure trailing newline for clean terminal output | ||
| print() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
load_toml()returns{}on parse errors (and on missing files), so a malformed override (or an unexpectedly missing defaults file) can silently produce “valid” merged JSON while exiting 0. Consider failing fast (non-zero exit) for these cases so customization mistakes don’t get silently ignored.Severity: medium
Other Locations
src/skills/bmad-cis-agent-creative-problem-solver/scripts/resolve-customization.py:51src/skills/bmad-cis-agent-design-thinking-coach/scripts/resolve-customization.py:51src/skills/bmad-cis-agent-innovation-strategist/scripts/resolve-customization.py:51src/skills/bmad-cis-agent-presentation-master/scripts/resolve-customization.py:51src/skills/bmad-cis-agent-storyteller/scripts/resolve-customization.py:51src/skills/bmad-cis-design-thinking/scripts/resolve-customization.py:51src/skills/bmad-cis-innovation-strategy/scripts/resolve-customization.py:51src/skills/bmad-cis-problem-solving/scripts/resolve-customization.py:51src/skills/bmad-cis-storytelling/scripts/resolve-customization.py:51🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.