Commit Graph
234 Commits
Author SHA1 Message Date
kaitranntt 418d121577 feat(cli): add --preset option to ccs api create command
- add provider-presets.ts with OpenRouter/GLM/GLMT/Kimi configs
- add --preset flag for quick profile creation
- auto-fill name, base URL, model from preset
- show preset info and API key hints
- update help with preset documentation and examples
2025-12-20 19:49:50 -05:00
kaitranntt d193626e3b feat(cli): add interactive OpenRouter model picker for api create
- add openrouter-catalog.ts with fetcher and 24h file cache

- add openrouter-picker.ts with interactive search UI

- detect OpenRouter URL in api-command.ts handleCreate()

- offer interactive browse when no --model flag provided

- support tier mapping configuration (opus/sonnet/haiku)
2025-12-20 18:31:40 -05:00
kaitranntt 4a5b832a6e refactor: remove unused deprecated code
- remove hasMcpWebSearch(), getMcpConfigPath() from websearch-manager

- delete deprecated web-server/routes.ts (no imports)
2025-12-19 16:02:39 -05:00
kaitranntt bae323c0d3 refactor(web-server): extract usage module to usage/ directory
- create web-server/usage/ with 7 focused modules

- extract: types, disk-cache, data-aggregator, aggregator, handlers, routes

- original files now re-export for backward compatibility

- slim routes.ts (49 lines) delegates to handlers.ts (489 lines)
2025-12-19 16:02:18 -05:00
kaitranntt c1e5ec70b5 refactor(utils): modularize ui.ts into ui/ directory
- split 647-line ui.ts into 10 focused modules (<115 lines each)

- extract: colors, indicators, boxes, tables, text, spinner, tasks

- add init.ts for shared state and types.ts for interfaces

- ui.ts now re-exports from ui/index.ts for backward compat
2025-12-19 16:01:50 -05:00
kaitranntt 6372b3d303 refactor: add barrel exports to api/, glmt/, management/
- src/api/index.ts: re-export services module

- src/glmt/index.ts: export all GLMT transformers and pipeline

- src/management/index.ts: export doctor, managers, diagnostics, checks, repair
2025-12-19 16:01:22 -05:00
kaitranntt 99afb3e011 refactor(utils): remove deprecated color and error functions from helpers.ts
- remove getColors(), colors, colored(), getTerminalInfo()

- keep error(), expandPath(), levenshteinDistance(), findSimilarStrings()

- reduce file from 155 to 92 lines (-63 lines)
2025-12-19 15:40:04 -05:00
kaitranntt e1f135a93a refactor(utils): extract formatRelativeTime to utils/time.ts
- create utils/time.ts for centralized time formatting

- remove duplicate from auth/commands/types.ts

- re-export for backward compatibility

- export from utils/index.ts
2025-12-19 15:39:40 -05:00
kaitranntt 18424cba89 refactor(utils): use canonical ValidationResult from types/utils
- import ValidationResult from types/utils

- create DelegationValidationResult extending base type

- standardize on 'valid' property naming
2025-12-19 15:39:19 -05:00
kaitranntt a8f7dad4e3 refactor(websearch): unify CLI status types with ComponentStatus
- replace GeminiCliStatus, GrokCliStatus, OpenCodeCliStatus with type aliases

- use ComponentStatus from types/utils as single source of truth

- fix null vs undefined for optional fields
2025-12-19 15:38:57 -05:00
kaitranntt 6c78b63908 refactor(types): add generic types and consolidate ExecutionResult
- add OperationResult<T> for success/failure patterns

- add ComponentStatus for CLI tool statuses

- add ValidationResult for validation patterns

- remove duplicate ExecutionResult, re-export from executor/types
2025-12-19 15:38:31 -05:00
kaitranntt 50c427d339 refactor: add barrel exports for commands and utils directories
- src/commands/index.ts exports all command handlers

- src/utils/index.ts exports common utilities
2025-12-19 12:36:43 -05:00
kaitranntt 0341f4f86f refactor(auth): modularize auth-commands into commands/ directory
- extract create, list, show, remove, default command handlers

- extract types.ts with CommandContext and parseArgs

- slim auth-commands.ts from 725 to 235 lines (68% reduction)

- add barrel exports at commands/index.ts and auth/index.ts
2025-12-19 12:36:24 -05:00
kaitranntt c3baaa8251 refactor(delegation): modularize headless-executor into executor/ directory
- extract types, stream-parser, result-aggregator

- consolidate ExecutionResult to executor/types.ts (DRY)

- slim headless-executor.ts from 729 to 391 lines (46% reduction)

- add barrel exports at executor/index.ts and delegation/index.ts
2025-12-19 12:35:59 -05:00
kaitranntt 5e4fa200df refactor(utils): modularize websearch-manager into websearch/ directory
- extract gemini-cli, grok-cli, opencode-cli providers

