Skip to content

refactor(cli): centralize settings and modernize ESM module system - #4

Merged
nicknisi merged 9 commits into
mainfrom
nicknisi/cli-improvements
Jan 17, 2026
Merged

refactor(cli): centralize settings and modernize ESM module system#4
nicknisi merged 9 commits into
mainfrom
nicknisi/cli-improvements

Conversation

@nicknisi

Copy link
Copy Markdown
Member

Summary

This PR modernizes the CLI package with a centralized configuration system and full ESM compliance. The changes reduce code duplication, improve maintainability, and remove unused legacy code.

Centralized Settings System

  • New settings.json - Single source of truth for all CLI configuration including:
    • API URLs (WorkOS, dashboard) with dev/prod variants
    • Framework-specific settings (ports, callback paths)
    • Telemetry configuration
    • Logging settings
    • Documentation URLs
    • Branding (ASCII art)
  • New settings.ts - Type-safe accessor with full TypeScript interface
  • Refactored constants.ts - Now derives values from settings instead of hardcoding

ESM Modernization

  • Switched from node16 to nodenext module resolution
  • Added explicit .js extensions to all relative imports
  • Updated to ESM-native chalk@5.4.1 (from CJS chalk@2.4.1)
  • Enabled resolveJsonModule with import attributes (with { type: 'json' })
  • Added "type": "module" to package.json
  • Replaced CJS __dirname pattern with import.meta.url

Removed Legacy Code

  • Deleted query.ts - Unused LLM query system (99 lines)
  • Removed CloudRegion and AIModel types - No longer needed
  • Removed region-specific URL functions - getHostFromRegion, getCloudUrlFromRegion, getOauthClientIdFromRegion
  • Removed unused agentResult variable from agent runner

Code Quality Improvements

  • Replaced console.error with debug() for consistent error logging
  • Added node: protocol prefix to built-in module imports in tests
  • Prefixed unused parameters with underscore (_apiKey)
  • Simplified clack-utils.ts with cleaner control flow
  • Fixed terminal width detection (process.stdout.columns guard)

Files Changed

CategoryFiles
Newsettings.json, src/lib/settings.ts
Deletedsrc/utils/query.ts
Core refactorsconstants.ts, urls.ts, debug.ts, bin.ts
ESM imports25+ files updated with .js extensions
Configtsconfig.json, package.json

Cache getSettings() at module level to avoid repeated calls, inline trivial wrapper functions, and remove unused parameters.
- Delete query.ts (replaced by Claude Agent SDK)
- Remove unused region functions from urls.ts
- Remove CloudRegion and AIModel types
- Remove CloudRegion import from clack-utils.ts
- Remove getClaudeCodeExecutablePath() using require.resolve
- Use fileURLToPath(import.meta.url) for ESM-compatible __dirname
- Fixes 'require is not defined' and '__dirname is not defined' errors
@nicknisi

Copy link
Copy Markdown
MemberAuthor
capture_20260117_100249

@nicknisi
nicknisi merged commit ca258c9 into mainJan 17, 2026
2 checks passed
@nicknisi
nicknisi deleted the nicknisi/cli-improvements branch January 17, 2026 16:03
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@nicknisi