Skip to content
Merged
2 changes: 1 addition & 1 deletion docs/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ DevOps CLI supports hierarchical configuration resolution through:
4. **Global User Configuration** (`~/.config/devops-cli/config.yaml`)
5. **System Defaults**

`setting_sources` in `src/devops_cli/config/settings.py` declares the order of items 2 to 5 one time, as pydantic-settings sources. A setting takes the value of the first source that holds it, and only that value is checked against the type of the setting: a value that a variable replaces is not checked. A null in the project file is no value, so the value of the global file stays. A config file whose document is not a mapping of keys to values stops the load with an error that names the file. `DEVOPS_CLI_DATA_DIR` also moves each data path that no variable of its own sets into that directory, so the data paths of a config file do not apply. A credential resolves in its own order: the OS keyring, Vault, its variable, and last the config file, for a credential that a config file can hold.
`setting_sources` in `src/devops_cli/config/settings.py` declares the order of items 2 to 5 one time, as pydantic-settings sources. A setting takes the value of the first source that holds it, and only that value is checked against the type of the setting: a value that a variable replaces is not checked. A null in the project file is no value, so the value of the global file stays. A config file whose document is not a mapping of keys to values stops the load with an error that names the file. A settings save writes a config file as YAML 1.2, and each read of a config file reads YAML 1.2 too. So a bare `off`, `on`, `yes`, `no` or `12:30` is a string, and only a bare `true` or `false` is a bool. A key that a mapping holds two times stops the load with an error that names the file, the line and the column. `DEVOPS_CLI_DATA_DIR` also moves each data path that no variable of its own sets into that directory, so the data paths of a config file do not apply. A credential resolves in its own order: the OS keyring, Vault, its variable, and last the config file, for a credential that a config file can hold.

A `devops review` command reads a tree it does not own. Started in a repository other than devops-cli's own, it looks for no project configuration, reading only the file `DEVOPS_CLI_CONFIG` names, and it resolves a relative data path under `~/.local/share/devops-cli` rather than under that repository, so its default data directory is `~/.local/share/devops-cli/.data`. What a review keeps -- its sessions, the feedback dataset, runs, samples, library contracts and AI spend -- every other command started outside devops-cli's own repository reads and writes there too. devops-cli's own repository is the one whose checkout holds the source of the devops-cli that runs, as an editable install's does; its code already runs, so a review started there, or in any worktree of it, reads its project configuration and keeps all data under its main worktree's `.data`, as every other command does. A clone nested in that checkout is another repository, and an installed devops-cli trusts no repository this way. An absolute `DEVOPS_CLI_DATA_DIR` or `data.dir` names the data directory every command uses.

Expand Down
2 changes: 1 addition & 1 deletion docs/roadmap/intake.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ devops gh issues close <number> --reason not-planned

## Jev for the proposal

The setting `roadmap.intake.jev` has three values (ADR 0019). `off` is the default and makes no Jev request. `shadow` keeps the `triage` model for every label and every flag, and records what TypeSafe Jev (`typesafe/jev-1.14`) would answer. `on` asks Jev for the fields of the proposal in place of the `triage` model. Jev must not decide yet: on the 25 closed issues of `devops roadmap eval jev` it ties the `triage` model on type, and it is behind on priority, Value and Effort. Use `shadow` to measure it on real new issues.
The setting `roadmap.intake.jev` has three values (ADR 0019). `off` is the default and makes no Jev request. `shadow` keeps the `triage` model for every label and every flag, and records what TypeSafe Jev (`typesafe/jev-1.14`) would answer. `on` asks Jev for the fields of the proposal in place of the `triage` model. Jev must not decide yet: on the 25 closed issues of `devops roadmap eval jev` it ties the `triage` model on type, and it is behind on priority, Value and Effort. Use `shadow` to measure it on real new issues. A config file is read as YAML 1.2 ([configuration reference](../CONFIGURATION.md)), so `jev: off` and `jev: on` with no quotes are the modes `off` and `on`. A bool, such as `jev: true`, is not a mode, and the settings do not load.

One request holds a question for each field that has a fixed list:

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
schema: spec-driven
created: 2026-11-11
skip_specs: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Design

## Decisions

