@ftrdotdev/pi-tui 0.8.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 +46 -40
  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";
@@ -40,9 +41,9 @@ export const TuiConfig = Schema.Struct({
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
  });
48
49
 
@@ -56,25 +57,25 @@ export const DEFAULT_CONFIG: TuiConfig = {
56
57
  vim: false,
57
58
  icons: { mode: "auto" },
58
59
  footerSegments: {
59
- cwd: true,
60
- gitBranch: true,
61
- gitStatus: true,
62
- gitCommit: false,
63
- runtime: true,
64
- context: true,
65
- tokens: true,
66
- cost: true,
67
- extensionStatuses: true,
68
- },
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"],
69
70
  telemetry: {
70
- enabled: true,
71
- tps: true,
72
- ttft: true,
73
- duration: true,
74
- tokens: true,
75
- stalls: true,
76
- cost: true,
77
- },
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"],
78
79
  smartCompaction: {
79
80
  enabled: true,
80
81
  classifier: null,
@@ -166,7 +167,7 @@ const FileSchema = Schema.fromJsonString(
166
167
  smartCompaction: Schema.optional(
167
168
  Schema.Struct({
168
169
  enabled: OptionalBoolean,
169
- classifier: Schema.optional(Schema.NullOr(Schema.String)),
170
+ classifier: Schema.NullOr(Schema.String).pipe(Schema.optional),
170
171
  needsContextProbabilityThreshold: Schema.optional(Schema.Finite),
171
172
  minAnswerConfidence: Schema.optional(Schema.Finite),
172
173
  // Pre-rename names. They stay declared and read as aliases, so an
@@ -252,17 +253,26 @@ export function applyDefaults(partial: TuiConfigFile): TuiConfig {
252
253
  };
253
254
  }
254
255
 
255
- export class ConfigReadError extends Schema.TaggedError<ConfigReadError>()("ConfigReadError", {
256
+ export class ConfigReadError extends Schema.TaggedError<
257
+ ConfigReadError,
258
+ { readonly brand: unique symbol }
259
+ >()("ConfigReadError", {
256
260
  path: Schema.String,
257
261
  message: Schema.String,
258
262
  }) {}
259
263
 
260
- export class ConfigParseError extends Schema.TaggedError<ConfigParseError>()("ConfigParseError", {
264
+ export class ConfigParseError extends Schema.TaggedError<
265
+ ConfigParseError,
266
+ { readonly brand: unique symbol }
267
+ >()("ConfigParseError", {
261
268
  path: Schema.String,
262
269
  message: Schema.String,
263
270
  }) {}
264
271
 
265
- export class ConfigWriteError extends Schema.TaggedError<ConfigWriteError>()("ConfigWriteError", {
272
+ export class ConfigWriteError extends Schema.TaggedError<
273
+ ConfigWriteError,
274
+ { readonly brand: unique symbol }
275
+ >()("ConfigWriteError", {
266
276
  path: Schema.String,
267
277
  message: Schema.String,
268
278
  }) {}
@@ -277,7 +287,7 @@ export class TuiConfigService extends Context.Service<
277
287
  readonly loadOrDefault: Effect.Effect<TuiConfig, never, never>;
278
288
  readonly save: (config: TuiConfig) => Effect.Effect<void, ConfigWriteError>;
279
289
  }
280
- >()("tui/config/TuiConfigService") {
290
+ >()("@ftrdotdev/pi-tui/config/TuiConfigService") {
281
291
  static make(path: string): Layer.Layer<TuiConfigService, never, FileSystem.FileSystem> {
282
292
  return Layer.effect(
283
293
  TuiConfigService,
@@ -288,18 +298,16 @@ export class TuiConfigService extends Context.Service<
288
298
  const exists = yield* fs
289
299
  .exists(path)
290
300
  .pipe(
291
- Effect.catch(
292
- (err: PlatformError.PlatformError) =>
293
- new ConfigReadError({ path, message: err.message }),
301
+ Effect.catch((err: PlatformError.PlatformError) =>
302
+ ConfigReadError.make({ path, message: err.message }),
294
303
  ),
295
304
  );
296
305
 
297
306
  if (!exists) {
298
307
  yield* fs.makeDirectory(dirname(path), { recursive: true }).pipe(
299
308
  Effect.andThen(() => fs.writeFileString(path, encodeConfig(DEFAULT_CONFIG) + "\n")),
300
- Effect.catch(
301
- (err: PlatformError.PlatformError) =>
302
- new ConfigWriteError({ path, message: err.message }),
309
+ Effect.catch((err: PlatformError.PlatformError) =>
310
+ ConfigWriteError.make({ path, message: err.message }),
303
311
  ),
304
312
  );
305
313
  return applyDefaults({});
@@ -308,8 +316,8 @@ export class TuiConfigService extends Context.Service<
308
316
  const config = yield* fs.readFileString(path).pipe(
309
317
  Effect.flatMap(decodeConfigEffect),
310
318
  Effect.catchTags({
311
- SchemaError: (err) => new ConfigParseError({ path, message: err.message }),
312
- 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 }),
313
321
  }),
314
322
  );
315
323
 
@@ -329,17 +337,15 @@ export class TuiConfigService extends Context.Service<
329
337
  yield* fs
330
338
  .makeDirectory(dirname(path), { recursive: true })
331
339
  .pipe(
332
- Effect.catch(
333
- (err: PlatformError.PlatformError) =>
334
- new ConfigWriteError({ path, message: err.message }),
340
+ Effect.catch((err: PlatformError.PlatformError) =>
341
+ ConfigWriteError.make({ path, message: err.message }),
335
342
  ),
336
343
  );
337
344
  yield* fs
338
345
  .writeFileString(path, JSON.stringify(config, null, 2) + "\n")
339
346
  .pipe(
340
- Effect.catch(
341
- (err: PlatformError.PlatformError) =>
342
- new ConfigWriteError({ path, message: err.message }),
347
+ Effect.catch((err: PlatformError.PlatformError) =>
348
+ ConfigWriteError.make({ path, message: err.message }),
343
349
  ),
344
350
  );
345
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;