Skip to content

docs(agents): a matching table lives beside its one owner, and moves to config/ only when a second package imports it #1016

Closed

Description

@dan-petty

Decision (owner, 2026-10-22)

This section replaces any text below that conflicts with it.

  • A string table lives beside its one owner. It moves to src/devops_cli/config/ only when a second package imports it.
  • A maintained library or a language parser does the classification. A hand-written list is acceptable only for a closed domain that a standard defines, such as an RFC or a language grammar.
  • AGENTS.md lines 16 to 19 become one bullet, "Classify With Parsers, Not Hand Lists" (pair A16). The duplicate bullet "Standard Parsers Over Brittle Literals" is deleted (pair A17).
  • The template in src/devops_cli/ai/instruction_generator.py:313-320, RELEASE_CYCLE.md:63-65 and docs/ROUTINE_TASKS.md:28, 102-103 state the same rule.
  • No constant moves in this pull request. A constant moves when its module is next touched.
  • No gate checks the placement. The project adds no new ratchet. The module core/config_placement.py, the baseline file tests/fixtures/config_placement_baseline.json and the two invariants of the plan below are not built. The change to DEFAULT_SANDBOX_POLICY that satisfies the second invariant is not needed.

Acceptance criteria for this decision:

  • No document and no generator output says that constants must be declared in constants.py or defaults.py.
  • AGENTS.md is shorter than before the change.
  • uv run devops ci passes.

Refreshed plan (2026-10-17, unblocking review)

This section supersedes any text below that conflicts with it.

Decisions

Scope

Delivery

  1. One PR (M) into main, with Closes #1016. Tests come first: tmp_path trees for each rule in the new checker, then the whole-tree test with the generated baseline.

Acceptance criteria
These replace the body's criteria on the same subjects. The other criteria stand, with their lines re-pointed as listed under Current references.

  • src/devops_cli/core/config_placement.py holds both checks as functions of parsed trees and a baseline mapping. tmp_path trees prove each rule: a name read by modules in two packages passes, with config/ counting as one package; a name only config/ reads passes; an unlisted single-package name fails; a listed name that now passes fails; a module that only re-exports a name does not count; a name that only builds another config/ name takes that name's importers; an __init__.py that reads a name counts in its own package; and a CONST_* or DEFAULT_* name declared outside config/ and read by another package fails.
  • test_the_source_tree_keeps_its_structural_invariants (tests/test_architectural_invariants.py:215) runs both checks on the trees from _parse_src() and parses nothing else. Its --durations=0 time rises by at most 1 s over the same test at the PR's base on the same machine, and the PR records both numbers. The checks run offline.
  • The baseline is generated at the PR's base and lists names by package. At 3dd7fa6 that is about 1,090 single-package names in 50 packages, plus the 45 CONST_ERROR_CODE_* names under their own key. The unread and test-only names also get their own keys: about 150 and 45 names at 3dd7fa6, or empty if refactor(config): the config barrel and the unused config names go, and the package inits stop re-exporting #776's first step has landed.
  • Invariant 2's one failure is DEFAULT_SANDBOX_POLICY (src/devops_cli/sandbox/models.py:441), which src/devops_cli/docker/sandbox.py:73 reads. This PR changes that field to Field(default_factory=SandboxPolicy).

Current references (verified at 3dd7fa6)

  • Rule in AGENTS.md: heading at AGENTS.md:17, brittle-subset bullets at :18-19, placement bullet at :20.
  • Rule in the template: src/devops_cli/ai/instruction_generator.py:312 (heading), :313-314 (brittle-subset bullets) and :315 (placement bullet).
  • Docs: RELEASE_CYCLE.md:63-66, with constants at :65. docs/ROUTINE_TASKS.md:28 and :100-104, with constants at :102.
  • Overwrite guard: src/devops_cli/commands/ai.py:948-954.
  • Whole-tree parse: _parse_src at tests/test_architectural_invariants.py:206-212, the test at :215-234, and the tmp_path tests of the import-graph checks at :377-487. tests/test_public_export_surface.py:104-112 (_exporting_modules) is a separate parse and is left as it is.
  • Invariant 2: src/devops_cli/sandbox/models.py:441; src/devops_cli/docker/sandbox.py:30-35 (import) and :73 (field). The __init__.py example is src/devops_cli/ai/retries/__init__.py:24-26.
  • Hook and test selection: .pre-commit-config.yaml:65-71 and src/devops_cli/core/test_selection.py:87-111.
  • Problem-section examples: _EMBEDDING_MODEL_HINTS is now at src/devops_cli/commands/benchmark.py:29 and _SENSITIVE_ARG_FLAGS at src/devops_cli/security/sanitizer.py:350.
  • refactor(config): the config barrel and the unused config names go, and the package inits stop re-exporting #776's barrel: src/devops_cli/config/__init__.py:408 (_SETTINGS_EXPORTS), :442 (__getattr__) and :450 (__all__).

