Skip to content

Commit 935fb66

Browse files
committed
docs(cli): add first-run onboarding for missing api_url
Any command resolving an unconfigured API URL now triggers an inline TTY prompt that persists to config.json; non-TTY contexts return a structured JSON error with code config.missing.api_url so CI / AI agents fail cleanly.
1 parent bbbc142 commit 935fb66

1 file changed

Lines changed: 37 additions & 2 deletions

File tree

docs/superpowers/specs/2026-05-14-mx-core-cli-design.md

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,40 @@ Applicable to every command unless noted.
102102

103103
Environment variables: `MXS_API_URL`, `MXS_TOKEN`, `MXS_DEBUG=1`.
104104

105-
Resolution precedence: flag > env > `~/.config/mxs/` > prompt / error.
105+
Resolution precedence: flag > env > `~/.config/mxs/` > onboarding prompt / error.
106+
107+
### 4.1.1 Onboarding (first-run / missing api_url)
108+
109+
When any command resolves the API URL and finds none from flag, env, or `~/.config/mxs/config.json`, the CLI enters an inline onboarding prompt:
110+
111+
```
112+
$ mxs post list
113+
👋 mx-space CLI — first run
114+
115+
? API URL of your mx-core server: https://blog.example.com
116+
🔍 probing… API v2 (prefix /api/v2)
117+
✅ saved to ~/.config/mxs/config.json
118+
119+
You are not logged in yet. Run `mxs auth login` to authenticate.
120+
```
121+
122+
Rules:
123+
124+
- The prompt only runs when stdin is a TTY. In non-TTY contexts (CI, piped input, `--json` mode in scripts), the CLI exits with code 5 and the JSON error:
125+
126+
```json
127+
{
128+
"ok": false,
129+
"code": "config.missing.api_url",
130+
"message": "API URL is not configured",
131+
"hint": "set MXS_API_URL or pass --api-url <url>, or run `mxs auth login` in an interactive shell"
132+
}
133+
```
134+
135+
- The URL is normalised: trailing slash stripped, scheme required (`https://` assumed if absent and host is not `localhost`).
136+
- After capture, the CLI immediately runs the prefix-detection probe (§8.3) and persists `api_url` / `api_base` / `auth_base` / `api_version` to `config.json`.
137+
- If the user then needs auth, they are reminded to run `mxs auth login`; the original command is **not** auto-continued (we don't surprise the user by running their command against an unauthenticated server in onboarding).
138+
- `mxs auth login` itself follows the same onboarding when missing api_url — it asks once, persists, then proceeds with the device flow.
106139

107140
### 4.2 Auth
108141

@@ -505,7 +538,7 @@ The route resolves to:
505538

506539
```
507540
$ mxs auth login
508-
? API URL: https://blog.example.com
541+
? API URL: https://blog.example.com # only asked if not yet configured (§4.1.1)
509542
🔍 probing server… API v2 (prefix /api/v2)
510543
🔐 requesting device code…
511544
📱 visit: https://blog.example.com/api/v2/device?user_code=ABCD-EFGH
@@ -515,6 +548,8 @@ $ mxs auth login
515548
🗝 token saved to ~/.config/mxs/credentials.json
516549
```
517550

551+
When `MXS_API_URL` is set or `config.json` already has `api_url`, the URL prompt is skipped.
552+
518553
CLI uses `better-auth/client` + `deviceAuthorizationClient()`:
519554

520555
```ts

0 commit comments

Comments
 (0)