- **The reader changes, not the writer and not the types.** The writer `round_trip.edit` writes YAML 1.2 with ruamel.yaml. Each reader of a config file now reads YAML 1.2 with the same library, so each string that a save writes loads as the same string. This fixes all string settings, not only the two mode fields.
- **One reader, `parse_config_yaml`, in `config/yaml_errors.py`.** It calls `YAML(typ="safe", pure=True).load(text)`. `pure=True` keeps the Python parser of YAML 1.2 when ruamel.yaml.clib is installed. A new `YAML` object for each call keeps the reader free of shared state between threads.
- **The import of ruamel.yaml stays inside the functions.** `parse_config_yaml`, `load_yaml` and `yaml_load_errors` import ruamel.yaml when they run. A command that reads no config file, such as `devops config --help`, does not import the 29 modules of ruamel.yaml. `config/write_history.py` imports `round_trip`, which already imports ruamel.yaml.
- **`load_yaml` catches the errors of ruamel.yaml.** `yaml_load_errors()` gives the `YAMLError` of ruamel.yaml and the errors of a value that the loader cannot build (`ValueError`, `LookupError`, `AttributeError`, `RecursionError`). `load_yaml` catches them for each parse, the round trip included, so its `errors` parameter goes. The rule of #1468 stays: the error names the file, the type of the error, and its line and column, and quotes no text of the file. The text of the file stays in the frame of the parse, which is not in the traceback of the error.
- **The mode types stay as they are.** `JevMode`, `DecisionMode` and the refusal of a bool of #4438 do not change. A bare `true` is a bool in YAML 1.2, so the scenario "The old bool is refused" of `roadmap-intake-jev` stays true.
- **The ConfigMap render reads only its config as YAML 1.2.** Kubernetes reads the manifest of the template, and its parser reads YAML 1.1, so the render reads the manifest with PyYAML. The config in the manifest is a devops-cli config file, so the render reads it with `parse_config_yaml`. The render writes the config with PyYAML, which quotes each word that YAML 1.1 reads as a bool or a number, such as `'off'`. The YAML 1.2 reader of the Service reads the same string. The render validates the settings of the YAML 1.2 read of the text that it writes, so it never writes a config that the Service cannot load.
- **The SSH key prefix reads the project config file as YAML 1.2.** `crypto/ssh_keys.py` reads `ssh.key_prefix` from a project config file without the settings load. It reads the same files, so it uses the same reader. It catches the errors that the settings load catches (`yaml_load_errors()`) and an `OSError`, so a tagged value that the loader cannot build gives no prefix and does not stop the command. The `try` block holds only the read and the parse.
- **A duplicate key stops the load.** The safe loader of ruamel.yaml refuses a key that a mapping holds two times, as YAML 1.2 requires. PyYAML kept the last value with no message. The error names the file, the line and the column, so a person can remove the duplicate.

## Rejected alternatives

- **A `BeforeValidator` on `JevMode` and `DecisionMode` that maps a bool to a mode.** The closed plan pull request #4599 proposed it. It fixes 2 of about 100 string settings: `devops config set search.language no` still writes `no` and stops each later load. It also makes `jev: true` and `jev: yes` load as `on`, the live mode, against #4438 and ADR 0019.
- **Quote the values in `round_trip.edit`.** Quotes cover only a file that the writer writes. A file that a person types, and the config of a ConfigMap, stay exposed.
- **A PyYAML loader subclass with the booleans of YAML 1.2.** It patches PyYAML and keeps two YAML versions in one process. Each other YAML 1.1 form, such as `12:30` as 750, still changes type. The import cost of ruamel.yaml (29 modules, only for a command that reads a config file) does not justify it.
- **Import ruamel.yaml at the top of `yaml_errors.py`.** The settings module imports `yaml_errors`. So each start that imports the settings module, such as `devops config --help`, would import the 29 modules of ruamel.yaml, also when it reads no config file. `python -X importtime` shows that `devops config --help` imports `devops_cli.config.settings` and does not import `ruamel.yaml`.
- **Write the config of the ConfigMap with ruamel.yaml too.** A prototype on the repository template wrote a different text: it folds the long telemetry URL at 80 columns and writes `jev: off` bare. The PyYAML writer quotes each word that YAML 1.1 reads as a bool or a number, so the YAML 1.2 reader reads the same value for each setting of the template.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Proposal: #4481

## Why

