API Reference / cli /

edit_algorithm.py

tuiml edit-algorithm: patch the source of a user-authored algorithm.

Thin CLI wrapper over the tuiml_edit_algorithm tool. It performs a single exact string replacement in a stored algorithm, re-validates the result, and re-registers the class in the component registry.

Functions

Command

tuiml edit-algorithm

Line 19
tuiml edit-algorithm [OPTIONS]

Apply a targeted string replacement to a user-authored algorithm.

Replaces exactly one occurrence of --old-string with --new-string. The edit fails loudly when the text is missing or matches more than once, so add surrounding context until the snippet is unique. The patched source is AST-validated and the class is re-registered in the component registry, so every command and MCP tool sees the change right away.

The usual loop is tuiml read-algorithm to find the exact text, then this command to change it. Built-in algorithms are read-only; fork one with tuiml create-algorithm before editing it.

Requires TUIML_ALLOW_USER_ALGORITHMS=1 in the environment.

Change a default hyperparameter in the latest version:

bash
$ tuiml edit-algorithm --name MyKNN \
    --old-string "n_neighbors: int = 5" --new-string "n_neighbors: int = 7"

Keep the current version intact and save the edit as a new patch version:

bash
$ tuiml edit-algorithm --name MyKNN --bump-version \
    --old-string "metric = 'euclidean'" --new-string "metric = 'manhattan'"

Patch one specific version rather than the latest:

bash
$ tuiml edit-algorithm --name MyKNN --version 1.0.0 \
    --old-string "return preds" --new-string "return preds.astype(int)"

Options

--name
str required
User algorithm name (directory name / class name).
--old-string
str required
Exact text to replace. Must appear exactly once in the file.
--new-string
str required
Replacement text.
--version
str
Version to patch, e.g. '1.0.2'. Defaults to the latest version.
--bump-version/--no-bump-version
= False
Save the edit as a new patch version instead of overwriting the current one.
--json-output
flag
Print the raw JSON result.