@ftrdotdev/pi-tui 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/LICENSE +21 -0
- package/README.md +63 -0
- package/package.json +80 -0
- package/src/autocomplete-contract.test.ts +126 -0
- package/src/autocomplete-contract.ts +91 -0
- package/src/commands/git-execution.test.ts +69 -0
- package/src/commands/git-execution.ts +198 -0
- package/src/commands/git-status.test.ts +379 -0
- package/src/commands/git-status.ts +320 -0
- package/src/components/bordered-box.test.ts +136 -0
- package/src/components/bordered-box.ts +106 -0
- package/src/components/define-component.ts +33 -0
- package/src/components/index.ts +35 -0
- package/src/config.test.ts +469 -0
- package/src/config.ts +307 -0
- package/src/frame/box-frame.test.ts +44 -0
- package/src/frame/box-frame.ts +160 -0
- package/src/icons.ts +203 -0
- package/src/index.ts +359 -0
- package/src/runtime.ts +256 -0
- package/src/session-lifecycle.ts +41 -0
- package/src/state.test.ts +7 -0
- package/src/state.ts +90 -0
- package/src/telemetry.ts +301 -0
- package/src/ui/editor-tint.test.ts +70 -0
- package/src/ui/editor-tint.ts +78 -0
- package/src/ui/editor.ts +403 -0
- package/src/ui/footer.test.ts +350 -0
- package/src/ui/footer.ts +225 -0
- package/src/ui/header.test.ts +260 -0
- package/src/ui/header.ts +165 -0
- package/src/ui/preview.test.ts +639 -0
- package/src/ui/preview.ts +374 -0
- package/src/ui/render-helpers.ts +275 -0
- package/src/ui/settings-command.test.ts +218 -0
- package/src/ui/settings-command.ts +390 -0
- package/src/utils.ts +448 -0
- package/src/vim/editor-close-autocomplete.ts +26 -0
- package/src/vim/editor-host.test.ts +340 -0
- package/src/vim/editor-state.test.ts +385 -0
- package/src/vim/editor-state.ts +314 -0
- package/src/vim/mode-indicator.test.ts +27 -0
- package/src/vim/mode-indicator.ts +44 -0
- package/src/vim/selection-render.test.ts +77 -0
- package/src/vim/selection-render.ts +85 -0
- package/src/vim/text-model.test.ts +85 -0
- package/src/vim/text-model.ts +75 -0
- package/src/vim/vim-router.test.ts +50 -0
- package/src/vim/vim-router.ts +55 -0
- package/src/vim/word-motion.ts +96 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { assert, it } from "@effect/vitest";
|
|
2
|
+
import { Effect, Random } from "effect";
|
|
3
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
import { HeaderRenderService, installHeader } from "./header.ts";
|
|
5
|
+
|
|
6
|
+
// Pixel parity: the header must render byte-identically through makeBorderedBox
|
|
7
|
+
// as it did with its hand-rolled box (captured before the refactor). The tips
|
|
8
|
+
// shuffle draws from Effect's Random service, so every construction in this
|
|
9
|
+
// file runs under a fixed seed to keep the tips cells — and therefore the
|
|
10
|
+
// frozen tables — deterministic.
|
|
11
|
+
const plainTheme = {
|
|
12
|
+
fg: (_color: string, text: string) => text,
|
|
13
|
+
bg: (_color: string, text: string) => text,
|
|
14
|
+
bold: (text: string) => `*${text}*`,
|
|
15
|
+
} as unknown as Theme;
|
|
16
|
+
|
|
17
|
+
const pi = {
|
|
18
|
+
getCommands: () => [
|
|
19
|
+
{ name: "tui" },
|
|
20
|
+
{ name: "settings" },
|
|
21
|
+
{ name: "model" },
|
|
22
|
+
{ name: "preview" },
|
|
23
|
+
],
|
|
24
|
+
getThinkingLevel: () => "off",
|
|
25
|
+
} as never;
|
|
26
|
+
|
|
27
|
+
const ctx = {
|
|
28
|
+
model: { provider: "anthropic", id: "claude-sonnet-4" },
|
|
29
|
+
cwd: "/projects/pi-mono/packages/tui",
|
|
30
|
+
ui: { theme: plainTheme },
|
|
31
|
+
} as never;
|
|
32
|
+
|
|
33
|
+
const TIPS_SEED = "pixel-parity";
|
|
34
|
+
|
|
35
|
+
const EXPECTED: Record<string, string[]> = {
|
|
36
|
+
20: ["Pi v0.84.2"],
|
|
37
|
+
24: [
|
|
38
|
+
"\u256d\u2500\u2500\u2500 Pi v0.84.2 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256e",
|
|
39
|
+
"\u2502 \u2502",
|
|
40
|
+
"\u2502 \u2502",
|
|
41
|
+
"\u2502 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2502",
|
|
42
|
+
"\u2502 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2502",
|
|
43
|
+
"\u2502 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588 \u2502",
|
|
44
|
+
"\u2502 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2502",
|
|
45
|
+
"\u2502 \u2502",
|
|
46
|
+
"\u2502*Let's make some Pi\u001b[0m...\u001b[0m\u2502",
|
|
47
|
+
"\u2502anthropic/claude-so\u001b[0m...\u001b[0m\u2502",
|
|
48
|
+
"\u2502/projects/pi-mono/p\u001b[0m...\u001b[0m\u2502",
|
|
49
|
+
"\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f",
|
|
50
|
+
],
|
|
51
|
+
30: [
|
|
52
|
+
"\u256d\u2500\u2500\u2500 Pi v0.84.2 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256e",
|
|
53
|
+
"\u2502 \u2502",
|
|
54
|
+
"\u2502 \u2502",
|
|
55
|
+
"\u2502 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2502",
|
|
56
|
+
"\u2502 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2502",
|
|
57
|
+
"\u2502 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588 \u2502",
|
|
58
|
+
"\u2502 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2502",
|
|
59
|
+
"\u2502 \u2502",
|
|
60
|
+
"\u2502 *Let's make some Pi(e)* \u2502",
|
|
61
|
+
"\u2502anthropic/claude-sonnet-4\u001b[0m...\u001b[0m\u2502",
|
|
62
|
+
"\u2502/projects/pi-mono/package\u001b[0m...\u001b[0m\u2502",
|
|
63
|
+
"\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f",
|
|
64
|
+
],
|
|
65
|
+
40: [
|
|
66
|
+
"\u256d\u2500\u2500\u2500 Pi v0.84.2 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256e",
|
|
67
|
+
"\u2502 \u2502",
|
|
68
|
+
"\u2502 \u2502",
|
|
69
|
+
"\u2502 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2502",
|
|
70
|
+
"\u2502 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2502",
|
|
71
|
+
"\u2502 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588 \u2502",
|
|
72
|
+
"\u2502 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2502",
|
|
73
|
+
"\u2502 \u2502",
|
|
74
|
+
"\u2502 *Let's make some Pi(e)* \u2502",
|
|
75
|
+
"\u2502anthropic/claude-sonnet-4 \u00b7 thinkin\u001b[0m...\u001b[0m\u2502",
|
|
76
|
+
"\u2502 /projects/pi-mono/packages/tui \u2502",
|
|
77
|
+
"\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f",
|
|
78
|
+
],
|
|
79
|
+
60: [
|
|
80
|
+
"\u256d\u2500\u2500\u2500 Pi v0.84.2 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256e",
|
|
81
|
+
"\u2502 \u2502 \u2502",
|
|
82
|
+
"\u2502 \u2502 *Welcome* \u2502",
|
|
83
|
+
"\u2502 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2502 Ask Pi anything \u2502",
|
|
84
|
+
"\u2502 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2502 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2502",
|
|
85
|
+
"\u2502 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588 \u2502 *Commands* \u2502",
|
|
86
|
+
"\u2502 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2502 /tui \u2502",
|
|
87
|
+
"\u2502 \u2502 /copy \u2502",
|
|
88
|
+
"\u2502 *Let's make some Pi(e)* \u2502 /logout \u2502",
|
|
89
|
+
"\u2502anthropic/claude-sonnet-4 \u00b7 thinking\u001b[0m...\u001b[0m \u2502 /scoped-models \u2502",
|
|
90
|
+
"\u2502 /projects/pi-mono/packages/tui \u2502 \u2502",
|
|
91
|
+
"\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f",
|
|
92
|
+
],
|
|
93
|
+
80: [
|
|
94
|
+
"\u256d\u2500\u2500\u2500 Pi v0.84.2 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256e",
|
|
95
|
+
"\u2502 \u2502 \u2502",
|
|
96
|
+
"\u2502 \u2502 *Welcome* \u2502",
|
|
97
|
+
"\u2502 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2502 Ask Pi anything \u2502",
|
|
98
|
+
"\u2502 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2502 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2502",
|
|
99
|
+
"\u2502 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588 \u2502 *Commands* \u2502",
|
|
100
|
+
"\u2502 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2502 /tui \u2502",
|
|
101
|
+
"\u2502 \u2502 /copy \u2502",
|
|
102
|
+
"\u2502 *Let's make some Pi(e)* \u2502 /logout \u2502",
|
|
103
|
+
"\u2502 anthropic/claude-sonnet-4 \u00b7 thinking off \u2502 /scoped-models \u2502",
|
|
104
|
+
"\u2502 /projects/pi-mono/packages/tui \u2502 \u2502",
|
|
105
|
+
"\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f",
|
|
106
|
+
],
|
|
107
|
+
100: [
|
|
108
|
+
"\u256d\u2500\u2500\u2500 Pi v0.84.2 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256e",
|
|
109
|
+
"\u2502 \u2502 \u2502",
|
|
110
|
+
"\u2502 \u2502 *Welcome* \u2502",
|
|
111
|
+
"\u2502 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2502 Ask Pi anything \u2502",
|
|
112
|
+
"\u2502 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2502 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2502",
|
|
113
|
+
"\u2502 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588 \u2502 *Commands* \u2502",
|
|
114
|
+
"\u2502 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2502 /tui \u2502",
|
|
115
|
+
"\u2502 \u2502 /copy \u2502",
|
|
116
|
+
"\u2502 *Let's make some Pi(e)* \u2502 /logout \u2502",
|
|
117
|
+
"\u2502 anthropic/claude-sonnet-4 \u00b7 thinking off \u2502 /scoped-models \u2502",
|
|
118
|
+
"\u2502 /projects/pi-mono/packages/tui \u2502 \u2502",
|
|
119
|
+
"\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f",
|
|
120
|
+
],
|
|
121
|
+
120: [
|
|
122
|
+
"\u256d\u2500\u2500\u2500 Pi v0.84.2 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256e",
|
|
123
|
+
"\u2502 \u2502 \u2502",
|
|
124
|
+
"\u2502 \u2502 *Welcome* \u2502",
|
|
125
|
+
"\u2502 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2502 Ask Pi anything \u2502",
|
|
126
|
+
"\u2502 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2502 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2502",
|
|
127
|
+
"\u2502 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588 \u2502 *Commands* \u2502",
|
|
128
|
+
"\u2502 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2502 /tui \u2502",
|
|
129
|
+
"\u2502 \u2502 /copy \u2502",
|
|
130
|
+
"\u2502 *Let's make some Pi(e)* \u2502 /logout \u2502",
|
|
131
|
+
"\u2502 anthropic/claude-sonnet-4 \u00b7 thinking off \u2502 /scoped-models \u2502",
|
|
132
|
+
"\u2502 /projects/pi-mono/packages/tui \u2502 \u2502",
|
|
133
|
+
"\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f",
|
|
134
|
+
],
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// Render one width through the service layer entry under the fixed seed.
|
|
138
|
+
const renderHeader = (width: number) =>
|
|
139
|
+
Effect.runSync(
|
|
140
|
+
Effect.gen(function* () {
|
|
141
|
+
const svc = yield* HeaderRenderService;
|
|
142
|
+
return yield* svc.render(width);
|
|
143
|
+
})
|
|
144
|
+
.pipe(Effect.provide(HeaderRenderService.make(pi, ctx)))
|
|
145
|
+
.pipe(Random.withSeed(TIPS_SEED)),
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
for (const width of Object.keys(EXPECTED)) {
|
|
149
|
+
it(`renders the boxed header identically at width ${width}`, () => {
|
|
150
|
+
assert.deepStrictEqual(renderHeader(Number(width)), EXPECTED[width]);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
it("header tips are fixed at service build while live inputs are re-read per run", () => {
|
|
155
|
+
let thinking = "off";
|
|
156
|
+
const mutablePi = {
|
|
157
|
+
getCommands: () => [
|
|
158
|
+
{ name: "tui" },
|
|
159
|
+
{ name: "settings" },
|
|
160
|
+
{ name: "model" },
|
|
161
|
+
{ name: "preview" },
|
|
162
|
+
],
|
|
163
|
+
getThinkingLevel: () => thinking,
|
|
164
|
+
} as never;
|
|
165
|
+
const mutableCtx = {
|
|
166
|
+
model: { provider: "anthropic", id: "claude-sonnet-4" },
|
|
167
|
+
cwd: "/projects/pi-mono/packages/tui",
|
|
168
|
+
ui: { theme: plainTheme },
|
|
169
|
+
} as never;
|
|
170
|
+
|
|
171
|
+
const layer = HeaderRenderService.make(mutablePi, mutableCtx);
|
|
172
|
+
const render = (width: number) =>
|
|
173
|
+
Effect.runSync(
|
|
174
|
+
Effect.gen(function* () {
|
|
175
|
+
const svc = yield* HeaderRenderService;
|
|
176
|
+
return yield* svc.render(width);
|
|
177
|
+
})
|
|
178
|
+
.pipe(Effect.provide(layer))
|
|
179
|
+
.pipe(Random.withSeed(TIPS_SEED)),
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
const first = render(60);
|
|
183
|
+
thinking = "high";
|
|
184
|
+
(mutableCtx as { cwd: string }).cwd = "/workspace/elsewhere";
|
|
185
|
+
const second = render(60);
|
|
186
|
+
|
|
187
|
+
// The tips cells (everything after the column separator) are frozen at
|
|
188
|
+
// service build: identical across both runs, including the four slash
|
|
189
|
+
// commands. The left cells re-read live inputs per run.
|
|
190
|
+
// Row shape: rail │ LEFT cell │ tips cell │ rail — the tips cell is the
|
|
191
|
+
// second split part after the rail-separated LEFT cell.
|
|
192
|
+
const tipsCells = (lines: string[]) =>
|
|
193
|
+
lines.map((line) => {
|
|
194
|
+
const parts = line.split("│");
|
|
195
|
+
const cell = parts.length >= 3 ? parts[2] : undefined;
|
|
196
|
+
return cell?.trim() ?? "";
|
|
197
|
+
});
|
|
198
|
+
assert.deepStrictEqual(tipsCells(second), tipsCells(first));
|
|
199
|
+
assert.deepStrictEqual(tipsCells(first).slice(6, 10), [
|
|
200
|
+
"/tui",
|
|
201
|
+
"/copy",
|
|
202
|
+
"/logout",
|
|
203
|
+
"/scoped-models",
|
|
204
|
+
]);
|
|
205
|
+
|
|
206
|
+
// Live re-reads per run: the model/thinking row (index 9) and the cwd row
|
|
207
|
+
// (index 10) change when the fake live inputs change.
|
|
208
|
+
assert.notStrictEqual(second[9], first[9]);
|
|
209
|
+
assert.notStrictEqual(second[10], first[10]);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it("installHeader registers a closure component at mount and unregisters on cleanup", () => {
|
|
213
|
+
let captured: ((tui: unknown, theme: unknown) => unknown) | undefined;
|
|
214
|
+
let unregistered = false;
|
|
215
|
+
const mountCtx = {
|
|
216
|
+
model: { provider: "anthropic", id: "claude-sonnet-4" },
|
|
217
|
+
cwd: "/projects/pi-mono/packages/tui",
|
|
218
|
+
ui: {
|
|
219
|
+
theme: plainTheme,
|
|
220
|
+
setHeader(factory: ((tui: unknown, theme: unknown) => unknown) | undefined) {
|
|
221
|
+
captured = factory;
|
|
222
|
+
if (factory === undefined) unregistered = true;
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
} as never;
|
|
226
|
+
|
|
227
|
+
const cleanup = installHeader(pi, mountCtx);
|
|
228
|
+
|
|
229
|
+
assert.strictEqual(typeof captured, "function");
|
|
230
|
+
const componentA = captured!(undefined, plainTheme) as {
|
|
231
|
+
render: (width: number) => string[];
|
|
232
|
+
};
|
|
233
|
+
const linesA = componentA.render(80);
|
|
234
|
+
|
|
235
|
+
// Re-mount swaps the slot to a fresh component; both render the header.
|
|
236
|
+
const componentB = captured!(undefined, plainTheme) as {
|
|
237
|
+
render: (width: number) => string[];
|
|
238
|
+
};
|
|
239
|
+
assert.notStrictEqual(componentA, componentB);
|
|
240
|
+
const linesB = componentB.render(80);
|
|
241
|
+
|
|
242
|
+
// The seam uses the ambient Random service for the tips shuffle, so only
|
|
243
|
+
// the tips cells of rows 6-9 are non-deterministic. Everything else must be
|
|
244
|
+
// byte-identical to the frozen table: borders, logo rows, title, and the
|
|
245
|
+
// empty rail rows.
|
|
246
|
+
const expected80 = EXPECTED[80]!;
|
|
247
|
+
for (const [label, lines] of [
|
|
248
|
+
["first mount", linesA],
|
|
249
|
+
["remount", linesB],
|
|
250
|
+
] as const) {
|
|
251
|
+
assert.strictEqual(lines.length, expected80.length, `${label}: line count`);
|
|
252
|
+
for (const i of [0, 1, 2, 3, 4, 5, 10, 11]) {
|
|
253
|
+
assert.deepStrictEqual(lines[i], expected80[i], `${label}: row ${i}`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
cleanup();
|
|
258
|
+
assert.strictEqual(unregistered, true);
|
|
259
|
+
assert.strictEqual(captured, undefined);
|
|
260
|
+
});
|
package/src/ui/header.ts
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import {
|
|
2
|
+
VERSION,
|
|
3
|
+
type ExtensionAPI,
|
|
4
|
+
type ExtensionContext,
|
|
5
|
+
type Theme,
|
|
6
|
+
} from "@earendil-works/pi-coding-agent";
|
|
7
|
+
import { Context, Effect, Layer } from "effect";
|
|
8
|
+
import { makeBorderedBox } from "../components/bordered-box.ts";
|
|
9
|
+
import { defineComponent, type DisposableComponent } from "../components/define-component.ts";
|
|
10
|
+
import { renderLogo, twoColumn } from "./render-helpers.ts";
|
|
11
|
+
import {
|
|
12
|
+
center,
|
|
13
|
+
collectPiCommandNames,
|
|
14
|
+
formatCwd,
|
|
15
|
+
formatModelLabel,
|
|
16
|
+
formatThinkingLabel,
|
|
17
|
+
headerColumnWidths,
|
|
18
|
+
padRight,
|
|
19
|
+
pickSlashCommandTips,
|
|
20
|
+
} from "../utils.ts";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Pi header widget (`setHeader`), framed in the house rounded box.
|
|
24
|
+
*
|
|
25
|
+
* The frame (top border with the `Pi vVERSION` label, the `│` rails, the
|
|
26
|
+
* bottom border) is rendered by {@link makeBorderedBox} so every view in
|
|
27
|
+
* this package shares one border implementation. Only the body — logo, title,
|
|
28
|
+
* model/effort/cwd column, and the slash-command tips — is composed here.
|
|
29
|
+
* The header keeps the body rail-flush (`paddingX: 0`) to preserve a
|
|
30
|
+
* zero-gap look between content and rails.
|
|
31
|
+
*
|
|
32
|
+
* Construction follows the house service pattern (preview.ts): the service
|
|
33
|
+
* builds through a `Layer.effect` factory, its render is a named synchronous
|
|
34
|
+
* total effect, tips are computed once at service build from the command pool
|
|
35
|
+
* and never re-read, and the closure component handed to pi runs the render
|
|
36
|
+
* effect with `Effect.runSync` per invocation.
|
|
37
|
+
*/
|
|
38
|
+
export class HeaderRenderService extends Context.Service<
|
|
39
|
+
HeaderRenderService,
|
|
40
|
+
{ readonly render: (width: number) => Effect.Effect<string[]> }
|
|
41
|
+
>()("tui/header/HeaderRenderService") {
|
|
42
|
+
static make(pi: ExtensionAPI, ctx: ExtensionContext): Layer.Layer<HeaderRenderService> {
|
|
43
|
+
return Layer.effect(
|
|
44
|
+
HeaderRenderService,
|
|
45
|
+
Effect.gen(function* () {
|
|
46
|
+
// Construction-once tips (preserves the former constructor semantics):
|
|
47
|
+
// computed from `pi.getCommands()` at service build, never re-read.
|
|
48
|
+
const tipCommands = yield* pickSlashCommandTips(collectPiCommandNames(pi.getCommands()), {
|
|
49
|
+
fixed: ["tui"],
|
|
50
|
+
count: 3,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// Named synchronous total step: the body column composition, rendered
|
|
54
|
+
// at `innerWidth` because the frame owns the two rail columns.
|
|
55
|
+
const renderBody = (
|
|
56
|
+
theme: Theme,
|
|
57
|
+
_innerWidth: number,
|
|
58
|
+
leftWidth: number,
|
|
59
|
+
rightWidth: number,
|
|
60
|
+
useTips: boolean,
|
|
61
|
+
) =>
|
|
62
|
+
Effect.sync(function () {
|
|
63
|
+
const paint = (s: string) => theme.fg("accent", s);
|
|
64
|
+
const muted = (s: string) => theme.fg("muted", s);
|
|
65
|
+
const dim = (s: string) => theme.fg("dim", s);
|
|
66
|
+
const bold = (s: string) => theme.bold(s);
|
|
67
|
+
|
|
68
|
+
const leftLines = [
|
|
69
|
+
...renderLogo(paint).map((line) => center(line, leftWidth)),
|
|
70
|
+
center(bold("Let's make some Pi(e)"), leftWidth),
|
|
71
|
+
center(
|
|
72
|
+
muted(
|
|
73
|
+
`${formatModelLabel(ctx.model)} · ${formatThinkingLabel(pi.getThinkingLevel())}`,
|
|
74
|
+
),
|
|
75
|
+
leftWidth,
|
|
76
|
+
),
|
|
77
|
+
center(dim(formatCwd(ctx.cwd)), leftWidth),
|
|
78
|
+
];
|
|
79
|
+
|
|
80
|
+
const tipDivider = paint("─".repeat(Math.max(8, Math.min(rightWidth, 22))));
|
|
81
|
+
const [cmd0 = "", cmd1 = "", cmd2 = "", cmd3 = ""] = tipCommands;
|
|
82
|
+
const tipLines = [
|
|
83
|
+
"",
|
|
84
|
+
paint(bold("Welcome")),
|
|
85
|
+
muted("Ask Pi anything"),
|
|
86
|
+
tipDivider,
|
|
87
|
+
paint(bold("Commands")),
|
|
88
|
+
muted(cmd0),
|
|
89
|
+
muted(cmd1),
|
|
90
|
+
muted(cmd2),
|
|
91
|
+
muted(cmd3),
|
|
92
|
+
"",
|
|
93
|
+
];
|
|
94
|
+
|
|
95
|
+
const rows: string[] = [];
|
|
96
|
+
for (let i = 0; i < leftLines.length; i++) {
|
|
97
|
+
const content = useTips
|
|
98
|
+
? twoColumn(leftLines[i] ?? "", tipLines[i] ?? "", leftWidth, rightWidth, paint)
|
|
99
|
+
: padRight(leftLines[i] ?? "", leftWidth);
|
|
100
|
+
rows.push(content);
|
|
101
|
+
}
|
|
102
|
+
return rows;
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const render = Effect.fn("HeaderRenderService.render")(function* (width: number) {
|
|
106
|
+
const theme = ctx.ui.theme; // per-render live read
|
|
107
|
+
const paint = (s: string) => theme.fg("accent", s);
|
|
108
|
+
|
|
109
|
+
if (width < 24) return [paint(`Pi v${VERSION}`)]; // short-circuit
|
|
110
|
+
|
|
111
|
+
const innerWidth = width - 2;
|
|
112
|
+
const { leftWidth, rightWidth, useTips } = headerColumnWidths(innerWidth);
|
|
113
|
+
const bodyLines = yield* renderBody(theme, innerWidth, leftWidth, rightWidth, useTips);
|
|
114
|
+
// The body component renders the precomputed column lines;
|
|
115
|
+
// makeBorderedBox pads them into the frame rails.
|
|
116
|
+
const body = defineComponent({
|
|
117
|
+
render: () => bodyLines,
|
|
118
|
+
invalidate: () => {},
|
|
119
|
+
});
|
|
120
|
+
return makeBorderedBox(body, theme, {
|
|
121
|
+
label: `${paint("Pi")} v${VERSION}`,
|
|
122
|
+
paddingX: 0,
|
|
123
|
+
}).render(width);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
return HeaderRenderService.of({ render });
|
|
127
|
+
}),
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Register the header widget with `ctx.ui.setHeader` and return a cleanup
|
|
134
|
+
* that unregisters it. The mount factory builds the service layer
|
|
135
|
+
* synchronously at mount (tips drawn once from `pi.getCommands()`),
|
|
136
|
+
* disposes the previous mount on re-mount, and hands pi a closure
|
|
137
|
+
* component whose `render` runs the service's render effect synchronously.
|
|
138
|
+
*/
|
|
139
|
+
export function installHeader(pi: ExtensionAPI, ctx: ExtensionContext): () => void {
|
|
140
|
+
let header: DisposableComponent | undefined;
|
|
141
|
+
ctx.ui.setHeader(() => {
|
|
142
|
+
// Re-mount: dispose the previous instance before building the new one.
|
|
143
|
+
if (header?.dispose) header.dispose();
|
|
144
|
+
// Build the service layer and run construction synchronously at mount.
|
|
145
|
+
const svc = Context.get(
|
|
146
|
+
Effect.runSync(
|
|
147
|
+
Effect.context<HeaderRenderService>().pipe(
|
|
148
|
+
Effect.provide(HeaderRenderService.make(pi, ctx)),
|
|
149
|
+
),
|
|
150
|
+
),
|
|
151
|
+
HeaderRenderService,
|
|
152
|
+
);
|
|
153
|
+
header = defineComponent({
|
|
154
|
+
render: (width: number) => Effect.runSync(svc.render(width)), // only sync run at the seam
|
|
155
|
+
invalidate: () => {},
|
|
156
|
+
dispose: () => {},
|
|
157
|
+
});
|
|
158
|
+
return header;
|
|
159
|
+
});
|
|
160
|
+
return () => {
|
|
161
|
+
if (header?.dispose) header.dispose();
|
|
162
|
+
header = undefined;
|
|
163
|
+
ctx.ui.setHeader(undefined);
|
|
164
|
+
};
|
|
165
|
+
}
|