A bare `off` or `on` as the value of `roadmap.intake.jev` stops the settings load (#4481). The settings save writes a config file with ruamel.yaml, which writes YAML 1.2 (`round_trip.edit`). The readers read the file with PyYAML `yaml.safe_load`, which reads YAML 1.1. In YAML 1.1, a bare `off` is `false`, a bare `no` is `false` and a bare `12:30` is the number 750. So `devops config set roadmap.intake.jev off` writes `jev: off`, and the next load reads `false`, which the mode type refuses. The same defect occurs for each string setting: `devops config set search.language no` and `devops config set k8s.context 12:30` write the file and then stop each later load.

## What Changes

- Each reader of a config file reads it as YAML 1.2 with the safe loader of ruamel.yaml (`YAML(typ="safe", pure=True)`), the library that writes the file. The readers are the settings load (`settings._read_config_file`), the two readers of `write_history`, the audit of `devops config audit-keys`, the config in the ConfigMap template of `k8s/configmap.py`, and the project config read of the SSH key prefix (`crypto/ssh_keys.py`).
- `config/yaml_errors.py` holds the one YAML 1.2 reader, `parse_config_yaml`, and the errors of a load, `yaml_load_errors()`. `load_yaml` catches the `YAMLError` of ruamel.yaml in place of the error of PyYAML. Each function imports ruamel.yaml when it runs, so a command that reads no config file does not import it.
- A bare `off`, `on`, `yes` or `no` in a config file loads as a string. A key that a mapping holds two times stops the load with an error that names the file, the line and the column. `JevMode`, `DecisionMode` and the refusal of a bool stay as they are: a bare `true` is still a bool, and the mode types refuse it.
- The ConfigMap render reads the manifest of the template with PyYAML, because Kubernetes reads the manifest. Only the config in the manifest is read as YAML 1.2.
- `docs/CONFIGURATION.md` and `docs/roadmap/intake.md` state that a config file is read as YAML 1.2.
- These behaviors are observable (the settings load, `devops config set`, `devops config audit-keys`, the ConfigMap render and the SSH key prefix), so the change has a spec delta.

## Capabilities

- `config-commands`: ADDED requirements for the YAML 1.2 read of each config file. MODIFIED requirement "A write or an edit of a config file quotes no text of a file that a YAML parser cannot load", because no reader of a config file uses PyYAML after this change.

## Impact

- Each command that loads the settings imports ruamel.yaml when it reads a config file: 29 more modules. `uv run devops ci --only startup-imports` measures the start of the help commands.
- Values that change type, from the census of the committed config inputs: none. Values of the YAML 1.1 forms change: a bare `0755` loads as 755 and not as 493, a bare `1:30` loads as the string `1:30`, so a number setting refuses it, and a bare `1e3` loads as the number 1000.0.
- The change fits one pull request.

## Feasibility

The premise was confirmed with commands on PyYAML 6 and ruamel.yaml 0.19.1, the version that `pyproject.toml` pins:

- `yaml.safe_load("jev: off")` gives `{'jev': False}`, and `YAML(typ="safe", pure=True).load("jev: off")` gives `{'jev': 'off'}`. The same holds for `on`, `yes` and `no`. `12:30` gives 750 with PyYAML and `'12:30'` with ruamel.yaml.
- A key that a mapping holds two times raises `DuplicateKeyError`, a `MarkedYAMLError` with a mark. `roadmap: [unclosed` raises `ParserError` with a mark. `!!int <text>` raises `ValueError`, `!!bool <text>` raises `KeyError`, and a document that nests too deep raises `RecursionError`, as with PyYAML. `!!timestamp <text>` raises `ConstructorError` with a mark, where PyYAML raised `AttributeError`.
- ruamel.yaml.clib is not installed. `pure=True` keeps the Python parser of YAML 1.2 also when it is installed: the deprecation text of `ruamel.yaml.main.safe_load` names `typ='safe', pure=True` as its replacement.
- Census of the readers: `git grep -nE 'yaml\.safe_load(_all)?\(' -- 'src/*.py'` gives 44 lines. 7 of them are in `src/devops_cli/config`, `commands/config.py`, `k8s/configmap.py` and `crypto/ssh_keys.py`: 6 read a config file, and 1 reads the Kubernetes manifest of the ConfigMap template and stays PyYAML. The other 37 lines read other files (manifests, rule packs, `labels.yml`, `.pre-commit-config.yaml`), not a config file of devops-cli.
- Census of the values: on `config.example.yaml` and the config in `k8s/devops/configmap.example.yaml`, 0 of 84 values change between the two readers.
- With `import devops_cli.config.settings` done first, `import ruamel.yaml` adds 29 modules.

## Existing Tool Considered

ruamel.yaml (`ruamel-yaml==0.19.1`), an open and maintained library that `pyproject.toml` already pins and that `round_trip.edit` uses to write the file. Its safe loader reads YAML 1.2, the version that the writer writes. The change builds no code to keep: each reader calls the loader of the library.

The change deletes this internal code: the PyYAML imports of `config/settings.py` and `config/write_history.py`, the `errors` parameter of `load_yaml`, `_LOAD_ERRORS` of `config/round_trip.py` and `_AUDIT_READ_ERRORS` of `commands/config.py`.
Loading