@lune_99/pi-shell-inspector 0.1.0 → 1.3.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/CHANGELOG.md +24 -4
- package/README.md +12 -11
- package/package.json +1 -1
- package/src/index.ts +36 -25
- package/src/shell/dock-alert.ts +78 -0
- package/src/shell/dock-line.ts +42 -0
- package/src/shell/inspector/frame.ts +7 -7
- package/src/shell/inspector/geometry.ts +1 -4
- package/src/shell/inspector/job-format.ts +4 -1
- package/src/shell/inspector/output-rows.ts +3 -1
- package/src/shell/inspector/panes.ts +4 -1
- package/src/shell/shell-dock-contribution.ts +89 -55
- package/src/shell/shell-dock.ts +92 -35
- package/src/shell/shell-inspector.ts +37 -20
- package/src/shell/shell-manager.ts +42 -67
- package/src/shell/shell-notification-box.ts +32 -9
- package/src/shell/shell-notification.ts +51 -34
- package/src/tools/background-bash.ts +10 -9
- package/src/tools/bash-tool.ts +16 -16
- package/src/utils/get-agent-tool-result.ts +2 -2
package/src/shell/shell-dock.ts
CHANGED
|
@@ -1,20 +1,34 @@
|
|
|
1
1
|
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
2
|
+
import { fitRanked, type RankedPart } from "./dock-line.ts";
|
|
3
|
+
import type { ShellManager } from "./shell-manager.ts";
|
|
4
|
+
import { collapseShellCommand } from "./shell-command.ts";
|
|
5
5
|
|
|
6
6
|
const WIDGET_ID = "pi-shell-inspector";
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Ranks of the parts after the row's lead: a narrow row drops the lowest first, so failures stay
|
|
10
|
+
* longest and the hint goes first. The lead itself is never left out.
|
|
11
|
+
*/
|
|
12
|
+
const FAILED_RANK = 6;
|
|
13
|
+
const KILLED_RANK = 5;
|
|
14
|
+
const RUNNING_RANK = 4;
|
|
15
|
+
const COMPLETED_RANK = 3;
|
|
16
|
+
const COMMAND_RANK = 2;
|
|
17
|
+
const ELAPSED_RANK = 1;
|
|
18
|
+
const HINT_RANK = 0;
|
|
8
19
|
|
|
9
20
|
export class ShellDock {
|
|
10
21
|
private refreshTimer: ReturnType<typeof setInterval> | undefined;
|
|
11
22
|
private selected = false;
|
|
12
23
|
private ctx: ExtensionContext | undefined;
|
|
24
|
+
private readonly manager: ShellManager;
|
|
13
25
|
|
|
14
|
-
constructor() {
|
|
26
|
+
constructor(manager: ShellManager) {
|
|
27
|
+
this.manager = manager;
|
|
28
|
+
}
|
|
15
29
|
|
|
16
30
|
private syncRefreshTimer(): void {
|
|
17
|
-
const hasRunningJobs =
|
|
31
|
+
const hasRunningJobs = this.manager.jobsStatusStat.runningCount > 0;
|
|
18
32
|
|
|
19
33
|
if (hasRunningJobs && !this.refreshTimer) {
|
|
20
34
|
this.refreshTimer = setInterval(() => {
|
|
@@ -46,11 +60,13 @@ export class ShellDock {
|
|
|
46
60
|
}
|
|
47
61
|
|
|
48
62
|
render(): void {
|
|
49
|
-
if (!this.ctx || !this.ctx.hasUI) {
|
|
63
|
+
if (!this.ctx || !this.ctx.hasUI) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
50
66
|
|
|
51
67
|
this.syncRefreshTimer();
|
|
52
68
|
|
|
53
|
-
const jobs =
|
|
69
|
+
const jobs = this.manager.getAllJobsList();
|
|
54
70
|
|
|
55
71
|
if (jobs.length === 0) {
|
|
56
72
|
this.selected = false;
|
|
@@ -58,13 +74,22 @@ export class ShellDock {
|
|
|
58
74
|
return;
|
|
59
75
|
}
|
|
60
76
|
|
|
61
|
-
const
|
|
77
|
+
const { lead, parts } = shellDockSummary(this.ctx, this.manager);
|
|
78
|
+
const separator = this.ctx.ui.theme.fg("dim", " · ");
|
|
62
79
|
|
|
80
|
+
// Pi pads string rows by one column on each side; this row keeps the same margins.
|
|
63
81
|
this.ctx.ui.setWidget(
|
|
64
82
|
WIDGET_ID,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
83
|
+
() => ({
|
|
84
|
+
render: (width) => [
|
|
85
|
+
` ${
|
|
86
|
+
fitRanked(parts, Math.max(0, width - 2), (texts) =>
|
|
87
|
+
[lead, ...texts].join(separator),
|
|
88
|
+
) ?? ""
|
|
89
|
+
}`,
|
|
90
|
+
],
|
|
91
|
+
invalidate() {},
|
|
92
|
+
}),
|
|
68
93
|
{
|
|
69
94
|
placement: "belowEditor",
|
|
70
95
|
},
|
|
@@ -79,15 +104,22 @@ export class ShellDock {
|
|
|
79
104
|
this.refreshTimer = undefined;
|
|
80
105
|
}
|
|
81
106
|
|
|
82
|
-
if (!this.ctx || !this.ctx.hasUI) {
|
|
107
|
+
if (!this.ctx || !this.ctx.hasUI) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
83
110
|
|
|
84
111
|
this.selected = false;
|
|
85
112
|
this.ctx.ui.setWidget(WIDGET_ID, undefined);
|
|
86
113
|
}
|
|
87
114
|
}
|
|
88
115
|
|
|
89
|
-
|
|
90
|
-
|
|
116
|
+
/** The lead names the jobs; the parts after it are left out whole while the row is too wide. */
|
|
117
|
+
function shellDockSummary(
|
|
118
|
+
ctx: ExtensionContext,
|
|
119
|
+
manager: ShellManager,
|
|
120
|
+
): { lead: string; parts: RankedPart[] } {
|
|
121
|
+
const status = manager.getAllJobsStatusStat();
|
|
122
|
+
const hint = { text: ctx.ui.theme.fg("dim", "/shell to open"), rank: HINT_RANK };
|
|
91
123
|
|
|
92
124
|
// only one running shell case
|
|
93
125
|
if (
|
|
@@ -96,39 +128,64 @@ function shellDockSummary(ctx: ExtensionContext): string {
|
|
|
96
128
|
status.failedCount === 0 &&
|
|
97
129
|
status.killedCount === 0
|
|
98
130
|
) {
|
|
99
|
-
const runningJob =
|
|
131
|
+
const runningJob = manager.getRunningJobsList()[0];
|
|
100
132
|
const elapsedTime = Math.floor((Date.now() - runningJob!.startedAt) / 1000);
|
|
101
|
-
return
|
|
102
|
-
ctx.ui.theme.fg("accent", `${status.runningCount} running shell`),
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
133
|
+
return {
|
|
134
|
+
lead: ctx.ui.theme.fg("accent", `${status.runningCount} running shell`),
|
|
135
|
+
parts: [
|
|
136
|
+
{ text: collapseShellCommand(runningJob!.command), rank: COMMAND_RANK },
|
|
137
|
+
{ text: `${elapsedTime}s`, rank: ELAPSED_RANK },
|
|
138
|
+
hint,
|
|
139
|
+
],
|
|
140
|
+
};
|
|
106
141
|
}
|
|
107
142
|
// only one completed shell case
|
|
108
|
-
if (
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
143
|
+
if (
|
|
144
|
+
status.completedCount === 1 &&
|
|
145
|
+
status.runningCount === 0 &&
|
|
146
|
+
status.failedCount === 0 &&
|
|
147
|
+
status.killedCount === 0
|
|
148
|
+
) {
|
|
149
|
+
const completedJob = manager.getCompletedJobsList()[0];
|
|
150
|
+
const elapsedTime = Math.floor(
|
|
151
|
+
(completedJob!.finishedAt! - completedJob!.startedAt) / 1000,
|
|
152
|
+
);
|
|
153
|
+
return {
|
|
154
|
+
lead:
|
|
155
|
+
ctx.ui.theme.fg("success", `${status.completedCount} shell completed`) +
|
|
156
|
+
` in ${elapsedTime}s`,
|
|
157
|
+
parts: [hint],
|
|
158
|
+
};
|
|
112
159
|
}
|
|
113
160
|
|
|
114
|
-
const parts:
|
|
115
|
-
const jobCount =
|
|
116
|
-
parts.push(`${jobCount} ${jobCount === 1 ? "shell" : "shells"}`);
|
|
161
|
+
const parts: RankedPart[] = [];
|
|
162
|
+
const jobCount = manager.getAllJobsList().length;
|
|
117
163
|
|
|
118
164
|
if (status.runningCount > 0) {
|
|
119
|
-
parts.push(
|
|
165
|
+
parts.push({
|
|
166
|
+
text: ctx.ui.theme.fg("accent", `${status.runningCount} running`),
|
|
167
|
+
rank: RUNNING_RANK,
|
|
168
|
+
});
|
|
120
169
|
}
|
|
121
170
|
if (status.completedCount > 0) {
|
|
122
|
-
parts.push(
|
|
171
|
+
parts.push({
|
|
172
|
+
text: ctx.ui.theme.fg("success", `${status.completedCount} completed`),
|
|
173
|
+
rank: COMPLETED_RANK,
|
|
174
|
+
});
|
|
123
175
|
}
|
|
124
176
|
if (status.failedCount > 0) {
|
|
125
|
-
parts.push(
|
|
177
|
+
parts.push({
|
|
178
|
+
text: ctx.ui.theme.fg("error", `${status.failedCount} failed`),
|
|
179
|
+
rank: FAILED_RANK,
|
|
180
|
+
});
|
|
126
181
|
}
|
|
127
182
|
if (status.killedCount > 0) {
|
|
128
|
-
parts.push(
|
|
183
|
+
parts.push({
|
|
184
|
+
text: ctx.ui.theme.fg("error", `${status.killedCount} killed`),
|
|
185
|
+
rank: KILLED_RANK,
|
|
186
|
+
});
|
|
129
187
|
}
|
|
188
|
+
parts.push(hint);
|
|
130
189
|
|
|
131
|
-
return `${
|
|
190
|
+
return { lead: `${jobCount} ${jobCount === 1 ? "shell" : "shells"}`, parts };
|
|
132
191
|
}
|
|
133
|
-
|
|
134
|
-
export const shellDock = new ShellDock();
|
|
@@ -15,22 +15,31 @@ import {
|
|
|
15
15
|
renderFooter,
|
|
16
16
|
renderHeader,
|
|
17
17
|
} from "./inspector/frame.ts";
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
BODY_TOP,
|
|
20
|
+
listWindowStart,
|
|
21
|
+
paneGeometry,
|
|
22
|
+
type PaneGeometry,
|
|
23
|
+
} from "./inspector/geometry.ts";
|
|
19
24
|
import { CommandPreviews, type ThemeColor } from "./inspector/job-format.ts";
|
|
20
25
|
import { OutputRowsCache } from "./inspector/output-rows.ts";
|
|
21
26
|
import { OutputViewport } from "./inspector/output-viewport.ts";
|
|
22
27
|
import { renderDetails, renderEmptyList, renderJobList } from "./inspector/panes.ts";
|
|
23
28
|
import { ScrollbarVisibility } from "./inspector/scrollbar.ts";
|
|
24
29
|
import { formatShellCommand } from "./shell-command.ts";
|
|
25
|
-
import {
|
|
30
|
+
import type { ShellManager } from "./shell-manager.ts";
|
|
26
31
|
|
|
27
32
|
const REFRESH_INTERVAL_MS = 1000;
|
|
28
33
|
|
|
29
|
-
export async function openShellInspector(
|
|
34
|
+
export async function openShellInspector(
|
|
35
|
+
ctx: ExtensionContext,
|
|
36
|
+
manager: ShellManager,
|
|
37
|
+
): Promise<void> {
|
|
30
38
|
await ctx.ui.custom<void>(
|
|
31
39
|
(tui, _theme, _keybindings, done) => {
|
|
32
40
|
const inspector = new ShellInspector(
|
|
33
41
|
ctx,
|
|
42
|
+
manager,
|
|
34
43
|
() => tui.requestRender(),
|
|
35
44
|
() => done(),
|
|
36
45
|
() => tui.terminal.rows,
|
|
@@ -68,6 +77,7 @@ interface FrameLayout {
|
|
|
68
77
|
|
|
69
78
|
export class ShellInspector implements Component {
|
|
70
79
|
private readonly ctx: ExtensionContext;
|
|
80
|
+
private readonly manager: ShellManager;
|
|
71
81
|
private readonly requestRender: () => void;
|
|
72
82
|
private readonly close: () => void;
|
|
73
83
|
private readonly terminalRows: () => number;
|
|
@@ -87,12 +97,14 @@ export class ShellInspector implements Component {
|
|
|
87
97
|
|
|
88
98
|
constructor(
|
|
89
99
|
ctx: ExtensionContext,
|
|
100
|
+
manager: ShellManager,
|
|
90
101
|
requestRender: () => void,
|
|
91
102
|
close: () => void,
|
|
92
103
|
terminalRows: () => number = () => 40,
|
|
93
104
|
theme: Theme = ctx.ui.theme,
|
|
94
105
|
) {
|
|
95
106
|
this.ctx = ctx;
|
|
107
|
+
this.manager = manager;
|
|
96
108
|
this.requestRender = requestRender;
|
|
97
109
|
this.close = close;
|
|
98
110
|
this.terminalRows = terminalRows;
|
|
@@ -103,9 +115,9 @@ export class ShellInspector implements Component {
|
|
|
103
115
|
|
|
104
116
|
// The index is memory-only state on the manager: reopening the overlay resumes the last
|
|
105
117
|
// selection, while a fresh session starts on the first shell.
|
|
106
|
-
this.selectedIndex =
|
|
118
|
+
this.selectedIndex = this.manager.getInspectorIndex();
|
|
107
119
|
|
|
108
|
-
this.unsubscribeJobs =
|
|
120
|
+
this.unsubscribeJobs = this.manager.subscribe(() => {
|
|
109
121
|
this.syncRefreshTimer();
|
|
110
122
|
this.requestRender();
|
|
111
123
|
});
|
|
@@ -120,7 +132,7 @@ export class ShellInspector implements Component {
|
|
|
120
132
|
return;
|
|
121
133
|
}
|
|
122
134
|
|
|
123
|
-
const jobs =
|
|
135
|
+
const jobs = this.manager.getAllJobsList();
|
|
124
136
|
|
|
125
137
|
if (jobs.length === 0) {
|
|
126
138
|
return;
|
|
@@ -130,7 +142,7 @@ export class ShellInspector implements Component {
|
|
|
130
142
|
const chosenJob = jobs[this.selectedIndex];
|
|
131
143
|
|
|
132
144
|
if (chosenJob) {
|
|
133
|
-
|
|
145
|
+
this.manager.settleJob(chosenJob.id, {
|
|
134
146
|
type: "killed",
|
|
135
147
|
error: "Shell killed by user",
|
|
136
148
|
});
|
|
@@ -217,7 +229,7 @@ export class ShellInspector implements Component {
|
|
|
217
229
|
|
|
218
230
|
const row = event.y - BODY_TOP;
|
|
219
231
|
const index = layout.listStart + row;
|
|
220
|
-
const jobCount =
|
|
232
|
+
const jobCount = this.manager.getAllJobsList().length;
|
|
221
233
|
|
|
222
234
|
if (
|
|
223
235
|
event.x < 1 ||
|
|
@@ -235,7 +247,7 @@ export class ShellInspector implements Component {
|
|
|
235
247
|
}
|
|
236
248
|
|
|
237
249
|
render(width: number): string[] {
|
|
238
|
-
const jobs =
|
|
250
|
+
const jobs = this.manager.getAllJobsList();
|
|
239
251
|
const hasJobs = jobs.length > 0;
|
|
240
252
|
|
|
241
253
|
this.syncRefreshTimer();
|
|
@@ -248,7 +260,7 @@ export class ShellInspector implements Component {
|
|
|
248
260
|
}
|
|
249
261
|
|
|
250
262
|
// The clamped index is what the user sees, so it is also what a later reopen should restore.
|
|
251
|
-
|
|
263
|
+
this.manager.setInspectorIndex(this.selectedIndex);
|
|
252
264
|
|
|
253
265
|
const geometry = paneGeometry(width, this.terminalRows());
|
|
254
266
|
const { bodyHeight, leftWidth, rightWidth } = geometry;
|
|
@@ -284,7 +296,7 @@ export class ShellInspector implements Component {
|
|
|
284
296
|
this.previews,
|
|
285
297
|
{
|
|
286
298
|
job,
|
|
287
|
-
output: this.outputs.get(
|
|
299
|
+
output: this.outputs.get(this.manager, job.id, this.outputWidth),
|
|
288
300
|
viewport: this.viewport,
|
|
289
301
|
showScrollbar: this.scrollbars.isVisible("output"),
|
|
290
302
|
},
|
|
@@ -298,7 +310,7 @@ export class ShellInspector implements Component {
|
|
|
298
310
|
this.theme,
|
|
299
311
|
geometry.innerWidth,
|
|
300
312
|
jobs.length,
|
|
301
|
-
|
|
313
|
+
this.manager.jobsStatusStat.runningCount,
|
|
302
314
|
);
|
|
303
315
|
const separator = renderBottomSeparator(
|
|
304
316
|
this.theme,
|
|
@@ -337,14 +349,19 @@ export class ShellInspector implements Component {
|
|
|
337
349
|
this.unsubscribeJobs = undefined;
|
|
338
350
|
}
|
|
339
351
|
|
|
340
|
-
private clearSelectedJob(
|
|
352
|
+
private clearSelectedJob(
|
|
353
|
+
job: Readonly<{ id: string; label?: string; command: string }> | undefined,
|
|
354
|
+
): void {
|
|
341
355
|
if (!job) {
|
|
342
356
|
return;
|
|
343
357
|
}
|
|
344
358
|
|
|
345
|
-
if (
|
|
359
|
+
if (this.manager.clearJob(job.id)) {
|
|
346
360
|
this.viewport.follow();
|
|
347
|
-
this.showNotice(
|
|
361
|
+
this.showNotice(
|
|
362
|
+
`Cleared ${formatShellCommand(job.label ?? job.command, 28)}`,
|
|
363
|
+
"success",
|
|
364
|
+
);
|
|
348
365
|
} else {
|
|
349
366
|
this.showNotice("Clear failed, only completed, failed, or killed", "accent");
|
|
350
367
|
}
|
|
@@ -356,7 +373,7 @@ export class ShellInspector implements Component {
|
|
|
356
373
|
}
|
|
357
374
|
|
|
358
375
|
private moveSelection(step: number): void {
|
|
359
|
-
const jobCount =
|
|
376
|
+
const jobCount = this.manager.getAllJobsList().length;
|
|
360
377
|
|
|
361
378
|
if (jobCount === 0 || step === 0) {
|
|
362
379
|
return;
|
|
@@ -371,7 +388,7 @@ export class ShellInspector implements Component {
|
|
|
371
388
|
}
|
|
372
389
|
|
|
373
390
|
this.selectedIndex = index;
|
|
374
|
-
|
|
391
|
+
this.manager.setInspectorIndex(index);
|
|
375
392
|
|
|
376
393
|
// A different job has a different output; reading it from the middle would be confusing.
|
|
377
394
|
this.viewport.follow();
|
|
@@ -385,14 +402,14 @@ export class ShellInspector implements Component {
|
|
|
385
402
|
}
|
|
386
403
|
|
|
387
404
|
private scrollOutput(step: number): void {
|
|
388
|
-
const job =
|
|
405
|
+
const job = this.manager.getAllJobsList()[this.selectedIndex];
|
|
389
406
|
|
|
390
407
|
if (!job) {
|
|
391
408
|
return;
|
|
392
409
|
}
|
|
393
410
|
|
|
394
411
|
const result = this.viewport.scrollBy(step, () =>
|
|
395
|
-
this.outputs.get(
|
|
412
|
+
this.outputs.get(this.manager, job.id, this.outputWidth),
|
|
396
413
|
);
|
|
397
414
|
|
|
398
415
|
if (result === "ignored") {
|
|
@@ -423,7 +440,7 @@ export class ShellInspector implements Component {
|
|
|
423
440
|
}
|
|
424
441
|
|
|
425
442
|
private syncRefreshTimer(): void {
|
|
426
|
-
const hasRunningJobs =
|
|
443
|
+
const hasRunningJobs = this.manager.jobsStatusStat.runningCount > 0;
|
|
427
444
|
|
|
428
445
|
if (hasRunningJobs && !this.refreshTimer) {
|
|
429
446
|
this.refreshTimer = setInterval(() => {
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_MAX_LINES,
|
|
3
|
+
truncateTail,
|
|
4
|
+
type ExtensionAPI,
|
|
5
|
+
type ExtensionContext,
|
|
6
|
+
} from "@earendil-works/pi-coding-agent";
|
|
2
7
|
import xterm, { type Terminal as XtermTerminal } from "@xterm/headless";
|
|
3
8
|
|
|
4
9
|
// @xterm/headless ships CommonJS, and its UMD factory hides the exports from Node's
|
|
5
10
|
// named-export detection, so the class has to come off the default import.
|
|
6
11
|
const { Terminal } = xterm;
|
|
7
12
|
|
|
8
|
-
import {
|
|
9
|
-
appendFileSync,
|
|
10
|
-
writeFileSync,
|
|
11
|
-
} from "node:fs";
|
|
13
|
+
import { appendFileSync, writeFileSync } from "node:fs";
|
|
12
14
|
import { join } from "node:path";
|
|
13
15
|
import { randomUUID } from "node:crypto";
|
|
14
16
|
import { tmpdir } from "node:os";
|
|
@@ -35,11 +37,7 @@ const screenRevisions = new WeakMap<XtermTerminal, number>();
|
|
|
35
37
|
// Beside the terminal instead of on ShellJob: the job record is what tests and the snapshot see.
|
|
36
38
|
const screenFeeds = new WeakMap<XtermTerminal, ScreenFeed>();
|
|
37
39
|
|
|
38
|
-
export type ShellJobStatus =
|
|
39
|
-
| "running"
|
|
40
|
-
| "completed"
|
|
41
|
-
| "failed"
|
|
42
|
-
| "killed";
|
|
40
|
+
export type ShellJobStatus = "running" | "completed" | "failed" | "killed";
|
|
43
41
|
|
|
44
42
|
export interface ShellJob {
|
|
45
43
|
id: string;
|
|
@@ -95,22 +93,22 @@ export type ShellManagerEvent =
|
|
|
95
93
|
| { type: "job-killed"; id: string }
|
|
96
94
|
| { type: "job-cleared"; id: string }
|
|
97
95
|
| { type: "output-updated"; id: string }
|
|
98
|
-
| { type: "jobs-cleared" }
|
|
96
|
+
| { type: "jobs-cleared" };
|
|
99
97
|
|
|
100
98
|
export type ShellJobOutcome =
|
|
101
99
|
| {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
100
|
+
type: "completed";
|
|
101
|
+
exitCode?: number;
|
|
102
|
+
}
|
|
105
103
|
| {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
104
|
+
type: "failed";
|
|
105
|
+
error: string;
|
|
106
|
+
exitCode?: number;
|
|
107
|
+
}
|
|
110
108
|
| {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
109
|
+
type: "killed";
|
|
110
|
+
error?: string;
|
|
111
|
+
};
|
|
114
112
|
|
|
115
113
|
export type ShellManagerListener = (event: ShellManagerEvent) => void;
|
|
116
114
|
|
|
@@ -173,12 +171,12 @@ export class ShellManager {
|
|
|
173
171
|
|
|
174
172
|
this.emit({
|
|
175
173
|
type: "job-started",
|
|
176
|
-
id: input.id
|
|
174
|
+
id: input.id,
|
|
177
175
|
});
|
|
178
176
|
}
|
|
179
177
|
|
|
180
178
|
/**
|
|
181
|
-
*
|
|
179
|
+
*
|
|
182
180
|
* @param pi The extension API instance, used to persist the current state of all jobs and their statistics to the pi session log.
|
|
183
181
|
*/
|
|
184
182
|
clearAllJobs(pi?: ExtensionAPI): void {
|
|
@@ -191,8 +189,8 @@ export class ShellManager {
|
|
|
191
189
|
// Persist the current state of all jobs and their statistics to the pi session log.
|
|
192
190
|
if (pi) {
|
|
193
191
|
pi.appendEntry("pi-shell-inspector-view-status", {
|
|
194
|
-
jobs: this.getAllJobsList().map(job => this.getJobSnapshot(job.id)),
|
|
195
|
-
stats: this.getAllJobsStatusStat()
|
|
192
|
+
jobs: this.getAllJobsList().map((job) => this.getJobSnapshot(job.id)),
|
|
193
|
+
stats: this.getAllJobsStatusStat(),
|
|
196
194
|
});
|
|
197
195
|
}
|
|
198
196
|
|
|
@@ -206,14 +204,11 @@ export class ShellManager {
|
|
|
206
204
|
this.clearManagerstatus();
|
|
207
205
|
this.inspectorIndex = 0;
|
|
208
206
|
this.emit({
|
|
209
|
-
type: "jobs-cleared"
|
|
207
|
+
type: "jobs-cleared",
|
|
210
208
|
});
|
|
211
|
-
}
|
|
209
|
+
}
|
|
212
210
|
|
|
213
|
-
appendOutput(
|
|
214
|
-
id: string,
|
|
215
|
-
chunk: string,
|
|
216
|
-
): void {
|
|
211
|
+
appendOutput(id: string, chunk: string): void {
|
|
217
212
|
const job = this.getRunningJob(id);
|
|
218
213
|
const next = job.output.content + chunk;
|
|
219
214
|
job.output.totalBytes += Buffer.byteLength(chunk);
|
|
@@ -228,10 +223,7 @@ export class ShellManager {
|
|
|
228
223
|
if (!truncation.truncated) {
|
|
229
224
|
job.output.content = next;
|
|
230
225
|
} else {
|
|
231
|
-
const path = join(
|
|
232
|
-
tmpdir(),
|
|
233
|
-
`pi-shell-inspector-bash-${randomUUID()}.log`,
|
|
234
|
-
);
|
|
226
|
+
const path = join(tmpdir(), `pi-shell-inspector-bash-${randomUUID()}.log`);
|
|
235
227
|
writeFileSync(path, next, "utf8");
|
|
236
228
|
|
|
237
229
|
job.output.fullOutputPath = path;
|
|
@@ -248,7 +240,7 @@ export class ShellManager {
|
|
|
248
240
|
|
|
249
241
|
this.emit({
|
|
250
242
|
type: "output-updated",
|
|
251
|
-
id: id
|
|
243
|
+
id: id,
|
|
252
244
|
});
|
|
253
245
|
}
|
|
254
246
|
|
|
@@ -326,15 +318,11 @@ export class ShellManager {
|
|
|
326
318
|
}
|
|
327
319
|
|
|
328
320
|
getRunningJobsList(): readonly Readonly<ShellJob>[] {
|
|
329
|
-
return Array.from(this.jobs.values()).filter(
|
|
330
|
-
(job) => job.status === "running",
|
|
331
|
-
);
|
|
321
|
+
return Array.from(this.jobs.values()).filter((job) => job.status === "running");
|
|
332
322
|
}
|
|
333
323
|
|
|
334
324
|
getCompletedJobsList(): readonly Readonly<ShellJob>[] {
|
|
335
|
-
return Array.from(this.jobs.values()).filter(
|
|
336
|
-
(job) => job.status === "completed",
|
|
337
|
-
);
|
|
325
|
+
return Array.from(this.jobs.values()).filter((job) => job.status === "completed");
|
|
338
326
|
}
|
|
339
327
|
|
|
340
328
|
getAllJobsStatusStat(): JobsStatusStat {
|
|
@@ -354,10 +342,7 @@ export class ShellManager {
|
|
|
354
342
|
};
|
|
355
343
|
}
|
|
356
344
|
|
|
357
|
-
settleJob(
|
|
358
|
-
id: string,
|
|
359
|
-
outcome: ShellJobOutcome,
|
|
360
|
-
): boolean {
|
|
345
|
+
settleJob(id: string, outcome: ShellJobOutcome): boolean {
|
|
361
346
|
// Settling is idempotent: the detached execution can race session teardown, and a job that
|
|
362
347
|
// is unknown or no longer running must not be settled again (or counted twice).
|
|
363
348
|
if (this.getJob(id)?.status !== "running") {
|
|
@@ -379,9 +364,9 @@ export class ShellManager {
|
|
|
379
364
|
const shellStateEntry = [...ctx.sessionManager.getBranch()]
|
|
380
365
|
.reverse()
|
|
381
366
|
.find(
|
|
382
|
-
entry =>
|
|
367
|
+
(entry) =>
|
|
383
368
|
entry.type === "custom" &&
|
|
384
|
-
entry.customType === "pi-shell-inspector-view-status"
|
|
369
|
+
entry.customType === "pi-shell-inspector-view-status",
|
|
385
370
|
);
|
|
386
371
|
|
|
387
372
|
if (!shellStateEntry || shellStateEntry.type !== "custom") return;
|
|
@@ -420,9 +405,7 @@ export class ShellManager {
|
|
|
420
405
|
const job = this.requireJob(id);
|
|
421
406
|
|
|
422
407
|
if (job.status !== "running") {
|
|
423
|
-
throw new Error(
|
|
424
|
-
`Shell job "${id}" is not running: ${job.status}`,
|
|
425
|
-
);
|
|
408
|
+
throw new Error(`Shell job "${id}" is not running: ${job.status}`);
|
|
426
409
|
}
|
|
427
410
|
|
|
428
411
|
return job;
|
|
@@ -432,7 +415,7 @@ export class ShellManager {
|
|
|
432
415
|
for (const listener of this.listeners) {
|
|
433
416
|
try {
|
|
434
417
|
listener(event);
|
|
435
|
-
} catch
|
|
418
|
+
} catch {
|
|
436
419
|
// Ignore errors thrown by listeners to prevent one failing listener from affecting others.
|
|
437
420
|
}
|
|
438
421
|
}
|
|
@@ -452,15 +435,11 @@ export class ShellManager {
|
|
|
452
435
|
|
|
453
436
|
this.emit({
|
|
454
437
|
type: "job-completed",
|
|
455
|
-
id: id
|
|
438
|
+
id: id,
|
|
456
439
|
});
|
|
457
440
|
}
|
|
458
441
|
|
|
459
|
-
private failJob(
|
|
460
|
-
id: string,
|
|
461
|
-
error: string,
|
|
462
|
-
exitCode?: number,
|
|
463
|
-
): void {
|
|
442
|
+
private failJob(id: string, error: string, exitCode?: number): void {
|
|
464
443
|
const job = this.getRunningJob(id);
|
|
465
444
|
const now = Date.now();
|
|
466
445
|
|
|
@@ -475,7 +454,7 @@ export class ShellManager {
|
|
|
475
454
|
|
|
476
455
|
this.emit({
|
|
477
456
|
type: "job-failed",
|
|
478
|
-
id: id
|
|
457
|
+
id: id,
|
|
479
458
|
});
|
|
480
459
|
}
|
|
481
460
|
|
|
@@ -495,7 +474,7 @@ export class ShellManager {
|
|
|
495
474
|
|
|
496
475
|
this.emit({
|
|
497
476
|
type: "job-killed",
|
|
498
|
-
id: id
|
|
477
|
+
id: id,
|
|
499
478
|
});
|
|
500
479
|
}
|
|
501
480
|
|
|
@@ -526,7 +505,7 @@ export class ShellManager {
|
|
|
526
505
|
|
|
527
506
|
this.emit({
|
|
528
507
|
type: "job-cleared",
|
|
529
|
-
id: id
|
|
508
|
+
id: id,
|
|
530
509
|
});
|
|
531
510
|
return true;
|
|
532
511
|
}
|
|
@@ -562,8 +541,8 @@ export class ShellManager {
|
|
|
562
541
|
totalLines: job.output.totalLines,
|
|
563
542
|
totalBytes: job.output.totalBytes,
|
|
564
543
|
fullOutputPath: job.output.fullOutputPath,
|
|
565
|
-
}
|
|
566
|
-
}
|
|
544
|
+
},
|
|
545
|
+
};
|
|
567
546
|
}
|
|
568
547
|
}
|
|
569
548
|
|
|
@@ -589,7 +568,3 @@ function disposeScreen(terminal: XtermTerminal): void {
|
|
|
589
568
|
screenFeeds.get(terminal)?.dispose();
|
|
590
569
|
terminal.dispose();
|
|
591
570
|
}
|
|
592
|
-
|
|
593
|
-
// Shared singleton: its state outlives extension reloads, which is why the
|
|
594
|
-
// extension clears it explicitly on session start.
|
|
595
|
-
export const shellManager = new ShellManager();
|