@h-rig/cli 0.0.6-alpha.87 → 0.0.6-alpha.89
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/bin/rig.js +1380 -865
- package/dist/src/app/board.js +462 -48
- package/dist/src/app-opentui/adapters/common.d.ts +3 -0
- package/dist/src/app-opentui/adapters/common.js +4 -0
- package/dist/src/app-opentui/adapters/doctor.js +458 -46
- package/dist/src/app-opentui/adapters/family.js +701 -151
- package/dist/src/app-opentui/adapters/fleet.js +477 -46
- package/dist/src/app-opentui/adapters/inbox.js +477 -46
- package/dist/src/app-opentui/adapters/init.js +497 -74
- package/dist/src/app-opentui/adapters/inspect.js +477 -46
- package/dist/src/app-opentui/adapters/pi-attach.d.ts +7 -0
- package/dist/src/app-opentui/adapters/pi-attach.js +1004 -519
- package/dist/src/app-opentui/adapters/run-detail.js +477 -46
- package/dist/src/app-opentui/adapters/server.d.ts +26 -0
- package/dist/src/app-opentui/adapters/server.js +676 -59
- package/dist/src/app-opentui/adapters/tasks.js +621 -549
- package/dist/src/app-opentui/autocomplete.js +4 -2
- package/dist/src/app-opentui/bootstrap.js +1376 -861
- package/dist/src/app-opentui/command-palette.js +37 -10
- package/dist/src/app-opentui/index.js +632 -528
- package/dist/src/app-opentui/intent.js +33 -8
- package/dist/src/app-opentui/keymap.js +43 -414
- package/dist/src/app-opentui/pi-host-child.js +496 -57
- package/dist/src/app-opentui/pi-pty-host.d.ts +14 -64
- package/dist/src/app-opentui/pi-pty-host.js +3 -397
- package/dist/src/app-opentui/react/App.js +144 -469
- package/dist/src/app-opentui/react/ChromeHost.js +44 -415
- package/dist/src/app-opentui/react/launch.js +659 -552
- package/dist/src/app-opentui/react/nav.js +1 -1
- package/dist/src/app-opentui/registry.js +1181 -742
- package/dist/src/app-opentui/remote-link.d.ts +10 -0
- package/dist/src/app-opentui/remote-link.js +47 -0
- package/dist/src/app-opentui/render/terminal-handoff.d.ts +16 -0
- package/dist/src/app-opentui/render/terminal-handoff.js +14 -0
- package/dist/src/app-opentui/runtime.js +632 -528
- package/dist/src/app-opentui/scenes/doctor.js +1 -1
- package/dist/src/app-opentui/scenes/error.js +50 -4
- package/dist/src/app-opentui/scenes/family.js +60 -6
- package/dist/src/app-opentui/scenes/fleet.js +65 -13
- package/dist/src/app-opentui/scenes/help.js +4 -2
- package/dist/src/app-opentui/scenes/init.js +12 -12
- package/dist/src/app-opentui/scenes/main.js +7 -7
- package/dist/src/app-opentui/scenes/server.js +83 -11
- package/dist/src/app-opentui/scenes/tasks.js +79 -16
- package/dist/src/app-opentui/state.js +25 -5
- package/dist/src/app-opentui/surface-catalog.js +4 -2
- package/dist/src/app-opentui/types.d.ts +1 -1
- package/dist/src/commands/_cli-format.d.ts +10 -1
- package/dist/src/commands/_cli-format.js +5 -2
- package/dist/src/commands/_connection-state.d.ts +11 -1
- package/dist/src/commands/_connection-state.js +50 -5
- package/dist/src/commands/_doctor-checks.js +458 -46
- package/dist/src/commands/_help-catalog.js +4 -2
- package/dist/src/commands/_json-output.js +4 -0
- package/dist/src/commands/_operator-view.js +496 -57
- package/dist/src/commands/_pi-frontend.d.ts +25 -0
- package/dist/src/commands/_pi-frontend.js +497 -57
- package/dist/src/commands/_preflight.js +509 -72
- package/dist/src/commands/_server-client.d.ts +33 -0
- package/dist/src/commands/_server-client.js +477 -46
- package/dist/src/commands/_server-events.js +446 -41
- package/dist/src/commands/_snapshot-upload.js +460 -48
- package/dist/src/commands/connect.js +620 -15
- package/dist/src/commands/doctor.js +458 -46
- package/dist/src/commands/github.js +462 -50
- package/dist/src/commands/inbox.js +458 -46
- package/dist/src/commands/init.js +497 -74
- package/dist/src/commands/inspect.js +458 -46
- package/dist/src/commands/run.js +496 -57
- package/dist/src/commands/server.js +647 -163
- package/dist/src/commands/setup.js +463 -51
- package/dist/src/commands/stats.js +462 -48
- package/dist/src/commands/task-run-driver.js +464 -52
- package/dist/src/commands/task.js +551 -85
- package/dist/src/commands.js +701 -151
- package/dist/src/index.js +705 -151
- package/dist/src/launcher.js +4 -0
- package/package.json +8 -8
|
@@ -1,78 +1,28 @@
|
|
|
1
|
-
import { StyledText } from "@opentui/core";
|
|
2
1
|
export type PiPtyHostStatus = "starting" | "running" | "exited" | "failed";
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* The worker/remote Pi daemon still owns tools, skills, cwd, model, session and
|
|
7
|
-
* context. This local host only mirrors a PTY/xterm viewport into selectable
|
|
8
|
-
* OpenTUI text. Keep this snapshot path explicit until Rig grows a dedicated
|
|
9
|
-
* PTY/xterm viewport renderable or deliberately suspends OpenTUI for direct Pi
|
|
10
|
-
* terminal ownership.
|
|
11
|
-
*/
|
|
2
|
+
/** Vestigial presentation snapshot. No longer produced (attach ejects to native
|
|
3
|
+
* Pi); retained as a type so the handoff scene's now-dead terminal branch still
|
|
4
|
+
* compiles. */
|
|
12
5
|
export type PiPtyHostSnapshot = {
|
|
13
6
|
readonly runId: string;
|
|
14
7
|
readonly status: PiPtyHostStatus;
|
|
15
8
|
readonly cols: number;
|
|
16
9
|
readonly rows: number;
|
|
17
10
|
readonly lines: readonly string[];
|
|
18
|
-
readonly styledLines?: readonly StyledText[];
|
|
11
|
+
readonly styledLines?: readonly import("@opentui/core").StyledText[];
|
|
19
12
|
readonly message?: string;
|
|
20
13
|
readonly resizeError?: string;
|
|
21
14
|
readonly exitCode?: number;
|
|
22
15
|
readonly signal?: string | null;
|
|
23
16
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
readonly
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
readonly env?: NodeJS.ProcessEnv;
|
|
31
|
-
readonly onSnapshot?: (snapshot: PiPtyHostSnapshot) => void;
|
|
32
|
-
readonly onExit?: (snapshot: PiPtyHostSnapshot) => void;
|
|
33
|
-
readonly onError?: (error: unknown, snapshot: PiPtyHostSnapshot) => void;
|
|
17
|
+
/** Minimal handle the shell's embedded-terminal code paths type against. Nothing
|
|
18
|
+
* constructs one anymore. */
|
|
19
|
+
export type PiPtyHost = {
|
|
20
|
+
readonly disposed: boolean;
|
|
21
|
+
write(data: string | Uint8Array | BufferSource): void;
|
|
22
|
+
resize(cols: number, rows: number): void;
|
|
34
23
|
};
|
|
24
|
+
/** There is no in-shell Pi host since attach ejects to native Pi — always null. */
|
|
35
25
|
export declare function getActivePiHost(): PiPtyHost | null;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
export declare
|
|
39
|
-
private readonly runId;
|
|
40
|
-
private readonly projectRoot;
|
|
41
|
-
private readonly onSnapshot?;
|
|
42
|
-
private readonly onExit?;
|
|
43
|
-
private readonly onError?;
|
|
44
|
-
private readonly terminal;
|
|
45
|
-
private readonly disposables;
|
|
46
|
-
private readonly decoder;
|
|
47
|
-
private proc;
|
|
48
|
-
private pty;
|
|
49
|
-
private status;
|
|
50
|
-
private cols;
|
|
51
|
-
private rows;
|
|
52
|
-
private message;
|
|
53
|
-
private lastResizeError;
|
|
54
|
-
private exitCode;
|
|
55
|
-
private signal;
|
|
56
|
-
private notifyTimer;
|
|
57
|
-
/** Last streamed buffer content, so the onWriteParsed handler only emits a
|
|
58
|
-
* snapshot when the rendered content actually changed. */
|
|
59
|
-
private lastStreamKey;
|
|
60
|
-
private _disposed;
|
|
61
|
-
constructor(options: PiPtyHostOptions);
|
|
62
|
-
get disposed(): boolean;
|
|
63
|
-
get snapshot(): PiPtyHostSnapshot;
|
|
64
|
-
start(): Promise<void>;
|
|
65
|
-
write(data: PiPtyInput): void;
|
|
66
|
-
resize(cols: number, rows: number): void;
|
|
67
|
-
detach(): PiPtyHostSnapshot;
|
|
68
|
-
dispose(reason?: string, options?: {
|
|
69
|
-
readonly kill?: boolean;
|
|
70
|
-
readonly notify?: boolean;
|
|
71
|
-
}): void;
|
|
72
|
-
private handlePtyData;
|
|
73
|
-
private emitSnapshotSoon;
|
|
74
|
-
private createSnapshot;
|
|
75
|
-
private registerTerminalResponders;
|
|
76
|
-
private respondToRawTerminalQueries;
|
|
77
|
-
}
|
|
78
|
-
export {};
|
|
26
|
+
/** No-op: nothing to stop, since attach ejects to native Pi and never spawns an
|
|
27
|
+
* in-shell host. Kept so existing detach/cleanup call sites compile unchanged. */
|
|
28
|
+
export declare function stopActivePiHost(_reason?: string): void;
|
|
@@ -1,404 +1,10 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// packages/cli/src/app-opentui/pi-pty-host.ts
|
|
3
|
-
import { fileURLToPath } from "url";
|
|
4
|
-
import { basename } from "path";
|
|
5
|
-
import { RGBA, StyledText, TextAttributes } from "@opentui/core";
|
|
6
|
-
import { Terminal as XtermTerminal } from "@xterm/headless";
|
|
7
|
-
var MIN_COLS = 40;
|
|
8
|
-
var MIN_ROWS = 12;
|
|
9
|
-
var MAX_ROWS = 300;
|
|
10
|
-
var MAX_SNAPSHOT_LINES = 360;
|
|
11
|
-
var STYLED_SNAPSHOT_MARGIN = 6;
|
|
12
|
-
var SNAPSHOT_DELAY_MS = 120;
|
|
13
|
-
var fallbackChildScriptPath = fileURLToPath(new URL("./pi-host-child.ts", import.meta.url));
|
|
14
|
-
var activeHost = null;
|
|
15
|
-
function clampCols(cols) {
|
|
16
|
-
return Math.max(MIN_COLS, Math.trunc(cols || 100));
|
|
17
|
-
}
|
|
18
|
-
function clampRows(rows) {
|
|
19
|
-
return Math.max(MIN_ROWS, Math.min(MAX_ROWS, Math.trunc(rows || 35)));
|
|
20
|
-
}
|
|
21
|
-
var XTERM_COLOR_MODE_INDEXED_16 = 16777216;
|
|
22
|
-
var XTERM_COLOR_MODE_INDEXED_256 = 33554432;
|
|
23
|
-
var XTERM_COLOR_MODE_RGB = 50331648;
|
|
24
|
-
function rgbaFromXtermColor(mode, value) {
|
|
25
|
-
if (mode === 1 || mode === 2 || mode === XTERM_COLOR_MODE_INDEXED_16 || mode === XTERM_COLOR_MODE_INDEXED_256) {
|
|
26
|
-
return RGBA.fromIndex(value);
|
|
27
|
-
}
|
|
28
|
-
if (mode === 3 || mode === XTERM_COLOR_MODE_RGB) {
|
|
29
|
-
return RGBA.fromInts(value >> 16 & 255, value >> 8 & 255, value & 255);
|
|
30
|
-
}
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
function textAttributesFromCell(cell) {
|
|
34
|
-
let attributes = TextAttributes.NONE;
|
|
35
|
-
if (cell.isBold())
|
|
36
|
-
attributes |= TextAttributes.BOLD;
|
|
37
|
-
if (cell.isDim())
|
|
38
|
-
attributes |= TextAttributes.DIM;
|
|
39
|
-
if (cell.isItalic())
|
|
40
|
-
attributes |= TextAttributes.ITALIC;
|
|
41
|
-
if (cell.isUnderline())
|
|
42
|
-
attributes |= TextAttributes.UNDERLINE;
|
|
43
|
-
if (cell.isBlink())
|
|
44
|
-
attributes |= TextAttributes.BLINK;
|
|
45
|
-
if (cell.isInverse())
|
|
46
|
-
attributes |= TextAttributes.INVERSE;
|
|
47
|
-
if (cell.isInvisible())
|
|
48
|
-
attributes |= TextAttributes.HIDDEN;
|
|
49
|
-
if (cell.isStrikethrough())
|
|
50
|
-
attributes |= TextAttributes.STRIKETHROUGH;
|
|
51
|
-
return attributes;
|
|
52
|
-
}
|
|
53
|
-
function sameRgba(a, b) {
|
|
54
|
-
if (!a && !b)
|
|
55
|
-
return true;
|
|
56
|
-
return Boolean(a && b && a.equals(b));
|
|
57
|
-
}
|
|
58
|
-
function sameStyle(a, b) {
|
|
59
|
-
return sameRgba(a.fg, b.fg) && sameRgba(a.bg, b.bg) && (a.attributes ?? 0) === (b.attributes ?? 0);
|
|
60
|
-
}
|
|
61
|
-
function styleFromCell(cell) {
|
|
62
|
-
return {
|
|
63
|
-
fg: rgbaFromXtermColor(cell.getFgColorMode(), cell.getFgColor()),
|
|
64
|
-
bg: rgbaFromXtermColor(cell.getBgColorMode(), cell.getBgColor()),
|
|
65
|
-
attributes: textAttributesFromCell(cell)
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
function lineToStyledText(line, cols) {
|
|
69
|
-
if (!line)
|
|
70
|
-
return new StyledText([{ __isChunk: true, text: "" }]);
|
|
71
|
-
const chunks = [];
|
|
72
|
-
let run = "";
|
|
73
|
-
let runStyle = null;
|
|
74
|
-
const flush = () => {
|
|
75
|
-
if (!run)
|
|
76
|
-
return;
|
|
77
|
-
chunks.push({
|
|
78
|
-
__isChunk: true,
|
|
79
|
-
text: run,
|
|
80
|
-
...runStyle?.fg ? { fg: runStyle.fg } : {},
|
|
81
|
-
...runStyle?.bg ? { bg: runStyle.bg } : {},
|
|
82
|
-
...(runStyle?.attributes ?? 0) !== 0 ? { attributes: runStyle.attributes } : {}
|
|
83
|
-
});
|
|
84
|
-
run = "";
|
|
85
|
-
};
|
|
86
|
-
for (let index = 0;index < cols; index += 1) {
|
|
87
|
-
const cell = line.getCell(index);
|
|
88
|
-
if (!cell) {
|
|
89
|
-
if (runStyle !== null)
|
|
90
|
-
flush();
|
|
91
|
-
runStyle = null;
|
|
92
|
-
run += " ";
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
if (cell.getWidth() === 0)
|
|
96
|
-
continue;
|
|
97
|
-
const style = styleFromCell(cell);
|
|
98
|
-
if (!runStyle || !sameStyle(runStyle, style)) {
|
|
99
|
-
flush();
|
|
100
|
-
runStyle = style;
|
|
101
|
-
}
|
|
102
|
-
run += cell.getChars() || " ";
|
|
103
|
-
}
|
|
104
|
-
flush();
|
|
105
|
-
return new StyledText(chunks.length > 0 ? chunks : [{ __isChunk: true, text: "" }]);
|
|
106
|
-
}
|
|
107
|
-
function childCommandPrefix() {
|
|
108
|
-
const execName = basename(process.execPath).toLowerCase();
|
|
109
|
-
const currentEntry = process.argv[1];
|
|
110
|
-
if (execName === "bun" || execName === "bun.exe") {
|
|
111
|
-
return currentEntry ? [process.execPath, currentEntry, "__opentui-pi-host"] : [process.execPath, fallbackChildScriptPath];
|
|
112
|
-
}
|
|
113
|
-
return [process.execPath, "__opentui-pi-host"];
|
|
114
|
-
}
|
|
115
|
-
function withEnv(base) {
|
|
116
|
-
const env = {};
|
|
117
|
-
for (const [key, value] of Object.entries(base ?? process.env)) {
|
|
118
|
-
if (key === "RIG_PLAIN" || key === "RIG_CLI_PLAIN_HELP" || key === "NO_COLOR")
|
|
119
|
-
continue;
|
|
120
|
-
if (typeof value === "string")
|
|
121
|
-
env[key] = value;
|
|
122
|
-
}
|
|
123
|
-
return {
|
|
124
|
-
...env,
|
|
125
|
-
TERM: "xterm-256color",
|
|
126
|
-
COLORTERM: "truecolor",
|
|
127
|
-
FORCE_COLOR: env.FORCE_COLOR ?? "1",
|
|
128
|
-
RIG_OPENTUI_PI_HOST: "1"
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
3
|
function getActivePiHost() {
|
|
132
|
-
return
|
|
133
|
-
}
|
|
134
|
-
async function startPiPtyHost(options) {
|
|
135
|
-
activeHost?.dispose("replace");
|
|
136
|
-
const host = new PiPtyHost(options);
|
|
137
|
-
activeHost = host;
|
|
138
|
-
await host.start();
|
|
139
|
-
return host;
|
|
140
|
-
}
|
|
141
|
-
function stopActivePiHost(reason = "detach") {
|
|
142
|
-
activeHost?.dispose(reason);
|
|
143
|
-
activeHost = null;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
class PiPtyHost {
|
|
147
|
-
runId;
|
|
148
|
-
projectRoot;
|
|
149
|
-
onSnapshot;
|
|
150
|
-
onExit;
|
|
151
|
-
onError;
|
|
152
|
-
terminal;
|
|
153
|
-
disposables = [];
|
|
154
|
-
decoder = new TextDecoder("utf-8");
|
|
155
|
-
proc = null;
|
|
156
|
-
pty = null;
|
|
157
|
-
status = "starting";
|
|
158
|
-
cols;
|
|
159
|
-
rows;
|
|
160
|
-
message = "starting bundled Pi";
|
|
161
|
-
lastResizeError = null;
|
|
162
|
-
exitCode;
|
|
163
|
-
signal;
|
|
164
|
-
notifyTimer = null;
|
|
165
|
-
lastStreamKey = "";
|
|
166
|
-
_disposed = false;
|
|
167
|
-
constructor(options) {
|
|
168
|
-
this.runId = options.runId;
|
|
169
|
-
this.projectRoot = options.projectRoot;
|
|
170
|
-
this.cols = clampCols(options.cols);
|
|
171
|
-
this.rows = clampRows(options.rows);
|
|
172
|
-
this.onSnapshot = options.onSnapshot;
|
|
173
|
-
this.onExit = options.onExit;
|
|
174
|
-
this.onError = options.onError;
|
|
175
|
-
this.terminal = new XtermTerminal({
|
|
176
|
-
allowProposedApi: true,
|
|
177
|
-
cols: this.cols,
|
|
178
|
-
rows: this.rows,
|
|
179
|
-
scrollback: 1000
|
|
180
|
-
});
|
|
181
|
-
this.registerTerminalResponders();
|
|
182
|
-
this.disposables.push(this.terminal.onWriteParsed(() => {
|
|
183
|
-
if (this._disposed)
|
|
184
|
-
return;
|
|
185
|
-
const snapshot = this.createSnapshot();
|
|
186
|
-
const key = snapshot.lines.join(`
|
|
187
|
-
`);
|
|
188
|
-
if (key === this.lastStreamKey)
|
|
189
|
-
return;
|
|
190
|
-
this.lastStreamKey = key;
|
|
191
|
-
this.onSnapshot?.(snapshot);
|
|
192
|
-
}));
|
|
193
|
-
}
|
|
194
|
-
get disposed() {
|
|
195
|
-
return this._disposed;
|
|
196
|
-
}
|
|
197
|
-
get snapshot() {
|
|
198
|
-
return this.createSnapshot();
|
|
199
|
-
}
|
|
200
|
-
async start() {
|
|
201
|
-
if (this._disposed)
|
|
202
|
-
throw new Error("Pi PTY host is disposed.");
|
|
203
|
-
if (typeof Bun.Terminal !== "function") {
|
|
204
|
-
throw new Error("Bun native PTY is unavailable in this runtime. Pi host requires Bun.Terminal.");
|
|
205
|
-
}
|
|
206
|
-
const spawnOptions = {
|
|
207
|
-
cwd: this.projectRoot,
|
|
208
|
-
env: withEnv(process.env),
|
|
209
|
-
terminal: {
|
|
210
|
-
cols: this.cols,
|
|
211
|
-
rows: this.rows,
|
|
212
|
-
name: "xterm-256color",
|
|
213
|
-
data: (_terminal, data) => this.handlePtyData(data)
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
const proc = Bun.spawn([
|
|
217
|
-
...childCommandPrefix(),
|
|
218
|
-
"--run-id",
|
|
219
|
-
this.runId,
|
|
220
|
-
"--project-root",
|
|
221
|
-
this.projectRoot
|
|
222
|
-
], spawnOptions);
|
|
223
|
-
if (!proc.terminal)
|
|
224
|
-
throw new Error("Bun did not attach a terminal to the bundled Pi child process.");
|
|
225
|
-
this.proc = proc;
|
|
226
|
-
this.pty = proc.terminal;
|
|
227
|
-
this.status = "running";
|
|
228
|
-
this.message = "bundled Pi running inside this app";
|
|
229
|
-
this.emitSnapshotSoon(0);
|
|
230
|
-
proc.exited.then((exitCode) => {
|
|
231
|
-
if (this._disposed)
|
|
232
|
-
return;
|
|
233
|
-
this.status = exitCode === 0 ? "exited" : "failed";
|
|
234
|
-
this.exitCode = exitCode;
|
|
235
|
-
this.signal = null;
|
|
236
|
-
this.message = exitCode === 0 ? "bundled Pi exited" : `bundled Pi exited with code ${exitCode}`;
|
|
237
|
-
const snapshot = this.createSnapshot();
|
|
238
|
-
this.onSnapshot?.(snapshot);
|
|
239
|
-
this.onExit?.(snapshot);
|
|
240
|
-
if (activeHost === this)
|
|
241
|
-
activeHost = null;
|
|
242
|
-
this.dispose("exit", { kill: false, notify: false });
|
|
243
|
-
}).catch((error) => {
|
|
244
|
-
if (this._disposed)
|
|
245
|
-
return;
|
|
246
|
-
this.status = "failed";
|
|
247
|
-
this.message = error instanceof Error ? error.message : String(error);
|
|
248
|
-
const snapshot = this.createSnapshot();
|
|
249
|
-
this.onSnapshot?.(snapshot);
|
|
250
|
-
this.onError?.(error, snapshot);
|
|
251
|
-
if (activeHost === this)
|
|
252
|
-
activeHost = null;
|
|
253
|
-
this.dispose("error", { kill: false, notify: false });
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
write(data) {
|
|
257
|
-
if (this._disposed || !this.pty)
|
|
258
|
-
return;
|
|
259
|
-
try {
|
|
260
|
-
this.pty.write(data);
|
|
261
|
-
} catch (error) {
|
|
262
|
-
this.status = "failed";
|
|
263
|
-
this.message = error instanceof Error ? error.message : String(error);
|
|
264
|
-
const snapshot = this.createSnapshot();
|
|
265
|
-
this.onSnapshot?.(snapshot);
|
|
266
|
-
this.onError?.(error, snapshot);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
resize(cols, rows) {
|
|
270
|
-
const nextCols = clampCols(cols);
|
|
271
|
-
const nextRows = clampRows(rows);
|
|
272
|
-
if (nextCols === this.cols && nextRows === this.rows)
|
|
273
|
-
return;
|
|
274
|
-
this.cols = nextCols;
|
|
275
|
-
this.rows = nextRows;
|
|
276
|
-
this.terminal.resize(nextCols, nextRows);
|
|
277
|
-
try {
|
|
278
|
-
this.pty?.resize(nextCols, nextRows);
|
|
279
|
-
this.lastResizeError = null;
|
|
280
|
-
} catch (error) {
|
|
281
|
-
this.lastResizeError = error instanceof Error ? error.message : String(error);
|
|
282
|
-
}
|
|
283
|
-
this.emitSnapshotSoon(0);
|
|
284
|
-
}
|
|
285
|
-
detach() {
|
|
286
|
-
this.dispose("detach");
|
|
287
|
-
return this.createSnapshot("detached from bundled Pi");
|
|
288
|
-
}
|
|
289
|
-
dispose(reason = "dispose", options = {}) {
|
|
290
|
-
if (this._disposed)
|
|
291
|
-
return;
|
|
292
|
-
this._disposed = true;
|
|
293
|
-
if (this.notifyTimer)
|
|
294
|
-
clearTimeout(this.notifyTimer);
|
|
295
|
-
this.notifyTimer = null;
|
|
296
|
-
for (const disposable of this.disposables.splice(0)) {
|
|
297
|
-
try {
|
|
298
|
-
disposable.dispose();
|
|
299
|
-
} catch {}
|
|
300
|
-
}
|
|
301
|
-
if (options.kill !== false) {
|
|
302
|
-
try {
|
|
303
|
-
this.proc?.kill("SIGTERM");
|
|
304
|
-
} catch {}
|
|
305
|
-
}
|
|
306
|
-
try {
|
|
307
|
-
this.pty?.close();
|
|
308
|
-
} catch {}
|
|
309
|
-
try {
|
|
310
|
-
this.terminal.dispose();
|
|
311
|
-
} catch {}
|
|
312
|
-
if (activeHost === this)
|
|
313
|
-
activeHost = null;
|
|
314
|
-
if (options.notify) {
|
|
315
|
-
this.message = reason;
|
|
316
|
-
this.onSnapshot?.(this.createSnapshot(reason));
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
handlePtyData(data) {
|
|
320
|
-
if (this._disposed)
|
|
321
|
-
return;
|
|
322
|
-
const text = this.decoder.decode(data, { stream: true });
|
|
323
|
-
this.respondToRawTerminalQueries(text);
|
|
324
|
-
this.terminal.write(data);
|
|
325
|
-
}
|
|
326
|
-
emitSnapshotSoon(delayMs = SNAPSHOT_DELAY_MS) {
|
|
327
|
-
if (this._disposed || this.notifyTimer)
|
|
328
|
-
return;
|
|
329
|
-
this.notifyTimer = setTimeout(() => {
|
|
330
|
-
this.notifyTimer = null;
|
|
331
|
-
if (this._disposed)
|
|
332
|
-
return;
|
|
333
|
-
this.onSnapshot?.(this.createSnapshot());
|
|
334
|
-
}, delayMs);
|
|
335
|
-
}
|
|
336
|
-
createSnapshot(message = this.message) {
|
|
337
|
-
const buffer = this.terminal.buffer.active;
|
|
338
|
-
const end = buffer.length;
|
|
339
|
-
const start = Math.max(0, end - MAX_SNAPSHOT_LINES);
|
|
340
|
-
const styledStart = Math.max(start, end - this.rows - STYLED_SNAPSHOT_MARGIN);
|
|
341
|
-
const lines = [];
|
|
342
|
-
const styledLines = [];
|
|
343
|
-
for (let row = start;row < end; row += 1) {
|
|
344
|
-
const line = buffer.getLine(row);
|
|
345
|
-
lines.push((line?.translateToString(false) ?? "").slice(0, this.cols));
|
|
346
|
-
if (row >= styledStart)
|
|
347
|
-
styledLines[lines.length - 1] = lineToStyledText(line, this.cols);
|
|
348
|
-
}
|
|
349
|
-
while (lines.length < this.rows) {
|
|
350
|
-
lines.push("");
|
|
351
|
-
styledLines[lines.length - 1] = new StyledText([{ __isChunk: true, text: "" }]);
|
|
352
|
-
}
|
|
353
|
-
const resolvedMessage = this.lastResizeError ? `resize degraded: ${this.lastResizeError}` : message;
|
|
354
|
-
return {
|
|
355
|
-
runId: this.runId,
|
|
356
|
-
status: this.status,
|
|
357
|
-
cols: this.cols,
|
|
358
|
-
rows: this.rows,
|
|
359
|
-
lines,
|
|
360
|
-
styledLines,
|
|
361
|
-
message: resolvedMessage,
|
|
362
|
-
...this.lastResizeError ? { resizeError: this.lastResizeError } : {},
|
|
363
|
-
...this.exitCode !== undefined ? { exitCode: this.exitCode } : {},
|
|
364
|
-
...this.signal !== undefined ? { signal: this.signal } : {}
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
registerTerminalResponders() {
|
|
368
|
-
this.disposables.push(this.terminal.parser.registerCsiHandler({ final: "c" }, (params) => {
|
|
369
|
-
if (params.length === 0 || params[0] === 0)
|
|
370
|
-
this.write("\x1B[?62;22c");
|
|
371
|
-
return false;
|
|
372
|
-
}));
|
|
373
|
-
this.disposables.push(this.terminal.parser.registerCsiHandler({ prefix: ">", final: "c" }, (params) => {
|
|
374
|
-
if (params.length === 0 || params[0] === 0)
|
|
375
|
-
this.write("\x1B[>0;0;0c");
|
|
376
|
-
return false;
|
|
377
|
-
}));
|
|
378
|
-
this.disposables.push(this.terminal.parser.registerCsiHandler({ final: "n" }, (params) => {
|
|
379
|
-
if (params[0] === 5) {
|
|
380
|
-
this.write("\x1B[0n");
|
|
381
|
-
} else if (params[0] === 6) {
|
|
382
|
-
const row = this.terminal.buffer.active.cursorY + 1;
|
|
383
|
-
const col = this.terminal.buffer.active.cursorX + 1;
|
|
384
|
-
this.write(`\x1B[${row};${col}R`);
|
|
385
|
-
}
|
|
386
|
-
return false;
|
|
387
|
-
}));
|
|
388
|
-
}
|
|
389
|
-
respondToRawTerminalQueries(text) {
|
|
390
|
-
if (!text)
|
|
391
|
-
return;
|
|
392
|
-
const decrqm = /\x1b\[\?(\d+)\$p/g;
|
|
393
|
-
let match;
|
|
394
|
-
while ((match = decrqm.exec(text)) !== null) {
|
|
395
|
-
this.write(`\x1B[?${match[1]};2$y`);
|
|
396
|
-
}
|
|
397
|
-
}
|
|
4
|
+
return null;
|
|
398
5
|
}
|
|
6
|
+
function stopActivePiHost(_reason) {}
|
|
399
7
|
export {
|
|
400
8
|
stopActivePiHost,
|
|
401
|
-
|
|
402
|
-
getActivePiHost,
|
|
403
|
-
PiPtyHost
|
|
9
|
+
getActivePiHost
|
|
404
10
|
};
|