@tkpdx01/ccc 1.2.5 → 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,10 +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 { syncCommand } from './sync.js';
7
- export { editCommand } from './edit.js';
8
- export { deleteCommand } from './delete.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 { 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,143 +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
- getClaudeSettingsTemplate
10
- } from '../profiles.js';
11
- import { launchClaude } from '../launch.js';
12
-
13
- export function newCommand(program) {
14
- program
15
- .command('new [name]')
16
- .description('基于 ~/.claude/settings.json 模板创建新配置')
17
- .action(async (name) => {
18
- const template = getClaudeSettingsTemplate();
19
-
20
- // 显示模板状态
21
- if (template) {
22
- console.log(chalk.green('✓ 检测到模板文件: ~/.claude/settings.json'));
23
- console.log(chalk.gray(' 将基于此模板创建新配置\n'));
24
- } else {
25
- console.log(chalk.yellow('! 未找到模板文件: ~/.claude/settings.json'));
26
- console.log(chalk.gray(' 将创建空白配置\n'));
27
- }
28
-
29
- // 如果没有提供名称,询问
30
- if (!name) {
31
- const { profileName } = await inquirer.prompt([
32
- {
33
- type: 'input',
34
- name: 'profileName',
35
- message: '配置名称:',
36
- validate: (input) => input.trim() ? true : '请输入配置名称'
37
- }
38
- ]);
39
- name = profileName;
40
- }
41
-
42
- // 检查是否已存在
43
- if (profileExists(name)) {
44
- const { overwrite } = await inquirer.prompt([
45
- {
46
- type: 'confirm',
47
- name: 'overwrite',
48
- message: `配置 "${name}" 已存在,是否覆盖?`,
49
- default: false
50
- }
51
- ]);
52
- if (!overwrite) {
53
- console.log(chalk.yellow('已取消'));
54
- process.exit(0);
55
- }
56
- }
57
-
58
- // 基于模板创建,但需要用户填写 API 信息
59
- const baseSettings = template || {};
60
-
61
- // 显示模板中已有的设置(如果有)
62
- if (template) {
63
- console.log(chalk.cyan('模板中的现有设置:'));
64
- if (template.apiUrl) console.log(chalk.gray(` API URL: ${template.apiUrl}`));
65
- if (template.apiKey) console.log(chalk.gray(` API Key: ${template.apiKey.substring(0, 10)}...`));
66
- const otherKeys = Object.keys(template).filter(k => !['apiUrl', 'apiKey'].includes(k));
67
- if (otherKeys.length > 0) {
68
- console.log(chalk.gray(` 其他设置: ${otherKeys.join(', ')}`));
69
- }
70
- console.log();
71
- }
72
-
73
- const { apiUrl, apiKey, finalName } = await inquirer.prompt([
74
- {
75
- type: 'input',
76
- name: 'apiUrl',
77
- message: 'API URL:',
78
- default: baseSettings.apiUrl || 'https://api.anthropic.com'
79
- },
80
- {
81
- type: 'input',
82
- name: 'apiKey',
83
- message: 'API Key:',
84
- default: baseSettings.apiKey || ''
85
- },
86
- {
87
- type: 'input',
88
- name: 'finalName',
89
- message: 'Profile 名称:',
90
- default: name
91
- }
92
- ]);
93
-
94
- // 如果名称改变了,检查新名称是否存在
95
- if (finalName !== name && profileExists(finalName)) {
96
- const { overwriteNew } = await inquirer.prompt([
97
- {
98
- type: 'confirm',
99
- name: 'overwriteNew',
100
- message: `配置 "${finalName}" 已存在,是否覆盖?`,
101
- default: false
102
- }
103
- ]);
104
- if (!overwriteNew) {
105
- console.log(chalk.yellow('已取消'));
106
- process.exit(0);
107
- }
108
- }
109
-
110
- // 合并设置:保留模板中的其他设置,覆盖 API 相关设置
111
- const newSettings = {
112
- ...baseSettings,
113
- apiUrl,
114
- apiKey
115
- };
116
-
117
- ensureDirs();
118
- saveProfile(finalName, newSettings);
119
- console.log(chalk.green(`\n✓ 配置 "${finalName}" 已创建`));
120
-
121
- // 如果是第一个 profile,设为默认
122
- const profiles = getProfiles();
123
- if (profiles.length === 1) {
124
- setDefaultProfile(finalName);
125
- console.log(chalk.green(`✓ 已设为默认配置`));
126
- }
127
-
128
- // 询问是否立即使用
129
- const { useNow } = await inquirer.prompt([
130
- {
131
- type: 'confirm',
132
- name: 'useNow',
133
- message: '是否立即启动 Claude?',
134
- default: false
135
- }
136
- ]);
137
-
138
- if (useNow) {
139
- launchClaude(finalName);
140
- }
141
- });
142
- }
143
-
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' && 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
+