indieclaw-agent 1.1.0 → 1.1.1
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/index.js +57 -18
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -455,46 +455,85 @@ function handleCronList(ws, { id }) {
|
|
|
455
455
|
});
|
|
456
456
|
}
|
|
457
457
|
|
|
458
|
-
// --- Terminal (PTY) ---
|
|
458
|
+
// --- Terminal (PTY with child_process fallback) ---
|
|
459
459
|
function handleTerminalStart(ws, { id }) {
|
|
460
|
-
|
|
461
|
-
|
|
460
|
+
const shell = process.env.SHELL || '/bin/bash';
|
|
461
|
+
|
|
462
|
+
// Try node-pty first
|
|
463
|
+
if (pty) {
|
|
464
|
+
try {
|
|
465
|
+
const term = pty.spawn(shell, [], {
|
|
466
|
+
name: 'xterm-256color',
|
|
467
|
+
cols: 80,
|
|
468
|
+
rows: 24,
|
|
469
|
+
cwd: os.homedir(),
|
|
470
|
+
env: { ...process.env, TERM: 'xterm-256color' },
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
term._ws = ws;
|
|
474
|
+
term._isPty = true;
|
|
475
|
+
terminals.set(id, term);
|
|
476
|
+
|
|
477
|
+
term.onData((data) => {
|
|
478
|
+
send(ws, { type: 'terminal.output', id, data });
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
term.onExit(({ exitCode }) => {
|
|
482
|
+
send(ws, { type: 'terminal.exit', id, exitCode });
|
|
483
|
+
terminals.delete(id);
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
return reply(ws, id, { pid: term.pid });
|
|
487
|
+
} catch (err) {
|
|
488
|
+
console.log(`[agent] node-pty spawn failed (${err.message}), using fallback`);
|
|
489
|
+
}
|
|
462
490
|
}
|
|
463
491
|
|
|
464
|
-
|
|
465
|
-
const
|
|
466
|
-
|
|
467
|
-
cols: 80,
|
|
468
|
-
rows: 24,
|
|
492
|
+
// Fallback: child_process.spawn
|
|
493
|
+
const { spawn } = require('child_process');
|
|
494
|
+
const proc = spawn(shell, ['-i'], {
|
|
469
495
|
cwd: os.homedir(),
|
|
470
|
-
env: { ...process.env, TERM: '
|
|
496
|
+
env: { ...process.env, TERM: 'dumb' },
|
|
497
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
471
498
|
});
|
|
472
499
|
|
|
473
|
-
|
|
474
|
-
|
|
500
|
+
proc._ws = ws;
|
|
501
|
+
proc._isPty = false;
|
|
475
502
|
|
|
476
|
-
|
|
477
|
-
send(ws, { type: 'terminal.output', id, data });
|
|
503
|
+
proc.stdout.on('data', (data) => {
|
|
504
|
+
send(ws, { type: 'terminal.output', id, data: data.toString() });
|
|
478
505
|
});
|
|
479
506
|
|
|
480
|
-
|
|
481
|
-
send(ws, { type: 'terminal.
|
|
507
|
+
proc.stderr.on('data', (data) => {
|
|
508
|
+
send(ws, { type: 'terminal.output', id, data: data.toString() });
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
proc.on('exit', (exitCode) => {
|
|
512
|
+
send(ws, { type: 'terminal.exit', id, exitCode: exitCode ?? 0 });
|
|
482
513
|
terminals.delete(id);
|
|
483
514
|
});
|
|
484
515
|
|
|
485
|
-
|
|
516
|
+
terminals.set(id, proc);
|
|
517
|
+
reply(ws, id, { pid: proc.pid });
|
|
486
518
|
}
|
|
487
519
|
|
|
488
520
|
function handleTerminalInput(ws, { id, data }) {
|
|
489
521
|
const term = terminals.get(id);
|
|
490
522
|
if (!term) return replyError(ws, id, 'Terminal not found');
|
|
491
|
-
term.
|
|
523
|
+
if (term._isPty) {
|
|
524
|
+
term.write(data);
|
|
525
|
+
} else {
|
|
526
|
+
term.stdin.write(data);
|
|
527
|
+
}
|
|
492
528
|
}
|
|
493
529
|
|
|
494
530
|
function handleTerminalResize(ws, { id, cols, rows }) {
|
|
495
531
|
const term = terminals.get(id);
|
|
496
532
|
if (!term) return replyError(ws, id, 'Terminal not found');
|
|
497
|
-
term.resize
|
|
533
|
+
if (term._isPty && term.resize) {
|
|
534
|
+
term.resize(cols, rows);
|
|
535
|
+
}
|
|
536
|
+
// fallback processes don't support resize
|
|
498
537
|
}
|
|
499
538
|
|
|
500
539
|
function handleTerminalStop(ws, { id }) {
|