cMeta open-source categories, artifacts and automations

[ Back to projects ]
[ Back ]

One category from internal.

← All categories

utils

Miscellaneous helper commands exposed through the uniform interface.

Comes from
(internal)
License
Apache-2.0
UID
234ce5e3262e4d52
Tags
category utils
Copyright
2025-2026 Grigori Fursin and cTuning Labs. See the cMeta COPYRIGHT and LICENSE files for details.

Its own commands

CommandWhat it does
access_ctuning_server
v1.py:1639-1706
Access cTuning server
signature

    def access_ctuning_server_(
        self,
        ctx,  # Execution context dictionary with category, command, and control data.
        query = {},  # Input parameter used by this function.
        headers = {},  # Input parameter used by this function.
        timeout = 30,  # Timeout value in seconds.
        url = None,  # Input parameter used by this function.
        api_key = None,  # Input parameter used by this function.
        files = {},  # Input parameter used by this function.
    ):

        """
            Access cTuning server

            Args:
                ctx: Execution context dictionary with category, command, and control data.
                query: Input parameter used by this function.
                headers: Input parameter used by this function.
                timeout: Timeout value in seconds.
                url: Input parameter used by this function.
                api_key: Input parameter used by this function.
                files: Input parameter used by this function.
            Returns:
                dict: Operation result.
            Raises:
                Exception: Propagated runtime errors, if any.
        """
api_key
v1.py:160-235
Generate API keys for a cMeta config (for example the `api_keys` list of the `cserver` web app).
signature

    def api_key_(
        self,
        ctx,  # cMeta context object.
        arg1 = 1,  # How many keys to generate.
        nbytes = 24,  # Random bytes per key (24 -> 192 bits, a 32-character string).
        config = 'cserver',  # Config artifact named in the ready-to-paste command.
        key = 'api_keys',  # Config key named in the ready-to-paste command.
        bare = False,  # Print the keys alone, for scripts.
        clipboard = False,  # Copy the keys to the clipboard.
    ):

        """
            Generate API keys for a cMeta config (for example the `api_keys` list of the `cserver` web app).

            A key is only a random string: the server compares what a request carries against the list in the
            config. These come from `secrets.token_urlsafe`, so they are safe to use as bearer tokens.

                cx utils api_key                     one key, with the line to paste
                cx utils api_key 3                   three keys, ready for a device each
                cx utils api_key --bare              the key alone, for a script
                cx utils api_key --nbytes=32         a longer key

            Args:
                ctx (dict): cMeta context object.
                arg1 (int): How many keys to generate.
                nbytes (int): Random bytes per key (24 -> 192 bits, a 32-character string).
                config (str): Config artifact named in the ready-to-paste command.
                key (str): Config key named in the ready-to-paste command.
                bare (bool): Print the keys alone, for scripts.
                clipboard (bool): Copy the keys to the clipboard.

            Returns:
                dict: Operation result with `api_keys` (a list) and `api_key` (the first one).
            Raises:
                Exception: Propagated runtime errors, if any.
        """
artifacts
v1.py:1410-1530
Analyze all artifacts for all categories
signature

    def artifacts_(
        self,
        ctx,  # Execution context dictionary with category, command, and control data.
        arg1 = None,  # First positional argument from command input.
        arg2 = None,  # Second positional argument from command input.
        skip_categories = None,  # Input parameter used by this function.
        func = None,  # Input parameter used by this function.
        func_params = {},  # Input parameter used by this function.
    ):

        """
            Analyze all artifacts for all categories

            arg1: categories
            arg2: artifacts
            top_num: number of top artifacts to show in rankings (default: 30)
            slow: if False (default), use cached results when artifact hasn't changed; if True, always perform deep analysis

            @base.find_

            Args:
                ctx: Execution context dictionary with category, command, and control data.
                arg1: First positional argument from command input.
                arg2: Second positional argument from command input.
                skip_categories: Input parameter used by this function.
                func: Input parameter used by this function.
                func_params: Input parameter used by this function.
            Returns:
                dict: Operation result.
            Raises:
                Exception: Propagated runtime errors, if any.
        """
