@tkpdx01/ccc 1.3.1 → 1.3.3

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/index.js CHANGED
@@ -27,7 +27,7 @@ const program = new Command();
27
27
  program
28
28
  .name('ccc')
29
29
  .description('Claude Code Settings Launcher - 管理多个 Claude Code 配置文件')
30
- .version('1.3.1');
30
+ .version('1.3.3');
31
31
 
32
32
  // 注册所有命令
33
33
  listCommand(program);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tkpdx01/ccc",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "description": "Claude Code Settings Launcher - Manage multiple Claude Code profiles",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -12,7 +12,8 @@ import {
12
12
  deleteProfile,
13
13
  resolveProfile,
14
14
  getProfileCredentials,
15
- getClaudeSettingsTemplate
15
+ getClaudeSettingsTemplate,
16
+ ensureDisableNonessentialTraffic
16
17
  } from '../profiles.js';
17
18
 
18
19
  export function editCommand(program) {
@@ -95,6 +96,14 @@ export function editCommand(program) {
95
96
  currentProfile.env.ANTHROPIC_AUTH_TOKEN = apiKey;
96
97
  currentProfile.env.ANTHROPIC_BASE_URL = apiUrl;
97
98
 
99
+ // 确保主配置有 CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC 设置
100
+ ensureDisableNonessentialTraffic();
101
+
102
+ // 确保影子配置也有该设置
103
+ if (currentProfile.env.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC !== '1') {
104
+ currentProfile.env.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC = '1';
105
+ }
106
+
98
107
  // 如果重命名
99
108
  if (newName && newName !== profile) {
100
109
  const newPath = getProfilePath(newName);
@@ -9,10 +9,11 @@ import {
9
9
  getProfiles,
10
10
  getProfilePath,
11
11
  setDefaultProfile,
12
- profileExists
12
+ profileExists,
13
+ createProfileFromTemplate
13
14
  } from '../profiles.js';
14
15
  import { parseCCSwitchSQL, parseAllApiHubJSON, detectFileFormat } from '../parsers.js';
15
- import { extractFromText, getDomainName, sanitizeProfileName, convertToClaudeSettings } from '../utils.js';
16
+ import { extractFromText, getDomainName, sanitizeProfileName } from '../utils.js';
16
17
 
17
18
  // 生成唯一的 profile 名称(如果重复则加后缀 token2, token3...)
18
19
  function getUniqueProfileName(baseName, usedNames) {
@@ -191,9 +192,14 @@ export function importCommand(program) {
191
192
  }
192
193
  }
193
194
 
194
- // 转换并保存配置(影子配置只包含 API 凭证)
195
- const settings = convertToClaudeSettings(provider);
196
- fs.writeFileSync(profilePath, JSON.stringify(settings, null, 2));
195
+ // provider 中提取 API 凭证
196
+ const config = provider.settingsConfig || {};
197
+ const env = config.env || {};
198
+ const apiKey = env.ANTHROPIC_AUTH_TOKEN || env.ANTHROPIC_API_KEY || config.apiKey || '';
199
+ const apiUrl = env.ANTHROPIC_BASE_URL || config.apiUrl || provider.websiteUrl || '';
200
+
201
+ // 使用主配置模板创建完整的 profile(确保有 env 对象)
202
+ createProfileFromTemplate(profileName, apiUrl, apiKey);
197
203
  console.log(chalk.green(`✓ ${profileName}`));
198
204
  imported++;
199
205
  }
@@ -318,12 +324,6 @@ export async function interactiveImport() {
318
324
  const finalApiUrl = apiUrl || 'https://api.anthropic.com';
319
325
  const finalApiKey = apiKey || tokens[0] || '';
320
326
 
321
- // 影子配置只存储 API 凭证
322
- const settings = {
323
- ANTHROPIC_AUTH_TOKEN: finalApiKey,
324
- ANTHROPIC_BASE_URL: finalApiUrl
325
- };
326
-
327
327
  ensureDirs();
328
328
  const profilePath = getProfilePath(profileName);
329
329
 
@@ -343,7 +343,8 @@ export async function interactiveImport() {
343
343
  }
344
344
  }
345
345
 
346
- fs.writeFileSync(profilePath, JSON.stringify(settings, null, 2));
346
+ // 使用主配置模板创建完整的 profile(确保有 env 对象)
347
+ createProfileFromTemplate(profileName, finalApiUrl, finalApiKey);
347
348
  console.log(chalk.green(`\n✓ Profile "${profileName}" 已保存到 ${profilePath}`));
348
349
 
349
350
  // 如果是第一个 profile,设为默认
package/src/profiles.js CHANGED
@@ -86,6 +86,29 @@ export function getClaudeSettingsTemplate() {
86
86
  return null;
87
87
  }
88
88
 
89
+ // 确保主配置中有 CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC 设置
90
+ // 如果没有则添加,并返回更新后的模板
91
+ export function ensureDisableNonessentialTraffic() {
92
+ const template = getClaudeSettingsTemplate();
93
+ if (!template) {
94
+ return null;
95
+ }
96
+
97
+ // 确保 env 对象存在
98
+ if (!template.env) {
99
+ template.env = {};
100
+ }
101
+
102
+ // 检查是否已有该设置
103
+ if (template.env.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC !== '1') {
104
+ template.env.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC = '1';
105
+ // 保存回主配置
106
+ fs.writeFileSync(CLAUDE_SETTINGS_PATH, JSON.stringify(template, null, 2));
107
+ }
108
+
109
+ return template;
110
+ }
111
+
89
112
  // 读取 profile 配置
90
113
  export function readProfile(name) {
91
114
  const profilePath = getProfilePath(name);
@@ -108,6 +131,9 @@ export function saveProfile(name, settings) {
108
131
 
109
132
  // 创建基于主配置的 profile(复制 ~/.claude/settings.json 并设置 env)
110
133
  export function createProfileFromTemplate(name, apiUrl, apiKey) {
134
+ // 先确保主配置有 CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC 设置
135
+ ensureDisableNonessentialTraffic();
136
+
111
137
  const template = getClaudeSettingsTemplate() || {};
112
138
 
113
139
  // 确保 env 对象存在
@@ -125,6 +151,9 @@ export function createProfileFromTemplate(name, apiUrl, apiKey) {
125
151
 
126
152
  // 同步主配置到 profile(保留 profile 的 API 凭证)
127
153
  export function syncProfileWithTemplate(name) {
154
+ // 先确保主配置有 CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC 设置
155
+ ensureDisableNonessentialTraffic();
156
+
128
157
  const template = getClaudeSettingsTemplate();
129
158
  if (!template) {
130
159
  return null;