@narumitw/pi-starship 0.49.3 → 0.50.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.
Files changed (100) hide show
  1. package/NOTICES.md +4 -2
  2. package/README.md +62 -16
  3. package/package.json +10 -11
  4. package/src/command-contract.ts +13 -0
  5. package/src/command-inspector.ts +198 -0
  6. package/src/command-preset-picker.ts +203 -0
  7. package/src/command-preview.ts +206 -0
  8. package/src/commands.ts +784 -0
  9. package/src/config.ts +794 -0
  10. package/src/format/formatter.ts +275 -0
  11. package/src/format/style.ts +278 -0
  12. package/src/index.ts +1 -1
  13. package/src/modules/activity.ts +38 -0
  14. package/src/modules/brand.ts +13 -0
  15. package/src/modules/cache.ts +23 -0
  16. package/src/modules/catalog.ts +124 -0
  17. package/src/modules/cloud.ts +74 -0
  18. package/src/modules/context.ts +33 -0
  19. package/src/modules/cost.ts +31 -0
  20. package/src/modules/deployment.ts +61 -0
  21. package/src/modules/development.ts +112 -0
  22. package/src/modules/directory.ts +151 -0
  23. package/src/modules/display.ts +14 -0
  24. package/src/modules/execution.ts +84 -0
  25. package/src/modules/extension-status.ts +93 -0
  26. package/src/modules/fill.ts +14 -0
  27. package/src/modules/git/branch.ts +31 -0
  28. package/src/modules/git/commit.ts +29 -0
  29. package/src/modules/git/metrics.ts +26 -0
  30. package/src/modules/git/runtime.ts +415 -0
  31. package/src/modules/git/state.ts +21 -0
  32. package/src/modules/git/status.ts +87 -0
  33. package/src/modules/git/worktree.ts +16 -0
  34. package/src/modules/github-pr.ts +24 -0
  35. package/src/modules/helpers.ts +5 -0
  36. package/src/modules/index.ts +31 -0
  37. package/src/modules/inspection.ts +138 -0
  38. package/src/modules/languages.ts +87 -0
  39. package/src/modules/model.ts +85 -0
  40. package/src/modules/package.ts +17 -0
  41. package/src/modules/provider.ts +13 -0
  42. package/src/modules/render.ts +166 -0
  43. package/src/modules/terminal.ts +60 -0
  44. package/src/modules/thinking.ts +13 -0
  45. package/src/modules/time.ts +20 -0
  46. package/src/modules/tokens.ts +18 -0
  47. package/src/modules/truncation.ts +37 -0
  48. package/src/modules/turn.ts +13 -0
  49. package/src/modules/types.ts +189 -0
  50. package/src/modules/workspace-helpers.ts +10 -0
  51. package/src/pi-starship.ts +619 -0
  52. package/src/presets/bracketed-segments.ts +45 -0
  53. package/src/presets/catalog.ts +138 -0
  54. package/src/presets/catppuccin-powerline.ts +90 -0
  55. package/src/presets/gruvbox-rainbow.ts +66 -0
  56. package/src/presets/jetpack.ts +51 -0
  57. package/src/presets/minimal.ts +23 -0
  58. package/src/presets/nerd-font-symbols.ts +27 -0
  59. package/src/presets/no-empty-icons.ts +47 -0
  60. package/src/presets/no-nerd-font.ts +51 -0
  61. package/src/presets/no-runtime-versions.ts +52 -0
  62. package/src/presets/pastel-powerline.ts +53 -0
  63. package/src/presets/plain-text-symbols.ts +52 -0
  64. package/src/presets/pure-preset.ts +55 -0
  65. package/src/presets/tokyo-night.ts +53 -0
  66. package/src/runtime/cloud.ts +166 -0
  67. package/src/runtime/command.ts +123 -0
  68. package/src/runtime/deployment.ts +201 -0
  69. package/src/runtime/development.ts +153 -0
  70. package/src/runtime/execution.ts +151 -0
  71. package/src/runtime/github-pr.ts +332 -0
  72. package/src/runtime/helpers.ts +274 -0
  73. package/src/runtime/languages.ts +205 -0
  74. package/src/runtime/package.ts +112 -0
  75. package/src/runtime/refresh-controller.ts +107 -0
  76. package/src/runtime/types.ts +63 -0
  77. package/src/runtime/workspace.ts +147 -0
  78. package/src/usage.ts +53 -0
  79. package/dist/chunks/chunk-CKNSOLSW.ts +0 -10
  80. package/dist/chunks/chunk-CKNSOLSW.ts.map +0 -7
  81. package/dist/chunks/chunk-G2GG2V6Q.ts +0 -218
  82. package/dist/chunks/chunk-G2GG2V6Q.ts.map +0 -7
  83. package/dist/chunks/chunk-Q6DLIM7H.ts +0 -2492
  84. package/dist/chunks/chunk-Q6DLIM7H.ts.map +0 -7
  85. package/dist/chunks/cloud-JBSZWTB6.ts +0 -142
  86. package/dist/chunks/cloud-JBSZWTB6.ts.map +0 -7
  87. package/dist/chunks/commands-BSQZ2R4M.ts +0 -757
  88. package/dist/chunks/commands-BSQZ2R4M.ts.map +0 -7
  89. package/dist/chunks/deployment-ZNYM4B6W.ts +0 -172
  90. package/dist/chunks/deployment-ZNYM4B6W.ts.map +0 -7
  91. package/dist/chunks/development-TNWZ5SRC.ts +0 -132
  92. package/dist/chunks/development-TNWZ5SRC.ts.map +0 -7
  93. package/dist/chunks/execution-QHAP4U33.ts +0 -132
  94. package/dist/chunks/execution-QHAP4U33.ts.map +0 -7
  95. package/dist/chunks/languages-DPWDCH6Q.ts +0 -184
  96. package/dist/chunks/languages-DPWDCH6Q.ts.map +0 -7
  97. package/dist/chunks/package-MXN2YFLX.ts +0 -104
  98. package/dist/chunks/package-MXN2YFLX.ts.map +0 -7
  99. package/dist/pi-starship.ts +0 -1350
  100. package/dist/pi-starship.ts.map +0 -7