convert_old_entries
v1.py:1256-1407
Convert legacy CK/CM/CMX entries in a path (arg1) by merging _cmeta.json or _cmeta.yaml with meta
signature

    def convert_old_entries_(
        self,
        ctx,  # cMeta context.
        arg1 = '.',  # Path to search for entries to convert.
        meta = {},  # Merge this meta with existing _cmeta files.
    ):

        """
            Convert legacy CK/CM/CMX entries in a path (arg1) by merging _cmeta.json or _cmeta.yaml with meta

            Args:
                ctx (dict): cMeta context.
                arg1 (str): Path to search for entries to convert.
                meta (dict): Merge this meta with existing _cmeta files.

            Returns:
                dict: Operation result.
            Raises:
                Exception: Propagated runtime errors, if any.
        """
copy_date_time_iso_to_clipboard
v1.py:937-961
Copy text to clipboard
signature

    def copy_date_time_iso_to_clipboard_(
        self,
        ctx,  # cMeta context object.
        do_not_fail = True,  # Do not fail on error if True.
    ):

        """
            Copy text to clipboard

            Args:
                ctx (dict): cMeta context object.
                arg1 (str): Text to copy to clipboard.
                add_quotes (bool): Add quotes to the text if True.
                do_not_fail (bool): Do not fail on error if True.

            Returns:
                dict: Operation result.
            Raises:
                Exception: Propagated runtime errors, if any.
        """
copy_date_time_to_clipboard
v1.py:910-934
Copy text to clipboard
signature

    def copy_date_time_to_clipboard_(
        self,
        ctx,  # cMeta context object.
        do_not_fail = True,  # Do not fail on error if True.
    ):

        """
            Copy text to clipboard

            Args:
                ctx (dict): cMeta context object.
                arg1 (str): Text to copy to clipboard.
                add_quotes (bool): Add quotes to the text if True.
                do_not_fail (bool): Do not fail on error if True.

            Returns:
                dict: Operation result.
            Raises:
                Exception: Propagated runtime errors, if any.
        """
copy_date_to_clipboard
v1.py:883-907
Copy text to clipboard
signature

    def copy_date_to_clipboard_(
        self,
        ctx,  # cMeta context object.
        do_not_fail = True,  # Do not fail on error if True.
    ):

        """
            Copy text to clipboard

            Args:
                ctx (dict): cMeta context object.
                arg1 (str): Text to copy to clipboard.
                add_quotes (bool): Add quotes to the text if True.
                do_not_fail (bool): Do not fail on error if True.

            Returns:
                dict: Operation result.
            Raises:
                Exception: Propagated runtime errors, if any.
        """
copy_text_to_clipboard
v1.py:858-880
Copy text to clipboard
signature

    def copy_text_to_clipboard_(
        self,
        ctx,  # cMeta context object.
        arg1 = '',  # Text to copy to clipboard.
        add_quotes = False,  # Add quotes to the text if True.
        do_not_fail = True,  # Do not fail on error if True.
    ):

        """
            Copy text to clipboard

            Args:
                ctx (dict): cMeta context object.
                arg1 (str): Text to copy to clipboard.
                add_quotes (bool): Add quotes to the text if True.
                do_not_fail (bool): Do not fail on error if True.

            Returns:
                dict: Operation result.
            Raises:
                Exception: Propagated runtime errors, if any.
        """
create_artifact_with_date
v1.py:1534-1634
Create artifact with date
signature

    def create_artifact_with_date(
        self,
        params,  # Input parameters dictionary.
    ):

        """
            Create artifact with date

            @base.create_

            Args:
                params: Input parameters dictionary.
            Returns:
                dict: Operation result.
            Raises:
                Exception: Propagated runtime errors, if any.
        """
detect_category
v1.py:713-784
Detect the cMeta category of the current (or a given) directory
signature

    def detect_category_(
        self,
        ctx,  # cMeta context.
        arg1 = None,  # Directory to inspect. If None, use the current directory.
        fail_if_not_found = False,  # If True, return an error when nothing is detected.
    ):

        """
            Detect the cMeta category of the current (or a given) directory

            Uses the same detection as `cx . <command>`: locate the plugged
            repository that contains the directory, then report the category
            (and the artifact, when standing inside one).

            Prints the category as `alias,UID`, or as just the alias when the
            UID is not known - such as when standing in the category directory
            itself rather than inside one of its artifacts. Prints nothing when
            no category can be detected.

            Detecting nothing is not an error: the command returns 0 with
            `category` set to None, so callers can fall back to a wider search.
            Pass `fail_if_not_found` to turn it into an error instead.

            Args:
                ctx (dict): cMeta context.
                arg1 (str): Directory to inspect. If None, use the current directory.
                fail_if_not_found (bool): If True, return an error when nothing is detected.

            Returns:
                dict: Operation result with `category` (str or None),
                      `category_alias`, `category_uid`, `artifact_name`,
                      `artifact_repo_name` and the inspected `path`.
            Raises:
                Exception: Propagated runtime errors, if any.
        """
