# A store on the server

A project's store can live on the server instead of the repo; the repo then holds only `.aitodo.yaml` (`store: server`, `server`, `project`).

```console
$ tkt store init --server https://tkt.ideathon.me --register --name Payments
```

- Every non-`local` command goes unchanged to `POST /v1/projects/{p}/cli`: the same output and exit codes; your token (read; write for writes) goes with every call.
- Stage 2 stays local: your `tkt` resolves the `location: repo` refs from your worktree; the server never sees it.
- A local command on `/cli`: 403 `ERR_COMMAND_NOT_ALLOWED`; in a `store: server` repo it needs `--workspace-dir` (else `ERR_STORE_LOCATION`). A store copy beside the pointer stops all forwarding (`ERR_STORE_LOCATION`, "stale local copy"): remove it.

## Details

- **Creating:** `tkt store init --server <url> --project <id>` (admin): an empty git-backed store in `$AITODO_SERVER_DATA/stores/<id>/` (`sharedCounter: false`) plus `./.aitodo.yaml`. `--register --name N --as NAME` registers first (invite: `AITODO_INVITE` or a hidden prompt) and saves the admin token (`--json`: `registered: {name, tokenName, credentials}`; a failed store prints the id and the retry command); `--operator`: no invite. `--project` and `--register` exclude each other (exit 2). A local store (pinned or one level below: a move, [Moving a store](/en/docs/guides/maintenance/store-move.md#maint-store-move)) or an existing server store: `ERR_STORE_LOCATION`.
- **The pointer** takes no `workspaceDir` (else `ERR_FILE_PARSE`); `--workspace-dir` / `AITODO_WORKSPACE_DIR` override it. `tkt where` names server and project.
- **Forwarding:** `{argv, stdin?, files?: {name: base64}, columns?}` in, `{exit_code, stdout, stderr, files, store_version, stage1?}` out; `next --claim`, `reorg --interactive` are writes. An HTTP error prints `Error [ERR_…]`, exit 1. `columns`: terminal width (default 100). `tkt ticket get`, `tkt next --claim --json`, `tkt report context` return Stage-1 JSON (`AITODO_STAGE1_OUT`), resolved via `--worktree-dir`, `AITODO_WORKTREE_DIR` or the cwd; `--raw`, `--brief`, `--summary` render on the server; `tkt reorg`, `reorg apply` run there without Stage 2.
- **Files:** `--file`, `--new-file`, `tkt ticket import FILE`, `tkt reorg apply PLAN` upload (`-`: stdin; outside the cwd: renamed `_in/…`); `--out`, `tkt reorg --plan FILE` come back. 1 MB per file, 4 MB per call, checked before decoding; the request body at most 15424 KB (follows `AITODO_CLI_CALL_MAX_BYTES`), read only after the token check (else 401/403), measured as it arrives (413 `ERR_PAYLOAD_TOO_LARGE`).
- **Refused** in a forwarded argv (400 `ERR_BAD_REQUEST`): `--workspace-dir`, `--workspace`, `--worktree-dir`, `--llm`, `--llm-cmd`, `--llm-provider` (`--no-llm` is fine); a path outside the call's dir (absolute, `..`, `~`) in any spelling of its option (`-oPATH`, `--out=PATH`, short clusters), also in `report context --compare`; an argv the server would read otherwise than `tkt`.
- **Isolation:** an id (doc, gotcha, group, ticket, milestone, decision) is one name in the project's own store: one with `/`, `\` or `..` is `ERR_ID_INVALID`. A store file that leads out (a symlink) is left out of lists; reading or writing it is `ERR_PATH_OUTSIDE_STORE`, locally too.
- **On the server** `tkt` runs in a temp dir, allowlisted env (no secret or token), `AITODO_SERVER_RUN=1`, `AITODO_SERVER_ACTOR=<token name>`. A successful changing write is one commit (author `<token name> via <project>`, message `tkt <argv>` without `--body`, `--file` and other free text); anything else is rolled back; `store_version` is HEAD. With a stale copy `tkt doctor` prints only `STALE_LOCAL_STORE` (exit 2).
- **Confinement** (Linux, Landlock): a run (also a `store:import`'s `tkt doctor`) writes only its store and temp dir and reads only those, Python and system files; never another store or `server.db`; from ABI 4 TCP only connects to the server's port, no bind; up to ABI 3 the network stays open. On Linux without Landlock no run starts (503 `ERR_CONFINEMENT_UNAVAILABLE`); `AITODO_CLI_CONFINE=off` switches it off; macOS: none. The startup log names it.
- **Limits** (`AITODO_CLI_*`, `AITODO_STORE_MAX_BYTES`, checked at startup): 30 s per call (504 `ERR_TIMEOUT`); one call per project, 10 s wait (409 `ERR_STORE_BUSY`: retry); 4 runs at once; 120 calls per minute per token (429 `ERR_RATE_LIMITED`); 100 MB of disk per project, git history and archives included (413 `ERR_PAYLOAD_TOO_LARGE`, rolled back; `tkt doctor` shows the parts, `STORE_QUOTA_NEAR` from 80 %); a server low on disk: 507 `ERR_SERVER_DISK_FULL`, writes paused, the operator is notified; 1 MB output per stream (the rest dropped, the cut noted); 64 MB Stage-1 result per call (`AITODO_CLI_STAGE1_MAX_BYTES`; over it 413 `ERR_PAYLOAD_TOO_LARGE`: narrow with `--budget` or `--group`); 2048 MB memory per run (`AITODO_CLI_MEMORY_MAX_BYTES`, Linux only, set by the run itself; over it 507 `ERR_RUN_MEMORY_LIMIT`, rolled back).
- REST: `POST /v1/projects/{p}/store` (admin, 201; again 409 `ERR_STORE_LOCATION`), `GET /v1/projects/{p}/store` `{location: repo|server|moving, storeVersion, movedAt}`; store elsewhere: 409 `ERR_STORE_LOCATION`, moving: 409 `ERR_STORE_MOVING`.

## Commands on this page

- [`tkt store init`](/en/docs/reference/commands/maintenance.md#tkt-store-init): Create the project's store on the server and point this directory at it (`.aitodo.yaml`: store: server)

## Related

- Guide: [Moving a store](/en/docs/guides/maintenance/store-move.md): A store lives in one place at a time, the repo or the server; the server's record is the truth (GET /v1/projects/{p}/store: location: repo\|server\|moving,…
- Error code · 403: [`ERR_COMMAND_NOT_ALLOWED`](/en/docs/reference/errors.md#ERR_COMMAND_NOT_ALLOWED): A local command sent to a server store's /cli
- Error code · 409: [`ERR_STORE_BUSY`](/en/docs/reference/errors.md#ERR_STORE_BUSY): The project's store stayed locked past the wait
- Error code · 429: [`ERR_RATE_LIMITED`](/en/docs/reference/errors.md#ERR_RATE_LIMITED): More calls than the server allows in its window: forwarded calls, reports, registrations
- Error code · 504: [`ERR_TIMEOUT`](/en/docs/reference/errors.md#ERR_TIMEOUT): A forwarded call ran longer than the server allows
- Error code · 400: [`ERR_BAD_REQUEST`](/en/docs/reference/errors.md#ERR_BAD_REQUEST): A forwarded call with an option the server sets itself, or a file path outside the call's temp dir
- Error code · 422: [`ERR_PATH_OUTSIDE_STORE`](/en/docs/reference/errors.md#ERR_PATH_OUTSIDE_STORE): A store path leads outside the store (.., an absolute path, a symlink out); nothing read or written
- Env var: [`AITODO_SERVER_DATA`](/en/docs/reference/env.md#AITODO_SERVER_DATA): The server's data directory: server.db and the server stores
- Env var: [`AITODO_CLI_TIMEOUT`](/en/docs/reference/env.md#AITODO_CLI_TIMEOUT): Seconds one forwarded tkt call may run on a server store
- Env var: [`AITODO_CLI_LOCK_WAIT`](/en/docs/reference/env.md#AITODO_CLI_LOCK_WAIT): Seconds a write waits for the store lock
- Env var: [`AITODO_CLI_MAX_PROCS`](/en/docs/reference/env.md#AITODO_CLI_MAX_PROCS): Forwarded calls running at once
- Env var: [`AITODO_CLI_RATE_LIMIT`](/en/docs/reference/env.md#AITODO_CLI_RATE_LIMIT): Forwarded calls per minute per token