@@ -0,0 +1,206 @@
1
+ import { stripVTControlCharacters } from "node:util";
2
+ import type { ExtensionCommandContext, KeybindingsManager } from "@earendil-works/pi-coding-agent";
3
+ import { Key, matchesKey, truncateToWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
4
+
5
+ const RESERVED_HOST_ROWS = 3;
6
+
7
+ export interface PreviewMenuItem<Value extends string> {
8
+ value: Value;
9
+ label: string;
10
+ }
11
+
12
+ export type PreviewMenuResult<Value extends string> =
13
+ | { kind: "selected"; value: Value }
14
+ | { kind: "cancelled" }
15
+ | { kind: "closed" };
16
+
17
+ export async function showPreviewActionMenu<Value extends string>(
18
+ ctx: ExtensionCommandContext,
19
+ title: string,
20
+ body: (width: number) => readonly string[],
21
+ items: readonly PreviewMenuItem<Value>[],
22
+ signal?: AbortSignal,
23
+ ): Promise<PreviewMenuResult<Value> | undefined> {
24
+ if (signal?.aborted) return { kind: "closed" };
25
+ return ctx.ui.custom<PreviewMenuResult<Value> | undefined>((tui, theme, keybindings, done) => {
26
+ let selectedIndex = 0;
27
+ let scrollOffset = 0;
28
+ let lastMaximumScroll = 0;
29
+ let lastViewportSize = 1;
30
+ let disposed = false;
31
+ let deferredAbort: ReturnType<typeof setImmediate> | undefined;
32
+ const closeForAbort = () => {
33
+ if (disposed) return;
34
+ if (deferredAbort) clearImmediate(deferredAbort);
35
+ deferredAbort = undefined;
36
+ done({ kind: "closed" });
37
+ };
38
+ signal?.addEventListener("abort", closeForAbort, { once: true });
39
+ if (signal?.aborted) deferredAbort = setImmediate(closeForAbort);
40
+
41
+ const requestRender = () => {
42
+ if (!disposed) tui.requestRender();
43
+ };
44
+ const moveSelection = (delta: number) => {
45
+ if (items.length === 0) return;
46
+ selectedIndex = (selectedIndex + delta + items.length) % items.length;
47
+ requestRender();
48
+ };
49
+ const movePreview = (offset: number) => {
50
+ scrollOffset = Math.max(0, Math.min(offset, lastMaximumScroll));
51
+ requestRender();
52
+ };
53
+
54
+ return {
55
+ render(width: number): string[] {
56
+ const safeWidth = Math.max(1, width);
57
+ const terminalRows = Number.isFinite(tui.terminal.rows)
58
+ ? Math.floor(tui.terminal.rows)
59
+ : 24;
60
+ const availableRows = Math.max(1, terminalRows - RESERVED_HOST_ROWS);
61
+ const bodyLines = body(safeWidth).flatMap((line) =>
62
+ line ? wrapTextWithAnsi(line, safeWidth) : [""],
63
+ );
64
+ const layout = allocateLayout(availableRows, items.length, bodyLines.length);
65
+ lastViewportSize = layout.previewRows;
66
+ lastMaximumScroll = Math.max(0, bodyLines.length - layout.previewRows);
67
+ scrollOffset = Math.max(0, Math.min(scrollOffset, lastMaximumScroll));
68
+ const actionStart = actionWindowStart(selectedIndex, items.length, layout.actionRows);
69
+ const actionLines = items
70
+ .slice(actionStart, actionStart + layout.actionRows)
71
+ .map((item, index) => {
72
+ const absoluteIndex = actionStart + index;
73
+ const prefix = absoluteIndex === selectedIndex ? "→ " : " ";
74
+ return theme.fg(
75
+ absoluteIndex === selectedIndex ? "accent" : "text",
76
+ `${prefix}${safeDisplayText(item.label)}`,
77
+ );
78
+ });
79
+ const position = layout.positionRows
80
+ ? [theme.fg("dim", previewPosition(scrollOffset, layout.previewRows, bodyLines.length))]
81
+ : [];
82
+ const lines = [
83
+ ...(layout.titleRows ? [theme.fg("accent", theme.bold(safeDisplayText(title)))] : []),
84
+ ...bodyLines.slice(scrollOffset, scrollOffset + layout.previewRows),
85
+ ...position,
86
+ ...actionLines,
87
+ ...(layout.hintRows ? [theme.fg("dim", previewHint(keybindings))] : []),
88
+ ];
89
+ return lines.map((line) => truncateToWidth(line, safeWidth, ""));
90
+ },
91
+ invalidate() {},
92
+ handleInput(data: string) {
93
+ if (disposed) return;
94
+ if (matchesKey(data, Key.ctrl("c"))) {
95
+ done({ kind: "closed" });
96
+ } else if (keybindings.matches(data, "tui.select.cancel")) {
97
+ done({ kind: "cancelled" });
98
+ } else if (keybindings.matches(data, "tui.select.up")) {
99
+ moveSelection(-1);
100
+ } else if (keybindings.matches(data, "tui.select.down")) {
101
+ moveSelection(1);
102
+ } else if (keybindings.matches(data, "tui.select.pageUp")) {
103
+ movePreview(scrollOffset - lastViewportSize);
104
+ } else if (keybindings.matches(data, "tui.select.pageDown")) {
105
+ movePreview(scrollOffset + lastViewportSize);
106
+ } else if (matchesKey(data, Key.home)) {
107
+ movePreview(0);
108
+ } else if (matchesKey(data, Key.end)) {
109
+ movePreview(lastMaximumScroll);
110
+ } else if (keybindings.matches(data, "tui.select.confirm")) {
111
+ const item = items[selectedIndex];
112
+ if (item) done({ kind: "selected", value: item.value });
113
+ }
114
+ },
115
+ dispose() {
116
+ if (disposed) return;
117
+ disposed = true;
118
+ if (deferredAbort) clearImmediate(deferredAbort);
119
+ deferredAbort = undefined;
120
+ signal?.removeEventListener("abort", closeForAbort);
121
+ },
122
+ };
123
+ });
124
+ }
125
+
126
+ interface PreviewLayout {
127
+ titleRows: number;
128
+ previewRows: number;
129
+ positionRows: number;
130
+ actionRows: number;
131
+ hintRows: number;
132
+ }
133
+
134
+ function allocateLayout(
135
+ availableRows: number,
136
+ actionCount: number,
137
+ bodyLineCount: number,
138
+ ): PreviewLayout {
139
+ if (availableRows === 1) {
140
+ return { titleRows: 0, previewRows: 0, positionRows: 0, actionRows: 1, hintRows: 0 };
141
+ }
142
+ const titleRows = availableRows >= 3 ? 1 : 0;
143
+ const hintRows = availableRows >= 3 ? 1 : 0;
144
+ const minimumPreviewRows = bodyLineCount > 0 && availableRows >= 4 ? 1 : 0;
145
+ const availableActionRows = Math.max(
146
+ 1,
147
+ availableRows - titleRows - hintRows - minimumPreviewRows,
148
+ );
149
+ const actionRows = Math.min(Math.max(1, actionCount), availableActionRows);
150
+ let previewRows = Math.max(0, availableRows - titleRows - hintRows - actionRows);
151
+ const positionRows = previewRows >= 2 && bodyLineCount > previewRows ? 1 : 0;
152
+ previewRows -= positionRows;
153
+ return { titleRows, previewRows, positionRows, actionRows, hintRows };
154
+ }
155
+
156
+ function actionWindowStart(selectedIndex: number, itemCount: number, viewportSize: number): number {
157
+ if (itemCount <= viewportSize) return 0;
158
+ return Math.max(0, Math.min(selectedIndex, itemCount - viewportSize));
159
+ }
160
+
161
+ function previewPosition(offset: number, viewportSize: number, lineCount: number): string {
162
+ if (lineCount === 0) return "0/0";
163
+ return `${offset + 1}-${Math.min(lineCount, offset + viewportSize)}/${lineCount}`;
164
+ }
165
+
166
+ function previewHint(keybindings: Pick<KeybindingsManager, "getKeys">): string {
167
+ const up = bindingText(keybindings, "tui.select.up");
168
+ const down = bindingText(keybindings, "tui.select.down");
169
+ const confirm = bindingText(keybindings, "tui.select.confirm");
170
+ const cancel = bindingText(keybindings, "tui.select.cancel", "ctrl+c");
171
+ const pageUp = bindingText(keybindings, "tui.select.pageUp");
172
+ const pageDown = bindingText(keybindings, "tui.select.pageDown");
173
+ return [
174
+ ...(up || down ? [`${[up, down].filter(Boolean).join("/")} navigate`] : []),
175
+ ...(confirm ? [`${confirm} select`] : []),
176
+ ...(cancel ? [`${cancel} discard`] : []),
177
+ "ctrl+c close",
178
+ ...(pageUp || pageDown ? [`${[pageUp, pageDown].filter(Boolean).join("/")} preview`] : []),
179
+ ].join(" • ");
180
+ }
181
+
182
+ function bindingText(
183
+ keybindings: Pick<KeybindingsManager, "getKeys">,
184
+ binding: Parameters<KeybindingsManager["getKeys"]>[0],
185
+ excluded?: string,
186
+ ): string {
187
+ return keybindings
188
+ .getKeys(binding)
189
+ .filter((key) => key !== excluded)
190
+ .map((key) => {
191
+ if (key === "up") return "↑";
192
+ if (key === "down") return "↓";
193
+ if (key === "escape") return "esc";
194
+ if (key === "return") return "enter";
195
+ return safeDisplayText(key);
196
+ })
197
+ .join("/");
198
+ }
199
+
200
+ function safeDisplayText(value: string): string {
201
+ return Array.from(stripVTControlCharacters(value), (character) => {
202
+ const codePoint = character.codePointAt(0) ?? 0;
203
+ const control = codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f);
204
+ return control ? "" : character;
205
+ }).join("");
206
+ }