@ftrdotdev/pi-tui 0.7.0 → 0.9.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 (76) hide show
  1. package/CHANGELOG.md +225 -0
  2. package/README.md +5 -0
  3. package/package.json +18 -15
  4. package/src/activity-service.test.ts +97 -0
  5. package/src/activity.test.ts +1 -1
  6. package/src/activity.ts +38 -0
  7. package/src/chrome/budget.test.ts +345 -0
  8. package/src/chrome/budget.ts +220 -0
  9. package/src/chrome/declarations.ts +303 -0
  10. package/src/chrome/facts.test.ts +165 -0
  11. package/src/chrome/facts.ts +267 -0
  12. package/src/chrome/frame.ts +45 -0
  13. package/src/chrome/laws.test.ts +231 -0
  14. package/src/chrome/port.test.ts +164 -0
  15. package/src/chrome/port.ts +67 -0
  16. package/src/chrome/service-provider.test.ts +383 -0
  17. package/src/chrome/service-provider.ts +55 -0
  18. package/src/commands/git-execution.test.ts +5 -2
  19. package/src/commands/git-execution.ts +27 -15
  20. package/src/commands/git-status.test.ts +47 -15
  21. package/src/commands/git-status.ts +83 -31
  22. package/src/components/bordered-box.test.ts +12 -15
  23. package/src/components/bordered-box.ts +11 -7
  24. package/src/components/define-component.ts +1 -1
  25. package/src/components/index.ts +7 -0
  26. package/src/components/row-list.test.ts +310 -0
  27. package/src/components/row-list.ts +272 -0
  28. package/src/config.test.ts +118 -3
  29. package/src/config.ts +50 -42
  30. package/src/frame/box-frame.test.ts +53 -7
  31. package/src/harness-policy.test.ts +47 -0
  32. package/src/icons.test.ts +19 -0
  33. package/src/icons.ts +50 -31
  34. package/src/index.test.ts +135 -0
  35. package/src/index.ts +118 -119
  36. package/src/layers.test.ts +94 -0
  37. package/src/layers.ts +92 -0
  38. package/src/runtime-service.test.ts +218 -0
  39. package/src/runtime-service.ts +103 -0
  40. package/src/runtime.test.ts +165 -66
  41. package/src/runtime.ts +127 -93
  42. package/src/session-lifecycle-service.test.ts +95 -0
  43. package/src/session-lifecycle.test.ts +77 -0
  44. package/src/session-lifecycle.ts +21 -0
  45. package/src/state.test.ts +132 -3
  46. package/src/state.ts +43 -13
  47. package/src/telemetry-service.test.ts +250 -0
  48. package/src/telemetry.test.ts +322 -0
  49. package/src/telemetry.ts +130 -23
  50. package/src/ui/editor-tint.test.ts +58 -45
  51. package/src/ui/editor-tint.ts +1 -1
  52. package/src/ui/editor.ts +117 -53
  53. package/src/ui/footer.test.ts +349 -120
  54. package/src/ui/footer.ts +147 -124
  55. package/src/ui/header.test.ts +203 -223
  56. package/src/ui/header.ts +32 -96
  57. package/src/ui/preview.test.ts +73 -70
  58. package/src/ui/preview.ts +48 -33
  59. package/src/ui/render-helpers.test.ts +82 -13
  60. package/src/ui/render-helpers.ts +110 -122
  61. package/src/ui/settings-command.test.ts +70 -11
  62. package/src/ui/settings-command.ts +30 -45
  63. package/src/ui/theme-color.test.ts +4 -3
  64. package/src/usage-totals-service.test.ts +230 -0
  65. package/src/usage-totals-service.ts +59 -0
  66. package/src/utils.test.ts +46 -50
  67. package/src/utils.ts +41 -239
  68. package/src/vim/editor-host.test.ts +201 -75
  69. package/src/vim/editor-state.ts +2 -2
  70. package/src/vim/mode-indicator.test.ts +6 -5
  71. package/src/vim/mode-indicator.ts +13 -9
  72. package/src/vim/selection-render.ts +8 -4
  73. package/src/vim/text-model.test.ts +52 -14
  74. package/src/vim/text-model.ts +1 -1
  75. package/src/vim/vim-router.test.ts +3 -0
  76. package/src/vim/vim-router.ts +1 -1
