Skip to content

Refactor CLI architecture: modularize commands and centralize API layer#8

Merged
smorin merged 11 commits intomainfrom
claude/codebase-improvements-research-eYnwQ
Mar 11, 2026
Merged

Refactor CLI architecture: modularize commands and centralize API layer#8
smorin merged 11 commits intomainfrom
claude/codebase-improvements-research-eYnwQ

Conversation

@smorin
Copy link
Copy Markdown
Owner

@smorin smorin commented Mar 11, 2026

Summary

This PR significantly restructures the agent2linear codebase by extracting command registration logic into dedicated modules and creating a centralized API layer. The changes improve maintainability, reduce code duplication, and establish clearer separation of concerns.

Key Changes

Command Architecture Refactoring

  • Extracted command registration: Created register.ts files for each command group (config, initiatives, projects, issues, teams, members, aliases, templates, milestone-templates, workflow-states, labels, cycles, cache, colors, icons)
  • Simplified main CLI entry point: Reduced src/cli.ts from 551 lines to 69 lines by delegating command setup to registration modules
  • Consistent command structure: All command groups now follow the same registration pattern via registerXxxCommands(cli) functions

Centralized API Layer

  • New src/lib/api/ directory: Created domain-specific API modules:
    • client.ts: Singleton Linear SDK client with error handling
    • projects.ts: Project CRUD and filtering (1557 lines with performance optimizations)
    • issues.ts: Issue operations with comment support (977 lines)
    • labels.ts: Issue and project label management (431 lines)
    • members.ts: Member/user operations (342 lines)
    • workflow-states.ts: Workflow state management (247 lines)
    • teams.ts, initiatives.ts, templates.ts, cycles.ts: Entity-specific operations
    • index.ts: Barrel export for convenient importing
  • Extracted from monolithic linear-client.ts: Reduced from 4084 lines to a focused client wrapper

Testing & Validation

  • Added comprehensive test files:
    • src/lib/validators.test.ts: Validation function tests
    • src/lib/parsers.test.ts: Parser function tests
    • src/lib/error-handler.test.ts: Error handling tests

New Utilities & Commands

  • Logger module (src/lib/logger.ts): Structured logging with level support
  • Command runner (src/lib/command-runner.ts): Shared middleware for standardized error handling and alias resolution
  • New commands: whoami, doctor, issue comment
  • Cycle management: Full cycle command support with list, view, and alias sync

Configuration & Infrastructure

  • ESLint enhancement: Added eslint-plugin-simple-import-sort for import organization
  • GitHub Actions: Added CI and release workflows
  • Documentation: Added RECOMMENDATIONS.md with product and codebase improvement suggestions
  • UI reorganization: Moved WalkthroughScreen to src/ui/components/

Enhanced Features

  • Dry-run mode: Added to issue and project creation/update commands
  • Bulk operations: Support for bulk issue updates
  • Extended filtering: Added date range filters to issue list operations
  • Performance optimizations: Implemented conditional fetching and batch queries in project API to reduce API calls by 92-98%

Notable Implementation Details

  • All API modules use a consistent error handling pattern with LinearClientError
  • The centralized client uses a singleton pattern with caching for efficiency
  • Command registration functions follow a uniform structure for consistency
  • The refactoring maintains backward compatibility with existing command interfaces
  • New setLogLevel() and setNoColor() functions provide global output control

https://claude.ai/code/session_01LE3Rf4kmo1TBCozoF14LCa

claude added 11 commits March 11, 2026 04:39
Research-based analysis with two recommendation sets:
- 13 product recommendations (CLI commands, flags, UX)
- 12 codebase recommendations (architecture, testing, tooling)

Key product items: whoami, doctor, dry-run, cycles, issue comments,
bulk ops, stdin piping, column selection, help examples.

Key codebase items: split cli.ts/linear-client.ts monoliths,
consolidate caching, add unit tests, structured logging, CI/CD.

https://claude.ai/code/session_01LE3Rf4kmo1TBCozoF14LCa
Product improvements:
- Add whoami command showing authenticated user and organization info
- Add doctor command for diagnostic checks (API, config, cache, aliases)
- Add cycle list/view/sync-aliases commands
- Add issue comment subcommand
- Add --dry-run flag to issue/project create/update commands
- Add --columns flag to issue/project/members list commands
- Add date range filters (--created-after, --created-before, etc.) to issue list
- Add stdin piping support for issue create (title from stdin)
- Add bulk update support (--bulk) for issue update
- Add --no-color global flag to disable emojis
- Document no-delete design decision in README

Codebase improvements:
- Fix version mismatch (0.24.0 → 0.24.1)
- Move WalkthroughScreen.tsx to src/ui/components/
- Add GitHub Actions CI/CD workflows
- Add ESLint import ordering plugin
- Add unit tests for parsers, validators, and error handler (71 new tests)
- Add LinearClient singleton caching
- Add structured logging (logger.ts) with --quiet/--verbose flags
- Add generic fetchWithCache helper to entity cache
- Add command-runner.ts middleware for standardized error handling
- Begin splitting cli.ts into per-entity register.ts files
- Begin splitting linear-client.ts into domain API modules

https://claude.ai/code/session_01LE3Rf4kmo1TBCozoF14LCa
Continuation of cli.ts split refactoring (C1) - adds registration
modules for alias and config commands.

https://claude.ai/code/session_01LE3Rf4kmo1TBCozoF14LCa
Continuation of C1 (cli.ts split) and C2 (linear-client.ts split)
refactoring - adds issue command registration and projects API module.

https://claude.ai/code/session_01LE3Rf4kmo1TBCozoF14LCa
Adds registration modules for: colors, icons, issue-labels,
project-labels, templates, and workflow-states commands.
Completes C1 cli.ts split refactoring.

https://claude.ai/code/session_01LE3Rf4kmo1TBCozoF14LCa
Reduces cli.ts from 1831 to 176 lines by extracting command
registration into 17 dedicated register.ts files under each
command directory. Global options and top-level commands remain
in cli.ts.

https://claude.ai/code/session_01LE3Rf4kmo1TBCozoF14LCa
Reduces linear-client.ts from 4195 to 3 lines (thin re-export) by
extracting all API functions into 10 domain modules under src/lib/api/:
client, projects, issues, teams, initiatives, members, labels,
workflow-states, templates, cycles. Barrel re-export in index.ts
ensures backward compatibility for all existing imports.

https://claude.ai/code/session_01LE3Rf4kmo1TBCozoF14LCa
- Auto-fix 122 import/export sorting warnings (simple-import-sort)
- Remove unused parseAdvancedDependency import in parsers.test.ts
- Replace all 55 no-explicit-any warnings with proper types:
  - Use unknown for error handler catch parameters
  - Use specific interfaces for Commander.js options (IssueListCommandOptions, ProjectListCommandOptions)
  - Use Record<string, unknown> for generic API response objects
  - Use proper GraphQL response interfaces for raw queries
  - Type API call tracker and issue resolver parameters

https://claude.ai/code/session_01LE3Rf4kmo1TBCozoF14LCa
@smorin smorin merged commit f1db2e4 into main Mar 11, 2026
2 checks passed
@smorin smorin deleted the claude/codebase-improvements-research-eYnwQ branch March 11, 2026 06:46
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