@keeroklab/cli 0.3.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.
Files changed (2) hide show
  1. package/package.json +2 -1
  2. 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.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": {
@@ -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
  }