Commit Graph
1412 Commits
Author SHA1 Message Date
Tam Nhu Tran e5fe86f520 feat: add native Claude effort override 2026-04-30 22:36:47 -04:00
Tam Nhu Tran 3b15082ea4 Merge remote-tracking branch 'origin/dev' into kai/feat/1138-logging-revamp 2026-04-30 16:47:28 -04:00
Tam Nhu Tran 1e5580a30a fix(config-facade): mtime-based staleness detection for cache
getCachedConfig() now checks config file mtime on each call.
If external code writes via unified-config-loader directly,
the facade detects the file change and re-reads from disk
automatically. Resolves PR-Agent "Stale Cache" finding.
2026-04-30 15:56:50 -04:00
Tam Nhu Tran 2290a1dc5a docs(config-facade): clarify cache coherence contract
Document that uncached reads (loadOrCreateUnifiedConfig)
bypass the cache and callers should use
invalidateConfigCache() if they mix uncached reads
with cached writes outside the facade. Resolves
remaining PR-Agent concern from #1150 comment.
2026-04-30 15:44:34 -04:00
Tam Nhu Tran 6d266fc7e8 fix: remove raw write re-exports from facade (cache bypass)
PR-Agent #1150 review flagged that re-exporting
saveUnifiedConfig/mutateUnifiedConfig/updateUnifiedConfig
allows callers to bypass the cache. Only export the
cache-coherent wrappers (saveConfig/mutateConfig/updateConfig).
Raw functions still available via direct import from
unified-config-loader if needed.

- Remove raw write re-exports from facade
- Add test verifying raw writes are NOT exported
- Add test verifying cache-coherent wrappers ARE exported
2026-04-30 15:37:17 -04:00
Tam Nhu Tran b8ed36e370 fix: round 3 red-team — test false-positive, dead code,
edge-case coverage

- Fix false-positive test: use CCSError with recoverable=false
  instead of plain Error (never exercised recoverable check)
- Remove redundant retryableCheck ?? defaultRetryableCheck
  (destructuring already defaults)
- Add test: retryAfter > maxDelayMs (server directive wins)
- Add test: baseDelayMs=0 produces immediate retries
- Add test: onRetry not called when maxRetries=0
2026-04-30 15:16:07 -04:00
Tam Nhu Tran 18e865ea36 fix: round 2 red-team fixes — onRetry safety, validation, barrel
- retry-strategy: wrap onRetry in try/catch to prevent
  callback errors from aborting retries
- retry-strategy: validate baseDelayMs >= 0
- retry-strategy: update JSDoc to clarify
  retryAfter/maxDelayMs interaction
- errors/index.ts: add ValidationError to barrel
- Tests: onRetry throw test, negative baseDelayMs test
2026-04-30 14:59:44 -04:00
Tam Nhu Tran 9bb1bdbad9 fix: address red-team review findings — cache aliasing, jitter cap, cause shadowing
- config-loader-facade: use structuredClone() to prevent cache aliasing
- retry-strategy: re-cap delay after jitter to enforce maxDelayMs boundary
- retry-strategy: wire retryAfter from RetryableError into delay computation
- retry-strategy: guard against negative maxRetries
- error-types: rename RetryableError.cause to originalError to avoid shadowing Error.cause
- Tests updated for all fixes
2026-04-30 14:37:28 -04:00
Tam Nhu Tran cb8b34b36d Merge branch 'kai/refactor/1135-item2-config-loader-facade' into kai/refactor/1135-structural-maintainability 2026-04-30 14:10:42 -04:00
Tam Nhu Tran b5fae5e8c9 Merge branch 'kai/refactor/1135-item9-error-hierarchy-retry' into kai/refactor/1135-structural-maintainability 2026-04-30 14:10:30 -04:00
Tam Nhu Tran b7aea78512 Revert "Revert "refactor(config): reorganize unified-config-types into schemas directory""
This reverts commit 06bce198eb.
2026-04-30 14:07:32 -04:00
Tam Nhu Tran 0868e92bb1 Revert "Revert "refactor(config): reorganize unified-config-types into schemas directory""
This reverts commit 06bce198eb.
2026-04-30 14:05:33 -04:00
Tam Nhu Tran 1e9a7f3fa0 refactor(config): add config-loader-facade with memoization
Single import path for all config loading. Re-exports all 26 functions
from unified-config-loader and 4 from config-manager. Adds memoization
for loadOrCreateUnifiedConfig via getCachedConfig() with automatic cache
invalidation on write operations (mutateConfig, updateConfig). Pure
structural refactor -- no existing imports modified.
2026-04-30 14:03:48 -04:00
Tam Nhu Tran 06bce198eb Revert "refactor(config): reorganize unified-config-types into schemas directory"
This reverts commit 51df0ee55b.
2026-04-30 13:57:08 -04:00
Tam Nhu Tran 51df0ee55b refactor(config): reorganize unified-config-types into schemas directory
Split the 1,128-line unified-config-types.ts into focused schema modules
under src/config/schemas/ for maintainability. Each file is under 200 LOC.

