# Propose install, build, lint and test commands from the repository's files.

> Reads the repository at its default branch from Koidog's mirror (never runs anything) and proposes check commands from `package.json` (bun, pnpm, yarn or npm, chosen by the lockfile), `Cargo.toml`, `go.mod`, `pyproject.toml` and `requirements*.txt`, a `Makefile`, Swift packages and Xcode projects, and Gradle.
> https://koi.dog/docs/api/projects/detect-project-commands/

`POST /api/v1/projects/{id}/detect-commands` · Scope: `config`

The proposals are stored and answered as `suggestions`; Koidog also reads them once when a project is created. Nothing changes the project's `validation` unless `apply` is true (then only `fields`, default every field proposed; its preview and named commands are kept), or you write the commands yourself with `PATCH /projects/{id}`. An empty repository proposes nothing (`state: empty`). The timeline records the key ID, action and outcome.

## Path parameters.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | yes | The project's id. |

## Headers.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | `string` | no | Retry the same request with the same key. [Retry rules](https://koi.dog/docs/api/#retries). |

## Body.

An omitted body is read as `{}`.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `apply` | `boolean` | no | False (the default): read the repository and store the proposals, changing nothing else. True: also write them into the project's `validation` (only the fields in `fields`, default every field proposed), keeping its preview and named commands. Default `false`. |
| `fields` | `array` | no | With `apply`: which of `install`, `build`, `lint` and `test` to write. Default: every field that was proposed. Any of `install`, `build`, `lint`, `test`. At least 1 item. |

## Response.

200 OK · JSON object

- **422 validation_failed**: Each schema error appears in `details`.

## Request.

```sh
curl -X POST "https://api.koi.dog/api/v1/projects/$ID/detect-commands" \
    -H "Authorization: Bearer $KOIDOG_API_KEY" \
    -H "Idempotency-Key: $(uuidgen)"
```

```js
const res = await fetch(`https://api.koi.dog/api/v1/projects/${process.env.ID}/detect-commands`, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.KOIDOG_API_KEY}`,
    "Idempotency-Key": crypto.randomUUID(),
  },
});
console.log(await res.json());
```

```python
import os
import uuid

import requests

r = requests.post(
    f"https://api.koi.dog/api/v1/projects/{os.environ['ID']}/detect-commands",
    headers={
        "Authorization": f"Bearer {os.environ['KOIDOG_API_KEY']}",
        "Idempotency-Key": str(uuid.uuid4()),
    },
)
r.raise_for_status()
print(r.json())
```

## Response example.

```json
{
  "suggestions": {
    "projectId": "string",
    "state": "proposed",
    "reason": "string",
    "branch": "string",
    "sha": "string",
    "detectedAt": "string",
    …
  },
  "project": {
    "id": "string",
    "name": "string",
    "repo": "string",
    "defaultBranch": "string",
    "instructions": "string",
    "validation": { … },
    …
  },
  "applied": []
}
```