@@ -1,138 +1,114 @@
1
- import { assert, it } from "@effect/vitest";
2
- import { vi } from "vitest";
3
- import { Effect, Random } from "effect";
1
+ // Each test is its own entry point: it builds a fresh layer for one scenario and
2
+ // runs its effects inside it, so providing there is the pattern the rule allows.
3
+ /* oxlint-disable effecttsgo/strict-effect-provide */
4
+ import { assert, it, vi } from "@effect/vitest";
5
+ import { themeDouble } from "@ftrdotdev/pi-test-kit";
6
+ import { headerCtxDouble, stubChromePort } from "../../test-support/doubles.ts";
7
+ import { Effect } from "effect";
4
8
  import { VERSION, type Theme } from "@earendil-works/pi-coding-agent";
9
+ import { visibleWidth } from "@earendil-works/pi-tui";
10
+ import type { ChromePort } from "../chrome/port.ts";
5
11
  import { HeaderRenderService, installHeader, resetScreenClearMemory } from "./header.ts";
6
12
 
7
- // Pixel parity: the header must render byte-identically through makeBorderedBox
8
- // as it did with its hand-rolled box (captured before the refactor). The tips
9
- // shuffle draws from Effect's Random service, so every construction in this
10
- // file runs under a fixed seed to keep the tips cells — and therefore the
11
- // frozen tables — deterministic.
12
- const plainTheme = {
13
- fg: (_color: string, text: string) => text,
14
- bg: (_color: string, text: string) => text,
15
- bold: (text: string) => `*${text}*`,
16
- style: (text: string) => text,
17
- } as unknown as Theme;
13
+ // Pixel parity: the header renders byte-identically through makeBorderedBox.
14
+ // The header is deterministic (no Random draw, no tips panel), so the table
15
+ // needs no seed.
16
+ const plainTheme = themeDouble({ bold: (text) => `*${text}*` });
18
17
 
19
- const pi = {
20
- getCommands: () => [
21
- { name: "tui" },
22
- { name: "settings" },
23
- { name: "model" },
24
- { name: "preview" },
25
- ],
26
- getThinkingLevel: () => "off",
27
- } as never;
18
+ const REAL_PROCESS = process;
19
+ const REAL_STDOUT = process.stdout;
20
+ const REAL_IS_TTY = Object.getOwnPropertyDescriptor(process.stdout, "isTTY");
28
21
 
29
- const ctx = {
30
- model: { provider: "anthropic", id: "claude-sonnet-4" },
31
- cwd: "/projects/pi-mono/packages/tui",
32
- ui: { theme: plainTheme },
33
- } as never;
22
+ /** A port whose only meaningful fact for the header is its theme. */
23
+ const headerPort = (theme: Theme): ChromePort => stubChromePort({ theme: () => theme });
34
24
 
35
- const TIPS_SEED = "pixel-parity";
25
+ const WIDTHS = [24, 30, 40, 60, 80, 100, 120];
26
+ const FROZEN_VERSION = "v1.5.0";
36
27
 
37
28
  const EXPECTED: Record<string, string[]> = {
38
- 20: ["Pi v0.84.4"],
39
29
  24: [
40
- "\u256d\u2500\u2500\u2500 Pi v0.84.4 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256e",
41
- "\u2502 \u2502",
42
- "\u2502 \u2502",
43
- "\u2502 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2502",
44
- "\u2502 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2502",
45
- "\u2502 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588 \u2502",
46
- "\u2502 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2502",
47
- "\u2502 \u2502",
48
- "\u2502*Let's make some Pi\u001b[0m...\u001b[0m\u2502",
49
- "\u2502anthropic/claude-so\u001b[0m...\u001b[0m\u2502",
50
- "\u2502/projects/pi-mono/p\u001b[0m...\u001b[0m\u2502",
51
- "\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f",
30
+ "╭─── Pi v1.5.0 ────────╮",
31
+ "│ │",
32
+ "│ │",
33
+ "│ █████████ │",
34
+ "│ ███ ███ │",
35
+ "│ ██████ ███ │",
36
+ "│ ███ ███ │",
37
+ "│ │",
38
+ "│*Let's make some Pi\u001b[0m...\u001b[0m│",
39
+ "╰──────────────────────╯",
52
40
  ],
53
41
  30: [
54
- "\u256d\u2500\u2500\u2500 Pi v0.84.4 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256e",
55
- "\u2502 \u2502",
56
- "\u2502 \u2502",
57
- "\u2502 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2502",
58
- "\u2502 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2502",
59
- "\u2502 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588 \u2502",
60
- "\u2502 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2502",
61
- "\u2502 \u2502",
62
- "\u2502 *Let's make some Pi(e)* \u2502",
63
- "\u2502anthropic/claude-sonnet-4\u001b[0m...\u001b[0m\u2502",
64
- "\u2502/projects/pi-mono/package\u001b[0m...\u001b[0m\u2502",
65
- "\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",
42
+ "╭─── Pi v1.5.0 ──────────────╮",
43
+ "│ │",
44
+ "│ │",
45
+ "│ █████████ │",
46
+ "│ ███ ███ │",
47
+ "│ ██████ ███ │",
48
+ "│ ███ ███ │",
49
+ "│ │",
50
+ "│ *Let's make some Pi(e)* │",
51
+ "╰────────────────────────────╯",
66
52
  ],
67
53
  40: [
68
- "\u256d\u2500\u2500\u2500 Pi v0.84.4 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256e",
69
- "\u2502 \u2502",
70
- "\u2502 \u2502",
71
- "\u2502 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2502",
72
- "\u2502 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2502",
73
- "\u2502 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588 \u2502",
74
- "\u2502 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2502",
75
- "\u2502 \u2502",
76
- "\u2502 *Let's make some Pi(e)* \u2502",
77
- "\u2502anthropic/claude-sonnet-4 \u00b7 thinkin\u001b[0m...\u001b[0m\u2502",
78
- "\u2502 /projects/pi-mono/packages/tui \u2502",
79
- "\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",
54
+ "╭─── Pi v1.5.0 ────────────────────────╮",
55
+ "│ │",
56
+ "│ │",
57
+ "│ █████████ │",
58
+ "│ ███ ███ │",
59
+ "│ ██████ ███ │",
60
+ "│ ███ ███ │",
61
+ "│ │",
62
+ "│ *Let's make some Pi(e)* │",
63
+ "╰──────────────────────────────────────╯",
80
64
  ],
81
65
  60: [
82
- "\u256d\u2500\u2500\u2500 Pi v0.84.4 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\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",
83
- "\u2502 \u2502 \u2502",
84
- "\u2502 \u2502 *Welcome* \u2502",
85
- "\u2502 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2502 Ask Pi anything \u2502",
86
- "\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",
87
- "\u2502 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588 \u2502 *Commands* \u2502",
88
- "\u2502 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2502 /tui \u2502",
89
- "\u2502 \u2502 /copy \u2502",
90
- "\u2502 *Let's make some Pi(e)* \u2502 /logout \u2502",
91
- "\u2502anthropic/claude-sonnet-4 \u00b7 thinking\u001b[0m...\u001b[0m \u2502 /scoped-models \u2502",
92
- "\u2502 /projects/pi-mono/packages/tui \u2502 \u2502",
93
- "\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",
66
+ "╭─── Pi v1.5.0 ────────────────────────────────────────────╮",
67
+ "│ │",
68
+ "│ │",
69
+ "│ █████████ │",
70
+ "│ ███ ███ │",
71
+ "│ ██████ ███ │",
72
+ "│ ███ ███ │",
73
+ "│ │",
74
+ "│ *Let's make some Pi(e)* │",
75
+ "╰──────────────────────────────────────────────────────────╯",
94
76
  ],
95
77
  80: [
96
- "\u256d\u2500\u2500\u2500 Pi v0.84.4 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\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",
97
- "\u2502 \u2502 \u2502",
98
- "\u2502 \u2502 *Welcome* \u2502",
99
- "\u2502 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2502 Ask Pi anything \u2502",
100
- "\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",
101
- "\u2502 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588 \u2502 *Commands* \u2502",
102
- "\u2502 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2502 /tui \u2502",
103
- "\u2502 \u2502 /copy \u2502",
104
- "\u2502 *Let's make some Pi(e)* \u2502 /logout \u2502",
105
- "\u2502 anthropic/claude-sonnet-4 \u00b7 thinking off \u2502 /scoped-models \u2502",
106
- "\u2502 /projects/pi-mono/packages/tui \u2502 \u2502",
107
- "\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",
78
+ "╭─── Pi v1.5.0 ────────────────────────────────────────────────────────────────╮",
79
+ "│ │",
80
+ "│ │",
81
+ "│ █████████ │",
82
+ "│ ███ ███ │",
83
+ "│ ██████ ███ │",
84
+ "│ ███ ███ │",
85
+ "│ │",
86
+ "│ *Let's make some Pi(e)* │",
87
+ "╰──────────────────────────────────────────────────────────────────────────────╯",
108
88
  ],
109
89
  100: [
110
- "\u256d\u2500\u2500\u2500 Pi v0.84.4 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\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",
111
- "\u2502 \u2502 \u2502",
112
- "\u2502 \u2502 *Welcome* \u2502",
113
- "\u2502 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2502 Ask Pi anything \u2502",
114
- "\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",
115
- "\u2502 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588 \u2502 *Commands* \u2502",
116
- "\u2502 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2502 /tui \u2502",
117
- "\u2502 \u2502 /copy \u2502",
118
- "\u2502 *Let's make some Pi(e)* \u2502 /logout \u2502",
119
- "\u2502 anthropic/claude-sonnet-4 \u00b7 thinking off \u2502 /scoped-models \u2502",
120
- "\u2502 /projects/pi-mono/packages/tui \u2502 \u2502",
121
- "\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",
90
+ "╭─── Pi v1.5.0 ────────────────────────────────────────────────────────────────────────────────────╮",
91
+ "│ │",
92
+ "│ │",
93
+ "│ █████████ │",
94
+ "│ ███ ███ │",
95
+ "│ ██████ ███ │",
96
+ "│ ███ ███ │",
97
+ "│ │",
98
+ "│ *Let's make some Pi(e)* │",
99
+ "╰──────────────────────────────────────────────────────────────────────────────────────────────────╯",
122
100
  ],
123
101
  120: [
124
- "\u256d\u2500\u2500\u2500 Pi v0.84.4 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\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",
125
- "\u2502 \u2502 \u2502",
126
- "\u2502 \u2502 *Welcome* \u2502",
127
- "\u2502 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2502 Ask Pi anything \u2502",
128
- "\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",
129
- "\u2502 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588 \u2502 *Commands* \u2502",
130
- "\u2502 \u2588\u2588\u2588 \u2588\u2588\u2588 \u2502 /tui \u2502",
131
- "\u2502 \u2502 /copy \u2502",
132
- "\u2502 *Let's make some Pi(e)* \u2502 /logout \u2502",
133
- "\u2502 anthropic/claude-sonnet-4 \u00b7 thinking off \u2502 /scoped-models \u2502",
134
- "\u2502 /projects/pi-mono/packages/tui \u2502 \u2502",
135
- "\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",
102
+ "╭─── Pi v1.5.0 ────────────────────────────────────────────────────────────────────────────────────────────────────────╮",
103
+ "│ │",
104
+ "│ │",
105
+ "│ █████████ │",
106
+ "│ ███ ███ │",
107
+ "│ ██████ ███ │",
108
+ "│ ███ ███ │",
109
+ "│ │",
110
+ "│ *Let's make some Pi(e)* │",
111
+ "╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯",
136
112
  ],
137
113
  };
138
114
 
@@ -140,7 +116,6 @@ const EXPECTED: Record<string, string[]> = {
140
116
  // dependency bump does not break pixel parity. A version of a different length
141
117
  // changes the top-border padding, so restore each boxed row to its frozen width
142
118
  // by adding or removing trailing dashes before the closing corner.
143
- const FROZEN_VERSION = "v0.84.4";
144
119
  for (const [width, lines] of Object.entries(EXPECTED)) {
145
120
  EXPECTED[width] = lines.map((line) => {
146
121
  if (!line.includes(FROZEN_VERSION)) return line;
@@ -152,85 +127,87 @@ for (const [width, lines] of Object.entries(EXPECTED)) {
152
127
  });
153
128
  }
154
129
 
155
- // Render one width through the service layer entry under the fixed seed.
156
- const renderHeader = (width: number) =>
157
- Effect.runSync(
130
+ for (const width of WIDTHS) {
131
+ it.effect(`renders the boxed header identically at width ${width}`, () =>
158
132
  Effect.gen(function* () {
159
133
  const svc = yield* HeaderRenderService;
160
- return yield* svc.render(width);
161
- })
162
- .pipe(Effect.provide(HeaderRenderService.make(pi, ctx)))
163
- .pipe(Random.withSeed(TIPS_SEED)),
134
+ const rendered = yield* svc.render(width);
135
+ assert.deepStrictEqual(rendered, EXPECTED[String(width)]);
136
+ }).pipe(Effect.provide(HeaderRenderService.make(headerPort(plainTheme)))),
164
137
  );
165
-
166
- for (const width of Object.keys(EXPECTED)) {
167
- it(`renders the boxed header identically at width ${width}`, () => {
168
- assert.deepStrictEqual(renderHeader(Number(width)), EXPECTED[width]);
169
- });
170
138
  }
171
139
 
172
- it("header tips are fixed at service build while live inputs are re-read per run", () => {
173
- let thinking = "off";
174
- const mutablePi = {
175
- getCommands: () => [
176
- { name: "tui" },
177
- { name: "settings" },
178
- { name: "model" },
179
- { name: "preview" },
180
- ],
181
- getThinkingLevel: () => thinking,
182
- } as never;
183
- const mutableCtx = {
184
- model: { provider: "anthropic", id: "claude-sonnet-4" },
185
- cwd: "/projects/pi-mono/packages/tui",
186
- ui: { theme: plainTheme },
187
- } as never;
140
+ it.effect("the header renders no fact other than its version", () =>
141
+ Effect.gen(function* () {
142
+ // Arrange: the layer with a model name and a cwd the footer owns.
143
+ const svc = yield* HeaderRenderService;
144
+
145
+ // Act: render at 80.
146
+ const lines = yield* svc.render(80);
147
+ const joined = lines.join("\n");
188
148
 
189
- const layer = HeaderRenderService.make(mutablePi, mutableCtx);
190
- const render = (width: number) =>
191
- Effect.runSync(
192
- Effect.gen(function* () {
193
- const svc = yield* HeaderRenderService;
194
- return yield* svc.render(width);
195
- })
196
- .pipe(Effect.provide(layer))
197
- .pipe(Random.withSeed(TIPS_SEED)),
198
- );
149
+ // Assert: none of the footer's facts appear, and the version does.
150
+ assert.ok(!joined.includes("anthropic"));
151
+ assert.ok(!joined.includes("claude-sonnet-4"));
152
+ assert.ok(!joined.includes("/projects/pi-mono"));
153
+ assert.ok(!joined.includes("thinking"));
154
+ assert.ok(!joined.includes("/scoped-models"));
155
+ assert.ok(joined.includes(`Pi v${VERSION}`));
156
+ }).pipe(Effect.provide(HeaderRenderService.make(headerPort(plainTheme)))),
157
+ );
199
158
 
200
- const first = render(60);
201
- thinking = "high";
202
- (mutableCtx as { cwd: string }).cwd = "/workspace/elsewhere";
203
- const second = render(60);
159
+ it.effect("the header renders from the port's theme", () => {
160
+ // Arrange: a marker theme that labels accent and bold text.
161
+ const markerTheme = themeDouble({
162
+ fg: (color, text) => `${color}:${text}`,
163
+ bold: (text) => `*${text}*`,
164
+ });
165
+
166
+ return Effect.gen(function* () {
167
+ const svc = yield* HeaderRenderService;
204
168
 
205
- // The tips cells (everything after the column separator) are frozen at
206
- // service build: identical across both runs, including the four slash
207
- // commands. The left cells re-read live inputs per run.
208
- // Row shape: rail │ LEFT cell │ tips cell │ rail — the tips cell is the
209
- // second split part after the rail-separated LEFT cell.
210
- const tipsCells = (lines: string[]) =>
211
- lines.map((line) => {
212
- const parts = line.split("│");
213
- const cell = parts.length >= 3 ? parts[2] : undefined;
214
- return cell?.trim() ?? "";
215
- });
216
- assert.deepStrictEqual(tipsCells(second), tipsCells(first));
217
- assert.deepStrictEqual(tipsCells(first).slice(6, 10), [
218
- "/tui",
219
- "/copy",
220
- "/logout",
221
- "/scoped-models",
222
- ]);
169
+ // Act: render at 60.
170
+ const lines = yield* svc.render(60);
223
171
 
224
- // Live re-reads per run: the model/thinking row (index 9) and the cwd row
225
- // (index 10) change when the fake live inputs change.
226
- assert.notStrictEqual(second[9], first[9]);
227
- assert.notStrictEqual(second[10], first[10]);
172
+ // Assert: the title carries the port theme's bold marker; the footer's
173
+ // model fact stays absent.
174
+ assert.ok(lines[8]!.includes("*Let's make some Pi(e)*"));
175
+ assert.ok(lines[0]!.includes("accent:"));
176
+ assert.ok(!lines.join("\n").includes("anthropic"));
177
+ }).pipe(Effect.provide(HeaderRenderService.make(headerPort(markerTheme))));
228
178
  });
229
179
 
180
+ it.effect("the header box is 10 rows at every width at or above 24", () =>
181
+ Effect.gen(function* () {
182
+ const svc = yield* HeaderRenderService;
183
+
184
+ for (const width of WIDTHS) {
185
+ if (width < 24) continue;
186
+ const lines = yield* svc.render(width);
187
+ assert.strictEqual(lines.length, 10, `width ${width}: row count`);
188
+ assert.ok(lines[0]!.startsWith("╭─"), `width ${width}: top border`);
189
+ assert.ok(lines[0]!.includes(`Pi v${VERSION}`), `width ${width}: version label`);
190
+ assert.ok(lines[lines.length - 1]!.startsWith("\u2570"), `width ${width}: bottom border`);
191
+ for (const line of lines) {
192
+ assert.strictEqual(visibleWidth(line), width, `width ${width}: line width`);
193
+ }
194
+ }
195
+ }).pipe(Effect.provide(HeaderRenderService.make(headerPort(plainTheme)))),
196
+ );
197
+
198
+ it.effect("the header is deterministic without a seed", () =>
199
+ Effect.gen(function* () {
200
+ const svc = yield* HeaderRenderService;
201
+ const first = yield* svc.render(80);
202
+ const second = yield* svc.render(80);
203
+ assert.deepStrictEqual(first, second);
204
+ }).pipe(Effect.provide(HeaderRenderService.make(headerPort(plainTheme)))),
205
+ );
206
+
230
207
  it("installHeader registers a closure component at mount and unregisters on cleanup", () => {
231
208
  let captured: ((tui: unknown, theme: unknown) => unknown) | undefined;
232
209
  let unregistered = false;
233
- const mountCtx = {
210
+ const mountCtx = headerCtxDouble({
234
211
  model: { provider: "anthropic", id: "claude-sonnet-4" },
235
212
  cwd: "/projects/pi-mono/packages/tui",
236
213
  ui: {
@@ -240,9 +217,9 @@ it("installHeader registers a closure component at mount and unregisters on clea
240
217
  if (factory === undefined) unregistered = true;
241
218
  },
242
219
  },
243
- } as never;
220
+ });
244
221
 
245
- const cleanup = installHeader(pi, mountCtx);
222
+ const cleanup = installHeader(mountCtx, headerPort(plainTheme));
246
223
 
247
224
  assert.strictEqual(typeof captured, "function");
248
225
  const componentA = captured!({ mode: "fullscreen" }, plainTheme) as {
@@ -250,27 +227,16 @@ it("installHeader registers a closure component at mount and unregisters on clea
250
227
  };
251
228
  const linesA = componentA.render(80);
252
229
 
253
- // Re-mount swaps the slot to a fresh component; both render the header.
230
+ // Re-mount swaps the slot to a fresh component; both render the same box.
254
231
  const componentB = captured!({ mode: "fullscreen" }, plainTheme) as {
255
232
  render: (width: number) => string[];
256
233
  };
257
234
  assert.notStrictEqual(componentA, componentB);
258
235
  const linesB = componentB.render(80);
259
236
 
260
- // The seam uses the ambient Random service for the tips shuffle, so only
261
- // the tips cells of rows 6-9 are non-deterministic. Everything else must be
262
- // byte-identical to the frozen table: borders, logo rows, title, and the
263
- // empty rail rows.
264
- const expected80 = EXPECTED[80]!;
265
- for (const [label, lines] of [
266
- ["first mount", linesA],
267
- ["remount", linesB],
268
- ] as const) {
269
- assert.strictEqual(lines.length, expected80.length, `${label}: line count`);
270
- for (const i of [0, 1, 2, 3, 4, 5, 10, 11]) {
271
- assert.deepStrictEqual(lines[i], expected80[i], `${label}: row ${i}`);
272
- }
273
- }
237
+ // The seam is deterministic: the remount renders the frozen table exactly.
238
+ assert.deepStrictEqual(linesA, EXPECTED[80]);
239
+ assert.deepStrictEqual(linesB, EXPECTED[80]);
274
240
 
275
241
  cleanup();
276
242
  assert.strictEqual(unregistered, true);
@@ -281,7 +247,7 @@ it("installHeader registers a closure component at mount and unregisters on clea
281
247
  const captureMountCtx = (
282
248
  onFactory: (factory: ((tui: unknown, theme: unknown) => unknown) | undefined) => void,
283
249
  ) =>
284
- ({
250
+ headerCtxDouble({
285
251
  model: { provider: "anthropic", id: "claude-sonnet-4" },
286
252
  cwd: "/projects/pi-mono/packages/tui",
287
253
  ui: {
@@ -290,34 +256,48 @@ const captureMountCtx = (
290
256
  onFactory(factory);
291
257
  },
292
258
  },
293
- }) as never;
259
+ });
294
260
 
295
261
  it("clears the screen once per process, and only in regular mode", () => {
296
- const originalIsTTY = process.stdout.isTTY;
297
- Object.defineProperty(process.stdout, "isTTY", { value: true, configurable: true });
298
- const write = vi.spyOn(process.stdout, "write").mockImplementation(() => true);
299
- try {
300
- resetScreenClearMemory();
301
- let captured: ((tui: unknown, theme: unknown) => unknown) | undefined;
302
- const mountCtx = captureMountCtx((factory) => {
303
- captured = factory;
304
- });
262
+ const written: unknown[] = [];
263
+ const fakeStdout = {
264
+ isTTY: true,
265
+ write: (chunk: unknown) => {
266
+ written.push(chunk);
267
+ return true;
268
+ },
269
+ };
270
+ vi.stubGlobal(
271
+ "process",
272
+ Object.create(process, { stdout: { value: fakeStdout, configurable: true } }),
273
+ );
305
274
 
306
- installHeader(pi, mountCtx);
307
- captured!({ mode: "fullscreen" }, plainTheme);
308
- assert.strictEqual(write.mock.calls.length, 0, "fullscreen must not clear");
275
+ resetScreenClearMemory();
276
+ let captured: ((tui: unknown, theme: unknown) => unknown) | undefined;
277
+ const mountCtx = captureMountCtx((factory) => {
278
+ captured = factory;
279
+ });
280
+
281
+ installHeader(mountCtx, headerPort(plainTheme));
282
+ captured!({ mode: "fullscreen" }, plainTheme);
283
+ assert.strictEqual(written.length, 0, "fullscreen must not clear");
309
284
 
310
- captured!({ mode: "regular" }, plainTheme);
311
- assert.deepStrictEqual(write.mock.calls[0]?.[0], "\x1b[2J\x1b[H");
285
+ captured!({ mode: "regular" }, plainTheme);
286
+ assert.deepStrictEqual(written[0], "\x1b[2J\x1b[H");
287
+
288
+ // A reload re-mounts in regular mode while pi-tui still holds the
289
+ // previous lines. The once guard must keep it from writing escape codes
290
+ // behind the renderer's back (the blank-widget regression).
291
+ captured!({ mode: "regular" }, plainTheme);
292
+ assert.strictEqual(written.length, 1, "re-mount must not clear again");
293
+
294
+ resetScreenClearMemory();
295
+ });
312
296
 
313
- // A reload re-mounts in regular mode while pi-tui still holds the
314
- // previous lines. The once guard must keep it from writing escape codes
315
- // behind the renderer's back (the blank-widget regression).
316
- captured!({ mode: "regular" }, plainTheme);
317
- assert.strictEqual(write.mock.calls.length, 1, "re-mount must not clear again");
318
- } finally {
319
- write.mockRestore();
320
- Object.defineProperty(process.stdout, "isTTY", { value: originalIsTTY, configurable: true });
321
- resetScreenClearMemory();
322
- }
297
+ it("the faked terminal does not outlive the test that made it", () => {
298
+ assert.strictEqual(process, REAL_PROCESS);
299
+ assert.strictEqual(process.stdout, REAL_STDOUT);
300
+ assert.deepStrictEqual(Object.getOwnPropertyDescriptor(process.stdout, "isTTY"), REAL_IS_TTY);
301
+ // oxlint-disable-next-line typescript/unbound-method -- identity check only.
302
+ assert.strictEqual(vi.isMockFunction(process.stdout.write), false);
323
303
  });