detect_repo
v1.py:787-855
Detect the cMeta repository of the current (or a given) directory
signature

    def detect_repo_(
        self,
        ctx,  # cMeta context.
        arg1 = None,  # Directory to inspect. If None, use the current directory.
        fail_if_not_found = False,  # If True, return an error when nothing is detected.
    ):

        """
            Detect the cMeta repository of the current (or a given) directory

            The counterpart of `detect_category`, using the same detection as
            `cx . <command>`: find which plugged repository contains the
            directory.

            Prints the repository as `alias,UID`, or as just the alias or UID
            when only one of them is known. Prints nothing when the directory
            is outside every plugged repository.

            Detecting nothing is not an error: the command returns 0 with
            `repo` set to None, so callers can fall back to a wider search.
            Pass `fail_if_not_found` to turn it into an error instead.

            Args:
                ctx (dict): cMeta context.
                arg1 (str): Directory to inspect. If None, use the current directory.
                fail_if_not_found (bool): If True, return an error when nothing is detected.

            Returns:
                dict: Operation result with `repo` (str or None), `repo_alias`,
                      `repo_uid`, `artifact_path` (the path relative to the
                      repository root) and the inspected `path`.
            Raises:
                Exception: Propagated runtime errors, if any.
        """
find_by_cid
v1.py:316-551
Find artifacts by standard CID
signature

    def find_by_cid_(
        self,
        ctx,  # cMeta context.
        arg1 = None,  # Standard CID.
        tags = None,  # Comma-separated string or iterable of tags to match ("-tag" excludes).
        far = False,  # If True, open FAR manager in found artifact path.
        web = False,  # If True, decode web-style `cmeta:///?` CID input.
        ask = False,  # If True, ask for CID in console.
        skip_non_indexed = False,  # If True, skip non-indexed repositories.
        match = None,  # Value for match.
        match_empty_version = False,  # Value for match empty version.
        match_empty_values = False,  # Match when queried values or keys are empty.
        all_tags = None,  # Value for all tags.
        smart_match = None,  # Comma-separated values - keep artifacts holding any of them under any meta key.
        search_text = None,  # Space-separated texts - keep artifacts whose files contain any of them.
        search_files = None,  # Comma-separated globs naming those files (default "*info*.md"; "**" recurses).
        search_file_names = None,  # Space-separated strings that must ALL appear in a file name (recursive).
        after_date = None,  # Keep artifacts dated on or after this (ISO or YYYY[MM[DD[-HHMM]]]).
        before_date = None,  # Keep artifacts dated on or before this (same formats).
    ):

        """
            Find artifacts by standard CID

            Args:
                ctx (dict): cMeta context.
                arg1 (str): Standard CID.
                tags (str): Comma-separated string or iterable of tags to match ("-tag" excludes).
                far (bool): If True, open FAR manager in found artifact path.
                web (bool): If True, decode web-style `cmeta:///?` CID input.
                ask (bool): If True, ask for CID in console.
                skip_non_indexed (bool): If True, skip non-indexed repositories.
                match (dict): Value for match.
                match_empty_version (bool): Value for match empty version.
                match_empty_values (bool): Match when queried values or keys are empty.
                all_tags (str): Value for all tags.
                smart_match (str | list): Comma-separated values - keep artifacts holding
                                          any of them under any meta key.
                search_text (str | list): Space-separated texts - keep artifacts whose
                                          files contain any of them.
                search_files (str | list): Comma-separated globs naming those files
                                           (default "*info*.md"; "**" recurses).
                search_file_names (str | list): Space-separated strings that must ALL
                                               appear in a file name. Always recursive,
                                               and replaces search_files when given.
                after_date (str): Keep artifacts dated on or after this. Full ISO, or
                                  YYYY / YYYYMM / YYYYMMDD / YYYYMMDD-HHMM and the
                                  dashed variants. The date is taken from the artifact
                                  name when it starts with one, else from
                                  last_update_timestamp, else from creation_timestamp.
                before_date (str): Keep artifacts dated on or before this, same formats.

            Returns:
                dict: Operation result. When search_text or search_file_names was
                      given, "files" holds the full paths of every matching file
                      and those are printed instead of the artifact directories.
            Raises:
                Exception: Propagated runtime errors, if any.
        """
