@narumitw/pi-starship 0.50.2 → 0.51.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/README.md +52 -4
- package/package.json +2 -2
- package/src/command-preview.ts +95 -97
- package/src/commands.ts +3 -0
- package/src/modules/directory.ts +1 -1
- package/src/modules/model.ts +1 -1
- package/src/runtime/github-pr.ts +23 -12
- package/src/modules/terminal.ts +0 -60
package/README.md
CHANGED
|
@@ -491,10 +491,58 @@ Variables have these values:
|
|
|
491
491
|
- `$number`: digits such as `123`.
|
|
492
492
|
- `$link`: an OSC 8 `#123` link for a safe HTTP(S) URL, otherwise plain `#123`.
|
|
493
493
|
- `$state`: `open`, `draft`, `merged`, or `closed`.
|
|
494
|
-
- `$checks`:
|
|
495
|
-
- `$review`: `approved
|
|
496
|
-
|
|
497
|
-
|
|
494
|
+
- `$checks`: all non-zero check counts in passed, failed, pending order, or `-` when no checks exist.
|
|
495
|
+
- `$review`: `R✓` for approved, `R×` for changes requested, `R?` for review required, or empty
|
|
496
|
+
when unknown.
|
|
497
|
+
- `$status`: one result selected in this order: merged, closed, draft, failing checks, changes
|
|
498
|
+
requested, pending checks, approved, review required, passing checks, then no checks.
|
|
499
|
+
|
|
500
|
+
The compact symbols are font-safe and distinct from Git's default `$`, `!`, and `?` worktree markers:
|
|
501
|
+
|
|
502
|
+
| Compact value | Meaning |
|
|
503
|
+
| --- | --- |
|
|
504
|
+
| `✓<n>` | Checks that passed, including successful, skipped, and neutral conclusions |
|
|
505
|
+
| `×<n>` | Checks that failed |
|
|
506
|
+
| `…<n>` | Checks that are pending |
|
|
507
|
+
| `R✓` | Review approved |
|
|
508
|
+
| `R×` | Changes requested |
|
|
509
|
+
| `R?` | Review required |
|
|
510
|
+
| `M` / `C` / `D` | Merged, closed, or draft PR |
|
|
511
|
+
| `-` | No checks |
|
|
512
|
+
|
|
513
|
+
The unchanged default module format uses `$status` and now renders compact output:
|
|
514
|
+
|
|
515
|
+
```text
|
|
516
|
+
PR #123 · ×2
|
|
517
|
+
PR #123 · R✓
|
|
518
|
+
PR #123 · M
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
Use the existing `$checks` and `$review` variables together when every check category and the review
|
|
522
|
+
result should remain visible:
|
|
523
|
+
|
|
524
|
+
```toml
|
|
525
|
+
[github_pr]
|
|
526
|
+
format = "[$symbol$link( $checks)( $review) ]($style)"
|
|
527
|
+
```
|
|
528
|
+
|
|
529
|
+
```text
|
|
530
|
+
PR #123 ✓12 ×2 …7 R×
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
This is a breaking display migration for custom formats that use these variables:
|
|
534
|
+
|
|
535
|
+
| Previous value | Compact value |
|
|
536
|
+
| --- | --- |
|
|
537
|
+
| `checks passing` | `✓<n>` |
|
|
538
|
+
| `<n> failing` | `×<n>` |
|
|
539
|
+
| `<n> pending` | `…<n>` |
|
|
540
|
+
| `no checks` | `-` |
|
|
541
|
+
| `approved` / `changes requested` / `review required` | `R✓` / `R×` / `R?` |
|
|
542
|
+
| `merged` / `closed` / `draft` | `M` / `C` / `D` |
|
|
543
|
+
|
|
544
|
+
The old English values have no verbose aliases.
|
|
545
|
+
The variable names and default module format remain unchanged, so no TOML field migration is needed.
|
|
498
546
|
|
|
499
547
|
The query runs only in TUI sessions when the enabled module is reachable from the root format. It
|
|
500
548
|
refreshes at session start, immediately after a branch change, after each agent run, after accepted
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@narumitw/pi-starship",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.51.0",
|
|
4
4
|
"description": "Native Starship-style TOML statusline for the Pi coding agent.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"typecheck": "tsc --noEmit"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@narumitw/pi-tui-kit": "^0.
|
|
37
|
+
"@narumitw/pi-tui-kit": "^0.54.0",
|
|
38
38
|
"smol-toml": "^1.7.1",
|
|
39
39
|
"yaml": "^2.9.0"
|
|
40
40
|
},
|
package/src/command-preview.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { stripVTControlCharacters } from "node:util";
|
|
2
2
|
import type { ExtensionCommandContext, KeybindingsManager } from "@earendil-works/pi-coding-agent";
|
|
3
3
|
import { Key, matchesKey, truncateToWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
4
|
+
import { runCustomInteraction } from "@narumitw/pi-tui-kit";
|
|
4
5
|
|
|
5
6
|
const RESERVED_HOST_ROWS = 3;
|
|
6
7
|
|
|
@@ -20,107 +21,104 @@ export async function showPreviewActionMenu<Value extends string>(
|
|
|
20
21
|
body: (width: number) => readonly string[],
|
|
21
22
|
items: readonly PreviewMenuItem<Value>[],
|
|
22
23
|
signal?: AbortSignal,
|
|
24
|
+
isCurrent: () => boolean = () => !signal?.aborted,
|
|
23
25
|
): Promise<PreviewMenuResult<Value> | undefined> {
|
|
24
|
-
if (signal?.aborted) return { kind: "closed" };
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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);
|
|
26
|
+
if (signal?.aborted || !isCurrent()) return { kind: "closed" };
|
|
27
|
+
const result = await runCustomInteraction<PreviewMenuResult<Value>>(ctx, {
|
|
28
|
+
signal,
|
|
29
|
+
isCurrent,
|
|
30
|
+
create: ({ tui, theme, keybindings, complete }) => {
|
|
31
|
+
let selectedIndex = 0;
|
|
32
|
+
let scrollOffset = 0;
|
|
33
|
+
let lastMaximumScroll = 0;
|
|
34
|
+
let lastViewportSize = 1;
|
|
35
|
+
let disposed = false;
|
|
40
36
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
37
|
+
const requestRender = () => {
|
|
38
|
+
if (!disposed) tui.requestRender();
|
|
39
|
+
};
|
|
40
|
+
const moveSelection = (delta: number) => {
|
|
41
|
+
if (items.length === 0) return;
|
|
42
|
+
selectedIndex = (selectedIndex + delta + items.length) % items.length;
|
|
43
|
+
requestRender();
|
|
44
|
+
};
|
|
45
|
+
const movePreview = (offset: number) => {
|
|
46
|
+
scrollOffset = Math.max(0, Math.min(offset, lastMaximumScroll));
|
|
47
|
+
requestRender();
|
|
48
|
+
};
|
|
53
49
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
},
|
|
122
|
-
};
|
|
50
|
+
return {
|
|
51
|
+
render(width: number): string[] {
|
|
52
|
+
const safeWidth = Math.max(1, width);
|
|
53
|
+
const terminalRows = Number.isFinite(tui.terminal.rows)
|
|
54
|
+
? Math.floor(tui.terminal.rows)
|
|
55
|
+
: 24;
|
|
56
|
+
const availableRows = Math.max(1, terminalRows - RESERVED_HOST_ROWS);
|
|
57
|
+
const bodyLines = body(safeWidth).flatMap((line) =>
|
|
58
|
+
line ? wrapTextWithAnsi(line, safeWidth) : [""],
|
|
59
|
+
);
|
|
60
|
+
const layout = allocateLayout(availableRows, items.length, bodyLines.length);
|
|
61
|
+
lastViewportSize = layout.previewRows;
|
|
62
|
+
lastMaximumScroll = Math.max(0, bodyLines.length - layout.previewRows);
|
|
63
|
+
scrollOffset = Math.max(0, Math.min(scrollOffset, lastMaximumScroll));
|
|
64
|
+
const actionStart = actionWindowStart(selectedIndex, items.length, layout.actionRows);
|
|
65
|
+
const actionLines = items
|
|
66
|
+
.slice(actionStart, actionStart + layout.actionRows)
|
|
67
|
+
.map((item, index) => {
|
|
68
|
+
const absoluteIndex = actionStart + index;
|
|
69
|
+
const prefix = absoluteIndex === selectedIndex ? "→ " : " ";
|
|
70
|
+
return theme.fg(
|
|
71
|
+
absoluteIndex === selectedIndex ? "accent" : "text",
|
|
72
|
+
`${prefix}${safeDisplayText(item.label)}`,
|
|
73
|
+
);
|
|
74
|
+
});
|
|
75
|
+
const position = layout.positionRows
|
|
76
|
+
? [theme.fg("dim", previewPosition(scrollOffset, layout.previewRows, bodyLines.length))]
|
|
77
|
+
: [];
|
|
78
|
+
const lines = [
|
|
79
|
+
...(layout.titleRows ? [theme.fg("accent", theme.bold(safeDisplayText(title)))] : []),
|
|
80
|
+
...bodyLines.slice(scrollOffset, scrollOffset + layout.previewRows),
|
|
81
|
+
...position,
|
|
82
|
+
...actionLines,
|
|
83
|
+
...(layout.hintRows ? [theme.fg("dim", previewHint(keybindings))] : []),
|
|
84
|
+
];
|
|
85
|
+
return lines.map((line) => truncateToWidth(line, safeWidth, ""));
|
|
86
|
+
},
|
|
87
|
+
invalidate() {},
|
|
88
|
+
handleInput(data: string) {
|
|
89
|
+
if (disposed) return;
|
|
90
|
+
if (matchesKey(data, Key.ctrl("c"))) {
|
|
91
|
+
complete({ kind: "closed" });
|
|
92
|
+
} else if (keybindings.matches(data, "tui.select.cancel")) {
|
|
93
|
+
complete({ kind: "cancelled" });
|
|
94
|
+
} else if (keybindings.matches(data, "tui.select.up")) {
|
|
95
|
+
moveSelection(-1);
|
|
96
|
+
} else if (keybindings.matches(data, "tui.select.down")) {
|
|
97
|
+
moveSelection(1);
|
|
98
|
+
} else if (keybindings.matches(data, "tui.select.pageUp")) {
|
|
99
|
+
movePreview(scrollOffset - lastViewportSize);
|
|
100
|
+
} else if (keybindings.matches(data, "tui.select.pageDown")) {
|
|
101
|
+
movePreview(scrollOffset + lastViewportSize);
|
|
102
|
+
} else if (matchesKey(data, Key.home)) {
|
|
103
|
+
movePreview(0);
|
|
104
|
+
} else if (matchesKey(data, Key.end)) {
|
|
105
|
+
movePreview(lastMaximumScroll);
|
|
106
|
+
} else if (keybindings.matches(data, "tui.select.confirm")) {
|
|
107
|
+
const item = items[selectedIndex];
|
|
108
|
+
if (item) complete({ kind: "selected", value: item.value });
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
dispose() {
|
|
112
|
+
if (disposed) return;
|
|
113
|
+
disposed = true;
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
},
|
|
123
117
|
});
|
|
118
|
+
if (result.kind === "completed") return result.value;
|
|
119
|
+
if (result.kind === "error") throw result.error;
|
|
120
|
+
if (result.kind === "stale" && (signal?.aborted || !isCurrent())) return { kind: "closed" };
|
|
121
|
+
return undefined;
|
|
124
122
|
}
|
|
125
123
|
|
|
126
124
|
interface PreviewLayout {
|
package/src/commands.ts
CHANGED
|
@@ -300,6 +300,7 @@ async function editSettings(
|
|
|
300
300
|
{ value: PREVIEW_ACTIONS.cancel, label: "Discard draft" },
|
|
301
301
|
],
|
|
302
302
|
owner.signal,
|
|
303
|
+
owner.isCurrent,
|
|
303
304
|
);
|
|
304
305
|
if (!isCurrentOwner(owner)) return "cancel";
|
|
305
306
|
if (action?.kind === "closed") return "close";
|
|
@@ -384,6 +385,7 @@ async function applyPreset(
|
|
|
384
385
|
{ value: PREVIEW_ACTIONS.cancel, label: "Choose another preset" },
|
|
385
386
|
],
|
|
386
387
|
owner.signal,
|
|
388
|
+
owner.isCurrent,
|
|
387
389
|
);
|
|
388
390
|
if (!isCurrentOwner(owner)) return "cancel";
|
|
389
391
|
if (action?.kind === "closed") return "close";
|
|
@@ -461,6 +463,7 @@ async function reviewAndApply(
|
|
|
461
463
|
},
|
|
462
464
|
],
|
|
463
465
|
owner.signal,
|
|
466
|
+
owner.isCurrent,
|
|
464
467
|
);
|
|
465
468
|
if (!isCurrentOwner(owner)) return "cancel";
|
|
466
469
|
if (selection?.kind === "closed") return "close";
|
package/src/modules/directory.ts
CHANGED
package/src/modules/model.ts
CHANGED
package/src/runtime/github-pr.ts
CHANGED
|
@@ -180,16 +180,25 @@ function summarizeChecks(value: unknown): CheckSummary {
|
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
function formatChecks(checks: CheckSummary): string {
|
|
183
|
-
if (checks.total === 0) return "
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
183
|
+
if (checks.total === 0) return "-";
|
|
184
|
+
const passed = checks.total - checks.failed - checks.pending;
|
|
185
|
+
return [
|
|
186
|
+
compactCount("✓", passed),
|
|
187
|
+
compactCount("×", checks.failed),
|
|
188
|
+
compactCount("…", checks.pending),
|
|
189
|
+
]
|
|
190
|
+
.filter(Boolean)
|
|
191
|
+
.join(" ");
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function compactCount(symbol: string, count: number): string {
|
|
195
|
+
return count > 0 ? `${symbol}${count}` : "";
|
|
187
196
|
}
|
|
188
197
|
|
|
189
198
|
function formatReview(review: ReviewDecision): string {
|
|
190
|
-
if (review === "APPROVED") return "
|
|
191
|
-
if (review === "CHANGES_REQUESTED") return "
|
|
192
|
-
if (review === "REVIEW_REQUIRED") return "
|
|
199
|
+
if (review === "APPROVED") return "R✓";
|
|
200
|
+
if (review === "CHANGES_REQUESTED") return "R×";
|
|
201
|
+
if (review === "REVIEW_REQUIRED") return "R?";
|
|
193
202
|
return "";
|
|
194
203
|
}
|
|
195
204
|
|
|
@@ -199,11 +208,13 @@ function compactStatus(
|
|
|
199
208
|
checksText: string,
|
|
200
209
|
review: string,
|
|
201
210
|
): string {
|
|
202
|
-
if (state === "merged"
|
|
203
|
-
if (
|
|
204
|
-
if (
|
|
205
|
-
if (checks.
|
|
206
|
-
if (review === "
|
|
211
|
+
if (state === "merged") return "M";
|
|
212
|
+
if (state === "closed") return "C";
|
|
213
|
+
if (state === "draft") return "D";
|
|
214
|
+
if (checks.failed > 0) return compactCount("×", checks.failed);
|
|
215
|
+
if (review === "R×") return review;
|
|
216
|
+
if (checks.pending > 0) return compactCount("…", checks.pending);
|
|
217
|
+
if (review === "R✓" || review === "R?") return review;
|
|
207
218
|
return checksText;
|
|
208
219
|
}
|
|
209
220
|
|
package/src/modules/terminal.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
export function sanitizeTerminalText(value: string): string {
|
|
2
|
-
let result = "";
|
|
3
|
-
for (let index = 0; index < value.length; ) {
|
|
4
|
-
const codePoint = value.codePointAt(index) ?? 0;
|
|
5
|
-
const character = String.fromCodePoint(codePoint);
|
|
6
|
-
if (codePoint === 0x1b || codePoint === 0x9b || codePoint === 0x9d) {
|
|
7
|
-
index = skipTerminalEscape(value, index, codePoint);
|
|
8
|
-
continue;
|
|
9
|
-
}
|
|
10
|
-
if (
|
|
11
|
-
codePoint <= 0x1f ||
|
|
12
|
-
(codePoint >= 0x7f && codePoint <= 0x9f) ||
|
|
13
|
-
codePoint === 0x2028 ||
|
|
14
|
-
codePoint === 0x2029
|
|
15
|
-
) {
|
|
16
|
-
if (
|
|
17
|
-
codePoint === 0x09 ||
|
|
18
|
-
codePoint === 0x0a ||
|
|
19
|
-
codePoint === 0x0d ||
|
|
20
|
-
codePoint === 0x85 ||
|
|
21
|
-
codePoint === 0x2028 ||
|
|
22
|
-
codePoint === 0x2029
|
|
23
|
-
) {
|
|
24
|
-
result += " ";
|
|
25
|
-
}
|
|
26
|
-
index += character.length;
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
result += character;
|
|
30
|
-
index += character.length;
|
|
31
|
-
}
|
|
32
|
-
return result;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function skipTerminalEscape(value: string, start: number, codePoint: number): number {
|
|
36
|
-
let index = start + 1;
|
|
37
|
-
const next = value.charCodeAt(index);
|
|
38
|
-
const isOsc = codePoint === 0x9d || (codePoint === 0x1b && next === 0x5d);
|
|
39
|
-
if (isOsc) {
|
|
40
|
-
if (codePoint === 0x1b) index += 1;
|
|
41
|
-
while (index < value.length) {
|
|
42
|
-
const current = value.charCodeAt(index);
|
|
43
|
-
if (current === 0x07 || current === 0x9c) return index + 1;
|
|
44
|
-
if (current === 0x1b && value.charCodeAt(index + 1) === 0x5c) return index + 2;
|
|
45
|
-
index += 1;
|
|
46
|
-
}
|
|
47
|
-
return index;
|
|
48
|
-
}
|
|
49
|
-
const isCsi = codePoint === 0x9b || (codePoint === 0x1b && next === 0x5b);
|
|
50
|
-
if (isCsi) {
|
|
51
|
-
if (codePoint === 0x1b) index += 1;
|
|
52
|
-
while (index < value.length) {
|
|
53
|
-
const current = value.charCodeAt(index);
|
|
54
|
-
index += 1;
|
|
55
|
-
if (current >= 0x40 && current <= 0x7e) break;
|
|
56
|
-
}
|
|
57
|
-
return index;
|
|
58
|
-
}
|
|
59
|
-
return Math.min(value.length, start + (codePoint === 0x1b ? 2 : 1));
|
|
60
|
-
}
|