# Command-line interface

The same executable that opens the GUI can configure a profile from a terminal.
`kurama cli` is an interactive wizard for humans; `kurama apply` is the
non-interactive command for scripts.

```
kurama                     Open the graphical wizard
kurama gui [flags]         Open the graphical wizard explicitly
kurama serve [flags]       Run the local server without opening a browser
kurama cli [flags]         Run the guided terminal wizard
kurama apply [flags]       Apply a configuration non-interactively
kurama detect              List Firefox-family browsers
kurama profiles            List profiles for one browser
kurama install             Install Firefox with winget (Windows)
kurama restore             Restore a profile backup
kurama doctor              Check the environment and bundled assets
kurama version             Print build information
kurama help                Show the command overview
```

Run `kurama <command> -h` for the exact flags of that command.

## Exit codes

| Code | Meaning |
| --- | --- |
| `0` | Success, including a dry run. |
| `1` | Any handled failure: invalid flag, cancelled confirmation, missing browser, apply error. |

Errors are printed to stderr as `kurama: <message>`. Machine-readable output is
written to stdout only when `--json` is supported and set.

## `kurama cli`

The terminal wizard asks the same questions as the GUI, in the same order:
browser, profile, starting point, options, interests, add-ons, bookmarks, and
finishing touches. It prints a summary and asks for confirmation before applying.

```bash
kurama cli
kurama cli --browser firefox
kurama cli --dry-run          # print the plan, change nothing
kurama cli --json --dry-run   # emit the plan as JSON
```

If only one supported browser is installed it is selected automatically. The
wizard refuses to continue if the browser is running and asks you to close it.

## `kurama apply`

`apply` builds a plan from flags and runs the shared pipeline. In a
non-interactive shell it **requires `--yes`** before changing anything, which
prevents a forgotten script from editing a profile.

```bash
# Recommended, with an explicit confirmation inside a terminal
kurama apply --yes

# A separate private profile with maximum privacy
kurama apply --profile private --preset maximum_privacy --yes

# Modify an existing profile by name
kurama apply --existing default --options block_ai,ghost_mode --yes

# Pick add-ons and only essential bookmarks
kurama apply --addons ublock-origin,clearurls --bookmarks essential --yes

# Preview only; no browser or profile is touched
kurama apply --dry-run --preset compatibility
kurama apply --dry-run --json
```

### Flags

| Flag | Default | Meaning |
| --- | --- | --- |
| `--browser ID` | first installed | `firefox`, `librewolf`, `waterfox`, `floorp`, `zen`, `mullvad`, `palemoon`, or `tor`. |
| `--profile NAME` | `kurama` | Name for a new profile. |
| `--existing NAME` | — | Modify this existing profile instead of creating one. |
| `--profile-path PATH` | — | Modify an existing profile by folder path. |
| `--preset ID` | `balanced` | `balanced`, `maximum_privacy`, `compatibility`, or `custom`. |
| `--options LIST` | preset | Comma-separated option IDs, or `none`. |
| `--addons LIST` | preset | Comma-separated add-on IDs, or `none`. |
| `--bookmarks LIST` | suggested | IDs, or `none`, `all`, `essential`. A missing flag uses interest suggestions; an empty flag selects none. |
| `--interests LIST` | preset | Comma-separated interest IDs used for defaults. |
| `--import-bookmarks FILE` | — | Netscape HTML export to merge into the generated bookmark file. |
| `--wallpaper` | `false` | Install the bundled new-tab wallpaper. |
| `--wallpaper-path FILE` | — | Use a JPEG, PNG, WebP, GIF, or AVIF image instead. |
| `--shortcut` | `false` | Create a desktop shortcut for the profile. |
| `--launch` | `false` | Open the browser when the run finishes. |
| `--no-addon-install` | `false` | Do not use WebDriver; open each add-on's store page. |
| `--yes` | `false` | Skip confirmation. Required when stdin is not a terminal. |
| `--dry-run` | `false` | Print the plan and exit. |
| `--json` | `false` | Print the plan/result as JSON. |

