Skip to content

refactor(2/3): production code simplification and cleanup - #6

Merged
terryso merged 9 commits into
mainfrom
refactor/2-prod-cleanup-v2
Jun 9, 2026
Merged

refactor(2/3): production code simplification and cleanup#6
terryso merged 9 commits into
mainfrom
refactor/2-prod-cleanup-v2

Conversation

@terryso

@terryso terryso commented Jun 9, 2026

Copy link
Copy Markdown
Owner

Summary

9 iterations of targeted production code simplification — code cleanup, redundant code removal, and small helper extractions.

Changes

  • gnhf 31: normalizePath → EnvUtils, buildJSONPostRequest → LLMClient
  • gnhf 32: BashTool configureBashProcess() helper
  • gnhf 33: AgentOptions.resolvedCwd computed property, Compact stripCodeFences
  • gnhf 34: RunTracker transitionRun helper, RunPersistenceService makeSDKJSON*
  • gnhf 48: SaveSkillTool cleanup (reviewErrorResponse, withBaseDir, requireNonEmptyInput)
  • gnhf 52: Agent performPauseAndWait (deduplicate pause/resume logic)
  • gnhf 53: SandboxChecker strip helpers, PersistedSSEEvent simplification
  • gnhf 54: Remove 3 redundant manual Equatable implementations
  • gnhf 56: ToolContext.requireStore() + StoreUnavailableError (centralize 15 guard patterns)

Verification

  • ✅ Zero behavioral changes — pure refactoring
  • ✅ Only public API addition: StoreUnavailableError + ToolContext.requireStore() (new, non-breaking)

🤖 Generated with Claude Code

terryso added 9 commits June 9, 2026 11:38
…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.
@terryso
terryso merged commit 28d7054 into main Jun 9, 2026
2 checks passed
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