# 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 on Linux |
| --- | --- |
| System | `/etc/mission-control/mission-control.yaml` |
| User | `~/.config/mission-control/mission-control.yaml` |
| 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_` |

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

## 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 config = @settings.load_config(
    store,
    @settings.config_builder("/w", platform=Linux),
  )
  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)
}
```
