@lune_99/pi-shell-inspector 0.0.0-stage → 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 ADDED
@@ -0,0 +1,195 @@
1
+ # Changelog
2
+
3
+ ## [Unreleased]
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
+
23
+ ### Added
24
+
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.
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.
27
+ - **Clickable themed notifications.** With the Lune theme on, a settled background-shell card opens
28
+ from its `click to show more` hint or its hidden-output row and closes with another click, like
29
+ a tool card. This needs a theme version that accepts the card key; older themes keep the
30
+ `ctrl+o` toggle. When a job's output was too long to keep and went to a log file, its
31
+ `click to view full output` row opens that complete log instead of the retained tail.
32
+
33
+ ### Changed
34
+
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.
36
+
37
+ - **Dock protocol from Core.** Use `createDockContribution` and its types from
38
+ `@lune_99/pi-lune-extensions-core/dock` to join the optional shared Dock. Core supplies the
39
+ scoped registry and contributor lifecycle.
40
+
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.
42
+
43
+ - **Simplified Dock integration.** The shared contributor adapter owns registration,
44
+ session UI cleanup, and host-presence switching. The existing independent status bar is
45
+ restored immediately when Lune Dock is disabled through `/dock` or is absent.
46
+
47
+ ## [1.2.0] - 2026-10-05
48
+
49
+ ### Added
50
+
51
+ - **Auto-hiding scrollbars in `/shell`.** Overflowing output and shell lists now show themed
52
+ scrollbars during scrolling or shell selection, hiding independently after one second of inactivity.
53
+ The bars reflect each viewport without covering text or changing the pause-and-follow behavior.
54
+ - **The `/shell` inspector remembers the selected shell.** Closing the overlay and reopening `/shell`
55
+ resumes on the shell that was selected last instead of jumping back to the first entry. The
56
+ position is memory-only view state: it is not written to the session snapshot, and clearing the
57
+ shell list (new session, shutdown, tree navigation) resets it to the first shell.
58
+
59
+ ### Changed
60
+
61
+ - **Background shell notifications now appear in the transcript.** A settled shell - or one batch of
62
+ them - draws a tool-result band under the command that started it: a status header, one row per
63
+ job with its command, outcome and runtime, and the tail of its output, which `ctrl+o` expands to
64
+ the full text. The agent-facing message is unchanged, and the box reads the output from that same
65
+ message instead of storing a second copy; job ids stay in the message, not in the row, because
66
+ only the agent needs them.
67
+
68
+ ### Fixed
69
+
70
+ - **Inspector output wraps instead of truncating long lines.** The detail pane reflows output to its
71
+ width, preserving long lines and wide characters without ellipses. Scrolling moves through the
72
+ wrapped rows, so content taller than the pane remains readable with the existing controls.
73
+ - **`/shell` no longer lags while scrolling.** Every repaint re-read and re-wrapped the whole
74
+ scrollback, so a wheel tick over a 2000-line output cost ~18ms and a one-second refresh or
75
+ streaming burst ~9–11ms. Wrapped rows are now cached per screen revision and width, and a pane
76
+ that follows the newest output wraps only its last rows, which brings those frames to ~0.2–1.2ms.
77
+ `ShellManager` gains `getScreenRevision(id)` for readers that cache what they derive from a screen.
78
+
79
+ - **A flooding background shell no longer crashes the host.** Output that arrived faster than the
80
+ screen emulator parsed it (`yes`, a verbose build) piled up until xterm threw
81
+ `write data discarded` from the stream handler, which exited pi. Output is now fed to the
82
+ emulator with flow control that drops the oldest unparsed output, so the screen still ends with
83
+ the newest; the retained text and the spill file are unaffected.
84
+
85
+ ### Refactored
86
+
87
+ - **Split `shell-inspector.ts` into `src/shell/inspector/`.** The 830-line component is now a
88
+ ~440-line orchestrator for input, selection and timers, with layout, frame, panes, scrollbars,
89
+ footer notice, output rows and the output viewport in their own modules. Rendering and key
90
+ behavior are unchanged.
91
+
92
+ ## [1.1.0] - 2026-10-02
93
+
94
+ ### Added
95
+
96
+ - **Agent kill tool.** `kill_background_shell` stops one managed background shell by its job ID,
97
+ aborting the shell's process tree through the same manager primitive as `/shell`'s `x` key so the
98
+ agent never needs a pid. A killed shell stays listed as `killed`, with its output still readable
99
+ through `background_shell` and `/shell`, until it is explicitly cleared.
100
+ - **Shell labels.** Background `bash` calls accept an optional `label`: a short human-readable
101
+ name that `/shell` shows in the job list instead of the command, since the left pane is too
102
+ narrow to show most commands. Labels are trimmed, blank ones are ignored, and they survive
103
+ session restore.
104
+ - **Inspector clear key.** Pressing `c` in `/shell` removes the selected shell when it has settled
105
+ (`completed`, `failed` or `killed`) and refuses a running one without touching its process. The
106
+ footer answers either outcome with a short-lived notice that replaces the key hints, and the
107
+ persistent hints now advertise `c to clear`.
108
+ - **Mouse support in `/shell`.** In pi's fullscreen mode, the wheel scrolls the output pane (with the
109
+ same pause-and-follow behavior as the scroll keys) or moves the selection over the job list, and a
110
+ left click selects a job. Presses elsewhere are left to pi's text selection, and regular mode keeps
111
+ the keyboard-only controls.
112
+ - **Back-to-bottom label.** While the output is paused, the separator under the panes shows a
113
+ clickable `[ ↓ Back to bottom · End ]` label that resumes following the newest output.
114
+
115
+ ### Changed
116
+
117
+ - **BREAKING:** **Background `bash` results are structured in codemode.** A background call now
118
+ resolves to `{ background, command, shell_job_id }` instead of a string, so a script reads the job
119
+ id as a field instead of parsing the text; scripts that treated the background result as text must
120
+ switch to `shell_job_id`. Foreground results keep the built-in
121
+ `{ output, truncated, exit_code, wall_time_seconds }` shape.
122
+ - **BREAKING:** **The pi peer requirements are explicit.** `@earendil-works/pi-coding-agent` and
123
+ `@earendil-works/pi-tui` are declared as `>=1.0.0` instead of `*`, so a pre-1.0 pi installation
124
+ fails the install instead of loading against an unsupported API; upgrade pi to 1.0.0 or newer.
125
+ - **`/shell` opens on an empty job list.** The inspector renders an empty frame instead of doing
126
+ nothing when there are no shell jobs, and clearing the last entry keeps that frame on screen
127
+ rather than closing the overlay.
128
+ - **Background shell notifications are batched and failure-tolerant.** Terminal job events now
129
+ accumulate into one steering message per batch, with `details.jobs[]` replacing the single
130
+ `shellJobId`, and a failed delivery keeps a per-notification budget of two retries through the
131
+ normal batching scheduler instead of crashing Pi with an unhandled rejection. Exhausted
132
+ notifications are reported through the session UI (stderr when headless) and dropped without
133
+ blocking later ones.
134
+
135
+ ## [1.0.3] - 2026-09-28
136
+
137
+ ### Fixed
138
+
139
+ - **Command previews are normalized in `/shell` too.** The inspector renders job commands through the same
140
+ formatter as the dock (`src/shell/shell-command.ts`), so terminal sequences, carriage returns, newlines,
141
+ tabs and repeated spaces can no longer break the job list or the selected-job header.
142
+
143
+ ## [1.0.2] - 2026-09-26
144
+
145
+ ### Added
146
+
147
+ - **Inspector kill key.** Pressing `x` in `/shell` stops the selected running shell: its process
148
+ tree is aborted and the agent receives exactly one steering notification carrying the shell id,
149
+ command, kill reason and the output collected so far.
150
+
151
+ ### Changed
152
+
153
+ - **Display-width command truncation.** The dock measures the command in terminal columns instead
154
+ of UTF-16 code units, so CJK and emoji commands are cut at a text-element boundary and the `…`
155
+ marker stays inside the 20-column budget.
156
+ - **Status-colored dock summary.** Running, completed, failed and killed segments now carry their
157
+ own colors with dim separators, and mixed job lists render per-status counts.
158
+
159
+ ### Fixed
160
+
161
+ - **Lifecycle kills no longer notify.** Leaving a branch (`session_before_tree`) stops running
162
+ shells and persists them as `killed` without sending a background-shell notification or
163
+ triggering an agent turn; `session_tree` restores that state.
164
+ - **Listener failures are isolated.** A throwing `ShellManager` subscriber no longer prevents later
165
+ subscribers from receiving the event, nor makes `startJob()` / `appendOutput()` / `settleJob()`
166
+ fail after the mutation was applied.
167
+ - **Control bytes can no longer break the dock.** Commands are stripped of terminal sequences and
168
+ have carriage returns, newlines and tabs collapsed before truncation, so the dock stays one line.
169
+ - **Notification delivery matches pi's API.** The notifier calls `pi.sendMessage()` synchronously
170
+ (it returns `void`, and pi owns delivery errors), so a synchronous throw from a stale extension
171
+ API can no longer roll back the settled job state or escape as an unhandled rejection.
172
+
173
+ ## [1.0.1] - 2026-09-25
174
+
175
+ ### Changed
176
+
177
+ - README leads with npm installation and badges, and the preview image uses an absolute URL.
178
+
179
+ ## [1.0.0] - 2026-09-25
180
+
181
+ ### Added
182
+
183
+ - Initial release: background `bash` mode with a shared shell manager, the one-line shell dock, the
184
+ `/shell` inspector with output scrolling, the `background_shell` status/output tool, bounded
185
+ output retention with full-output spill files, terminal-screen rendering of streamed output, and
186
+ persistence/restore of shell state across session lifecycle events.
187
+
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
191
+ [1.1.0]: https://github.com/Nouvelle-Lune/lune-shell-inspector/compare/v1.0.3...v1.1.0
192
+ [1.0.3]: https://github.com/Nouvelle-Lune/lune-shell-inspector/compare/v1.0.2...v1.0.3
193
+ [1.0.2]: https://github.com/Nouvelle-Lune/lune-shell-inspector/compare/v1.0.1...v1.0.2
194
+ [1.0.1]: https://github.com/Nouvelle-Lune/lune-shell-inspector/compare/v1.0.0...v1.0.1
195
+ [1.0.0]: https://github.com/Nouvelle-Lune/lune-shell-inspector/releases/tag/v1.0.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nouvelle-Lune
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,146 @@
1
- # Temporary Holding Version
1
+ # Lune Shell Inspector
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm version](https://img.shields.io/npm/v/@lune_99/pi-shell-inspector.svg)](https://www.npmjs.com/package/@lune_99/pi-shell-inspector) [![npm downloads](https://img.shields.io/npm/dw/@lune_99/pi-shell-inspector.svg)](https://www.npmjs.com/package/@lune_99/pi-shell-inspector) [![license](https://img.shields.io/npm/l/@lune_99/pi-shell-inspector.svg)](https://github.com/Nouvelle-Lune/lune-pi/blob/main/packages/pi-shell-inspector/LICENSE)
4
+
5
+ ![Lune Shell Inspector preview](https://raw.githubusercontent.com/Nouvelle-Lune/lune-pi/main/packages/pi-shell-inspector/assets/preview.png)
6
+
7
+ **Managed background shells for [Pi](https://pi.dev), with a live dock and an interactive `/shell` inspector.**
8
+
9
+ Lune Shell Inspector lets Pi keep long-running commands visible and manageable without changing the normal foreground `bash` experience. Commands that need an immediate result stay in the foreground; independent work can run in the background while the agent continues.
10
+
11
+ ## Quick start
12
+
13
+ Install from npm:
14
+
15
+ ```bash
16
+ pi install npm:@lune_99/pi-shell-inspector
17
+ ```
18
+
19
+ Then start Pi normally:
20
+
21
+ ```bash
22
+ pi
23
+ ```
24
+
25
+ There is no separate shell mode to enter. The extension augments Pi's existing `bash` tool with foreground and background execution.
26
+
27
+ For example:
28
+
29
+ ```text
30
+ Start the dev server in the background, then keep working on the feature.
31
+ ```
32
+
33
+ or:
34
+
35
+ ```text
36
+ Run this command in the foreground because I need the result before continuing.
37
+ ```
38
+
39
+ ## What it does
40
+
41
+ - **Keeps foreground bash native.** Normal commands continue to use Pi's standard foreground behavior and transcript rendering.
42
+ - **Runs independent work in the background.** Background shell jobs return immediately so the agent can continue with other work.
43
+ - **Shows live shell status below the editor.** The dock summarizes running and settled jobs without taking over the transcript.
44
+ - **Adds an interactive `/shell` inspector.** Browse jobs, inspect status and metadata, follow or scroll their terminal output, stop a running job, and clear settled ones from the list.
45
+ - **Makes terminal output readable.** Progress bars, redraws, spinners, and other terminal-style output are rendered as a screen instead of raw escape sequences.
46
+ - **Lets the agent inspect background jobs.** The `background_shell` tool can query job status and, when needed, current output.
47
+ - **Lets the agent stop a job it no longer needs.** A running background shell can be cancelled on request, and it stays in the list with its output, so nothing has to be read before the job is stopped.
48
+ - **Returns completion to the agent.** When a background job finishes, fails, or is killed, the result is delivered back to the agent so it can react without constant polling, and the same batch appears in the transcript as a status band with the command, outcome and output tail (`ctrl+o` expands it; with the Lune theme on, a click does too).
49
+ - **Follows the Pi session.** Shell state is restored with the active session branch, and running jobs are stopped when their owning Pi session shuts down.
50
+
51
+ ## Shell dock
52
+
53
+ Background jobs appear in a compact status dock below the editor.
54
+
55
+ Examples:
56
+
57
+ ```text
58
+ 1 running shell · npm test · 12s · /shell to open
59
+ ```
60
+
61
+ ```text
62
+ 5 shells · 3 running · 1 completed · 1 failed · /shell to open
63
+ ```
64
+
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.
66
+
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.
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
+
71
+ ## `/shell` inspector
72
+
73
+ Run:
74
+
75
+ ```text
76
+ /shell
77
+ ```
78
+
79
+ to open the shell inspector.
80
+
81
+ The job list stays on the left, showing a job's label when it has one and its command otherwise; the selected shell's command, status, working directory, duration, exit information, and terminal output appear on the right.
82
+
83
+ Keyboard controls:
84
+
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` |
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.
96
+
97
+ The inspector remembers which shell you were viewing: close it and reopen `/shell` and the selection is where you left it. That position lives in memory only, so a reloaded or resumed session opens on the first shell again.
98
+
99
+ In pi's fullscreen mode (the default since pi 1.0.0), the mouse works too: the wheel scrolls the output pane or moves the selection over the job list, and clicking a job selects it. Regular mode leaves the mouse to the terminal, so every action keeps its key.
100
+
101
+ Each pane has an automatically hidden scrollbar on its right edge when its content exceeds the viewport. Scrolling output reveals the output scrollbar; selecting a shell in an overflowing list reveals the list scrollbar. Each hides independently after one second without further interaction. The bars show the current position and visible proportion without covering text or changing wrapping.
102
+
103
+ Output follows the newest lines by default. Scrolling upward pauses that follow behavior so new output does not pull the viewport away from what you are reading. While paused, a `[ ↓ Back to bottom · End ]` label appears on the separator below the output; click it or press `End` to follow the newest lines again.
104
+
105
+ ## Agent-facing tools
106
+
107
+ ### `bash`
108
+
109
+ Foreground is the default. Background execution is intended for commands that can safely continue independently while the agent does other work. A background call may carry an optional `label`, which the `/shell` job list shows in place of the command.
110
+
111
+ ### `background_shell`
112
+
113
+ The companion tool lets the agent:
114
+
115
+ - list managed background shells;
116
+ - query selected shell IDs;
117
+ - inspect status without loading output;
118
+ - request current output when it is actually needed.
119
+
120
+ ### `kill_background_shell`
121
+
122
+ Cancels a running background shell when its work is no longer wanted: a dev server you are done with, a watcher left behind by a re-run, a test run that is clearly redundant. The agent stops the job it already knows about, so only that one shell goes away.
123
+
124
+ Cancelling is not deleting. The shell stays in `/shell` with its output, so you can still read what it printed before it stopped.
125
+
126
+ ## Development
127
+
128
+ ```bash
129
+ npm install
130
+ npm test
131
+ npm run typecheck
132
+ npm run tui:demo
133
+ ```
134
+
135
+ `@earendil-works/pi-coding-agent`, `@earendil-works/pi-tui`, and `typebox` are supplied by the Pi host at runtime, so the package declares them as `peerDependencies` with a `"*"` range and never bundles them. They are repeated in `devDependencies` so local typecheck and tests resolve the same modules Pi injects.
136
+
137
+ The Dock contribution comes from `@lune_99/pi-lune-extensions-core/dock`. Core is a required runtime dependency (`@lune_99/pi-lune-extensions-core@^0.1.0` from npm); no sibling checkout or local build is needed. The optional Dock host is separate: without a compatible host, the plugin keeps its independent status bar.
138
+
139
+ ## License
140
+
141
+ MIT
142
+
143
+ Lune Dock can be toggled with `/dock`. Turning it off immediately restores this plugin's
144
+ independent status bar. The choice belongs to Lune Dock and is saved in
145
+ `~/.pi/agent/lune-settings/pi-dock.json` (following `PI_CODING_AGENT_DIR`; a project can
146
+ override it in `<project>/.pi/lune-settings/pi-dock.json`).
Binary file
package/package.json CHANGED
@@ -1,6 +1,76 @@
1
1
  {
2
- "name": "@lune_99/pi-shell-inspector",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@lune_99/pi-shell-inspector",
3
+ "version": "1.3.0",
4
+ "description": "Shell dock and /shell inspector for pi's background bash jobs",
5
+ "type": "module",
6
+ "files": [
7
+ "src",
8
+ "assets",
9
+ "README.md",
10
+ "CHANGELOG.md",
11
+ "LICENSE"
12
+ ],
13
+ "pi": {
14
+ "extensions": [
15
+ "./src/index.ts"
16
+ ],
17
+ "image": "./assets/preview.png"
18
+ },
19
+ "scripts": {
20
+ "test": "node --experimental-strip-types --test 'test/**/*.test.ts'",
21
+ "typecheck": "tsc --noEmit",
22
+ "tui:demo": "node --experimental-strip-types test/tui/launch.ts"
23
+ },
24
+ "keywords": [
25
+ "pi-package",
26
+ "pi",
27
+ "pi-coding-agent",
28
+ "shell",
29
+ "bash",
30
+ "background-shell",
31
+ "terminal",
32
+ "tui"
33
+ ],
34
+ "author": "Nouvelle-Lune",
35
+ "license": "MIT",
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "git+https://github.com/Nouvelle-Lune/lune-pi.git",
39
+ "directory": "packages/pi-shell-inspector"
40
+ },
41
+ "homepage": "https://github.com/Nouvelle-Lune/lune-pi/tree/main/packages/pi-shell-inspector#readme",
42
+ "bugs": {
43
+ "url": "https://github.com/Nouvelle-Lune/lune-pi/issues"
44
+ },
45
+ "engines": {
46
+ "node": ">=22.19.0"
47
+ },
48
+ "dependencies": {
49
+ "@lune_99/pi-lune-extensions-core": "^0.1.0",
50
+ "@xterm/headless": "^6.0.0"
51
+ },
52
+ "peerDependencies": {
53
+ "@earendil-works/pi-coding-agent": ">=1.0.0",
54
+ "@earendil-works/pi-tui": ">=1.0.0",
55
+ "typebox": "*"
56
+ },
57
+ "peerDependenciesMeta": {
58
+ "@earendil-works/pi-coding-agent": {
59
+ "optional": true
60
+ },
61
+ "@earendil-works/pi-tui": {
62
+ "optional": true
63
+ },
64
+ "typebox": {
65
+ "optional": true
66
+ }
67
+ },
68
+ "devDependencies": {
69
+ "@earendil-works/pi-ai": "1.3.0",
70
+ "@earendil-works/pi-coding-agent": "1.3.0",
71
+ "@earendil-works/pi-tui": "1.3.0",
72
+ "@types/node": "^22.20.2",
73
+ "typebox": "1.3.27",
74
+ "typescript": "5.9.3"
75
+ }
76
+ }
package/src/index.ts ADDED
@@ -0,0 +1,114 @@
1
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
+
3
+ import { ShellDockContribution } from "./shell/shell-dock-contribution.ts";
4
+
5
+ import { ShellManager } from "./shell/shell-manager.ts";
6
+
7
+ import { BashTool, BackgroundShellTool, KillBackgroundShellTool } from "./tools/bash-tool.ts";
8
+ import {
9
+ BACKGROUND_SHELL_NOTIFICATION_TYPE,
10
+ registerBackgroundShellNotifications,
11
+ type BackgroundShellNotificationDetails,
12
+ } from "./shell/shell-notification.ts";
13
+ import { renderBackgroundShellNotificationBox } from "./shell/shell-notification-box.ts";
14
+
15
+ export default function (pi: ExtensionAPI): void {
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);
28
+
29
+ // Registered once per load: the transcript looks the renderer up by custom type when it draws
30
+ // the message, so a session-scoped registration would only re-register the same function.
31
+ pi.registerMessageRenderer<BackgroundShellNotificationDetails>(
32
+ BACKGROUND_SHELL_NOTIFICATION_TYPE,
33
+ renderBackgroundShellNotificationBox,
34
+ );
35
+
36
+ let unsubscribeShellManager: (() => void) | undefined;
37
+
38
+ let unsubscribeBackgroundShellNotifications: (() => void) | undefined;
39
+
40
+ pi.on("session_start", (_event, ctx) => {
41
+ // Release the old context before manager resets can notify its subscribers.
42
+ unsubscribeShellManager?.();
43
+ unsubscribeShellManager = undefined;
44
+ dock.detach({ retired: true });
45
+ // Restore the shell manager state from the session context.
46
+ shellManager.restoreShellManager(ctx);
47
+
48
+ dock.attach(ctx);
49
+
50
+ unsubscribeShellManager = shellManager.subscribe((event) => {
51
+ dock.onManagerEvent(event);
52
+ });
53
+
54
+ unsubscribeBackgroundShellNotifications?.();
55
+
56
+ // Register background shell notifications
57
+ unsubscribeBackgroundShellNotifications = registerBackgroundShellNotifications(
58
+ pi,
59
+ shellManager,
60
+ ctx,
61
+ );
62
+ });
63
+
64
+ pi.on("session_shutdown", () => {
65
+ // Unsubscribe before clearing: clearAllJobs() emits, and a live
66
+ // listener would re-render the dock after it was removed.
67
+ unsubscribeShellManager?.();
68
+ unsubscribeShellManager = undefined;
69
+ dock.detach();
70
+ unsubscribeBackgroundShellNotifications?.();
71
+ unsubscribeBackgroundShellNotifications = undefined;
72
+ shellManager.clearAllJobs(pi);
73
+ });
74
+
75
+ pi.on("session_before_tree", (_event, ctx) => {
76
+ unsubscribeBackgroundShellNotifications?.();
77
+ unsubscribeBackgroundShellNotifications = undefined;
78
+ try {
79
+ shellManager.clearAllJobs(pi);
80
+ } finally {
81
+ unsubscribeBackgroundShellNotifications = registerBackgroundShellNotifications(
82
+ pi,
83
+ shellManager,
84
+ ctx,
85
+ );
86
+ }
87
+ });
88
+
89
+ pi.on("session_tree", (_event, ctx) => {
90
+ shellManager.clearAllJobs();
91
+ shellManager.restoreShellManager(ctx);
92
+ dock.render();
93
+ });
94
+
95
+ // Register tools
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));
101
+
102
+ // Register commands
103
+ pi.registerCommand("shell", {
104
+ description: "Open the shell inspector",
105
+ handler: async (_args, ctx) => {
106
+ if (ctx.mode !== "tui") {
107
+ return;
108
+ }
109
+ await dock.open(ctx);
110
+ },
111
+ });
112
+
113
+ return shellManager;
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
+ }