Board — API reference¶
Columns¶
BOARD_ORDER
module-attribute
¶
BOARD_ORDER: tuple[str, ...] = (
BACKLOG,
REFINED,
IN_PROGRESS,
IN_REVIEW,
DONE,
)
LABELS
module-attribute
¶
LABELS: dict[str, str] = {
BACKLOG: "Backlog",
REFINED: "Refined",
IN_PROGRESS: "In Progress",
IN_REVIEW: "In Review",
DONE: "Done",
ARCHIVED: "Archived",
}
STEP_STATUSES
module-attribute
¶
STEP_STATUSES: tuple[str, ...] = (
STEP_PENDING,
STEP_IN_PROGRESS,
STEP_DONE,
STEP_SKIPPED,
STEP_PAUSED,
)
is_valid_status
¶
Return True if status is one of the fixed columns.
label
¶
Return the display label for a status (falls back to the raw value).
Database¶
connection
¶
Context manager that opens and closes a board database connection.
ensure_schema
¶
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:
|
get_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
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Connection
|
A |
get_project
¶
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¶
board_markdown
¶
Render a board listing as one markdown document grouped by column.
| PARAMETER | DESCRIPTION |
|---|---|
cards
|
Card dicts (each optionally carrying
TYPE:
|
project
|
Project name for the document title, or
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The markdown document, without a trailing newline. |
card_markdown
¶
Render one card as a markdown document.
| PARAMETER | DESCRIPTION |
|---|---|
card
|
A card dict as returned by :func:
TYPE:
|
level
|
Heading level for the card title; sections render at
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The markdown document, without a trailing newline. |
epic_markdown
¶
Render an epic and its members as one markdown document.
| PARAMETER | DESCRIPTION |
|---|---|
epic
|
An epic dict as returned by
:func:
TYPE:
|
| 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: |
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: |
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: |
Service¶
CardClosed
¶
Bases: Exception
Raised when binding a session to a card that is done or archived.
CardNotFound
¶
Bases: Exception
Raised by mutations when no card has the given id.
EpicOrigin
¶
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
¶
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,
|
LinkCycle
¶
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.
|
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
¶
Append a comment to a card and bump its updated_at.
Raises :class:CardNotFound if the id is unknown.
add_link
¶
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 |
RelationError
|
For an unknown link_type, a self-link, a link that already exists, or an epic on either end. |
add_tag
¶
Add a tag to a card (idempotent).
Raises :class:CardNotFound if the id is unknown.
archive_card
¶
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
¶
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
¶
Return a card's active session bindings (empty for an unknown id).
complete_card
¶
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
¶
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
¶
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
¶
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
¶
Return one card as a dict, or None if no card has that id.
get_comments
¶
Return a card's comments in insertion order.
get_epic
¶
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:
|
project
|
Restrict to one project, or
TYPE:
|
statuses
|
Restrict to these statuses;
TYPE:
|
include_archived
|
When no statuses filter is set, whether to include archived cards (default excludes them).
TYPE:
|
tag
|
Restrict to cards carrying this tag, or
TYPE:
|
search
|
Restrict to cards whose title contains this substring,
case-insensitively, or
TYPE:
|
session
|
Restrict to cards with an active binding to this Claude
Code session id, or
TYPE:
|
kind
|
Restrict to this
TYPE:
|
parent_id
|
Restrict to the members of this epic, or
TYPE:
|
ready
|
Restrict to cards :func:
TYPE:
|
claimant
|
With ready, the session id asking; its own bindings don't
hold a card back.
TYPE:
|
list_epics
¶
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
¶
Return the distinct project names on the board, sorted.
Epics' reserved :data:EPIC_PROJECT isn't a project and is left out.
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
¶
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
¶
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
¶
Delete a card permanently (comments cascade).
Raises :class:CardNotFound if the id is unknown.
remove_link
¶
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 a tag from a card (no-op if the tag is absent).
Raises :class:CardNotFound if the id is unknown.
review_card
¶
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
¶
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
¶
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
¶
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
¶
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.