Repository navigation
feat(cli): add the output format join point and restore colour negotiation - #391
Merged
Merged
Conversation
…ation Closes #326. The serialization primitives already existed -- `format_json`, `format_yaml`, `format_serialized` -- but nothing joined them to the commands. Each of the 53 commands offering `--json` emitted its own `write_stdout(json.dumps(...))`, deciding for itself whether to call `model_dump()` or `to_dict()` first, so adding a second format meant editing every one of them. None offered YAML, although `format_yaml` had been there the whole time. `emit_serialized(payload, fmt)` is the join. It takes a Pydantic model, an object exposing `to_dict()`, or a plain structure. Ten emission sites across `ai_gateway`, `ai_controller` and `ai_chaos` now route through it and gained working YAML with no signature change, because they already exposed `--format`. YAML was not portable. `yaml.dump` writes a Python constructor tag for anything it does not recognise, so `QuiesceState.QUIESCED` rendered as `!!python/object/apply:devops_cli.ai.controller.models.QuiesceState` and `yaml.safe_load` refused to read it back -- the output was unusable by any consumer that is not this interpreter. Values now pass through JSON coercion before `safe_dump`, so both formats describe the same data, and a test asserts that for enums, paths and datetimes rather than for a payload that was already plain. Terminal capability negotiation was defeated by its own wrapper. `get_console` defaulted `color_system` to `None`, and `None` is not "unspecified" to Rich -- it means no colour at all. Any caller passing `file=` or `force_terminal=` therefore lost colour silently. Only tests do that today, which is why nobody noticed, but it is the opposite of what the function is for. The default now inherits Rich's negotiation, so `NO_COLOR`, a non-TTY destination and `TERM=dumb` all take effect, and passing `color_system=None` explicitly still disables colour, which is what this suite wants. Four tests pin each case; the colour one has to describe a colour-capable terminal first, since the suite runs under `NO_COLOR=1` and `TERM=dumb`. The issue asked for `--json` / `--yaml` across 100% of subcommands. That target is wrong and the task file records why: an interactive chat, a port-forward daemon and a TUI have no result to serialise, and a `--format` flag that emits an empty object is worse than no flag. The remaining adoption is roadmapped as every command whose output is a value, enumerated rather than assumed. Measured at close: 306 commands, 53 with `--json`, 17 with `--format`, 10 on the join point.
This was referenced Sep 22, 2026
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #326.
The serialization primitives already existed --
format_json,format_yaml,format_serialized-- but nothing joined them to the commands. Each of the 53 commands offering--jsonemitted its ownwrite_stdout(json.dumps(...)), deciding for itself whether to callmodel_dump()orto_dict()first, so adding a second format meant editing every one of them. None offered YAML, althoughformat_yamlhad been there the whole time.emit_serialized(payload, fmt)is the join. It takes a Pydantic model, an object exposingto_dict(), or a plain structure. Ten emission sites acrossai_gateway,ai_controllerandai_chaosnow route through it and gained working YAML with no signature change, because they already exposed--format.YAML was not portable.
yaml.dumpwrites a Python constructor tag for anything it does not recognise, soQuiesceState.QUIESCEDrendered as!!python/object/apply:devops_cli.ai.controller.models.QuiesceStateandyaml.safe_loadrefused to read it back -- the output was unusable by any consumer that is not this interpreter. Values now pass through JSON coercion beforesafe_dump, so both formats describe the same data, and a test asserts that for enums, paths and datetimes rather than for a payload that was already plain.Terminal capability negotiation was defeated by its own wrapper.
get_consoledefaultedcolor_systemtoNone, andNoneis not "unspecified" to Rich -- it means no colour at all. Any caller passingfile=orforce_terminal=therefore lost colour silently. Only tests do that today, which is why nobody noticed, but it is the opposite of what the function is for. The default now inherits Rich's negotiation, soNO_COLOR, a non-TTY destination andTERM=dumball take effect, and passingcolor_system=Noneexplicitly still disables colour, which is what this suite wants. Four tests pin each case; the colour one has to describe a colour-capable terminal first, since the suite runs underNO_COLOR=1andTERM=dumb.The issue asked for
--json/--yamlacross 100% of subcommands. That target is wrong and the task file records why: an interactive chat, a port-forward daemon and a TUI have no result to serialise, and a--formatflag that emits an empty object is worse than no flag. The remaining adoption is roadmapped as every command whose output is a value, enumerated rather than assumed. Measured at close: 306 commands, 53 with--json, 17 with--format, 10 on the join point.