refactor(2/3): production code simplification and cleanup - #6
Merged
Conversation
…t, buildJSONPostRequest into LLMClient.swift) and fixed TraceRecorder to use makeISO8601DateFormatter(), eliminating 5 duplication sites (3× normalizePath private methods and 2× buildRequest POST+JSON-serialization blocks) with all 5682+12 tests passing.
…liminating duplicated Process setup code (executable URL, arguments, cwd, environment merging) between launchBackgroundProcess and executeBashProcess, with all 5682+12 tests passing.
…(eliminating 6× duplicated `cwd ?? FileManager.default.currentDirectoryPath` in Agent.swift) and replaced private `stripMarkdownFences` in Compact.swift with the shared `stripCodeFences` from LLMResponseHelpers.swift, net -7 lines with all 5682+12 tests passing.
…izing the duplicated guard+validate+update pattern across 4 state transition methods (startRun, completeRun, failRun, cancelRun), and replaced 4 raw JSONEncoder()/JSONDecoder() constructions in RunPersistenceService.swift with shared makeSDKJSONEncoder()/makeSDKJSONDecoder() factories, net -10 lines with all 5682+12 tests passing.
…JSONResponse error patterns with reviewErrorResponse() helper, replacing manual Skill reconstruction with skill.withBaseDir(), and replacing manual empty-name guard with requireNonEmptyInput(), reducing the file from 125→105 lines (-20 lines) with all 5682+12 tests passing.
…t, eliminating ~35 lines of duplicated pause/resume/timeout logic between setupPauseHandler (stream) and setupPromptPauseHandler (prompt), reducing Agent.swift from 3586→3581 lines with all 5682+12 tests passing.
…rs in SandboxChecker.swift (eliminating 6 duplicated backslash/quote-stripping blocks across extractSubshellCommand and extractCommandBasename) and simplified PersistedSSEEvent.init(from:) in APITypes.swift (replacing 34-line verbose switch with 15-line nil-first-then-assign pattern), net -22 lines with all 5682+12 tests passing.
…Data, SystemData in SDKMessage.swift and OutputFormat in AgentTypes.swift) that compared all stored properties identically to what Swift synthesizes, net -35 lines with all 5682+12 tests passing.
…g 15 duplicated "store not available" guard-else-return patterns across 12 tool files into single-line try calls, net -5 lines with all 5682+12 tests passing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
9 iterations of targeted production code simplification — code cleanup, redundant code removal, and small helper extractions.
Changes
Verification
🤖 Generated with Claude Code