# Store API

One store's endpoints, for local and dev runs.

Served only with `AITODO_STORE_API=1` (tickets, groups, milestones, releases, decisions, docs, gotchas, templates, graph, workspace config, index), they answer what `tkt … --json` prints.

## Details

They take no token, so a request that came in on a network address gets 404 (forwarded headers do not change that), and the container refuses to start with `AITODO_STORE_API=1`.

Example:

```
curl -s http://127.0.0.1:8000/v1/tickets?status=todo
curl -s -X POST http://127.0.0.1:8000/v1/tickets -H 'content-type: application/json' \
  -d '{"title": "First ticket", "groups": ["payments"]}'
```

- **Milestones:** every `tkt milestone` subcommand has a REST counterpart with the same validation, error codes and JSON shape. `GET /v1/milestones/{milestone_id}` includes the hints of `tkt lint milestone://…`; `GET …/plan?from=…` is `tkt milestone plan`, and `--apply` is a POST of the `add` suggestions to `…/tickets`. `DELETE /v1/tickets/{ticket_id}` names the milestones the ticket left in the `X-Removed-From-Milestones` header.
- **Decisions:** the same objects as `tkt decision … --json`. `GET /v1/decisions` filters: `?status=&affects=`. `PATCH /v1/decisions/{decision_id}`: a relationship list replaces that type, `[]` empties it, `"until": null` clears it.
- **Docs and gotchas:** read only. `GET /v1/docs`, `…/{doc_id}` (`?anchor=`) and `…/{doc_id}/refs` answer as `tkt doc … --json`; `/v1/gotchas` as `tkt gotcha … --json`. Writes go through the forwarded CLI (`POST /v1/projects/{project_id}/cli`), which also reports their impact.
- **Picking up work:** `GET /v1/tickets:next` (filters: `milestone`, `group`, `type`, `assignee`) ranks the startable tickets; `POST /v1/tickets:next` `{"assignee": "…"}` claims the top one atomically and returns its bundle; `POST /v1/tickets/{ticket_id}:release` gives it back (someone else's claim: `ERR_ALREADY_CLAIMED`, 409, unless `"force": true`). REST does not read git claims (the server has no git): `/v1/tickets:next` never reports `claimed_elsewhere`; use `tkt next` and `tkt ticket claims` in a worktree.

## Store API endpoints

| endpoint | summary | role |
|---|---|---|
| `POST /v1/groups` | create group |  |
| `GET /v1/groups/{group_id}` | get group |  |
| `GET /v1/groups` | list groups |  |
| `PATCH /v1/groups/{group_id}` | update group |  |
| `DELETE /v1/groups/{group_id}` | delete group |  |
| `POST /v1/tickets` | create ticket |  |
| `GET /v1/tickets/{ticket_id}/raw` | get ticket raw |  |
| `GET /v1/tickets/{ticket_id}` | get ticket bundle |  |
| `POST /v1/tickets:import` | Create a whole plan of tickets, key-referenced dependencies included (#43) |  |
| `GET /v1/tickets:next` | The next startable ticket, the ranked candidates and why the rest are skipped (#100) |  |
| `POST /v1/tickets:next` | Claim the next startable ticket: assignee + `todo → in_progress`, atomically; returns its Context Bundle |  |
| `POST /v1/tickets/{ticket_id}:release` | Give a claimed ticket back (`in_progress → todo`, assignee cleared); someone else's claim needs `force` (ERR\_ALREADY\_CLAIMED, 409) (#100) |  |
| `POST /v1/tickets/{ticket_id}:move` | Move a ticket to another primary group: new id, every reference rewritten (#62) |  |
| `POST /v1/tickets/{ticket_id}:resolve` | Re-resolve refs and re-run the context guard |  |
| `PATCH /v1/tickets/{ticket_id}` | update ticket |  |
| `DELETE /v1/tickets/{ticket_id}` | delete ticket |  |
| `GET /v1/tickets` | list tickets |  |
| `GET /v1/tickets/{ticket_id}/context-references` | get ticket context references |  |
| `POST /v1/context-references:resolve` | resolve context reference |  |
| `POST /v1/index:rebuild` | rebuild index |  |
| `GET /v1/index/status` | index status |  |
| `GET /v1/workspace/config` | Every known config.yaml key with its value and source (file / default) |  |
| `PATCH /v1/workspace/config` | Set keys (`null` unsets one); all or nothing: a bad key or value is 422 and nothing is written |  |
| `GET /v1/templates` | list templates |  |
| `GET /v1/templates/{ticket_type}` | get template |  |
| `GET /v1/tickets/{ticket_id}/graph` | Hierarchy + dependencies around a ticket (an epic brings its children) |  |
| `GET /v1/groups/{group_id}/graph` | Every ticket of a group, clustered by epic |  |
| `GET /v1/graph` | The whole workspace, clustered by group (no depth: everything is already in); with `ref`, the links around one store item that is not a ticket, `depth` hops out |  |
| `POST /v1/milestones` | create milestone |  |
| `GET /v1/milestones` | list milestones |  |
| `GET /v1/milestones/{milestone_id}` | get milestone |  |
| `PATCH /v1/milestones/{milestone_id}` | patch milestone |  |
| `DELETE /v1/milestones/{milestone_id}` | delete milestone |  |
| `POST /v1/milestones/{milestone_id}/tickets` | All-or-nothing; an existing member is reported in `unchanged`, not an error |  |
| `DELETE /v1/milestones/{milestone_id}/tickets` | A ticket that is no member is reported in `unchanged`; an id naming nothing fails the call |  |
| `GET /v1/milestones/{milestone_id}/plan` | Open blockers outside the set with their chains and suggestions |  |
| `GET /v1/milestones/{milestone_id}/board` | board |  |
| `GET /v1/milestones/{milestone_id}/exit-criteria` | list milestone exit criteria |  |
| `POST /v1/milestones/{milestone_id}/exit-criteria` | add milestone exit criterion |  |
| `PATCH /v1/milestones/{milestone_id}/exit-criteria` | Check (`done: true`) or uncheck the `selectors`, or every item with `all: true` |  |
| `PATCH /v1/milestones/{milestone_id}/exit-criteria/{selector}` | `text` rewrites the item (`ac edit`), `done` ticks or unticks it (`ac check\|uncheck`) |  |
| `DELETE /v1/milestones/{milestone_id}/exit-criteria/{selector}` | remove milestone exit criterion |  |
| `PUT /v1/milestones/{milestone_id}/sections/{name}` | Replace the section's content (`tkt <kind> section set`) |  |
| `POST /v1/milestones/{milestone_id}/sections/{name}` | Append after the section's last line (`tkt <kind> section append`) |  |
| `POST /v1/decisions` | create decision |  |
| `GET /v1/decisions` | list decisions |  |
| `GET /v1/decisions/{decision_id}` | get decision |  |
| `PATCH /v1/decisions/{decision_id}` | patch decision |  |
| `GET /v1/decisions/{decision_id}/refs` | Who cites the decision, and how: `tkt decision refs` |  |
| `POST /v1/releases` | create release |  |
| `GET /v1/releases` | list releases |  |
| `GET /v1/releases/{release_id}` | The view plus its context guard hints (#290), as `tkt release get --json` |  |
| `PATCH /v1/releases/{release_id}` | patch release |  |
| `DELETE /v1/releases/{release_id}` | delete release |  |
| `POST /v1/releases/{release_id}/members` | All-or-nothing; an existing member is reported in `unchanged`, not an error |  |
| `DELETE /v1/releases/{release_id}/members` | A member that is not in the release is reported in `unchanged`; one naming nothing fails the call |  |
| `POST /v1/releases/{release_id}/ship` | `tkt release ship`: never asks, so an older version needs `allowOlder` |  |
| `POST /v1/releases:adopt` | Adopt an untracked version as a shipped release |  |
| `POST /v1/releases/{release_id}/notes` | `tkt release notes`: the factual changelog only (the LLM summary is the CLI's, with its provider options); a release not shipped yet is a preview unless `write`; notes it already has are replaced only with `yes` (409 ERR\_RELEASE\_NOTES\_EXIST) |  |
| `GET /v1/releases/{release_id}/exit-criteria` | list release exit criteria |  |
| `POST /v1/releases/{release_id}/exit-criteria` | add release exit criterion |  |
| `PATCH /v1/releases/{release_id}/exit-criteria` | Check (`done: true`) or uncheck the `selectors`, or every item with `all: true` |  |
| `PATCH /v1/releases/{release_id}/exit-criteria/{selector}` | `text` rewrites the item (`ac edit`), `done` ticks or unticks it (`ac check\|uncheck`) |  |
| `DELETE /v1/releases/{release_id}/exit-criteria/{selector}` | remove release exit criterion |  |
| `PUT /v1/releases/{release_id}/sections/{name}` | Replace the section's content (`tkt <kind> section set`) |  |
| `POST /v1/releases/{release_id}/sections/{name}` | Append after the section's last line (`tkt <kind> section append`) |  |
| `POST /v1/releases/{release_id}/note` | A dated `- YYYY-MM-DD: text` entry under `## Notes` (`tkt <kind> note`) |  |
| `GET /v1/search` | The whole store's items for `q`, best first, each with its key, score and why |  |
| `GET /v1/reviews/{ref:path}` | The open reviews of `ref` (it builds on a changed item), the ones it opened (as a source), and everything that builds on it along the chain with its path (`reached`, #400) |  |
| `GET /v1/docs` | list docs |  |
| `GET /v1/docs/{doc_id}` | `tkt doc get --json`: hints, completeness, line 1, `referencedBy`; or the part `anchor` names |  |
| `GET /v1/docs/{doc_id}/refs` | Who references the doc, and how: `tkt doc refs` |  |
| `GET /v1/gotchas` | list gotchas |  |
| `GET /v1/gotchas/{gotcha_id}` | `tkt gotcha get --json`: hints, completeness, line 1, `referencedBy`; or the part `anchor` names |  |
| `GET /v1/gotchas/{gotcha_id}/refs` | Who references or inherits the gotcha, and how: `tkt gotcha refs` |  |
