aicodeswitch 1.3.6 → 1.3.8

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/bin/cli.js CHANGED
@@ -1,41 +1,17 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const path = require('path');
4
- const fs = require('fs');
5
- const os = require('os');
6
4
 
7
5
  const args = process.argv.slice(2);
8
6
  const command = args[0];
9
7
 
10
- // 检查是否有更新版本的 current 文件
11
- const CURRENT_FILE = path.join(os.homedir(), '.aicodeswitch', 'current');
12
-
13
- let binDir = __dirname;
14
- let useLocalVersion = true;
15
-
16
- // 如果存在 current 文件,使用更新版本的脚本
17
- if (fs.existsSync(CURRENT_FILE)) {
18
- try {
19
- const currentPath = fs.readFileSync(CURRENT_FILE, 'utf-8').trim();
20
- const currentBinDir = path.join(currentPath, 'bin');
21
-
22
- // 检查新版本的 bin 目录是否存在
23
- if (fs.existsSync(currentBinDir) && fs.existsSync(path.join(currentBinDir, 'cli.js'))) {
24
- binDir = currentBinDir;
25
- useLocalVersion = false;
26
- }
27
- } catch (err) {
28
- // 读取失败,使用本地版本
29
- }
30
- }
31
-
32
8
  const commands = {
33
- start: () => require(path.join(binDir, 'start')),
34
- stop: () => require(path.join(binDir, 'stop')),
35
- restart: () => require(path.join(binDir, 'restart')),
36
- update: () => require(path.join(binDir, 'update')),
37
- restore: () => require(path.join(binDir, 'restore')),
38
- version: () => require(path.join(binDir, 'version')),
9
+ start: () => require(path.join(__dirname, 'start')),
10
+ stop: () => require(path.join(__dirname, 'stop')),
11
+ restart: () => require(path.join(__dirname, 'restart')),
12
+ update: () => require(path.join(__dirname, 'update')),
13
+ restore: () => require(path.join(__dirname, 'restore')),
14
+ version: () => require(path.join(__dirname, 'version')),
39
15
  };
40
16
 
