> ## Documentation Index
> Fetch the complete documentation index at: https://psychiatrist.sudo.la/llms.txt
> Use this file to discover all available pages before exploring further.

# Embedding the bot

> Run the bot for a checkout in your own process with Practice: its state, typed events, commands and errors.

`Practice` runs the bot for one GitHub checkout. Construct it with the checkout's project settings, the person's GitHub login, and an agent limiter created with `limit(n)`. Pass a harness or tracker to supply those operations yourself. The terminal UI creates one practice and runs it in-process.

Call `practice.run(signal)` to scan for and work on tickets until the signal is aborted or the practice closes. Read its current state from `practice.state`. Subscribe with `practice.on(event, listener)` to receive typed `job`, `agent`, `hitl`, and `activity` updates. A `reset` event provides the fresh state after a reset. Remove a subscription with `practice.off(event, listener)`.

Use `approve`, `reject`, `answer`, `deleteHitl`, and `moveIssue` with numeric HITL IDs. The other commands are `chat`, `guide`, `create`, `createDone`, `squash`, `claim`, `skip`, `pause`, `resume`, `reset`, and `activeWorktrees`. Catch command failures by their exported error classes, such as `ItemNotFoundError`, `CommandConflictError` or `TrackerCommandError`.

When running multiple practices in a process, pass the same limiter and `SqliteDatabase` to each. `database.usage()` gives token totals by repository. `database.history({ repo, before, limit })` pages through activity across repositories or for one repository. Migrated activity keeps its order within each repository and has a null timestamp when the old log recorded only the time of day. Call `practice.close()` before closing a database you supplied. `close()` rejects with `PersistenceError`, naming the HITL items, when a result of a post, a move or filed tickets still could not be saved: after a restart those items show as approved. The message says which ones GitHub already has (don't approve them again) and which it refused (delete them to try again).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.