- extract hook-config, hook-env, hook-installer, status, types

- slim websearch-manager.ts from 867 to 103 lines (88% reduction)

- add barrel export at websearch/index.ts
2025-12-19 12:35:37 -05:00
kaitranntt c1f30ae800 refactor(web-server): modularize health-service into health/ directory
- extract system, environment, config, profile, symlink checks

- extract cliproxy, oauth, websearch checks and types

- slim health-service.ts from 901 to 146 lines (84% reduction)

- add barrel export at health/index.ts
2025-12-19 12:35:13 -05:00
kaitranntt d3c94fe6a2 refactor(cliproxy): modularize binary-manager into binary/ directory
- extract types, version-checker, lifecycle, updater, installer

- extract downloader (verifier), extractors (tar, zip), version-cache

- slim binary-manager.ts from 1080 to 137 lines (87% reduction)

- add barrel export at binary/index.ts
2025-12-19 12:34:48 -05:00
kaitranntt b49b7d17b2 refactor(cliproxy): extract service layer from cliproxy-command
- create cliproxy/services/ with 6 modules (1179 → 634 lines)

- variant-service, variant-settings, variant-config-adapter

- proxy-lifecycle-service, binary-service

- separate CLI parsing from business logic

Phase 5: Command Refactor (cliproxy-command.ts)
2025-12-19 11:48:45 -05:00
kaitranntt ecb6bb448a refactor(api): extract service layer from api-command
- create api/services/ with 5 modules (800 → 426 lines)

- validation-service, profile-types, profile-reader, profile-writer

- separate CLI parsing from business logic

Phase 5: Command Refactor (api-command.ts)
2025-12-19 11:48:33 -05:00
kaitranntt 5c28935d1e refactor(cliproxy): modularize auth handler and binary
- extract 6 auth modules to auth/ directory (932 → 65 lines)

- oauth-handler, oauth-process, token-manager

- environment-detector, auth-types

- extract binary/ with downloader, verifier modules

Phase 3: Large Files Breakdown (auth-handler.ts)
2025-12-19 11:48:21 -05:00
kaitranntt cd107e354c refactor(glmt): modularize transformer pipeline
- extract 7 pipeline modules (1122 → 206 lines)

- request-transformer, stream-parser, response-builder

- tool-call-handler, content-transformer

- shared types.ts for pipeline interfaces

Phase 3: Large Files Breakdown (glmt-transformer.ts)
2025-12-19 11:48:07 -05:00
kaitranntt 0eb2030dc2 refactor(management): modularize doctor health checks
- extract 9 check modules to checks/ directory (1260 → 186 lines)

- add repair/ directory with auto-repair extraction

- system, env, config, profile, cliproxy, oauth, symlink checks

- shared types.ts for check result interfaces

Phase 3: Large Files Breakdown (doctor.ts)
2025-12-19 11:47:55 -05:00
kaitranntt 22dbfd91c5 refactor(errors): centralize error handling infrastructure
- add errors/ directory with error types, handler, cleanup registry

- extract claude-spawner.ts from auth modules

- update imports across auth, ccs, web-server

Phase 2 & 4: Error handling consolidation
2025-12-19 11:47:43 -05:00
kaitranntt 9346ff2be9 refactor(web-server): extract usage aggregator service
- extract usage-aggregator.ts from usage-routes.ts (883 → 188 lines)

- add services/ directory with barrel export

- separate data aggregation logic from route handlers

Phase 2: Duplicate Extraction
2025-12-19 11:47:30 -05:00
kaitranntt a12c3d800a refactor(web-server): modularize routes into dedicated files
- extract 14 route modules from monolithic routes.ts (2198 → 49 lines)

- add route-helpers.ts for shared utilities

- add index.ts barrel export for clean imports

- health, profile, config, settings, provider, copilot routes

- variant, proxy, cliproxy-auth, cliproxy-stats, websearch, misc routes

Phase 1: Routes Modularization
2025-12-19 11:47:19 -05:00
Kai (Tam Nhu) TranandGitHub af814aeee8 Merge pull request #153 from kaitranntt/kai/fix/cliproxy-port-race
fix(cliproxy): prevent port race condition with unified detection and startup lock
2025-12-19 10:54:11 -05:00
kaitranntt 2d2cd3eca2 feat(recovery): add lazy initialization for bun/pnpm users
Bun and pnpm block postinstall scripts by default for security.
This causes ~/.ccs/ directory to not be created on fresh install.

Added lazy initialization in RecoveryManager that mirrors postinstall.js:
- ensureSharedDirectories() - creates ~/.ccs/shared/ subdirs
- ensureGlmSettings() - creates glm.settings.json with defaults
- ensureGlmtSettings() - creates glmt.settings.json with thinking mode
- ensureKimiSettings() - creates kimi.settings.json with k2-thinking-turbo
- ensureShellCompletions() - installs completion files
- Fixed config.json to include glmt profile, removed deprecated default

