@keeroklab/cli 0.1.1 ā 0.3.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/index.js +13 -3
- 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.3.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/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,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
|
}
|