@x-all-in-one/coding-helper 0.1.0 → 0.2.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 CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  CLI 工具,用于配置 AI 编程助手(Claude Code、OpenCode、Codex)的 API 端点和模型。
4
4
 
5
+ ## 功能
6
+
7
+ - 统一管理多个 AI 编程工具的配置
8
+ - 交互式配置向导
9
+ - 支持自定义 API 端点和模型
10
+ - 多语言支持(中文/英文)
11
+
5
12
  ## 安装
6
13
 
7
14
  ```bash
@@ -23,101 +30,11 @@ chelper --help
23
30
  chelper lang
24
31
  ```
25
32
 
26
- ## 开发
27
-
28
- ### 环境要求
29
-
30
- - Node.js >= 18
31
- - pnpm >= 10
32
-
33
- ### 常用命令
34
-
35
- ```bash
36
- pnpm install # 安装依赖
37
- pnpm dev # 开发模式(热重载)
38
- pnpm build # 构建项目
39
- pnpm lint # 代码检查
40
- pnpm lint:fix # 自动修复
41
- ```
42
-
43
- ### 目录结构
44
-
45
- ```
46
- src/
47
- ├── cli.ts # 入口文件
48
- ├── lib/
49
- │ ├── config.ts # 配置管理 (~/.chelper/config.yaml)
50
- │ ├── i18n.ts # 国际化
51
- │ ├── tool-manager.ts # 工具注册管理
52
- │ ├── wizard/ # 交互式 TUI
53
- │ ├── tools/ # 工具实现 (Claude Code, OpenCode, Codex)
54
- │ └── plugins/ # 插件实现
55
- └── locales/ # 语言文件
56
- ```
57
-
58
- ## 发版流程
59
-
60
- 本项目使用 [Changeset](https://github.com/changesets/changesets) 进行版本管理。
61
-
62
- ### 1. 创建 Changeset
63
-
64
- 开发完成后,运行以下命令声明版本变更:
65
-
66
- ```bash
67
- pnpm changeset
68
- ```
69
-
70
- 交互式选择:
71
- - **patch** - 修复 bug (0.0.x)
72
- - **minor** - 新功能 (0.x.0)
73
- - **major** - 破坏性变更 (x.0.0)
74
-
75
- 这会在 `.changeset/` 目录下生成一个 markdown 文件。
76
-
77
- ### 2. 提交代码
78
-
79
- ```bash
80
- git add .
81
- git commit -m "feat: 添加新功能"
82
- git push origin feature/xxx
83
- ```
84
-
85
- ### 3. 创建 MR 并合并
86
-
87
- 创建 Merge Request 合并到 `main` 分支。
88
-
89
- ### 4. 自动发版
90
-
91
- 合并后,GitLab CI 会自动:
92
- 1. 执行 `changeset version` 更新版本号和 CHANGELOG
93
- 2. 执行 `changeset publish` 发布到 npm
94
- 3. 提交版本变更并推送
95
-
96
- ## Commit 规范
97
-
98
- 使用 [Conventional Commits](https://www.conventionalcommits.org/) 规范:
99
-
100
- | 类型 | 说明 |
101
- |------|------|
102
- | `feat` | 新功能 |
103
- | `fix` | 修复 bug |
104
- | `docs` | 文档变更 |
105
- | `style` | 代码格式(不影响功能) |
106
- | `refactor` | 重构(不是新功能也不是修复) |
107
- | `perf` | 性能优化 |
108
- | `test` | 测试相关 |
109
- | `chore` | 构建/工具变更 |
110
-
111
- ## GitLab CI
112
-
113
- 流水线包含以下阶段:
33
+ ## 支持的工具
114
34
 
115
- | 阶段 | 说明 |
116
- |------|------|
117
- | `install` | 安装依赖 |
118
- | `lint` | 代码检查 |
119
- | `build` | 构建项目 |
120
- | `release` | 发版(仅 main 分支) |
35
+ - [Claude Code](https://claude.ai/code) - Anthropic 官方 CLI
36
+ - [OpenCode](https://github.com/opencode-ai/opencode) - 开源 AI 编程助手
37
+ - [Codex](https://github.com/openai/codex) - OpenAI CLI
121
38
 
122
39
  ## License
123
40
 
@@ -38,7 +38,7 @@ export class OhMyOpenCodePlugin {
38
38
  }
39
39
  const isWindows = process.platform === 'win32';
40
40
  const command = isWindows ? 'bunx.cmd' : 'bunx';
41
- const args = ['oh-my-opencode', 'install'];
41
+ const args = ['oh-my-opencode', 'install', '--no-tui', '--claude=no', '--chatgpt=no', '--gemini=no'];
42
42
  return new Promise((resolve, reject) => {
43
43
  const child = spawn(command, args, {
44
44
  stdio: 'inherit',
@@ -116,6 +116,7 @@ export declare class OpenCodeTool extends BaseTool {
116
116
  /**
117
117
  * 同步模型列表到配置(不改变当前选择的模型)
118
118
  * 仅更新 provider.xaio.models 部分
119
+ * 如果 provider 不存在但有 apiKey,则创建新的 provider
119
120
  */
120
121
  syncModelsToConfig(modelInfos: ModelInfo[]): void;
121
122
  /**
@@ -1,6 +1,7 @@
1
1
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
2
2
  import { homedir } from 'node:os';
3
3
  import { dirname, join } from 'node:path';
4
+ import { configManager } from '../config.js';
4
5
  import { BaseTool } from './base-tool.js';
5
6
  // X-AIO Provider ID
6
7
  const XAIO_PROVIDER_ID = 'xaio';
@@ -268,15 +269,35 @@ export class OpenCodeTool extends BaseTool {
268
269
  /**
269
270
  * 同步模型列表到配置(不改变当前选择的模型)
270
271
  * 仅更新 provider.xaio.models 部分
272
+ * 如果 provider 不存在但有 apiKey,则创建新的 provider
271
273
  */
272
274
  syncModelsToConfig(modelInfos) {
273
275
  const currentConfig = this.getConfig();
274
- const xaioProvider = currentConfig.provider?.[XAIO_PROVIDER_ID];
276
+ let xaioProvider = currentConfig.provider?.[XAIO_PROVIDER_ID];
275
277
  if (!xaioProvider) {
276
- // 如果还没有配置过,不做任何操作
277
- return;
278
+ // 如果还没有配置过,尝试从 configManager 获取 apiKey 创建 provider
279
+ const apiKey = configManager.getApiKey();
280
+ if (!apiKey) {
281
+ // 没有 apiKey,无法创建 provider
282
+ return;
283
+ }
284
+ // 创建新的 provider
285
+ xaioProvider = {
286
+ npm: '@ai-sdk/openai-compatible',
287
+ name: OPENCODE_DEFAULT_CONFIG.PROVIDER_NAME,
288
+ options: {
289
+ baseURL: OPENCODE_DEFAULT_CONFIG.BASE_URL,
290
+ apiKey,
291
+ },
292
+ models: {},
293
+ };
294
+ // 初始化 provider 对象
295
+ if (!currentConfig.provider) {
296
+ currentConfig.provider = {};
297
+ }
298
+ currentConfig.provider[XAIO_PROVIDER_ID] = xaioProvider;
278
299
  }
279
- // 只更新 models 部分
300
+ // 更新 models 部分
280
301
  const modelsConfig = this.buildModelsConfig(modelInfos);
281
302
  xaioProvider.models = modelsConfig;
282
303
  this.saveConfig(currentConfig);
@@ -14,6 +14,10 @@ export declare class PluginMenu {
14
14
  * 安装插件
15
15
  */
16
16
  private installPlugin;
17
+ /**
18
+ * 提示用户刷新模型列表
19
+ */
20
+ private promptRefreshModels;
17
21
  /**
18
22
  * 装载插件
19
23
  */
@@ -2,6 +2,7 @@ import chalk from 'chalk';
2
2
  import inquirer from 'inquirer';
3
3
  import ora from 'ora';
4
4
  import { i18n } from '../../i18n.js';
5
+ import { modelService } from '../../model-service.js';
5
6
  import { promptHelper } from '../ui/prompt-helper.js';
6
7
  import { uiRenderer } from '../ui/ui-renderer.js';
7
8
  /**
@@ -83,6 +84,10 @@ export class PluginMenu {
83
84
  try {
84
85
  await plugin.install();
85
86
  console.log(chalk.green(`\n✓ ${i18n.t('wizard.plugin_installed', { plugin: plugin.displayName })}`));
87
+ // oh-my-opencode 安装后提示刷新模型列表
88
+ if (plugin.name === 'oh-my-opencode') {
89
+ await this.promptRefreshModels();
90
+ }
86
91
  }
87
92
  catch (error) {
88
93
  console.log(chalk.red(`\n✗ ${i18n.t('wizard.plugin_install_failed', { plugin: plugin.displayName })}`));
@@ -90,6 +95,33 @@ export class PluginMenu {
90
95
  }
91
96
  await promptHelper.pressEnterToContinue();
92
97
  }
98
+ /**
99
+ * 提示用户刷新模型列表
100
+ */
101
+ async promptRefreshModels() {
102
+ console.log('');
103
+ const { shouldRefresh } = await promptHelper.promptWithHints([
104
+ {
105
+ type: 'confirm',
106
+ name: 'shouldRefresh',
107
+ message: i18n.t('wizard.prompt_refresh_models'),
108
+ default: true,
109
+ },
110
+ ]);
111
+ if (shouldRefresh) {
112
+ const spinner = ora({
113
+ text: i18n.t('wizard.refreshing_models'),
114
+ spinner: 'star2',
115
+ }).start();
116
+ const result = await modelService.refreshAndSyncToOpenCode();
117
+ if (result.success) {
118
+ spinner.succeed(chalk.green(i18n.t('wizard.models_refreshed', { count: String(result.count) })));
119
+ }
120
+ else {
121
+ spinner.fail(i18n.t('wizard.refresh_models_failed'));
122
+ }
123
+ }
124
+ }
93
125
  /**
94
126
  * 装载插件
95
127
  */
@@ -198,6 +198,7 @@
198
198
  "tool_started": "Tool started",
199
199
  "tool_start_failed": "Failed to start tool",
200
200
  "action_refresh_models": "Refresh Model List - (Update available models to config)",
201
+ "prompt_refresh_models": "Refresh model list now? (Update available models to config)",
201
202
  "refreshing_models": "Refreshing model list...",
202
203
  "models_refreshed": "Model list refreshed, {{count}} models synced",
203
204
  "refresh_models_failed": "Failed to refresh model list"
@@ -198,6 +198,7 @@
198
198
  "tool_started": "工具已启动",
199
199
  "tool_start_failed": "启动工具失败",
200
200
  "action_refresh_models": "刷新模型列表 - (更新可用模型到配置)",
201
+ "prompt_refresh_models": "是否立即刷新模型列表?(更新可用模型到配置)",
201
202
  "refreshing_models": "正在刷新模型列表...",
202
203
  "models_refreshed": "模型列表已刷新,共同步 {{count}} 个模型",
203
204
  "refresh_models_failed": "刷新模型列表失败"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@x-all-in-one/coding-helper",
3
3
  "type": "module",
4
- "version": "0.1.0",
4
+ "version": "0.2.0",
5
5
  "description": "X All In One Coding Helper",
6
6
  "author": "X.AIO",
7
7
  "homepage": "https://docs.x-aio.com/zh/docs",
@@ -42,6 +42,8 @@
42
42
  "devDependencies": {
43
43
  "@antfu/eslint-config": "^6.2.0",
44
44
  "@changesets/cli": "^2.29.8",
45
+ "@commitlint/cli": "^20.3.1",
46
+ "@commitlint/config-conventional": "^20.3.1",
45
47
  "@eslint/js": "^9.39.1",
46
48
  "@types/inquirer": "^9.0.7",
47
49
  "@types/js-yaml": "^4.0.9",
@@ -49,7 +51,9 @@
49
51
  "eslint": "^9.39.1",
50
52
  "eslint-plugin-format": "^1.2.0",
51
53
  "globals": "^16.5.0",
54
+ "husky": "^9.1.7",
52
55
  "javascript-obfuscator": "^4.1.0",
56
+ "lint-staged": "^16.2.7",
53
57
  "nodemon": "^3.1.11",
54
58
  "tsx": "^4.20.6",
55
59
  "typescript": "^5.9.3",
@@ -62,6 +66,7 @@
62
66
  "start": "node dist/cli.js",
63
67
  "lint": "eslint .",
64
68
  "lint:fix": "eslint . --fix",
69
+ "type-check": "tsc --noEmit",
65
70
  "changeset": "changeset",
66
71
  "version": "changeset version",
67
72
  "release": "pnpm run build && changeset publish"