An omitted `--addons` follows the preset. An explicit `--addons none` clears it.
The same distinction applies to `--bookmarks`. Unknown IDs fail with the list of
valid values, before anything is written.

### JSON output

`--dry-run --json` prints the plan object. A real run prints:

```json
{"plan": {…}, "result": {…}, "error": ""}
```

The result includes `profilePath`, `userJsPath`, `backupDir`, `installedAddons`,
`addonPages`, `bookmarkCount`, `wallpaper`, `shortcut`, `launched`, timestamps,
and `warnings`. `error` is a string so a script can inspect a failed run without
losing the completed portion.

## `kurama detect`

Prints every supported browser with its status, version, detection source,
executable, and profile folder. Missing browsers include their official
download link.

```bash
kurama detect
kurama detect --json
```

## `kurama profiles`

Lists the profiles registered in `profiles.ini` for one browser, including
whether each folder exists and whether kurama created it.

```bash
kurama profiles --browser firefox
kurama profiles --browser librewolf --json
```

## `kurama install`

Installs Firefox with winget on Windows. It refuses to run without `--yes` in a
non-interactive shell and is a no-op when Firefox is already installed.

```bash
kurama install --yes
```

Forks are not installed by kurama. `detect` and `install` print their official
download page instead. This is deliberate: fork packages vary by platform and
some ship their own profile rules.

## `kurama restore`

Restores the newest backup, or a specific backup folder, for a profile. It
refuses to run while the browser is open.

```bash
kurama restore --browser firefox --profile kurama --yes
kurama restore --backup "C:\Users\me\...\backups\20260101-120000.000" --yes
```

Only files kurama manages are restored. If a managed file did not exist before
the backed-up apply, restore removes it, which prevents leftover kurama files.

## `kurama doctor`

A support command. It reports the version, platform, installed browsers and
whether they are running, winget availability, config path, log folder,
bundled uBlock Origin manifest, bundled wallpaper size, the WebDriver version
and source (or why it is unavailable), and any problems.

```bash
kurama doctor
kurama doctor --json
```

## `kurama serve`

Runs the local server without opening a browser. Useful for remote shells,
testing, or opening the GUI manually.

```bash
kurama serve
kurama serve --port 18765 --json
kurama serve --addr 127.0.0.1 --open
```

`serve` never opens a browser unless `--open` is present. Use `kurama gui
--no-open` when you want the normal single-instance launcher behaviour but do
not want a browser tab opened automatically.

The JSON line contains a tokenized launcher URL. Treat it as a secret while the
process runs: anyone who can open it gets a session cookie for the local API.

## Environment variables

| Variable | Effect |
| --- | --- |
| `KURAMA_CONFIG_DIR` | Override the config directory. Used by tests to stay isolated. |
| `KURAMA_NO_WEBDRIVER` | Any non-empty value disables automatic add-on installation. |
| `KURAMA_GECKODRIVER` | Use this geckodriver binary instead of the bundled copy. |
| `KURAMA_DRIVER_CACHE` | Replace the driver cache root (tests use this). |
| `KURAMA_WEBDRIVER_HEADLESS` | `0` shows the Firefox window used for installation. |
| `KURAMA_WEBDRIVER_VERBOSE` | Include geckodriver/Firefox diagnostics in the log. |
| `KURAMA_NO_SELENIUM`, `KURAMA_SELENIUM_HEADLESS`, `KURAMA_SELENIUM_VERBOSE` | Legacy aliases kept for existing scripts. |

## Examples that are safe to try

```bash
# See what the recommended plan would do, without changing anything
kurama apply --dry-run --preset balanced

# Configure a throwaway profile and open it
kurama apply --profile test --preset balanced --launch --yes

# Remove kurama's additions from that profile
kurama restore --browser firefox --profile test --yes

# Check why automatic add-on installation is not working
kurama doctor
KURAMA_WEBDRIVER_VERBOSE=1 kurama apply --profile test --addons clearurls --yes
```
