@tkpdx01/ccc 1.2.6 → 1.2.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.
@@ -1,9 +1,10 @@
1
- export { listCommand } from './list.js';
2
- export { useCommand } from './use.js';
3
- export { showCommand } from './show.js';
4
- export { importCommand } from './import.js';
5
- export { newCommand } from './new.js';
6
- export { editCommand } from './edit.js';
7
- export { deleteCommand } from './delete.js';
8
- export { helpCommand, showHelp } from './help.js';
9
-
1
+ export { listCommand } from './list.js';
2
+ export { useCommand } from './use.js';
3
+ export { showCommand } from './show.js';
4
+ export { importCommand } from './import.js';
5
+ export { newCommand } from './new.js';
6
+ export { editCommand } from './edit.js';
7
+ export { deleteCommand } from './delete.js';
8
+ export { syncCommand } from './sync.js';
9
+ export { helpCommand, showHelp } from './help.js';
10
+
@@ -1,58 +1,46 @@
1
- import fs from 'fs';
2
- import chalk from 'chalk';
3
- import Table from 'cli-table3';
4
- import { getProfiles, getDefaultProfile, getProfilePath } from '../profiles.js';
5
-
6
- export function listCommand(program) {
7
- program
8
- .command('list')
9
- .alias('ls')
10
- .description('列出所有 profiles')
11
- .action(() => {
12
- const profiles = getProfiles();
13
- const defaultProfile = getDefaultProfile();
14
-
15
- if (profiles.length === 0) {
16
- console.log(chalk.yellow('没有可用的 profiles'));
17
- console.log(chalk.gray('使用 "ccc import" 导入配置'));
18
- return;
19
- }
20
-
21
- const table = new Table({
22
- head: [chalk.cyan('#'), chalk.cyan('Profile'), chalk.cyan('ANTHROPIC_BASE_URL')],
23
- style: { head: [], border: [] },
24
- chars: {
25
- 'top': '─', 'top-mid': '', 'top-left': '', 'top-right': '',
26
- 'bottom': '', 'bottom-mid': '', 'bottom-left': '', 'bottom-right': '',
27
- 'left': '│', 'left-mid': '', 'mid': '', 'mid-mid': '┼',
28
- 'right': '│', 'right-mid': '┤', 'middle': '│'
29
- }
30
- });
31
-
32
- profiles.forEach((p, index) => {
33
- const isDefault = p === defaultProfile;
34
- const profilePath = getProfilePath(p);
35
- let baseUrl = chalk.gray('(未设置)');
36
-
37
- try {
38
- const content = fs.readFileSync(profilePath, 'utf-8');
39
- // 用正则从 JSON 文件内容中提取 ANTHROPIC_BASE_URL(新格式直接在顶层)
40
- const match = content.match(/"ANTHROPIC_BASE_URL"\s*:\s*"([^"]+)"/);
41
- if (match && match[1]) {
42
- baseUrl = match[1];
43
- }
44
- } catch {
45
- baseUrl = chalk.red('(读取失败)');
46
- }
47
-
48
- const num = isDefault ? chalk.green(`${index + 1}`) : chalk.gray(`${index + 1}`);
49
- const name = isDefault ? chalk.green(`${p} *`) : p;
50
- table.push([num, name, baseUrl]);
51
- });
52
-
53
- console.log();
54
- console.log(table.toString());
55
- console.log(chalk.gray(`\n 共 ${profiles.length} 个配置,* 表示默认,可用序号或名称启动\n`));
56
- });
57
- }
58
-
1
+ import chalk from 'chalk';
2
+ import Table from 'cli-table3';
3
+ import { getProfiles, getDefaultProfile, getProfileCredentials } from '../profiles.js';
4
+
5
+ export function listCommand(program) {
6
+ program
7
+ .command('list')
8
+ .alias('ls')
9
+ .description('列出所有 profiles')
10
+ .action(() => {
11
+ const profiles = getProfiles();
12
+ const defaultProfile = getDefaultProfile();
13
+
14
+ if (profiles.length === 0) {
15
+ console.log(chalk.yellow('没有可用的 profiles'));
16
+ console.log(chalk.gray('使用 "ccc import" 导入配置'));
17
+ return;
18
+ }
19
+
20
+ const table = new Table({
21
+ head: [chalk.cyan('#'), chalk.cyan('Profile'), chalk.cyan('ANTHROPIC_BASE_URL')],
22
+ style: { head: [], border: [] },
23
+ chars: {
24
+ 'top': '─', 'top-mid': '┬', 'top-left': '┌', 'top-right': '┐',
25
+ 'bottom': '─', 'bottom-mid': '', 'bottom-left': '', 'bottom-right': '',
26
+ 'left': '', 'left-mid': '', 'mid': '', 'mid-mid': '',
27
+ 'right': '│', 'right-mid': '', 'middle': ''
28
+ }
29
+ });
30
+
31
+ profiles.forEach((p, index) => {
32
+ const isDefault = p === defaultProfile;
33
+ const { apiUrl } = getProfileCredentials(p);
34
+ const baseUrl = apiUrl || chalk.gray('(未设置)');
35
+
36
+ const num = isDefault ? chalk.green(`${index + 1}`) : chalk.gray(`${index + 1}`);
37
+ const name = isDefault ? chalk.green(`${p} *`) : p;
38
+ table.push([num, name, baseUrl]);
39
+ });
40
+
41
+ console.log();
42
+ console.log(table.toString());
43
+ console.log(chalk.gray(`\n 共 ${profiles.length} 个配置,* 表示默认,可用序号或名称启动\n`));
44
+ });
45
+ }
46
+
@@ -1,115 +1,109 @@
1
- import chalk from 'chalk';
2
- import inquirer from 'inquirer';
3
- import {
4
- ensureDirs,
5
- getProfiles,
6
- profileExists,
7
- saveProfile,
8
- setDefaultProfile
9
- } from '../profiles.js';
10
- import { launchClaude } from '../launch.js';
11
-
12
- export function newCommand(program) {
13
- program
14
- .command('new [name]')
15
- .description('创建新的影子配置(只包含 API 凭证)')
16
- .action(async (name) => {
17
- // 如果没有提供名称,询问
18
- if (!name) {
19
- const { profileName } = await inquirer.prompt([
20
- {
21
- type: 'input',
22
- name: 'profileName',
23
- message: '配置名称:',
24
- validate: (input) => input.trim() ? true : '请输入配置名称'
25
- }
26
- ]);
27
- name = profileName;
28
- }
29
-
30
- // 检查是否已存在
31
- if (profileExists(name)) {
32
- const { overwrite } = await inquirer.prompt([
33
- {
34
- type: 'confirm',
35
- name: 'overwrite',
36
- message: `配置 "${name}" 已存在,是否覆盖?`,
37
- default: false
38
- }
39
- ]);
40
- if (!overwrite) {
41
- console.log(chalk.yellow('已取消'));
42
- process.exit(0);
43
- }
44
- }
45
-
46
- const { apiUrl, apiKey, finalName } = await inquirer.prompt([
47
- {
48
- type: 'input',
49
- name: 'apiUrl',
50
- message: 'ANTHROPIC_BASE_URL:',
51
- default: 'https://api.anthropic.com'
52
- },
53
- {
54
- type: 'input',
55
- name: 'apiKey',
56
- message: 'ANTHROPIC_AUTH_TOKEN:',
57
- default: ''
58
- },
59
- {
60
- type: 'input',
61
- name: 'finalName',
62
- message: 'Profile 名称:',
63
- default: name
64
- }
65
- ]);
66
-
67
- // 如果名称改变了,检查新名称是否存在
68
- if (finalName !== name && profileExists(finalName)) {
69
- const { overwriteNew } = await inquirer.prompt([
70
- {
71
- type: 'confirm',
72
- name: 'overwriteNew',
73
- message: `配置 "${finalName}" 已存在,是否覆盖?`,
74
- default: false
75
- }
76
- ]);
77
- if (!overwriteNew) {
78
- console.log(chalk.yellow('已取消'));
79
- process.exit(0);
80
- }
81
- }
82
-
83
- // 影子配置只存储 API 凭证
84
- const newSettings = {
85
- ANTHROPIC_AUTH_TOKEN: apiKey,
86
- ANTHROPIC_BASE_URL: apiUrl
87
- };
88
-
89
- ensureDirs();
90
- saveProfile(finalName, newSettings);
91
- console.log(chalk.green(`\n✓ 配置 "${finalName}" 已创建`));
92
-
93
- // 如果是第一个 profile,设为默认
94
- const profiles = getProfiles();
95
- if (profiles.length === 1) {
96
- setDefaultProfile(finalName);
97
- console.log(chalk.green(`✓ 已设为默认配置`));
98
- }
99
-
100
- // 询问是否立即使用
101
- const { useNow } = await inquirer.prompt([
102
- {
103
- type: 'confirm',
104
- name: 'useNow',
105
- message: '是否立即启动 Claude?',
106
- default: false
107
- }
108
- ]);
109
-
110
- if (useNow) {
111
- launchClaude(finalName);
112
- }
113
- });
114
- }
115
-
1
+ import chalk from 'chalk';
2
+ import inquirer from 'inquirer';
3
+ import {
4
+ ensureDirs,
5
+ getProfiles,
6
+ profileExists,
7
+ createProfileFromTemplate,
8
+ setDefaultProfile
9
+ } from '../profiles.js';
10
+ import { launchClaude } from '../launch.js';
11
+
12
+ export function newCommand(program) {
13
+ program
14
+ .command('new [name]')
15
+ .description('创建新的配置(基于 ~/.claude/settings.json,在 env 中设置 API 凭证)')
16
+ .action(async (name) => {
17
+ // 如果没有提供名称,询问
18
+ if (!name) {
19
+ const { profileName } = await inquirer.prompt([
20
+ {
21
+ type: 'input',
22
+ name: 'profileName',
23
+ message: '配置名称:',
24
+ validate: (input) => input.trim() ? true : '请输入配置名称'
25
+ }
26
+ ]);
27
+ name = profileName;
28
+ }
29
+
30
+ // 检查是否已存在
31
+ if (profileExists(name)) {
32
+ const { overwrite } = await inquirer.prompt([
33
+ {
34
+ type: 'confirm',
35
+ name: 'overwrite',
36
+ message: `配置 "${name}" 已存在,是否覆盖?`,
37
+ default: false
38
+ }
39
+ ]);
40
+ if (!overwrite) {
41
+ console.log(chalk.yellow('已取消'));
42
+ process.exit(0);
43
+ }
44
+ }
45
+
46
+ const { apiUrl, apiKey, finalName } = await inquirer.prompt([
47
+ {
48
+ type: 'input',
49
+ name: 'apiUrl',
50
+ message: 'ANTHROPIC_BASE_URL:',
51
+ default: 'https://api.anthropic.com'
52
+ },
53
+ {
54
+ type: 'input',
55
+ name: 'apiKey',
56
+ message: 'ANTHROPIC_AUTH_TOKEN:',
57
+ default: ''
58
+ },
59
+ {
60
+ type: 'input',
61
+ name: 'finalName',
62
+ message: 'Profile 名称:',
63
+ default: name
64
+ }
65
+ ]);
66
+
67
+ // 如果名称改变了,检查新名称是否存在
68
+ if (finalName !== name && profileExists(finalName)) {
69
+ const { overwriteNew } = await inquirer.prompt([
70
+ {
71
+ type: 'confirm',
72
+ name: 'overwriteNew',
73
+ message: `配置 "${finalName}" 已存在,是否覆盖?`,
74
+ default: false
75
+ }
76
+ ]);
77
+ if (!overwriteNew) {
78
+ console.log(chalk.yellow('已取消'));
79
+ process.exit(0);
80
+ }
81
+ }
82
+
83
+ ensureDirs();
84
+ createProfileFromTemplate(finalName, apiUrl, apiKey);
85
+ console.log(chalk.green(`\n✓ 配置 "${finalName}" 已创建(基于 ~/.claude/settings.json)`));
86
+
87
+ // 如果是第一个 profile,设为默认
88
+ const profiles = getProfiles();
89
+ if (profiles.length === 1) {
90
+ setDefaultProfile(finalName);
91
+ console.log(chalk.green(`✓ 已设为默认配置`));
92
+ }
93
+
94
+ // 询问是否立即使用
95
+ const { useNow } = await inquirer.prompt([
96
+ {
97
+ type: 'confirm',
98
+ name: 'useNow',
99
+ message: '是否立即启动 Claude?',
100
+ default: false
101
+ }
102
+ ]);
103
+
104
+ if (useNow) {
105
+ launchClaude(finalName);
106
+ }
107
+ });
108
+ }
109
+
@@ -1,68 +1,68 @@
1
- import chalk from 'chalk';
2
- import inquirer from 'inquirer';
3
- import {
4
- getProfiles,
5
- getDefaultProfile,
6
- profileExists,
7
- getProfilePath,
8
- readProfile
9
- } from '../profiles.js';
10
- import { formatValue } from '../utils.js';
11
-
12
- export function showCommand(program) {
13
- program
14
- .command('show [profile]')
15
- .description('显示 profile 的完整配置')
16
- .action(async (profile) => {
17
- const profiles = getProfiles();
18
-
19
- if (profiles.length === 0) {
20
- console.log(chalk.yellow('没有可用的 profiles'));
21
- process.exit(0);
22
- }
23
-
24
- // 如果没有指定 profile,交互选择
25
- if (!profile) {
26
- const defaultProfile = getDefaultProfile();
27
- const { selectedProfile } = await inquirer.prompt([
28
- {
29
- type: 'list',
30
- name: 'selectedProfile',
31
- message: '选择要查看的配置:',
32
- choices: profiles,
33
- default: defaultProfile
34
- }
35
- ]);
36
- profile = selectedProfile;
37
- }
38
-
39
- if (!profileExists(profile)) {
40
- console.log(chalk.red(`Profile "${profile}" 不存在`));
41
- process.exit(1);
42
- }
43
-
44
- const profilePath = getProfilePath(profile);
45
- const settings = readProfile(profile);
46
- const isDefault = getDefaultProfile() === profile;
47
-
48
- console.log(chalk.cyan.bold(`\n Profile: ${profile}`) + (isDefault ? chalk.green(' (默认)') : ''));
49
- console.log(chalk.gray(` 路径: ${profilePath}\n`));
50
-
51
- // 格式化显示配置
52
- Object.entries(settings).forEach(([key, value]) => {
53
- const formattedValue = formatValue(key, value);
54
- if ((key === 'apiKey' || key === 'ANTHROPIC_AUTH_TOKEN') && value) {
55
- console.log(` ${chalk.cyan(key)}: ${chalk.yellow(formattedValue)}`);
56
- } else if (typeof value === 'boolean') {
57
- console.log(` ${chalk.cyan(key)}: ${value ? chalk.green(formattedValue) : chalk.red(formattedValue)}`);
58
- } else if (typeof value === 'object') {
59
- console.log(` ${chalk.cyan(key)}: ${chalk.gray(formattedValue)}`);
60
- } else {
61
- console.log(` ${chalk.cyan(key)}: ${chalk.white(formattedValue)}`);
62
- }
63
- });
64
-
65
- console.log();
66
- });
67
- }
68
-
1
+ import chalk from 'chalk';
2
+ import inquirer from 'inquirer';
3
+ import {
4
+ getProfiles,
5
+ getDefaultProfile,
6
+ profileExists,
7
+ getProfilePath,
8
+ readProfile
9
+ } from '../profiles.js';
10
+ import { formatValue } from '../utils.js';
11
+
12
+ export function showCommand(program) {
13
+ program
14
+ .command('show [profile]')
15
+ .description('显示 profile 的完整配置')
16
+ .action(async (profile) => {
17
+ const profiles = getProfiles();
18
+
19
+ if (profiles.length === 0) {
20
+ console.log(chalk.yellow('没有可用的 profiles'));
21
+ process.exit(0);
22
+ }
23
+
24
+ // 如果没有指定 profile,交互选择
25
+ if (!profile) {
26
+ const defaultProfile = getDefaultProfile();
27
+ const { selectedProfile } = await inquirer.prompt([
28
+ {
29
+ type: 'list',
30
+ name: 'selectedProfile',
31
+ message: '选择要查看的配置:',
32
+ choices: profiles,
33
+ default: defaultProfile
34
+ }
35
+ ]);
36
+ profile = selectedProfile;
37
+ }
38
+
39
+ if (!profileExists(profile)) {
40
+ console.log(chalk.red(`Profile "${profile}" 不存在`));
41
+ process.exit(1);
42
+ }
43
+
44
+ const profilePath = getProfilePath(profile);
45
+ const settings = readProfile(profile);
46
+ const isDefault = getDefaultProfile() === profile;
47
+
48
+ console.log(chalk.cyan.bold(`\n Profile: ${profile}`) + (isDefault ? chalk.green(' (默认)') : ''));
49
+ console.log(chalk.gray(` 路径: ${profilePath}\n`));
50
+
51
+ // 格式化显示配置
52
+ Object.entries(settings).forEach(([key, value]) => {
53
+ const formattedValue = formatValue(key, value);
54
+ if ((key === 'apiKey' || key === 'ANTHROPIC_AUTH_TOKEN') && value) {
55
+ console.log(` ${chalk.cyan(key)}: ${chalk.yellow(formattedValue)}`);
56
+ } else if (typeof value === 'boolean') {
57
+ console.log(` ${chalk.cyan(key)}: ${value ? chalk.green(formattedValue) : chalk.red(formattedValue)}`);
58
+ } else if (typeof value === 'object') {
59
+ console.log(` ${chalk.cyan(key)}: ${chalk.gray(formattedValue)}`);
60
+ } else {
61
+ console.log(` ${chalk.cyan(key)}: ${chalk.white(formattedValue)}`);
62
+ }
63
+ });
64
+
65
+ console.log();
66
+ });
67
+ }
68
+
@@ -0,0 +1,93 @@
1
+ import chalk from 'chalk';
2
+ import inquirer from 'inquirer';
3
+ import {
4
+ getProfiles,
5
+ syncProfileWithTemplate,
6
+ getClaudeSettingsTemplate,
7
+ resolveProfile
8
+ } from '../profiles.js';
9
+
10
+ export function syncCommand(program) {
11
+ program
12
+ .command('sync [profile]')
13
+ .description('同步 ~/.claude/settings.json 到 profile(保留 API 凭证)')
14
+ .option('-a, --all', '同步所有 profiles')
15
+ .action(async (profile, options) => {
16
+ // 检查主配置是否存在
17
+ const template = getClaudeSettingsTemplate();
18
+ if (!template) {
19
+ console.log(chalk.red('未找到 ~/.claude/settings.json'));
20
+ console.log(chalk.gray('请确保 Claude Code 已正确安装'));
21
+ process.exit(1);
22
+ }
23
+
24
+ const profiles = getProfiles();
25
+
26
+ if (profiles.length === 0) {
27
+ console.log(chalk.yellow('没有可用的 profiles'));
28
+ console.log(chalk.gray('使用 "ccc new" 创建配置'));
29
+ process.exit(0);
30
+ }
31
+
32
+ // 同步所有 profiles
33
+ if (options.all) {
34
+ const { confirm } = await inquirer.prompt([
35
+ {
36
+ type: 'confirm',
37
+ name: 'confirm',
38
+ message: `确定要同步所有 ${profiles.length} 个 profiles 吗?`,
39
+ default: false
40
+ }
41
+ ]);
42
+
43
+ if (!confirm) {
44
+ console.log(chalk.yellow('已取消'));
45
+ process.exit(0);
46
+ }
47
+
48
+ console.log(chalk.cyan('\n开始同步所有 profiles...\n'));
49
+
50
+ let successCount = 0;
51
+ for (const p of profiles) {
52
+ const result = syncProfileWithTemplate(p);
53
+ if (result) {
54
+ console.log(chalk.green(` ✓ ${p}`));
55
+ successCount++;
56
+ } else {
57
+ console.log(chalk.red(` ✗ ${p} (同步失败)`));
58
+ }
59
+ }
60
+
61
+ console.log(chalk.green(`\n✓ 已同步 ${successCount}/${profiles.length} 个 profiles`));
62
+ return;
63
+ }
64
+
65
+ // 同步单个 profile
66
+ if (!profile) {
67
+ const { selectedProfile } = await inquirer.prompt([
68
+ {
69
+ type: 'list',
70
+ name: 'selectedProfile',
71
+ message: '选择要同步的配置:',
72
+ choices: profiles
73
+ }
74
+ ]);
75
+ profile = selectedProfile;
76
+ } else {
77
+ const resolved = resolveProfile(profile);
78
+ if (!resolved) {
79
+ console.log(chalk.red(`Profile "${profile}" 不存在`));
80
+ process.exit(1);
81
+ }
82
+ profile = resolved;
83
+ }
84
+
85
+ const result = syncProfileWithTemplate(profile);
86
+ if (result) {
87
+ console.log(chalk.green(`\n✓ Profile "${profile}" 已同步(保留了 API 凭证)`));
88
+ } else {
89
+ console.log(chalk.red(`\n✗ 同步失败`));
90
+ process.exit(1);
91
+ }
92
+ });
93
+ }
@@ -1,19 +1,19 @@
1
- import chalk from 'chalk';
2
- import { profileExists, setDefaultProfile } from '../profiles.js';
3
-
4
- export function useCommand(program) {
5
- program
6
- .command('use <profile>')
7
- .description('设置默认 profile')
8
- .action((profile) => {
9
- if (!profileExists(profile)) {
10
- console.log(chalk.red(`Profile "${profile}" 不存在`));
11
- console.log(chalk.yellow(`使用 "ccc list" 查看可用的 profiles`));
12
- process.exit(1);
13
- }
14
-
15
- setDefaultProfile(profile);
16
- console.log(chalk.green(`✓ 默认 profile 已设置为 "${profile}"`));
17
- });
18
- }
19
-
1
+ import chalk from 'chalk';
2
+ import { profileExists, setDefaultProfile } from '../profiles.js';
3
+
4
+ export function useCommand(program) {
5
+ program
6
+ .command('use <profile>')
7
+ .description('设置默认 profile')
8
+ .action((profile) => {
9
+ if (!profileExists(profile)) {
10
+ console.log(chalk.red(`Profile "${profile}" 不存在`));
11
+ console.log(chalk.yellow(`使用 "ccc list" 查看可用的 profiles`));
12
+ process.exit(1);
13
+ }
14
+
15
+ setDefaultProfile(profile);
16
+ console.log(chalk.green(`✓ 默认 profile 已设置为 "${profile}"`));
17
+ });
18
+ }
19
+
package/src/config.js CHANGED
@@ -1,9 +1,9 @@
1
- import path from 'path';
2
- import os from 'os';
3
-
4
- // 配置文件存储目录
5
- export const CONFIG_DIR = path.join(os.homedir(), '.ccc');
6
- export const PROFILES_DIR = path.join(CONFIG_DIR, 'profiles');
7
- export const DEFAULT_FILE = path.join(CONFIG_DIR, 'default');
8
- export const CLAUDE_SETTINGS_PATH = path.join(os.homedir(), '.claude', 'settings.json');
9
-
1
+ import path from 'path';
2
+ import os from 'os';
3
+
4
+ // 配置文件存储目录
5
+ export const CONFIG_DIR = path.join(os.homedir(), '.ccc');
6
+ export const PROFILES_DIR = path.join(CONFIG_DIR, 'profiles');
7
+ export const DEFAULT_FILE = path.join(CONFIG_DIR, 'default');
8
+ export const CLAUDE_SETTINGS_PATH = path.join(os.homedir(), '.claude', 'settings.json');
9
+