Skip to content

refactor(cli): deepen the command layer — retention sweep + relocate policy prompt#141

Merged
allisson merged 3 commits into
mainfrom
improve-codebase
May 28, 2026
Merged

refactor(cli): deepen the command layer — retention sweep + relocate policy prompt#141
allisson merged 3 commits into
mainfrom
improve-codebase

Conversation

@allisson

Copy link
Copy Markdown
Owner

Summary

Two deepenings in the CLI command layer, each turning shallow/misplaced modules into deep, well-located ones. Informed by an architecture review; both follow the project's existing deepening campaign (#136#139).

1. Collapse six retention-sweep commands into one deep module

purge-secrets, purge-transit-keys, purge-tokenization-keys, clean-expired-tokens, clean-audit-logs, and purge-auth-tokens each re-typed the same shape (a Result struct, ToText/ToJSON, and a Run* doing validate → log → track → output), diverging only in noun, metric label, and one usecase method. Their ToJSON was byte-identical.

  • New RunRetentionSweep + SweepSpec own the machinery once; each command supplies a SweepSpec with a Sweep closure adapting its differently-named usecase method (PurgeDeleted, CleanupExpired, DeleteOlderThan, PurgeExpiredAndRevoked).
  • Bug fixed: audit-log cleanup now flows through metrics.Track like every other sweep (it was previously untracked — drift).
  • auth-token purge keeps its no-dry-run notice via SupportsDryRun=false.
  • User-facing output preserved via per-spec verb/subject strings.
  • Six per-command test files collapse into one table-driven test.
  • New retention sweep concept recorded in CONTEXT.md.

2. Relocate the policy-prompt module out of internal/ui

The interactive policy-prompt helpers lived in an infrastructure package that did terminal I/O and imported auth/domain, yet were used only by the client CLI commands. Moved to cmd/app/commands beside their only callers; deleted the now-empty internal/ui. Pure move — same logic, same tests; the infra→domain import direction is gone.

Net effect

  • ~1.4k lines of duplicated/misplaced code removed; one deep module + one table-driven test added.
  • No behaviour change except: audit-log cleanup is now metered, and the auth-token dry-run notice wording is slightly clearer.

Validation

  • make test — race-enabled, all packages PASS
  • make lint — golangci-lint 0 issues, govulncheck no vulnerabilities
  • go build ./... — clean

🤖 Generated with Claude Code

allisson and others added 3 commits May 28, 2026 15:44
…dule

The purge-* and clean-* commands each re-typed the same shape — a
Result struct, ToText/ToJSON, and a Run* with validate → log → track →
output — diverging only in noun, metric label, and one usecase method.
Their ToJSON was byte-identical across all six.

Introduce RunRetentionSweep + SweepSpec, a single deep module that owns
the sweep machinery. Each command supplies a SweepSpec (verb, subject,
metric labels, dry-run support, and a Sweep closure adapting its usecase
method). The differently-named usecase methods (PurgeDeleted,
CleanupExpired, DeleteOlderThan, PurgeExpiredAndRevoked) are adapted by
closure, so no shared interface is needed.

- audit-log cleanup now flows through metrics.Track like every other
  sweep (previously untracked — drift, now fixed).
- auth-token purge keeps its no-dry-run notice via SupportsDryRun=false.
- user-facing output is preserved via per-spec verb/subject strings.

The six per-command test files collapse into one table-driven test on
RunRetentionSweep. Records the concept in CONTEXT.md.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…al/ui

The interactive policy-prompt functions (PromptForPolicies,
PromptForPoliciesUpdate, ParseCapabilities) lived in internal/ui — an
infrastructure package doing terminal I/O and importing auth/domain, yet
used only by the create-client and update-client CLI commands.

Relocate them to cmd/app/commands (package commands) beside their only
callers and delete the now-empty internal/ui package. Pure move: same
logic, same tests, same behaviour. The seam now lives where the
behaviour does, and the infra→domain import direction is gone.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ric fix

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@allisson allisson merged commit 06ac1d3 into main May 28, 2026
3 checks passed
@allisson allisson deleted the improve-codebase branch May 28, 2026 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant