Skip to content

refactor(output): move inline Rich markup to theme roles #4760

Open

Description

@dan-petty

Problem or Motivation

After the Rich theme of #4748 merges, about 577 inline markups in 58 files (688 minus the 111 of messages.py) and 162 style= arguments still name colors directly, such as [green], [bold red] or style="cyan". The output of the same state can then still differ from module to module, and the theme roles do not apply there.

Proposed Solution & Architectural Design

  • Move the inline markups and style= arguments to the role names of src/devops_cli/design/roles.ini (status.ok, status.warn, status.error, sev.*, muted, heading, accent, link, code).
  • Do the move one module group at a time, in 2 or 3 pull requests, so each pull request stays small.
  • Add an ast-grep rule (Python is a built-in ast-grep language) that rejects raw color names in markup strings and style= arguments outside output/console.py and roles.ini.

Target Subsystem

Terminal output (src/devops_cli/).

Existing Tool Considered

Rich theme roles (Rich 15.0.0, in use) and ast-grep (in use, with sgconfig.yml). No new dependency and no custom checker. Cost (estimate): about 150,000 tokens and 1 day over the pull requests.

Acceptance Criteria

  • The ast-grep rule reports 0 raw color names in src/devops_cli outside the allowed files.
  • The existing output tests pass.

Dependencies

Source: #4735

Alternatives check of 2026-11-14: not-applicable.
Class: refactor, no search.
Tool: none found.

Proposed design

Problem statement

About 577 inline Rich markups and 162 style= arguments in 58 files name raw colors such as [green] and style="cyan". The same state can then render differently from module to module, and the theme roles do not apply there. The change moves each markup and each style= argument to a theme role of #4748 and adds an ast-grep rule that rejects a raw color name. The work waits on #4748 and is too big for one pull request, so three pull requests deliver it.

Acceptance criteria

Requirement: Raw color names in markup strings are rejected

The ast-grep rule SHALL report a raw Rich color name in a markup string of src/devops_cli, unless the file is src/devops_cli/output/console.py or src/devops_cli/design/roles.ini.

Scenario: A command prints a raw color

  • WHEN A Python file under src/devops_cli/commands/ holds the markup string [green]ok[/green].
  • THEN ast-grep scan reports one finding at that line, and the invalid case of the rule test matches it.

Requirement: Raw color names in style arguments are rejected

The ast-grep rule SHALL report a raw Rich color name in a style= argument of src/devops_cli, unless the file is src/devops_cli/output/console.py or src/devops_cli/design/roles.ini.

Scenario: A table sets a raw color

  • WHEN A Python file under src/devops_cli/roadmap/ passes style="cyan" to a Rich object.
  • THEN ast-grep scan reports one finding at that line, and the invalid case of the rule test matches it.

Requirement: Theme role names pass the rule

The ast-grep rule MUST accept each role name of the theme in a markup string and in a style= argument.

Scenario: A module prints a role name

  • WHEN A Python file under src/devops_cli/ holds [status.ok]ok[/status.ok] and style="muted".
  • THEN ast-grep scan reports no finding for those lines, and the valid case of the rule test passes.

Requirement: The theme files keep their raw color names

The ast-grep rule MUST report no finding for src/devops_cli/output/console.py and src/devops_cli/design/roles.ini.

Scenario: The theme names a raw color

  • WHEN src/devops_cli/output/console.py passes style="cyan" to a Rich object, and src/devops_cli/design/roles.ini maps status.ok to green.
  • THEN ast-grep scan reports no finding for those files, and the valid case of the rule test passes.

Requirement: No raw color name remains outside the theme

Each migrated module SHALL name a theme role instead of a raw Rich color in a markup string and in a style= argument.

Scenario: The whole package is scanned

  • WHEN ast-grep scan runs on src/devops_cli after the last module group merges.
  • THEN The scan reports zero raw color names outside src/devops_cli/output/console.py and src/devops_cli/design/roles.ini.

Requirement: Rendered output stays the same

The rendered output of each migrated message MUST equal its output before the migration.

Scenario: The output tests run on a migrated module group

  • WHEN The suite tests/output/test_output.py runs on the pull request of a module group.
  • THEN Each test passes with no change to its expected string.

Existing Tool Considered

Rich 15.0.0 (pyproject.toml:14) supplies the theme roles, and ast-grep 0.51.2 (pyproject.toml:123) supplies the scan. Neither has a built-in rule for a raw Rich color in a markup string or a style= argument, so the change writes one ast-grep rule and its rule tests. The body estimates that code at about 150,000 tokens and 1 day over the pull requests. The alternatives check of 2026-11-14 recorded not-applicable for a refactor, with no search and no tool.

