naas_abi.cli
What it is
A small interactive CLI module that scaffolds ABI modules and components by copying files from src/core/__templates__, performing simple string replacements, and (for modules) enabling the new module in YAML config files.
Public API
format_module_name(name: str) -> str- Normalizes a raw module name (lowercase, underscores, removes invalid characters).
get_component_selection() -> dict- Prompts for which template component folders to include when creating a module.
enable_module_in_config(module_path: str) -> None- Updates
config.yamlorconfig.<ENV>.yaml(if present) to ensure the given module path is listed undermoduleswithenabled: True.
- Updates
create_new_module() -> None- Interactive module generator:
- Prompts for module name and target location (
src/core,src/custom, marketplace paths). - Copies selected components from
src/core/__templates__into the new module directory. - Rewrites template references inside
.py,.md,.ttlfiles and renames filenames containingTemplate. - Attempts to enable the module in config.
- Prompts for module name and target location (
- Interactive module generator:
create_agent() -> None- Interactive agent generator:
- Copies
TemplateAgent.pyandTemplateAgent_test.pyinto a chosen target folder as<Name>Agent.pyand<Name>Agent_test.py. - Adjusts imports based on target location.
- Ensures a
models/folder exists at the module root (creates it from templates if missing).
- Copies
- Interactive agent generator:
create_component(component_type: str, template_files: list[str], file_suffix: str) -> None- Generic interactive component generator used by the specific helpers below.
create_integration() -> None- Creates an integration from template files.
create_workflow() -> None- Creates a workflow from template files.
create_pipeline() -> None- Creates a pipeline from template files.
create_ontology() -> None- Creates ontology
.ttlfiles from templates.
- Creates ontology
main() -> None- CLI entry point. Dispatches based on
sys.argv[1]:create-module,create-agent,create-integration,create-workflow,create-pipeline,create-ontology.
- CLI entry point. Dispatches based on
Configuration/Dependencies
- Filesystem expectations:
- Templates must exist under
src/core/__templates__/(e.g.,agents/TemplateAgent.py,models/, etc.). - Config files are optional:
- Reads/writes
config.yamland may preferconfig.<ENV>.yamldepending on environment resolution.
- Reads/writes
- Templates must exist under
- Environment/config resolution for enabling modules:
- Uses
ENVenvironment variable if set. - Otherwise may inspect
config.yamlto find a dotenv secret adapter and readENVfrom that dotenv file.
- Uses
- Python dependencies:
PyYAML(yaml.safe_load,yaml.dump)rich(Console,Prompt)- Optional at runtime (only when resolving ENV via dotenv adapter):
naas_abi_core.services.secret.adaptors.secondary.dotenv_secret_secondaryadaptor.DotenvSecretSecondaryAdaptor
Usage
Run as a module/script and pass a command:
import sys
from naas_abi import cli
sys.argv = ["naas-abi", "create-module"]
cli.main()
Or from a shell (equivalent behavior when executed as a script):
python -m naas_abi.cli create-agent
Available commands:
create-modulecreate-agentcreate-integrationcreate-workflowcreate-pipelinecreate-ontology
Caveats
- The CLI is interactive (uses
rich.prompt.Prompt) and expects to run in a TTY. - Scaffolding assumes a specific repository layout (
src/core/__templates__); missing templates will cause errors. enable_module_in_config()may modify YAML config files in-place and will attempt to sortmodulesbypath.- Module name validation in
create_new_module()allows-and.by regex, butformat_module_name()will strip hyphens (keeps only[a-z0-9_]).