plazbot-cli 0.3.2 → 0.3.3
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/dist/studio/runRepl.js +37 -1
- package/package.json +1 -1
- package/src/studio/runRepl.tsx +38 -1
package/dist/studio/runRepl.js
CHANGED
|
@@ -6,6 +6,12 @@ import { dirname, join } from 'node:path';
|
|
|
6
6
|
import { App } from './components/App.js';
|
|
7
7
|
import { getStoredCredentials } from '../utils/credentials.js';
|
|
8
8
|
import { logger } from '../utils/logger.js';
|
|
9
|
+
// Alternate screen buffer (ANSI). Same trick used by vim, htop, claude code, lazygit.
|
|
10
|
+
// The TUI runs in a clean canvas and the original scrollback is restored on exit,
|
|
11
|
+
// which eliminates the "ghost frames" Ink leaves behind when the terminal is resized.
|
|
12
|
+
const ALT_SCREEN_ENTER = '\x1b[?1049h\x1b[H';
|
|
13
|
+
const ALT_SCREEN_EXIT = '\x1b[?1049l';
|
|
14
|
+
const SHOW_CURSOR = '\x1b[?25h';
|
|
9
15
|
export async function runRepl(opts) {
|
|
10
16
|
let creds;
|
|
11
17
|
try {
|
|
@@ -30,6 +36,31 @@ export async function runRepl(opts) {
|
|
|
30
36
|
dev: opts.dev,
|
|
31
37
|
};
|
|
32
38
|
const version = readVersion();
|
|
39
|
+
const useAltScreen = !!process.stdout.isTTY;
|
|
40
|
+
// Cleanup idempotente; lo registramos en varias señales para que la terminal
|
|
41
|
+
// nunca quede en alt screen ni con el cursor oculto si el proceso muere mal.
|
|
42
|
+
let cleanedUp = false;
|
|
43
|
+
const restoreTerminal = () => {
|
|
44
|
+
if (cleanedUp)
|
|
45
|
+
return;
|
|
46
|
+
cleanedUp = true;
|
|
47
|
+
if (useAltScreen) {
|
|
48
|
+
process.stdout.write(ALT_SCREEN_EXIT);
|
|
49
|
+
process.stdout.write(SHOW_CURSOR);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
if (useAltScreen) {
|
|
53
|
+
process.stdout.write(ALT_SCREEN_ENTER);
|
|
54
|
+
}
|
|
55
|
+
process.on('exit', restoreTerminal);
|
|
56
|
+
process.on('SIGHUP', restoreTerminal);
|
|
57
|
+
process.on('SIGTERM', restoreTerminal);
|
|
58
|
+
process.on('uncaughtException', (err) => {
|
|
59
|
+
restoreTerminal();
|
|
60
|
+
// Re-emit so node prints the trace after restoring the terminal.
|
|
61
|
+
console.error(err);
|
|
62
|
+
process.exit(1);
|
|
63
|
+
});
|
|
33
64
|
const { waitUntilExit } = render(_jsx(App, { version: version, stream: stream, initialAgentId: opts.agentId ?? null, dev: opts.dev, supportMode: supportMode }), {
|
|
34
65
|
exitOnCtrlC: false,
|
|
35
66
|
});
|
|
@@ -37,7 +68,12 @@ export async function runRepl(opts) {
|
|
|
37
68
|
process.on('SIGINT', () => {
|
|
38
69
|
// no-op aquí; App.tsx llama exit() al detectar Ctrl+C.
|
|
39
70
|
});
|
|
40
|
-
|
|
71
|
+
try {
|
|
72
|
+
await waitUntilExit();
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
restoreTerminal();
|
|
76
|
+
}
|
|
41
77
|
}
|
|
42
78
|
function readVersion() {
|
|
43
79
|
try {
|
package/package.json
CHANGED
package/src/studio/runRepl.tsx
CHANGED
|
@@ -15,6 +15,13 @@ interface RunReplOptions {
|
|
|
15
15
|
workspaceOverride?: string;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
// Alternate screen buffer (ANSI). Same trick used by vim, htop, claude code, lazygit.
|
|
19
|
+
// The TUI runs in a clean canvas and the original scrollback is restored on exit,
|
|
20
|
+
// which eliminates the "ghost frames" Ink leaves behind when the terminal is resized.
|
|
21
|
+
const ALT_SCREEN_ENTER = '\x1b[?1049h\x1b[H';
|
|
22
|
+
const ALT_SCREEN_EXIT = '\x1b[?1049l';
|
|
23
|
+
const SHOW_CURSOR = '\x1b[?25h';
|
|
24
|
+
|
|
18
25
|
export async function runRepl(opts: RunReplOptions): Promise<void> {
|
|
19
26
|
let creds;
|
|
20
27
|
try {
|
|
@@ -42,6 +49,32 @@ export async function runRepl(opts: RunReplOptions): Promise<void> {
|
|
|
42
49
|
};
|
|
43
50
|
|
|
44
51
|
const version = readVersion();
|
|
52
|
+
const useAltScreen = !!process.stdout.isTTY;
|
|
53
|
+
|
|
54
|
+
// Cleanup idempotente; lo registramos en varias señales para que la terminal
|
|
55
|
+
// nunca quede en alt screen ni con el cursor oculto si el proceso muere mal.
|
|
56
|
+
let cleanedUp = false;
|
|
57
|
+
const restoreTerminal = () => {
|
|
58
|
+
if (cleanedUp) return;
|
|
59
|
+
cleanedUp = true;
|
|
60
|
+
if (useAltScreen) {
|
|
61
|
+
process.stdout.write(ALT_SCREEN_EXIT);
|
|
62
|
+
process.stdout.write(SHOW_CURSOR);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
if (useAltScreen) {
|
|
67
|
+
process.stdout.write(ALT_SCREEN_ENTER);
|
|
68
|
+
}
|
|
69
|
+
process.on('exit', restoreTerminal);
|
|
70
|
+
process.on('SIGHUP', restoreTerminal);
|
|
71
|
+
process.on('SIGTERM', restoreTerminal);
|
|
72
|
+
process.on('uncaughtException', (err) => {
|
|
73
|
+
restoreTerminal();
|
|
74
|
+
// Re-emit so node prints the trace after restoring the terminal.
|
|
75
|
+
console.error(err);
|
|
76
|
+
process.exit(1);
|
|
77
|
+
});
|
|
45
78
|
|
|
46
79
|
const { waitUntilExit } = render(
|
|
47
80
|
<App
|
|
@@ -61,7 +94,11 @@ export async function runRepl(opts: RunReplOptions): Promise<void> {
|
|
|
61
94
|
// no-op aquí; App.tsx llama exit() al detectar Ctrl+C.
|
|
62
95
|
});
|
|
63
96
|
|
|
64
|
-
|
|
97
|
+
try {
|
|
98
|
+
await waitUntilExit();
|
|
99
|
+
} finally {
|
|
100
|
+
restoreTerminal();
|
|
101
|
+
}
|
|
65
102
|
}
|
|
66
103
|
|
|
67
104
|
function readVersion(): string {
|