Interactive Helpers and Notifications¶
This slice of the utility API covers the parts of StackOps that talk directly to a person: small formatting helpers, interactive pickers, and email / HTML notification helpers.
The current modules are:
| Module | Purpose |
|---|---|
stackops.utils.accessories |
Small shared helpers such as random strings, list/timeframe splitting, rich formatting, and git-root discovery |
stackops.utils.options |
Terminal choice helpers, plus cloud and SSH selectors |
stackops.utils.options_utils.tv_options |
Preview-based selection from a mapping of names to payloads |
stackops.utils.notifications |
Markdown-to-HTML rendering plus SMTP email sending |
accessories¶
Frequently used helpers from stackops.utils.accessories include:
randstr()for random tokens or noun-style namessplit_list()for chunking lists by size or number of bucketssplit_timeframe()for splitting a UTC interval into fixed windowspprint(),get_repr(), andhuman_friendly_dict()for human-readable outputget_repo_root()for locating the git repository root from aPath
These are intentionally small, but they show up throughout the CLI and helper layers.
choose_from_options¶
stackops.utils.options.choose_from_options() is the main interactive picker.
Current behavior:
- accepts any iterable of options
- supports a numbered prompt fallback
- can use Television when
tv=Trueandtvis installed - supports
preview="bat"for Television-backed previews - accepts an optional default item
- allows custom string input when
custom_input=True
Two implementation details matter in practice:
- the default must already be present in the option list
- multi-select is primarily implemented through the Television path; the plain prompt fallback still behaves like a single-choice prompt
Other exported helpers in the same module:
choose_cloud_interactively()runsrclone listremotesand lets the user choose a remoteget_ssh_hosts()parses~/.ssh/configwith Paramikochoose_ssh_host()builds a Television-backed picker on top of that SSH host list
Example:
from stackops.utils.options import choose_from_options, choose_ssh_host
from stackops.utils.options_utils.tv_options import choose_from_dict_with_preview
target = choose_from_options(
options=["local", "remote", "cloud"],
msg="Select a target",
multi=False,
tv=True,
preview=None,
)
ssh_host = choose_ssh_host(multi=False)
preview_choice = choose_from_dict_with_preview(
{
"README.md": "# Example\n",
"config.toml": "workers = 8\n",
},
extension="md",
multi=False,
preview_size_percent=60,
)
print(target)
print(ssh_host)
print(preview_choice)
Preview selection¶
stackops.utils.options_utils.tv_options.choose_from_dict_with_preview() is the lower-level preview helper used by AST search, semantic search, and other payload-preview flows.
It takes:
- a mapping from option label to preview content
- an optional extension hint
multi=TrueorFalse- a preview size percentage
The implementation dispatches to Windows- or Unix-specific Television helpers.
Notifications¶
stackops.utils.notifications currently exposes three main layers:
download_to_memory()for fetching a remote asset into memorymd2html()for turning Markdown into HTML through Rich's HTML exporterEmailfor SMTP-based email sending
Current Email behavior:
Email.get_source_of_truth()reads config from~/dotfiles/stackops/emails.iniEmail.__init__()opens either an SSL or TLS SMTP connection based on the configsend_message()appends an automation footer and optionally converts Markdown to HTMLsend_and_close()requires aconfig_name;config_name=Nonecurrently raisesNotImplementedError
Example:
from stackops.utils.notifications import Email, md2html
html = md2html("# Report\nAll tasks finished.")
print(html[:120])
Email.send_and_close(
config_name="primary",
to="team@example.com",
subject="Job finished",
body="# Completed\nAll tasks finished successfully.",
)
API reference¶
Accessories¶
Options¶
options
¶
Preview selection¶
tv_options
¶
Notifications¶
notifications
¶
Notifications Module