@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,10 +1,16 @@
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 */
1
4
  import { assert, it } from "@effect/vitest";
5
+ import { PROPERTY_RUNS } from "@ftrdotdev/pi-test-kit";
2
6
  import { Effect, PlatformError, Schema } from "effect";
3
7
  import * as FileSystem from "effect/FileSystem";
4
8
  import * as NodeFileSystem from "@effect/platform-node/NodeFileSystem";
5
9
  import { join } from "node:path";
6
10
  import { fileURLToPath } from "node:url";
7
11
  import { getAgentDir } from "@earendil-works/pi-coding-agent";
12
+ import { configArbitrary } from "../test-support/generators.ts";
13
+ import { FACTS, type FactRecord } from "./chrome/facts.ts";
8
14
  import {
9
15
  adjustSmartCompactionProbability,
10
16
  adjustMaxCandidates,
@@ -22,6 +28,93 @@ import {
22
28
 
23
29
  const TEST_PATH = "/tmp/tui-test/tui.json";
24
30
 
31
+ it("the defaults are the registry's defaults", () => {
32
+ // Arrange: the registry-derived expected values. Each mapping is explicit
33
+ // because the flag name and the fact key are not always the same.
34
+ const fromRegistry = {
35
+ footerSegments: {
36
+ cwd: FACTS.cwd.defaultEnabled,
37
+ gitBranch: FACTS.gitBranch.defaultEnabled,
38
+ gitStatus: FACTS.gitStatus.defaultEnabled,
39
+ gitCommit: FACTS.gitCommit.defaultEnabled,
40
+ runtime: FACTS.runtime.defaultEnabled,
41
+ context: FACTS.contextOccupancy.defaultEnabled,
42
+ tokens: FACTS.tokenCounts.defaultEnabled,
43
+ cost: FACTS.cost.defaultEnabled,
44
+ extensionStatuses: FACTS.extensionStatuses.defaultEnabled,
45
+ },
46
+ telemetry: {
47
+ enabled: true,
48
+ tps: FACTS.turnTps.defaultEnabled,
49
+ ttft: FACTS.turnTtft.defaultEnabled,
50
+ duration: FACTS.turnDuration.defaultEnabled,
51
+ tokens: FACTS.turnTokens.defaultEnabled,
52
+ stalls: FACTS.turnStalls.defaultEnabled,
53
+ cost: FACTS.turnCostRate.defaultEnabled,
54
+ },
55
+ };
56
+
57
+ // Assert: the live defaults come from the registry, and the quiet default
58
+ // is the literal set the design names.
59
+ assert.deepStrictEqual(DEFAULT_CONFIG.footerSegments, fromRegistry.footerSegments);
60
+ assert.deepStrictEqual(DEFAULT_CONFIG.telemetry, fromRegistry.telemetry);
61
+ assert.deepStrictEqual(DEFAULT_CONFIG.footerSegments, {
62
+ cwd: true,
63
+ gitBranch: true,
64
+ gitStatus: true,
65
+ gitCommit: false,
66
+ runtime: false,
67
+ context: true,
68
+ tokens: true,
69
+ cost: true,
70
+ extensionStatuses: true,
71
+ });
72
+ assert.deepStrictEqual(DEFAULT_CONFIG.telemetry, {
73
+ enabled: true,
74
+ tps: true,
75
+ ttft: true,
76
+ duration: false,
77
+ tokens: false,
78
+ stalls: true,
79
+ cost: false,
80
+ });
81
+ // The same defaults arrive through the partial-file funnel.
82
+ assert.deepStrictEqual(applyDefaults({}).footerSegments, DEFAULT_CONFIG.footerSegments);
83
+ assert.deepStrictEqual(applyDefaults({}).telemetry, DEFAULT_CONFIG.telemetry);
84
+ });
85
+
86
+ it("every registry key exists in the schema and every schema flag maps to a fact", () => {
87
+ // Arrange: the decoded config and the registry's keyed facts.
88
+ const decoded = Schema.decodeSync(TuiConfig)(DEFAULT_CONFIG);
89
+ const facts: readonly FactRecord[] = Object.values(FACTS);
90
+ const registryKeys = facts.flatMap((fact) => (fact.key === undefined ? [] : [fact.key]));
91
+
92
+ // Assert: every registry key resolves in the decoded config.
93
+ for (const key of registryKeys) {
94
+ const container = key.startsWith("footerSegments.")
95
+ ? decoded.footerSegments
96
+ : decoded.telemetry;
97
+ const flag = key.slice(key.indexOf(".") + 1);
98
+ assert.strictEqual(typeof (container as Record<string, unknown>)[flag], "boolean", key);
99
+ }
100
+
101
+ // Assert: every section flag (except the surface switch) has exactly one fact.
102
+ const sections = [
103
+ { name: "footerSegments", flags: Object.keys(decoded.footerSegments) },
104
+ {
105
+ name: "telemetry",
106
+ flags: Object.keys(decoded.telemetry).filter((flag) => flag !== "enabled"),
107
+ },
108
+ ] as const;
109
+ for (const section of sections) {
110
+ for (const flag of section.flags) {
111
+ const key = `${section.name}.${flag}`;
112
+ const owners = registryKeys.filter((candidate) => candidate === key);
113
+ assert.strictEqual(owners.length, 1, `${key}: expected one fact owner, got ${owners.length}`);
114
+ }
115
+ }
116
+ });
117
+
25
118
  interface MemFs {
26
119
  readonly fs: Partial<FileSystem.FileSystem>;
27
120
  readonly files: Map<string, string>;
@@ -52,7 +145,7 @@ function makeMemFs(init: Record<string, string> = {}, dirs: ReadonlyArray<string
52
145
  }),
53
146
  makeDirectory: (path, options) =>
54
147
  Effect.sync(() => {
55
- if (options?.recursive) {
148
+ if (options?.recursive ?? false) {
56
149
  let current = path;
57
150
  while (current !== "/" && current !== ".") {
58
151
  dirSet.add(current);
@@ -462,13 +555,13 @@ it("applyDefaults fills in every field from a partial file", () => {
462
555
  });
463
556
 
464
557
  it("ConfigParseError carries the expected tag", () => {
465
- const err = new ConfigParseError({ path: "x", message: "bad" });
558
+ const err = ConfigParseError.make({ path: "x", message: "bad" });
466
559
  assert.strictEqual(err._tag, "ConfigParseError");
467
560
  assert.instanceOf(err, ConfigParseError);
468
561
  });
469
562
 
470
563
  it("ConfigWriteError carries the expected tag", () => {
471
- const err = new ConfigWriteError({ path: "x", message: "bad" });
564
+ const err = ConfigWriteError.make({ path: "x", message: "bad" });
472
565
  assert.strictEqual(err._tag, "ConfigWriteError");
473
566
  assert.instanceOf(err, ConfigWriteError);
474
567
  });
@@ -633,3 +726,25 @@ it.effect("save keeps a chosen classifier through a load round trip", () =>
633
726
  });
634
727
  }),
635
728
  );
729
+
730
+ it.prop(
731
+ "a config survives decode after encode",
732
+ { config: configArbitrary },
733
+ ({ config }) => {
734
+ const once = encodeConfig(config);
735
+ assert.deepStrictEqual(
736
+ JSON.parse(JSON.stringify(encodeConfig(decodeConfig(once)))),
737
+ JSON.parse(JSON.stringify(once)),
738
+ );
739
+ },
740
+ { arbitrary: { runs: PROPERTY_RUNS } },
741
+ );
742
+
743
+ it.prop(
744
+ "defaulting a decoded encoded config reproduces it",
745
+ { config: configArbitrary },
746
+ ({ config }) => {
747
+ assert.deepStrictEqual(applyDefaults(decodeConfig(encodeConfig(config))), config);
748
+ },
749
+ { arbitrary: { runs: PROPERTY_RUNS } },
750
+ );
package/src/config.ts CHANGED
@@ -3,6 +3,7 @@ import { getAgentDir } from "@earendil-works/pi-coding-agent";
3
3
  import { Context, Effect, Layer, Schema } from "effect";
4
4
  import * as FileSystem from "effect/FileSystem";
5
5
  import * as PlatformError from "effect/PlatformError";
6
+ import { FACTS } from "./chrome/facts.ts";
6
7
  export type { IconMode } from "./icons.ts";
7
8
 
8
9
  export type SettingsLanguage = "en";
@@ -12,7 +13,7 @@ const CONFIG_FILE_NAME = "tui.json";
12
13
  const IconModeSchema = Schema.Literals(["auto", "nerd", "ascii"] as const);
13
14
  const SettingsLanguageSchema = Schema.Literals(["en"] as const);
14
15
 
15
- export class TuiConfig extends Schema.Class<TuiConfig>("tui/config/TuiConfig")({
16
+ export const TuiConfig = Schema.Struct({
16
17
  enabled: Schema.Boolean,
17
18
  settingsLanguage: SettingsLanguageSchema,
18
19
  vim: Schema.Boolean,
@@ -40,11 +41,13 @@ export class TuiConfig extends Schema.Class<TuiConfig>("tui/config/TuiConfig")({
40
41
  smartCompaction: Schema.Struct({
41
42
  enabled: Schema.Boolean,
42
43
  classifier: Schema.NullOr(Schema.String),
43
- needsContextProbabilityThreshold: Schema.Number,
44
- minAnswerConfidence: Schema.Number,
45
- maxCandidates: Schema.Number,
44
+ needsContextProbabilityThreshold: Schema.Finite,
45
+ minAnswerConfidence: Schema.Finite,
46
+ maxCandidates: Schema.Finite,
46
47
  }),
47
- }) {}
48
+ });
49
+
50
+ export type TuiConfig = typeof TuiConfig.Type;
48
51
 
49
52
  export type TelemetryConfig = TuiConfig["telemetry"];
50
53
 
@@ -54,25 +57,25 @@ export const DEFAULT_CONFIG: TuiConfig = {
54
57
  vim: false,
55
58
  icons: { mode: "auto" },
56
59
  footerSegments: {
57
- cwd: true,
58
- gitBranch: true,
59
- gitStatus: true,
60
- gitCommit: false,
61
- runtime: true,
62
- context: true,
63
- tokens: true,
64
- cost: true,
65
- extensionStatuses: true,
66
- },
60
+ cwd: FACTS.cwd.defaultEnabled,
61
+ gitBranch: FACTS.gitBranch.defaultEnabled,
62
+ gitStatus: FACTS.gitStatus.defaultEnabled,
63
+ gitCommit: FACTS.gitCommit.defaultEnabled,
64
+ runtime: FACTS.runtime.defaultEnabled,
65
+ context: FACTS.contextOccupancy.defaultEnabled,
66
+ tokens: FACTS.tokenCounts.defaultEnabled,
67
+ cost: FACTS.cost.defaultEnabled,
68
+ extensionStatuses: FACTS.extensionStatuses.defaultEnabled,
69
+ } satisfies TuiConfig["footerSegments"],
67
70
  telemetry: {
68
- enabled: true,
69
- tps: true,
70
- ttft: true,
71
- duration: true,
72
- tokens: true,
73
- stalls: true,
74
- cost: true,
75
- },
71
+ enabled: true, // the surface switch, not a fact
72
+ tps: FACTS.turnTps.defaultEnabled,
73
+ ttft: FACTS.turnTtft.defaultEnabled,
74
+ duration: FACTS.turnDuration.defaultEnabled,
75
+ tokens: FACTS.turnTokens.defaultEnabled,
76
+ stalls: FACTS.turnStalls.defaultEnabled,
77
+ cost: FACTS.turnCostRate.defaultEnabled,
78
+ } satisfies TuiConfig["telemetry"],
76
79
  smartCompaction: {
77
80
  enabled: true,
78
81
  classifier: null,
@@ -164,7 +167,7 @@ const FileSchema = Schema.fromJsonString(
164
167
  smartCompaction: Schema.optional(
165
168
  Schema.Struct({
166
169
  enabled: OptionalBoolean,
167
- classifier: Schema.optional(Schema.NullOr(Schema.String)),
170
+ classifier: Schema.NullOr(Schema.String).pipe(Schema.optional),
168
171
  needsContextProbabilityThreshold: Schema.optional(Schema.Finite),
169
172
  minAnswerConfidence: Schema.optional(Schema.Finite),
170
173
  // Pre-rename names. They stay declared and read as aliases, so an
@@ -250,17 +253,26 @@ export function applyDefaults(partial: TuiConfigFile): TuiConfig {
250
253
  };
251
254
  }
252
255
 
253
- export class ConfigReadError extends Schema.TaggedError<ConfigReadError>()("ConfigReadError", {
256
+ export class ConfigReadError extends Schema.TaggedError<
257
+ ConfigReadError,
258
+ { readonly brand: unique symbol }
259
+ >()("ConfigReadError", {
254
260
  path: Schema.String,
255
261
  message: Schema.String,
256
262
  }) {}
257
263
 
258
- export class ConfigParseError extends Schema.TaggedError<ConfigParseError>()("ConfigParseError", {
264
+ export class ConfigParseError extends Schema.TaggedError<
265
+ ConfigParseError,
266
+ { readonly brand: unique symbol }
267
+ >()("ConfigParseError", {
259
268
  path: Schema.String,
260
269
  message: Schema.String,
261
270
  }) {}
262
271
 
263
- export class ConfigWriteError extends Schema.TaggedError<ConfigWriteError>()("ConfigWriteError", {
272
+ export class ConfigWriteError extends Schema.TaggedError<
273
+ ConfigWriteError,
274
+ { readonly brand: unique symbol }
275
+ >()("ConfigWriteError", {
264
276
  path: Schema.String,
265
277
  message: Schema.String,
266
278
  }) {}
@@ -275,7 +287,7 @@ export class TuiConfigService extends Context.Service<
275
287
  readonly loadOrDefault: Effect.Effect<TuiConfig, never, never>;
276
288
  readonly save: (config: TuiConfig) => Effect.Effect<void, ConfigWriteError>;
277
289
  }
278
- >()("tui/config/TuiConfigService") {
290
+ >()("@ftrdotdev/pi-tui/config/TuiConfigService") {
279
291
  static make(path: string): Layer.Layer<TuiConfigService, never, FileSystem.FileSystem> {
280
292
  return Layer.effect(
281
293
  TuiConfigService,
@@ -286,18 +298,16 @@ export class TuiConfigService extends Context.Service<
286
298
  const exists = yield* fs
287
299
  .exists(path)
288
300
  .pipe(
289
- Effect.catch(
290
- (err: PlatformError.PlatformError) =>
291
- new ConfigReadError({ path, message: err.message }),
301
+ Effect.catch((err: PlatformError.PlatformError) =>
302
+ ConfigReadError.make({ path, message: err.message }),
292
303
  ),
293
304
  );
294
305
 
295
306
  if (!exists) {
296
307
  yield* fs.makeDirectory(dirname(path), { recursive: true }).pipe(
297
308
  Effect.andThen(() => fs.writeFileString(path, encodeConfig(DEFAULT_CONFIG) + "\n")),
298
- Effect.catch(
299
- (err: PlatformError.PlatformError) =>
300
- new ConfigWriteError({ path, message: err.message }),
309
+ Effect.catch((err: PlatformError.PlatformError) =>
310
+ ConfigWriteError.make({ path, message: err.message }),
301
311
  ),
302
312
  );
303
313
  return applyDefaults({});
@@ -306,8 +316,8 @@ export class TuiConfigService extends Context.Service<
306
316
  const config = yield* fs.readFileString(path).pipe(
307
317
  Effect.flatMap(decodeConfigEffect),
308
318
  Effect.catchTags({
309
- SchemaError: (err) => new ConfigParseError({ path, message: err.message }),
310
- PlatformError: (err) => new ConfigReadError({ path, message: err.message }),
319
+ SchemaError: (err) => ConfigParseError.make({ path, message: err.message }),
320
+ PlatformError: (err) => ConfigReadError.make({ path, message: err.message }),
311
321
  }),
312
322
  );
313
323
 
@@ -327,17 +337,15 @@ export class TuiConfigService extends Context.Service<
327
337
  yield* fs
328
338
  .makeDirectory(dirname(path), { recursive: true })
329
339
  .pipe(
330
- Effect.catch(
331
- (err: PlatformError.PlatformError) =>
332
- new ConfigWriteError({ path, message: err.message }),
340
+ Effect.catch((err: PlatformError.PlatformError) =>
341
+ ConfigWriteError.make({ path, message: err.message }),
333
342
  ),
334
343
  );
335
344
  yield* fs
336
345
  .writeFileString(path, JSON.stringify(config, null, 2) + "\n")
337
346
  .pipe(
338
- Effect.catch(
339
- (err: PlatformError.PlatformError) =>
340
- new ConfigWriteError({ path, message: err.message }),
347
+ Effect.catch((err: PlatformError.PlatformError) =>
348
+ ConfigWriteError.make({ path, message: err.message }),
341
349
  ),
342
350
  );
343
351
  });
@@ -1,4 +1,6 @@
1
1
  import { assert, it } from "@effect/vitest";
2
+ import { PROPERTY_RUNS } from "@ftrdotdev/pi-test-kit";
3
+ import { frameOptionsArbitrary } from "../../test-support/generators.ts";
2
4
  import { buildBoxFrame, composeBorderLine } from "./box-frame.ts";
3
5
 
4
6
  const compose = (
@@ -22,13 +24,6 @@ it("honors a custom label suffix", () => {
22
24
  assert.strictEqual(compose(frame), `╭─── ↓ 5 more ${"─".repeat(5)}╮`);
23
25
  });
24
26
 
25
- it("clips to a plain frame when the label plus a custom suffix would overflow", () => {
26
- // 4 (─── ) + 8 (label) + 1 (suffix) = 13 > width - 2 = 10 → label dropped.
27
- const frame = buildBoxFrame(12, { label: "↓ 5 more", labelWidth: 8, labelSuffix: " " });
28
- assert.strictEqual(frame!.top.label, null);
29
- assert.strictEqual(`${frame!.top.left}${frame!.top.fill}${frame!.top.right}`, "╭──────────╮");
30
- });
31
-
32
27
  it("leaves the bottom border untouched by the label options", () => {
33
28
  const frame = buildBoxFrame(20, { label: "hi", labelWidth: 2, labelSuffix: " " })!;
34
29
  assert.strictEqual(frame.bottom.left, "╰");
@@ -42,3 +37,54 @@ it("paints the chrome but passes the label through raw", () => {
42
37
  assert.strictEqual(composeBorderLine(frame, "top", paint), `<╭><─── >hi< ─────><──────><╮>`);
43
38
  assert.strictEqual(composeBorderLine(frame, "bottom", paint), `<╰><──────────────────><╯>`);
44
39
  });
40
+
41
+ it.prop(
42
+ "the composed top and bottom lines are exactly the requested width",
43
+ { frame: frameOptionsArbitrary },
44
+ ({ frame }) => {
45
+ const built = buildBoxFrame(frame.width, {
46
+ paddingX: frame.paddingX,
47
+ label: frame.label,
48
+ labelSuffix: frame.labelSuffix,
49
+ })!;
50
+ // ASCII label and suffix, one unit per cell, so `.length` is the cell count.
51
+ assert.strictEqual(compose(built, "top").length, frame.width);
52
+ assert.strictEqual(compose(built, "bottom").length, frame.width);
53
+ },
54
+ { arbitrary: { runs: PROPERTY_RUNS } },
55
+ );
56
+
57
+ it.prop(
58
+ "the content width stays inside the interior",
59
+ { frame: frameOptionsArbitrary },
60
+ ({ frame }) => {
61
+ const built = buildBoxFrame(frame.width, {
62
+ paddingX: frame.paddingX,
63
+ label: frame.label,
64
+ labelSuffix: frame.labelSuffix,
65
+ })!;
66
+ assert.isAtLeast(built.contentWidth, 1);
67
+ assert.isAtMost(built.contentWidth, frame.width - 2);
68
+ assert.strictEqual(built.padLeft.length, frame.paddingX);
69
+ assert.strictEqual(built.padRight.length, frame.paddingX);
70
+ },
71
+ { arbitrary: { runs: PROPERTY_RUNS } },
72
+ );
73
+
74
+ it.prop(
75
+ "the label is dropped exactly when the fixed chrome cannot fit",
76
+ { frame: frameOptionsArbitrary },
77
+ ({ frame }) => {
78
+ const built = buildBoxFrame(frame.width, {
79
+ paddingX: frame.paddingX,
80
+ label: frame.label,
81
+ labelSuffix: frame.labelSuffix,
82
+ })!;
83
+ // The chrome fits when the minimum label width is met and the corners plus
84
+ // the decorative runs leave room inside the rails.
85
+ const fits =
86
+ frame.width >= 8 && 4 + frame.label.length + frame.labelSuffix.length <= frame.width - 2;
87
+ assert.strictEqual(built.top.label === null, !fits);
88
+ },
89
+ { arbitrary: { runs: PROPERTY_RUNS } },
90
+ );
@@ -0,0 +1,47 @@
1
+ import { expect, it, vi } from "@effect/vitest";
2
+ import { readFileSync } from "node:fs";
3
+ import { fileURLToPath } from "node:url";
4
+ import { createVitest } from "vitest/node";
5
+
6
+ const PACKAGE_ROOT = fileURLToPath(new URL("..", import.meta.url));
7
+ const REAL_LOG = console.log;
8
+ const PROBE = "PI_HARNESS_PROBE";
9
+
10
+ it("this package's run resolves the shared policy without stating it", async () => {
11
+ const vitest = await createVitest({ root: PACKAGE_ROOT, watch: false });
12
+ try {
13
+ const project = vitest.projects.at(0);
14
+ expect(project?.config.name).toBe("tui");
15
+ expect(project?.config.restoreMocks).toBe(true);
16
+ expect(project?.config.unstubEnvs).toBe(true);
17
+ expect(project?.config.unstubGlobals).toBe(true);
18
+ expect(project?.config.isolate).toBe(false);
19
+ } finally {
20
+ await vitest.close();
21
+ }
22
+ });
23
+
24
+ it("the package config states no shared key", () => {
25
+ const source = readFileSync(new URL("../vitest.config.ts", import.meta.url), "utf8");
26
+ expect(source).toContain("baseTestConfig");
27
+ for (const key of ["restoreMocks", "unstubEnvs", "unstubGlobals", "fakeTimers", "isolate"]) {
28
+ expect(source).not.toContain(key);
29
+ }
30
+ });
31
+
32
+ it("a stubbed environment variable is set for the test that stubs it", () => {
33
+ vi.stubEnv(PROBE, "1");
34
+ });
35
+
36
+ it("a stubbed environment variable is absent in the next test", () => {
37
+ expect(process.env[PROBE]).toBeUndefined();
38
+ });
39
+
40
+ it("a spy made in one test replaces the function for that test", () => {
41
+ vi.spyOn(console, "log").mockImplementation(() => {});
42
+ });
43
+
44
+ it("a spy made in one test is not a mock in the next", () => {
45
+ expect(vi.isMockFunction(console.log)).toBe(false);
46
+ expect(console.log).toBe(REAL_LOG);
47
+ });
@@ -0,0 +1,19 @@
1
+ import { assert, it } from "@effect/vitest";
2
+ import {
3
+ glyphCollisions,
4
+ glyphLetterViolations,
5
+ glyphWidthViolations,
6
+ } from "../test-support/glyph-laws.ts";
7
+
8
+ it("every ascii glyph is distinct across the whole table", () => {
9
+ // Act/Assert: the law reports the first colliding pair by slot and value.
10
+ assert.deepStrictEqual(glyphCollisions(), []);
11
+ });
12
+
13
+ it("every ascii glyph is exactly one terminal column and one code point", () => {
14
+ assert.deepStrictEqual(glyphWidthViolations(), []);
15
+ });
16
+
17
+ it("the ascii table contains no non-vim letter stand-ins", () => {
18
+ assert.deepStrictEqual(glyphLetterViolations(), []);
19
+ });
package/src/icons.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { isNonEmptyString } from "./utils.ts";
2
+
1
3
  export type IconMode = "auto" | "nerd" | "ascii";
2
4
 
3
5
  export interface IconGlyphs {
@@ -14,7 +16,6 @@ export interface IconGlyphs {
14
16
  tool: string;
15
17
  input: string;
16
18
  output: string;
17
- cacheHit: string;
18
19
  cost: string;
19
20
  speed: string;
20
21
  latency: string;
@@ -30,6 +31,10 @@ export interface IconGlyphs {
30
31
  untracked: string;
31
32
  renamed: string;
32
33
  deleted: string;
34
+ /** Vim mode indicator on the editor's top border. */
35
+ vimNormal: string;
36
+ vimVisual: string;
37
+ vimInsert: string;
33
38
  }
34
39
 
35
40
  const NERD_GLYPHS: IconGlyphs = {
@@ -45,7 +50,6 @@ const NERD_GLYPHS: IconGlyphs = {
45
50
  // client network view: input = upload to API, output = download from API
46
51
  input: "",
47
52
  output: "",
48
- cacheHit: "",
49
53
  cost: "",
50
54
  speed: "󰓅",
51
55
  latency: "",
@@ -61,40 +65,55 @@ const NERD_GLYPHS: IconGlyphs = {
61
65
  untracked: "?",
62
66
  renamed: "»",
63
67
  deleted: "✘",
68
+ vimNormal: "N",
69
+ vimVisual: "V",
70
+ vimInsert: "I",
64
71
  };
65
72
 
66
- // the footer's icon-like feel on non-Nerd-Font terminals. Symbols chosen to
67
- // avoid collisions with the git-status set {= S ! A ? r x ^ v}.
68
- const ASCII_GLYPHS: IconGlyphs = {
69
- cwd: "@",
70
- git: "*",
71
- working: "o",
72
- done: "+",
73
- context: "%",
74
- model: "M",
75
- thinking: "~",
76
- inference: "~", // same glyph as thinking: the model is generating
77
- tool: ">", // outside the git-status collision set {= S ! A ? r x ^ v}
73
+ // Non-Nerd-Font terminals get the house's Unicode set: every value is one code
74
+ // point, one terminal column, and distinct from every other value in this
75
+ // table. The vim slots stay letters for clarity; the width and distinctness
76
+ // laws cover them and the no-letter law exempts them.
77
+ export const ASCII_GLYPHS: IconGlyphs = {
78
+ cwd: "⌂",
79
+ git: "⎇",
80
+ working: "▶",
81
+ done: "✓",
82
+ context: "◧",
83
+ model: "◈",
84
+ thinking: "✳",
85
+ inference: "✻",
86
+ tool: "⚙",
78
87
  input: "↑",
79
88
  output: "↓",
80
- cacheHit: "c",
81
89
  cost: "$",
82
- speed: ">",
83
- latency: "~",
84
- stall: "!",
85
- extensions: "&",
86
- ahead: "^",
87
- behind: "v",
88
- diverged: "^v",
89
- conflicted: "=",
90
- stashed: "S",
91
- modified: "!",
92
- staged: "A",
90
+ speed: "»",
91
+ latency: "◷",
92
+ stall: "⊘",
93
+ extensions: "❖",
94
+ ahead: "⇡",
95
+ behind: "⇣",
96
+ diverged: "⋔",
97
+ conflicted: "≠",
98
+ stashed: "▣",
99
+ modified: "●",
100
+ staged: "▲",
93
101
  untracked: "?",
94
- renamed: "r",
95
- deleted: "x",
102
+ renamed: "→",
103
+ deleted: "✕",
104
+ vimNormal: "N",
105
+ vimVisual: "V",
106
+ vimInsert: "I",
96
107
  };
97
108
 
109
+ /** Bar cells live beside the glyph table so their width is covered by the same law. */
110
+ export const ASCII_BAR_CELLS = { filled: "▮", empty: "▯" } as const;
111
+ export const NERD_BAR_CELLS = { filled: "█", empty: "░" } as const;
112
+
113
+ export function resolveBarCells(mode: IconMode): { filled: string; empty: string } {
114
+ return resolveIconMode(mode) === "ascii" ? ASCII_BAR_CELLS : NERD_BAR_CELLS;
115
+ }
116
+
98
117
  const NERD_FONT_TERMINALS = new Set([
99
118
  "iTerm.app",
100
119
  "Ghostty",
@@ -108,15 +127,15 @@ const NERD_FONT_TERMINALS = new Set([
108
127
 
109
128
  export function detectNerdFont(): boolean {
110
129
  const termProgram = process.env.TERM_PROGRAM;
111
- if (termProgram && NERD_FONT_TERMINALS.has(termProgram)) return true;
130
+ if (isNonEmptyString(termProgram) && NERD_FONT_TERMINALS.has(termProgram)) return true;
112
131
 
113
132
  const lcTerminal = process.env.LC_TERMINAL;
114
- if (lcTerminal && NERD_FONT_TERMINALS.has(lcTerminal)) return true;
133
+ if (isNonEmptyString(lcTerminal) && NERD_FONT_TERMINALS.has(lcTerminal)) return true;
115
134
 
116
135
  if (process.env.TERM === "xterm-kitty") return true;
117
136
 
118
137
  // Windows Terminal sets WT_SESSION (not TERM_PROGRAM)
119
- if (process.env.WT_SESSION) return true;
138
+ if (isNonEmptyString(process.env.WT_SESSION)) return true;
120
139
 
121
140
  // VS Code integrated terminal
122
141
  if (process.env.TERM_PROGRAM === "vscode") return true;