domain_command_registry.py
python
sha256:08c083095bcaffb4c43ce947668fac93bf5d261e13d321776170c4019dd1d77d
fix: migration must never update identity.toml on a failed …
Sonnet 5
minor
⚠ breaking
9 hours ago
| 1 | """Registry mapping a domain name to its dedicated CLI subcommand names. |
| 2 | |
| 3 | Populated as a side effect of argparse tree construction (muse.cli.app's |
| 4 | `main()`, and the `register()` functions of domain-named command modules |
| 5 | like `mist.py`/`social.py`) — never hand-typed anywhere. See muse#74: a |
| 6 | domain's `supported_commands` manifest field was previously a literal |
| 7 | Python list hardcoded into `muse domains publish`, identical for every |
| 8 | domain regardless of what it actually supports. |
| 9 | |
| 10 | A domain with no dedicated top-level `muse <name> <verb>` namespace (e.g. |
| 11 | "identity") simply has no entry — querying it returns `[]`, which is the |
| 12 | honest answer, not a borrowed list from an unrelated domain. |
| 13 | |
| 14 | This module has zero dependencies on `app.py` or any command module, by |
| 15 | design — it must be importable from anywhere (including `domains.py`) |
| 16 | without risking a circular import. |
| 17 | """ |
| 18 | |
| 19 | from collections.abc import Iterable |
| 20 | |
| 21 | _REGISTRY: dict[str, list[str]] = {} |
| 22 | |
| 23 | |
| 24 | def register_namespace(domain_name: str, commands: Iterable[str]) -> None: |
| 25 | """Record *domain_name*'s CLI subcommand names, replacing any prior entry. |
| 26 | |
| 27 | Called once per CLI invocation, immediately after a domain-named |
| 28 | top-level command (``muse code``, ``muse mist``, ``muse social``, ...) |
| 29 | finishes building its own subparser tree — the same object argparse |
| 30 | itself dispatches from, so this can never drift from reality. |
| 31 | |
| 32 | Idempotent: registering the same *domain_name* again replaces the |
| 33 | stored list rather than merging or appending to it. |
| 34 | """ |
| 35 | _REGISTRY[domain_name] = sorted(commands) |
| 36 | |
| 37 | |
| 38 | def get_supported_commands(domain_name: str) -> list[str]: |
| 39 | """Return the live list of ``muse <domain_name> <verb>`` subcommand |
| 40 | names, or ``[]`` if *domain_name* has no dedicated top-level CLI |
| 41 | namespace. |
| 42 | |
| 43 | Returns a fresh copy — mutating the result never affects the registry. |
| 44 | """ |
| 45 | return list(_REGISTRY.get(domain_name, [])) |
File History
1 commit
sha256:08c083095bcaffb4c43ce947668fac93bf5d261e13d321776170c4019dd1d77d
fix: migration must never update identity.toml on a failed …
Sonnet 5
minor
⚠
9 hours ago