Context — API reference¶
canonical_project
¶
Resolve a project slug to its canonical form via the alias map.
| PARAMETER | DESCRIPTION |
|---|---|
project
|
A project slug, or
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
The canonical slug when |
str | None
|
|
get_branch
¶
Return the current git branch name, or None.
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
The branch name, or |
str | None
|
HEAD, or on a default branch ( |
str | None
|
branches is treated as project-scoped rather than branch-scoped. |
get_context
¶
Return the current project and branch context.
| RETURNS | DESCRIPTION |
|---|---|
dict
|
A dict with keys |
dict
|
string or |
get_project
¶
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 |
str | None
|
fails (extremely unlikely). |
load_project_aliases
¶
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
¶
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:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The munged slug. |