From d3559279a2b01b2f96b598fa5ecd63b06821ff09 Mon Sep 17 00:00:00 2001 From: kaitranntt Date: Sun, 16 Nov 2025 07:01:09 -0500 Subject: [PATCH] fix(kimi): resolve API 401 errors from deprecated model fields - Remove 5 deprecated model fields from Kimi settings causing auth failures - Update config/base-kimi.settings.json template with clean configuration - Add automatic migration in scripts/postinstall.js to remove deprecated fields - Preserve user API keys and custom settings during migration - Update CHANGELOG.md with v4.1.1 and v4.1.2 entries - Bump version to 4.1.2 across all files and installers Fixes authentication issues with Moonshot AI (Kimi) API due to deprecated model parameters that are now rejected by the service. --- CHANGELOG.md | 31 +++++++++++++++++ VERSION | 2 +- config/base-kimi.settings.json | 7 +--- installers/install.ps1 | 2 +- installers/install.sh | 2 +- lib/ccs | 2 +- lib/ccs.ps1 | 2 +- package.json | 2 +- scripts/postinstall.js | 63 ++++++++++++++++++++++++++++++---- 9 files changed, 95 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae5c0e38..c608ceb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,37 @@ Format: [Keep a Changelog](https://keepachangelog.com/) +## [4.1.2] - 2025-11-16 + +### Fixed +- **Kimi API 401 errors** caused by deprecated model fields + - Removed `ANTHROPIC_MODEL`, `ANTHROPIC_SMALL_FAST_MODEL`, `ANTHROPIC_DEFAULT_OPUS_MODEL`, `ANTHROPIC_DEFAULT_SONNET_MODEL`, `ANTHROPIC_DEFAULT_HAIKU_MODEL` from Kimi settings + - Kimi API update now rejects requests with these fields (previously optional, now break authentication) + - Automatic migration removes deprecated fields from existing `~/.ccs/kimi.settings.json` + - Preserves user API keys and custom settings during migration + - Updated `config/base-kimi.settings.json` template + - Users experiencing 401 errors will be automatically fixed on next install/update + +### Changed +- Kimi settings now minimal: only `ANTHROPIC_BASE_URL` and `ANTHROPIC_AUTH_TOKEN` required + +--- + +## [4.1.1] - 2025-11-16 + +### Fixed +- **npm install fails to copy .claude/ directory** to `~/.ccs/.claude/` + - Error: "[!] CCS .claude/ directory not found, skipping symlink installation" + - Created `bin/utils/claude-dir-installer.js` utility to copy `.claude/` from package + - Updated `scripts/postinstall.js` to copy `.claude/` before creating symlinks + - Updated `ccs update` command to re-install `.claude/` directory + - Supports Node.js 14+ with fallback for versions < 16.7.0 + +### Added +- `ClaudeDirInstaller` utility class for managing `.claude/` directory installation + +--- + ## [4.1.0] - 2025-11-16 ### Added diff --git a/VERSION b/VERSION index 627a3f43..4d0dcda0 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.1.1 +4.1.2 diff --git a/config/base-kimi.settings.json b/config/base-kimi.settings.json index ef554791..5ad236f9 100644 --- a/config/base-kimi.settings.json +++ b/config/base-kimi.settings.json @@ -1,12 +1,7 @@ { "env": { "ANTHROPIC_BASE_URL": "https://api.kimi.com/coding/", - "ANTHROPIC_AUTH_TOKEN": "YOUR_KIMI_API_KEY_HERE", - "ANTHROPIC_MODEL": "kimi-for-coding", - "ANTHROPIC_SMALL_FAST_MODEL": "kimi-for-coding", - "ANTHROPIC_DEFAULT_OPUS_MODEL": "kimi-for-coding", - "ANTHROPIC_DEFAULT_SONNET_MODEL": "kimi-for-coding", - "ANTHROPIC_DEFAULT_HAIKU_MODEL": "kimi-for-coding" + "ANTHROPIC_AUTH_TOKEN": "YOUR_KIMI_API_KEY_HERE" }, "alwaysThinkingEnabled": true } \ No newline at end of file diff --git a/installers/install.ps1 b/installers/install.ps1 index cfda70fa..febcdd05 100644 --- a/installers/install.ps1 +++ b/installers/install.ps1 @@ -31,7 +31,7 @@ $InstallMethod = if ($ScriptDir -and ((Test-Path "$ScriptDir\lib\ccs.ps1") -or ( # IMPORTANT: Update this version when releasing new versions! # This hardcoded version is used for standalone installations (irm | iex) # For git installations, VERSION file is read if available -$CcsVersion = "4.1.1" +$CcsVersion = "4.1.2" # Try to read VERSION file for git installations if ($ScriptDir) { diff --git a/installers/install.sh b/installers/install.sh index 8f23ca38..f4d5c961 100755 --- a/installers/install.sh +++ b/installers/install.sh @@ -32,7 +32,7 @@ fi # IMPORTANT: Update this version when releasing new versions! # This hardcoded version is used for standalone installations (curl | bash) # For git installations, VERSION file is read if available -CCS_VERSION="4.1.1" +CCS_VERSION="4.1.2" # Try to read VERSION file for git installations if [[ -f "$SCRIPT_DIR/VERSION" ]]; then diff --git a/lib/ccs b/lib/ccs index f177d438..eed3999f 100755 --- a/lib/ccs +++ b/lib/ccs @@ -2,7 +2,7 @@ set -euo pipefail # Version (updated by scripts/bump-version.sh) -CCS_VERSION="4.1.1" +CCS_VERSION="4.1.2" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" readonly CONFIG_FILE="${CCS_CONFIG:-$HOME/.ccs/config.json}" readonly PROFILES_JSON="$HOME/.ccs/profiles.json" diff --git a/lib/ccs.ps1 b/lib/ccs.ps1 index 0798f1c4..725a254d 100644 --- a/lib/ccs.ps1 +++ b/lib/ccs.ps1 @@ -12,7 +12,7 @@ param( $ErrorActionPreference = "Stop" # Version (updated by scripts/bump-version.sh) -$CcsVersion = "4.1.1" +$CcsVersion = "4.1.2" $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path $ConfigFile = if ($env:CCS_CONFIG) { $env:CCS_CONFIG } else { "$env:USERPROFILE\.ccs\config.json" } $ProfilesJson = "$env:USERPROFILE\.ccs\profiles.json" diff --git a/package.json b/package.json index a1eff3c3..20dc3b33 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kaitranntt/ccs", - "version": "4.1.1", + "version": "4.1.2", "description": "Claude Code Switch - Instant profile switching between Claude Sonnet 4.5 and GLM 4.6", "keywords": [ "cli", diff --git a/scripts/postinstall.js b/scripts/postinstall.js index ab19055c..2fd84cca 100755 --- a/scripts/postinstall.js +++ b/scripts/postinstall.js @@ -284,12 +284,7 @@ function createConfigFiles() { const kimiSettings = { env: { ANTHROPIC_BASE_URL: 'https://api.kimi.com/coding/', - ANTHROPIC_AUTH_TOKEN: 'YOUR_KIMI_API_KEY_HERE', - ANTHROPIC_MODEL: 'kimi-for-coding', - ANTHROPIC_SMALL_FAST_MODEL: 'kimi-for-coding', - ANTHROPIC_DEFAULT_OPUS_MODEL: 'kimi-for-coding', - ANTHROPIC_DEFAULT_SONNET_MODEL: 'kimi-for-coding', - ANTHROPIC_DEFAULT_HAIKU_MODEL: 'kimi-for-coding' + ANTHROPIC_AUTH_TOKEN: 'YOUR_KIMI_API_KEY_HERE' }, alwaysThinkingEnabled: true }; @@ -309,6 +304,62 @@ function createConfigFiles() { console.log('[OK] Kimi profile exists: ~/.ccs/kimi.settings.json (preserved)'); } + // Migrate existing Kimi configs to remove deprecated model fields (v4.1.2) + // Kimi API changed - model fields now cause 401 errors + if (fs.existsSync(kimiSettingsPath)) { + try { + const existing = JSON.parse(fs.readFileSync(kimiSettingsPath, 'utf8')); + let updated = false; + + // Ensure env object exists + if (!existing.env) { + existing.env = {}; + updated = true; + } + + // Remove deprecated model fields that cause 401 errors + const deprecatedFields = [ + 'ANTHROPIC_MODEL', + 'ANTHROPIC_SMALL_FAST_MODEL', + 'ANTHROPIC_DEFAULT_OPUS_MODEL', + 'ANTHROPIC_DEFAULT_SONNET_MODEL', + 'ANTHROPIC_DEFAULT_HAIKU_MODEL' + ]; + + for (const field of deprecatedFields) { + if (existing.env[field] !== undefined) { + delete existing.env[field]; + updated = true; + } + } + + // Ensure required fields exist + if (!existing.env.ANTHROPIC_BASE_URL) { + existing.env.ANTHROPIC_BASE_URL = 'https://api.kimi.com/coding/'; + updated = true; + } + + // Add alwaysThinkingEnabled if missing + if (existing.alwaysThinkingEnabled === undefined) { + existing.alwaysThinkingEnabled = true; + updated = true; + } + + // Write back if updated + if (updated) { + const tmpPath = `${kimiSettingsPath}.tmp`; + fs.writeFileSync(tmpPath, JSON.stringify(existing, null, 2) + '\n', 'utf8'); + fs.renameSync(tmpPath, kimiSettingsPath); + console.log('[OK] Migrated Kimi config (v4.1.2): removed deprecated model fields'); + console.log(' Kimi API no longer requires model fields (they cause 401 errors)'); + } + } catch (err) { + console.warn('[!] Kimi config migration failed:', err.message); + console.warn(' Existing config preserved, but may cause 401 errors'); + console.warn(' Manually remove ANTHROPIC_MODEL fields from ~/.ccs/kimi.settings.json'); + } + } + // Copy shell completion files to ~/.ccs/completions/ const completionsDir = path.join(ccsDir, 'completions'); const scriptsCompletionDir = path.join(__dirname, '../scripts/completion');