Skip to content

Board — API reference

Columns

ALL_STATUSES module-attribute

ALL_STATUSES: tuple[str, ...] = (*BOARD_ORDER, ARCHIVED)

ARCHIVED module-attribute

ARCHIVED = 'archived'

BACKLOG module-attribute

BACKLOG = 'backlog'

BLOCKED_TAG module-attribute

BLOCKED_TAG = 'blocked'

BLOCKS module-attribute

BLOCKS = 'blocks'

BOARD_ORDER module-attribute

BOARD_ORDER: tuple[str, ...] = (
    BACKLOG,
    REFINED,
    IN_PROGRESS,
    IN_REVIEW,
    DONE,
)

CARD module-attribute

CARD = 'card'

DONE module-attribute

DONE = 'done'

EPIC module-attribute

EPIC = 'epic'

EPIC_PROJECT module-attribute

EPIC_PROJECT = '@epic'

IN_PROGRESS module-attribute

IN_PROGRESS = 'in_progress'

IN_REVIEW module-attribute

IN_REVIEW = 'in_review'

KINDS module-attribute

KINDS: tuple[str, ...] = (CARD, EPIC)

LABELS module-attribute

LABELS: dict[str, str] = {
    BACKLOG: "Backlog",
    REFINED: "Refined",
    IN_PROGRESS: "In Progress",
    IN_REVIEW: "In Review",
    DONE: "Done",
    ARCHIVED: "Archived",
}
LINK_TYPES: tuple[str, ...] = (BLOCKS,)

ORIGIN_LABEL module-attribute

ORIGIN_LABEL = 'from'

REFINED module-attribute

REFINED = 'refined'

STEP_DONE module-attribute

STEP_DONE = 'done'

STEP_IN_PROGRESS module-attribute

STEP_IN_PROGRESS = 'in_progress'

STEP_PAUSED module-attribute

STEP_PAUSED = 'paused'

STEP_PENDING module-attribute

STEP_PENDING = 'pending'

STEP_SKIPPED module-attribute

STEP_SKIPPED = 'skipped'

STEP_STATUSES module-attribute

STEP_STATUSES: tuple[str, ...] = (
    STEP_PENDING,
    STEP_IN_PROGRESS,
    STEP_DONE,
    STEP_SKIPPED,
    STEP_PAUSED,
)

is_valid_status

is_valid_status(status: str) -> bool

Return True if status is one of the fixed columns.

label

label(status: str) -> str

Return the display label for a status (falls back to the raw value).

Database

connection

connection(db_path: Path | None = None)

Context manager that opens and closes a board database connection.

ensure_schema

ensure_schema(conn: Connection) -> None

Apply any pending migrations to the database.

Safe to call on every connection open - checks a single integer and returns immediately if the schema is current.

Safe to call from several processes at once, too: right after an upgrade the session-start hook, the CLI and the TUI can all open the board together. The unlocked version read only decides whether to look further; each pending migration then takes the write lock (BEGIN IMMEDIATE), re-checks that no other process applied it meanwhile, and applies it with its version row in one transaction. Without the re-check a non-idempotent body such as ADD COLUMN would run twice and fail with duplicate column.

PARAMETER DESCRIPTION
conn

Open board database connection.

TYPE: Connection

get_connection

get_connection(db_path: Path | None = None) -> Connection

Open a board database connection.

The connection has WAL journal mode enabled (for concurrent reads), foreign-key enforcement enabled (so card_comments cascade-delete on ON DELETE CASCADE), and the current schema applied via migrations.

PARAMETER DESCRIPTION
db_path

Override the database path (defaults to {data_dir}/board.db).

TYPE: Path | None DEFAULT: None

RETURNS DESCRIPTION
Connection

A sqlite3.Connection ready for use. The caller must close it.

get_data_dir

get_data_dir() -> Path

Return the mait-code data directory, creating it if needed.

get_db_path

get_db_path() -> Path

Return the board database path.

get_project

get_project() -> str

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

Delegates to mait_code.context.get_project(), falling back to the current directory name.

Export

FORMATS module-attribute

FORMATS: tuple[str, ...] = (MARKDOWN, JSON)

JSON module-attribute

JSON = 'json'

MARKDOWN module-attribute

MARKDOWN = 'markdown'

board_markdown

board_markdown(
    cards: Iterable[dict], *, project: str | None = None
) -> str

