@tkpdx01/ccc 1.2.7 → 1.3.0

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,10 +1,11 @@
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
+ 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 { webdavCommand } from './webdav.js';
10
+ export { helpCommand, showHelp } from './help.js';
11
+
@@ -1,46 +1,46 @@
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
+ 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,109 +1,109 @@
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
+ 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
+
@@ -1,93 +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
+ 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
+ }