get_datetime
v1.py:1770-1802
Args:
signature

    def get_datetime_(
        self,
        ctx,  # Execution context dictionary with category, command, and control data.
    ):

        """
            Args:
                ctx: Execution context dictionary with category, command, and control data.
            Returns:
                dict: Operation result.
            Raises:
                Exception: Propagated runtime errors, if any.
        """
hash_password
v1.py:238-313
Hash a password for a cMeta config, so the plain text is not stored on disk.
signature

    def hash_password_(
        self,
        ctx,  # cMeta context object.
        arg1 = '',  # Password to hash. Asked for without echo when omitted.
        config = 'cserver',  # Config artifact named in the ready-to-paste command.
        key = 'password_sha256',  # Config key named in the ready-to-paste command.
        bare = False,  # Print the digest alone, for scripts.
        clipboard = False,  # Copy the digest to the clipboard.
    ):

        """
            Hash a password for a cMeta config, so the plain text is not stored on disk.

            The shipped use is the shared password of the `cserver` web app, which accepts either
            `password` (plain) or `password_sha256` (this digest, which takes precedence):

                cx utils hash_password                     # asks without echo, then confirms
                cx utils hash_password "my passphrase"     # left in the shell history - avoid
                cx utils hash_password --bare               # the digest alone

            Args:
                ctx (dict): cMeta context object.
                arg1 (str): Password to hash. Asked for without echo when omitted.
                config (str): Config artifact named in the ready-to-paste command.
                key (str): Config key named in the ready-to-paste command.
                bare (bool): Print the digest alone, for scripts ("quiet" is a reserved cMeta flag).
                clipboard (bool): Copy the digest to the clipboard.

            Returns:
                dict: Operation result with `sha256`.
            Raises:
                Exception: Propagated runtime errors, if any.
        """
json2pickle
v1.py:1137-1189
Convert JSON file to pickle file
signature

    def json2pickle_(
        self,
        ctx,  # cMeta context.
        arg1,  # JSON file.
        arg2 = None,  # Pickle file (if not specified, use base of json file with .pkl).
    ):

        """
            Convert JSON file to pickle file

            Args:
                ctx (dict): cMeta context.
                arg1 (str): JSON file.
                arg2 (str): Pickle file (if not specified, use base of json file with .pkl).

            Returns:
                dict: Operation result.
            Raises:
                Exception: Propagated runtime errors, if any.
        """
json2yaml
v1.py:964-1008
Convert JSON file to YAML file
signature

    def json2yaml_(
        self,
        ctx,  # cMeta context.
        arg1,  # Input JSON file.
        arg2 = None,  # Output YAML file (if None, use {input file without ext}.yaml).
        force = False,  # If True and output file exists, overwrite it.
        f = False,  # If True and output file exists, overwrite it.
        sort_keys = False,  # Sort keys in output if True.
    ):

        """
            Convert JSON file to YAML file

            Args:
                ctx (dict): cMeta context.
                arg1 (str): Input JSON file.
                arg2 (str): Output YAML file (if None, use {input file without ext}.yaml).
                force (bool): If True and output file exists, overwrite it.
                f (bool): If True and output file exists, overwrite it.
                sort_keys (bool): Sort keys in output if True.

            Returns:
                dict: Operation result.
            Raises:
                Exception: Propagated runtime errors, if any.
        """
native_host_check
v1.py:52-58
Check native messaging transport and the artifact's declared requests.
signature

    def native_host_check_(self, ctx, arg1=None):

        """Check native messaging transport and the artifact's declared requests."""
native_host_install
v1.py:44-50
Register a native messaging host declared by a cMeta artifact.
signature

    def native_host_install_(self, ctx, arg1=None, apply=False):

        """Register a native messaging host declared by a cMeta artifact."""
