@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
@@ -0,0 +1,67 @@
1
+ // The chrome input port (types only in Slice 1).
2
+ //
3
+ // Every member is a live getter: the pi render seam is synchronous, so a
4
+ // snapshot or a promise cannot satisfy it. Slices 3-6 write each planner once
5
+ // against `ChromePort`; Slice 9 adds the plain provider and its test.
6
+ import type { ExtensionContext, Theme } from "@earendil-works/pi-coding-agent";
7
+ import type { TuiConfig } from "../config.ts";
8
+ import type { FooterState, ModelMeta, UsageTotals } from "../state.ts";
9
+ import type { GitStatus } from "../commands/git-status.ts";
10
+ import type { RuntimeInfo } from "../runtime.ts";
11
+ import { getUsageTotals } from "../state.ts";
12
+
13
+ export interface ChromeFacts {
14
+ readonly cwd: () => string;
15
+ readonly git: () => GitStatus;
16
+ readonly runtime: () => readonly RuntimeInfo[];
17
+ readonly usage: () => UsageTotals;
18
+ readonly model: () => ModelMeta;
19
+ readonly contextUsage: () => ReturnType<ExtensionContext["getContextUsage"]>;
20
+ readonly extensionStatuses: () => ReadonlyMap<string, string>;
21
+ readonly activity: () => FooterState["tracker"];
22
+ readonly lastDoneIn: () => number | undefined;
23
+ readonly config: () => TuiConfig;
24
+ readonly theme: () => Theme;
25
+ readonly now: () => number;
26
+ readonly notifyWidth: () => number;
27
+ }
28
+
29
+ export interface ChromePort {
30
+ readonly facts: ChromeFacts;
31
+ }
32
+
33
+ /** The pi-side inputs the plain provider reads (Slice 9). */
34
+ export interface ChromeProviderSources {
35
+ readonly state: () => FooterState;
36
+ readonly config: () => TuiConfig;
37
+ readonly model: () => ModelMeta;
38
+ readonly extensionStatuses: () => ReadonlyMap<string, string>;
39
+ }
40
+
41
+ /**
42
+ * The plain provider (legacy, D13): plan 1's mount used it. It stays as the
43
+ * parity oracle for `makeServiceChromeProvider` and is deleted when the plain
44
+ * path is retired, together with `getUsageTotals`.
45
+ */
46
+ export function makePlainChromeProvider(
47
+ ctx: ExtensionContext,
48
+ sources: ChromeProviderSources,
49
+ ): ChromePort {
50
+ return {
51
+ facts: {
52
+ cwd: () => ctx.sessionManager.getCwd(),
53
+ git: () => sources.state().git,
54
+ runtime: () => sources.state().runtime,
55
+ usage: () => getUsageTotals(ctx),
56
+ model: () => sources.model(),
57
+ contextUsage: () => ctx.getContextUsage(),
58
+ extensionStatuses: () => sources.extensionStatuses(),
59
+ activity: () => sources.state().tracker,
60
+ lastDoneIn: () => sources.state().lastDoneIn,
61
+ config: () => sources.config(),
62
+ theme: () => ctx.ui.theme,
63
+ now: () => Date.now(),
64
+ notifyWidth: () => process.stdout.columns ?? 80,
65
+ },
66
+ };
67
+ }
@@ -0,0 +1,383 @@
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 { afterEach, assert, beforeEach, it, vi } from "@effect/vitest";
5
+ import { themeDouble } from "@ftrdotdev/pi-test-kit";
6
+ import { Effect } from "effect";
7
+ import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
8
+ import { footerCtxDouble } from "../../test-support/doubles.ts";
9
+ import { ActivityService } from "../activity.ts";
10
+ import { GitStatus } from "../commands/git-status.ts";
11
+ import { DEFAULT_CONFIG, type TuiConfig } from "../config.ts";
12
+ import { createTuiSessionHost, type TuiSessionHost } from "../layers.ts";
13
+ import type { RuntimeEnv } from "../runtime.ts";
14
+ import { RuntimeInfoService } from "../runtime-service.ts";
15
+ import { invalidateUsageCache, type ModelMeta, type SessionEntry } from "../state.ts";
16
+ import { TurnTelemetryService } from "../telemetry.ts";
17
+ import { UsageTotalsService } from "../usage-totals-service.ts";
18
+ import { FooterRenderService } from "../ui/footer.ts";
19
+ import { HeaderRenderService } from "../ui/header.ts";
20
+ import { composeNotifyLine } from "../telemetry.ts";
21
+ import { makeChromePortBuilder } from "./service-provider.ts";
22
+ import { makePlainChromeProvider } from "./port.ts";
23
+
24
+ // ---------------------------------------------------------------------------
25
+ // A/B parity: the service provider must produce the same facts, frames and
26
+ // notify lines as plan 1's plain provider. The plain pipeline stays the
27
+ // oracle, so the frozen tables anchor both (D12: freeze the clock).
28
+ // ---------------------------------------------------------------------------
29
+
30
+ const plainTheme = themeDouble();
31
+
32
+ const WIDTHS = [30, 40, 60, 80, 100, 120] as const;
33
+
34
+ const config: TuiConfig = { ...DEFAULT_CONFIG, icons: { mode: "ascii" } };
35
+
36
+ const MODEL: ModelMeta = {
37
+ provider: "Anthropic",
38
+ model: "claude-sonnet-4-0",
39
+ effort: "medium",
40
+ };
41
+
42
+ const STATUSES = new Map([["lint", "running"]]);
43
+
44
+ const GIT = GitStatus.make({
45
+ branch: "feature/refactor",
46
+ ahead: 2,
47
+ behind: 1,
48
+ modified: 3,
49
+ untracked: 1,
50
+ staged: 2,
51
+ stashed: 1,
52
+ conflicted: 0,
53
+ renamed: 0,
54
+ deleted: 0,
55
+ commit: null,
56
+ });
57
+
58
+ /** One user message and two assistant messages with fixed usage values. */
59
+ const ENTRIES = [
60
+ {
61
+ type: "message",
62
+ id: "u1",
63
+ parentId: null,
64
+ timestamp: "t0",
65
+ message: { role: "user", content: "hi" },
66
+ },
67
+ {
68
+ type: "message",
69
+ id: "a1",
70
+ parentId: "u1",
71
+ timestamp: "t1",
72
+ message: {
73
+ role: "assistant",
74
+ content: [],
75
+ usage: {
76
+ input: 1200,
77
+ output: 400,
78
+ cacheRead: 800,
79
+ cacheWrite: 100,
80
+ totalTokens: 2500,
81
+ cost: { input: 0.02, output: 0.01, cacheRead: 0.01, cacheWrite: 0.002, total: 0.042 },
82
+ },
83
+ timestamp: 1_700_000_001_000,
84
+ },
85
+ },
86
+ {
87
+ type: "message",
88
+ id: "a2",
89
+ parentId: "a1",
90
+ timestamp: "t2",
91
+ message: {
92
+ role: "assistant",
93
+ content: [],
94
+ usage: {
95
+ input: 1200,
96
+ output: 400,
97
+ cacheRead: 800,
98
+ cacheWrite: 100,
99
+ totalTokens: 2500,
100
+ cost: { input: 0.02, output: 0.01, cacheRead: 0.01, cacheWrite: 0.002, total: 0.042 },
101
+ },
102
+ timestamp: 1_700_000_002_000,
103
+ },
104
+ },
105
+ ];
106
+
107
+ interface Fixture {
108
+ readonly ctx: ExtensionContext;
109
+ readonly host: TuiSessionHost;
110
+ readonly entries: unknown[];
111
+ }
112
+
113
+ const makeFixture = (): Fixture => {
114
+ const entries: unknown[] = [...ENTRIES];
115
+ const ctx = footerCtxDouble({
116
+ model: {
117
+ provider: "anthropic",
118
+ id: "claude-sonnet-4-0",
119
+ contextWindow: 200000,
120
+ reasoning: true,
121
+ },
122
+ cwd: "/workspace/pi-mono",
123
+ getContextUsage: () => ({ contextWindow: 200000, tokens: 100000, percent: 50.0 }),
124
+ sessionManager: {
125
+ getCwd: () => "/workspace/pi-mono",
126
+ getEntries: () => entries,
127
+ },
128
+ ui: { theme: plainTheme },
129
+ });
130
+ const host = createTuiSessionHost();
131
+ host.state.git = GIT;
132
+ host.state.sessionStartEpoch = 1_700_000_000_000;
133
+ return { ctx, host, entries };
134
+ };
135
+
136
+ const emptyEnv: RuntimeEnv = {
137
+ matches: () => Effect.succeed(false),
138
+ fingerprint: () => Effect.succeed(""),
139
+ version: () => Effect.undefined,
140
+ };
141
+
142
+ const sources = {
143
+ config: () => config,
144
+ model: () => MODEL,
145
+ extensionStatuses: () => STATUSES,
146
+ };
147
+
148
+ /** Resolves the three handles once, then builds both providers over one fixture. */
149
+ const providersOver = Effect.fnUntraced(function* (fixture: Fixture) {
150
+ const activity = yield* Effect.service(ActivityService).pipe(
151
+ Effect.provide(ActivityService.layerTest(() => fixture.host.state)),
152
+ );
153
+ const usage = yield* Effect.service(UsageTotalsService).pipe(
154
+ Effect.provide(
155
+ UsageTotalsService.layerTest(
156
+ () => fixture.entries as SessionEntry[],
157
+ () => 1,
158
+ ),
159
+ ),
160
+ );
161
+ const runtime = yield* Effect.service(RuntimeInfoService).pipe(
162
+ Effect.provide(
163
+ RuntimeInfoService.layerTest(
164
+ emptyEnv,
165
+ () => fixture.host.state,
166
+ () => 1,
167
+ ),
168
+ ),
169
+ );
170
+ const handles = { activity, usage, runtime };
171
+ const plain = makePlainChromeProvider(fixture.ctx, {
172
+ state: () => fixture.host.state,
173
+ ...sources,
174
+ });
175
+ const service = makeChromePortBuilder(fixture.host, handles)(fixture.ctx, sources);
176
+ return { plain, service };
177
+ });
178
+
179
+ // Fake only Date: the footer timer reads `port.facts.now()`, so two renders a
180
+ // moment apart could straddle a second boundary (D12).
181
+ beforeEach(() => {
182
+ vi.useFakeTimers({ toFake: ["Date"] });
183
+ vi.setSystemTime(0);
184
+ invalidateUsageCache();
185
+ });
186
+
187
+ afterEach(() => vi.useRealTimers());
188
+
189
+ it.effect("the provider satisfies every port member and is live", () =>
190
+ Effect.gen(function* () {
191
+ // Arrange
192
+ const fixture = makeFixture();
193
+ const { plain, service } = yield* providersOver(fixture);
194
+ const reads: ReadonlyArray<readonly [string, () => unknown, () => unknown]> = [
195
+ ["cwd", () => plain.facts.cwd(), () => service.facts.cwd()],
196
+ ["git", () => plain.facts.git(), () => service.facts.git()],
197
+ ["runtime", () => plain.facts.runtime(), () => service.facts.runtime()],
198
+ ["usage", () => plain.facts.usage(), () => service.facts.usage()],
199
+ ["model", () => plain.facts.model(), () => service.facts.model()],
200
+ ["contextUsage", () => plain.facts.contextUsage(), () => service.facts.contextUsage()],
201
+ [
202
+ "extensionStatuses",
203
+ () => plain.facts.extensionStatuses(),
204
+ () => service.facts.extensionStatuses(),
205
+ ],
206
+ ["activity", () => plain.facts.activity(), () => service.facts.activity()],
207
+ ["lastDoneIn", () => plain.facts.lastDoneIn(), () => service.facts.lastDoneIn()],
208
+ ["config", () => plain.facts.config(), () => service.facts.config()],
209
+ ["theme", () => plain.facts.theme(), () => service.facts.theme()],
210
+ ["now", () => plain.facts.now(), () => service.facts.now()],
211
+ ["notifyWidth", () => plain.facts.notifyWidth(), () => service.facts.notifyWidth()],
212
+ ];
213
+
214
+ // Act/Assert: every member agrees.
215
+ for (const [name, plainRead, serviceRead] of reads) {
216
+ assert.deepStrictEqual(serviceRead(), plainRead(), `${name} differs`);
217
+ }
218
+
219
+ // Act: mutate the host state and the entries behind both providers.
220
+ fixture.host.state.git = GitStatus.make({
221
+ branch: "next",
222
+ ahead: 2,
223
+ behind: 1,
224
+ modified: 3,
225
+ untracked: 1,
226
+ staged: 2,
227
+ stashed: 1,
228
+ conflicted: 0,
229
+ renamed: 0,
230
+ deleted: 0,
231
+ commit: null,
232
+ });
233
+ fixture.entries.push({
234
+ type: "message",
235
+ id: "a3",
236
+ parentId: "a2",
237
+ timestamp: "t3",
238
+ message: {
239
+ role: "assistant",
240
+ content: [],
241
+ usage: {
242
+ input: 10,
243
+ output: 0,
244
+ cacheRead: 0,
245
+ cacheWrite: 0,
246
+ totalTokens: 10,
247
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0.001 },
248
+ },
249
+ timestamp: 1_700_000_003_000,
250
+ },
251
+ });
252
+
253
+ // Assert: both see the new values; nothing was snapshotted at build.
254
+ assert.strictEqual(service.facts.git(), plain.facts.git());
255
+ assert.strictEqual(service.facts.git().branch, "next");
256
+ assert.strictEqual(service.facts.usage().input, plain.facts.usage().input);
257
+ assert.strictEqual(service.facts.usage().input, 2410);
258
+ }),
259
+ );
260
+
261
+ it.effect("footer frames are byte-identical through both providers at every pinned width", () =>
262
+ Effect.gen(function* () {
263
+ // Arrange
264
+ const fixture = makeFixture();
265
+ const { plain, service } = yield* providersOver(fixture);
266
+ const renderOver = (port: typeof plain) =>
267
+ Effect.gen(function* () {
268
+ const renderer = yield* FooterRenderService;
269
+ const lines: (readonly string[])[] = [];
270
+ for (const width of WIDTHS) {
271
+ const line = yield* renderer.render(width);
272
+ lines.push(line);
273
+ }
274
+ return lines;
275
+ }).pipe(Effect.provide(FooterRenderService.make(port)));
276
+
277
+ // Act
278
+ const plainFrames = yield* renderOver(plain);
279
+ const serviceFrames = yield* renderOver(service);
280
+
281
+ // Assert: byte-identical per width, same line count (statuses included).
282
+ for (let index = 0; index < WIDTHS.length; index++) {
283
+ assert.deepStrictEqual(serviceFrames[index], plainFrames[index], `width ${WIDTHS[index]}`);
284
+ }
285
+ }),
286
+ );
287
+
288
+ it.effect("header frames are byte-identical at every pinned width", () =>
289
+ Effect.gen(function* () {
290
+ // Arrange
291
+ const fixture = makeFixture();
292
+ const { plain, service } = yield* providersOver(fixture);
293
+ const renderOver = (port: typeof plain) =>
294
+ Effect.gen(function* () {
295
+ const renderer = yield* HeaderRenderService;
296
+ const lines: (readonly string[])[] = [];
297
+ for (const width of WIDTHS) {
298
+ const line = yield* renderer.render(width);
299
+ lines.push(line);
300
+ }
301
+ return lines;
302
+ }).pipe(Effect.provide(HeaderRenderService.make(port)));
303
+
304
+ // Act
305
+ const plainFrames = yield* renderOver(plain);
306
+ const serviceFrames = yield* renderOver(service);
307
+
308
+ // Assert
309
+ for (let index = 0; index < WIDTHS.length; index++) {
310
+ assert.deepStrictEqual(serviceFrames[index], plainFrames[index], `width ${WIDTHS[index]}`);
311
+ }
312
+ }),
313
+ );
314
+
315
+ /** The notify measurement, produced by the service from a scripted clock. */
316
+ const measurementOver = Effect.fnUntraced(function* () {
317
+ let now = 0;
318
+ const telemetry = yield* Effect.service(TurnTelemetryService).pipe(
319
+ Effect.provide(TurnTelemetryService.layerTest(() => now)),
320
+ );
321
+ const send = (instant: number, input: Parameters<typeof telemetry.handle>[0]) => {
322
+ now = instant;
323
+ return telemetry.handle(input);
324
+ };
325
+ const message = {
326
+ role: "assistant",
327
+ usage: {
328
+ input: 1200,
329
+ output: 400,
330
+ totalTokens: 1740,
331
+ cost: { total: 0.012 },
332
+ },
333
+ };
334
+ const event = <T>(value: unknown): T => value as T;
335
+ send(0, event({ type: "agent_start" }));
336
+ send(100, event({ type: "turn_start" }));
337
+ send(100, event({ type: "message_start", message }));
338
+ send(
339
+ 400,
340
+ event({
341
+ type: "message_update",
342
+ message,
343
+ assistantMessageEvent: { type: "text_delta", delta: "Hello" },
344
+ }),
345
+ );
346
+ send(
347
+ 2400,
348
+ event({
349
+ type: "message_update",
350
+ message,
351
+ assistantMessageEvent: { type: "text_delta", delta: " world" },
352
+ }),
353
+ );
354
+ send(2900, event({ type: "message_end", message }));
355
+ send(3000, event({ type: "turn_end" }));
356
+ const measurement = send(3000, event({ type: "agent_settled" }));
357
+ assert.ok(measurement !== undefined);
358
+ return measurement;
359
+ });
360
+
361
+ it.effect("the notify line is byte-identical at 30/80/120", () =>
362
+ Effect.gen(function* () {
363
+ // Arrange
364
+ const fixture = makeFixture();
365
+ const { plain, service } = yield* providersOver(fixture);
366
+ const measurement = yield* measurementOver();
367
+
368
+ // Act/Assert: each pinned width, composed from each provider's own facts.
369
+ for (const width of [30, 80, 120]) {
370
+ const compose = (port: typeof plain) =>
371
+ composeNotifyLine(measurement, {
372
+ theme: port.facts.theme(),
373
+ config: port.facts.config().telemetry,
374
+ iconMode: port.facts.config().icons.mode,
375
+ width,
376
+ });
377
+ assert.strictEqual(compose(service), compose(plain), `width ${width}`);
378
+ }
379
+ // The width fact itself stays the live terminal width for both providers.
380
+ assert.strictEqual(plain.facts.notifyWidth(), process.stdout.columns ?? 80);
381
+ assert.strictEqual(service.facts.notifyWidth(), plain.facts.notifyWidth());
382
+ }),
383
+ );
@@ -0,0 +1,55 @@
1
+ import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
+ import type { ChromePort } from "./port.ts";
3
+ import type { ActivityService } from "../activity.ts";
4
+ import type { RuntimeInfoService } from "../runtime-service.ts";
5
+ import type { TuiConfig } from "../config.ts";
6
+ import type { TuiSessionHost } from "../layers.ts";
7
+ import type { ModelMeta } from "../state.ts";
8
+ import type { UsageTotalsService } from "../usage-totals-service.ts";
9
+
10
+ /** The three services the port reads, resolved once in `main`'s prologue (D11). */
11
+ export interface TuiServiceHandles {
12
+ readonly activity: ActivityService["Service"];
13
+ readonly usage: UsageTotalsService["Service"];
14
+ readonly runtime: RuntimeInfoService["Service"];
15
+ }
16
+
17
+ /** The pi-side inputs the service provider reads; state comes from the host. */
18
+ export interface ServiceChromeProviderSources {
19
+ readonly config: () => TuiConfig;
20
+ readonly model: () => ModelMeta;
21
+ readonly extensionStatuses: () => ReadonlyMap<string, string>;
22
+ }
23
+
24
+ /** The one construction point: host + resolved handles, then a per-mount builder (D11). */
25
+ export function makeChromePortBuilder(
26
+ host: TuiSessionHost,
27
+ handles: TuiServiceHandles,
28
+ ): (ctx: ExtensionContext, sources: ServiceChromeProviderSources) => ChromePort {
29
+ return (ctx, sources) => makeServiceChromeProvider(ctx, host, handles, sources);
30
+ }
31
+
32
+ export function makeServiceChromeProvider(
33
+ ctx: ExtensionContext,
34
+ host: TuiSessionHost,
35
+ handles: TuiServiceHandles,
36
+ sources: ServiceChromeProviderSources,
37
+ ): ChromePort {
38
+ return {
39
+ facts: {
40
+ cwd: () => ctx.sessionManager.getCwd(),
41
+ git: () => host.state.git,
42
+ runtime: () => handles.runtime.current(),
43
+ usage: () => handles.usage.totals(),
44
+ model: () => sources.model(),
45
+ contextUsage: () => ctx.getContextUsage(),
46
+ extensionStatuses: () => sources.extensionStatuses(),
47
+ activity: () => handles.activity.tracker(),
48
+ lastDoneIn: () => host.state.lastDoneIn,
49
+ config: () => sources.config(),
50
+ theme: () => ctx.ui.theme,
51
+ now: () => Date.now(),
52
+ notifyWidth: () => process.stdout.columns ?? 80,
53
+ },
54
+ };
55
+ }
@@ -1,3 +1,6 @@
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";
2
5
  import { Duration, Effect } from "effect";
