Skip to content

refactor: Tech debt cleanup and code quality improvements#31

Merged
eyelock merged 14 commits into
mainfrom
refactor/tech-debt
Jan 15, 2026
Merged

refactor: Tech debt cleanup and code quality improvements#31
eyelock merged 14 commits into
mainfrom
refactor/tech-debt

Conversation

@eyelock
Copy link
Copy Markdown
Owner

@eyelock eyelock commented Jan 15, 2026

Summary

This PR addresses accumulated tech debt and improves code quality across the codebase:

Architecture Improvements:

  • Extract shared models and generic installer (phase 1)
  • Extract TabManager and BoardPersistence from viewmodel (phase 2)
  • Extract TerminalThemeManager from TerminalSessionManager
  • Extract reusable UI components from large view files
  • Add Constants file to consolidate magic values

MCP Server Improvements:

  • Add type-safe JSON Schema builder DSL
  • Add centralized input validation layer

Testing:

  • Add resource and prompt handler tests with coverage target
  • Improve test coverage for shared models and validation

Documentation:

  • Add code style guide from tech debt cleanup
  • Add error handling guidelines
  • Add memory management patterns

Housekeeping:

  • Add missing build artifacts to gitignore

Test plan

  • Manual smoke testing completed
  • CI passes (automated checks)
  • All existing tests pass

🤖 Generated with Claude Code

David Collie and others added 14 commits January 15, 2026 08:08
- Create TermQShared target with Sendable domain models (Tag, Column, Card, Board)
- Add shared OutputTypes (TerminalOutput, ColumnOutput, PendingOutput, ErrorOutput)
- Add shared BoardLoader for consistent board loading/writing across CLI and MCP
- Extract generic ComponentInstaller protocol to eliminate CLI/MCP installer duplication
- Migrate termq-cli to use TermQShared (remove ~200 lines of duplicate models)
- Migrate MCPServerLib to use TermQShared with type aliases for compatibility
- Add TermQSharedTests for shared model coverage

Net reduction: ~1000 lines of duplicated code

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Split BoardViewModel from 768 to 441 lines by extracting:

- TabManager: Session tab state, navigation, attention indicators, transient cards
- BoardPersistence: Save/load operations, file monitoring for external changes
- FileMonitor: Helper class for dispatch source-based file monitoring

BoardViewModel now coordinates these managers while maintaining backwards
compatible API through proxy properties and methods.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Phase 3 of tech debt cleanup - split the TerminalSessionManager god object
by extracting theme management into a dedicated TerminalThemeManager class.

Changes:
- Create TerminalThemeManager for theme state and application logic
- TerminalSessionManager now delegates theme operations to themeManager
- Proxy properties maintain API compatibility (themeId, currentTheme)
- Theme callback mechanism for applying changes to all sessions

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Improve test coverage from 66% to 78%:
- Add testResource* tests for all MCP resource handlers (terminals, columns, pending, context)
- Add testPrompt* tests for all MCP prompt handlers (session_start, workflow_guide, terminal_summary)
- Add test.coverage Makefile target for easy coverage reporting

Coverage improvements:
- ResourceHandlers.swift: 0% → 95%
- PromptHandlers.swift: 0% → 94%

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Create .claude/commands/code-style.md capturing patterns learned:
- Swift 6 Sendable conformance patterns
- Actor-isolated class with dispatch source helpers
- God object decomposition strategy
- Init order with callback configure() pattern
- Generic type extraction for code deduplication
- Observable vs Sendable model separation
- MCP testing patterns with type extraction helpers
- Refactoring checklist for future upgrades

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Extract MCPStatusView from ContentView (23 lines)
- Extract SafePasteAnalyzer from TerminalHostView (63 lines)
- Extract LLMVendor enum from CardEditorView (54 lines)

Addresses Issue #6 from forensic code review.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Create Constants.swift with Shell, Terminal, Columns, ColorPalette,
  LLMTokens, and Activity configuration constants
- Update TerminalSessionManager to use Terminal and Activity constants
- Update ColumnEditorView to use ColorPalette constants
- Update ContentView to use Columns.fallbackName constant

Addresses Issue #7 from forensic code review.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Define context-specific patterns for CLI, MCP, ViewModels, and file ops
- Document when to use try?, throw, or return isError
- Add typed error definition examples
- List errors that should never be silently ignored
- Update refactoring checklist with error handling items

Addresses Issue #9 from forensic code review.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Create SchemaBuilder enum with type-safe property definitions
- Add convenience methods: string(), bool(), int() for common types
- Refactor SchemaDefinitions to use builder pattern
- Replace verbose nested dictionary literals with clean DSL syntax

Example:
  inputSchema: S.objectSchema([
      S.string("identifier", "Terminal name or UUID", required: true),
      S.string("column", "Target column name", required: true),
  ])

Addresses forensic review Issue #10.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Create InputValidator enum with type-safe parameter extraction
- Add validation methods: requireString, requireNonEmptyString, requireUUID
- Add optional extractors: optionalString, optionalBool, optionalUUID, optionalPath
- Define ValidationError enum with descriptive error messages
- Refactor all MCP tool handlers to use centralized validation
- Consistent error handling: return isError:true instead of throwing

Benefits:
- Type-safe parameter extraction reduces runtime errors
- Consistent error messages improve LLM experience
- Path validation with tilde expansion
- UUID format validation with clear error messages

Addresses forensic review Issue #11.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Audit findings:
- No actual memory leaks found in codebase
- All closures properly use [weak self] where needed
- Event monitors have cleanup in onDisappear
- Timers and dispatch sources cleaned up in deinit
- Callback-based coordination avoids retain cycles

Documentation added:
- Closure capture rules for classes vs structs
- Event monitor cleanup pattern
- Timer/dispatch source cleanup
- Callback-based coordination guidance
- Checklist item for memory management

Addresses forensic review Issue #12.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add comprehensive InputValidator tests (93% line coverage)
- Add TermQError error description tests (100% coverage)
- Add ColumnOutput, PendingOutput, PendingSummary tests
- Add SetResponse and MoveResponse tests
- Fix test assertions for order-independent badge comparisons
- Fix path validation tests for trailing slash normalization

Total coverage improved from ~75% to ~80% lines.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add termqcli and TermQ_TermQ.bundle to gitignore - these are
generated during the build process and shouldn't be tracked.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
NSAlert requires main actor isolation in Xcode 16.4+ with stricter
Swift concurrency checking. Add @mainactor annotation to satisfy
the compiler's concurrency requirements.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@eyelock eyelock merged commit 17675d3 into main Jan 15, 2026
5 checks passed
@eyelock eyelock deleted the refactor/tech-debt branch January 15, 2026 13:24
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