evals 2.2.5 → 2.2.6
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/package.json +1 -1
- package/spawn-interactive.js +34 -14
package/package.json
CHANGED
package/spawn-interactive.js
CHANGED
|
@@ -2,30 +2,50 @@ import { spawn } from 'child_process';
|
|
|
2
2
|
import { openSync } from 'fs';
|
|
3
3
|
|
|
4
4
|
function tryOpenTTY() {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
if (process.platform === 'win32') {
|
|
6
|
+
// On Windows, avoid CON device (issues in Node.js 22)
|
|
7
|
+
// Use isTTY check instead, and stdio: 'inherit' for spawning
|
|
8
|
+
if (process.stdin.isTTY && process.stdout.isTTY && process.stderr.isTTY) {
|
|
9
|
+
return { available: true, useInherit: true };
|
|
10
|
+
}
|
|
10
11
|
return { available: false };
|
|
12
|
+
} else {
|
|
13
|
+
// On macOS/Linux, use direct /dev/tty access
|
|
14
|
+
try {
|
|
15
|
+
const device = '/dev/tty';
|
|
16
|
+
openSync(device, 'r');
|
|
17
|
+
return { device, available: true, useInherit: false };
|
|
18
|
+
} catch (err) {
|
|
19
|
+
return { available: false };
|
|
20
|
+
}
|
|
11
21
|
}
|
|
12
22
|
}
|
|
13
23
|
|
|
14
24
|
const tty = tryOpenTTY();
|
|
15
25
|
|
|
16
26
|
if (tty.available) {
|
|
17
|
-
const
|
|
18
|
-
stdio:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
27
|
+
const spawnOptions = tty.useInherit
|
|
28
|
+
? { stdio: 'inherit', shell: true }
|
|
29
|
+
: {
|
|
30
|
+
stdio: [
|
|
31
|
+
openSync(tty.device, 'r'),
|
|
32
|
+
openSync(tty.device, 'w'),
|
|
33
|
+
openSync(tty.device, 'w')
|
|
34
|
+
]
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const child = spawn('node', ['./cli.js'], spawnOptions);
|
|
24
38
|
|
|
25
39
|
child.on('close', (code) => {
|
|
26
|
-
process.exit(code);
|
|
40
|
+
process.exit(code || 0);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
child.on('error', (err) => {
|
|
44
|
+
console.error('Failed to start interactive CLI:', err.message);
|
|
45
|
+
console.log('Run `npx evals` to complete setup.');
|
|
46
|
+
process.exit(1);
|
|
27
47
|
});
|
|
28
48
|
} else {
|
|
29
49
|
console.log('Run `npx evals` to complete setup.');
|
|
30
|
-
process.exit(1)
|
|
50
|
+
process.exit(1);
|
|
31
51
|
}
|