Now any ccs command will auto-create full ~/.ccs/ structure on first run.

Fixes: bun add -g @kaitranntt/ccs not creating ~/.ccs/
2025-12-19 10:50:52 -05:00
kaitranntt 96f17e3afb fix(cliproxy): prevent port race condition with unified detection and startup lock
Add proxy-detector.ts for unified detection with multiple fallbacks:
- HTTP health check (most reliable)
- Session lock file check
- Port process detection with HTTP retry (handles Windows PID-XXXXX)

Add startup-lock.ts for file-based mutex:
- 10s timeout with 20 retries at 250ms intervals
- Stale lock detection via PID check
- Cross-platform support

Update cliproxy-executor.ts and service-manager.ts to use new modules.

Fixes race conditions when running simultaneous ccs commands.
2025-12-19 10:50:25 -05:00
kaitranntt 2373100c17 fix(web-server): add comprehensive reserved name validation
- Import isReservedName from centralized reserved-names module
- Add validation to POST /api/profiles endpoint
- Add validation to POST /api/cliproxy/openai-compat endpoint
- Refactor hardcoded arrays to use centralized isReservedName()
- Fixes DRY violation and ensures consistent validation across all endpoints
2025-12-19 09:55:27 -05:00
kaitranntt 7ea64bdb43 fix(cliproxy): prevent variant names matching reserved provider names
Added validation to reject variant names that match reserved CLIProxy
provider names (gemini, codex, agy, qwen, iflow). Also protected reserved
provider settings files from being deleted when deleting variants.

This prevents accidental deletion of default provider configurations when
users create variants with conflicting names.
2025-12-19 09:49:05 -05:00
kaitranntt 598454c931 fix(cliproxy): include BASE_URL and AUTH_TOKEN when applying presets
Presets now always include ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN
when applied to provider settings. This ensures CLIProxy routing works
correctly for Gemini, Codex, and Agy providers.

Also fixes settings save failing for new profiles by changing PUT
/api/settings/:profile to upsert behavior (create if not exists).
2025-12-19 09:44:14 -05:00
kaitranntt 68eab562ce feat(env): add debug logging for global env injection
- log injected global env var names in debug mode (CCS_DEBUG)

- log when telemetry/reporting env vars are applied in CLIProxy
2025-12-19 07:58:19 -05:00
kaitranntt b6b18173cc fix(update-checker): resolve dev channel update and duplicate comments
Fixes tag-agnostic cache issue causing 'ccs update --dev' to require
force. Implements tag-specific caching (dev_version vs latest_version)
to correctly detect updates across channels. Disables duplicate bot
comments on dev releases in .releaserc.cjs.
2025-12-19 04:50:09 -05:00
kaitranntt 03aea4eac2 fix(remote-proxy): fix TypeError and make port optional with protocol defaults
- Fix TypeError: error.code?.toLowerCase - add type guard for non-string error codes
- Make remote proxy port optional - defaults to 443 (HTTPS) or 80 (HTTP)
- Smart URL building - omits port when using protocol default
- UI improvements - show default port hint, allow empty port field
- Better validation - only host is required, port uses smart defaults

Closes #142
2025-12-19 04:23:20 -05:00
kaitranntt a3b172cc43 fix(cliproxy): register session on dashboard start and add port-based stop fallback
Dashboard Stop/Update buttons failed with contradictory errors:
- Stop: "No active CLIProxy session found"
- Update: "CLIProxy was already running"

Root cause: service-manager spawned proxy but never called registerSession(),
so stopProxy() couldn't find the lock file.

Changes:
- service-manager.ts: Add registerSession() after spawn
- session-tracker.ts: Make stopProxy() async with port-based fallback
- routes.ts: Update proxy-stop endpoint to async
- cliproxy-command.ts: Update handleStop() to await async stopProxy()
- port-utils.ts: Fix double-escaped regex for Windows port detection
- session-tracker.test.js: Update tests for async stopProxy()
2025-12-19 03:57:06 -05:00
kaitranntt 903bc10fea fix(profiles): prevent env var inheritance for settings-based profiles
- Load settings file and explicitly inject ANTHROPIC_* env vars
- Prevents stale CLIProxy env vars from overriding settings file values
- Fixes GLM/Kimi requests incorrectly routing through CLIProxyAPI
2025-12-19 02:40:29 -05:00
kaitranntt 8d8d4c248a refactor: rename proxy to cliproxy_server and update API routes 2025-12-19 02:14:49 -05:00
kaitranntt 196422cee1 docs(cliproxy): add remote proxy documentation
- add proxy CLI flags section to help command output

- add proxy environment variables section to help

