@x-all-in-one/coding-helper 0.0.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.
- package/README.md +93 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +15 -0
- package/dist/commands/auth.d.ts +1 -0
- package/dist/commands/auth.js +148 -0
- package/dist/commands/config.d.ts +1 -0
- package/dist/commands/config.js +133 -0
- package/dist/commands/doctor.d.ts +1 -0
- package/dist/commands/doctor.js +128 -0
- package/dist/commands/index.d.ts +4 -0
- package/dist/commands/index.js +4 -0
- package/dist/commands/lang.d.ts +1 -0
- package/dist/commands/lang.js +29 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/lib/api-validator.d.ts +16 -0
- package/dist/lib/api-validator.js +75 -0
- package/dist/lib/claude-code-manager.d.ts +79 -0
- package/dist/lib/claude-code-manager.js +201 -0
- package/dist/lib/command.d.ts +10 -0
- package/dist/lib/command.js +174 -0
- package/dist/lib/config.d.ts +37 -0
- package/dist/lib/config.js +92 -0
- package/dist/lib/i18n.d.ts +20 -0
- package/dist/lib/i18n.js +148 -0
- package/dist/lib/tool-manager.d.ts +24 -0
- package/dist/lib/tool-manager.js +256 -0
- package/dist/lib/wizard.d.ts +44 -0
- package/dist/lib/wizard.js +673 -0
- package/dist/locales/en_US.json +201 -0
- package/dist/locales/zh_CN.json +201 -0
- package/dist/utils/logger.d.ts +17 -0
- package/dist/utils/logger.js +41 -0
- package/dist/utils/string-width.d.ts +38 -0
- package/dist/utils/string-width.js +130 -0
- package/package.json +66 -0
package/README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# coding-helper
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
## Getting started
|
|
6
|
+
|
|
7
|
+
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
|
8
|
+
|
|
9
|
+
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
|
10
|
+
|
|
11
|
+
## Add your files
|
|
12
|
+
|
|
13
|
+
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
|
|
14
|
+
- [ ] [Add files using the command line](https://docs.gitlab.com/topics/git/add_files/#add-files-to-a-git-repository) or push an existing Git repository with the following command:
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
cd existing_repo
|
|
18
|
+
git remote add origin https://gitlab.yeaosound.com/xaio-ai/coding-helper.git
|
|
19
|
+
git branch -M main
|
|
20
|
+
git push -uf origin main
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Integrate with your tools
|
|
24
|
+
|
|
25
|
+
- [ ] [Set up project integrations](https://gitlab.yeaosound.com/xaio-ai/coding-helper/-/settings/integrations)
|
|
26
|
+
|
|
27
|
+
## Collaborate with your team
|
|
28
|
+
|
|
29
|
+
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
|
|
30
|
+
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
|
31
|
+
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
|
32
|
+
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
|
33
|
+
- [ ] [Set auto-merge](https://docs.gitlab.com/user/project/merge_requests/auto_merge/)
|
|
34
|
+
|
|
35
|
+
## Test and Deploy
|
|
36
|
+
|
|
37
|
+
Use the built-in continuous integration in GitLab.
|
|
38
|
+
|
|
39
|
+
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/)
|
|
40
|
+
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
|
|
41
|
+
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
|
42
|
+
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
|
43
|
+
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
|
44
|
+
|
|
45
|
+
***
|
|
46
|
+
|
|
47
|
+
# Editing this README
|
|
48
|
+
|
|
49
|
+
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
|
50
|
+
|
|
51
|
+
## Suggestions for a good README
|
|
52
|
+
|
|
53
|
+
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
|
54
|
+
|
|
55
|
+
## Name
|
|
56
|
+
Choose a self-explaining name for your project.
|
|
57
|
+
|
|
58
|
+
## Description
|
|
59
|
+
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
|
60
|
+
|
|
61
|
+
## Badges
|
|
62
|
+
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
|
63
|
+
|
|
64
|
+
## Visuals
|
|
65
|
+
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
|
66
|
+
|
|
67
|
+
## Installation
|
|
68
|
+
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
|
69
|
+
|
|
70
|
+
## Usage
|
|
71
|
+
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
|
72
|
+
|
|
73
|
+
## Support
|
|
74
|
+
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
|
75
|
+
|
|
76
|
+
## Roadmap
|
|
77
|
+
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
|
78
|
+
|
|
79
|
+
## Contributing
|
|
80
|
+
State if you are open to contributions and what your requirements are for accepting them.
|
|
81
|
+
|
|
82
|
+
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
|
83
|
+
|
|
84
|
+
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
|
85
|
+
|
|
86
|
+
## Authors and acknowledgment
|
|
87
|
+
Show your appreciation to those who have contributed to the project.
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
For open source projects, say how it is licensed.
|
|
91
|
+
|
|
92
|
+
## Project status
|
|
93
|
+
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from './lib/command.js';
|
|
3
|
+
import { i18n } from './lib/i18n.js';
|
|
4
|
+
async function main() {
|
|
5
|
+
const args = process.argv.slice(2);
|
|
6
|
+
const command = new Command();
|
|
7
|
+
try {
|
|
8
|
+
await command.execute(args);
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
console.error(`${i18n.t('cli.error_general')}`, error instanceof Error ? error.message : String(error));
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
main();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function authCommand(args: string[]): Promise<void>;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import inquirer from 'inquirer';
|
|
2
|
+
import ora from 'ora';
|
|
3
|
+
import { configManager } from '../lib/config.js';
|
|
4
|
+
import { i18n } from '../lib/i18n.js';
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
import { toolManager } from '../lib/tool-manager.js';
|
|
7
|
+
import { validateApiKey } from '../lib/api-validator.js';
|
|
8
|
+
import { DEFAULT_CONFIG } from '../lib/claude-code-manager.js';
|
|
9
|
+
/**
|
|
10
|
+
* 支持的工具列表
|
|
11
|
+
*/
|
|
12
|
+
const SUPPORTED_RELOAD_TOOLS = ['claude', 'claude-code'];
|
|
13
|
+
/**
|
|
14
|
+
* 重新加载配置到指定工具
|
|
15
|
+
*/
|
|
16
|
+
async function reloadToTool(tool) {
|
|
17
|
+
const normalizedTool = tool.toLowerCase();
|
|
18
|
+
if (!SUPPORTED_RELOAD_TOOLS.includes(normalizedTool)) {
|
|
19
|
+
console.log(chalk.red(i18n.t('auth.reload_tool_not_supported', { tool })));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const apiKey = configManager.getApiKey();
|
|
23
|
+
if (!apiKey) {
|
|
24
|
+
console.log(chalk.red(i18n.t('auth.reload_missing_config')));
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const models = configManager.getModels();
|
|
28
|
+
console.log(chalk.blue(i18n.t('auth.reloading', { tool: 'Claude Code' })));
|
|
29
|
+
try {
|
|
30
|
+
toolManager.loadModelConfig('claude-code', {
|
|
31
|
+
apiKey,
|
|
32
|
+
haikuModel: models.haikuModel || DEFAULT_CONFIG.ANTHROPIC_DEFAULT_HAIKU_MODEL,
|
|
33
|
+
sonnetModel: models.sonnetModel || DEFAULT_CONFIG.ANTHROPIC_DEFAULT_SONNET_MODEL,
|
|
34
|
+
opusModel: models.opusModel || DEFAULT_CONFIG.ANTHROPIC_DEFAULT_OPUS_MODEL
|
|
35
|
+
});
|
|
36
|
+
await new Promise(resolve => setTimeout(resolve, 800));
|
|
37
|
+
console.log(chalk.green(i18n.t('auth.reloaded', { tool: 'Claude Code' })));
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
console.log(chalk.red(i18n.t('auth.reload_failed')));
|
|
41
|
+
if (error instanceof Error) {
|
|
42
|
+
console.log(chalk.red(error.message));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* 撤销 API Key
|
|
48
|
+
*/
|
|
49
|
+
async function revokeApiKey() {
|
|
50
|
+
const { confirm } = await inquirer.prompt([
|
|
51
|
+
{
|
|
52
|
+
type: 'confirm',
|
|
53
|
+
name: 'confirm',
|
|
54
|
+
message: i18n.t('auth.revoke_confirm'),
|
|
55
|
+
default: false
|
|
56
|
+
}
|
|
57
|
+
]);
|
|
58
|
+
if (confirm) {
|
|
59
|
+
configManager.revokeApiKey();
|
|
60
|
+
console.log(chalk.green(i18n.t('auth.revoked')));
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
console.log(chalk.yellow(i18n.t('auth.not_revoked')));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* 交互式设置 API Key
|
|
68
|
+
*/
|
|
69
|
+
async function interactiveAuth() {
|
|
70
|
+
const { token } = await inquirer.prompt([
|
|
71
|
+
{
|
|
72
|
+
type: 'password',
|
|
73
|
+
name: 'token',
|
|
74
|
+
message: i18n.t('auth.token_prompt'),
|
|
75
|
+
validate: (input) => {
|
|
76
|
+
if (!input || input.trim().length === 0) {
|
|
77
|
+
return i18n.t('auth.token_required');
|
|
78
|
+
}
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
]);
|
|
83
|
+
// Validate API Key
|
|
84
|
+
const spinner = ora({
|
|
85
|
+
text: i18n.t('wizard.validating_api_key'),
|
|
86
|
+
spinner: 'dots'
|
|
87
|
+
}).start();
|
|
88
|
+
const validationResult = await validateApiKey(token.trim());
|
|
89
|
+
if (!validationResult.valid) {
|
|
90
|
+
if (validationResult.error === 'invalid_api_key') {
|
|
91
|
+
spinner.fail(chalk.red(i18n.t('wizard.api_key_invalid')));
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
spinner.fail(chalk.red(i18n.t('wizard.api_key_network_error')));
|
|
95
|
+
}
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
spinner.succeed(chalk.green(i18n.t('wizard.api_key_valid')));
|
|
99
|
+
configManager.setApiKey(token.trim());
|
|
100
|
+
console.log(chalk.green(i18n.t('auth.saved')));
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* 直接设置 API Key
|
|
104
|
+
*/
|
|
105
|
+
async function directAuth(token) {
|
|
106
|
+
const spinner = ora({
|
|
107
|
+
text: i18n.t('wizard.validating_api_key'),
|
|
108
|
+
spinner: 'star2'
|
|
109
|
+
}).start();
|
|
110
|
+
const validationResult = await validateApiKey(token);
|
|
111
|
+
await new Promise(resolve => setTimeout(resolve, 800));
|
|
112
|
+
if (!validationResult.valid) {
|
|
113
|
+
if (validationResult.error === 'invalid_api_key') {
|
|
114
|
+
spinner.fail(chalk.red(i18n.t('wizard.api_key_invalid')));
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
spinner.fail(chalk.red(i18n.t('wizard.api_key_network_error')));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
configManager.setApiKey(token);
|
|
122
|
+
spinner.succeed(chalk.green(i18n.t('auth.saved')));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
export async function authCommand(args) {
|
|
126
|
+
// 无参数:交互式模式
|
|
127
|
+
if (args.length === 0) {
|
|
128
|
+
await interactiveAuth();
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
// chelper auth revoke
|
|
132
|
+
if (args[0] === 'revoke') {
|
|
133
|
+
await revokeApiKey();
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
// chelper auth reload <tool>
|
|
137
|
+
if (args[0] === 'reload') {
|
|
138
|
+
await reloadToTool(args[1] || '');
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
// chelper auth <token>
|
|
142
|
+
if (args.length >= 1) {
|
|
143
|
+
await directAuth(args[0]);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
// 显示用法
|
|
147
|
+
console.log(i18n.t('auth.set_usage'));
|
|
148
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function configCommand(args: string[]): Promise<void>;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import inquirer from 'inquirer';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { wizard } from '../lib/wizard.js';
|
|
4
|
+
import { toolManager, SUPPORTED_TOOLS } from '../lib/tool-manager.js';
|
|
5
|
+
import { i18n } from '../lib/i18n.js';
|
|
6
|
+
export async function configCommand(args) {
|
|
7
|
+
const subCommand = args[0];
|
|
8
|
+
const toolName = args[1];
|
|
9
|
+
// 如果没有参数,进入交互式选择
|
|
10
|
+
if (!subCommand) {
|
|
11
|
+
const { selectedTool } = await inquirer.prompt([
|
|
12
|
+
{
|
|
13
|
+
type: 'list',
|
|
14
|
+
name: 'selectedTool',
|
|
15
|
+
message: i18n.t('wizard.select_tool'),
|
|
16
|
+
choices: Object.values(SUPPORTED_TOOLS).map(tool => ({
|
|
17
|
+
name: `${tool.displayName} (${tool.name})`,
|
|
18
|
+
value: tool.name
|
|
19
|
+
}))
|
|
20
|
+
}
|
|
21
|
+
]);
|
|
22
|
+
// 检查工具是否安装
|
|
23
|
+
if (!toolManager.isToolInstalled(selectedTool)) {
|
|
24
|
+
console.log(chalk.yellow(`\n${i18n.t('wizard.tool_not_installed', { tool: SUPPORTED_TOOLS[selectedTool].displayName })}`));
|
|
25
|
+
const { shouldInstall } = await inquirer.prompt([
|
|
26
|
+
{
|
|
27
|
+
type: 'confirm',
|
|
28
|
+
name: 'shouldInstall',
|
|
29
|
+
message: i18n.t('wizard.install_tool_confirm'),
|
|
30
|
+
default: true
|
|
31
|
+
}
|
|
32
|
+
]);
|
|
33
|
+
if (shouldInstall) {
|
|
34
|
+
try {
|
|
35
|
+
await toolManager.installTool(selectedTool);
|
|
36
|
+
await new Promise(resolve => setTimeout(resolve, 600));
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
console.error(chalk.red(i18n.t('install.install_failed_detail')));
|
|
40
|
+
if (error.message) {
|
|
41
|
+
console.error(chalk.gray(error.message));
|
|
42
|
+
}
|
|
43
|
+
await new Promise(resolve => setTimeout(resolve, 600));
|
|
44
|
+
// 询问是否跳过安装
|
|
45
|
+
const { skipInstall } = await inquirer.prompt([
|
|
46
|
+
{
|
|
47
|
+
type: 'list',
|
|
48
|
+
name: 'skipInstall',
|
|
49
|
+
message: i18n.t('install.skip_install_confirm'),
|
|
50
|
+
choices: [
|
|
51
|
+
{ name: i18n.t('install.skip_install_yes'), value: true },
|
|
52
|
+
{ name: i18n.t('install.skip_install_no'), value: false }
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
]);
|
|
56
|
+
if (!skipInstall) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
console.log(chalk.yellow(i18n.t('wizard.install_skipped')));
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// 进入工具配置菜单
|
|
67
|
+
await wizard.showToolMenu(selectedTool);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
// 处理 claude-code 子命令
|
|
71
|
+
if (subCommand === 'claude-code' || toolName === 'claude-code') {
|
|
72
|
+
if (!toolManager.isToolInstalled('claude-code')) {
|
|
73
|
+
console.log(chalk.yellow(i18n.t('wizard.tool_not_installed', { tool: 'Claude Code' })));
|
|
74
|
+
const { shouldInstall } = await inquirer.prompt([
|
|
75
|
+
{
|
|
76
|
+
type: 'confirm',
|
|
77
|
+
name: 'shouldInstall',
|
|
78
|
+
message: i18n.t('wizard.install_tool_confirm'),
|
|
79
|
+
default: true
|
|
80
|
+
}
|
|
81
|
+
]);
|
|
82
|
+
if (shouldInstall) {
|
|
83
|
+
try {
|
|
84
|
+
await toolManager.installTool('claude-code');
|
|
85
|
+
await new Promise(resolve => setTimeout(resolve, 600));
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
console.error(chalk.red(i18n.t('install.install_failed_detail')));
|
|
89
|
+
if (error.message) {
|
|
90
|
+
console.error(chalk.gray(error.message));
|
|
91
|
+
}
|
|
92
|
+
await new Promise(resolve => setTimeout(resolve, 600));
|
|
93
|
+
// 询问是否跳过安装
|
|
94
|
+
const { skipInstall } = await inquirer.prompt([
|
|
95
|
+
{
|
|
96
|
+
type: 'list',
|
|
97
|
+
name: 'skipInstall',
|
|
98
|
+
message: i18n.t('install.skip_install_confirm'),
|
|
99
|
+
choices: [
|
|
100
|
+
{ name: i18n.t('install.skip_install_yes'), value: true },
|
|
101
|
+
{ name: i18n.t('install.skip_install_no'), value: false }
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
]);
|
|
105
|
+
if (!skipInstall) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
console.log(chalk.yellow(i18n.t('wizard.install_skipped')));
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
await wizard.showToolMenu('claude-code');
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
// 其他工具的支持
|
|
119
|
+
if (SUPPORTED_TOOLS[subCommand]) {
|
|
120
|
+
if (!toolManager.isToolInstalled(subCommand)) {
|
|
121
|
+
console.log(chalk.yellow(i18n.t('wizard.tool_not_installed', { tool: SUPPORTED_TOOLS[subCommand].displayName })));
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
await wizard.showToolMenu(subCommand);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
console.error(chalk.red(`Unknown command: ${subCommand}`));
|
|
128
|
+
console.log(chalk.gray('Usage: chelper config [tool-name]'));
|
|
129
|
+
console.log(chalk.gray('Available tools:'));
|
|
130
|
+
Object.values(SUPPORTED_TOOLS).forEach(tool => {
|
|
131
|
+
console.log(chalk.gray(` - ${tool.name}: ${tool.displayName}`));
|
|
132
|
+
});
|
|
133
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function doctorCommand(): Promise<void>;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import ora from 'ora';
|
|
3
|
+
import { configManager } from '../lib/config.js';
|
|
4
|
+
import { toolManager } from '../lib/tool-manager.js';
|
|
5
|
+
import { claudeCodeManager } from '../lib/claude-code-manager.js';
|
|
6
|
+
import { i18n } from '../lib/i18n.js';
|
|
7
|
+
import { validateApiKey } from '../lib/api-validator.js';
|
|
8
|
+
export async function doctorCommand() {
|
|
9
|
+
const spinner = ora(i18n.t('doctor.checking')).start();
|
|
10
|
+
const results = [];
|
|
11
|
+
// Check 1: PATH environment variable
|
|
12
|
+
spinner.text = i18n.t('doctor.check_path');
|
|
13
|
+
try {
|
|
14
|
+
const path = process.env.PATH || '';
|
|
15
|
+
results.push({
|
|
16
|
+
name: 'PATH',
|
|
17
|
+
passed: path.length > 0,
|
|
18
|
+
message: path.length > 0 ? undefined : 'PATH is empty'
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
results.push({
|
|
23
|
+
name: 'PATH',
|
|
24
|
+
passed: false,
|
|
25
|
+
message: String(error)
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
await new Promise(resolve => setTimeout(resolve, 800));
|
|
29
|
+
// Check 2: API Key & Network (combined check)
|
|
30
|
+
spinner.text = i18n.t('doctor.check_api_key_network');
|
|
31
|
+
const apiKey = configManager.getApiKey();
|
|
32
|
+
if (!apiKey) {
|
|
33
|
+
results.push({
|
|
34
|
+
name: 'API Key & Network',
|
|
35
|
+
passed: false,
|
|
36
|
+
message: chalk.yellow(i18n.t('doctor.api_key_missing'))
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
const validationResult = await validateApiKey(apiKey);
|
|
41
|
+
if (validationResult.valid) {
|
|
42
|
+
results.push({
|
|
43
|
+
name: 'API Key & Network',
|
|
44
|
+
passed: true
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
else if (validationResult.error === 'invalid_api_key') {
|
|
48
|
+
results.push({
|
|
49
|
+
name: 'API Key & Network',
|
|
50
|
+
passed: false,
|
|
51
|
+
message: chalk.yellow(i18n.t('doctor.api_key_invalid'))
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
results.push({
|
|
56
|
+
name: 'API Key & Network',
|
|
57
|
+
passed: false,
|
|
58
|
+
message: chalk.yellow(i18n.t('doctor.network_error'))
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
await new Promise(resolve => setTimeout(resolve, 800));
|
|
63
|
+
// Check 3: Git Env when using the windows platform and claude-code tool
|
|
64
|
+
if (process.platform === 'win32' && toolManager.isToolInstalled('claude-code')) {
|
|
65
|
+
spinner.text = i18n.t('doctor.check_git_env');
|
|
66
|
+
const gitInstalled = toolManager.isGitInstalled();
|
|
67
|
+
results.push({
|
|
68
|
+
name: 'Git Environment',
|
|
69
|
+
passed: gitInstalled,
|
|
70
|
+
message: gitInstalled ? undefined : chalk.yellow(i18n.t('doctor.git_not_installed'))
|
|
71
|
+
});
|
|
72
|
+
await new Promise(resolve => setTimeout(resolve, 800));
|
|
73
|
+
}
|
|
74
|
+
// Check 4: Configuration status
|
|
75
|
+
spinner.text = i18n.t('doctor.check_config');
|
|
76
|
+
const detectedConfig = claudeCodeManager.getModelConfig();
|
|
77
|
+
const models = configManager.getModels();
|
|
78
|
+
const configComplete = !!apiKey && !!(models.haikuModel || models.sonnetModel || models.opusModel);
|
|
79
|
+
let configMessage = '';
|
|
80
|
+
if (configComplete) {
|
|
81
|
+
configMessage = i18n.t('doctor.config_configured');
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
configMessage = i18n.t('doctor.config_not_configured');
|
|
85
|
+
}
|
|
86
|
+
results.push({
|
|
87
|
+
name: 'Configuration',
|
|
88
|
+
passed: configComplete,
|
|
89
|
+
message: configComplete ? undefined : chalk.yellow(configMessage)
|
|
90
|
+
});
|
|
91
|
+
await new Promise(resolve => setTimeout(resolve, 800));
|
|
92
|
+
// Check 5: Installed tools (检测所有支持的工具)
|
|
93
|
+
spinner.text = i18n.t('doctor.check_tools');
|
|
94
|
+
const supportedTools = toolManager.getSupportedTools();
|
|
95
|
+
for (const tool of supportedTools) {
|
|
96
|
+
const isInstalled = toolManager.isToolInstalled(tool.name);
|
|
97
|
+
results.push({
|
|
98
|
+
name: `Tool: ${tool.displayName} (${tool.name})`,
|
|
99
|
+
passed: isInstalled,
|
|
100
|
+
message: isInstalled ? undefined : chalk.yellow(i18n.t('doctor.tool_not_found', { tool: tool.displayName }))
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
await new Promise(resolve => setTimeout(resolve, 800));
|
|
104
|
+
spinner.stop();
|
|
105
|
+
// Display results
|
|
106
|
+
console.log(chalk.cyan.bold('\n=== Health Check Results ===\n'));
|
|
107
|
+
let allPassed = true;
|
|
108
|
+
for (const result of results) {
|
|
109
|
+
const icon = result.passed ? chalk.green('✓') : chalk.red('✗');
|
|
110
|
+
console.log(`${icon} ${result.name}`);
|
|
111
|
+
if (result.message) {
|
|
112
|
+
console.log(` ${chalk.gray(result.message)}`);
|
|
113
|
+
}
|
|
114
|
+
if (!result.passed) {
|
|
115
|
+
allPassed = false;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
console.log();
|
|
119
|
+
if (allPassed) {
|
|
120
|
+
console.log(chalk.green.bold(i18n.t('doctor.all_good')));
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
console.log(chalk.gray('\n' + i18n.t('doctor.suggestions') + ':'));
|
|
124
|
+
console.log(chalk.gray('- Run "chelper init" to configure missing settings'));
|
|
125
|
+
console.log(chalk.gray('- Check your network connection'));
|
|
126
|
+
console.log(chalk.gray('- Ensure required tools are installed'));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function langCommand(args: string[]): Promise<void>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { configManager } from '../lib/config.js';
|
|
2
|
+
import { i18n } from '../lib/i18n.js';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
export async function langCommand(args) {
|
|
5
|
+
if (args.length === 0 || args[0] === 'show') {
|
|
6
|
+
// Show current language
|
|
7
|
+
const currentLang = configManager.getLang();
|
|
8
|
+
console.log(`${i18n.t('lang.current')}: ${chalk.cyan(currentLang)}`);
|
|
9
|
+
console.log(`${i18n.t('lang.available')}: ${i18n.getAvailableLocales().join(', ')}`);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (args[0] === 'set' && args.length >= 2) {
|
|
13
|
+
const newLang = args[1];
|
|
14
|
+
const availableLocales = i18n.getAvailableLocales();
|
|
15
|
+
if (!availableLocales.includes(newLang)) {
|
|
16
|
+
console.error(chalk.red(i18n.t('lang.invalid', { lang: newLang })));
|
|
17
|
+
console.log(`${i18n.t('lang.available')}: ${availableLocales.join(', ')}`);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const oldLang = configManager.getLang();
|
|
21
|
+
configManager.setLang(newLang);
|
|
22
|
+
i18n.loadFromConfig(newLang);
|
|
23
|
+
console.log(chalk.green(i18n.t('lang.changed', { from: oldLang, to: newLang })));
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
// Show usage
|
|
27
|
+
console.log(i18n.t('lang.show_usage'));
|
|
28
|
+
console.log(i18n.t('lang.set_usage'));
|
|
29
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API Key 和网络验证模块
|
|
3
|
+
* 通过调用模型列表 API 来验证 API Key 的有效性和网络连通性
|
|
4
|
+
*/
|
|
5
|
+
export interface ValidateApiKeyResult {
|
|
6
|
+
valid: boolean;
|
|
7
|
+
error?: 'network_error' | 'invalid_api_key' | 'unknown_error';
|
|
8
|
+
message?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 验证 API Key 的有效性和网络连通性
|
|
12
|
+
*
|
|
13
|
+
* @param apiKey - API Key
|
|
14
|
+
* @returns 验证结果,包含 valid 状态和可选的错误信息
|
|
15
|
+
*/
|
|
16
|
+
export declare function validateApiKey(apiKey: string): Promise<ValidateApiKeyResult>;
|