@keeroklab/cli 0.1.1 → 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/package.json +11 -5
- package/src/pty-capture.js +36 -33
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keeroklab/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "CLI wrapper for Keerok Lab — live Claude Code supervision",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -12,7 +12,14 @@
|
|
|
12
12
|
"files": [
|
|
13
13
|
"src/"
|
|
14
14
|
],
|
|
15
|
-
"keywords": [
|
|
15
|
+
"keywords": [
|
|
16
|
+
"claude",
|
|
17
|
+
"lab",
|
|
18
|
+
"supervision",
|
|
19
|
+
"terminal",
|
|
20
|
+
"claude-code",
|
|
21
|
+
"keerok"
|
|
22
|
+
],
|
|
16
23
|
"author": "Keerok <hello@keerok.tech> (https://keerok.tech)",
|
|
17
24
|
"repository": {
|
|
18
25
|
"type": "git",
|
|
@@ -24,10 +31,9 @@
|
|
|
24
31
|
},
|
|
25
32
|
"license": "MIT",
|
|
26
33
|
"dependencies": {
|
|
34
|
+
"chalk": "^5.3.0",
|
|
27
35
|
"commander": "^12.0.0",
|
|
28
|
-
"
|
|
29
|
-
"ws": "^8.16.0",
|
|
30
|
-
"chalk": "^5.3.0"
|
|
36
|
+
"ws": "^8.16.0"
|
|
31
37
|
},
|
|
32
38
|
"engines": {
|
|
33
39
|
"node": ">=18.0.0"
|
package/src/pty-capture.js
CHANGED
|
@@ -1,59 +1,60 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* pty-capture.js — Spawns a
|
|
3
|
-
* Uses
|
|
4
|
-
*
|
|
2
|
+
* pty-capture.js — Spawns a process and captures output.
|
|
3
|
+
* Uses child_process.spawn with pipes to capture terminal output
|
|
4
|
+
* and forward it to both stdout and the WebSocket handler.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import
|
|
7
|
+
import { spawn } from 'child_process';
|
|
8
8
|
import os from 'os';
|
|
9
9
|
|
|
10
10
|
export function spawnPty(command, handlers) {
|
|
11
11
|
const shell = os.platform() === 'win32' ? 'powershell.exe' : process.env.SHELL || '/bin/bash';
|
|
12
|
-
const args = command === shell ? [] : ['-c', command];
|
|
13
|
-
const useShell = command !== shell;
|
|
14
|
-
|
|
15
12
|
const cols = process.stdout.columns || 80;
|
|
16
13
|
const rows = process.stdout.rows || 24;
|
|
17
14
|
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
{
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
},
|
|
30
|
-
}
|
|
31
|
-
);
|
|
15
|
+
const child = spawn(shell, ['-c', command], {
|
|
16
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
17
|
+
cwd: process.cwd(),
|
|
18
|
+
env: {
|
|
19
|
+
...process.env,
|
|
20
|
+
TERM: 'xterm-256color',
|
|
21
|
+
FORCE_COLOR: '1',
|
|
22
|
+
COLUMNS: String(cols),
|
|
23
|
+
LINES: String(rows),
|
|
24
|
+
},
|
|
25
|
+
});
|
|
32
26
|
|
|
33
|
-
// Forward
|
|
34
|
-
|
|
27
|
+
// Forward stdout to both terminal and handler
|
|
28
|
+
child.stdout.on('data', (data) => {
|
|
35
29
|
process.stdout.write(data);
|
|
36
|
-
handlers.onData?.(data);
|
|
30
|
+
handlers.onData?.(data.toString());
|
|
37
31
|
});
|
|
38
32
|
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
// Forward stderr to both terminal and handler
|
|
34
|
+
child.stderr.on('data', (data) => {
|
|
35
|
+
process.stderr.write(data);
|
|
36
|
+
handlers.onData?.(data.toString());
|
|
41
37
|
});
|
|
42
38
|
|
|
43
|
-
|
|
39
|
+
child.on('exit', (code) => {
|
|
40
|
+
handlers.onExit?.(code ?? 0);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Forward stdin to child
|
|
44
44
|
if (process.stdin.isTTY) {
|
|
45
45
|
process.stdin.setRawMode(true);
|
|
46
46
|
}
|
|
47
47
|
process.stdin.resume();
|
|
48
48
|
process.stdin.on('data', (data) => {
|
|
49
|
-
|
|
49
|
+
if (child.stdin.writable) {
|
|
50
|
+
child.stdin.write(data);
|
|
51
|
+
}
|
|
50
52
|
});
|
|
51
53
|
|
|
52
54
|
// Handle terminal resize
|
|
53
55
|
process.stdout.on('resize', () => {
|
|
54
56
|
const newCols = process.stdout.columns;
|
|
55
57
|
const newRows = process.stdout.rows;
|
|
56
|
-
term.resize(newCols, newRows);
|
|
57
58
|
handlers.onResize?.(newCols, newRows);
|
|
58
59
|
});
|
|
59
60
|
|
|
@@ -62,13 +63,15 @@ export function spawnPty(command, handlers) {
|
|
|
62
63
|
|
|
63
64
|
return {
|
|
64
65
|
kill() {
|
|
65
|
-
|
|
66
|
+
child.kill();
|
|
66
67
|
},
|
|
67
68
|
write(data) {
|
|
68
|
-
|
|
69
|
+
if (child.stdin.writable) {
|
|
70
|
+
child.stdin.write(data);
|
|
71
|
+
}
|
|
69
72
|
},
|
|
70
|
-
resize(
|
|
71
|
-
|
|
73
|
+
resize() {
|
|
74
|
+
// child_process doesn't support resize, but we notify the handler
|
|
72
75
|
},
|
|
73
76
|
};
|
|
74
77
|
}
|