coding-tool-x 3.4.6 → 3.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coding-tool-x",
3
- "version": "3.4.6",
3
+ "version": "3.4.7",
4
4
  "description": "Vibe Coding 增强工作助手 - 智能会话管理、动态渠道切换、全局搜索、实时监控",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -1,5 +1,13 @@
1
1
  const fs = require('fs');
2
2
  const { PATHS, NATIVE_PATHS, ensureStorageDirMigrated } = require('./config/paths');
3
+ const { isWindowsLikePlatform } = require('./utils/home-dir');
4
+
5
+ function buildEchoCommand(value) {
6
+ if (isWindowsLikePlatform(process.platform, process.env)) {
7
+ return `cmd /c echo ${value}`;
8
+ }
9
+ return `echo '${value}'`;
10
+ }
3
11
 
4
12
  // 恢复配置到默认状态
5
13
  async function resetConfig() {
@@ -56,7 +64,7 @@ async function resetConfig() {
56
64
  if (!settings.env) settings.env = {};
57
65
  settings.env.ANTHROPIC_BASE_URL = activeChannel.baseUrl;
58
66
  settings.env.ANTHROPIC_API_KEY = activeChannel.apiKey;
59
- settings.apiKeyHelper = `echo '${activeChannel.apiKey}'`;
67
+ settings.apiKeyHelper = buildEchoCommand(activeChannel.apiKey);
60
68
 
61
69
  fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2), 'utf8');
62
70
  console.log(`[OK] 已恢复到渠道: ${activeChannel.name}`);
@@ -107,34 +107,32 @@ function findActiveChannelFromSettings() {
107
107
  }
108
108
  }
109
109
 
110
- if (!baseUrl || !apiKey || baseUrl.includes('127.0.0.1')) {
111
- console.log('[Proxy] Invalid settings: empty baseUrl/apiKey or localhost detected');
112
- return null;
113
- }
114
-
115
110
  const channels = getAllChannels();
116
111
 
117
112
  // Level 1: Exact match (baseUrl + apiKey)