New schema files:
- version.ts: UNIFIED_CONFIG_VERSION constant
- auth.ts: AccountConfig, ProfileConfig, OAuthAccounts, CLIProxyAuthConfig, etc.
- cliproxy.ts: CLIProxyConfig, CompositeTierConfig, routing/safety types
- copilot-cursor.ts: CopilotConfig, CursorConfig + defaults
- proxy-server.ts: CliproxyServerConfig, GlobalEnvConfig, ImageAnalysisConfig
- quota.ts: QuotaManagementConfig + all quota types and defaults
- thinking.ts: ThinkingConfig + tier defaults
- channels.ts: OfficialChannelsConfig (Telegram, Discord, iMessage)
- websearch.ts: All WebSearch backend types (DuckDuckGo, Brave, Exa, etc.)
- browser.ts: BrowserConfig, BrowserClaudeConfig, BrowserCodexConfig
- logging.ts: LoggingConfig, PreferencesConfig
- unified-config.ts: UnifiedConfig interface, factory, type guard
- index.ts: Barrel re-export of all schema modules

unified-config-types.ts is now a thin backward-compatible barrel that
re-exports everything from schemas/index. All 67 existing imports across
the codebase continue to resolve unchanged.
2026-04-30 13:54:40 -04:00
Tam Nhu Tran d089ab06c2 refactor(errors): add RetryableError and retry-strategy utility
Extract retryable error class and reusable withRetry wrapper from
scattered retry logic in glmt-proxy and binary/downloader.
2026-04-30 13:46:33 -04:00
Kai (Tam Nhu) TranandGitHub b892739756 Merge pull request #1146 from kaitranntt/kai/feat/1138-logs-ui-redesign
feat(ui): redesign dashboard logs page (#1142)
2026-04-30 13:14:47 -04:00
Tam Nhu Tran 8afee344e1 feat(targets,management): instrument adapter spawn lifecycle and instance manager
Each target adapter (claude, codex, droid) now emits dispatch on child
spawn and respond on child exit with latencyMs. instance-manager emits
lifecycle events for instance create / start / stop so multi-instance flows
are traceable per requestId.

Refs #1141, #1138
2026-04-30 13:00:49 -04:00
Tam Nhu Tran 1ff4329ee4 feat(providers): instrument copilot, cursor, and glmt across daemons and executors
Provider modules now emit structured stage tags around daemon spawn /
ready / stop, executor invocations, and upstream dispatch. glmt-transformer
gets cleanup-stage error conversion; legacy glmt-proxy adds minimal
listen + retry instrumentation (full per-request stages live in proxy-server
since glmt-proxy is compat-only).

Refs #1141, #1138
2026-04-30 13:00:33 -04:00
Tam Nhu Tran bf8759460d feat(auth,commands): instrument oauth handler, profile registry, and doctor pipeline
Emit auth-stage events around OAuth round-trips and profile lookups so auth
flows are traceable end-to-end. Doctor command emits dispatch stages around
each health-check phase for clearer diagnostic logs.

Refs #1141, #1138
2026-04-30 13:00:16 -04:00
Tam Nhu Tran 4700727915 feat(proxy,cli): emit lifecycle stages with x-ccs-request-id propagation
Wrap proxy server entry edge in withRequestContext so every inbound request
gets a requestId (reused from x-ccs-request-id header when valid UUID-ish,
freshly minted otherwise). messages-route emits 7 stages: intake / auth /
transform / route / dispatch / upstream / respond, each with latencyMs and
structured error metadata on failure.

CCS CLI entry (ccs.ts) wraps main() in runWithRequestId and emits
cli.command.start / complete / failed stages so command lifecycle is
correlatable end-to-end.

Refs #1141, #1138
2026-04-30 13:00:00 -04:00
Tam Nhu Tran 7a22e89046 feat(logging): add structured contract, ALS context, stage helpers, and redaction coverage
Establish the structured-log foundation that downstream modules consume:
- LogStage union (intake|route|auth|dispatch|upstream|transform|respond|cleanup)
- AsyncLocalStorage-backed log-context for end-to-end requestId propagation
- Logger.stage() emit helper with optional latencyMs and structured metadata
- Extended log-redaction patterns for proxy-authorization, x-goog-api-key,
  oauth-code, refresh-token classes; Bearer/Basic/Token value-shape masking
- Public exports: getRecentLogEntries, withRequestContext, runWithRequestId,
  getRequestId

Refs #1141, #1138
2026-04-30 12:59:42 -04:00
Tam Nhu Tran 33a1553431 test: include colocated cliproxy tests in buckets 2026-04-30 12:49:57 -04:00
Tam Nhu Tran d9ace607e5 fix(proxy): shape direct OpenAI reasoning chat payloads 2026-04-30 12:33:02 -04:00
Tam Nhu Tran 20c2005df9 fix(cliproxy): clear stale cleanup timer and fix session/tunnel edge cases
- Stop cleanup interval when all auth sessions are removed (unregister,
  cancel, cancelAll) so the Node event loop isn't held alive.
- getActiveSessionForProvider now returns the most recent session by
  startedAt instead of the first map entry.
- HTTPS tunnel includes port in Host header when non-443.
2026-04-29 18:13:15 -04:00
Tam Nhu Tran 6633bf456b fix(cliproxy): handle all invalid prefixes and reverse-order collisions
forceValidChars() now ensures leading char is letter or underscore
(catches dot, hyphen, colon, slash — not just digits). registerTools()
always registers in mapping so collisions are detected regardless of
tool registration order.
2026-04-29 18:04:19 -04:00
Tam Nhu Tran 218d0cf6c6 fix(cliproxy): sanitize invalid tool name chars and disambiguate collisions
sanitizeToolName() fallback now forces valid characters (replaces
unsupported chars with underscores, ensures leading letter/underscore)
instead of only truncating. registerTools() disambiguates colliding
sanitized names with numeric suffixes so restoreToolUse() always maps
back to the correct original.
2026-04-29 17:57:11 -04:00
Tam Nhu Tran 31dc18657c fix(cliproxy): fix base-config-loader __dirname path and stale mock.module paths
- base-config-loader.ts moved from src/cliproxy/ to src/cliproxy/config/,
  so __dirname relative path needs one more .. to reach config/ dir
- Update mock.module paths for proxy-detector and routing-strategy
  in non-colocated test files
2026-04-29 17:40:33 -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
Kai (Tam Nhu) TranandGitHub 561189efe6 Merge pull request #1136 from kaitranntt/kai/refactor/1135-plugin-path-normalizer
refactor: extract plugin path normalizer
2026-04-29 15:02:51 -04:00
Tam Nhu Tran 3330229686 refactor: extract plugin path normalizer 2026-04-29 14:42:39 -04:00
seilk 83c16e216a fix(proxy): avoid leaking tool_result image URLs 2026-04-30 02:18:22 +09:00
seilk f6bb31c956 fix(proxy): stringify tool_result images for OpenAI upstreams 2026-04-30 00:55:45 +09:00
Tam Nhu Tran 5013d411a7 feat(cliproxy): self-pause exhausted quota accounts 2026-04-28 20:35:15 -04:00
Tam Nhu Tran 30f350a74f fix(usage): preserve pricing overrides and legacy merges 2026-04-28 16:51:06 -04:00
Tam Nhu Tran 42fc5281a1 fix(usage): clarify static pricing fallback 2026-04-28 16:26:27 -04:00
Tam Nhu Tran c7141b3d3a fix(usage): honor provider-aware pricing precedence 2026-04-28 16:11:07 -04:00
Tam Nhu Tran f736190196 fix(usage): avoid cross-provider pricing fallback 2026-04-28 15:55:35 -04:00
Tam Nhu Tran fc90b6f473 fix(usage): normalize provider aliases in aggregation 2026-04-28 15:43:13 -04:00
Tam Nhu Tran a538627933 fix(usage): harden models.dev analytics integration 2026-04-28 15:25:58 -04:00
Tam Nhu Tran a38c1a75ba feat: integrate models.dev pricing metadata 2026-04-28 14:50:26 -04:00
Tam Nhu Tran 73c82b3567 Merge remote-tracking branch 'origin/dev' into kai/fix/1118-ai-provider-model-rules 2026-04-28 14:27:53 -04:00
Tam Nhu Tran 9a28ca55d8 fix(cliproxy): tolerate plain AI provider model rules 2026-04-28 14:19:21 -04:00
Tam Nhu Tran aa7f155161 test(cliproxy): stabilize routing endpoint coverage 2026-04-28 14:07:15 -04:00
Tam Nhu Tran 8ef703024b fix(cliproxy): probe routing via management endpoint 2026-04-28 14:02:58 -04:00
Kai (Tam Nhu) TranandGitHub b6432f783e Merge pull request #1114 from yousiki/fix/claude-utilization-percent-unit
fix(cliproxy): use explicit utilization unit per Claude payload form
2026-04-28 13:41:31 -04:00
Kai (Tam Nhu) TranandGitHub a8e0d95bc8 Merge pull request #1117 from kaitranntt/kai/feat/1115-session-affinity
feat: add local CLIProxy session affinity controls
2026-04-28 13:37:37 -04:00
Tam Nhu Tran 5267c421ca fix(cliproxy): harden session affinity behavior 2026-04-28 13:27:05 -04:00