Skip to content

Context — API reference

DEFAULT_BRANCHES module-attribute

DEFAULT_BRANCHES = {'main', 'master'}

canonical_project

canonical_project(project: str | None) -> str | None

Resolve a project slug to its canonical form via the alias map.

PARAMETER DESCRIPTION
project

A project slug, or None.

TYPE: str | None

RETURNS DESCRIPTION
str | None

The canonical slug when project is a known alias, otherwise

str | None

project unchanged. None passes through.

get_branch

get_branch() -> str | None

Return the current git branch name, or None.

RETURNS DESCRIPTION
str | None

The branch name, or None when not in a git repo, on a detached

str | None

HEAD, or on a default branch (main/master) — work on default

str | None

branches is treated as project-scoped rather than branch-scoped.

get_context

get_context() -> dict

Return the current project and branch context.

RETURNS DESCRIPTION
dict

A dict with keys "project" and "branch", each mapping to a

dict

string or None.

get_project

get_project() -> str | None

Return the current project identifier (basename of git root or cwd).

The raw slug is resolved through the project-alias map (see :func:canonical_project) so a renamed working directory maps back to its canonical project.

RETURNS DESCRIPTION
str | None

The canonical project identifier, or None only if cwd resolution

str | None

fails (extremely unlikely).

load_project_aliases

load_project_aliases() -> dict[str, str]

Load the project-alias map from the mait-code data directory.

The map lives at project-aliases.json in the data directory and maps an old or alternate project slug to its canonical form, e.g. {"h-cc-bridge": "hermes-cc-bridge"}. A missing or malformed file yields an empty map. The result is cached per data directory for the process lifetime.

RETURNS DESCRIPTION
dict[str, str]

A mapping of alias slug to canonical slug (possibly empty).

munge_path

munge_path(path: str) -> str

Apply Claude Code's path-to-slug sanitiser: every non-alphanumeric → -.

Mirrors Claude Code's own cwd.replace(/[^a-zA-Z0-9]/g, "-"). An absolute path's leading / therefore becomes the leading - of the slug. Used both to find a project's native-memory dir (forward) and to reverse a slug back to a path (see :func:mait_code.tools.memory.native.resolve_slug).

The 200-char truncation-plus-hash that Claude Code applies to very long paths is not reproduced here — such projects are unresolvable and fall back to their raw slug.

PARAMETER DESCRIPTION
path

An absolute filesystem path (or a single path component).

TYPE: str

RETURNS DESCRIPTION
str

The munged slug.