Commit Graph
30 Commits
Author SHA1 Message Date
Kai (Tam Nhu) TranandGitHub 50b0ffba75 fix(cliproxy): refresh upstream model and quota surfaces (#1158)
* fix(cliproxy): refresh upstream model and quota surfaces

* test(cliproxy): cover codex legacy model fallback
2026-05-01 02:19:31 -04:00
Tam Nhu Tran c3c8cb7a82 fix(cliproxy): exclude colocated tests from tsconfig and eslint
- Add src/**/__tests__/** to tsconfig.json exclude list
- Add ignores pattern for __tests__ in eslint.config.mjs
- Fix ui/src/lib/api-client.ts import path for provider-entitlement-types
- Remove stale build artifacts from ui/src/lib/ and tests/mocks/
2026-04-29 17:18:23 -04:00
Tam Nhu Tran 273214d166 fix(cliproxy): correct relative import paths in colocated tests 2026-04-29 17:10:05 -04:00
Tam Nhu Tran 1c72b4b8d5 refactor(cliproxy): flatten module structure and colocate tests (#1135)
- Split types.ts (331 LOC) into 4 concern-based files under types/:
  platform-types, binary-types, provider-types, config-types
- Preserve backward compat via barrel re-export (types.ts → types/index)
- Reorganize 53 root-level files into 8 subdirectories:
  accounts/, ai-providers/, auth/, binary/, config/, executor/,
  management/, proxy/, quota/, routing/, services/, sync/
- Reduce src/cliproxy/ root from 65 to 8 files (target: ≤10)
- Colocate 87 unit tests from tests/unit/cliproxy/ into
  src/cliproxy/*/__tests__/ (13 colocated test directories)
- Update import paths across 40+ consumer files
- Add TDD backward-compat test for types split

Refs #1135
2026-04-29 17:06:39 -04:00
Sergey Galuza a7871283d4 test(cliproxy): replace process-wide mock.module with DI seams
Bun's `mock.module()` is process-wide and is NOT undone by `mock.restore()`.
Two test files used module-level mocks that leaked across test runs,
silently breaking unrelated suites that imported the mocked modules
transitively:

- tests/unit/cliproxy/version-checker-stale-cache.test.ts mocked
  binary/version-checker, contaminating cliproxy-stats-routes-install
  and cliproxy-stats-routes-model-update suites that import a route
  module which transitively imports version-checker.
- tests/unit/cliproxy/service-manager-startup.test.ts mocked 8 modules
  at top level (binary-manager, stats-fetcher, etc.), contaminating any
  later file that imports them.

CI happens to be green because file ordering on the GitHub runner places
victim files BEFORE contaminators in `bun test`. On Linux locally the
order is reversed, producing 6 reproducible test failures on every
`bun run test:fast` run. A change in OS, bun version, or new test files
that import the mocked modules could silently flip the CI runner's
order and surface these failures unexpectedly.

Replaced module-level mocks with explicit dependency-injection seams in
production code, following the existing pattern in version-checker.ts
and version-cache.ts (`fetchJsonFn?`, `fetchLatestVersionFn?`):

- src/cliproxy/types.ts: `BinaryManagerConfig.checkForUpdatesFn` (optional)
- src/cliproxy/binary/lifecycle.ts: route through new fn with default
- src/cliproxy/service-manager.ts: `ensureCliproxyService(deps?)` with
  optional `ensureBinaryFn`, `detectRunningProxyFn`,
  `configNeedsRegenerationFn`, `withStartupLockFn`

All deps fields are optional with real-implementation defaults, so
production callers are unchanged. Tests now inject deterministic stubs
through call-site parameters instead of module-level mocks.

Verified locally: \`bun run validate\` is now 2540 pass / 0 fail
(previously 2534 pass / 6 fail at the same upstream/main HEAD).

Built [OnSteroids](https://onsteroids.ai)
2026-04-26 09:43:09 +02:00
Tam Nhu Tran 3d22bb07f0 fix(cliproxy): route plus backend to maintained fork 2026-04-23 21:25:29 -04:00
Tam Nhu Tran 27f1416181 fix(cliproxy): avoid network-bound local startup
- skip CLIProxy auto-update checks on runtime bootstrap paths

- fail fast when local startup needs a missing binary instead of attempting installs

- add regression coverage for dashboard limited mode and startup test isolation
2026-04-15 22:55:11 -04:00
Tam Nhu Tran 4e15ec5387 fix(cliproxy): degrade gracefully on GitHub release 403s
- fall back to stale CLIProxy version caches instead of surfacing 500s

- remove duplicate dashboard update-check fetches and disable retry/focus refetch

- add backend and UI regressions for the degraded-path behavior
2026-04-13 22:19:16 -04:00
Tam Nhu Tran e8b7ac730f fix(docker): wrap session registration in try-catch and narrow ETXTBSY guard
Session registration in spawn handler can throw on lock contention or
disk errors — wrap in try-catch to prevent silent proxy-untracked state.

Narrow EBUSY catch to ETXTBSY only since EBUSY on non-Linux platforms
can mean mount point or directory in use, not running binary. Fix
misleading "skip" comment to say "abort".
2026-03-28 19:00:54 -04:00
Tam Nhu Tran 7d410b26d0 fix(docker): address review findings — PID guard, deleteBinary guard, blocked fallback
- Guard child.pid falsy in bootstrap (PID 0 creates immortal phantom lock)
- Add ETXTBSY/EBUSY guard to deleteBinary() (same vuln as downloadAndInstall)
- Fix error message to suggest container restart (not circular ccs docker update)
- Tighten status.blocked guard to handle missing blocker gracefully
2026-03-28 18:12:18 -04:00
Tam Nhu Tran 5eac9c584a fix(cliproxy): guard binary install against ETXTBSY when running
In Docker, the dashboard tried to update the CLIProxy binary while
the bootstrap's instance was already executing it, causing ETXTBSY.
Now catches the error and throws a clear message instead of crashing.
2026-03-28 17:56:03 -04:00
Tam Nhu Tran f50c9625de fix: harden global fetch proxy handling 2026-03-16 06:58:01 -04:00
kaitranntt 8c6afe2e73 feat: update cliproxy, config loader, glmt transformer, and provider routes 2026-02-10 10:45:16 -05:00
kaitranntt 713ee93606 test(cliproxy): add comprehensive proxy support unit tests
Add 34 unit tests covering:
- getProxyUrl: env var precedence (lowercase > uppercase > all_proxy)
- shouldBypassProxy: wildcard, exact match, suffix patterns, case-insensitivity
- getHostname: URL parsing with error handling
- getProxyAgent: proxy creation, NO_PROXY bypass, error handling

Export internal functions via __testExports for testability.
2026-02-04 17:05:24 -05:00
kaitranntt bcde5f4878 fix(cliproxy): add NO_PROXY support and error handling for proxy URLs
- Add shouldBypassProxy() to respect NO_PROXY/no_proxy env var
- Supports exact match, wildcard (*), and domain suffix patterns
- Add try-catch for malformed proxy URLs with graceful fallback
- Extract getHostname() helper for URL parsing
2026-02-04 16:59:18 -05:00
kaitranntt 9c527b7d15 fix(cliproxy): respect http_proxy env vars for binary downloads
CLIProxyAPI installation and updates now respect http_proxy, https_proxy,
and all_proxy environment variables when making network requests.

Uses https-proxy-agent and http-proxy-agent packages to route HTTP/HTTPS
requests through the configured proxy server.

Closes #266
2026-02-04 16:46:14 -05:00
kaitranntt 2794a548a5 fix(cliproxy): complete backend switching with proper binary extraction
- Add backend field to BinaryManagerConfig type for installer context
- Thread backend parameter through tar/zip extractors to use correct names
- Delete existing binary before install to prevent mismatched binaries
- Track backend in session metadata for debugging/monitoring
- Validate and preserve backend field in config mergeWithDefaults
- Pass backend to registerSession for session tracking

The core issue was extractors calling getExecutableName() without the
backend parameter, causing it to default to 'plus' regardless of user
selection. This resulted in wrong binaries being extracted/renamed.
2026-01-23 15:17:32 -05:00
kaitranntt 0a1cbcc612 fix(cliproxy): use backend-specific GitHub repos for version fetching
Root cause: fetchLatestVersion and fetchAllVersions were hardcoded to
CLIProxyAPIPlus repo, ignoring backend selection.

Changes:
- Add getGitHubApiUrls(backend) helper to types.ts
- Make fetchLatestVersion and fetchAllVersions backend-aware
- Make version list cache backend-specific (bin/{backend}/.version-list-cache.json)
- Update /api/cliproxy/versions route to use configured backend
- Allow version management even when proxy not running (ProxyStatusWidget)
- Show settings button in all states for easier access
2026-01-23 14:55:51 -05:00
kaitranntt a41fd2a093 fix(cliproxy): make version cache backend-specific for proper switching
- Add backend parameter to version cache functions (read/write/path)
- Store cache at bin/{backend}/.version-cache.json instead of shared location
- Pass backend through checkForUpdates() and BinaryManager
- Add refetchType: 'all' to force immediate query refetch on backend change
- Add cliproxy-server-config query invalidation for consistency
2026-01-23 14:40:40 -05:00
kaitranntt 628148c359 fix(cliproxy): make backend switching work with version pins and status
- Add backend param to isCLIProxyInstalled(), getCLIProxyPath(),
  getInstalledCliproxyVersion(), installCliproxyVersion()
- Update getBinaryStatus() to pass backend to all helper functions
- Add getBackendLabel() helper for dynamic CLI messages
- Replace hardcoded "CLIProxy Plus" strings with dynamic labels
- Pass --backend flag through install/update command handlers
- Import CLIProxyBackend type from types.ts instead of redefining

Setting `cliproxy.backend: original` in config.yaml now correctly
uses the original backend for version pins and binary operations.
2026-01-23 10:52:01 -05:00
kaitranntt 0abd021d25 fix(cliproxy): remove stable version cap, only v81-88 are faulty
- Set CLIPROXY_MAX_STABLE_VERSION to 9.9.999-0 (effectively no cap)
- v89+ are all stable, no longer show experimental warning
- Only v81-88 remain marked as faulty with known bugs
- Simplified lifecycle.ts to remove redundant experimental warning
2026-01-08 10:49:37 -05:00
Kai (Tam Nhu) TranGitHubgithub-actions[bot] <github-actions[bot]@users.noreply.github.com>
b6d65209cd feat(ci): add workflow_dispatch for AI review (#291)
* feat(ci): add AI code review workflow with Claude via CLIProxyAPI

- Self-hosted runner calls CLIProxyAPI at localhost:8317
- Triggers on PR open/update and /review comment
- Uses gemini-claude-opus-4-5-thinking for deep reviews
- Posts summary + inline comments via gh CLI
- Handles self-PR fallback to COMMENT mode

* chore(release): 7.15.0-dev.1 [skip ci]

* refactor(ci): use GitHub App for reviewer identity + new review format

- Posts as ccs-agy-reviewer[bot] via GitHub App token
- New review format: structured markdown with verdict, summary, issues table
- Single PR comment instead of inline comments
- Concise, focused on PR changes only

* chore(release): 7.15.0-dev.2 [skip ci]

* refactor(ci): switch to Claude Code CLI for reviews

- Use claude -p instead of custom TypeScript script
- Auto-install if not present on runner
- CLIProxyAPI via env vars (ANTHROPIC_BASE_URL, ANTHROPIC_MODEL)
- Allowed tools: Read, Glob, Grep
- Max 3 turns for file exploration

* chore(release): 7.15.0-dev.3 [skip ci]

* chore(release): 7.15.0-dev.4 [skip ci]

* feat(ci): add workflow_dispatch for manual review trigger

* chore(release): 7.15.0-dev.5 [skip ci]

* refactor(cliproxy): add faulty version range infrastructure (#289)

* refactor(cliproxy): add faulty version range infrastructure

- Add CLIPROXY_FAULTY_RANGE constant for marking known buggy versions
- Add isVersionFaulty() helper to version-checker.ts
- Update lifecycle.ts to warn users on faulty versions with upgrade suggestion
- Update health checks to distinguish faulty vs experimental versions
- Update stats routes to include faultyRange in API response
- Skip faulty versions when calculating latestStable

Infrastructure ready for future version promotions. Currently:
- v80 and below: stable
- v81+: marked as faulty (context cancellation bugs)

* chore: trigger review

* chore: re-trigger review

* chore: test PR trigger

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-01-07 02:25:49 -08:00
kaitranntt a69b2e9d10 feat(cliproxy): add version management UI with install/restart controls
Implements comprehensive version management for CLIProxyAPI Plus:

Backend APIs:
- GET /versions: fetch available versions from GitHub releases
- POST /install: install specific version with force flag for unstable
- POST /restart: restart proxy without version change

Frontend:
- 4-button layout: Restart, Update/Downgrade, Stop, Settings gear
- Collapsible version picker with dropdown + manual input
- Confirmation dialog for unstable versions (>6.6.80)
- Progressive disclosure (version picker hidden by default)

Ref: plans/260105-1250-cliproxy-version-management/
2026-01-05 13:12:46 -05:00
kaitranntt 212aef81bc fix(cliproxy): add edge case handling for version capping
- Add isAboveMaxStable() helper for version stability checks
- Add null/empty guard in clampToMaxStable() function
- Warn users on unstable v81+ without forcing downgrade
- Add context note showing latest version when it's unstable
- Clamp fallback version on GitHub API failure
2026-01-05 11:50:06 -05:00
kaitranntt 869ab3eecd fix(cliproxy): cap auto-update to v80 due to v81+ context bugs
CLIProxyAPIPlus v81+ has context cancellation bugs causing:
- Intermittent 500 errors
- "context canceled" errors during streaming
- Broken token refresh handling

Root cause: v81 commit 7a77b23 changed refreshToken to use
detached context.Background() causing race conditions.

Solution: Add CLIPROXY_MAX_STABLE_VERSION constant (6.6.80-0)
and clamp auto-update to this version until upstream fixes.

Closes #269
2026-01-05 11:41:52 -05:00
kaitranntt c2dd0261b7 refactor(cliproxy): enhance binary downloader with robust error handling
- Add categorized error detection for socket, timeout, HTTP, and redirect errors
- Implement smarter exponential backoff (longer delays for socket errors)
- Increase max retries from 3 to 5 with dynamic timeout adjustment
- Add resource cleanup (disable connection pooling for clean process exit)
- Add user-friendly error messages for each error type
- Refactor fetchText/fetchJson with retry logic and proper error handling
- Set 120s timeout for large binary downloads, 15-30s for text/JSON
- Prevent double-resolution and race conditions in Promise handlers
2025-12-22 18:22:32 -05:00
kaitranntt 4829902826 fix: update download URLs and binary names for CLIProxyAPIPlus
- Change binaryName from CLIProxyAPI_ to CLIProxyAPIPlus_ prefix
- Update download URL to use CLIProxyAPIPlus repository
- Update checksums URL to use CLIProxyAPIPlus repository
- Change executable name from cli-proxy-api to cli-proxy-api-plus
- Update User-Agent header to CCS-CLIProxyPlus-Updater
- Update status messages to say "CLIProxy Plus"

Fixes HTTP 404 error when running `ccs cliproxy --latest`
2025-12-21 23:09:41 -05:00
kaitranntt 6f8587db68 feat(cliproxy): migrate from CLIProxyAPI to CLIProxyAPIPlus
- Update GitHub repo URL to router-for-me/CLIProxyAPIPlus
- Handle new release naming pattern (v6.6.X-0 suffix)
- Add version comparison support for Plus releases
2025-12-21 22:25:48 -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 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