Dependencies and order


Problem

AGENTS.md:21-24 requires every string list, tuple or frozen set used for matching, classification or filtering to be declared in config/constants.py or config/defaults.py, "so that it can easily be audited". The same rule is in the AGENTS.md template, src/devops_cli/ai/instruction_generator.py:301-304. Two hand-written docs repeat it: RELEASE_CYCLE.md:63-65 and docs/ROUTINE_TASKS.md:28 and :100-103.

The location is what the rule costs, and the audit it protects no longer depends on it. Counted at 38517a8 (the release/v0.2.25 tip) with an AST pass over src/devops_cli: a name counts as imported by a module when the module from-imports it or reads it as an attribute of the config module; config/__init__.py's re-exports are not counted. How function-local imports and names that only build another config/ name are attributed moves the per-category counts by up to about ten, so they are approximate; the baseline this item writes is the exact list.

  • config/constants.py is 2,794 lines with 682 module-level names, imported by 193 modules. config/defaults.py is 869 lines with 595 names, imported by 208 modules.
  • Only one package imports about 490 of the constants and 376 of the defaults. Two or more packages import about 60 and 89. Only config/ itself uses about 20 and 34, and about 30 more constants only build another config/ name. 40 more are CONST_ERROR_CODE_*, which only exceptions/ reads (refactor(cli): exceptions carry their codes as class data, and one exit seam replaces 19 hand-rolled exits #1006 turns them into class data). Nothing imports about 35 and 94, and only tests import 7 and 1 (refactor(config): the config barrel and the unused config names go, and the package inits stop re-exporting #776 deletes or moves those).
  • 86% of the assignment lines in constants.py belong to a name that one module or none imports.
  • The rule is not followed today either. About 100 module-level string tables live outside config/ in about 50 modules, 71 of them with private names (for example _EMBEDDING_MODEL_HINTS in commands/benchmark.py:26 and _SENSITIVE_ARG_FLAGS in security/sanitizer.py:310). 41 CONST_* or DEFAULT_* names are declared in 19 modules outside config/. Reviewing config/ alone misses all of them. A grep for module-level upper-case collections finds 285 outside config/.

What the shared file costs, from git history:

The open item that moves single-use constants to their consumer, #776, waits on this rule: "the move needs that rule changed ... until that is decided, only the first step is ready". This item makes that decision and adds the checks that hold it.

Acceptance criteria

  • The rule in src/devops_cli/ai/instruction_generator.py:301-304 says: a string list, tuple or frozen set used for matching, classification or filtering is a named module-level Final table next to its single owner, or in config/constants.py or config/defaults.py once a second package imports it. When several modules of one package read a table, it lives in that package's constants.py. The rule names the audit query, rg -n '^_?[A-Z][A-Z0-9_]+(: [^=]+)? = (frozenset\(|tuple\(|set\(|\(|\[|\{)' src/devops_cli. The heading drops "Mandatory Constants/Defaults Placement". The two bullets on brittle pattern subsets above it are unchanged.
  • AGENTS.md:21-24 is edited by hand to the same heading and bullet, and git diff AGENTS.md changes nothing else. It is not regenerated: at 38517a8 devops ai agents rewrites the whole curated file from a model or from the shorter template (commands/ai.py:919, ai/instruction_generator.py:412-427), which docs(agents): instruction surfaces state only what is true, and devops ai agents never overwrites AGENTS.md #840 fixes.
  • RELEASE_CYCLE.md:63-65 and docs/ROUTINE_TASKS.md:28 and :100-103 state the new rule or point to it. rg -n "constants\.py" RELEASE_CYCLE.md docs/ROUTINE_TASKS.md finds no sentence telling readers to centralise tables there.
  • Invariant 1, config/ holds shared names, in tests/test_architectural_invariants.py. Every module-level name in config/constants.py and config/defaults.py passes if modules in two or more packages use it, with config/ counting as one package, or if only config/ uses it. A name used only to build another config/ name takes that name's importers. A module that only re-exports a name (imports it and lists it in __all__, never reads it) does not count. An __init__.py that reads a name counts in its own directory's package, as ai/retries/__init__.py does for CONST_RETRYABLE_HTTP_STATUS_CODES.
  • Today's failures of invariant 1 are listed by package in tests/fixtures/config_placement_baseline.json: about 870 single-package names in 46 packages, the 40 CONST_ERROR_CODE_* names under a key of their own, which refactor(cli): exceptions carry their codes as class data, and one exit seam replaces 19 hand-rolled exits #1006 empties, and about 130 unused and 8 test-only names under their own keys. The test fails when an unlisted name fails invariant 1, so no new single-owner name lands in config/. It also fails when a listed name passes, so each move PR deletes its entries and the baseline only shrinks.
  • Invariant 2, owned tables stay owned, in the same file. A CONST_* or DEFAULT_* name declared outside config/ is used only by modules of its own package, with re-exports excluded as above. Today one name fails: DEFAULT_SANDBOX_POLICY (sandbox/models.py:396), which docker/sandbox.py:59 reads. This PR has docker/sandbox.py build its default with default_factory=SandboxPolicy.
  • A failure names the file, line, name and importing packages, and says where the name belongs.
  • Both checks reuse one cached parse of src/devops_cli, shared with _exporting_modules (tests/test_public_export_surface.py:104-108), which already parses every source module. Parsing the tree takes 2 to 3 s on the dev container, so the budget covers the checks themselves: at most 1 s beyond that parse, recorded from uv run pytest tests/test_architectural_invariants.py tests/test_public_export_surface.py --durations=0. They run offline.
  • uv run devops ci passes.

Key questions

  • Does the rule keep its goal? (proposed) Yes. The goal is one place to audit tables for brittleness. A query meets it better than a file: the grep above lists the 192 tables in constants.py and defaults.py and the 285 outside config/, which the file rule already misses.
  • What counts as a package, or "subsystem", in the invariants? (proposed) The importing module's parent package directory, so commands/pr.py and commands/gh.py are one package and ai/review/ is another. It follows from the file tree, with no hand-kept list of subsystems.
  • Where does a table go when two modules of one package read it? (proposed) In that package's constants.py, created when first needed, as ai/harness/constants.py already is. About 60 of the single-package names are shared this way.
  • Baseline as names or as counts? (proposed) Names, grouped by package, in one JSON file. A count would let a new single-owner name replace a moved one unseen. Grouping by package lets the move PRs delete separate blocks without conflicting.
  • Do the invariants check Final? (proposed) No. 37 of the 41 names outside config/ and 587 of the 595 in defaults.py lack it. The move items add Final to each name they move, and mypy already rejects reassigning a Final name. Enforcing it now would be a 600-line annotation change with no behaviour gain.
  • Should the 71 private-named string tables be renamed CONST_*? (proposed) No. The audit grep matches module-level upper-case names, private or not, so renaming them buys nothing.
  • Does this item promise fewer rebases? (proposed) No. The measured constants.py edits merge cleanly. The gain is locality and an audit that covers every table.
  • Which names stay in config/ for good? (proposed) Those that two or more packages use (about 60 constants and 89 defaults today), names only config/ uses, and the DEFAULT_* values behind Settings fields, which refactor(config): a settings field is the one declaration, and the option, env and config-show registries become views of it #1000 keeps in defaults.py.

Depends on: none.
Order: lands before the move items, one per package group, which take over #776's second step. The owner accepted this rule on 2026-10-02; they are #1025, #1026, #1027, #1028, #1029, #1030, #1031, #1032. #776's first step (delete the config/__init__.py re-exports and the unused names) does not wait on it. #586 (v0.2.25) edits ai/instruction_generator.py and tests/test_architectural_invariants.py, #840 (v0.2.27) and #841 rewrite AGENTS.md and its template, #851 edits other template bullets, and #1007 edits the same docs/ROUTINE_TASKS.md:28 row. Each touches other lines; whichever lands second rebases.
Related: #776 (the moves, which waited on this rule), #840 (devops ai agents stops overwriting AGENTS.md), #1006 (CONST_ERROR_CODE_* become class data), #1000 (Settings-backed defaults stay in defaults.py), #1007 (moves help text next to its command, the same rule applied to lang/), #933 (shared-file conflicts, measured on CHANGELOG.md), #431 (what the matching lists contain).

Proposed design

Problem statement

The current rule in AGENTS.md requires all string lists, tuples, or frozen sets used for matching, classification, or filtering to be declared in config/constants.py or config/defaults.py. This rule is costly due to merge conflicts, locality issues, and audit inefficiencies. The goal is to allow tables to live next to their single owner and move to config/ only when a second package imports them.

Acceptance criteria

  • Criterion 1: src/devops_cli/core/config_placement.py holds both checks as functions of parsed trees and a baseline mapping, with tmp_path trees proving each rule.
    Verification: Run tests in tests/test_architectural_invariants.py that use tmp_path trees to verify the new checker functions.
  • Criterion 2: test_the_source_tree_keeps_its_structural_invariants runs both checks on the trees from _parse_src() and parses nothing else, with time increase under 1s.
    Verification: Run uv run pytest tests/test_architectural_invariants.py --durations=0 and verify duration difference is within 1 second.
  • Criterion 3: The baseline is generated at the PR's base and lists names by package, with about 1,090 single-package names in 50 packages.
    Verification: Check tests/fixtures/config_placement_baseline.json contains expected structure with package groupings.
  • Criterion 4: Invariant 2's one failure is DEFAULT_SANDBOX_POLICY which is changed to use Field(default_factory=SandboxPolicy).
    Verification: Verify src/devops_cli/docker/sandbox.py:73 uses Field(default_factory=SandboxPolicy) for DEFAULT_SANDBOX_POLICY.

Key questions

  • Does the rule keep its goal?: Yes. The goal is one place to audit tables for brittleness. A query meets it better than a file: the grep above lists the 192 tables in constants.py and defaults.py and the 285 outside config/, which the file rule already misses. [sources: src/devops_cli/core/import_graph.py]
  • What counts as a package, or "subsystem", in the invariants?: The importing module's parent package directory, so commands/pr.py and commands/release.py are one package and ai/review/ is another. It follows from the file tree, with no hand-kept list of subsystems. [sources: AGENTS.md]
  • Where does a table go when two modules of one package read it?: In that package's constants.py, created when first needed, as ai/harness/constants.py already is. About 60 of the single-package names are shared this way. [sources: src/devops_cli/core/import_graph.py]
  • Baseline as names or as counts?: Names, grouped by package, in one JSON file. A count would let a new single-owner name replace a moved one unseen. Grouping by package lets the move PRs delete separate blocks without conflicting. (proposed) [sources: src/devops_cli/core/import_graph.py]
  • Do the invariants check Final?: No. 37 of the 41 names outside config/ and 587 of the 595 in defaults.py lack it. The move items add Final to each name they move, and mypy already rejects reassigning a Final name. Enforcing it now would be a 600-line annotation change with no behaviour gain. [sources: src/devops_cli/core/import_graph.py]
  • Should the 71 private-named string tables be renamed CONST_*?: No. The audit grep matches module-level upper-case names, private or not, so renaming them buys nothing. (proposed) [sources: src/devops_cli/core/import_graph.py]
  • Does this item promise fewer rebases?: No. The measured constants.py edits merge cleanly. The gain is locality and an audit that covers every table. [sources: src/devops_cli/core/import_graph.py]
  • Which names stay in config/ for good?: Those that two or more packages use (about 60 constants and 89 defaults today), names only config/ uses, and the DEFAULT_* values behind Settings fields, which refactor(config): a settings field is the one declaration, and the option, env and config-show registries become views of it #1000 keeps in defaults.py. [sources: src/devops_cli/core/import_graph.py]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/docs
    scope/config
    priority/p3-low
    scope/agent
    on Oct 2, 2026
  2. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    Consolidation (2026-10-03): the per-package moves stay separate PRs, as accepted on 2026-10-02. They are tracked with dependency links rather than sub-issues, because this item is a deliverable that lands first.

    Proposed native links, for a person to set:

    Exclusions recorded in the staged LINKS comments:

    Open key question: which one tool does every move PR use? Proposed: a libcst codemod or rope's move refactoring, chosen in the first move PR and reused after that, rather than hand edits.

    This item ships two invariant tests, the baseline and a docker/sandbox.py change, so it is not documentation-only. A person may want to relabel it from type/docs to type/refactor.

    #1006 and #1007 stay related, not dependent.


    AGENTS.md bullet shared with #1107. Lines cited at dcafadf.

    #1107 and this item edit the same AGENTS.md bullet and its template copy, but not the same lines.

    What #1107 changes

    • It replaces AGENTS.md:21-23 with one "Parse With the Library" bullet. Those lines are the "Strict Prohibition of Brittle Pattern Subsets & Mandatory Constants/Defaults Placement" heading and its two brittle-subset sub-bullets. In the template the same lines are ai/instruction_generator.py:301-303.
    • The closed-RFC-list exemption at :22 goes. Data no library can know becomes a constant with its source cited: a cloud's published metadata addresses as ipaddress objects, or a vendor's published SSH host keys as its known_hosts lines, written to ~/.ssh/known_hosts for OpenSSH to check.
    • Literal matching stays allowed for closed sets this project defines itself, such as its command names, enum values and config keys.
    • It also deletes the template's separate "Standard Parsers" bullet (:305-308).

    What #1107 leaves to this item

    Order

  3. added this to the v0.2.38 milestone on Oct 17, 2026
  4. dan-petty commented on Oct 18, 2026

    @dan-petty
    OwnerAuthor

    Status set to Ready at 25e2cda (see proposed design in issue body).

  5. removed this from the v0.2.38 milestone on Oct 20, 2026
  6. added
    status/ready
    value/medium
    effort/medium
    on Oct 28, 2026
  7. added a commit that references this issue on Oct 28, 2026
    0c2cba6
  8. removed
    status/ready
    on Oct 30, 2026
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/p3-lowscope/agentscope/configtype/docsvalue/medium

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions