Skip to content

chore: remove dead code and consolidate duplicated enforcement logic - #53

Merged
brendan-ch merged 4 commits into
mainfrom
chore/dead-code-simplify-audit
Jul 17, 2026
Merged

chore: remove dead code and consolidate duplicated enforcement logic#53
brendan-ch merged 4 commits into
mainfrom
chore/dead-code-simplify-audit

Conversation

@brendan-ch

Copy link
Copy Markdown
Owner

Summary

A dead-code / complexity / naming cleanup requested after an audit of the codebase, executed via spec-driven-development in 3 verified stages plus a post-review polish fix.

Dead code removed:

  • Unused LogCategory.auth and LogCategory.report enum cases (Shared/Diagnostics/LogEntry.swift) — confirmed zero non-declaration references repo-wide.

Duplication consolidated:

  • RulePolicy's hard-lock predicates now delegate to UninstallProtectionPolicy instead of reimplementing identical logic.
  • New Shared/Platform/DeviceActivityFactory.swift replaces 7 duplicated DeviceActivityEvent/DeviceActivitySchedule construction blocks across RuleScheduler, DeviceActivityMonitorExtension, and ShieldActionExtension.
  • New RuleSnapshotDTO.isEligible(kind:at:calendar:) replaces a duplicated 4-part eligibility guard across 3 LimitEnforcement handlers.

Naming over comments (per a newly added project rule — see below):

  • LogFilename.parse's magic 11/10 literals replaced with named constants.
  • RuleActivation's blockEnd renamed to currentBlockEnd, removing the comment it needed.
  • UsageReportFormatter's inline sort closure extracted into a named AppUsageRow.heaviestUsageFirst comparator.
  • New UUID.logTag extension replaces the repeated .uuidString.prefix(8) idiom and cryptic rid local (renamed ruleTag) across 8 files.
  • Two stale comments in DeviceActivityMonitorExtension.swift describing an obsolete "N=2" design corrected to describe the current N=1 design.

Project rule added (Docs/AGENT_SWIFT_GUIDELINES.md, separate commit): comments should be a relative rarity — prefer a descriptive rename first — with an explicit carve-out for the feature-spec /// doc comments, which remain required.

Verification

  • All three stages independently verified (build + full test suite) before combining, then the combined state re-verified — 397/397 passing throughout, matching the pre-change baseline exactly.
  • code-reviewer and security-reviewer (opus) both reviewed the full diff in parallel: 0 critical/high/medium findings from either. Code review flagged one LOW polish note (an implicit vs. explicit calendar: argument in ShieldActionExtension), which has been applied.
  • Merged origin/main (clean, no conflicts) and re-verified: 402/402 passing (397 + 5 new tests from main).
  • Manual UI validation: launched the built app on a simulator with the seeded scenario and confirmed Home renders correctly, exercising the refactored RuleActivation/RuleStatus derivation path. Did not drive taps through Rules/Settings interactively (no idb/Maestro-permission/computer-use path was available in-session for this run); this refactor touches zero View files, and the full XCUITest suite (which does drive those screens) passed before and after.

Test plan

  • Full unit + UI test suite passes (402/402)
  • Independent code review (opus) — approved
  • Independent security review (opus) — no issues
  • Maintainer spot-check of the RulePolicyUninstallProtectionPolicy delegation and the LimitEnforcement guard consolidation, since both touch Hard Mode / enforcement-eligibility logic (reviewed and verified equivalent by both automated reviews, but worth a human's own look given what they gate)

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com
Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com

brendan-ch and others added 4 commits July 17, 2026 14:32
Prompted by a codebase sweep for dead code and needlessly complex
patterns:

- Remove unused LogCategory.auth/.report cases and name the magic
  11/10 literals in LogFilename.parse.
- RulePolicy's hard-lock predicates now delegate to
  UninstallProtectionPolicy instead of reimplementing the same logic.
- Rename RuleActivation's blockEnd -> currentBlockEnd and extract
  UsageReportFormatter's sort into a named heaviestUsageFirst
  comparator, both replacing an explanatory comment with a
  self-documenting name.
- Add Shared/Platform/DeviceActivityFactory with
  nonRepeatingSchedule/thresholdEvents, replacing 7 duplicated
  DeviceActivityEvent/DeviceActivitySchedule construction blocks
  across RuleScheduler, DeviceActivityMonitorExtension, and
  ShieldActionExtension. Also corrects two comments describing the
  now-superseded N=2 foreground-arming design.
- Add RuleSnapshotDTO.isEligible(kind:at:calendar:) to replace a
  duplicated 4-part guard across 3 LimitEnforcement handlers, and a
  UUID.logTag extension to replace the repeated
  .uuidString.prefix(8)/`rid` idiom across 8 files.

All three stages verified independently and combined against the full
397-test suite (0 failures throughout); code-reviewer and
security-reviewer both passed with no critical/high/medium findings.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Comments should be a relative rarity; a rename is the first resort
before reaching for a comment, and naming must be unambiguous enough
for an agent reading only identifiers to infer behavior. Explicitly
exempts the feature-spec /// doc comments indexed by AGENTS.md's
"Rules feature map" — those are the behavior spec, not restatements,
and remain required.

The same rule was also added to the user's global
~/.claude/rules/common/coding-style.md (outside this repo).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@brendan-ch
brendan-ch marked this pull request as ready for review July 17, 2026 22:02
@brendan-ch
brendan-ch merged commit fba42d4 into main Jul 17, 2026
2 checks passed
@brendan-ch
brendan-ch deleted the chore/dead-code-simplify-audit branch July 17, 2026 22:03
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