Files
amitcoralogix 1447406c7c AIAP-1095 | cx init command (#204)
## Summary

Adds `cx init` — the single guided entry point for onboarding
(FORGE-658) — plus first-run guidance pointing unconfigured machines at
it (FORGE-659).

```
cx init                                                    # interactive walkthrough
cx init --url https://myteam.app.eu2.coralogix.com --api-key $CX_API_KEY --global   # prompt-free (CI / coding agents)
```

## What's in here

### `cx init` (new command)

A thin alias that chains `cx profiles add` → `cx skills install`, ending
in a success message. It holds no profile or skill logic of its own —
each step delegates to the command that owns it.

- **Two modes, chosen automatically (no mode flag):** bare `cx init` on
a terminal runs a guided quick setup (OAuth browser login by default,
region prompt, first-profile safety questions; credential storage /
label are defaulted instead of asked). Fully flag-specified runs (or no
terminal) are prompt-free for the profile step; `--global`/`--local` (or
`--no-skills`) makes the whole run prompt-free.
- **Idempotent, never silently lossy:** a *bare* re-run skips the
profile step when a profile exists and the skills step when the cx
skills are installed. Explicit profile flags are never discarded:
`--force` reconfigures the profile, and passing profile flags without it
fails instead of misreporting success. Env-sourced values (`CX_API_KEY`,
`CX_REGION`, `CX_PROFILE`) don't break a bare re-run — only flags typed
on the command line signal intent.
- **Fails fast, never hangs:** with no terminal and no API key, init
errors immediately naming `--api-key` — OAuth is only defaulted to on a
real terminal (pass `--oauth` to force it).
- **Skills failures never brick onboarding:** a missing npx or
unresolvable scope downgrades to a warning — a working profile still
counts as a successful setup.
- **Contradictions are rejected:** multiple `--profile` values fail
(init configures exactly one profile), and `--no-skills` conflicts with
`--global`/`--local`/`--agent`.
- **Flags:** `--url`, `--oauth`, `--force`, `--no-skills`,
`--global`/`--local`, `--agent <name>...`, plus the global
`--profile`/`--region`/`--api-key`.

### `cx profiles add`: internal quick mode

A new `quick` option (used only by init, not exposed as a flag) that
skips the optional prompts and pins sensible defaults: file credential
storage, no label. Non-interactive quick runs — the coding-agent path —
additionally pin JSON output; the guided human walkthrough keeps the
text default. The essential prompts (region, browser login,
first-profile safety questions) are unchanged.

### `cx skills install`: quieter, cheaper, honest output

- The non-interactive (`-y`) install captures the installer's verbose
TUI (banner, per-skill table, risk matrix) and prints a one-line summary
pointing at the skills.sh listing (https://skills.sh/coralogix/cx-cli).
`--interactive` keeps the installer's full output, risk table included.
- On failure the installer's own diagnostics (stdout and stderr) are
surfaced before the retry hint.
- `run_install` returns an `InstallOutcome` and owns a single
already-installed probe: `skip_if_installed` (set by init) skips an
existing install to stay idempotent, while the explicit command
reinstalls to update. A fresh init run is now 3 npx spawns instead of 6.

### First-run guidance (FORGE-659)

Credential-requiring commands on a machine with no profile configured
print exactly one actionable next step — `Run cx init` — and exit
non-zero, with no config-resolution chain, leaked io errors, or
competing `cx profiles add` instruction. Onboarding commands (`init`,
`profiles`, `skills`) are handled before profile resolution and are
never short-circuited by this.

## Testing

- `tests/init/main.rs` — the full non-interactive chain via a fake `npx`
on PATH (no Node/network): profile + skills ordering, `--profile`
naming, multi-`--profile` rejection, `--agent` passthrough,
`--no-skills` (and its flag conflicts), npx-missing / no-scope warnings,
fail-fast without a key, bare-re-run idempotency,
flags-over-existing-profile rejection, and `--force` reconfiguration.
- `tests/first_run/main.rs` — the `cx init` guidance is asserted on the
*whole* stderr (no `Error:`/`Caused by:`/`cx profiles add`), and never
hijacks `cx profiles list`.
- `tests/skills/main.rs` — output suppression + compact summary, failure
diagnostics surfaced from both streams, scope-aware detection.
- `cargo fmt` / `cargo clippy` / `cargo test` all green.

## Tickets

- Linear: FORGE-658 (cx init), FORGE-659 (first-run guidance).
Verification ping is tracked separately in FORGE-660.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-20 10:49:52 +03:00
..
2026-08-20 10:49:52 +03:00