native_host_run
v1.py:60-63
Serve one framed native message using cx's active cMeta home.
signature

    def native_host_run_(self, ctx, arg1=None):

        """Serve one framed native message using cx's active cMeta home."""
pickle2json
v1.py:1079-1134
Convert pickle file to JSON file
signature

    def pickle2json_(
        self,
        ctx,  # cMeta context.
        arg1,  # Pickle file.
        arg2 = None,  # JSON file (if not specified, use base of pickle file with .json).
        sort_keys = False,  # Sort keys in output if True.
    ):

        """
            Convert pickle file to JSON file

            Args:
                ctx (dict): cMeta context.
                arg1 (str): Pickle file.
                arg2 (str): JSON file (if not specified, use base of pickle file with .json).
                sort_keys (bool): Sort keys in output if True.

            Returns:
                dict: Operation result.
            Raises:
                Exception: Propagated runtime errors, if any.
        """
pkl2json
v1.py:1060-1075
@self.pickle2json_
signature

    def pkl2json(
        self,
        params,  # Input parameters dictionary.
    ):

        """
            @self.pickle2json_

            Args:
                params: Input parameters dictionary.
            Returns:
                dict: Operation result.
            Raises:
                Exception: Propagated runtime errors, if any.
        """
select_artifact
v1.py:1752-1767
Args:
signature

    def select_artifact(
        self,
        params,  # Input parameters dictionary.
    ):

        """
            Args:
                params: Input parameters dictionary.
            Returns:
                dict: Operation result.
            Raises:
                Exception: Propagated runtime errors, if any.
        """
smart_find_by_cid
v1.py:554-661
Find artifacts by wrapped CID
signature

    def smart_find_by_cid_(
        self,
        ctx,  # cMeta context.
        arg1 = None,  # CID that can be wrapped with some text.
        far = False,  # If True, open FAR in found artifact.
        web = False,  # If True, remove cmeta:///? from CID (web request).
        ask = False,  # If True, ask for CID in console.
        cid = None,  # Direct CID to use.
        tags = None,  # Comma-separated string or iterable of tags to match ("-tag" excludes).
        match = None,  # Value for match.
        match_empty_version = False,  # Value for match empty version.
        match_empty_values = False,  # Match when queried values or keys are empty.
        all_tags = None,  # Value for all tags.
        smart_match = None,  # Comma-separated values - keep artifacts holding any of them under any meta key.
        search_text = None,  # Space-separated texts - keep artifacts whose files contain any of them.
        search_files = None,  # Comma-separated globs naming those files (default "*info*.md"; "**" recurses).
        search_file_names = None,  # Space-separated strings that must ALL appear in a file name (recursive).
        after_date = None,  # Keep artifacts dated on or after this (ISO or YYYY[MM[DD[-HHMM]]]).
        before_date = None,  # Keep artifacts dated on or before this (same formats).
    ):

        """
            Find artifacts by wrapped CID

            Args:
                ctx (dict): cMeta context.
                arg1 (str): CID that can be wrapped with some text.
                far (bool): If True, open FAR in found artifact.
                web (bool): If True, remove cmeta:///? from CID (web request).
                ask (bool): If True, ask for CID in console.
                cid (str): Direct CID to use.
                tags (str): Comma-separated string or iterable of tags to match ("-tag" excludes).
                match (dict): Value for match.
                match_empty_version (bool): Value for match empty version.
                match_empty_values (bool): Match when queried values or keys are empty.
                all_tags (str): Value for all tags.
                smart_match (str | list): Comma-separated values - keep artifacts holding
                                          any of them under any meta key.
                search_text (str | list): Space-separated texts - keep artifacts whose
                                          files contain any of them.
                search_files (str | list): Comma-separated globs naming those files
                                           (default "*info*.md"; "**" recurses).
                search_file_names (str | list): Space-separated strings that must ALL
                                               appear in a file name. Always recursive,
                                               and replaces search_files when given.
                after_date (str): Keep artifacts dated on or after this. Full ISO, or
                                  YYYY / YYYYMM / YYYYMMDD / YYYYMMDD-HHMM and the
                                  dashed variants. The date is taken from the artifact
                                  name when it starts with one, else from
                                  last_update_timestamp, else from creation_timestamp.
                before_date (str): Keep artifacts dated on or before this, same formats.

            Returns:
                dict: Operation result.
            Raises:
                Exception: Propagated runtime errors, if any.
        """
