Files
wekan/docs/Features/Rules/Bots.md
T
Lauri Ojansivu b7589737f5 File docs/Features the way the WeKan menus are.
A feature's guide now sits under the menu it is used from, read from the
templates rather than from where somebody once put it: Header-Bar,
All-Boards, Pages, Board-Header (search and every Board View), Board-Sidebar
(Board Settings, Filter, Members, Labels, Archive), Rules, Swimlanes, Lists,
Cards, Member-Settings, Admin-Panel and Login-Page. Topics used from several
menus (editor, history, theme, translations, email, troubleshooting) are in
General.

- Each area has a README mapping its menu entries to their guides and to the
  template or server module that implements them. Board-Header/README.md
  lists all 40 Board View entries with the template boardBody.jade renders;
  five views (Table, Calendar Mode, Time, Timeline, Map) have no guide of
  their own yet and say so.
- Board-View.md listed 25 views while BOARD_VIEWS has 40; it now lists all
  of them with their English labels.
- Pages keep their file names. Where a released changelog links an old path,
  a "# Moved" page stays there and points to the new one; test-menu.sh skips
  folders holding only those.
- Undo was filed under Login; it is General/Undo now.
- Every link in docs, code comments, scripts and tests follows the move;
  docsLinksResolve checks them all.

Tests that read a doc follow it to its new place. boardViewSettings now fails
when Board-View.md or Board-Header/README.md differs from BOARD_VIEWS, or
names a template boardBody.jade does not render.

Thanks to xet7 !
2026-10-16 23:45:35 +03:00

92 lines
5.3 KiB
Markdown

# Bots
Board Settings → **Bots**, below **Workflow view**, is the [Rules](Rules/Rules.md)
page's view for **bots**: runners on your own server that this board hands
cards to. A runner can be an AI coding agent, a CI job or a script. The view
looks and works like kanbots, in the board's own theme, Font Awesome icons and
drag and drop. Like the rest of the Rules page it is for **board admins only**.
It is not a board view: it is not in the Board View menu and can never be a
public view.
```
┌ Bots ───────────┬ Dev / Bots 2 running · 1 waiting for you ─┬ Fix login ─────┐
│ ⚙ Coder host │ TODO 3 │ IN PROGRESS 2 │ REVIEW 1 │ DONE │ [Coder ▾][▶ Hand]│
│ [+ Add bot] │ ┌─────────┐ │ ┌──────────────────┐ │ │ │ ■ Stop │
│ ⚡ Live runs │ │bug #12 │ │ │feat #7 RUNNING │ │ │ │ RUNNING · $0.12 │
│ RUNNING Fix… │ │Fix login│ │ │Add export │ │ │ │ 💬 alice: please…│
│ ⟲ Activity │ └─────────┘ │ │>_ Bash: npm test │ │ │ │ ⚙ Edit: login.js │
│ Coder: Edit… │ │ │? Which file? │ │ │ │ [Reply…] [Send] │
│ │ │ │[a.js] [b.js] │ │ │ │ │
└─────────────────┴─────────────┴──────────────────────┴──────────┴───────┴──────────────────┘
```
- **The rail**: this board's bots (add one with a name, the runner's address
and an optional signing token), the **live runs** with what each is doing,
and the bots' recent **activity**.
- **The columns** are the board's lists. Each card shows its first label, its
number, its bot run's state (*Queued*, *Running*, *Waiting for you*, *Ready
to review*, *Done*, *Failed*, *Stopped*), the step it is on, and when the bot
asked a question, the answers to click. Drag a card to another column to
move it, as on the board.
- **The drawer** shows a card's thread: its comments and its run's events, in
order. **Hand to bot** gives the card to a bot, **Stop** stops the run, and
the reply box answers the bot.
## A bot has no rights of its own
Bots are like Rules and workflows: they act only through what WeKan already
allows, and override no WeKan permission.
- **WeKan only sends to a bot.** A bot is an outgoing webhook marked as a bot.
Handing it a card queues one dispatch through the ordinary webhook queue:
the SSRF guard, the bot's signing token as `X-Wekan-Token`, retries, and on
Sandstorm the Powerbox. A bot is subscribed to no board activity, due
reminders included, so nothing else from the board is sent to it.
- **The runner works through the REST API.** It changes the board with its
own WeKan user's API token, so it has that user's board role and nothing
more: comments, moves, labels and archiving are WeKan REST calls that WeKan
allows or refuses as for anyone.
- **Who hands over.** A board admin, in this view, or a Rule a board admin made
with the action **Hand the card to bot**. For example, "when a card is moved
to *In progress*, hand it to *Coder*" is kanbots' drag-to-start.
- **Answers and replies** are the admin's own card comments, written under
their right to comment in that list, and the bot is told.
## The runner's side
The dispatch is a JSON `POST` to the runner's address:
```json
{ "event": "bot.dispatch", "runId": "…", "bot": { "id": "…", "title": "Coder" },
"board": { "id": "…", "title": "Dev", "key": "DEV" },
"card": { "id": "…", "number": 7, "title": "…", "description": "…",
"list": { "id": "…", "title": "In progress" }, "labels": ["bug"], "url": "…" },
"comments": [{ "id": "…", "text": "…", "at": "…" }],
"report": "https://<wekan>/api/boards/<board>/cards/<card>/bot-runs/<run>",
"api": "https://<wekan>/api" }
```
The runner reports at `report` with its own API token
(`Authorization: Bearer <token>`); WeKan requires write access to the board:
```json
{ "status": "running", "tool": "Bash", "text": "npm test" }
{ "status": "awaiting_input", "question": "Which file?", "options": ["a.js", "b.js"] }
{ "status": "review", "text": "Ready: see the comment", "tokens": 1200, "costUsd": 0.12 }
```
`status` is one of `queued`, `running`, `awaiting_input`, `review`, `done`,
`failed` and `stopped`. A finished run (`done`, `failed`, `stopped`) stays
finished, the last 50 events are kept, and texts are bounded. Later the runner
receives `bot.answer` (`value`, `text`), `bot.reply` (`text`) and `bot.stop`.
## Files
| File | |
| --- | --- |
| `client/components/rules/rulesBots.jade`, `.js`, `.css` | The view |
| `server/bots.js` | Handing over, answers, replies, stopping, the run report route |
| `models/lib/botRuns.js` | A run's states and what may change them. No Meteor code |
| `models/botRuns.js` | The runs, written by the server only, published to board admins |
| `tests/botRuns.test.cjs`, `server/lib/tests/bots.tests.js` | The tests |