3
6
  import {
@@ -59,11 +62,11 @@ it("the default execution cap is the fixed 2-second constant", () => {
59
62
  });
60
63
 
61
64
  it("GitSpawnError and GitTimeoutError carry the expected tags", () => {
62
- const spawnErr = new GitSpawnError({ command: "git", message: "boom" });
65
+ const spawnErr = GitSpawnError.make({ command: "git", message: "boom" });
63
66
  assert.strictEqual(spawnErr._tag, "GitSpawnError");
64
67
  assert.instanceOf(spawnErr, GitSpawnError);
65
68
 
66
- const timeoutErr = new GitTimeoutError({ command: "git", durationMillis: 2000 });
69
+ const timeoutErr = GitTimeoutError.make({ command: "git", durationMillis: 2000 });
67
70
  assert.strictEqual(timeoutErr._tag, "GitTimeoutError");
68
71
  assert.instanceOf(timeoutErr, GitTimeoutError);
69
72
  });
@@ -19,13 +19,19 @@ export interface CommandResult {
19
19
  }
20
20
 
21
21
  /** A git invocation failed at the platform level (spawn, working directory, ...). */
22
- export class GitSpawnError extends Schema.TaggedError<GitSpawnError>()("GitSpawnError", {
22
+ export class GitSpawnError extends Schema.TaggedError<
23
+ GitSpawnError,
24
+ { readonly brand: unique symbol }
25
+ >()("GitSpawnError", {
23
26
  command: Schema.String,
24
27
  message: Schema.String,
25
28
  }) {}
26
29
 
27
30
  /** A git invocation exceeded the execution cap; the hung child is interrupted. */
28
- export class GitTimeoutError extends Schema.TaggedError<GitTimeoutError>()("GitTimeoutError", {
31
+ export class GitTimeoutError extends Schema.TaggedError<
32
+ GitTimeoutError,
33
+ { readonly brand: unique symbol }
34
+ >()("GitTimeoutError", {
29
35
  command: Schema.String,
30
36
  durationMillis: Schema.Finite,
31
37
  }) {}
@@ -39,12 +45,11 @@ const withCap = <E extends GitExecutionError>(
39
45
  command: string,
40
46
  effect: Effect.Effect<CommandResult, E, never>,
41
47
  ): Effect.Effect<CommandResult, GitExecutionError, never> =>
42
- effect.pipe(
43
- Effect.timeout(cap),
44
- Effect.catchTag("TimeoutError", () =>
45
- Effect.fail(new GitTimeoutError({ command, durationMillis: Duration.toMillis(cap) })),
46
- ),
47
- );
48
+ Effect.timeoutOrElse(effect, {
49
+ duration: cap,
50
+ orElse: () =>
51
+ Effect.fail(GitTimeoutError.make({ command, durationMillis: Duration.toMillis(cap) })),
52
+ });
48
53
 
49
54
  /**
50
55
  * Executes one command in a working directory and returns its stdout and exit
@@ -65,7 +70,7 @@ export class GitExecutionService extends Context.Service<
65
70
  cwd: string,
66
71
  ) => Effect.Effect<CommandResult, GitExecutionError, never>;
67
72
  }
68
- >()("tui/git/GitExecutionService") {
73
+ >()("@ftrdotdev/pi-tui/commands/git-execution/GitExecutionService") {
69
74
  /**
70
75
  * The real execution service over the platform
71
76
  * `ChildProcessSpawner.ChildProcessSpawner`.
@@ -87,7 +92,7 @@ export class GitExecutionService extends Context.Service<
87
92
  const commandEffect = Effect.scoped(
88
93
  Effect.gen(function* () {
89
94
  const handle = yield* spawner.spawn(CP.ChildProcess.make(command, args, { cwd }));
90
- const stdout = yield* Stream.mkString(Stream.decodeText(handle.stdout));
95
+ const stdout = yield* Stream.decodeText(handle.stdout).pipe(Stream.mkString);
91
96
  const exitCode = yield* handle.exitCode;
92
97
  return { stdout, exitCode };
93
98
  }),
@@ -96,9 +101,8 @@ export class GitExecutionService extends Context.Service<
96
101
  cap,
97
102
  command,
98
103
  commandEffect.pipe(
99
- Effect.mapError(
100
- (err: PlatformError.PlatformError) =>
101
- new GitSpawnError({ command, message: err.message }),
104
+ Effect.mapError((err: PlatformError.PlatformError) =>
105
+ GitSpawnError.make({ command, message: err.message }),
102
106
  ),
103
107
  ),
104
108
  );
@@ -182,7 +186,7 @@ export const makeStubLayer = (
182
186
  ) {
183
187
  const entry = lookup(command, args);
184
188
  if (entry === undefined) {
185
- return yield* new GitSpawnError({
189
+ return yield* GitSpawnError.make({
186
190
  command,
187
191
  message: `no stub response for ${command} ${args.join(" ")}`,
188
192
  });
@@ -193,7 +197,15 @@ export const makeStubLayer = (
193
197
  return { stdout: entry.stdout, exitCode: entry.exitCode };
194
198
  });
195
199
  return GitExecutionService.of({
196
- run: (command, args, cwd) => withCap(cap, command, run(command, args, cwd)),
200
+ // Untraced: the stub's inner `run` already carries the span, and a
201
+ // span per stubbed spawn would only duplicate it in test traces.
202
+ run: Effect.fnUntraced(function* (
203
+ command: string,
204
+ args: ReadonlyArray<string>,
205
+ cwd: string,
206
+ ): Effect.fn.Return<CommandResult, GitExecutionError> {
207
+ return yield* withCap(cap, command, run(command, args, cwd));
208
+ }),
197
209
  });
198
210
  }),
199
211
  );