Spokes API¶
Plugin system and event bus.
spokes¶
Spoke discovery, loading, and event bus implementation.
spokes
¶
Axium Spokes - Plugin system and event bus.
Spokes are the plugin architecture for Axium, allowing modular extensions
without modifying core code. Each Spoke lives in ~/.config/axium/spokes/
The EventBus provides event-driven coordination, allowing Spokes to: - React to environment changes (env_change event) - Know when other Spokes load (spoke_loaded event) - Add custom CLI commands via Typer - Register prefix rules dynamically
Spoke Structure
~/.config/axium/spokes/aws/ spoke.yaml - Manifest with name and entrypoint main.py - Implementation with register(app, events) function
Manifest Format (spoke.yaml): name: aws entrypoint: aws.main:register
Standard Events
- env_change(new_env: str, old_env: str) - Environment switched
- spoke_loaded(spoke_name: str) - Spoke finished loading
Example Spoke
def register(app, events): @app.command("aws-whoami") def aws_whoami(): import boto3 print(boto3.client("sts").get_caller_identity())
def on_env_change(new_env, old_env):
print(f"Env changed: {old_env} → {new_env}")
events.on("env_change", on_env_change)
SpokeMetadata
dataclass
¶
Metadata for an installed Spoke.
Tracks installation details, version, source, and current status for lifecycle management and display purposes.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Spoke name (matches directory name) |
version |
str
|
Semantic version string (e.g., "0.1.0") |
description |
str
|
Short description of Spoke functionality |
entrypoint |
str
|
Module:function for register() (e.g., "aws.main:register") |
source |
str
|
Installation source - "local:/path", "git:url", "registry:name" |
install_mode |
str
|
"copy" or "symlink" (symlink for editable installs) |
installed_at |
str
|
ISO 8601 timestamp of installation |
last_loaded |
str | None
|
ISO 8601 timestamp of last successful load (None if never loaded) |
status |
str
|
Current status - "active", "error", or "not-loaded" |
Example
>>> metadata = SpokeMetadata(
... name="aws",
... version="0.1.0",
... description="AWS helpers",
... entrypoint="aws.main:register",
... source="local:/Users/jon/spoke-aws",
... install_mode="symlink",
... installed_at="2025-10-07T15:30:00Z",
... last_loaded="2025-10-07T15:31:00Z",
... status="active"
... )
Source code in axium/core/spokes.py
to_dict()
¶
Convert metadata to dictionary for JSON serialization.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with all metadata fields |
Source code in axium/core/spokes.py
EventBus
¶
Event bus for Spoke coordination.
Provides publish-subscribe pattern for loosely-coupled communication between Axium core and Spokes. Events are synchronous and handlers are called in registration order.
Standard Events
env_change(new_env, old_env, pane=None): Emitted when environment switches spoke_loaded(spoke_name): Emitted when a Spoke finishes initial load spoke_reloaded(spoke_name): Emitted after a Spoke is reloaded (post-action) spoke_unloaded(spoke_name): Emitted after a Spoke is unloaded (post-action) gear_loaded(gear_name): Emitted when a Gear finishes loading gear_unloaded(gear_name): Emitted after a Gear is unloaded daemon_reload: Emitted after daemon configuration is reloaded config_reloaded: Emitted after all spoke configs are cleared and reloaded hud_segment_updated(spoke, value): Emitted when a HUD segment changes hud_refresh: Emitted when HUD should be regenerated
Attributes:
| Name | Type | Description |
|---|---|---|
_listeners |
dict[str, list[Callable]]
|
Dict mapping event names to lists of callback functions |
Example
Source code in axium/core/spokes.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
__init__()
¶
Initialize empty event bus.
Creates an empty listener registry. Listeners are added via on().
on(event_name, callback)
¶
Subscribe to an event.
Registers a callback to be invoked when the event is emitted. Multiple callbacks can be registered for the same event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_name
|
str
|
Name of event to listen for (e.g., "env_change") |
required |
callback
|
Callable
|
Function to call when event is emitted |
required |
Example
Note
Callbacks are invoked synchronously in registration order. Exceptions in callbacks are logged but don't stop event propagation.
Source code in axium/core/spokes.py
emit(event_name, *args, **kwargs)
¶
Emit an event to all subscribers.
Calls all registered callbacks for this event with provided arguments. If a callback raises an exception, it's logged and remaining callbacks continue to execute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_name
|
str
|
Name of event to emit |
required |
*args
|
Positional arguments to pass to callbacks |
()
|
|
**kwargs
|
Keyword arguments to pass to callbacks |
{}
|
Note
Events are synchronous - emit() blocks until all callbacks complete. Unknown events (no listeners) are silently ignored.
Source code in axium/core/spokes.py
get_event_bus()
¶
Get the global event bus singleton.
Returns the shared EventBus instance used by core and all Spokes. This ensures all parts of Axium communicate via the same event bus.
Returns:
| Type | Description |
|---|---|
EventBus
|
Global EventBus instance |
Example
Note
The singleton is created on first module import. All Spokes receive the same instance via register(app, events).
Source code in axium/core/spokes.py
get_spoke_metadata()
¶
Get metadata for all installed Spokes.
Loads metadata from JSON file and enriches with current status from the command registry.
Returns:
| Type | Description |
|---|---|
list[SpokeMetadata]
|
List of SpokeMetadata objects, sorted by name |
Example
Note
Status is enriched with current load state from registry. Spokes in metadata but not in registry show as "not-loaded".
Source code in axium/core/spokes.py
create_spoke(name, description=None, version='0.1.0', interactive=True)
¶
Create a new Spoke from template.
Scaffolds a new Spoke directory with spoke.yaml manifest and main.py implementation template. Prompts for details interactively if enabled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Spoke name (used for directory and defaults) |
required |
description
|
str | None
|
Short description (prompted if None and interactive=True) |
None
|
version
|
str
|
Semantic version string (default: "0.1.0") |
'0.1.0'
|
interactive
|
bool
|
Prompt for missing values if True |
True
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to created Spoke directory |
Example
Raises:
| Type | Description |
|---|---|
FileExistsError
|
If Spoke directory already exists |
ValueError
|
If name is invalid (empty, contains invalid characters) |
Note
- Creates directory structure in ~/.config/axium/spokes/
/ - Generates spoke.yaml with metadata
- Creates main.py with register() function and example command
- Adds entry to .spoke_metadata.json
Source code in axium/core/spokes.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 | |
validate_spoke(spoke_dir)
¶
Validate Spoke directory structure and manifest.
Checks that spoke_dir contains a valid spoke.yaml with required fields and that the entrypoint module exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spoke_dir
|
Path
|
Path to Spoke directory to validate |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with parsed spoke.yaml data if valid |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If spoke.yaml missing |
ValueError
|
If spoke.yaml invalid or missing required fields |
Note
Required fields in spoke.yaml: name, version, description, entrypoint Entrypoint format: "spoke.module:function" (e.g., "aws.main:register")
Source code in axium/core/spokes.py
install_spoke(source, editable=False, name=None)
¶
Install a Spoke from source.
Supports installation from local directories. Git and registry sources are planned for future implementation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Installation source - local path, git URL, or registry name |
required |
editable
|
bool
|
If True, symlink instead of copy (for development) |
False
|
name
|
str | None
|
Override Spoke name from manifest (optional) |
None
|
Returns:
| Type | Description |
|---|---|
SpokeMetadata
|
SpokeMetadata object for installed Spoke |
Example
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If source doesn't exist or invalid |
ValueError
|
If spoke.yaml invalid |
FileExistsError
|
If Spoke already installed |
Note
- Validates spoke.yaml before installation
- Adds entry to .spoke_metadata.json
- Does not auto-reload (caller should call reload_spokes())
Source code in axium/core/spokes.py
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 | |
reload_spokes(spoke_name=None)
¶
Reload spoke(s) dynamically without restarting daemon.
Unloads specified spoke(s) by clearing their commands from the registry, reloads their Python modules, and re-calls register() to re-register commands and event handlers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spoke_name
|
str | None
|
Specific spoke to reload, or None to reload all |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of spoke names that were successfully reloaded |
Raises:
| Type | Description |
|---|---|
ValueError
|
If specified spoke_name is not installed |
Example
Note
- Updates last_loaded timestamp in metadata
- Sets status to "active" on success, "error" on failure
- Emits spoke_reloaded event for each successful reload
- Useful for development without daemon restarts
Source code in axium/core/spokes.py
793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 | |
load_spokes(parent_app)
¶
Discover and load all Spokes from ~/.config/axium/spokes/.
Scans the spokes directory for subdirectories containing spoke.yaml. For each valid Spoke: 1. Parse spoke.yaml manifest 2. Import the entrypoint module 3. Call register(app, events) with CLI app and EventBus 4. Emit spoke_loaded event
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent_app
|
Any
|
Typer application instance to pass to Spoke register functions |
required |
Spoke Discovery
- Searches ~/.config/axium/spokes/
- Each subdirectory is checked for spoke.yaml
- Manifest must contain 'name' and 'entrypoint'
- Entrypoint format: "spoke.module:function" (e.g., "aws.main:register")
Register Signature
def register(app: Typer, events: EventBus) -> None
Example
Note
- Spokes are loaded in alphabetical order by directory name
- Errors in individual Spokes are logged but don't stop loading
- The spoke directory is added to sys.path for imports
- Returns silently if spokes directory doesn't exist
Source code in axium/core/spokes.py
965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 | |
list_spokes()
¶
List all installed Spokes to stdout.
Scans ~/.config/axium/spokes/ and displays Spoke names with their directory paths. Validates spoke.yaml exists and parses the name.
Output Format
Installed Spokes: - aws (~/.config/axium/spokes/aws) - k8s (~/.config/axium/spokes/k8s) (none found) # if directory empty/missing
Example
Note
- Displays "(none found)" if no Spokes are installed
- Shows "(invalid manifest: ...)" for Spokes with malformed YAML
- Does not attempt to load Spokes, only lists them