@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/CHANGELOG.md
CHANGED
|
@@ -2,10 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [1.3.0] - 2026-11-05
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
|
|
9
|
+
- **Quieter idle Dock item.** All display levels show only `○ Shell` when no jobs are tracked, matching Agents without the `· idle` suffix. Job summaries, status markers and inspector behavior are unchanged.
|
|
10
|
+
|
|
11
|
+
- **Dock lines drop whole parts instead of cutting them.** A short Lune Dock cell leaves out the runtime, then the latest command, then the counts, with failures kept longest, then `Shell`, down to the marker alone, as the Agents item does. The row below the editor no longer cuts the running command at 20 columns: it shows the whole command or leaves it out, after the `/shell to open` hint.
|
|
12
|
+
|
|
13
|
+
- **The Dock failure marker clears by itself.** A failed or killed job turns the Lune Dock marker into a red `✕` for 10 seconds, or until you open the inspector. After that, a gray `●` shows while failed jobs are listed and nothing runs, so an item that holds only failures no longer stays red after you have seen it.
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
|
|
17
|
+
- **Package and changelog versions agree.** Resume the existing 1.x version sequence after the scoped npm package's 0.1.0 release. Pi can now record a version newer than the retained history, so old changelog entries stop appearing on every new session after upgrading.
|
|
18
|
+
|
|
19
|
+
- **Each session owns its background shells.** A Lune Subagents run that selected `background_shell` killed the main session's jobs and cleared its shell view, because Pi reuses the loaded module for sessions in the same working directory and the job table lived in that module. Each extension load now has its own shell manager, so a run or a second session cannot see, kill or clear another session's jobs.
|
|
20
|
+
|
|
21
|
+
## [0.1.0] - 2026-10-16
|
|
22
|
+
|
|
5
23
|
### Added
|
|
6
24
|
|
|
7
25
|
- **Optional Lune Dock integration.** When Lune Dock is active, shell state joins its single status row and Enter opens the existing inspector. Viewing the inspector acknowledges current failure reminders without changing job outcomes; without the host, the standalone dock remains available.
|
|
8
|
-
- **Notifications follow the Lune theme.** While
|
|
26
|
+
- **Notifications follow the Lune theme.** While Lune Core Theme is on, settled background shells render as its call tree, with killed jobs marked as cancelled. With the theme off or not installed, the existing band remains, and notifications already on screen switch with the theme.
|
|
9
27
|
- **Clickable themed notifications.** With the Lune theme on, a settled background-shell card opens
|
|
10
28
|
from its `click to show more` hint or its hidden-output row and closes with another click, like
|
|
11
29
|
a tool card. This needs a theme version that accepts the card key; older themes keep the
|
|
@@ -14,10 +32,10 @@
|
|
|
14
32
|
|
|
15
33
|
### Changed
|
|
16
34
|
|
|
17
|
-
- **Published Core dependency.** Require `@lune_99/pi-lune-core@^0.1.0` from npm instead of a sibling checkout. Core remains a mandatory runtime dependency for shared infrastructure and settings.
|
|
35
|
+
- **Published Core dependency.** Require `@lune_99/pi-lune-extensions-core@^0.1.0` from npm instead of a sibling checkout. Core remains a mandatory runtime dependency for shared infrastructure and settings.
|
|
18
36
|
|
|
19
37
|
- **Dock protocol from Core.** Use `createDockContribution` and its types from
|
|
20
|
-
`@lune_99/pi-lune-core/dock` to join the optional shared Dock. Core supplies the
|
|
38
|
+
`@lune_99/pi-lune-extensions-core/dock` to join the optional shared Dock. Core supplies the
|
|
21
39
|
scoped registry and contributor lifecycle.
|
|
22
40
|
|
|
23
41
|
- **BREAKING: Lune Protocol v1 Draft 3 snapshots.** Publish plugin-styled, single-line base/detail/full Components instead of business summary fields. Idle providers stay registered; Dock owns density, visibility and order, while Enter opens the existing plugin UI. Update the host and both plugins together.
|
|
@@ -167,7 +185,9 @@
|
|
|
167
185
|
output retention with full-output spill files, terminal-screen rendering of streamed output, and
|
|
168
186
|
persistence/restore of shell state across session lifecycle events.
|
|
169
187
|
|
|
170
|
-
[Unreleased]: https://github.com/Nouvelle-Lune/lune-shell-inspector/
|
|
188
|
+
[Unreleased]: https://github.com/Nouvelle-Lune/lune-pi/compare/pi-shell-inspector/v1.3.0...HEAD
|
|
189
|
+
[1.3.0]: https://github.com/Nouvelle-Lune/lune-pi/releases/tag/pi-shell-inspector/v1.3.0
|
|
190
|
+
[0.1.0]: https://www.npmjs.com/package/@lune_99/pi-shell-inspector/v/0.1.0
|
|
171
191
|
[1.1.0]: https://github.com/Nouvelle-Lune/lune-shell-inspector/compare/v1.0.3...v1.1.0
|
|
172
192
|
[1.0.3]: https://github.com/Nouvelle-Lune/lune-shell-inspector/compare/v1.0.2...v1.0.3
|
|
173
193
|
[1.0.2]: https://github.com/Nouvelle-Lune/lune-shell-inspector/compare/v1.0.1...v1.0.2
|
package/README.md
CHANGED
|
@@ -16,7 +16,6 @@ Install from npm:
|
|
|
16
16
|
pi install npm:@lune_99/pi-shell-inspector
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
|
|
20
19
|
Then start Pi normally:
|
|
21
20
|
|
|
22
21
|
```bash
|
|
@@ -63,10 +62,12 @@ Examples:
|
|
|
63
62
|
5 shells · 3 running · 1 completed · 1 failed · /shell to open
|
|
64
63
|
```
|
|
65
64
|
|
|
66
|
-
The dock updates while jobs are running and disappears when there are no shell jobs to show.
|
|
65
|
+
The dock updates while jobs are running and disappears when there are no shell jobs to show. It never cuts a part: on a narrow terminal it leaves out the hint, the runtime and the command first.
|
|
67
66
|
|
|
68
67
|
With the optional **Lune Dock** host active, this independent row is replaced by a shared one-line dock. Press Down in an empty main editor, select a module with Left/Right, and press Enter to open its panel directly. Closing the panel returns to dock focus. The plugin publishes its own single-line `base`, `detail`, and `full` Components through the Dock protocol in `@lune_99/pi-lune-extensions-core/dock`; `/dock` controls density, visibility and order. Idle state remains available in the shared Dock, and hiding the plugin keeps its snapshots current. Removing the host restores the independent row.
|
|
69
68
|
|
|
69
|
+
The shared dock's marker shows the jobs' state: `◐` yellow while a job runs, `●` green when all jobs completed, `●` gray when some failed or were killed, and `○` without jobs. A new failure shows a red `✕` for 10 seconds, or until you open the inspector.
|
|
70
|
+
|
|
70
71
|
## `/shell` inspector
|
|
71
72
|
|
|
72
73
|
Run:
|
|
@@ -81,15 +82,15 @@ The job list stays on the left, showing a job's label when it has one and its co
|
|
|
81
82
|
|
|
82
83
|
Keyboard controls:
|
|
83
84
|
|
|
84
|
-
| Action
|
|
85
|
-
|
|
|
86
|
-
| Select shell
|
|
87
|
-
| Scroll output
|
|
88
|
-
| Jump to oldest output | `Home`
|
|
89
|
-
| Follow newest output
|
|
90
|
-
| Kill selected shell
|
|
91
|
-
| Clear selected shell
|
|
92
|
-
| Close inspector
|
|
85
|
+
| Action | Keys |
|
|
86
|
+
| --------------------- | ---------------------------------------------- |
|
|
87
|
+
| Select shell | `↑` / `↓` or `k` / `j` |
|
|
88
|
+
| Scroll output | `Shift+↑` / `Shift+↓` or `Shift+k` / `Shift+j` |
|
|
89
|
+
| Jump to oldest output | `Home` |
|
|
90
|
+
| Follow newest output | `End` |
|
|
91
|
+
| Kill selected shell | `x` |
|
|
92
|
+
| Clear selected shell | `c` |
|
|
93
|
+
| Close inspector | `Esc` |
|
|
93
94
|
|
|
94
95
|
Killing a running shell stops its process tree but keeps it in the list, with its output still readable. Clearing a completed, failed, or killed shell removes it from the list once you are done with it.
|
|
95
96
|
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
|
2
2
|
|
|
3
3
|
import { ShellDockContribution } from "./shell/shell-dock-contribution.ts";
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { ShellManager } from "./shell/shell-manager.ts";
|
|
6
6
|
|
|
7
7
|
import { BashTool, BackgroundShellTool, KillBackgroundShellTool } from "./tools/bash-tool.ts";
|
|
8
8
|
import {
|
|
@@ -13,7 +13,18 @@ import {
|
|
|
13
13
|
import { renderBackgroundShellNotificationBox } from "./shell/shell-notification-box.ts";
|
|
14
14
|
|
|
15
15
|
export default function (pi: ExtensionAPI): void {
|
|
16
|
-
|
|
16
|
+
installShellInspector(pi);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Register the extension on `pi` and return the shell manager of this load.
|
|
21
|
+
*
|
|
22
|
+
* The manager belongs to the load, not to the module: Pi reuses a loaded module for the sessions it
|
|
23
|
+
* starts in the same working directory, subagent runs included, and each of them owns its jobs.
|
|
24
|
+
*/
|
|
25
|
+
export function installShellInspector(pi: ExtensionAPI): ShellManager {
|
|
26
|
+
const shellManager = new ShellManager();
|
|
27
|
+
const dock = new ShellDockContribution(shellManager);
|
|
17
28
|
|
|
18
29
|
// Registered once per load: the transcript looks the renderer up by custom type when it draws
|
|
19
30
|
// the message, so a session-scoped registration would only re-register the same function.
|
|
@@ -22,40 +33,35 @@ export default function (pi: ExtensionAPI): void {
|
|
|
22
33
|
renderBackgroundShellNotificationBox,
|
|
23
34
|
);
|
|
24
35
|
|
|
25
|
-
let unsubscribeShellManager:
|
|
26
|
-
| (() => void)
|
|
27
|
-
| undefined;
|
|
36
|
+
let unsubscribeShellManager: (() => void) | undefined;
|
|
28
37
|
|
|
29
|
-
let unsubscribeBackgroundShellNotifications:
|
|
30
|
-
| (() => void)
|
|
31
|
-
| undefined;
|
|
38
|
+
let unsubscribeBackgroundShellNotifications: (() => void) | undefined;
|
|
32
39
|
|
|
33
40
|
pi.on("session_start", (_event, ctx) => {
|
|
34
41
|
// Release the old context before manager resets can notify its subscribers.
|
|
35
42
|
unsubscribeShellManager?.();
|
|
36
43
|
unsubscribeShellManager = undefined;
|
|
37
44
|
dock.detach({ retired: true });
|
|
38
|
-
// Module state may survive extension reloads, so a new session starts
|
|
39
|
-
// with an explicitly empty shell view.
|
|
40
|
-
shellManager.clearAllJobs();
|
|
41
45
|
// Restore the shell manager state from the session context.
|
|
42
46
|
shellManager.restoreShellManager(ctx);
|
|
43
47
|
|
|
44
48
|
dock.attach(ctx);
|
|
45
49
|
|
|
46
|
-
unsubscribeShellManager =
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
});
|
|
50
|
+
unsubscribeShellManager = shellManager.subscribe((event) => {
|
|
51
|
+
dock.onManagerEvent(event);
|
|
52
|
+
});
|
|
50
53
|
|
|
51
54
|
unsubscribeBackgroundShellNotifications?.();
|
|
52
55
|
|
|
53
56
|
// Register background shell notifications
|
|
54
|
-
unsubscribeBackgroundShellNotifications = registerBackgroundShellNotifications(
|
|
55
|
-
|
|
57
|
+
unsubscribeBackgroundShellNotifications = registerBackgroundShellNotifications(
|
|
58
|
+
pi,
|
|
59
|
+
shellManager,
|
|
60
|
+
ctx,
|
|
61
|
+
);
|
|
56
62
|
});
|
|
57
63
|
|
|
58
|
-
pi.on("session_shutdown", (
|
|
64
|
+
pi.on("session_shutdown", () => {
|
|
59
65
|
// Unsubscribe before clearing: clearAllJobs() emits, and a live
|
|
60
66
|
// listener would re-render the dock after it was removed.
|
|
61
67
|
unsubscribeShellManager?.();
|
|
@@ -72,9 +78,12 @@ export default function (pi: ExtensionAPI): void {
|
|
|
72
78
|
try {
|
|
73
79
|
shellManager.clearAllJobs(pi);
|
|
74
80
|
} finally {
|
|
75
|
-
unsubscribeBackgroundShellNotifications = registerBackgroundShellNotifications(
|
|
81
|
+
unsubscribeBackgroundShellNotifications = registerBackgroundShellNotifications(
|
|
82
|
+
pi,
|
|
83
|
+
shellManager,
|
|
84
|
+
ctx,
|
|
85
|
+
);
|
|
76
86
|
}
|
|
77
|
-
|
|
78
87
|
});
|
|
79
88
|
|
|
80
89
|
pi.on("session_tree", (_event, ctx) => {
|
|
@@ -84,11 +93,11 @@ export default function (pi: ExtensionAPI): void {
|
|
|
84
93
|
});
|
|
85
94
|
|
|
86
95
|
// Register tools
|
|
87
|
-
// The background tools only read the
|
|
88
|
-
// starts
|
|
89
|
-
pi.registerTool(BashTool());
|
|
90
|
-
pi.registerTool(BackgroundShellTool());
|
|
91
|
-
pi.registerTool(KillBackgroundShellTool());
|
|
96
|
+
// The background tools only read the jobs of this load's shell manager, so they ship with the
|
|
97
|
+
// wrapper that starts them; a separate extension could not see them.
|
|
98
|
+
pi.registerTool(BashTool(shellManager));
|
|
99
|
+
pi.registerTool(BackgroundShellTool(shellManager));
|
|
100
|
+
pi.registerTool(KillBackgroundShellTool(shellManager));
|
|
92
101
|
|
|
93
102
|
// Register commands
|
|
94
103
|
pi.registerCommand("shell", {
|
|
@@ -100,4 +109,6 @@ export default function (pi: ExtensionAPI): void {
|
|
|
100
109
|
await dock.open(ctx);
|
|
101
110
|
},
|
|
102
111
|
});
|
|
112
|
+
|
|
113
|
+
return shellManager;
|
|
103
114
|
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/** How long a failure keeps a Dock item's error marker when nobody opens the item's panel. */
|
|
2
|
+
export const ALERT_DURATION_MS = 10_000;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The lifetime of a Dock item's error marker. A failure shows from the time it happened until
|
|
6
|
+
* `ALERT_DURATION_MS` later, or until the user sees it in the item's panel. A check that finds a
|
|
7
|
+
* failure still showing also schedules the redraw that ends it, so a quiet screen does not keep
|
|
8
|
+
* the marker.
|
|
9
|
+
*/
|
|
10
|
+
export class DockAlerts {
|
|
11
|
+
private readonly seen = new Set<string>();
|
|
12
|
+
/** A failure without a known time starts its window when it is first checked. */
|
|
13
|
+
private readonly firstChecked = new Map<string, number>();
|
|
14
|
+
private timer: ReturnType<typeof setTimeout> | undefined;
|
|
15
|
+
private dueAt = Infinity;
|
|
16
|
+
private readonly redraw: () => void;
|
|
17
|
+
|
|
18
|
+
constructor(redraw: () => void) {
|
|
19
|
+
this.redraw = redraw;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Whether the failure `key`, which happened at `at`, still shows the marker. */
|
|
23
|
+
shows(key: string, at: number | undefined): boolean {
|
|
24
|
+
if (this.seen.has(key)) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const now = Date.now();
|
|
29
|
+
const since = at ?? this.firstChecked.get(key) ?? now;
|
|
30
|
+
|
|
31
|
+
if (at === undefined) {
|
|
32
|
+
this.firstChecked.set(key, since);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const endsAt = since + ALERT_DURATION_MS;
|
|
36
|
+
|
|
37
|
+
if (endsAt <= now) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (endsAt < this.dueAt) {
|
|
42
|
+
clearTimeout(this.timer);
|
|
43
|
+
this.dueAt = endsAt;
|
|
44
|
+
this.timer = setTimeout(() => {
|
|
45
|
+
this.timer = undefined;
|
|
46
|
+
this.dueAt = Infinity;
|
|
47
|
+
this.redraw();
|
|
48
|
+
}, endsAt - now);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The user saw the failure in the item's panel. False when it was seen before. */
|
|
55
|
+
acknowledge(key: string): boolean {
|
|
56
|
+
if (this.seen.has(key)) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
this.seen.add(key);
|
|
61
|
+
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
forget(key: string): void {
|
|
66
|
+
this.seen.delete(key);
|
|
67
|
+
this.firstChecked.delete(key);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Forgets every failure and stops the pending redraw, so a detached item draws nothing late. */
|
|
71
|
+
clear(): void {
|
|
72
|
+
clearTimeout(this.timer);
|
|
73
|
+
this.timer = undefined;
|
|
74
|
+
this.dueAt = Infinity;
|
|
75
|
+
this.seen.clear();
|
|
76
|
+
this.firstChecked.clear();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { visibleWidth } from "@earendil-works/pi-tui";
|
|
2
|
+
|
|
3
|
+
/** A part of a one-line summary; parts with a lower rank give way first when the line is too long. */
|
|
4
|
+
export interface RankedPart {
|
|
5
|
+
text: string;
|
|
6
|
+
rank: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The richest line that fits in `width`. `compose` gets the kept parts in their original order;
|
|
11
|
+
* the lowest-ranked part, the last one among equals, is left out until the line fits. So a narrow
|
|
12
|
+
* row shows fewer complete parts instead of a cut one. Undefined when not even `compose([])` fits.
|
|
13
|
+
*/
|
|
14
|
+
export function fitRanked(
|
|
15
|
+
parts: readonly RankedPart[],
|
|
16
|
+
width: number,
|
|
17
|
+
compose: (texts: readonly string[]) => string,
|
|
18
|
+
): string | undefined {
|
|
19
|
+
const kept = [...parts];
|
|
20
|
+
|
|
21
|
+
for (;;) {
|
|
22
|
+
const line = compose(kept.map((part) => part.text));
|
|
23
|
+
|
|
24
|
+
if (visibleWidth(line) <= width) {
|
|
25
|
+
return line;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (kept.length === 0) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let lowest = 0;
|
|
33
|
+
|
|
34
|
+
for (let index = 1; index < kept.length; index++) {
|
|
35
|
+
if (kept[index]!.rank <= kept[lowest]!.rank) {
|
|
36
|
+
lowest = index;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
kept.splice(lowest, 1);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -8,8 +8,7 @@ import type { Notice } from "./footer-notice.ts";
|
|
|
8
8
|
const BACK_TO_BOTTOM_LABEL = "[ ↓ Back to bottom · End ]";
|
|
9
9
|
const BACK_TO_BOTTOM_LABEL_WIDTH = visibleWidth(BACK_TO_BOTTOM_LABEL);
|
|
10
10
|
|
|
11
|
-
const KEY_HINTS =
|
|
12
|
-
"↑↓/jk shell · ⇧↑↓/jk scroll · Home/End · x to kill · c to clear · Esc to close";
|
|
11
|
+
const KEY_HINTS = "↑↓/jk shell · ⇧↑↓/jk scroll · Home/End · x to kill · c to clear · Esc to close";
|
|
13
12
|
|
|
14
13
|
function border(theme: Theme, text: string): string {
|
|
15
14
|
return theme.fg("border", text);
|
|
@@ -42,10 +41,7 @@ export function renderHeader(
|
|
|
42
41
|
}
|
|
43
42
|
|
|
44
43
|
export function renderFooter(theme: Theme, width: number, notice: Notice | undefined): string {
|
|
45
|
-
return cell(
|
|
46
|
-
notice ? theme.fg(notice.color, notice.text) : theme.fg("dim", KEY_HINTS),
|
|
47
|
-
width,
|
|
48
|
-
);
|
|
44
|
+
return cell(notice ? theme.fg(notice.color, notice.text) : theme.fg("dim", KEY_HINTS), width);
|
|
49
45
|
}
|
|
50
46
|
|
|
51
47
|
export interface BottomSeparator {
|
|
@@ -111,7 +107,11 @@ export function assembleFrame(theme: Theme, geometry: PaneGeometry, parts: Frame
|
|
|
111
107
|
);
|
|
112
108
|
}
|
|
113
109
|
|
|
114
|
-
lines.push(
|
|
110
|
+
lines.push(
|
|
111
|
+
parts.separator,
|
|
112
|
+
edge + parts.footer + edge,
|
|
113
|
+
border(theme, `└${"─".repeat(innerWidth)}┘`),
|
|
114
|
+
);
|
|
115
115
|
|
|
116
116
|
return lines;
|
|
117
117
|
}
|
|
@@ -27,10 +27,7 @@ export interface PaneGeometry {
|
|
|
27
27
|
export function paneGeometry(width: number, terminalRows: number): PaneGeometry {
|
|
28
28
|
const bodyHeight = Math.min(
|
|
29
29
|
BODY_MAX_HEIGHT,
|
|
30
|
-
Math.max(
|
|
31
|
-
BODY_MIN_HEIGHT,
|
|
32
|
-
Math.floor(terminalRows * OVERLAY_HEIGHT_RATIO) - FRAME_HEIGHT,
|
|
33
|
-
),
|
|
30
|
+
Math.max(BODY_MIN_HEIGHT, Math.floor(terminalRows * OVERLAY_HEIGHT_RATIO) - FRAME_HEIGHT),
|
|
34
31
|
);
|
|
35
32
|
|
|
36
33
|
const innerWidth = Math.max(
|
|
@@ -14,7 +14,10 @@ const MAX_CACHED_COMMANDS = 64;
|
|
|
14
14
|
* kilobytes; the same few commands are previewed again on every frame, so they are done once.
|
|
15
15
|
*/
|
|
16
16
|
export class CommandPreviews {
|
|
17
|
-
private readonly byCommand = new Map<
|
|
17
|
+
private readonly byCommand = new Map<
|
|
18
|
+
string,
|
|
19
|
+
{ collapsed: string; fitted: Map<number, string> }
|
|
20
|
+
>();
|
|
18
21
|
|
|
19
22
|
fit(command: string, maxWidth: number): string {
|
|
20
23
|
let entry = this.byCommand.get(command);
|
|
@@ -123,7 +123,9 @@ export class WrappedOutput {
|
|
|
123
123
|
*/
|
|
124
124
|
export class OutputRowsCache {
|
|
125
125
|
private readonly wraps = new LineWrapCache();
|
|
126
|
-
private entry:
|
|
126
|
+
private entry:
|
|
127
|
+
| { jobId: string; revision: number; width: number; output: WrappedOutput }
|
|
128
|
+
| undefined;
|
|
127
129
|
|
|
128
130
|
get(source: ScreenSource, jobId: string, width: number): WrappedOutput {
|
|
129
131
|
const revision = source.getScreenRevision(jobId);
|
|
@@ -113,7 +113,10 @@ export function renderDetails(
|
|
|
113
113
|
|
|
114
114
|
if (output.lineCount === 0) {
|
|
115
115
|
rows.push(
|
|
116
|
-
cell(
|
|
116
|
+
cell(
|
|
117
|
+
theme.fg("muted", job.status === "running" ? "no output yet" : "no output"),
|
|
118
|
+
width,
|
|
119
|
+
),
|
|
117
120
|
);
|
|
118
121
|
} else {
|
|
119
122
|
rows.push(
|
|
@@ -1,24 +1,51 @@
|
|
|
1
1
|
import type { ExtensionContext, ThemeColor } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
2
|
+
import { visibleWidth, type Component } from "@earendil-works/pi-tui";
|
|
3
|
+
import {
|
|
4
|
+
createDockContribution,
|
|
5
|
+
type DockHandle,
|
|
6
|
+
type LuneDockSnapshot,
|
|
7
|
+
} from "@lune_99/pi-lune-extensions-core/dock";
|
|
8
|
+
import { DockAlerts } from "./dock-alert.ts";
|
|
9
|
+
import { fitRanked, type RankedPart } from "./dock-line.ts";
|
|
10
|
+
import { ShellDock } from "./shell-dock.ts";
|
|
5
11
|
import { collapseShellCommand } from "./shell-command.ts";
|
|
6
12
|
import { openShellInspector } from "./shell-inspector.ts";
|
|
7
|
-
import {
|
|
13
|
+
import type { ShellManager, ShellManagerEvent } from "./shell-manager.ts";
|
|
8
14
|
|
|
9
15
|
export const SHELL_CONTRIBUTION_ID = "shell-inspector";
|
|
10
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Ranks of the line's parts: a narrow cell drops the lowest first, so failures stay longest and
|
|
19
|
+
* the runtime goes before the command it belongs to.
|
|
20
|
+
*/
|
|
21
|
+
const FAILED_RANK = 5;
|
|
22
|
+
const RUNNING_RANK = 4;
|
|
23
|
+
const COMPLETED_RANK = 3;
|
|
24
|
+
const LATEST_RANK = 2;
|
|
25
|
+
const ELAPSED_RANK = 1;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The Dock item of the background shells. Its lines count the jobs by status and never cut a
|
|
29
|
+
* part: a narrow cell leaves out whole parts, then the title. A failed or killed job turns the
|
|
30
|
+
* marker red for a short time, or until the user opens the inspector.
|
|
31
|
+
*/
|
|
11
32
|
export class ShellDockContribution {
|
|
12
33
|
private generation = 0;
|
|
13
|
-
private readonly
|
|
34
|
+
private readonly alerts = new DockAlerts(() => this.render());
|
|
14
35
|
private ctx: ExtensionContext | undefined;
|
|
15
36
|
private timer: ReturnType<typeof setInterval> | undefined;
|
|
16
|
-
private readonly
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
37
|
+
private readonly manager: ShellManager;
|
|
38
|
+
private readonly dock: DockHandle;
|
|
39
|
+
|
|
40
|
+
constructor(manager: ShellManager) {
|
|
41
|
+
this.manager = manager;
|
|
42
|
+
this.dock = createDockContribution({
|
|
43
|
+
id: SHELL_CONTRIBUTION_ID,
|
|
44
|
+
getSnapshot: (ctx) => this.getSnapshot(ctx),
|
|
45
|
+
activate: (ctx) => this.open(ctx),
|
|
46
|
+
standalone: new ShellDock(manager),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
22
49
|
|
|
23
50
|
attach(ctx: ExtensionContext): void {
|
|
24
51
|
this.detach({ retired: true });
|
|
@@ -33,12 +60,12 @@ export class ShellDockContribution {
|
|
|
33
60
|
this.timer = undefined;
|
|
34
61
|
this.ctx = undefined;
|
|
35
62
|
this.dock.detach(options);
|
|
36
|
-
this.
|
|
63
|
+
this.alerts.clear();
|
|
37
64
|
}
|
|
38
65
|
|
|
39
66
|
onManagerEvent(event: ShellManagerEvent): void {
|
|
40
|
-
if (event.type === "jobs-cleared") this.
|
|
41
|
-
if (event.type === "job-cleared") this.
|
|
67
|
+
if (event.type === "jobs-cleared") this.alerts.clear();
|
|
68
|
+
if (event.type === "job-cleared") this.alerts.forget(event.id);
|
|
42
69
|
// Output chunks affect the independent command/runtime row, not the shared summary.
|
|
43
70
|
this.dock.refresh({ summaryChanged: event.type !== "output-updated" });
|
|
44
71
|
this.syncTimer();
|
|
@@ -49,7 +76,7 @@ export class ShellDockContribution {
|
|
|
49
76
|
}
|
|
50
77
|
|
|
51
78
|
private syncTimer(): void {
|
|
52
|
-
if (this.ctx?.mode === "tui" &&
|
|
79
|
+
if (this.ctx?.mode === "tui" && this.manager.getRunningJobsList().length > 0) {
|
|
53
80
|
this.timer ??= setInterval(() => this.render(), 1000);
|
|
54
81
|
} else if (this.timer) {
|
|
55
82
|
clearInterval(this.timer);
|
|
@@ -57,66 +84,73 @@ export class ShellDockContribution {
|
|
|
57
84
|
}
|
|
58
85
|
}
|
|
59
86
|
|
|
87
|
+
/** Base names the item; detail adds the counts; full adds the latest job and its runtime. */
|
|
60
88
|
getSnapshot(ctx = this.ctx!): LuneDockSnapshot {
|
|
61
|
-
const
|
|
89
|
+
const theme = ctx.ui.theme;
|
|
90
|
+
const jobs = this.manager.getAllJobsList();
|
|
62
91
|
const failed = jobs.filter((job) => job.status === "failed" || job.status === "killed");
|
|
63
92
|
const running = jobs.filter((job) => job.status === "running");
|
|
93
|
+
const completed = jobs.filter((job) => job.status === "completed");
|
|
64
94
|
let color: ThemeColor;
|
|
65
95
|
let marker: string;
|
|
66
|
-
if (failed.some((job) =>
|
|
96
|
+
if (failed.some((job) => this.alerts.shows(job.id, job.finishedAt))) {
|
|
67
97
|
color = "error";
|
|
68
98
|
marker = "✕";
|
|
69
99
|
} else if (running.length > 0) {
|
|
70
100
|
color = "warning";
|
|
71
101
|
marker = "◐";
|
|
72
|
-
} else if (
|
|
102
|
+
} else if (failed.length > 0) {
|
|
103
|
+
// Settled with failures: green would claim success, and red stays for new failures.
|
|
104
|
+
color = "muted";
|
|
105
|
+
marker = "●";
|
|
106
|
+
} else if (completed.length > 0) {
|
|
73
107
|
color = "success";
|
|
74
108
|
marker = "●";
|
|
75
|
-
} else if (jobs.length > 0) {
|
|
76
|
-
color = "error";
|
|
77
|
-
marker = "✕";
|
|
78
109
|
} else {
|
|
79
110
|
color = "dim";
|
|
80
111
|
marker = "○";
|
|
81
112
|
}
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
113
|
+
const muted = (text: string): string => theme.fg("muted", text);
|
|
114
|
+
const summary: RankedPart[] = [
|
|
115
|
+
running.length > 0
|
|
116
|
+
? { text: muted(`${running.length} running`), rank: RUNNING_RANK }
|
|
117
|
+
: undefined,
|
|
118
|
+
completed.length > 0
|
|
119
|
+
? { text: muted(`${completed.length} completed`), rank: COMPLETED_RANK }
|
|
120
|
+
: undefined,
|
|
121
|
+
failed.length > 0
|
|
122
|
+
? { text: muted(`${failed.length} failed/killed`), rank: FAILED_RANK }
|
|
123
|
+
: undefined,
|
|
124
|
+
].filter((part) => part !== undefined);
|
|
94
125
|
const latest = jobs[jobs.length - 1];
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
126
|
+
const details: RankedPart[] = latest
|
|
127
|
+
? [
|
|
128
|
+
{
|
|
129
|
+
text: muted(`latest: ${collapseShellCommand(latest.command)}`),
|
|
130
|
+
rank: LATEST_RANK,
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
text: muted(
|
|
134
|
+
`${Math.floor(((latest.finishedAt ?? Date.now()) - latest.startedAt) / 1000)}s`,
|
|
135
|
+
),
|
|
136
|
+
rank: ELAPSED_RANK,
|
|
137
|
+
},
|
|
138
|
+
]
|
|
139
|
+
: [];
|
|
140
|
+
const symbol = theme.fg(color, marker);
|
|
141
|
+
// `● Shell · 2 running · 1 completed` with every part that fits, down to the marker alone.
|
|
142
|
+
const component = (parts: readonly RankedPart[]): Component => ({
|
|
100
143
|
render: (width) => [
|
|
101
|
-
|
|
102
|
-
`${
|
|
103
|
-
|
|
104
|
-
),
|
|
144
|
+
fitRanked(parts, width, (texts) =>
|
|
145
|
+
[`${symbol} Shell`, ...texts].join(muted(" · ")),
|
|
146
|
+
) ?? (visibleWidth(symbol) <= width ? symbol : ""),
|
|
105
147
|
],
|
|
106
148
|
invalidate() {},
|
|
107
149
|
});
|
|
108
150
|
return {
|
|
109
|
-
base: component(
|
|
151
|
+
base: component([]),
|
|
110
152
|
detail: component(summary),
|
|
111
|
-
full: component(
|
|
112
|
-
[
|
|
113
|
-
summary,
|
|
114
|
-
command ? `latest: ${command}` : undefined,
|
|
115
|
-
elapsed !== undefined ? `${elapsed}s` : undefined,
|
|
116
|
-
]
|
|
117
|
-
.filter(Boolean)
|
|
118
|
-
.join(" · "),
|
|
119
|
-
),
|
|
153
|
+
full: component([...summary, ...details]),
|
|
120
154
|
};
|
|
121
155
|
}
|
|
122
156
|
|
|
@@ -124,13 +158,13 @@ export class ShellDockContribution {
|
|
|
124
158
|
const generation = this.generation;
|
|
125
159
|
// A failure arriving after the panel opened has not necessarily been seen. Only
|
|
126
160
|
// the opening snapshot is acknowledged, and only after a successful interaction.
|
|
127
|
-
const seen =
|
|
161
|
+
const seen = this.manager
|
|
128
162
|
.getAllJobsList()
|
|
129
163
|
.filter((job) => job.status === "failed" || job.status === "killed")
|
|
130
164
|
.map((job) => job.id);
|
|
131
|
-
await openShellInspector(ctx);
|
|
165
|
+
await openShellInspector(ctx, this.manager);
|
|
132
166
|
if (generation !== this.generation) return;
|
|
133
|
-
for (const id of seen) this.
|
|
167
|
+
for (const id of seen) this.alerts.acknowledge(id);
|
|
134
168
|
this.render();
|
|
135
169
|
}
|
|
136
170
|
}
|