Render a board listing as one markdown document grouped by column.

PARAMETER DESCRIPTION
cards

Card dicts (each optionally carrying comments).

TYPE: Iterable[dict]

project

Project name for the document title, or None for an all-projects export.

TYPE: str | None DEFAULT: None

RETURNS DESCRIPTION
str

The markdown document, without a trailing newline.

card_markdown

card_markdown(card: dict, *, level: int = 1) -> str

Render one card as a markdown document.

PARAMETER DESCRIPTION
card

A card dict as returned by :func:~mait_code.tools.board.service.get_card, optionally carrying a comments list.

TYPE: dict

level

Heading level for the card title; sections render at level + 1. Defaults to a standalone document (# title).

TYPE: int DEFAULT: 1

RETURNS DESCRIPTION
str

The markdown document, without a trailing newline.

epic_markdown

epic_markdown(epic: dict) -> str

Render an epic and its members as one markdown document.

PARAMETER DESCRIPTION
epic

An epic dict as returned by :func:~mait_code.tools.board.service.get_epic - carrying members and progress - optionally with comments on it and its members.

TYPE: dict

RETURNS DESCRIPTION
str

The markdown document, without a trailing newline.

export_board

export_board(
    conn: Connection,
    *,
    fmt: str = MARKDOWN,
    project: str | None = None,
    statuses: Iterable[str] | None = None,
    include_archived: bool = False,
    search: str | None = None,
) -> str

Export a board listing as fmt - a JSON array or one markdown document.

Filter arguments mirror :func:~mait_code.tools.board.service.list_cards. Epics are left out, as on the board; see :func:export_epic.

RAISES DESCRIPTION
ValueError

If fmt is not one of :data:FORMATS.

export_card

export_card(
    conn: Connection, card_id: int, fmt: str = MARKDOWN
) -> str

Export one card, comments included, as fmt.

RAISES DESCRIPTION
CardNotFound

If no card has card_id.

ValueError

If fmt is not one of :data:FORMATS.

export_epic

export_epic(
    conn: Connection, epic_id: int, fmt: str = MARKDOWN
) -> str

Export an epic with its non-archived members, comments included.

The JSON form is the epic in the epic show --json shape, its members each carrying their own comments.

RAISES DESCRIPTION
CardNotFound

If no card has epic_id.

RelationError

If the card isn't an epic.

ValueError

If fmt is not one of :data:FORMATS.

Service

CardClosed

CardClosed(card_id: int, status: str)

Bases: Exception

Raised when binding a session to a card that is done or archived.

CardNotFound

CardNotFound(card_id: int)

Bases: Exception

Raised by mutations when no card has the given id.

EpicOrigin

EpicOrigin(card_id: int)

Bases: RelationError

Raised when a new card names an epic as the card it came from.

ATTRIBUTE DESCRIPTION
card_id

The epic named as the origin.

InheritedEpicClosed

InheritedEpicClosed(
    origin_id: int, epic_id: int, status: str
)

Bases: RelationError

Raised when a new card would inherit an epic that is done or archived.

Only :func:add_card with refuse_closed_epic=True raises it.

ATTRIBUTE DESCRIPTION
origin_id

The card the epic would have been inherited from.

epic_id

The closed epic.

status

The epic's status, done or archived.

LinkCycle

LinkCycle(path: list[int])

Bases: RelationError

Raised when a blocks link would close a loop.

ATTRIBUTE DESCRIPTION
path

The loop as card ids, starting and ending on the link's from card - e.g. [41, 47, 52, 41] for 41 blocks 47 when 47 already reaches 41 through 52.

RelationError

Bases: ValueError

Raised when a kind, parent or link change would break a board invariant.

The invariants: a card is an epic exactly when its project is :data:EPIC_PROJECT; a parent is always an epic and an epic has no parent; epics take no blocks links and bind no sessions; blocks links form no loops. The message says which one, ready to show a user.

add_card

add_card(
    conn: Connection,
    *,
    project: str | None,
    title: str,
    description: str | None = None,
    priority: str = "medium",
    created_by: str | None = None,
    kind: str = CARD,
    parent_id: int | None | _Unchanged = KEEP,
    origin_id: int | None = None,
    refuse_closed_epic: bool = False,
) -> int

Insert a backlog card and return its new id.

created_by names the client that raised the card when it arrives from somewhere other than a local session (see :mod:mait_code.remote); None means it was created locally.

An epic (kind=EPIC) always gets :data:EPIC_PROJECT - pass that or None as project - and no parent. A card needs a real project and may name its epic as parent_id.

origin_id names the card this one was split from or raised as a follow-up of, in any project. The new card joins the origin's epic unless parent_id is given (None for no epic), and gets an :data:ORIGIN_LABEL reference to #<origin_id> in the same transaction, which holds the write lock from the checks on, so a parallel writer can't change the origin or epic in between. Epics neither have an origin nor serve as one (:class:EpicOrigin).

refuse_closed_epic refuses to inherit an epic that is done or archived (:class:InheritedEpicClosed), for a caller that can't warn about one afterwards. An explicit parent_id is never refused for its status.

Raises :class:RelationError when the combination breaks those rules, and :class:CardNotFound for an unknown parent_id or origin_id.

add_comment

add_comment(
    conn: Connection,
    card_id: int,
    body: str,
    *,
    author: str = "me",
) -> None

Append a comment to a card and bump its updated_at.

Raises :class:CardNotFound if the id is unknown.

add_link(
    conn: Connection,
    from_id: int,
    to_id: int,
    link_type: str = BLOCKS,
) -> None

Record that from_id :data:BLOCKS to_id.

The checks and the insert share one write-locked transaction, so a parallel writer can't slip in the edge that closes a loop between them.

RAISES DESCRIPTION
CardNotFound

If either id is unknown.

LinkCycle

If to_id already reaches from_id along blocks links, so the new link would close a loop.

RelationError

For an unknown link_type, a self-link, a link that already exists, or an epic on either end.

add_tag

add_tag(conn: Connection, card_id: int, tag: str) -> None

Add a tag to a card (idempotent).

Raises :class:CardNotFound if the id is unknown.

archive_card

archive_card(conn: Connection, card_id: int) -> None

Archive a card (hide it from default views).

Closes the card (see :func:_on_close). Raises :class:CardNotFound if the id is unknown.

bind_session

bind_session(
    conn: Connection, card_id: int, session: SessionRef
) -> None

Bind a Claude Code session to an open card, in any column.

A binding means the session is working on the card, whichever column it sits in. Idempotent: re-binding the same session refreshes its pid and time. A card may carry several bindings (parallel sessions on one card). Raises :class:CardNotFound if the id is unknown, :class:RelationError for an epic (epics are never worked directly; checked first) and :class:CardClosed for a done or archived card.

block_card

block_card(
    conn: Connection,
    card_id: int,
    *,
    reason: str | None = None,
) -> None

Tag a card blocked in place; record reason as a comment if given.

Blocking no longer moves the card - it keeps its real flow position and gains a :data:BLOCKED_TAG tag. Raises :class:CardNotFound if the id is unknown.

card_sessions

card_sessions(conn: Connection, card_id: int) -> list[dict]

Return a card's active session bindings (empty for an unknown id).

complete_card

complete_card(
    conn: Connection,
    card_id: int,
    *,
    summary: str | None = None,
) -> None

Move a card to done with an optional completion summary.

Closes the card (see :func:_on_close). Raises :class:CardNotFound if the id is unknown.

dependency_graph

dependency_graph(
    conn: Connection, *, epic_id: int | None = None
) -> dict

Return the blocks graph as {"nodes": [...], "edges": [...]}.

Nodes are :func:_summary dicts plus a stub flag; edges are {"from", "to"} dicts. Archived cards are left out. Given epic_id, the nodes are the epic's members plus any card one link away outside it, flagged stub so a view can draw them dimmed; without it, every card on either end of a blocks link.

Raises :class:CardNotFound / :class:RelationError for an epic_id that is unknown or not an epic.

edit_card

edit_card(
    conn: Connection,
    card_id: int,
    *,
    parent_id: int | None | _Unchanged = KEEP,
    **fields: str,
) -> None

Update arbitrary card columns, bumping updated_at.

Pass column names as keyword arguments (e.g. title=.., acceptance_criteria=..). parent_id moves the card into that epic, or out of any with None; leave it out to keep the current one. Every change is checked first and written in one transaction, so a refused field leaves the card exactly as it was - the parent included.

kind isn't editable here - use :func:promote_epic. Raises :class:CardNotFound if the id (or parent_id) is unknown and :class:RelationError for kind, a parent_id that breaks the rules of :func:set_parent, or a project that would move a card to :data:EPIC_PROJECT or an epic off it; a no-op (no fields) is the caller's concern.

epic_members

epic_members(
    conn: Connection,
    epic_id: int,
    *,
    include_archived: bool = False,
) -> list[dict]

Return an epic's member cards, ordered priority-then-oldest.

Raises :class:CardNotFound for an unknown id and :class:RelationError if it isn't an epic.

epic_without_open_members

epic_without_open_members(
    conn: Connection, card_id: int
) -> int | None

Return card_id's epic if it has no open members left, else None.

Open means neither done nor archived. An epic's status is set by hand, so a caller that just finished or dropped a member can remind the user the epic may be ready to close - it never moves the epic itself. An epic that is already done or archived needs no reminder: None.

get_card

get_card(conn: Connection, card_id: int) -> dict | None

Return one card as a dict, or None if no card has that id.

get_comments

get_comments(conn: Connection, card_id: int) -> list[dict]

Return a card's comments in insertion order.

get_epic

get_epic(conn: Connection, epic_id: int) -> dict

Return an epic with its non-archived members and progress.

Raises :class:CardNotFound for an unknown id and :class:RelationError if it isn't an epic.

list_cards

list_cards(
    conn: Connection,
    *,
    project: str | None = None,
    statuses: Iterable[str] | None = None,
    include_archived: bool = False,
    tag: str | None = None,
    search: str | None = None,
    session: str | None = None,
    kind: str | None = CARD,
    parent_id: int | None = None,
    ready: bool = False,
    claimant: str | None = None,
) -> list[dict]

Return cards ordered priority-then-oldest.

PARAMETER DESCRIPTION
conn

Open board connection.

TYPE: Connection

project

Restrict to one project, or None for every project.

TYPE: str | None DEFAULT: None

statuses

Restrict to these statuses; None means "all". When given, it takes precedence over include_archived.

TYPE: Iterable[str] | None DEFAULT: None

include_archived

When no statuses filter is set, whether to include archived cards (default excludes them).

TYPE: bool DEFAULT: False

tag

Restrict to cards carrying this tag, or None for no tag filter.

TYPE: str | None DEFAULT: None

search

Restrict to cards whose title contains this substring, case-insensitively, or None for no title filter.

TYPE: str | None DEFAULT: None

session

Restrict to cards with an active binding to this Claude Code session id, or None for no session filter.

TYPE: str | None DEFAULT: None

kind

Restrict to this kind. Defaults to :data:CARD, so epics stay off every kanban-shaped listing unless asked for; None returns both.

TYPE: str | None DEFAULT: CARD

parent_id

Restrict to the members of this epic, or None for no parent filter.

TYPE: int | None DEFAULT: None

ready

Restrict to cards :func:next_refined could hand out - refined, not tagged blocked, not waiting on a blocker, and not held by a live session other than claimant.

TYPE: bool DEFAULT: False

claimant

With ready, the session id asking; its own bindings don't hold a card back. None treats every live binding as another's.

TYPE: str | None DEFAULT: None

list_epics

list_epics(
    conn: Connection, *, include_done: bool = False
) -> list[dict]

Return epics, priority-then-oldest, each with a progress dict.

progress counts the epic's non-archived members per :data:BOARD_ORDER status, plus total and waiting (open members held up by an unsettled blocker). Done epics are left out unless include_done; archived ones always are.

list_projects

list_projects(conn: Connection) -> list[str]

Return the distinct project names on the board, sorted.

Epics' reserved :data:EPIC_PROJECT isn't a project and is left out.

list_tags

list_tags(conn: Connection, card_id: int) -> list[str]

Return a card's tags, sorted.

move_card

move_card(
    conn: Connection,
    card_id: int,
    new_status: str,
    *,
    session: SessionRef | None = None,
) -> None

Move a card to new_status, maintaining the done- and session-invariants.

Entering done stamps completed_at; leaving it clears the stamp. Entering in_review releases the card's session bindings (the card is handed off), and entering done or archived closes it (see :func:_on_close); moves between the other columns keep them. Moving to in_progress with a session binds it - unless it's an epic, which never binds (its status is bookkeeping, not work). Raises :class:CardNotFound if the id is unknown.

next_refined

next_refined(
    conn: Connection,
    project: str | None,
    *,
    claim: bool = False,
    session: SessionRef | None = None,
    epic_id: int | None = None,
) -> dict | None

Return the top ready card for project (priority, then oldest).

Ready means refined, not tagged blocked, not waiting on any unsettled blocks link (see :func:_attach_links), and not held by a live session other than session - another session may be refining it under a playbook. Given epic_id, the search spans that epic's members in every project and project is ignored.

With claim=True the card is moved to in_progress first (guarded on its status so a concurrent claim can't double-move it) and, given a session, bound to it. The guard re-checks the status only, not readiness. Returns None when nothing is ready.

Raises :class:CardNotFound / :class:RelationError for an epic_id that is unknown or not an epic, and :class:ValueError when neither project nor epic_id is given.

promote_epic

promote_epic(conn: Connection, card_id: int) -> None

Turn an existing card into an epic, keeping its history.

Closes it as a card (see :func:_on_close), moves it to :data:EPIC_PROJECT and records the project it came from as a comment. Raises :class:CardNotFound for an unknown id and :class:RelationError if it is already an epic, has a parent, or has any blocks link - each of which an epic can't carry.

prune_stale_bindings

prune_stale_bindings(
    conn: Connection, *, older_than: timedelta
) -> int

Delete dead bindings last bound or resumed more than older_than ago.

A dead binding is kept so a resume can bring it back (see :func:refresh_session_pid), but on a card that stays open for weeks it would otherwise linger, and a recycled pid could make it read as live again. Age is counted from bound_at, which a bind, a resume and a /clear all renew; nothing records when a process dies, so a session that ran for longer than older_than without either is pruned as soon as it ends. Live bindings are never touched, whatever their age. Returns how many were deleted.

refine_card

refine_card(
    conn: Connection,
    card_id: int,
    *,
    description: str | None = None,
    acceptance: str | None = None,
) -> None

Move a card to refined, optionally setting description/acceptance.

Keeps the card's session bindings: a session may refine the card it is working on. Raises :class:CardNotFound if the id is unknown.

remove_card

remove_card(conn: Connection, card_id: int) -> None

Delete a card permanently (comments cascade).

Raises :class:CardNotFound if the id is unknown.

remove_link(
    conn: Connection,
    from_id: int,
    to_id: int,
    link_type: str = BLOCKS,
) -> bool

Remove a link; return True if there was one to remove.

remove_tag

remove_tag(
    conn: Connection, card_id: int, tag: str
) -> None

Remove a tag from a card (no-op if the tag is absent).

Raises :class:CardNotFound if the id is unknown.

review_card

review_card(
    conn: Connection, card_id: int, *, pr: str | None = None
) -> None

Move a card to in_review, recording pr as a PR reference.

The card is parked between in_progress and done until its pull request merges, and its session bindings are released. Re-reviewing with a PR the card already carries (e.g. after a re-push) doesn't duplicate the reference. Raises :class:CardNotFound if the id is unknown.

set_parent

set_parent(
    conn: Connection, card_id: int, epic_id: int | None
) -> None

Make card_id a member of epic epic_id, or of none with None.

Raises :class:CardNotFound for an unknown id and :class:RelationError when card_id is an epic (one level only) or epic_id isn't one.

summary_counts

summary_counts(
    conn: Connection, *, project: str | None = None
) -> dict[str, int]

Return per-column card counts (excluding archived and epics).

The result always has a key for every :data:BOARD_ORDER status, defaulting to 0. project=None counts across every project.

unbind_session

unbind_session(
    conn: Connection, card_id: int, session_id: str
) -> bool

Remove session_id's binding from a card.

Returns True if a binding was removed, False if there was none. Raises :class:CardNotFound if the id is unknown.

unblock_card

unblock_card(conn: Connection, card_id: int) -> None

Remove the blocked tag from a card (keeps its flow position).

Raises :class:CardNotFound if the id is unknown.

Sessions

SessionRef

Bases: NamedTuple

A Claude Code session: its id and the pid of the process serving it.

current_session

current_session() -> SessionRef | None

Return the session this process runs under, or None outside one.

Both variables must be present and the pid a positive integer; anything less is treated as "not in a Claude Code session" rather than guessed at.

Entry point

main

main()