@shareai-lab/kode 1.0.93 → 1.0.95
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/cli.js +67 -17
- package/package.json +1 -2
package/cli.js
CHANGED
|
@@ -3,10 +3,16 @@
|
|
|
3
3
|
const { spawn } = require('child_process');
|
|
4
4
|
const path = require('path');
|
|
5
5
|
|
|
6
|
-
// Prefer
|
|
6
|
+
// Prefer Bun if available for speed; otherwise use Node + tsx
|
|
7
7
|
const args = process.argv.slice(2);
|
|
8
8
|
const cliPath = path.join(__dirname, 'src', 'entrypoints', 'cli.tsx');
|
|
9
9
|
|
|
10
|
+
// Resolve tsx from this package directory (stable across global installs)
|
|
11
|
+
let tsxImportPath = null;
|
|
12
|
+
let tsxCliPath = null;
|
|
13
|
+
try { tsxImportPath = require.resolve('tsx', { paths: [__dirname] }); } catch {}
|
|
14
|
+
try { tsxCliPath = require.resolve('tsx/cli', { paths: [__dirname] }); } catch {}
|
|
15
|
+
|
|
10
16
|
// Enforce minimum Node version based on package.json engines.node
|
|
11
17
|
try {
|
|
12
18
|
const req = "${enginesNode}"
|
|
@@ -23,23 +29,67 @@ try {
|
|
|
23
29
|
} catch {}
|
|
24
30
|
|
|
25
31
|
// Find packaged Bun binary or fall back to system Bun
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return
|
|
32
|
+
function hasBun() {
|
|
33
|
+
try {
|
|
34
|
+
require('child_process').execSync('bun --version', { stdio: 'ignore' })
|
|
35
|
+
return true
|
|
36
|
+
} catch { return false }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function runWithBun() {
|
|
40
|
+
const bunCmd = process.platform === 'win32' ? 'bun.cmd' : 'bun'
|
|
41
|
+
const child = spawn(bunCmd, ['run', cliPath, ...args], {
|
|
42
|
+
stdio: 'inherit',
|
|
43
|
+
env: { ...process.env, YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm') },
|
|
44
|
+
})
|
|
45
|
+
child.on('error', () => runWithTsxCLI())
|
|
46
|
+
child.on('exit', code => {
|
|
47
|
+
if (code && code !== 0) return runWithTsxCLI()
|
|
48
|
+
process.exit(code || 0)
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function runWithTsxImport() {
|
|
53
|
+
let importArg = 'tsx'
|
|
54
|
+
try {
|
|
55
|
+
if (tsxImportPath) {
|
|
56
|
+
const { pathToFileURL } = require('node:url')
|
|
57
|
+
importArg = pathToFileURL(tsxImportPath).href
|
|
58
|
+
}
|
|
59
|
+
} catch {}
|
|
60
|
+
const baseArgs = ['--no-warnings=ExperimentalWarning', '--enable-source-maps']
|
|
61
|
+
const child = spawn(process.execPath, [...baseArgs, '--import', importArg, cliPath, ...args], {
|
|
62
|
+
stdio: 'inherit',
|
|
63
|
+
env: { ...process.env, YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm') },
|
|
64
|
+
})
|
|
65
|
+
child.on('error', () => runWithTsxCLI())
|
|
66
|
+
child.on('exit', code => {
|
|
67
|
+
if (code && code !== 0) return runWithTsxCLI()
|
|
68
|
+
process.exit(code || 0)
|
|
69
|
+
})
|
|
31
70
|
}
|
|
32
71
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
72
|
+
function runWithTsxCLI() {
|
|
73
|
+
if (!tsxCliPath) return fail()
|
|
74
|
+
const child = spawn(process.execPath, [tsxCliPath, cliPath, ...args], {
|
|
75
|
+
stdio: 'inherit',
|
|
76
|
+
env: { ...process.env, YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm') },
|
|
77
|
+
})
|
|
78
|
+
child.on('error', () => fail())
|
|
79
|
+
child.on('exit', code => process.exit(code || 0))
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function fail() {
|
|
39
83
|
console.error('')
|
|
40
|
-
console.error('Failed to start Kode
|
|
41
|
-
console.error('
|
|
42
|
-
console.error(' npm install -g bun')
|
|
84
|
+
console.error('Failed to start Kode.')
|
|
85
|
+
console.error('Try installing Bun: npm i -g bun, or ensure tsx is available.')
|
|
43
86
|
process.exit(1)
|
|
44
|
-
}
|
|
45
|
-
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (process.platform === 'win32') {
|
|
90
|
+
// On Windows, tsx CLI is the most reliable
|
|
91
|
+
runWithTsxCLI()
|
|
92
|
+
} else {
|
|
93
|
+
if (hasBun()) runWithBun()
|
|
94
|
+
else runWithTsxImport()
|
|
95
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shareai-lab/kode",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.95",
|
|
4
4
|
"bin": {
|
|
5
5
|
"kode": "cli.js",
|
|
6
6
|
"kwa": "cli.js",
|
|
@@ -46,7 +46,6 @@
|
|
|
46
46
|
"@img/sharp-win32-x64": "^0.33.5"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"bun": "^1.1.34",
|
|
50
49
|
"@anthropic-ai/bedrock-sdk": "^0.12.6",
|
|
51
50
|
"@anthropic-ai/sdk": "^0.39.0",
|
|
52
51
|
"@anthropic-ai/vertex-sdk": "^0.7.0",
|