Skip to content

refactor: apply /simplify cleanups across the codebase - #14

Merged
alexkroman merged 4 commits into
mainfrom
claude/simplify-codebase-dzf3lo
Jul 1, 2026
Merged

alexkroman merged 4 commits into
mainfrom
claude/simplify-codebase-dzf3lo

Conversation

@alexkroman

Copy link
Copy Markdown
Collaborator

Reuse / altitude:

  • Single dictation entry path: AppCoordinator.beginDictation/endDictation/
    cancelDictation shared by the key tap closures and the UI-test harness,
    replacing the hand-mirrored uiTest* copies of the missing-key gate.
  • One 16 kHz definition: SyncSTTLimits.sampleRate, referenced by MicCapture's
    recorder geometry and DictationSession's declared rate (previously two
    independent private constants).
  • Stub mics (engine tests + UITestMic) compute their canned buffer from
    SyncSTTLimits.minSamples instead of hardcoding 1600/2000, so a raised floor
    can't silently start dropping test audio.
  • UITestKeys.validAPIKey centralizes the "uitest-valid-key" sentinel used by
    AppDelegate's leak exercise and the harness window.
  • FocusCapture: shared systemFocusedElement() helper replaces the duplicated
    system-wide AX read (and its force-cast justification) in captureFieldContext
    and hasEditableFocusedElement; dropped the normalized() alias of
    trimmedNonEmpty() and its duplicate tests.
  • APIKeyStepView uses the engine's trimmedNonEmpty() rule instead of an inline
    trim; shared freshDefaults() test helper replaces two verbatim copies.
  • scripts/release-lib.sh: one sourced definition of the logging trio and the
    version helpers (is_semver, version_gt, parse_short_version,
    parse_bundle_version, parse_build_info_git_sha) that five release scripts
    each inlined; release.test.sh covers the new parse_bundle_version.

Simplification:

  • SoundStepView.displayLabel: dropped the DX-7/Juno-106 contains() chain that
    re-derived exactly what SoundPack.synth already returns.
  • StubTranscriber: Mode.transcript(String) replaces the streaming-era
    yieldChunks([String]) (every call site passed a single element).
  • TriggerKeyStore reads via TriggerKey.fromPersisted, the documented single
    decode-with-default rule, instead of re-encoding the right-cmd fallback.
  • WizardWindowController: inlined the single-caller gestureLine helper.

Coverage honesty:

  • Moved the pure meter math (meterFloorDB, linearLevel) to
    MicCapture+Meter.swift so the coverage gate counts it; MicCapture.swift
    stays excluded as the hardware-bound actor. check.sh's exclusion comment
    now describes the real layout (AVAudioRecorder, no phantom AudioDSP.swift).

Stale docs fixed: removed references to the deleted overlay auto-gain
(MicCapture, AGENTS.md), DictateHotkey.keyCaps and refreshBinding() naming in
AGENTS.md, and the "HARP 1" default in SoundPackStore's doc.

Verified here: bash -n on all scripts and scripts/release.test.sh (all pass).
Swift changes need scripts/check.sh on a Mac — this sandbox has no macOS
toolchain; CI is the authority.

Co-Authored-By: Claude Fable 5 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_012XWdVUaLE9RXmEfbuL3Lk5

claude added 2 commits July 1, 2026 21:21
Reuse / altitude:
- Single dictation entry path: AppCoordinator.beginDictation/endDictation/
  cancelDictation shared by the key tap closures and the UI-test harness,
  replacing the hand-mirrored uiTest* copies of the missing-key gate.
- One 16 kHz definition: SyncSTTLimits.sampleRate, referenced by MicCapture's
  recorder geometry and DictationSession's declared rate (previously two
  independent private constants).
- Stub mics (engine tests + UITestMic) compute their canned buffer from
  SyncSTTLimits.minSamples instead of hardcoding 1600/2000, so a raised floor
  can't silently start dropping test audio.
- UITestKeys.validAPIKey centralizes the "uitest-valid-key" sentinel used by
  AppDelegate's leak exercise and the harness window.
- FocusCapture: shared systemFocusedElement() helper replaces the duplicated
  system-wide AX read (and its force-cast justification) in captureFieldContext
  and hasEditableFocusedElement; dropped the normalized() alias of
  trimmedNonEmpty() and its duplicate tests.
- APIKeyStepView uses the engine's trimmedNonEmpty() rule instead of an inline
  trim; shared freshDefaults() test helper replaces two verbatim copies.
- scripts/release-lib.sh: one sourced definition of the logging trio and the
  version helpers (is_semver, version_gt, parse_short_version,
  parse_bundle_version, parse_build_info_git_sha) that five release scripts
  each inlined; release.test.sh covers the new parse_bundle_version.

Simplification:
- SoundStepView.displayLabel: dropped the DX-7/Juno-106 contains() chain that
  re-derived exactly what SoundPack.synth already returns.
- StubTranscriber: Mode.transcript(String) replaces the streaming-era
  yieldChunks([String]) (every call site passed a single element).
- TriggerKeyStore reads via TriggerKey.fromPersisted, the documented single
  decode-with-default rule, instead of re-encoding the right-cmd fallback.
- WizardWindowController: inlined the single-caller gestureLine helper.