- add Remote Proxy section to README with config examples

- document CLI flag overrides and priority resolution
2025-12-19 01:18:05 -05:00
kaitranntt 8decdfb515 feat(web-server): add proxy configuration API routes
- GET /api/proxy returns current proxy config

- PUT /api/proxy updates proxy settings in config.yaml

- POST /api/proxy/test tests remote connection

- register routes in web server index
2025-12-19 01:16:10 -05:00
kaitranntt bd1ff2f059 feat(cliproxy): integrate remote proxy mode in executor
- resolve proxy config with CLI flags, ENV vars, and config.yaml

- check remote proxy health before skipping local binary spawn

- implement TTY-aware fallback prompting when remote unreachable

- support --remote-only flag to disable fallback

- use remote or local env vars based on mode
2025-12-19 01:15:33 -05:00
kaitranntt f4a50d006c feat(cliproxy): add getRemoteEnvVars for remote proxy mode
- generate environment variables for remote CLIProxyAPI

- construct ANTHROPIC_BASE_URL from host/port/protocol

- include auth token in Authorization header when provided
2025-12-19 01:15:10 -05:00
kaitranntt 30d564cda6 feat(cliproxy): add remote proxy client for health checks
- checkRemoteProxy() tests remote CLIProxyAPI /health endpoint

- testConnection() validates remote proxy connectivity

- typed error codes: CONNECTION_REFUSED, TIMEOUT, AUTH_FAILED, UNKNOWN

- support for self-signed certificates with allowSelfSigned flag

- add type-level tests for interfaces
2025-12-19 01:13:54 -05:00
kaitranntt 68a93f0500 feat(cliproxy): add proxy config resolver with CLI flag support
- parseProxyFlags() extracts --proxy-host, --proxy-port, --proxy-protocol

- getProxyEnvVars() reads CCS_PROXY_* environment variables

- resolveProxyConfig() merges CLI > ENV > config.yaml > defaults

- hasProxyFlags() detects proxy-related CLI arguments

- add 29 comprehensive unit tests
2025-12-19 01:12:46 -05:00
kaitranntt 197174441f feat(config): add proxy section to unified config loader
- merge proxy config with defaults in loadUnifiedConfig

- preserve user overrides for remote/fallback/local sections
2025-12-19 01:11:49 -05:00
kaitranntt eff2e2d29f feat(config): add proxy configuration types and schema
- add ProxyRemoteConfig, ProxyFallbackConfig, ProxyLocalConfig interfaces

- add ProxyConfig composite type with remote/fallback/local sections

- add ResolvedProxyConfig interface for runtime config

- bump UNIFIED_CONFIG_VERSION to 5

- add DEFAULT_PROXY_CONFIG constant
2025-12-19 01:11:29 -05:00
kaitranntt 45207b4e7f feat(cleanup): add age-based error log cleanup
- add --errors flag to target error-*.log files

- add --days=N for age filtering (default: 7 days)

- show preview of files to delete before confirmation

- keep recent logs for debugging, only delete old ones
2025-12-18 23:45:44 -05:00
kaitranntt d43079b724 feat(ui): add version sync timestamp to ProxyStatusWidget
- Show current CLIProxyAPI version (e.g., v6.5.53)
- Display "Synced Xm ago" with full timestamp on hover
- Extend API response to include checkedAt timestamp
2025-12-18 23:24:15 -05:00
kaitranntt 96762a9f6e feat(ui): show CLIProxyAPI update availability in dashboard
- Add GET /api/cliproxy/update-check endpoint
- Export checkCliproxyUpdate() function from binary-manager
- Add useCliproxyUpdateCheck hook with 1-hour cache
- Update ProxyStatusWidget with amber "Update" badge when available
- Highlight Restart button as "Update" with amber styling when update pending
2025-12-18 23:17:05 -05:00
kaitranntt c9ad0b0779 feat(ui): add Stop and Restart buttons to ProxyStatusWidget
- Add POST /api/cliproxy/proxy-stop API endpoint
- Add proxyStop method in api-client and useStopProxy hook
- Update ProxyStatusWidget with Stop and Restart controls when running
- Restart = stop + delay + start (for applying CLIProxyAPI updates)

Complements the fix in binary-manager.ts which now tells users to stop
proxy before updates can be applied.
2025-12-18 23:03:45 -05:00
kaitranntt 2adc272f27 fix(cliproxy): prevent misleading update message when proxy is running
When CLIProxyAPI is already running as a background process, the update
cannot be applied because the old process is still in memory. Previously,
the CLI would download the new binary and show "Updating CLIProxyAPI..."
even though the running process remained on the old version.

Now checks if proxy is running before attempting update:
- If running: shows update available message with instruction to stop first
- If not running: proceeds with update as before

Fixes #143
2025-12-18 22:52:12 -05:00