41
17
  if (!command || !commands[command]) {
package/bin/update.js CHANGED
@@ -224,10 +224,24 @@ const update = async () => {
224
224
 
225
225
  // 检查是否需要 sudo
226
226
  const needSudo = needsSudo();
227
+
228
+ // 如果需要 sudo,显示提示让用户手动执行
227
229
  if (needSudo) {
228
- console.log(chalk.yellow.bold('⚠️ Note: '));
229
- console.log(chalk.white('This operation may require ') + chalk.yellow.bold('sudo') + chalk.white(' privileges.'));
230
- console.log(chalk.gray('If prompted, please enter your password.\n'));
230
+ console.log(boxen(
231
+ chalk.yellow.bold('⚠️ Sudo privileges required\n\n') +
232
+ chalk.white('This operation requires ') + chalk.yellow.bold('sudo') + chalk.white(' privileges.\n\n') +
233
+ chalk.white('Please run the following command to update:\n\n') +
234
+ chalk.cyan.bold(' sudo npm install -g ' + PACKAGE_NAME + '@latest\n\n') +
235
+ chalk.gray('After updating, run ') + chalk.cyan('aicos restart') + chalk.gray(' to restart the server.'),
236
+ {
237
+ padding: 1,
238
+ margin: 1,
239
+ borderStyle: 'round',
240
+ borderColor: 'yellow'
241
+ }
242
+ ));
243
+ console.log('');
244
+ process.exit(0);
231
245
  }
232
246
 
233
247
  // 执行更新
@@ -236,17 +250,14 @@ const update = async () => {
236
250
  color: 'cyan'
237
251
  }).start();
238
252
 
239
- const npmCommand = needSudo ? 'sudo' : 'npm';
240
- const npmArgs = needSudo ? ['npm', 'install', '-g', `${PACKAGE_NAME}@latest`] : ['install', '-g', `${PACKAGE_NAME}@latest`];
241
-
242
253
  try {
243
- await execCommand(npmCommand, npmArgs);
254
+ await execCommand('npm', ['install', '-g', `${PACKAGE_NAME}@latest`]);
244
255
  updateSpinner.succeed(chalk.green('Update successful!'));
245
256
  } catch (err) {
246
257
  updateSpinner.fail(chalk.red('Update failed'));
247
258
  console.log(chalk.yellow(`\nUpdate failed with error code ${err.code || 'unknown'}\n`));
248
259
  console.log(chalk.white('You can try manually updating:\n'));
249
- console.log(chalk.cyan(` ${npmCommand} ${npmArgs.join(' ')}\n`));
260
+ console.log(chalk.cyan(` npm install -g ${PACKAGE_NAME}@latest\n`));
250
261
  process.exit(1);
251
262
  }
252
263
 
package/bin/version.js CHANGED
@@ -1,51 +1,21 @@
1
1
  const path = require('path');
2
2
  const fs = require('fs');
3
- const os = require('os');
4
3
  const chalk = require('chalk');
5
4
  const boxen = require('boxen');
6
5
 
7
- const AICOSWITCH_DIR = path.join(os.homedir(), '.aicodeswitch');
8
- const CURRENT_FILE = path.join(AICOSWITCH_DIR, 'current');
9
-
10
6
  const getVersionInfo = () => {
11
- // 先检查是否有 current 文件(更新的版本)
12
- if (fs.existsSync(CURRENT_FILE)) {
13
- try {
14
- const currentPath = fs.readFileSync(CURRENT_FILE, 'utf-8').trim();
15
- const currentPackageJson = path.join(currentPath, 'package.json');
16
-
17
- if (fs.existsSync(currentPackageJson)) {
18
- const pkg = JSON.parse(fs.readFileSync(currentPackageJson, 'utf-8'));
19
-
20
- return {
21
- version: pkg.version,
22
- source: 'npm',
23
- path: currentPath,
24
- isUpdated: true
25
- };
26
- }
27
- } catch (err) {
28
- // 读取失败,fallback 到本地版本
29
- }
30
- }
31
-
32
- // 使用本地 package.json
33
7
  try {
34
8
  const packageJson = path.join(__dirname, '..', 'package.json');
35
9
  const pkg = JSON.parse(fs.readFileSync(packageJson, 'utf-8'));
36
10
 
37
11
  return {
38
12
  version: pkg.version,
39
- source: 'local',
40
- path: path.dirname(packageJson),
41
- isUpdated: false
13
+ path: path.dirname(packageJson)
42
14
  };
43
15
  } catch (err) {
44
16
  return {
45
17
  version: 'unknown',
46
- source: 'unknown',
47
- path: 'unknown',
48
- isUpdated: false
18
+ path: 'unknown'
49
19
  };
50
20
  }
51
21
  };
@@ -55,41 +25,21 @@ const version = () => {
55
25
 
56
26
  console.log('\n');
57
27
 
58
- if (info.isUpdated) {
59
- console.log(boxen(
60
- chalk.green.bold('AI Code Switch\n\n') +
61
- chalk.white('Version: ') + chalk.cyan.bold(info.version) + '\n' +
62
- chalk.white('Source: ') + chalk.yellow.bold('npm (updated)') + '\n' +
63
- chalk.white('Location: ') + chalk.gray(info.path),
64
- {
65
- padding: 1,
66
- margin: 1,
67
- borderStyle: 'double',
68
- borderColor: 'green'
69
- }
70
- ));
71
-
72
- console.log(chalk.cyan('💡 Tips:\n'));
73
- console.log(chalk.white(' • Check for updates: ') + chalk.yellow('aicos update'));
74
- console.log(chalk.white(' • Revert to local: ') + chalk.gray('rm ~/.aicodeswitch/current\n'));
75
- } else {
76
- console.log(boxen(
77
- chalk.cyan.bold('AI Code Switch\n\n') +
78
- chalk.white('Version: ') + chalk.cyan.bold(info.version) + '\n' +
79
- chalk.white('Source: ') + chalk.yellow.bold('local development') + '\n' +
80
- chalk.white('Location: ') + chalk.gray(info.path),
81
- {
82
- padding: 1,
83
- margin: 1,
84
- borderStyle: 'double',
85
- borderColor: 'cyan'
86
- }
87
- ));
28
+ console.log(boxen(
29
+ chalk.cyan.bold('AI Code Switch\n\n') +
30
+ chalk.white('Version: ') + chalk.cyan.bold(info.version) + '\n' +
31
+ chalk.white('Location: ') + chalk.gray(info.path),
32
+ {
33
+ padding: 1,
34
+ margin: 1,
35
+ borderStyle: 'double',
36
+ borderColor: 'cyan'
37
+ }
38
+ ));
88
39
 
89
- console.log(chalk.cyan('💡 Tips:\n'));
90
- console.log(chalk.white(' • Check for updates: ') + chalk.yellow('aicos update'));
91
- console.log(chalk.white(' • Update to latest: ') + chalk.yellow('aicos update\n'));
92
- }
40
+ console.log(chalk.cyan('💡 Tips:\n'));
41
+ console.log(chalk.white(' • Check for updates: ') + chalk.yellow('aicos update'));
42
+ console.log(chalk.white(' • Restart server: ') + chalk.yellow('aicos restart\n'));
93
43
 
94
44
  process.exit(0);
95
45
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aicodeswitch",
3
- "version": "1.3.6",
3
+ "version": "1.3.8",
4
4
  "description": "A tool to help you manage AI programming tools to access large language models locally. It allows your Claude Code, Codex and other tools to no longer be limited to official models.",
5
5
  "author": "tangshuang",
6
6
  "license": "GPL-3.0",