# Configuration

`mission-control` finds its configuration files with the moon-lander
configuration conventions for the application name `mission-control`. The files
are YAML. A more specific file wins:

| Source | Files |
| --- | --- |
| System | `mission-control.yaml` in the system folder |
| User | `mission-control.yaml` in the user folder or in `MISSION_CONTROL_HOME`, and not in both |
| Project, found from the working directory upward | `mission-control.yaml`, `.mission-control/mission-control.yaml` or `.config/mission-control/config.yaml` |
| Local override, next to the project file | `mission-control.local.yaml` |
| User override, next to the project file | `mission-control.user.yaml` |
| Environment | variables that start with `MISSION_CONTROL__`, such as `MISSION_CONTROL__DOWNLOAD__PROXY` for `download.proxy` |

The system folder and the user folder are:

| System | System folder | User folder |
| --- | --- | --- |
| Linux | `/etc/mission-control` | `~/.config/mission-control` |
| macOS | `/etc/mission-control` | `~/Library/Application Support/mission-control` |
| Windows | `%PROGRAMDATA%\mission-control` | `%APPDATA%\mission-control` |

On Linux and macOS, the variable `XDG_CONFIG_HOME` gives another place for the user
folder.

`mission-control config show` prints each merged setting and the file or
variable that set it.

## The `download`, `desktop` and `logging` sections

`mission-control desktop install` and `mission-control desktop update` use these
sections. Each setting is optional.

```yaml
download:
  proxy: http://proxy.example.com:8080      # an HTTP proxy, or none
  no_proxy: [internal.example.com]          # hosts that the command connects to directly
  proxy_login: { env: MY_PROXY_LOGIN }      # the variable with user:password
  ca_file: /etc/ssl/company.pem             # the certificates to trust
desktop:
  source: https://mirror.example.com/mission-control   # a mirror of the releases
  version: 0.6.0                            # the version that counts as the newest one
logging:
  level: information                        # the lowest level in the log file
```

- Without `download.proxy`, the command uses the variables `HTTPS_PROXY`, `ALL_PROXY` and
  `NO_PROXY` of the shell. A rule of `no_proxy` is also for the subdomains of its host,
  and `"*"` is for each host.
- A password cannot be in a file. Put `user:password` into an environment variable, and
  put the name of the variable into `download.proxy_login`.
- With `download.ca_file`, the command trusts only the certificates in this PEM file.
  Without it, the command trusts the ones of the system.
- `logging.level` is `trace`, `debug`, `information`, `warning`, `error` or `critical`. The
  log is in the folder `logs` of [the base folder](../../../docs/guides/web-ui.md#files).

Only the system file, the user file and the environment can have these sections. A cloned
repository cannot change where the app comes from. The command ignores the sections in a
file of a project, and prints a warning. A key that is not a setting gives a warning too. A
wrong value ends the command with exit code 1.

```mbt check
///|
async test "the sections of the app in the file of a user" {
  let store = @memory.MemoryStore()
  store.put(
    @okf.StorePath("home/ana/.config/mission-control/mission-control.yaml"),
    (
      #|download:
      #|  proxy: http://proxy.example.com:8080
      #|  no_proxy: [internal.example.com]
      #|  proxy_login: { env: MY_PROXY_LOGIN }
      #|  ca_file: /etc/ssl/company.pem
      #|desktop:
      #|  source: https://mirror.example.com/mission-control
      #|  version: 0.6.0
      #|logging:
      #|  level: information
      #|
    ),
  )
  let place = @settings.SearchPlace(
    env_vars=Map([("HOME", "/home/ana")]),
    platform=Some(Linux),
  ).in_folder("/w")
  let config = @settings.AppConfig::load(@settings.StoreFiles(store), place)
  assert_eq(config.problems(), ([], []))
  assert_eq(config.settings().map(setting => setting.0), [
    "download.proxy", "download.no_proxy", "download.proxy_login", "download.ca_file",
    "desktop.source", "desktop.version", "logging.level",
  ])
}
```

## The `kb` section

```yaml
kb:
  use: [openspec, ./rules/house.yaml]          # built-in profiles and rule packs
  severity: { concept-missing-title: error }   # rule name: error, warn or info
  disable: [stale-after-passed]                # rules that do not run
  overridable: [decision-needs-owner]          # rules that bundles and flags may lower or turn off
```

The configuration is the policy root. A bundle and the command line can add
rules, raise a severity and replace a rule. They can lower a severity or turn
off a rule only when the configuration lists it in `overridable` (or a pack of the
configuration marks it `overridable: true`; the flag counts only there). The OKF conformance and advisory rules are always
overridable. A key that is not a setting, or a value that breaks its rule, is
reported with its file, and the command goes on.

```mbt check
///|
async test "the kb section of a project file" {
  let store = @memory.MemoryStore()
  store.put(
    @okf.StorePath("w/.config/mission-control/config.yaml"),
    (
      #|kb:
      #|  use: [openspec, ./rules/house.yaml]
      #|  severity: { concept-missing-title: error }
      #|  disable: [stale-after-passed]
      #|  overridable: [decision-needs-owner]
      #|
    ),
  )
  let place = @settings.SearchPlace(env_vars=Map([]), platform=Some(Linux)).in_folder(
    "/w",
  )
  let config = @settings.load_config(
    @settings.StoreFiles(store),
    place.all_files(),
  )
  let (settings, problems) = @settings.KbSettings::of_config(config)
  assert_eq(problems, [])
  assert_eq(settings.uses.length(), 2)
  assert_eq(settings.severities.length(), 1)
  assert_eq(settings.disabled.length(), 1)
  assert_eq(settings.overridable.length(), 1)
}
```

## Rules that travel with a bundle

A bundle carries its own layer in the frontmatter of its root `index.md`, under
`x-mission-control`. It takes `use`, `severity` and `disable`, not
`overridable`. Pack paths are relative to the bundle root and must stay inside
the bundle.

```mbt check
///|
test "the bundle layer of a root index" {
  let knowledge = @okf.discover(
    @okf.DocumentSet::of_texts([
      (
        "design/index.md",
        (
          #|---
          #|okf_version: "0.3"
          #|x-mission-control:
          #|  use: [.rules/decisions.yaml]
          #|  severity: { decision-needs-context: error }
          #|  disable: [stale-after-passed]
          #|---
          #|
        ),
      ),
    ]),
  )
  let bundle = knowledge.bundles()[0]
  let (settings, problems) = @settings.KbSettings::of_bundle(bundle)
  assert_eq(problems, [])
  inspect(
    @settings.bundle_pack_path(bundle, ".rules/decisions.yaml"),
    content="design/.rules/decisions.yaml",
  )
  assert_eq(settings.severities.length(), 1)
}
```
