@lune_99/pi-dock 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.
@@ -0,0 +1,164 @@
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
+ usage: {
43
+ input: 28_000,
44
+ output: 5_600,
45
+ cacheRead: 187_000,
46
+ cacheWrite: 0,
47
+ cost: 0.008,
48
+ cacheHitRate: 98.9,
49
+ },
50
+ context: { tokens: 27_400, percent: 2.7, window: 1_000_000 },
51
+ autoCompact: true,
52
+ extensionStatuses: [],
53
+ };
54
+
55
+ /** Draws the candidate settings with the real renderer, focused so key hints and selection show. */
56
+ function dockPreview({ values, theme }: { values: DockSettings; theme: Theme }): Component {
57
+ const footer = new DockFooter();
58
+ const layout = {
59
+ style: values.style,
60
+ showModel: values.showModel,
61
+ showWorkspace: values.showWorkspace,
62
+ showUsage: values.showUsage,
63
+ };
64
+ return {
65
+ render: (width) =>
66
+ footer.render(width, theme, {
67
+ entries: sampleEntries,
68
+ status: values.style === "classic" ? undefined : sampleStatus,
69
+ selectedId: "shell",
70
+ mode: values.displayMode,
71
+ layout,
72
+ }),
73
+ invalidate() {},
74
+ };
75
+ }
76
+
77
+ export const dockPanel = defineSettingsPanel(dockSettings, {
78
+ id: "dock",
79
+ label: "Dock",
80
+ fields: (field) => [
81
+ field("enabled", {
82
+ label: "Dock",
83
+ description:
84
+ "Off removes the dock and restores Pi's footer and each plugin's own status bar.",
85
+ preview: dockPreview,
86
+ }),
87
+ field("style", {
88
+ label: "Style",
89
+ description:
90
+ "How the dock is framed. Every style except classic replaces Pi's footer with the model, directory and usage rows.",
91
+ choices: [
92
+ { value: "ruled", label: "ruled", description: "Rules between the rows" },
93
+ { value: "boxed", label: "boxed", description: "A rounded box around all rows" },
94
+ { value: "compact", label: "compact", description: "Two rows, no frame" },
95
+ {
96
+ value: "minimal",
97
+ label: "minimal",
98
+ description: "One row: cells, model, context",
99
+ },
100
+ {
101
+ value: "classic",
102
+ label: "classic",
103
+ description: "Cells only; Pi's footer stays",
104
+ },
105
+ ],
106
+ preview: dockPreview,
107
+ }),
108
+ field("displayMode", {
109
+ label: "Presentation",
110
+ description: "Horizontal information density of each plugin cell.",
111
+ choices: [
112
+ { value: "base", label: "base", description: "Identity only" },
113
+ { value: "detail", label: "detail", description: "Identity and a summary" },
114
+ {
115
+ value: "full",
116
+ label: "full",
117
+ description: "Identity, summary and the latest item",
118
+ },
119
+ ],
120
+ preview: dockPreview,
121
+ }),
122
+ field("showModel", {
123
+ label: "Show model",
124
+ description: "Provider, model and thinking level beside the cells.",
125
+ preview: dockPreview,
126
+ }),
127
+ field("showWorkspace", {
128
+ label: "Show directory",
129
+ description: "Working directory and git branch. Not drawn by minimal or classic.",
130
+ preview: dockPreview,
131
+ }),
132
+ field("showUsage", {
133
+ label: "Show usage",
134
+ description:
135
+ "Token, cache and cost counters with context use. Minimal keeps only context use; classic draws none.",
136
+ preview: dockPreview,
137
+ }),
138
+ field("hidden", {
139
+ label: "Hidden plugins",
140
+ description: "Plugins left out of the dock. They keep running and stay registered.",
141
+ formatValue: (value) => (value.length > 0 ? value.join(", ") : "none"),
142
+ choiceSource: {
143
+ multiple: true,
144
+ emptyMessage: "No plugin has registered with the dock",
145
+ load: ({ context }) =>
146
+ getDockRegistry()
147
+ .getContributions(context.ui)
148
+ .map(({ id }) => ({ value: id, label: id })),
149
+ },
150
+ }),
151
+ field("order", {
152
+ label: "Plugin order",
153
+ description:
154
+ 'JSON object of plugin id to position, e.g. {"ask-question": 1}. Smaller positions come first; plugins without one count as 0.',
155
+ editor: "json",
156
+ formatValue: (value) => {
157
+ const entries = Object.entries(value);
158
+ return entries.length > 0
159
+ ? entries.map(([id, position]) => `${id}=${position}`).join(", ")
160
+ : "registration order";
161
+ },
162
+ }),
163
+ ],
164
+ });
@@ -0,0 +1,104 @@
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
+ /** Components own their text and styling; this view adds only placement and focus chrome. */
20
+ export class DockView {
21
+ /** The controller keeps one view across widget rebuilds, so the window survives a re-created component. */
22
+ private start = 0;
23
+
24
+ render(
25
+ entries: readonly VisibleDockItem[],
26
+ width: number,
27
+ theme: Theme,
28
+ selectedId?: string,
29
+ mode: LuneDockDisplayMode = "detail",
30
+ ): string[] {
31
+ width = Math.max(0, Math.floor(width));
32
+ if (entries.length === 0 || width === 0) {
33
+ this.start = 0;
34
+ return [];
35
+ }
36
+ // An unfocused dock passes no selectedId, so there is no cell to keep visible and no focus chrome to draw.
37
+ const selected = entries.findIndex((entry) => entry.id === selectedId);
38
+
39
+ const anchor = Math.max(0, selected);
40
+
41
+ // The 12-column stride estimates how many cells fit; keep one visible when the row is too narrow to meet it.
42
+ const count = Math.min(entries.length, Math.max(1, Math.floor((width - 1) / 12)));
43
+
44
+ // Keep the current window stable until selection leaves it, then move only enough to reveal that cell.
45
+ this.start = Math.min(this.start, anchor, entries.length - count);
46
+
47
+ if (anchor >= this.start + count) {
48
+ this.start = anchor - count + 1;
49
+ }
50
+
51
+ if (selected < 0) {
52
+ this.start = 0;
53
+ }
54
+
55
+ const end = this.start + count;
56
+
57
+ const before = this.start > 0 ? `‹${this.start} ` : "";
58
+
59
+ const after = end < entries.length ? ` ${entries.length - end}›` : "";
60
+
61
+ // The gutter is one column either way, so focus never changes a contribution's allocation.
62
+ const gutter = selected >= 0 ? theme.fg("accent", "❯") : " ";
63
+
64
+ // Markers are ANSI-wrapped, so budget visible columns and keep 3 in step with the separator below.
65
+ const overhead = 1 + visibleWidth(before + after) + 3 * (count - 1);
66
+
67
+ const available = Math.max(0, width - overhead);
68
+
69
+ const cells = entries.slice(this.start, end).map((entry, index) => {
70
+ // Leftmost cells absorb the remainder so allocation stays independent of the selection.
71
+ const allocated = Math.floor(available / count) + (index < available % count ? 1 : 0);
72
+
73
+ const lines = resolveSnapshotLevel(entry.snapshot, mode).render(allocated);
74
+
75
+ // A level must publish one physical line; wrapping would corrupt the host's single-row widget.
76
+ if (lines.length !== 1 || /[\r\n]/.test(lines[0]!)) {
77
+ throw new Error(`Lune snapshot ${entry.id} (${mode}) must render exactly one line`);
78
+ }
79
+ // A level may overflow its allocation: Dock owns the width budget, not the plugin.
80
+ const text = truncateToWidth(lines[0]!, allocated);
81
+ // Background-only highlight keeps a selected cell exactly as wide as an unfocused one.
82
+ return entry.id === selectedId ? theme.bg("selectedBg", text) : text;
83
+ });
84
+
85
+ let line =
86
+ gutter +
87
+ theme.fg("dim", before) +
88
+ cells.join(theme.fg("dim", " │ ")) +
89
+ theme.fg("dim", after);
90
+
91
+ return [truncateToWidth(line, width)];
92
+ }
93
+ }
94
+
95
+ /** One-shot rendering for callers without a view instance; window state is deliberately not preserved. */
96
+ export function renderDockLine(
97
+ entries: readonly VisibleDockItem[],
98
+ width: number,
99
+ theme: Theme,
100
+ selectedId?: string,
101
+ mode: LuneDockDisplayMode = "detail",
102
+ ): string[] {
103
+ return new DockView().render(entries, width, theme, selectedId, mode);
104
+ }
@@ -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 });