test
v1.py:66-89
test function.
signature

    def test(
        self,
        params,  # Input dictionary used by this function.
    ):


        """
        test function.

        Args:
            params: Input dictionary used by this function.

        Returns:
            dict: Operation result.

        Raises:
            Exception: Propagated runtime errors, if any.
        """
test_public_server
v1.py:1726-1749
@self.access_ctuning_server_
signature

    def test_public_server(
        self,
        params,  # Input parameters dictionary.
    ):

        """
            @self.access_ctuning_server_

            Args:
                params: Input parameters dictionary.
            Returns:
                dict: Operation result.
            Raises:
                Exception: Propagated runtime errors, if any.
        """
uid
v1.py:92-122
Generate a 16-character cMeta UID.
signature

    def uid_(
        self,
        ctx,  # cMeta context object.
        clipboard = True,
    ):

        """
            Generate a 16-character cMeta UID.

            Args:
                ctx (dict): cMeta context object.
                clipboard (bool): If True, copy the generated UID to the clipboard.

            Returns:
                dict: Operation result.
            Raises:
                Exception: Propagated runtime errors, if any.
        """
utf8sig_to_utf8
v1.py:1192-1252
Convert UTF-8 with BOM (utf-8-sig) file to standard UTF-8
signature

    def utf8sig_to_utf8_(
        self,
        ctx,  # cMeta context.
        arg1,  # Input file (UTF-8 with BOM).
        arg2 = None,  # Output file (if None, overwrites input file and creates .bak backup).
    ):

        """
            Convert UTF-8 with BOM (utf-8-sig) file to standard UTF-8

            Args:
                ctx (dict): cMeta context.
                arg1 (str): Input file (UTF-8 with BOM).
                arg2 (str): Output file (if None, overwrites input file and creates .bak backup).

            Returns:
                dict: Operation result.
            Raises:
                Exception: Propagated runtime errors, if any.
        """
uuid
v1.py:125-157
Generate a UUID4 string.
signature

    def uuid_(
        self,
        ctx,  # cMeta context
        clipboard = True,
    ):

        """
            Generate a UUID4 string.

            Args:
                ctx (dict): cMeta context.
                clipboard (bool): If True, copy the generated UUID to the clipboard.

            Returns:
                dict: Operation result.
            Raises:
                Exception: Propagated runtime errors, if any.
        """
x
v1.py:1709-1723
@self.access_ctuning_server_
signature

    def x(
        self,
        params,  # Input parameters dictionary.
    ):

        """
            @self.access_ctuning_server_

            Args:
                params: Input parameters dictionary.
            Returns:
                dict: Operation result.
            Raises:
                Exception: Propagated runtime errors, if any.
        """
yaml2json
v1.py:1012-1056
Convert YAML file to JSON file
signature

    def yaml2json_(
        self,
        ctx,  # cMeta context.
        arg1,  # Input YAML file.
        arg2 = None,  # Output JSON file (if None, use {input file without ext}.json).
        force = False,  # If True and output file exists, overwrite it.
        f = False,  # If True and output file exists, overwrite it.
        sort_keys = False,  # Sort keys in output if True.
    ):

        """
            Convert YAML file to JSON file

            Args:
                ctx (dict): cMeta context.
                arg1 (str): Input YAML file.
                arg2 (str): Output JSON file (if None, use {input file without ext}.json).
                force (bool): If True and output file exists, overwrite it.
                f (bool): If True and output file exists, overwrite it.
                sort_keys (bool): Sort keys in output if True.

            Returns:
                dict: Operation result.
            Raises:
                Exception: Propagated runtime errors, if any.
        """

How to use it

cx utils access_ctuning_server
cx utils                     # list every command with its help
from cmeta import CMeta
cm = CMeta()
r = cm.access({'category': 'utils,234ce5e3262e4d52', 'command': 'access_ctuning_server'})

Artifacts

The open-source repositories ship no utils artifacts - this category holds what you and your runs create.

cx utils list

Depends on

Uses categories: category, config

Source: utils on GitHub · its API

Read live from the cMeta index of this server - the same data cx category list shows you locally.