@lune_99/pi-shell-inspector 0.0.0-stage → 0.1.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,175 @@
1
+ # Changelog
2
+
3
+ ## [Unreleased]
4
+
5
+ ### Added
6
+
7
+ - **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 the `pi-lune-core-theme` extension 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
+ - **Clickable themed notifications.** With the Lune theme on, a settled background-shell card opens
10
+ from its `click to show more` hint or its hidden-output row and closes with another click, like
11
+ a tool card. This needs a theme version that accepts the card key; older themes keep the
12
+ `ctrl+o` toggle. When a job's output was too long to keep and went to a log file, its
13
+ `click to view full output` row opens that complete log instead of the retained tail.
14
+
15
+ ### Changed
16
+
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.
18
+
19
+ - **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
21
+ scoped registry and contributor lifecycle.
22
+
23
+ - **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.
24
+
25
+ - **Simplified Dock integration.** The shared contributor adapter owns registration,
26
+ session UI cleanup, and host-presence switching. The existing independent status bar is
27
+ restored immediately when Lune Dock is disabled through `/dock` or is absent.
28
+
29
+ ## [1.2.0] - 2026-10-05
30
+
31
+ ### Added
32
+
33
+ - **Auto-hiding scrollbars in `/shell`.** Overflowing output and shell lists now show themed
34
+ scrollbars during scrolling or shell selection, hiding independently after one second of inactivity.
35
+ The bars reflect each viewport without covering text or changing the pause-and-follow behavior.
36
+ - **The `/shell` inspector remembers the selected shell.** Closing the overlay and reopening `/shell`
37
+ resumes on the shell that was selected last instead of jumping back to the first entry. The
38
+ position is memory-only view state: it is not written to the session snapshot, and clearing the
39
+ shell list (new session, shutdown, tree navigation) resets it to the first shell.
40
+
41
+ ### Changed
42
+
43
+ - **Background shell notifications now appear in the transcript.** A settled shell - or one batch of
44
+ them - draws a tool-result band under the command that started it: a status header, one row per
45
+ job with its command, outcome and runtime, and the tail of its output, which `ctrl+o` expands to
46
+ the full text. The agent-facing message is unchanged, and the box reads the output from that same
47
+ message instead of storing a second copy; job ids stay in the message, not in the row, because
48
+ only the agent needs them.
49
+
50
+ ### Fixed
51
+
52
+ - **Inspector output wraps instead of truncating long lines.** The detail pane reflows output to its
53
+ width, preserving long lines and wide characters without ellipses. Scrolling moves through the
54
+ wrapped rows, so content taller than the pane remains readable with the existing controls.
55
+ - **`/shell` no longer lags while scrolling.** Every repaint re-read and re-wrapped the whole
56
+ scrollback, so a wheel tick over a 2000-line output cost ~18ms and a one-second refresh or
57
+ streaming burst ~9–11ms. Wrapped rows are now cached per screen revision and width, and a pane
58
+ that follows the newest output wraps only its last rows, which brings those frames to ~0.2–1.2ms.
59
+ `ShellManager` gains `getScreenRevision(id)` for readers that cache what they derive from a screen.
60
+
61
+ - **A flooding background shell no longer crashes the host.** Output that arrived faster than the
62
+ screen emulator parsed it (`yes`, a verbose build) piled up until xterm threw
63
+ `write data discarded` from the stream handler, which exited pi. Output is now fed to the
64
+ emulator with flow control that drops the oldest unparsed output, so the screen still ends with
65
+ the newest; the retained text and the spill file are unaffected.
66
+
67
+ ### Refactored
68
+
69
+ - **Split `shell-inspector.ts` into `src/shell/inspector/`.** The 830-line component is now a
70
+ ~440-line orchestrator for input, selection and timers, with layout, frame, panes, scrollbars,
71
+ footer notice, output rows and the output viewport in their own modules. Rendering and key
72
+ behavior are unchanged.
73
+
74
+ ## [1.1.0] - 2026-10-02
75
+
76
+ ### Added
77
+
78
+ - **Agent kill tool.** `kill_background_shell` stops one managed background shell by its job ID,
79
+ aborting the shell's process tree through the same manager primitive as `/shell`'s `x` key so the
80
+ agent never needs a pid. A killed shell stays listed as `killed`, with its output still readable
81
+ through `background_shell` and `/shell`, until it is explicitly cleared.
82
+ - **Shell labels.** Background `bash` calls accept an optional `label`: a short human-readable
83
+ name that `/shell` shows in the job list instead of the command, since the left pane is too
84
+ narrow to show most commands. Labels are trimmed, blank ones are ignored, and they survive
85
+ session restore.
86
+ - **Inspector clear key.** Pressing `c` in `/shell` removes the selected shell when it has settled
87
+ (`completed`, `failed` or `killed`) and refuses a running one without touching its process. The
88
+ footer answers either outcome with a short-lived notice that replaces the key hints, and the
89
+ persistent hints now advertise `c to clear`.
90
+ - **Mouse support in `/shell`.** In pi's fullscreen mode, the wheel scrolls the output pane (with the
91
+ same pause-and-follow behavior as the scroll keys) or moves the selection over the job list, and a
92
+ left click selects a job. Presses elsewhere are left to pi's text selection, and regular mode keeps
93
+ the keyboard-only controls.
94
+ - **Back-to-bottom label.** While the output is paused, the separator under the panes shows a
95
+ clickable `[ ↓ Back to bottom · End ]` label that resumes following the newest output.
96
+
97
+ ### Changed
98
+
99
+ - **BREAKING:** **Background `bash` results are structured in codemode.** A background call now
100
+ resolves to `{ background, command, shell_job_id }` instead of a string, so a script reads the job
101
+ id as a field instead of parsing the text; scripts that treated the background result as text must
102
+ switch to `shell_job_id`. Foreground results keep the built-in
103
+ `{ output, truncated, exit_code, wall_time_seconds }` shape.
104
+ - **BREAKING:** **The pi peer requirements are explicit.** `@earendil-works/pi-coding-agent` and
105
+ `@earendil-works/pi-tui` are declared as `>=1.0.0` instead of `*`, so a pre-1.0 pi installation
106
+ fails the install instead of loading against an unsupported API; upgrade pi to 1.0.0 or newer.
107
+ - **`/shell` opens on an empty job list.** The inspector renders an empty frame instead of doing
108
+ nothing when there are no shell jobs, and clearing the last entry keeps that frame on screen
109
+ rather than closing the overlay.
110
+ - **Background shell notifications are batched and failure-tolerant.** Terminal job events now
111
+ accumulate into one steering message per batch, with `details.jobs[]` replacing the single
112
+ `shellJobId`, and a failed delivery keeps a per-notification budget of two retries through the
113
+ normal batching scheduler instead of crashing Pi with an unhandled rejection. Exhausted
114
+ notifications are reported through the session UI (stderr when headless) and dropped without
115
+ blocking later ones.
116
+
117
+ ## [1.0.3] - 2026-09-28
118
+
119
+ ### Fixed
120
+
121
+ - **Command previews are normalized in `/shell` too.** The inspector renders job commands through the same
122
+ formatter as the dock (`src/shell/shell-command.ts`), so terminal sequences, carriage returns, newlines,
123
+ tabs and repeated spaces can no longer break the job list or the selected-job header.
124
+
125
+ ## [1.0.2] - 2026-09-26
126
+
127
+ ### Added
128
+
129
+ - **Inspector kill key.** Pressing `x` in `/shell` stops the selected running shell: its process
130
+ tree is aborted and the agent receives exactly one steering notification carrying the shell id,
131
+ command, kill reason and the output collected so far.
132
+
133
+ ### Changed
134
+
135
+ - **Display-width command truncation.** The dock measures the command in terminal columns instead
136
+ of UTF-16 code units, so CJK and emoji commands are cut at a text-element boundary and the `…`
137
+ marker stays inside the 20-column budget.
138
+ - **Status-colored dock summary.** Running, completed, failed and killed segments now carry their
139
+ own colors with dim separators, and mixed job lists render per-status counts.
140
+
141
+ ### Fixed
142
+
143
+ - **Lifecycle kills no longer notify.** Leaving a branch (`session_before_tree`) stops running
144
+ shells and persists them as `killed` without sending a background-shell notification or
145
+ triggering an agent turn; `session_tree` restores that state.
146
+ - **Listener failures are isolated.** A throwing `ShellManager` subscriber no longer prevents later
147
+ subscribers from receiving the event, nor makes `startJob()` / `appendOutput()` / `settleJob()`
148
+ fail after the mutation was applied.
149
+ - **Control bytes can no longer break the dock.** Commands are stripped of terminal sequences and
150
+ have carriage returns, newlines and tabs collapsed before truncation, so the dock stays one line.
151
+ - **Notification delivery matches pi's API.** The notifier calls `pi.sendMessage()` synchronously
152
+ (it returns `void`, and pi owns delivery errors), so a synchronous throw from a stale extension
153
+ API can no longer roll back the settled job state or escape as an unhandled rejection.
154
+
155
+ ## [1.0.1] - 2026-09-25
156
+
157
+ ### Changed
158
+
159
+ - README leads with npm installation and badges, and the preview image uses an absolute URL.
160
+
161
+ ## [1.0.0] - 2026-09-25
162
+
163
+ ### Added
164
+
165
+ - Initial release: background `bash` mode with a shared shell manager, the one-line shell dock, the
166
+ `/shell` inspector with output scrolling, the `background_shell` status/output tool, bounded
167
+ output retention with full-output spill files, terminal-screen rendering of streamed output, and
168
+ persistence/restore of shell state across session lifecycle events.
169
+
170
+ [Unreleased]: https://github.com/Nouvelle-Lune/lune-shell-inspector/compare/v1.1.0...HEAD
171
+ [1.1.0]: https://github.com/Nouvelle-Lune/lune-shell-inspector/compare/v1.0.3...v1.1.0
172
+ [1.0.3]: https://github.com/Nouvelle-Lune/lune-shell-inspector/compare/v1.0.2...v1.0.3
173
+ [1.0.2]: https://github.com/Nouvelle-Lune/lune-shell-inspector/compare/v1.0.1...v1.0.2
174
+ [1.0.1]: https://github.com/Nouvelle-Lune/lune-shell-inspector/compare/v1.0.0...v1.0.1
175
+ [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,145 @@
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
+
20
+ Then start Pi normally:
21
+
22
+ ```bash
23
+ pi
24
+ ```
25
+
26
+ There is no separate shell mode to enter. The extension augments Pi's existing `bash` tool with foreground and background execution.
27
+
28
+ For example:
29
+
30
+ ```text
31
+ Start the dev server in the background, then keep working on the feature.
32
+ ```
33
+
34
+ or:
35
+
36
+ ```text
37
+ Run this command in the foreground because I need the result before continuing.
38
+ ```
39
+
40
+ ## What it does
41
+
42
+ - **Keeps foreground bash native.** Normal commands continue to use Pi's standard foreground behavior and transcript rendering.
43
+ - **Runs independent work in the background.** Background shell jobs return immediately so the agent can continue with other work.
44
+ - **Shows live shell status below the editor.** The dock summarizes running and settled jobs without taking over the transcript.
45
+ - **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.
46
+ - **Makes terminal output readable.** Progress bars, redraws, spinners, and other terminal-style output are rendered as a screen instead of raw escape sequences.
47
+ - **Lets the agent inspect background jobs.** The `background_shell` tool can query job status and, when needed, current output.
48
+ - **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.
49
+ - **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).
50
+ - **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.
51
+
52
+ ## Shell dock
53
+
54
+ Background jobs appear in a compact status dock below the editor.
55
+
56
+ Examples:
57
+
58
+ ```text
59
+ 1 running shell · npm test · 12s · /shell to open
60
+ ```
61
+
62
+ ```text
63
+ 5 shells · 3 running · 1 completed · 1 failed · /shell to open
64
+ ```
65
+
66
+ The dock updates while jobs are running and disappears when there are no shell jobs to show.
67
+
68
+ 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
+
70
+ ## `/shell` inspector
71
+
72
+ Run:
73
+
74
+ ```text
75
+ /shell
76
+ ```
77
+
78
+ to open the shell inspector.
79
+
80
+ 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.
81
+
82
+ Keyboard controls:
83
+
84
+ | Action | Keys |
85
+ | --- | --- |
86
+ | Select shell | `↑` / `↓` or `k` / `j` |
87
+ | Scroll output | `Shift+↑` / `Shift+↓` or `Shift+k` / `Shift+j` |
88
+ | Jump to oldest output | `Home` |
89
+ | Follow newest output | `End` |
90
+ | Kill selected shell | `x` |
91
+ | Clear selected shell | `c` |
92
+ | Close inspector | `Esc` |
93
+
94
+ 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
+ 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.
97
+
98
+ 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.
99
+
100
+ 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.
101
+
102
+ 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.
103
+
104
+ ## Agent-facing tools
105
+
106
+ ### `bash`
107
+
108
+ 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.
109
+
110
+ ### `background_shell`
111
+
112
+ The companion tool lets the agent:
113
+
114
+ - list managed background shells;
115
+ - query selected shell IDs;
116
+ - inspect status without loading output;
117
+ - request current output when it is actually needed.
118
+
119
+ ### `kill_background_shell`
120
+
121
+ 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.
122
+
123
+ Cancelling is not deleting. The shell stays in `/shell` with its output, so you can still read what it printed before it stopped.
124
+
125
+ ## Development
126
+
127
+ ```bash
128
+ npm install
129
+ npm test
130
+ npm run typecheck
131
+ npm run tui:demo
132
+ ```
133
+
134
+ `@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.
135
+
136
+ 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.
137
+
138
+ ## License
139
+
140
+ MIT
141
+
142
+ Lune Dock can be toggled with `/dock`. Turning it off immediately restores this plugin's
143
+ independent status bar. The choice belongs to Lune Dock and is saved in
144
+ `~/.pi/agent/lune-settings/pi-dock.json` (following `PI_CODING_AGENT_DIR`; a project can
145
+ 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": "0.1.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,103 @@
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
+ const dock = new ShellDockContribution();
17
+
18
+ // Registered once per load: the transcript looks the renderer up by custom type when it draws
19
+ // the message, so a session-scoped registration would only re-register the same function.
20
+ pi.registerMessageRenderer<BackgroundShellNotificationDetails>(
21
+ BACKGROUND_SHELL_NOTIFICATION_TYPE,
22
+ renderBackgroundShellNotificationBox,
23
+ );
24
+
25
+ let unsubscribeShellManager:
26
+ | (() => void)
27
+ | undefined;
28
+
29
+ let unsubscribeBackgroundShellNotifications:
30
+ | (() => void)
31
+ | undefined;
32
+
33
+ pi.on("session_start", (_event, ctx) => {
34
+ // Release the old context before manager resets can notify its subscribers.
35
+ unsubscribeShellManager?.();
36
+ unsubscribeShellManager = undefined;
37
+ 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
+ // Restore the shell manager state from the session context.
42
+ shellManager.restoreShellManager(ctx);
43
+
44
+ dock.attach(ctx);
45
+
46
+ unsubscribeShellManager =
47
+ shellManager.subscribe((event) => {
48
+ dock.onManagerEvent(event);
49
+ });
50
+
51
+ unsubscribeBackgroundShellNotifications?.();
52
+
53
+ // Register background shell notifications
54
+ unsubscribeBackgroundShellNotifications = registerBackgroundShellNotifications(pi, ctx);
55
+
56
+ });
57
+
58
+ pi.on("session_shutdown", (_event, ctx) => {
59
+ // Unsubscribe before clearing: clearAllJobs() emits, and a live
60
+ // listener would re-render the dock after it was removed.
61
+ unsubscribeShellManager?.();
62
+ unsubscribeShellManager = undefined;
63
+ dock.detach();
64
+ unsubscribeBackgroundShellNotifications?.();
65
+ unsubscribeBackgroundShellNotifications = undefined;
66
+ shellManager.clearAllJobs(pi);
67
+ });
68
+
69
+ pi.on("session_before_tree", (_event, ctx) => {
70
+ unsubscribeBackgroundShellNotifications?.();
71
+ unsubscribeBackgroundShellNotifications = undefined;
72
+ try {
73
+ shellManager.clearAllJobs(pi);
74
+ } finally {
75
+ unsubscribeBackgroundShellNotifications = registerBackgroundShellNotifications(pi, ctx);
76
+ }
77
+
78
+ });
79
+
80
+ pi.on("session_tree", (_event, ctx) => {
81
+ shellManager.clearAllJobs();
82
+ shellManager.restoreShellManager(ctx);
83
+ dock.render();
84
+ });
85
+
86
+ // Register tools
87
+ // The background tools only read the shared shell manager, so they ship with the wrapper that
88
+ // starts the jobs; a separate extension could not see them.
89
+ pi.registerTool(BashTool());
90
+ pi.registerTool(BackgroundShellTool());
91
+ pi.registerTool(KillBackgroundShellTool());
92
+
93
+ // Register commands
94
+ pi.registerCommand("shell", {
95
+ description: "Open the shell inspector",
96
+ handler: async (_args, ctx) => {
97
+ if (ctx.mode !== "tui") {
98
+ return;
99
+ }
100
+ await dock.open(ctx);
101
+ },
102
+ });
103
+ }
@@ -0,0 +1,21 @@
1
+ import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
2
+
3
+ /** One padding column on each side keeps text off the pane borders and leaves room for a scrollbar. */
4
+ export function cell(text: string, width: number): string {
5
+ return ` ${truncateToWidth(text, Math.max(0, width - 2), "…", true)} `;
6
+ }
7
+
8
+ export function pad(text: string, width: number): string {
9
+ return text + " ".repeat(Math.max(0, width - visibleWidth(text)));
10
+ }
11
+
12
+ /** Exactly `height` rows: shorter content is padded with blanks, longer content is cut. */
13
+ export function fill(rows: readonly string[], width: number, height: number): string[] {
14
+ const filled = rows.slice(0, height);
15
+
16
+ while (filled.length < height) {
17
+ filled.push(" ".repeat(width));
18
+ }
19
+
20
+ return filled;
21
+ }
@@ -0,0 +1,39 @@
1
+ import type { ThemeColor } from "./job-format.ts";
2
+
3
+ const NOTICE_DURATION_MS = 1800;
4
+
5
+ export interface Notice {
6
+ text: string;
7
+ color: ThemeColor;
8
+ }
9
+
10
+ /** A message that replaces the footer's key hints until it expires on its own. */
11
+ export class FooterNotice {
12
+ private current: Notice | undefined;
13
+ private timer: ReturnType<typeof setTimeout> | undefined;
14
+ private readonly onExpired: () => void;
15
+
16
+ constructor(onExpired: () => void) {
17
+ this.onExpired = onExpired;
18
+ }
19
+
20
+ get active(): Notice | undefined {
21
+ return this.current;
22
+ }
23
+
24
+ show(text: string, color: ThemeColor): void {
25
+ this.current = { text, color };
26
+
27
+ clearTimeout(this.timer);
28
+ this.timer = setTimeout(() => {
29
+ this.current = undefined;
30
+ this.timer = undefined;
31
+ this.onExpired();
32
+ }, NOTICE_DURATION_MS);
33
+ }
34
+
35
+ dispose(): void {
36
+ clearTimeout(this.timer);
37
+ this.timer = undefined;
38
+ }
39
+ }