@lune_99/pi-dock 0.0.0-stage → 0.2.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 +117 -0
- package/LICENSE +21 -0
- package/README.md +83 -2
- package/docs/dock-overview.png +0 -0
- package/docs/dock-overview.svg +12 -0
- package/docs/dock-styles.png +0 -0
- package/docs/dock-styles.svg +30 -0
- package/docs/reference.md +219 -0
- package/package.json +63 -5
- package/src/dock-controller.ts +450 -0
- package/src/dock-footer.ts +273 -0
- package/src/dock-panel.ts +166 -0
- package/src/dock-renderer.ts +118 -0
- package/src/dock-settings.ts +32 -0
- package/src/dock-status.ts +608 -0
- package/src/index.ts +53 -0
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { visibleWidth } from "@earendil-works/pi-tui";
|
|
3
|
+
import type { LuneDockDisplayMode } from "@lune_99/pi-lune-extensions-core/dock";
|
|
4
|
+
import { DockView, type VisibleDockItem } from "./dock-renderer.ts";
|
|
5
|
+
import {
|
|
6
|
+
CELL_SEPARATOR,
|
|
7
|
+
modelSegmentVariants,
|
|
8
|
+
renderContextCell,
|
|
9
|
+
renderInfoRow,
|
|
10
|
+
renderModelSegment,
|
|
11
|
+
renderStatusRow,
|
|
12
|
+
statColumns,
|
|
13
|
+
type DockStatus,
|
|
14
|
+
} from "./dock-status.ts";
|
|
15
|
+
|
|
16
|
+
export const DOCK_STYLES = ["ruled", "boxed", "compact", "minimal", "classic"] as const;
|
|
17
|
+
export type DockStyle = (typeof DOCK_STYLES)[number];
|
|
18
|
+
|
|
19
|
+
/** Which of the footer's statistics a style shows; classic leaves Pi's footer in charge of them. */
|
|
20
|
+
export interface DockLayout {
|
|
21
|
+
style: DockStyle;
|
|
22
|
+
showModel: boolean;
|
|
23
|
+
showWorkspace: boolean;
|
|
24
|
+
showUsage: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface DockFooterInput {
|
|
28
|
+
entries: readonly VisibleDockItem[];
|
|
29
|
+
/** Undefined for the classic style, which draws no statistics. */
|
|
30
|
+
status: DockStatus | undefined;
|
|
31
|
+
/** Set only while the dock has focus: an unfocused dock draws no selection and no key hints. */
|
|
32
|
+
selectedId: string | undefined;
|
|
33
|
+
mode: LuneDockDisplayMode;
|
|
34
|
+
layout: DockLayout;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Classic keeps Pi's own footer; every other style takes it over. */
|
|
38
|
+
export function replacesFooter(style: DockStyle): boolean {
|
|
39
|
+
return style !== "classic";
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Below this width the model name would crowd out the cells, so the cells keep the whole row. */
|
|
43
|
+
const MIN_MODEL_ROW_WIDTH = 40;
|
|
44
|
+
/** A box narrower than this has no room for its border and a cell, so it degrades to compact. */
|
|
45
|
+
const MIN_BOX_WIDTH = 24;
|
|
46
|
+
|
|
47
|
+
/** Longest first, so a narrow row still advertises some key. */
|
|
48
|
+
const KEY_HINTS = ["←→ select · enter open · esc back", "enter open · esc back", "enter open"];
|
|
49
|
+
|
|
50
|
+
interface Rows {
|
|
51
|
+
dock: string | undefined;
|
|
52
|
+
info: string | undefined;
|
|
53
|
+
statuses: string | undefined;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** What the dock row draws on its right; `width` is the span it occupies, at least the text's own. */
|
|
57
|
+
interface RightSegment {
|
|
58
|
+
text: string;
|
|
59
|
+
width: number;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const SEPARATOR_WIDTH = visibleWidth(CELL_SEPARATOR);
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Takes over Pi's footer: the module cells beside the model, then the working directory beside
|
|
66
|
+
* the usage statistics, framed according to the chosen style.
|
|
67
|
+
*/
|
|
68
|
+
export class DockFooter {
|
|
69
|
+
/** Owned here so the cell window survives the widget component being re-created. */
|
|
70
|
+
private readonly cells = new DockView();
|
|
71
|
+
|
|
72
|
+
render(width: number, theme: Theme, input: DockFooterInput): string[] {
|
|
73
|
+
width = Math.max(0, Math.floor(width));
|
|
74
|
+
if (width === 0) return [];
|
|
75
|
+
switch (input.layout.style) {
|
|
76
|
+
case "classic":
|
|
77
|
+
return this.renderClassic(width, theme, input);
|
|
78
|
+
case "boxed":
|
|
79
|
+
return width < MIN_BOX_WIDTH
|
|
80
|
+
? this.renderCompact(width, theme, input)
|
|
81
|
+
: this.renderBoxed(width, theme, input);
|
|
82
|
+
case "compact":
|
|
83
|
+
case "minimal":
|
|
84
|
+
return this.renderCompact(width, theme, input);
|
|
85
|
+
case "ruled":
|
|
86
|
+
return this.renderRuled(width, theme, input);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The original single row: cells with the key hint on the right, nothing else. */
|
|
91
|
+
private renderClassic(width: number, theme: Theme, input: DockFooterInput): string[] {
|
|
92
|
+
const row = this.cells.render(input.entries, width, theme, input.selectedId, input.mode)[0];
|
|
93
|
+
if (row === undefined) return [];
|
|
94
|
+
if (input.selectedId === undefined) return [row];
|
|
95
|
+
for (const hint of KEY_HINTS) {
|
|
96
|
+
const gap = width - visibleWidth(row) - visibleWidth(hint);
|
|
97
|
+
if (gap >= 3) return [row + " ".repeat(gap) + theme.fg("dim", hint)];
|
|
98
|
+
}
|
|
99
|
+
return [row];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private renderRuled(width: number, theme: Theme, input: DockFooterInput): string[] {
|
|
103
|
+
const rows = this.renderRows(width, theme, input, false);
|
|
104
|
+
const rule = theme.fg("borderMuted", "─".repeat(width));
|
|
105
|
+
const lines = [rule];
|
|
106
|
+
// The rule under the dock row carries the key hints and doubles as the closing rule.
|
|
107
|
+
if (rows.dock !== undefined) {
|
|
108
|
+
lines.push(
|
|
109
|
+
rows.dock,
|
|
110
|
+
input.selectedId === undefined ? rule : this.renderHintRule(width, theme),
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
if (rows.info !== undefined) lines.push(rows.info);
|
|
114
|
+
if (rows.statuses !== undefined) lines.push(rows.statuses);
|
|
115
|
+
if (rows.info !== undefined || rows.statuses !== undefined) lines.push(rule);
|
|
116
|
+
return lines.length === 1 ? [] : lines;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
private renderBoxed(width: number, theme: Theme, input: DockFooterInput): string[] {
|
|
120
|
+
// "│ " before and " │" after leave 4 columns, 1 of which the rows already spend on their gutter.
|
|
121
|
+
const rows = this.renderRows(width - 3, theme, input, false);
|
|
122
|
+
const border = (text: string) => theme.fg("borderMuted", text);
|
|
123
|
+
const frame = (left: string, fill: string, right: string) =>
|
|
124
|
+
border(left) + fill + border(right);
|
|
125
|
+
const wrap = (row: string) =>
|
|
126
|
+
border("│") +
|
|
127
|
+
row +
|
|
128
|
+
" ".repeat(Math.max(0, width - 3 - visibleWidth(row))) +
|
|
129
|
+
" " +
|
|
130
|
+
border("│");
|
|
131
|
+
const plain = border("─".repeat(width - 2));
|
|
132
|
+
const hinted =
|
|
133
|
+
input.selectedId === undefined ? plain : this.renderHintRule(width - 2, theme);
|
|
134
|
+
|
|
135
|
+
const more = rows.info !== undefined || rows.statuses !== undefined;
|
|
136
|
+
const lines: string[] = [];
|
|
137
|
+
if (rows.dock !== undefined) {
|
|
138
|
+
lines.push(wrap(rows.dock), frame(more ? "├" : "╰", hinted, more ? "┤" : "╯"));
|
|
139
|
+
}
|
|
140
|
+
if (rows.info !== undefined) lines.push(wrap(rows.info));
|
|
141
|
+
if (rows.statuses !== undefined) lines.push(wrap(rows.statuses));
|
|
142
|
+
if (lines.length === 0) return [];
|
|
143
|
+
if (rows.dock === undefined || more) lines.push(frame("╰", plain, "╯"));
|
|
144
|
+
return [frame("╭", plain, "╮"), ...lines];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** No frame at all; with no rule to ride on, the key hint takes the model's place while focused. */
|
|
148
|
+
private renderCompact(width: number, theme: Theme, input: DockFooterInput): string[] {
|
|
149
|
+
const rows = this.renderRows(width, theme, input, true);
|
|
150
|
+
return [rows.dock, rows.info, rows.statuses].filter((row) => row !== undefined);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private renderRows(
|
|
154
|
+
width: number,
|
|
155
|
+
theme: Theme,
|
|
156
|
+
input: DockFooterInput,
|
|
157
|
+
inlineHints: boolean,
|
|
158
|
+
): Rows {
|
|
159
|
+
const { status, layout } = input;
|
|
160
|
+
const showInfo = status !== undefined && layout.style !== "minimal";
|
|
161
|
+
return {
|
|
162
|
+
dock: this.renderDockRow(width, theme, input, inlineHints),
|
|
163
|
+
info:
|
|
164
|
+
showInfo && (layout.showWorkspace || layout.showUsage)
|
|
165
|
+
? renderInfoRow(status, width, theme, {
|
|
166
|
+
workspace: layout.showWorkspace,
|
|
167
|
+
usage: layout.showUsage,
|
|
168
|
+
})
|
|
169
|
+
: undefined,
|
|
170
|
+
statuses: status && renderStatusRow(status.extensionStatuses, width, theme),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
private renderDockRow(
|
|
175
|
+
width: number,
|
|
176
|
+
theme: Theme,
|
|
177
|
+
input: DockFooterInput,
|
|
178
|
+
inlineHints: boolean,
|
|
179
|
+
): string | undefined {
|
|
180
|
+
const hasCells = input.entries.length > 0;
|
|
181
|
+
const right = this.renderRightSegment(width, theme, input, inlineHints);
|
|
182
|
+
if (!hasCells && !right.text) return undefined;
|
|
183
|
+
|
|
184
|
+
const segment =
|
|
185
|
+
" ".repeat(Math.max(0, right.width - visibleWidth(right.text))) + right.text;
|
|
186
|
+
const tail = (hasCells && right.text ? theme.fg("dim", CELL_SEPARATOR) : "") + segment;
|
|
187
|
+
const left = hasCells
|
|
188
|
+
? (this.cells.render(
|
|
189
|
+
input.entries,
|
|
190
|
+
width - visibleWidth(tail),
|
|
191
|
+
theme,
|
|
192
|
+
input.selectedId,
|
|
193
|
+
input.mode,
|
|
194
|
+
)[0] ?? "")
|
|
195
|
+
: "";
|
|
196
|
+
return (
|
|
197
|
+
left + " ".repeat(Math.max(0, width - visibleWidth(left) - visibleWidth(tail))) + tail
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** Key hint while focused (when inline), otherwise the model; the minimal style adds context use. */
|
|
202
|
+
private renderRightSegment(
|
|
203
|
+
width: number,
|
|
204
|
+
theme: Theme,
|
|
205
|
+
input: DockFooterInput,
|
|
206
|
+
inlineHints: boolean,
|
|
207
|
+
): RightSegment {
|
|
208
|
+
const { status, layout } = input;
|
|
209
|
+
const minimal = layout.style === "minimal";
|
|
210
|
+
const flush = (text: string): RightSegment => ({ text, width: visibleWidth(text) });
|
|
211
|
+
// Minimal has no info row to share the line with, so the right side may claim more of it.
|
|
212
|
+
const budget = Math.floor(width * (minimal ? 0.6 : 0.5)) - SEPARATOR_WIDTH;
|
|
213
|
+
if (inlineHints && input.selectedId !== undefined) {
|
|
214
|
+
const hint = KEY_HINTS.find((candidate) => visibleWidth(candidate) <= budget);
|
|
215
|
+
if (hint) return flush(theme.fg("dim", hint));
|
|
216
|
+
}
|
|
217
|
+
if (!status || width < MIN_MODEL_ROW_WIDTH) return flush("");
|
|
218
|
+
if (minimal && layout.showUsage) {
|
|
219
|
+
// Context use outranks optional model segments, so speed never displaces the counter.
|
|
220
|
+
const context = renderContextCell(status, theme);
|
|
221
|
+
const models = layout.showModel ? modelSegmentVariants(status, theme) : [""];
|
|
222
|
+
for (const model of models) {
|
|
223
|
+
const combined = model
|
|
224
|
+
? model + theme.fg("dim", CELL_SEPARATOR) + context
|
|
225
|
+
: context;
|
|
226
|
+
if (visibleWidth(combined) <= budget) return flush(combined);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (!layout.showModel) return flush("");
|
|
230
|
+
// Keep the divider on the statistics grid without moving the model off the right edge.
|
|
231
|
+
return !minimal && layout.showUsage
|
|
232
|
+
? this.placeModel(width, theme, status, layout.showWorkspace, budget)
|
|
233
|
+
: flush(renderModelSegment(status, theme, budget));
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Keeps the divider on an info-row bar while the model stays flush right within that span.
|
|
238
|
+
* The rightmost bar with room wins; optional model segments go before divider alignment does,
|
|
239
|
+
* and a model too wide for any bar uses only its own width.
|
|
240
|
+
*/
|
|
241
|
+
private placeModel(
|
|
242
|
+
width: number,
|
|
243
|
+
theme: Theme,
|
|
244
|
+
status: DockStatus,
|
|
245
|
+
workspace: boolean,
|
|
246
|
+
budget: number,
|
|
247
|
+
): RightSegment {
|
|
248
|
+
const spans = statColumns(status, width, workspace)
|
|
249
|
+
.map((column) => column - SEPARATOR_WIDTH)
|
|
250
|
+
.filter((span) => span <= budget)
|
|
251
|
+
.sort((a, b) => a - b);
|
|
252
|
+
for (const text of modelSegmentVariants(status, theme)) {
|
|
253
|
+
const span = spans.find((candidate) => candidate >= visibleWidth(text));
|
|
254
|
+
if (span !== undefined) return { text, width: span };
|
|
255
|
+
}
|
|
256
|
+
const text = renderModelSegment(status, theme, budget);
|
|
257
|
+
return { text, width: visibleWidth(text) };
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** The hint rides the rule under the cells, so it never takes width from a cell or the model. */
|
|
261
|
+
private renderHintRule(width: number, theme: Theme): string {
|
|
262
|
+
for (const hint of KEY_HINTS) {
|
|
263
|
+
const fill = width - visibleWidth(hint) - 3;
|
|
264
|
+
if (fill < 3) continue;
|
|
265
|
+
return (
|
|
266
|
+
theme.fg("borderMuted", "─".repeat(fill)) +
|
|
267
|
+
` ${theme.fg("dim", hint)} ` +
|
|
268
|
+
theme.fg("borderMuted", "─")
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
return theme.fg("borderMuted", "─".repeat(width));
|
|
272
|
+
}
|
|
273
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { Component } from "@earendil-works/pi-tui";
|
|
3
|
+
import { truncateToWidth } from "@earendil-works/pi-tui";
|
|
4
|
+
import type { LuneDockSnapshot } from "@lune_99/pi-lune-extensions-core/dock";
|
|
5
|
+
import { getDockRegistry } from "@lune_99/pi-lune-extensions-core/dock/host";
|
|
6
|
+
import { defineSettingsPanel } from "@lune_99/pi-lune-extensions-core/panel";
|
|
7
|
+
import { DockFooter } from "./dock-footer.ts";
|
|
8
|
+
import { dockSettings, type DockSettings } from "./dock-settings.ts";
|
|
9
|
+
import type { DockStatus } from "./dock-status.ts";
|
|
10
|
+
|
|
11
|
+
const line = (text: string): Component => ({
|
|
12
|
+
render: (width) => [truncateToWidth(text, width)],
|
|
13
|
+
invalidate() {},
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
/** Preview cells are fixed samples: a preview is passive and must not read live plugin state. */
|
|
17
|
+
const sampleEntries = [
|
|
18
|
+
{
|
|
19
|
+
id: "shell",
|
|
20
|
+
snapshot: {
|
|
21
|
+
base: line("○ Shell"),
|
|
22
|
+
detail: line("○ Shell · 2 running"),
|
|
23
|
+
full: line("○ Shell · 2 running · latest: npm test · 14s"),
|
|
24
|
+
} satisfies LuneDockSnapshot,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
id: "ask",
|
|
28
|
+
snapshot: {
|
|
29
|
+
base: line("○ Ask"),
|
|
30
|
+
detail: line("○ Ask · 1 pending request"),
|
|
31
|
+
full: line("○ Ask · 1 pending request · API design"),
|
|
32
|
+
} satisfies LuneDockSnapshot,
|
|
33
|
+
},
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
const sampleStatus: DockStatus = {
|
|
37
|
+
cwd: "~/projects/lune",
|
|
38
|
+
branch: "main",
|
|
39
|
+
sessionName: undefined,
|
|
40
|
+
model: { provider: "anthropic", id: "claude-opus-5-5", thinking: "max" },
|
|
41
|
+
showProvider: true,
|
|
42
|
+
tokenSpeed: { tokensPerSecond: 48.2, generating: false },
|
|
43
|
+
usage: {
|
|
44
|
+
input: 28_000,
|
|
45
|
+
output: 5_600,
|
|
46
|
+
cacheRead: 187_000,
|
|
47
|
+
cacheWrite: 0,
|
|
48
|
+
cost: 0.008,
|
|
49
|
+
cacheHitRate: 98.9,
|
|
50
|
+
},
|
|
51
|
+
context: { tokens: 27_400, percent: 2.7, window: 1_000_000 },
|
|
52
|
+
autoCompact: true,
|
|
53
|
+
extensionStatuses: [],
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/** Draws the candidate settings with the real renderer, focused so key hints and selection show. */
|
|
57
|
+
function dockPreview({ values, theme }: { values: DockSettings; theme: Theme }): Component {
|
|
58
|
+
const footer = new DockFooter();
|
|
59
|
+
const layout = {
|
|
60
|
+
style: values.style,
|
|
61
|
+
showModel: values.showModel,
|
|
62
|
+
showWorkspace: values.showWorkspace,
|
|
63
|
+
showUsage: values.showUsage,
|
|
64
|
+
};
|
|
65
|
+
return {
|
|
66
|
+
render: (width) =>
|
|
67
|
+
footer.render(width, theme, {
|
|
68
|
+
entries: sampleEntries,
|
|
69
|
+
status: values.style === "classic" ? undefined : sampleStatus,
|
|
70
|
+
selectedId: "shell",
|
|
71
|
+
mode: values.displayMode,
|
|
72
|
+
layout,
|
|
73
|
+
}),
|
|
74
|
+
invalidate() {},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export const dockPanel = defineSettingsPanel(dockSettings, {
|
|
79
|
+
id: "dock",
|
|
80
|
+
label: "Dock",
|
|
81
|
+
fields: (field) => [
|
|
82
|
+
field("enabled", {
|
|
83
|
+
label: "Dock",
|
|
84
|
+
description:
|
|
85
|
+
"Off removes the dock and restores Pi's footer and each plugin's own status bar.",
|
|
86
|
+
preview: dockPreview,
|
|
87
|
+
}),
|
|
88
|
+
field("style", {
|
|
89
|
+
label: "Style",
|
|
90
|
+
description:
|
|
91
|
+
"How the dock is framed. Every style except classic replaces Pi's footer with the model, directory and usage rows.",
|
|
92
|
+
choices: [
|
|
93
|
+
{ value: "ruled", label: "ruled", description: "Rules between the rows" },
|
|
94
|
+
{ value: "boxed", label: "boxed", description: "A rounded box around all rows" },
|
|
95
|
+
{ value: "compact", label: "compact", description: "Two rows, no frame" },
|
|
96
|
+
{
|
|
97
|
+
value: "minimal",
|
|
98
|
+
label: "minimal",
|
|
99
|
+
description: "One row: cells, model, context",
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
value: "classic",
|
|
103
|
+
label: "classic",
|
|
104
|
+
description: "Cells only; Pi's footer stays",
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
preview: dockPreview,
|
|
108
|
+
}),
|
|
109
|
+
field("displayMode", {
|
|
110
|
+
label: "Presentation",
|
|
111
|
+
description: "Horizontal information density of each plugin cell.",
|
|
112
|
+
choices: [
|
|
113
|
+
{ value: "base", label: "base", description: "Identity only" },
|
|
114
|
+
{ value: "detail", label: "detail", description: "Identity and a summary" },
|
|
115
|
+
{
|
|
116
|
+
value: "full",
|
|
117
|
+
label: "full",
|
|
118
|
+
description: "Identity, summary and the latest item",
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
preview: dockPreview,
|
|
122
|
+
}),
|
|
123
|
+
field("showModel", {
|
|
124
|
+
label: "Show model",
|
|
125
|
+
description:
|
|
126
|
+
"Provider, model, thinking level and response token speed beside the cells.",
|
|
127
|
+
preview: dockPreview,
|
|
128
|
+
}),
|
|
129
|
+
field("showWorkspace", {
|
|
130
|
+
label: "Show directory",
|
|
131
|
+
description: "Working directory and git branch. Not drawn by minimal or classic.",
|
|
132
|
+
preview: dockPreview,
|
|
133
|
+
}),
|
|
134
|
+
field("showUsage", {
|
|
135
|
+
label: "Show usage",
|
|
136
|
+
description:
|
|
137
|
+
"Token, cache and cost counters with context use. Minimal keeps only context use; classic draws none.",
|
|
138
|
+
preview: dockPreview,
|
|
139
|
+
}),
|
|
140
|
+
field("hidden", {
|
|
141
|
+
label: "Hidden plugins",
|
|
142
|
+
description: "Plugins left out of the dock. They keep running and stay registered.",
|
|
143
|
+
formatValue: (value) => (value.length > 0 ? value.join(", ") : "none"),
|
|
144
|
+
choiceSource: {
|
|
145
|
+
multiple: true,
|
|
146
|
+
emptyMessage: "No plugin has registered with the dock",
|
|
147
|
+
load: ({ context }) =>
|
|
148
|
+
getDockRegistry()
|
|
149
|
+
.getContributions(context.ui)
|
|
150
|
+
.map(({ id }) => ({ value: id, label: id })),
|
|
151
|
+
},
|
|
152
|
+
}),
|
|
153
|
+
field("order", {
|
|
154
|
+
label: "Plugin order",
|
|
155
|
+
description:
|
|
156
|
+
'JSON object of plugin id to position, e.g. {"ask-question": 1}. Smaller positions come first; plugins without one count as 0.',
|
|
157
|
+
editor: "json",
|
|
158
|
+
formatValue: (value) => {
|
|
159
|
+
const entries = Object.entries(value);
|
|
160
|
+
return entries.length > 0
|
|
161
|
+
? entries.map(([id, position]) => `${id}=${position}`).join(", ")
|
|
162
|
+
: "registration order";
|
|
163
|
+
},
|
|
164
|
+
}),
|
|
165
|
+
],
|
|
166
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
3
|
+
import type { LuneDockSnapshot, LuneDockDisplayMode } from "@lune_99/pi-lune-extensions-core/dock";
|
|
4
|
+
|
|
5
|
+
export interface VisibleDockItem {
|
|
6
|
+
id: string;
|
|
7
|
+
snapshot: LuneDockSnapshot;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Levels are complete alternatives, never fragments: resolution degrades only downward.
|
|
12
|
+
*/
|
|
13
|
+
export function resolveSnapshotLevel(snapshot: LuneDockSnapshot, mode: LuneDockDisplayMode) {
|
|
14
|
+
if (mode === "full") return snapshot.full ?? snapshot.detail ?? snapshot.base;
|
|
15
|
+
if (mode === "detail") return snapshot.detail ?? snapshot.base;
|
|
16
|
+
return snapshot.base;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function renderCellText(entry: VisibleDockItem, mode: LuneDockDisplayMode, width: number): string {
|
|
20
|
+
const lines = resolveSnapshotLevel(entry.snapshot, mode).render(width);
|
|
21
|
+
// A level must publish one physical line; wrapping would corrupt the host's single-row widget.
|
|
22
|
+
if (lines.length !== 1 || /[\r\n]/.test(lines[0]!)) {
|
|
23
|
+
throw new Error(`Lune snapshot ${entry.id} (${mode}) must render exactly one line`);
|
|
24
|
+
}
|
|
25
|
+
return truncateToWidth(lines[0]!, width);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function highlight(theme: Theme, text: string): string {
|
|
29
|
+
// Reapply selection after ANSI style changes so plugin resets cannot clear its background.
|
|
30
|
+
return text
|
|
31
|
+
.split(/(\x1b\[[\d;:]*m)/)
|
|
32
|
+
.map((part, index) => (index % 2 === 0 ? theme.bg("selectedBg", part) : part))
|
|
33
|
+
.join("");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Components own their text and styling; this view adds only placement and focus chrome. */
|
|
37
|
+
export class DockView {
|
|
38
|
+
/** The controller keeps one view across widget rebuilds, so the window survives a re-created component. */
|
|
39
|
+
private start = 0;
|
|
40
|
+
|
|
41
|
+
render(
|
|
42
|
+
entries: readonly VisibleDockItem[],
|
|
43
|
+
width: number,
|
|
44
|
+
theme: Theme,
|
|
45
|
+
selectedId?: string,
|
|
46
|
+
mode: LuneDockDisplayMode = "detail",
|
|
47
|
+
): string[] {
|
|
48
|
+
width = Math.max(0, Math.floor(width));
|
|
49
|
+
if (entries.length === 0 || width === 0) {
|
|
50
|
+
this.start = 0;
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
// An unfocused dock passes no selectedId, so there is no cell to keep visible and no focus chrome to draw.
|
|
54
|
+
const selected = entries.findIndex((entry) => entry.id === selectedId);
|
|
55
|
+
|
|
56
|
+
const anchor = Math.max(0, selected);
|
|
57
|
+
|
|
58
|
+
// The 12-column stride estimates how many cells fit; keep one visible when the row is too narrow to meet it.
|
|
59
|
+
const count = Math.min(entries.length, Math.max(1, Math.floor((width - 1) / 12)));
|
|
60
|
+
|
|
61
|
+
// Keep the current window stable until selection leaves it, then move only enough to reveal that cell.
|
|
62
|
+
this.start = Math.min(this.start, anchor, entries.length - count);
|
|
63
|
+
|
|
64
|
+
if (anchor >= this.start + count) {
|
|
65
|
+
this.start = anchor - count + 1;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (selected < 0) {
|
|
69
|
+
this.start = 0;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const end = this.start + count;
|
|
73
|
+
|
|
74
|
+
let before = this.start > 0 ? `‹${this.start} ` : "";
|
|
75
|
+
let after = end < entries.length ? ` ${entries.length - end}›` : "";
|
|
76
|
+
|
|
77
|
+
// Overflow counts must leave the existing gutter available for the selected cell's marker.
|
|
78
|
+
if (selected >= 0 && 1 + visibleWidth(before + after) + 3 * (count - 1) >= width) {
|
|
79
|
+
before = "";
|
|
80
|
+
after = "";
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const overhead = 1 + visibleWidth(before + after) + 3 * (count - 1);
|
|
84
|
+
const available = Math.max(0, width - overhead);
|
|
85
|
+
const pointer = selected >= 0 ? highlight(theme, theme.fg("accent", "❯")) : "";
|
|
86
|
+
|
|
87
|
+
const cells = entries.slice(this.start, end).map((entry, index) => {
|
|
88
|
+
// Leftmost cells absorb the remainder so allocation stays independent of the selection.
|
|
89
|
+
const allocated = Math.floor(available / count) + (index < available % count ? 1 : 0);
|
|
90
|
+
const text = renderCellText(entry, mode, allocated);
|
|
91
|
+
const active = entry.id === selectedId;
|
|
92
|
+
// Reuse the gutter or separator's final blank column instead of adding space to a cell.
|
|
93
|
+
const prefix =
|
|
94
|
+
index === 0
|
|
95
|
+
? active
|
|
96
|
+
? pointer
|
|
97
|
+
: " "
|
|
98
|
+
: active
|
|
99
|
+
? theme.fg("dim", " │") + pointer
|
|
100
|
+
: theme.fg("dim", " │ ");
|
|
101
|
+
return prefix + (active ? highlight(theme, text) : text);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const line = theme.fg("dim", before) + cells.join("") + theme.fg("dim", after);
|
|
105
|
+
return [truncateToWidth(line, width)];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** One-shot rendering for callers without a view instance; window state is deliberately not preserved. */
|
|
110
|
+
export function renderDockLine(
|
|
111
|
+
entries: readonly VisibleDockItem[],
|
|
112
|
+
width: number,
|
|
113
|
+
theme: Theme,
|
|
114
|
+
selectedId?: string,
|
|
115
|
+
mode: LuneDockDisplayMode = "detail",
|
|
116
|
+
): string[] {
|
|
117
|
+
return new DockView().render(entries, width, theme, selectedId, mode);
|
|
118
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Type, type Static, type TLiteral } from "typebox";
|
|
2
|
+
import { defineSettings, type SettingsView } from "@lune_99/pi-lune-extensions-core/settings";
|
|
3
|
+
import { DOCK_STYLES } from "./dock-footer.ts";
|
|
4
|
+
|
|
5
|
+
export const SETTINGS_ID = "pi-dock";
|
|
6
|
+
|
|
7
|
+
function choice<const T extends readonly string[]>(values: T, initial: T[number]) {
|
|
8
|
+
const variants = values.map((value) => Type.Literal(value)) as {
|
|
9
|
+
-readonly [K in keyof T]: TLiteral<T[K]>;
|
|
10
|
+
};
|
|
11
|
+
return Type.Union<{ -readonly [K in keyof T]: TLiteral<T[K]> }>(
|
|
12
|
+
[...variants] as [...{ -readonly [K in keyof T]: TLiteral<T[K]> }],
|
|
13
|
+
{ default: initial },
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const dockSchema = Type.Object({
|
|
18
|
+
enabled: Type.Boolean({ default: true }),
|
|
19
|
+
displayMode: choice(["base", "detail", "full"] as const, "detail"),
|
|
20
|
+
style: choice(DOCK_STYLES, "ruled"),
|
|
21
|
+
showModel: Type.Boolean({ default: true }),
|
|
22
|
+
showWorkspace: Type.Boolean({ default: true }),
|
|
23
|
+
showUsage: Type.Boolean({ default: true }),
|
|
24
|
+
// Contribution IDs are not known until runtime, so visibility and order cannot be per-ID fields.
|
|
25
|
+
hidden: Type.Array(Type.String({ minLength: 1 }), { default: [], uniqueItems: true }),
|
|
26
|
+
order: Type.Record(Type.String({ minLength: 1 }), Type.Integer(), { default: {} }),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export type DockSettings = Static<typeof dockSchema>;
|
|
30
|
+
export type DockSettingsView = SettingsView<typeof dockSchema>;
|
|
31
|
+
|
|
32
|
+
export const dockSettings = defineSettings({ id: SETTINGS_ID, schema: dockSchema });
|