@shareai-lab/kode 1.1.1 → 1.1.3

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.
Files changed (2) hide show
  1. package/cli.js +62 -40
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -3,54 +3,76 @@
3
3
  const { spawn, execSync } = require('child_process');
4
4
  const path = require('path');
5
5
 
6
- // Prefer bun if available, otherwise use Node with local tsx CLI
6
+ // Kode requires Bun for best reliability & speed on Windows
7
7
  const args = process.argv.slice(2);
8
8
  const cliPath = path.join(__dirname, 'src', 'entrypoints', 'cli.tsx');
9
9
 
10
- // Try bun first
10
+ // Auto-set UTF-8 code page on Windows cmd if not already UTF-8
11
11
  try {
12
- execSync('bun --version', { stdio: 'ignore' });
12
+ if (process.platform === 'win32' && process.env.KODE_NO_AUTO_CHCP !== '1') {
13
+ const out = execSync('chcp', { encoding: 'utf8' });
14
+ if (!/65001/.test(out)) {
15
+ execSync('chcp 65001', { stdio: 'ignore' });
16
+ }
17
+ }
18
+ } catch {}
13
19
 
14
- // Bun is available
20
+ function startWithBun() {
15
21
  const child = spawn('bun', ['run', cliPath, ...args], {
16
22
  stdio: 'inherit',
17
- env: {
18
- ...process.env,
19
- YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm')
20
- }
21
- });
22
-
23
- child.on('exit', (code) => process.exit(code || 0));
24
- child.on('error', () => {
25
- // Fallback to node if bun fails
26
- runWithNode();
27
- });
28
- } catch {
29
- // Bun not available, use node
30
- runWithNode();
23
+ shell: process.platform === 'win32',
24
+ env: { ...process.env, YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm') },
25
+ })
26
+ child.on('exit', code => process.exit(code || 0))
27
+ child.on('error', () => showBunInstructionsAndExit())
31
28
  }
32
29
 
33
- function runWithNode() {
34
- // Use local tsx installation
35
- const tsxPath = path.join(__dirname, 'node_modules', '.bin', 'tsx');
36
- const child = spawn(tsxPath, [cliPath, ...args], {
37
- stdio: 'inherit',
38
- env: {
39
- ...process.env,
40
- YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm')
41
- }
42
- });
43
-
44
- child.on('error', (err) => {
45
- if (err && err.code === 'ENOENT') {
46
- console.error('\nError: tsx is required but not found.');
47
- console.error('Please run: npm install');
48
- process.exit(1);
49
- } else {
50
- console.error('Failed to start Kode:', err && err.message ? err.message : err);
51
- process.exit(1);
52
- }
53
- });
30
+ function showBunInstructionsAndExit() {
31
+ console.error('')
32
+ console.error('Kode requires Bun for optimal startup and compatibility.')
33
+ console.error('Install Bun, then install Kode with Bun, and run Kode:')
34
+ console.error('')
35
+ if (process.platform === 'win32') {
36
+ console.error('Windows (PowerShell, recommended):')
37
+ console.error(' winget install --id=Oven-sh.Bun -e')
38
+ console.error(' # 如果未安装 winget,可用 PowerShell 安装脚本:')
39
+ console.error(' powershell -ExecutionPolicy Bypass -NoLogo -NoProfile -Command "iwr https://bun.sh/install.ps1 -UseBasicParsing | iex"')
40
+ console.error(' # 若脚本受限:Set-ExecutionPolicy RemoteSigned -Scope CurrentUser')
41
+ console.error(' # bun 未自动加入 PATH,可执行:')
42
+ console.error(' setx PATH "%USERPROFILE%\\.bun\\bin;%PATH%"')
43
+ console.error('')
44
+ console.error('安装完成后:')
45
+ console.error(' bun --version')
46
+ console.error(' bun add -g @shareai-lab/kode@latest')
47
+ console.error(' kode')
48
+ } else if (process.platform === 'darwin') {
49
+ console.error('macOS:')
50
+ console.error(' brew tap oven-sh/bun && brew install bun')
51
+ console.error(' # 或者')
52
+ console.error(' curl -fsSL https://bun.sh/install | bash')
53
+ console.error(' # zsh: echo "export PATH=\"$HOME/.bun/bin:$PATH\"" >> ~/.zshrc && source ~/.zshrc')
54
+ console.error('')
55
+ console.error('安装完成后:')
56
+ console.error(' bun --version')
57
+ console.error(' bun add -g @shareai-lab/kode@latest')
58
+ console.error(' kode')
59
+ } else {
60
+ console.error('Linux:')
61
+ console.error(' curl -fsSL https://bun.sh/install | bash')
62
+ console.error(' echo "export PATH=\"$HOME/.bun/bin:$PATH\"" >> ~/.bashrc && source ~/.bashrc')
63
+ console.error('')
64
+ console.error('安装完成后:')
65
+ console.error(' bun --version')
66
+ console.error(' bun add -g @shareai-lab/kode@latest')
67
+ console.error(' kode')
68
+ }
69
+ console.error('')
70
+ process.exit(1)
71
+ }
54
72
 
55
- child.on('exit', (code) => process.exit(code || 0));
73
+ try {
74
+ execSync('bun --version', { stdio: 'ignore' })
75
+ startWithBun()
76
+ } catch {
77
+ showBunInstructionsAndExit()
56
78
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shareai-lab/kode",
3
- "version": "1.1.01",
3
+ "version": "1.1.03",
4
4
  "bin": {
5
5
  "kode": "cli.js",
6
6
  "kwa": "cli.js",