Coverage honesty:
- Moved the pure meter math (meterFloorDB, linearLevel) to
  MicCapture+Meter.swift so the coverage gate counts it; MicCapture.swift
  stays excluded as the hardware-bound actor. check.sh's exclusion comment
  now describes the real layout (AVAudioRecorder, no phantom AudioDSP.swift).

Stale docs fixed: removed references to the deleted overlay auto-gain
(MicCapture, AGENTS.md), DictateHotkey.keyCaps and refreshBinding() naming in
AGENTS.md, and the "HARP 1" default in SoundPackStore's doc.

Verified here: bash -n on all scripts and scripts/release.test.sh (all pass).
Swift changes need scripts/check.sh on a Mac — this sandbox has no macOS
toolchain; CI is the authority.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012XWdVUaLE9RXmEfbuL3Lk5
Correctness (all confirmed by adversarial verification):
- DictationSession: a cancel() during transcription no longer gets repainted
  as a red .failed (and falsely reported to Datadog) when the torn-down
  URLSession request throws URLError(.cancelled) — transcribe's catch now
  leaves a claimed .cancelled phase alone. Same guard for the post-insert
  .pasted overwrite and the short-clip guard's .idle overwrite, so cancel()
  reliably keeps the phase it claims. New CancelRaceTests case drives a
  transcriber that throws on cancellation like the real one.
- AppDelegate.updatePromptHostWindow: removed the force-unwrap that crashed
  when the user closed the main window before the launch update check
  finished (the recreated scene's NSWindow only materializes a run-loop pass
  later, and no other window canBecomeMain). AutoUpdater now takes an
  optional host window, retries a beat later, and falls back to an app-modal
  alert instead of crashing.
- TranscriptionPrompt: the key-terms Keywords clause — the one input with no
  upstream length cap — is now fitted (whole terms) to the Sync API's 4096-
  character prompt cap, so a huge Settings list can't make every dictation
  fail with a 400. Cap is now a named constant, asserted in tests.
- FocusCapture.priorSlice: the caret is a UTF-16 offset (AX range domain) but
  was used in Character arithmetic, so emoji before the cursor made "prior
  text" include text after the caret. Now resolved through the UTF-16 view
  with a boundary-safe fallback; regression tests added.

Confirmed cleanup:
- Overlay: .pasted/.noTarget hover tooltips now read
  OverlayUIState.accessibilityLabel instead of drifted hard-coded copies;
  the triplicated dismiss sequence is one dismissPanel(); stale shadow-size
  comment fixed.
- BlurtIdentity.subsystem: single definition of "dev.alex.blurt", adopted by
  all five Logger/OSSignposter subsystems, the Keychain service, the
  DictationLog queue label, and Monitoring's install-id key;
  reset-install.sh comments point at the constant. Stale
  XCTOSSignpostMetric claim in DictationSession's header corrected.
- SyncSTTLimits.minSamples is a stored constant (every caller passed
  SyncSTTLimits.sampleRate to the old function parameter).
- CueSoundPlayer: the cue-chime subsystem (players, volume, prime/preview,
  recording-edge detection) extracted out of AppCoordinator's body.
- PersistedSettings.allDefaultsKeys: engine-owned roster of settings keys;
  AppDelegate's UI-test reset iterates it instead of a hand-kept list.
- AppDelegate: surfaceMainWindow() returns the window it raised (drops the
  duplicated identifier lookup); openWindowByID is captured once by the
  launch-evaluated SettingsMenuButton (two redundant onAppear re-captures
  removed).
- AssemblyAITranscriber: shared static JSONEncoder (mirrors the decoder's
  documented rationale); single-caller generic decode<T> inlined; stale
  "peak-normalizes to 0.95" comment in PCMEncoder dropped.
- release-lib.sh: require_clean_tree / require_project_version /
  tag_exists_locally / tag_exists_on_origin replace the guards hand-rolled
  across the four release scripts; dead run_xcodebuild() removed from
  check.sh.

Verified here: bash -n on all scripts and scripts/release.test.sh (pass).
Swift changes need scripts/check.sh on a Mac — no macOS toolchain in this
sandbox; CI is the authority.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012XWdVUaLE9RXmEfbuL3Lk5
@alexkroman
alexkroman enabled auto-merge July 1, 2026 22:16
claude added 2 commits July 1, 2026 22:21
…limit

The CueSoundPlayer extraction pushed the file to 402 lines and CI's
swiftlint --strict failed on file_length. Tighten the new doc comments
(no content lost) to 397 lines. Moving the class to its own file is the
better fix but needs xcodegen on a Mac to regenerate the pbxproj.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012XWdVUaLE9RXmEfbuL3Lk5
…erty

Periphery failed CI on it: the property's only consumer was the redundant
openWindowByID re-capture removed in the previous commit (the capture
lives solely in SettingsMenuButton now).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012XWdVUaLE9RXmEfbuL3Lk5
@alexkroman
alexkroman added this pull request to the merge queue Jul 1, 2026
Merged via the queue into main with commit 1f64ea5 Jul 1, 2026
6 checks passed
@alexkroman
alexkroman deleted the claude/simplify-codebase-dzf3lo branch July 1, 2026 22:52
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.

2 participants