Break up aggregation god-files (cli.py ~4k, operator_status ~1.9k) via per-module registration #254

Open
opened 2026-06-26 12:04:40 +02:00 by claude · 8 comments
Collaborator

Source: operator chat + architect review (claude), 2026-06-26. Companion to decision D29 (modular-monolith boundaries). Not a floor change — internal structure for context economy, not behavior.

Problem

Patchwarden is already a clean modular monolith (75 bounded stdlib-only modules). But two seams grow O(number of modules) because each new module wires itself inline:

  • cli.py (~4054 LOC) — every contract adds its add_parser + add_argument + dispatch here (+50–82 LOC per contract, observed tick-over-tick).
  • operator_status.py (~1937 LOC) — every module appends its status section here (+14–120 LOC per feature).

Why it matters (the real driver, not tidiness)

The medium-term direction (D29) is per-module ownership — a dedicated agent thread health-checking each module on a cadence. That only works if "a module" is self-contained and context-window-sized. A 4k cli.py + 1.9k operator_status.py smear every module's surface across two god-files and kill agent-context economy. Boundary test: "can one agent own this module in isolation without loading half the repo?" — today, for anything CLI- or status-facing, the answer is no.

Proposed approach

Invert the dependency to a registry/hook:

  • each module exposes register_cli(subparsers) (owns its own subparser + args + handler) and a status_contribution(...);
  • cli.py + operator_status.py become thin dispatchers (~200 LOC) iterating the registry;
  • behavior unchanged, fully test-guarded (existing suite + a registry-completeness test that asserts every module is registered exactly once);
  • incremental — one module at a time (which itself models the per-module-ownership pattern).

Priority

Below the live-lap wedge — this is enabling infra, not capability. Do incrementally/opportunistically, not as a campaign. Keep stdlib-only; no new dependencies.

Refs: decision D29; operator chat 2026-06-26.

**Source:** operator chat + architect review (`claude`), 2026-06-26. Companion to decision **D29** (modular-monolith boundaries). **Not a floor change** — internal structure for **context economy**, not behavior. ## Problem Patchwarden is already a clean modular monolith (75 bounded stdlib-only modules). But two seams grow **O(number of modules)** because each new module wires itself **inline**: - `cli.py` (~4054 LOC) — every contract adds its `add_parser` + `add_argument` + dispatch here (+50–82 LOC per contract, observed tick-over-tick). - `operator_status.py` (~1937 LOC) — every module appends its status section here (+14–120 LOC per feature). ## Why it matters (the real driver, not tidiness) The medium-term direction (D29) is **per-module ownership** — a dedicated agent thread health-checking each module on a cadence. That only works if "a module" is self-contained and context-window-sized. A 4k `cli.py` + 1.9k `operator_status.py` smear every module's surface across two god-files and **kill agent-context economy**. Boundary test: *"can one agent own this module in isolation without loading half the repo?"* — today, for anything CLI- or status-facing, the answer is no. ## Proposed approach Invert the dependency to a registry/hook: - each module exposes `register_cli(subparsers)` (owns its own subparser + args + handler) and a `status_contribution(...)`; - `cli.py` + `operator_status.py` become thin dispatchers (~200 LOC) iterating the registry; - **behavior unchanged**, fully test-guarded (existing suite + a registry-completeness test that asserts every module is registered exactly once); - **incremental** — one module at a time (which itself models the per-module-ownership pattern). ## Priority Below the live-lap wedge — this is enabling infra, not capability. Do incrementally/opportunistically, not as a campaign. Keep stdlib-only; no new dependencies. Refs: decision D29; operator chat 2026-06-26.
Collaborator

Progress update from Codex:

  • First #254 slice landed via #256 / d42023da: core-modules and core-module-stack now register through cli_core_modules.py instead of wiring parser + handler logic directly inside cli.py.
  • Added a boundary test so cli.py no longer imports core_module_registry / resolve_core_module_stack directly.
  • Full verification before merge: 1048 passed, 163 subtests passed, plus self-dogfood checks green.

Remaining #254 work: repeat this pattern for additional command families, then apply the same per-module contribution pattern to operator_status.py. Keeping this issue open.

Progress update from Codex: - First #254 slice landed via #256 / `d42023da`: `core-modules` and `core-module-stack` now register through `cli_core_modules.py` instead of wiring parser + handler logic directly inside `cli.py`. - Added a boundary test so `cli.py` no longer imports `core_module_registry` / `resolve_core_module_stack` directly. - Full verification before merge: `1048 passed, 163 subtests passed`, plus self-dogfood checks green. Remaining #254 work: repeat this pattern for additional command families, then apply the same per-module contribution pattern to `operator_status.py`. Keeping this issue open.
Collaborator

Progress update from Codex:

  • Second #254 slice landed via #257 / afbc8b33: issue-check and pr-check now register through cli_policy_checks.py instead of wiring parser + handler logic directly inside cli.py.
  • Added cli_support.py for shared CLI-only output and required-check parsing, so evaluate / contract-pr reuse the same parser without keeping policy-check handlers in the godfile.
  • Added a boundary test so cli.py no longer imports IssueInput, PullRequestInput, evaluate_issue, or evaluate_pull_request directly.
  • Full verification before merge: 1049 passed, 163 subtests passed, plus self-dogfood checks green.

Remaining #254 work: continue moving command families out of cli.py, then apply the same contribution/registration pattern to operator_status.py. Keeping this issue open.

Progress update from Codex: - Second #254 slice landed via #257 / `afbc8b33`: `issue-check` and `pr-check` now register through `cli_policy_checks.py` instead of wiring parser + handler logic directly inside `cli.py`. - Added `cli_support.py` for shared CLI-only output and `required-check` parsing, so `evaluate` / `contract-pr` reuse the same parser without keeping policy-check handlers in the godfile. - Added a boundary test so `cli.py` no longer imports `IssueInput`, `PullRequestInput`, `evaluate_issue`, or `evaluate_pull_request` directly. - Full verification before merge: `1049 passed, 163 subtests passed`, plus self-dogfood checks green. Remaining #254 work: continue moving command families out of `cli.py`, then apply the same contribution/registration pattern to `operator_status.py`. Keeping this issue open.
Collaborator

Progress update from Codex:

  • Third #254 slice landed via #258 / 5a7c127b: external-wiring-backlog-check and handoff-contracts now register through cli_external_contracts.py instead of wiring parser + handler logic directly inside cli.py.
  • Added a boundary test so cli.py no longer imports ExternalWiringBacklogInput, evaluate_external_wiring_backlog, handoff_contract_registry, or render_handoff_contract_registry directly.
  • Full verification before merge: 1050 passed, 163 subtests passed, plus self-dogfood checks green.

Remaining #254 work: continue moving command families out of cli.py, then apply the same contribution/registration pattern to operator_status.py. Keeping this issue open.

Progress update from Codex: - Third #254 slice landed via #258 / `5a7c127b`: `external-wiring-backlog-check` and `handoff-contracts` now register through `cli_external_contracts.py` instead of wiring parser + handler logic directly inside `cli.py`. - Added a boundary test so `cli.py` no longer imports `ExternalWiringBacklogInput`, `evaluate_external_wiring_backlog`, `handoff_contract_registry`, or `render_handoff_contract_registry` directly. - Full verification before merge: `1050 passed, 163 subtests passed`, plus self-dogfood checks green. Remaining #254 work: continue moving command families out of `cli.py`, then apply the same contribution/registration pattern to `operator_status.py`. Keeping this issue open.
Collaborator

Progress update: merged PR #261 (9671df162a58) as another #254 slice.

Done in this slice:

  • moved the artifact-root manifest CLI family into src/patchwarden/cli_artifact_roots.py;
  • left cli.py as a registration consumer for those commands;
  • added a boundary test plus architecture inventory entry;
  • verified 1052 passed, 163 subtests passed before merge.

Remaining #254 scope: continue splitting the larger aggregation surfaces, especially operator_status, into per-module registration/inventory pieces.

Progress update: merged PR #261 (`9671df162a58`) as another #254 slice. Done in this slice: - moved the artifact-root manifest CLI family into `src/patchwarden/cli_artifact_roots.py`; - left `cli.py` as a registration consumer for those commands; - added a boundary test plus architecture inventory entry; - verified `1052 passed, 163 subtests passed` before merge. Remaining #254 scope: continue splitting the larger aggregation surfaces, especially `operator_status`, into per-module registration/inventory pieces.
Collaborator

Progress update: merged PR #262 (4041524459c0) as the next #254 slice.

Done in this slice:

  • moved patchwarden.operator_dashboard_read_model.v1 construction into src/patchwarden/operator_dashboard_read_model.py;
  • kept operator_status.py as the status SSoT and renderer entry point;
  • added a boundary test so dashboard counters/maturity helpers do not drift back into operator_status.py;
  • updated architecture inventory;
  • verified 1053 passed, 163 subtests passed plus green self Forgejo checks before exact-head merge.

Remaining #254 scope: continue shrinking operator_status.py by moving additional status contributions/artifact drilldowns toward per-module registration.

Progress update: merged PR #262 (`4041524459c0`) as the next #254 slice. Done in this slice: - moved `patchwarden.operator_dashboard_read_model.v1` construction into `src/patchwarden/operator_dashboard_read_model.py`; - kept `operator_status.py` as the status SSoT and renderer entry point; - added a boundary test so dashboard counters/maturity helpers do not drift back into `operator_status.py`; - updated architecture inventory; - verified `1053 passed, 163 subtests passed` plus green self Forgejo checks before exact-head merge. Remaining #254 scope: continue shrinking `operator_status.py` by moving additional status contributions/artifact drilldowns toward per-module registration.
Collaborator

Progress update: merged PR #263 (c2b505096a93) as another #254 slice.

Done in this slice:

  • moved the operator status artifact drilldown catalog into src/patchwarden/operator_artifact_drilldowns.py;
  • kept operator_status.py as the status SSoT and renderer entry point;
  • reduced operator_status.py to 1424 lines in this worktree after the split;
  • added a boundary test so _artifact_drilldowns does not drift back into operator_status.py;
  • updated architecture inventory;
  • verified 1054 passed, 163 subtests passed plus green self Forgejo checks before exact-head merge.

Remaining #254 scope: continue converting the remaining status payload sections into per-module contributions/registries.

Progress update: merged PR #263 (`c2b505096a93`) as another #254 slice. Done in this slice: - moved the operator status artifact drilldown catalog into `src/patchwarden/operator_artifact_drilldowns.py`; - kept `operator_status.py` as the status SSoT and renderer entry point; - reduced `operator_status.py` to 1424 lines in this worktree after the split; - added a boundary test so `_artifact_drilldowns` does not drift back into `operator_status.py`; - updated architecture inventory; - verified `1054 passed, 163 subtests passed` plus green self Forgejo checks before exact-head merge. Remaining #254 scope: continue converting the remaining status payload sections into per-module contributions/registries.
Collaborator

Progress update: merged PR #264 (451ed88909f4) as another #254 slice.

Done in this slice:

  • moved the external wiring backlog catalog and source-command enrichment into src/patchwarden/operator_external_wiring_backlog.py;
  • removed external_wiring.py's dependency on operator_status.py;
  • reduced operator_status.py to 1266 lines in this worktree after the split;
  • added a boundary test that keeps EXTERNAL_WIRING_BACKLOG out of operator_status.py and keeps the checker importing the catalog directly;
  • updated architecture inventory;
  • verified 1055 passed, 163 subtests passed plus green self Forgejo checks before exact-head merge.

Remaining #254 scope: continue converting remaining status payload sections, especially dogfood wedge/status contribution data, into per-module contributions or registries.

Progress update: merged PR #264 (`451ed88909f4`) as another #254 slice. Done in this slice: - moved the external wiring backlog catalog and source-command enrichment into `src/patchwarden/operator_external_wiring_backlog.py`; - removed `external_wiring.py`'s dependency on `operator_status.py`; - reduced `operator_status.py` to 1266 lines in this worktree after the split; - added a boundary test that keeps `EXTERNAL_WIRING_BACKLOG` out of `operator_status.py` and keeps the checker importing the catalog directly; - updated architecture inventory; - verified `1055 passed, 163 subtests passed` plus green self Forgejo checks before exact-head merge. Remaining #254 scope: continue converting remaining status payload sections, especially dogfood wedge/status contribution data, into per-module contributions or registries.
Collaborator

Progress update: merged PR #265 (24f6d9bf0c69) as another #254 slice.

Done in this slice:

  • moved the dogfood wedge status contribution into src/patchwarden/operator_dogfood_wedge.py;
  • kept operator_status.py as the status SSoT and renderer entry point;
  • reduced operator_status.py to 1216 lines in this worktree after the split;
  • added a boundary test so _dogfood_wedge does not drift back into operator_status.py;
  • updated architecture inventory;
  • verified 1056 passed, 163 subtests passed plus green self Forgejo checks before exact-head merge.

Remaining #254 scope: continue converting the remaining inline status payload sections, especially protection/passsage-layer catalogs, into per-module contributions or registries.

Progress update: merged PR #265 (`24f6d9bf0c69`) as another #254 slice. Done in this slice: - moved the dogfood wedge status contribution into `src/patchwarden/operator_dogfood_wedge.py`; - kept `operator_status.py` as the status SSoT and renderer entry point; - reduced `operator_status.py` to 1216 lines in this worktree after the split; - added a boundary test so `_dogfood_wedge` does not drift back into `operator_status.py`; - updated architecture inventory; - verified `1056 passed, 163 subtests passed` plus green self Forgejo checks before exact-head merge. Remaining #254 scope: continue converting the remaining inline status payload sections, especially protection/passsage-layer catalogs, into per-module contributions or registries.
Sign in to join this conversation.
No labels
agent/claude-code
agent/codex
agent/gemini
agent/hermes
agent/iskra
agent/ollama
agent/patchwarden
area:business-model
area:competitive
area:discovery
area:forgejo
area:metrics
area:product-strategy
area:v0-core
cagan-grade-approved
client:platform
dependency/blocked
dependency/blocks-others
dependency/cross-repo
dependency/needs-confirmation
domain:agents
domain:ci
domain:docs
domain:forgejo
domain:infra
domain:memory
domain:runtime
domain:signal
domain:ux
flow/architecture
flow/blocked
flow/deployed
flow/done
flow/implementation
flow/intake
flow/maintained
flow/observed
flow/ready
flow/refining
flow/retired
flow/review
judge/codex-candidate
judge/hermes-candidate
judge/low-confidence
judge/needs-refinement
judge/operator-needed
judge/p0
judge/p1
judge/p2
judge/p3
judge/park
judge/patchwarden-candidate
judge/stale-priority
kind/adr
kind/bug
kind/chore
kind/feature
kind/infra
kind/ops
kind/refactor
kind/research
kind:artifact
kind:decision
kind:dogfood
kind:epic
kind:implementation
kind:research
merge/auto
merge/manual
merge/manual-dependency-conflict
merge/manual-failing-tests
merge/manual-merge-conflict
merge/manual-missing-review
merge/manual-operator-preference
merge/manual-red-zone
merge/manual-security-sensitive
merge/manual-unclear-scope
merge/manual-unknown
mode:operator-only
mode:patchwarden-iskra-approved
mode:safe-auto
observed/erroring
observed/needs-followup
observed/pending
observed/retire-candidate
observed/unused
observed/used
priority:p0
priority:p1
priority:p2
priority:p3
ready-for-agent
review:claude-reviewed
review:codex-reviewed
review:dziadek-reviewed
review:needs-human
safety:external-write
safety:no-prod-mutation
safety:prod-impact
safety:secret-touch
size/large
size/medium
size/small
size/tiny
size/unknown
source/adr
source/agent-generated
source/manual
source/operator-chat
source/voice-note
status:blocked
status:blocked-on-discovery
status:cagan-grade-review-pending
status:codex-ready
status:merged:pending-evidence
status:needs-evidence
status:needs-operator-decision
status:operator-needed
status:parked
tier:0-anchor
tier:0-platform-substrate
tier:1-core
tier:1-iskra-value-layer
tier:2-supporting
tier:2-tools-products-modules
type:bug
type:chore
type:docs
type:feat
type:policy
type:research
wave:1-foundation
wave:2-positioning
wave:3-validation
wave:4-economics
wave:5-operating
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
pdurlej/patchwarden#254
No description provided.