Key questions

  • Which file builds the shared Rich console, and which files may keep a raw color name?: src/devops_cli/output/console.py builds the shared console (get_console, lines 80-114). The issue allows raw color names only in that file and in src/devops_cli/design/roles.ini; the theme file is not in this commit, so it arrives with feat(output): add one Rich theme of status roles and marks #4748. [sources: src/devops_cli/output/console.py:80, docs/DESIGN.md:266]
  • Where do the ast-grep rules and their tests live?: The rules live in .ast-grep/rules/ and the rule tests in .ast-grep/rule-tests/, as sgconfig.yml sets them. [sources: sgconfig.yml:1, sgconfig.yml:3]
  • Does the migration include src/devops_cli/lang/en/messages.py?: Yes. The rule scans all of src/devops_cli, and the acceptance criterion exempts only the theme files. (best practice) [sources: src/devops_cli/lang/en/messages.py:120, src/devops_cli/output/console.py:80]
    • Chosen: Include messages.py in the migration. The gate allows only the theme files to name a raw color, so its 111 markups must move. The 577 count leaves them out as an estimate of the rest, not as a scope limit.
    • Rejected: Leave messages.py out of the migration. The rule would then need a second exempt file, and the gate of the body names none.
  • Which role replaces each raw color name?: docs/DESIGN.md:266 records the terminal theme: green maps to status.ok, yellow to status.warn, red and bold red to status.error, default or no color to status.info, dim to muted, and cyan to accent. Keep bold as a modifier where the role is not already bold. A severity uses the one sev.* map; a heading, link or code span uses heading, link or code where feat(output): add one Rich theme of status roles and marks #4748 defines them. A raw color with no role (magenta, blue, white) takes the role of its content: accent for emphasis, code for a language or code token, and muted for an unknown or secondary value. Do not add a new role for a hue. (best practice) [sources: docs/DESIGN.md:266, docs/adr/0024-the-project-owns-its-design-tokens-in-the-dtcg-format-and-style-dictionary-builds-them.md:12, src/devops_cli/commands/rag.py:404, src/devops_cli/review/report.py:868]
    • Chosen: Map by the recorded terminal theme and the meaning of the text. docs/DESIGN.md:266 records the six ANSI mappings and the one severity map; the remaining roles are semantic, so magenta, blue and white go to accent, code or muted instead of new hue roles.
    • Rejected: Add a theme role for each raw color name. It copies the ANSI table into roles.ini, keeps the module-to-module drift, and gives magenta, blue and white roles that the theme does not define.
    • Rejected: Keep the raw colors outside the console. It leaves the problem of the item and fails the ast-grep gate.
  • When does the ast-grep rule land, and how does the scan stay green?: The rule lands in the first pull request with files set to the migrated paths, and each later pull request adds its paths. The last pull request sets files to all of src/devops_cli. (best practice) [sources: sgconfig.yml:1, docs/DESIGN.md:78]
    • Chosen: Rule first, scoped by files, extended per pull request. The scan passes at each pull request, and no list of 58 exempt files is kept.
    • Rejected: Rule last, after every module group. The first two pull requests can add a new raw color with no check.
    • Rejected: Rule first with an allowlist of the 58 files. Each pull request edits the allowlist, and the list is easy to leave stale.
  • How does the migration keep the rendered output the same?: docs/DESIGN.md:266 maps each role to the ANSI color and attribute of the markup it replaces: status.error is bold red, status.ok green, status.warn yellow, status.info default, muted dim, accent cyan. A bold modifier stays on a role that is not already bold. A pull request changes no expected string of tests/output/test_output.py. (best practice) [sources: docs/DESIGN.md:266, tests/output/test_output.py:414]
    • Chosen: Keep the expected strings and fix the role. A changed expected string hides a change of the rendered output.
    • Rejected: Update the expected strings in the output tests. It accepts a different output with no record of the change.

Fit

Needs splitting into 3 items:

  1. Pull request 1: migrate src/devops_cli/output/ except console.py, src/devops_cli/ui/ and src/devops_cli/lang/en/messages.py, and add the ast-grep rule and its rule tests, with files set to those paths.
  2. Pull request 2: migrate src/devops_cli/commands/ and src/devops_cli/roadmap/, and extend the rule files to those paths.
  3. Pull request 3: migrate every remaining file that the scan reports, including src/devops_cli/ai/, docs/, github/, prometheus/, config/, server/, review/, k8s/ and telemetry/, and extend the rule files to all of src/devops_cli.

Suspected block

None.

Dependencies

#4748

Activity

  1. added
    source/agent
    on Nov 11, 2026
  2. added
    type/refactor
    scope/output
    status/new
    value/medium
    effort/medium
    on Nov 11, 2026
  3. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/refactor. The refactor prefix of the title gives the type.
    • Scope: scope/output. The (output) scope of the title gives the scope.
    • Priority: P2-Medium. It is a planned consistency refactoring with a clear dependency on #4748 and no user-facing defect it fixes.
    • Value: Medium. It removes per-module color inconsistency and adds a lint rule that prevents future drift, improving maintainability for all CLI users.
    • Effort: Medium. The body estimates about 150,000 tokens and 1 day across 2 or 3 pull requests, which is moderate.
    • Related: feat(cli): rich renderables architecture, terminal capability negotiation & universal output serialization research #326, which asks for a different change. Both work on Rich terminal output in src/devops_cli, but #326 builds the renderables architecture while this candidate migrates existing inline markup to the theme roles that architecture provides.
  4. added
    priority/p2-medium
    on Nov 11, 2026
  5. devops-cli-service commented on Nov 14, 2026

    @devops-cli-service
    Contributor

    Alternatives check: not-applicable

    Class: refactor. The check makes no search and no model call for an item of this class.

    Tool: none found

    Checked on 2026-11-14. A person decides what this means for the item. The check changes no label and closes no issue.

  6. devops-cli-service commented on Nov 15, 2026

    @devops-cli-service
    Contributor

    The proposal at e5dfddb needs splitting into 3 items. A person splits the item into the items below, or replies in a comment or edits the body to keep one item, and the next refine round looks at the item again.

    1. Pull request 1: migrate src/devops_cli/output/ except console.py, src/devops_cli/ui/ and src/devops_cli/lang/en/messages.py, and add the ast-grep rule and its rule tests, with files set to those paths.
    2. Pull request 2: migrate src/devops_cli/commands/ and src/devops_cli/roadmap/, and extend the rule files to those paths.
    3. Pull request 3: migrate every remaining file that the scan reports, including src/devops_cli/ai/, docs/, github/, prometheus/, config/, server/, review/, k8s/ and telemetry/, and extend the rule files to all of src/devops_cli.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p2-mediumscope/outputsource/agentstatus/newtype/refactorvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions