# CADCraft control protocol Start the desktop app with `--control PORT` (or `CADCRAFT_CONTROL_PORT=PORT`). It listens on `127.0.0.1:PORT` for JSON lines: one request per line, one reply per line. A port given with `--control` wins over the variable; a bare `--control` keeps the variable's port. ```json {"id": 1, "method": "cmdline.input", "params": {"text": "circle 0,0 5"}} {"id": 1, "ok": true, "result": {"prompt": "Command:", "output": ["Command: CIRCLE"], ...}} ``` Errors come back as `{"id": …, "ok": false, "error": "message"}`. An unknown method's error points to `control.methods`, which lists the methods the server answers. A line that is not a JSON object with a string `method` (an HTTP request, text that isn't JSON, bytes that aren't UTF-8) gets one error reply and the server closes the connection; nothing sent after it runs. Blank lines are skipped. The server bounds what a client can hold: 16 connections at once (more get an error line and are closed), 256 MiB per request line (longer closes the connection), 64 queued requests (more are answered `{"ok": false, "error": "busy: …", "state": "not-run"}`), and 10 minutes idle or 30 seconds per blocked reply write before the socket is closed. The server waits up to 60 s for the app to answer a request. After that it replies with a timeout, and `state` tells whether sending the request again is safe: - `{"id": …, "ok": false, "error": "timeout", "state": "not-run"}`: the app had not started the request. It is cancelled and will never run, so sending it again is safe. - `{"id": …, "ok": false, "error": "timeout", "state": "may-have-run"}`: the app had already started it. It may still finish and change the drawing, and its late result is discarded. Inspect the drawing (`drawing.inspect`) before sending it again. The table below describes top-level control-protocol methods: names for the request's `method` field. `engine.commands` returns a separate command catalog, not a list of additional methods. | Method | Params | What it does | |---|---|---| | `cmdline.input` | `{text}` | Type a line at the command line exactly like a user. Starts commands by name/alias and answers prompts (points `x,y`, `@dx,dy`, `@d