@keeroklab/cli 0.2.0 ā 0.4.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 +2 -1
- package/src/index.js +13 -3
- package/src/pty-capture.js +17 -28
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keeroklab/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "CLI wrapper for Keerok Lab ā live Claude Code supervision",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"chalk": "^5.3.0",
|
|
35
35
|
"commander": "^12.0.0",
|
|
36
|
+
"node-pty": "^1.1.0",
|
|
36
37
|
"ws": "^8.16.0"
|
|
37
38
|
},
|
|
38
39
|
"engines": {
|
package/src/index.js
CHANGED
|
@@ -39,13 +39,20 @@ program
|
|
|
39
39
|
console.log(`\nš Instructions:\n${config.instructions}\n`);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
// Step 2: Connect WebSocket
|
|
42
|
+
// Step 2: Connect WebSocket and wait for session config
|
|
43
|
+
let resolveConfig;
|
|
44
|
+
const configReady = new Promise((resolve, reject) => {
|
|
45
|
+
resolveConfig = resolve;
|
|
46
|
+
setTimeout(() => reject(new Error('Timed out waiting for session config (5s)')), 5000);
|
|
47
|
+
});
|
|
48
|
+
|
|
43
49
|
const ws = createWsClient(config.ws_url, {
|
|
44
50
|
onSessionConfig: (data) => {
|
|
45
51
|
// API key received ā inject into environment
|
|
46
52
|
if (data.api_key) {
|
|
47
53
|
process.env.ANTHROPIC_API_KEY = data.api_key;
|
|
48
54
|
}
|
|
55
|
+
resolveConfig(data);
|
|
49
56
|
},
|
|
50
57
|
onBudgetWarning: (data) => {
|
|
51
58
|
console.log(`\nā ļø Budget warning: $${data.remaining_usd.toFixed(2)} remaining (${data.percentage.toFixed(0)}% used)\n`);
|
|
@@ -70,9 +77,12 @@ program
|
|
|
70
77
|
},
|
|
71
78
|
});
|
|
72
79
|
|
|
73
|
-
// Wait for WS connection
|
|
80
|
+
// Wait for WS connection, then wait for session_config (API key)
|
|
74
81
|
await ws.waitForConnection();
|
|
75
|
-
console.log('š WebSocket connected
|
|
82
|
+
console.log('š WebSocket connected');
|
|
83
|
+
console.log('ā³ Waiting for session config...');
|
|
84
|
+
await configReady;
|
|
85
|
+
console.log('š Session config received\n');
|
|
76
86
|
console.log('ā'.repeat(50));
|
|
77
87
|
console.log(`Starting: ${options.command}`);
|
|
78
88
|
console.log('ā'.repeat(50) + '\n');
|
package/src/pty-capture.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* pty-capture.js ā Spawns a process
|
|
3
|
-
* Uses
|
|
4
|
-
* and forward it to both stdout and the WebSocket handler.
|
|
2
|
+
* pty-capture.js ā Spawns a process in a real pseudo-terminal.
|
|
3
|
+
* Uses node-pty so interactive TUI apps (like claude) work properly.
|
|
5
4
|
*/
|
|
6
5
|
|
|
7
|
-
import
|
|
6
|
+
import pty from 'node-pty';
|
|
8
7
|
import os from 'os';
|
|
9
8
|
|
|
10
9
|
export function spawnPty(command, handlers) {
|
|
@@ -12,32 +11,25 @@ export function spawnPty(command, handlers) {
|
|
|
12
11
|
const cols = process.stdout.columns || 80;
|
|
13
12
|
const rows = process.stdout.rows || 24;
|
|
14
13
|
|
|
15
|
-
const child = spawn(shell, ['-c', command], {
|
|
16
|
-
|
|
14
|
+
const child = pty.spawn(shell, ['-c', command], {
|
|
15
|
+
name: 'xterm-256color',
|
|
16
|
+
cols,
|
|
17
|
+
rows,
|
|
17
18
|
cwd: process.cwd(),
|
|
18
19
|
env: {
|
|
19
20
|
...process.env,
|
|
20
|
-
TERM: 'xterm-256color',
|
|
21
21
|
FORCE_COLOR: '1',
|
|
22
|
-
COLUMNS: String(cols),
|
|
23
|
-
LINES: String(rows),
|
|
24
22
|
},
|
|
25
23
|
});
|
|
26
24
|
|
|
27
|
-
// Forward
|
|
28
|
-
child.
|
|
25
|
+
// Forward PTY output to both local terminal and handler
|
|
26
|
+
child.onData((data) => {
|
|
29
27
|
process.stdout.write(data);
|
|
30
|
-
handlers.onData?.(data
|
|
28
|
+
handlers.onData?.(data);
|
|
31
29
|
});
|
|
32
30
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
process.stderr.write(data);
|
|
36
|
-
handlers.onData?.(data.toString());
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
child.on('exit', (code) => {
|
|
40
|
-
handlers.onExit?.(code ?? 0);
|
|
31
|
+
child.onExit(({ exitCode }) => {
|
|
32
|
+
handlers.onExit?.(exitCode ?? 0);
|
|
41
33
|
});
|
|
42
34
|
|
|
43
35
|
// Forward stdin to child
|
|
@@ -46,15 +38,14 @@ export function spawnPty(command, handlers) {
|
|
|
46
38
|
}
|
|
47
39
|
process.stdin.resume();
|
|
48
40
|
process.stdin.on('data', (data) => {
|
|
49
|
-
|
|
50
|
-
child.stdin.write(data);
|
|
51
|
-
}
|
|
41
|
+
child.write(data.toString());
|
|
52
42
|
});
|
|
53
43
|
|
|
54
44
|
// Handle terminal resize
|
|
55
45
|
process.stdout.on('resize', () => {
|
|
56
46
|
const newCols = process.stdout.columns;
|
|
57
47
|
const newRows = process.stdout.rows;
|
|
48
|
+
child.resize(newCols, newRows);
|
|
58
49
|
handlers.onResize?.(newCols, newRows);
|
|
59
50
|
});
|
|
60
51
|
|
|
@@ -66,12 +57,10 @@ export function spawnPty(command, handlers) {
|
|
|
66
57
|
child.kill();
|
|
67
58
|
},
|
|
68
59
|
write(data) {
|
|
69
|
-
|
|
70
|
-
child.stdin.write(data);
|
|
71
|
-
}
|
|
60
|
+
child.write(data);
|
|
72
61
|
},
|
|
73
|
-
resize() {
|
|
74
|
-
|
|
62
|
+
resize(cols, rows) {
|
|
63
|
+
child.resize(cols, rows);
|
|
75
64
|
},
|
|
76
65
|
};
|
|
77
66
|
}
|