118
- let matchingChannel = channels.find(ch =>
119
- ch.baseUrl === baseUrl && ch.apiKey === apiKey
120
- );
121
-
122
- if (matchingChannel) {
123
- console.log(`[Proxy] Level 1 - Exact match: ${matchingChannel.name}`);
124
- return matchingChannel;
125
- }
113
+ if (baseUrl && apiKey && !baseUrl.includes('127.0.0.1')) {
114
+ let matchingChannel = channels.find(ch =>
115
+ ch.baseUrl === baseUrl && ch.apiKey === apiKey
116
+ );
117
+ if (matchingChannel) {
118
+ console.log(`[Proxy] Level 1 - Exact match: ${matchingChannel.name}`);
119
+ return matchingChannel;
120
+ }
126
121
 
127
- // Level 2: Match by baseUrl only (when apiKey differs)
128
- matchingChannel = channels.find(ch => ch.baseUrl === baseUrl);
129
- if (matchingChannel) {
130
- console.log(`[Proxy] Level 2 - Matched by baseUrl only: ${matchingChannel.name}`);
131
- return matchingChannel;
122
+ // Level 2: Match by baseUrl only (when apiKey differs)
123
+ matchingChannel = channels.find(ch => ch.baseUrl === baseUrl);
124
+ if (matchingChannel) {
125
+ console.log(`[Proxy] Level 2 - Matched by baseUrl only: ${matchingChannel.name}`);
126
+ return matchingChannel;
127
+ }
128
+ } else {
129
+ console.log('[Proxy] settings.json has no valid baseUrl/apiKey, falling back to channel list');
132
130
  }
133
131
 
134
132
  // Level 3: Use active-channel.json for last known active channel
135
133
  const activeChannelId = loadActiveChannelId();
136
134
  if (activeChannelId) {
137
- matchingChannel = channels.find(ch => ch.id === activeChannelId);
135
+ const matchingChannel = channels.find(ch => ch.id === activeChannelId);
138
136
  if (matchingChannel) {
139
137
  console.log(`[Proxy] Level 3 - Using last active channel: ${matchingChannel.name}`);
140
138
  return matchingChannel;
@@ -142,10 +140,10 @@ function findActiveChannelFromSettings() {
142
140
  }
143
141
 
144
142
  // Level 4: Return first enabled channel as last resort
145
- matchingChannel = channels.find(ch => ch.enabled !== false);
146
- if (matchingChannel) {
147
- console.log(`[Proxy] Level 4 - Using first enabled channel: ${matchingChannel.name}`);
148
- return matchingChannel;
143
+ const fallbackChannel = channels.find(ch => ch.enabled !== false);
144
+ if (fallbackChannel) {
145
+ console.log(`[Proxy] Level 4 - Using first enabled channel: ${fallbackChannel.name}`);
146
+ return fallbackChannel;
149
147
  }
150
148
 
151
149
  console.log('[Proxy] No matching channel found after all fallback levels');
@@ -4,6 +4,7 @@ const BaseChannelService = require('./base/base-channel-service');
4
4
  const { isProxyConfig } = require('./settings-manager');
5
5
  const { PATHS, NATIVE_PATHS } = require('../../config/paths');
6
6
  const { clearNativeOAuth } = require('./native-oauth-adapters');
7
+ const { isWindowsLikePlatform } = require('../../utils/home-dir');
7
8
 
8
9
  // ── Claude 特有工具函数 ──
9
10
 
@@ -51,7 +52,10 @@ function extractApiKeyFromHelper(apiKeyHelper) {
51
52
  }
52
53
 
53
54
  function buildApiKeyHelperCommand() {
54
- return 'echo \'ctx-managed\'';
55
+ if (isWindowsLikePlatform(process.platform, process.env)) {
56
+ return 'cmd /c echo ctx-managed';
57
+ }
58
+ return "echo 'ctx-managed'";
55
59
  }
56
60
 
57
61
  // ── Claude 原生设置写入 ──
@@ -105,6 +109,10 @@ function updateClaudeSettingsWithModelConfig(channel) {
105
109
  delete settings.env.NO_PROXY;
106
110
  }
107
111
 
112
+ if (settings.env && Object.keys(settings.env).length === 0) {
113
+ delete settings.env;
114
+ }
115
+
108
116
  settings.apiKeyHelper = buildApiKeyHelperCommand();
109
117
  fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2), 'utf8');
110
118
  }
@@ -133,6 +141,10 @@ function updateClaudeSettings(baseUrl, apiKey) {
133
141
  settings.env.ANTHROPIC_API_KEY = apiKey;
134
142
  }
135
143
 
144
+ if (settings.env && Object.keys(settings.env).length === 0) {
145
+ delete settings.env;
146
+ }
147
+
136
148
  settings.apiKeyHelper = buildApiKeyHelperCommand();
137
149
  fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2), 'utf8');
138
150
  }
@@ -1,5 +1,13 @@
1
1
  const fs = require('fs');
2
2
  const { NATIVE_PATHS } = require('../../config/paths');
3
+ const { isWindowsLikePlatform } = require('../../utils/home-dir');
4
+
5
+ function buildEchoCommand(value) {
6
+ if (isWindowsLikePlatform(process.platform, process.env)) {
7
+ return `cmd /c echo ${value}`;
8
+ }
9
+ return `echo '${value}'`;
10
+ }
3
11
 
4
12
  // Claude Code 配置文件路径
5
13
  function getSettingsPath() {
@@ -113,7 +121,7 @@ function setProxyConfig(proxyPort) {
113
121
  // 修改为代理配置(使用 Claude Code 的标准格式)
114
122
  settings.env.ANTHROPIC_BASE_URL = `http://127.0.0.1:${proxyPort}`;
115
123
  settings.env.ANTHROPIC_API_KEY = 'PROXY_KEY';
116
- settings.apiKeyHelper = `echo 'PROXY_KEY'`;
124
+ settings.apiKeyHelper = buildEchoCommand('PROXY_KEY');
117
125
 
118
126
  // 写入
119
127
  writeSettings(settings);