@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keeroklab/cli",
3
- "version": "0.2.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\n');
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');
@@ -1,10 +1,9 @@
1
1
  /**
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.
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 { spawn } from 'child_process';
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
- stdio: ['pipe', 'pipe', 'pipe'],
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 stdout to both terminal and handler
28
- child.stdout.on('data', (data) => {
25
+ // Forward PTY output to both local terminal and handler
26
+ child.onData((data) => {
29
27
  process.stdout.write(data);
30
- handlers.onData?.(data.toString());
28
+ handlers.onData?.(data);
31
29
  });
32
30
 
33
- // Forward stderr to both terminal and handler
34
- child.stderr.on('data', (data) => {
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
- if (child.stdin.writable) {
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
- if (child.stdin.writable) {
70
- child.stdin.write(data);
71
- }
60
+ child.write(data);
72
61
  },
73
- resize() {
74
- // child_process doesn't support resize, but we notify the handler
62
+ resize(cols, rows) {
63
+ child.resize(cols, rows);
75
64
  },
76
65
  };
77
66
  }