@lune_99/pi-dock 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,9 @@ import {
5
5
  getLastAssistantUsage,
6
6
  SettingsManager,
7
7
  type ExtensionContext,
8
+ type MessageEndEvent,
9
+ type MessageStartEvent,
10
+ type MessageUpdateEvent,
8
11
  type ReadonlyFooterDataProvider,
9
12
  type SessionEntry,
10
13
  type Theme,
@@ -37,6 +40,13 @@ export interface DockUsage {
37
40
  cacheHitRate: number | undefined;
38
41
  }
39
42
 
43
+ export interface DockTokenSpeed {
44
+ tokensPerSecond: number | undefined;
45
+ generating: boolean;
46
+ }
47
+
48
+ export type DockMessageEvent = MessageStartEvent | MessageUpdateEvent | MessageEndEvent;
49
+
40
50
  /** Everything the info rows display, so rendering never touches Pi. */
41
51
  export interface DockStatus {
42
52
  cwd: string;
@@ -45,6 +55,7 @@ export interface DockStatus {
45
55
  model: { provider: string; id: string; thinking: string | undefined } | undefined;
46
56
  /** Pi names the provider only when more than one is available. */
47
57
  showProvider: boolean;
58
+ tokenSpeed: DockTokenSpeed;
48
59
  usage: DockUsage;
49
60
  /** Pi reports no tokens or share until the first response after a compaction. */
50
61
  context: { tokens: number | null; percent: number | null; window: number };
@@ -148,6 +159,83 @@ export class DockStatusSource {
148
159
  private usage: { key: string; value: DockUsage } | undefined;
149
160
  private autoCompact: { ctx: ExtensionContext; value: boolean } | undefined;
150
161
  private readonly readAutoCompact: (ctx: ExtensionContext) => boolean;
162
+ private response:
163
+ | {
164
+ ui: ExtensionContext["ui"];
165
+ sessionId: string;
166
+ requestTimestamp: number;
167
+ provider: string | undefined;
168
+ model: string | undefined;
169
+ speed: DockTokenSpeed;
170
+ }
171
+ | undefined;
172
+
173
+ observeMessage(event: DockMessageEvent, ctx: ExtensionContext): boolean {
174
+ const message = event.message;
175
+ if (message.role !== "assistant") return false;
176
+ const sessionId = ctx.sessionManager.getSessionId();
177
+ const previous = this.response;
178
+ const continuing =
179
+ event.type !== "message_start" &&
180
+ previous?.ui === ctx.ui &&
181
+ previous.sessionId === sessionId &&
182
+ previous.requestTimestamp === message.timestamp;
183
+ const generating = event.type !== "message_end";
184
+ const { output } = message.usage;
185
+ const duration = message.durationMs;
186
+ // Partial usage is not a provider-neutral live token counter; only final SDK timing is measured.
187
+ const rate =
188
+ !generating &&
189
+ Number.isFinite(output) &&
190
+ output > 0 &&
191
+ duration !== undefined &&
192
+ Number.isFinite(duration) &&
193
+ duration > 0
194
+ ? (output / duration) * 1000
195
+ : undefined;
196
+ // Virtual selections route to physical message models; keep the selection that began this response.
197
+ const provider = continuing ? previous.provider : ctx.model?.provider;
198
+ const model = continuing ? previous.model : ctx.model?.id;
199
+ const sameSelection =
200
+ previous?.ui === ctx.ui &&
201
+ previous.sessionId === sessionId &&
202
+ previous.provider === provider &&
203
+ previous.model === model;
204
+ this.response = {
205
+ ui: ctx.ui,
206
+ sessionId,
207
+ requestTimestamp: message.timestamp,
208
+ provider,
209
+ model,
210
+ speed: {
211
+ // An unfinished or cancelled response must not erase the last measured rate.
212
+ tokensPerSecond:
213
+ rate !== undefined && Number.isFinite(rate) && rate > 0
214
+ ? rate
215
+ : sameSelection
216
+ ? previous.speed.tokensPerSecond
217
+ : undefined,
218
+ generating,
219
+ },
220
+ };
221
+ return true;
222
+ }
223
+
224
+ resetTokenSpeed(): void {
225
+ this.response = undefined;
226
+ }
227
+
228
+ private collectTokenSpeed(ctx: ExtensionContext): DockTokenSpeed {
229
+ const response = this.response;
230
+ const model = ctx.model;
231
+ return model &&
232
+ response?.ui === ctx.ui &&
233
+ response.sessionId === ctx.sessionManager.getSessionId() &&
234
+ response.provider === model.provider &&
235
+ response.model === model.id
236
+ ? response.speed
237
+ : { tokensPerSecond: undefined, generating: false };
238
+ }
151
239
 
152
240
  constructor(readCompaction: (ctx: ExtensionContext) => boolean = readAutoCompact) {
153
241
  this.readAutoCompact = readCompaction;
@@ -176,6 +264,7 @@ export class DockStatusSource {
176
264
  thinking: model.reasoning ? (level === "off" ? "thinking off" : level) : undefined,
177
265
  },
178
266
  showProvider: footerData.getAvailableProviderCount() > 1,
267
+ tokenSpeed: this.collectTokenSpeed(ctx),
179
268
  usage: this.collectUsage(ctx),
180
269
  context: {
181
270
  tokens: contextUsage?.tokens ?? null,
@@ -204,25 +293,54 @@ export class DockStatusSource {
204
293
  }
205
294
  }
206
295
 
207
- /** The provider is the first thing to go when the model name has to fit a narrow budget. */
208
- export function renderModelSegment(status: DockStatus, theme: Theme, width: number): string {
296
+ const MAX_SPEED_VALUE_WIDTH = 6;
297
+
298
+ function formatTokenSpeed(rate: number | undefined): string | undefined {
299
+ if (rate === undefined || !Number.isFinite(rate) || rate <= 0) return undefined;
300
+ if (rate < 0.1) return "<0.1";
301
+ for (const decimals of [1, 0]) {
302
+ const text = rate.toFixed(decimals);
303
+ if (text.length <= MAX_SPEED_VALUE_WIDTH) return text;
304
+ }
305
+ return rate.toExponential(0);
306
+ }
307
+
308
+ /** Drop optional segments whole before spending any of the model's own columns. */
309
+ export function modelSegmentVariants(status: DockStatus, theme: Theme): string[] {
209
310
  const model = status.model;
210
311
  const name = model?.id ?? "no-model";
211
312
  const thinking = model?.thinking ? theme.fg("dim", ` • ${model.thinking}`) : "";
212
313
  const bare = name + thinking;
213
314
  const withProvider =
214
315
  status.showProvider && model ? theme.fg("accent", `(${model.provider}) `) + bare : bare;
215
- return visibleWidth(withProvider) <= width ? withProvider : truncateToWidth(bare, width);
316
+ if (!model) return [bare];
317
+ const value = formatTokenSpeed(status.tokenSpeed.tokensPerSecond);
318
+ if (value === undefined) return [...new Set([withProvider, bare])];
319
+ const speed = theme.fg(status.tokenSpeed.generating ? "accent" : "dim", ` • ${value} tok/s`);
320
+ return [...new Set([withProvider + speed, bare + speed, withProvider, bare])];
216
321
  }
217
322
 
218
- /** Right-aligned, so a growing number extends leftwards into its own padding and nothing else moves. */
219
- function field(text: string, width: number): string {
323
+ export function renderModelSegment(status: DockStatus, theme: Theme, width: number): string {
324
+ const variants = modelSegmentVariants(status, theme);
325
+ return (
326
+ variants.find((text) => visibleWidth(text) <= width) ??
327
+ truncateToWidth(variants.at(-1)!, width)
328
+ );
329
+ }
330
+
331
+ /**
332
+ * Left-aligned, so a label stays one column after its bar and a growing number spends only the
333
+ * padding behind it.
334
+ */
335
+ function padEnd(text: string, width: number): string {
220
336
  const gap = width - visibleWidth(text);
221
- return gap >= 0 ? " ".repeat(gap) + text : truncateToWidth(text, width);
337
+ return gap >= 0 ? text + " ".repeat(gap) : truncateToWidth(text, width);
222
338
  }
223
339
 
224
- function value(theme: Theme, text: string, width: number): string {
225
- return field(theme.fg("muted", text), width);
340
+ /** Right-aligned, for the numerator of a fraction, so its slash never moves. */
341
+ function padStart(text: string, width: number): string {
342
+ const gap = width - visibleWidth(text);
343
+ return gap >= 0 ? " ".repeat(gap) + text : truncateToWidth(text, width);
226
344
  }
227
345
 
228
346
  const CONTEXT_JOINER = " · ";
@@ -234,11 +352,11 @@ const CONTEXT_WIDTH = COUNT_WIDTH + 1 + COUNT_WIDTH + visibleWidth(CONTEXT_JOINE
234
352
  */
235
353
  export function renderContextCell(status: DockStatus, theme: Theme): string {
236
354
  const { tokens, percent, window } = status.context;
237
- const used = field(tokens === null ? "?" : formatTokens(tokens), COUNT_WIDTH);
238
- const share = field(percent === null ? "?" : formatPercent(percent), PERCENT_WIDTH);
355
+ const used = padStart(tokens === null ? "?" : formatTokens(tokens), COUNT_WIDTH);
356
+ const share = percent === null ? "?" : formatPercent(percent);
239
357
  return theme.fg(
240
358
  (percent ?? 0) > 90 ? "error" : (percent ?? 0) > 70 ? "warning" : "muted",
241
- field(`${used}/${formatTokens(window)}${CONTEXT_JOINER}${share}`, CONTEXT_WIDTH),
359
+ padEnd(`${used}/${formatTokens(window)}${CONTEXT_JOINER}${share}`, CONTEXT_WIDTH),
242
360
  );
243
361
  }
244
362
 
@@ -247,61 +365,74 @@ interface StatSlot {
247
365
  keep: number;
248
366
  /** Columns reserved for the slot with every part present, whatever the values are. */
249
367
  width: number;
250
- /** Nothing is drawn for a slot without data, and `render` leaves out any part that has none. */
368
+ /** A slot without data keeps its columns but draws neither its bar nor any text. */
251
369
  hasData(status: DockStatus): boolean;
252
370
  render(status: DockStatus, theme: Theme): string;
253
371
  }
254
372
 
255
- /** A counter that is still zero is left out, so a provider that never reports it shows no gap. */
373
+ /**
374
+ * Each counter keeps its own columns, so one that is still zero is blank rather than absent and the
375
+ * counter after it never moves.
376
+ */
256
377
  function counters(theme: Theme, ...parts: [label: string, count: number][]): string {
257
378
  return parts
258
- .filter(([, count]) => count > 0)
259
- .map(
260
- ([label, count]) =>
261
- theme.fg("muted", label) + value(theme, formatTokens(count), COUNT_WIDTH),
379
+ .map(([label, count]) =>
380
+ padEnd(
381
+ count > 0 ? theme.fg("muted", label + formatTokens(count)) : "",
382
+ 1 + COUNT_WIDTH,
383
+ ),
262
384
  )
263
385
  .join(" ");
264
386
  }
265
387
 
388
+ /** A single counter with a slot to itself, drawn only once it is above zero. */
389
+ function counterSlot(keep: number, label: string, count: (usage: DockUsage) => number): StatSlot {
390
+ return {
391
+ keep,
392
+ width: 1 + COUNT_WIDTH,
393
+ hasData: ({ usage }) => count(usage) > 0,
394
+ render: ({ usage }, theme) => theme.fg("muted", label + formatTokens(count(usage))),
395
+ };
396
+ }
397
+
266
398
  /**
267
399
  * Which slots exist depends on the session, never on the numbers: auto-compaction is a setting
268
400
  * read once per session, so (auto) only claims its columns when it will be shown. Whether a slot
269
401
  * is drawn is a separate question, answered by `hasData`.
402
+ *
403
+ * Slots run from the one most likely to stay empty to the ones always drawn, so blank slots gather
404
+ * on the left, where they read as part of the gap after the directory, not as a hole between numbers.
405
+ * `keep` orders the drop independently: the counters and cost give way first, while the hit rate
406
+ * stays until only context and (auto) share the row.
270
407
  */
271
408
  function statSlots(status: DockStatus): StatSlot[] {
272
- const counterWidth = 2 * (1 + COUNT_WIDTH) + 1;
273
409
  const slots: StatSlot[] = [
410
+ // Cache writes come first: many providers never report them, and their slot then stays blank.
411
+ counterSlot(1, "W", (usage) => usage.cacheWrite),
412
+ counterSlot(2, "R", (usage) => usage.cacheRead),
274
413
  {
275
- keep: 3,
276
- width: counterWidth,
277
- hasData: ({ usage }) => usage.input > 0 || usage.output > 0,
278
- render: ({ usage }, theme) => counters(theme, ["↑", usage.input], ["↓", usage.output]),
279
- },
280
- {
281
- keep: 1,
282
- width: counterWidth,
283
- hasData: ({ usage }) => usage.cacheRead > 0 || usage.cacheWrite > 0,
284
- render: ({ usage }, theme) =>
285
- counters(theme, ["R", usage.cacheRead], ["W", usage.cacheWrite]),
286
- },
287
- {
288
- keep: 2,
289
- width: 2 + PERCENT_WIDTH,
414
+ keep: 5,
415
+ width: 3 + PERCENT_WIDTH,
290
416
  // A provider that reports no cache traffic has no hit rate worth quoting.
291
417
  hasData: ({ usage }) =>
292
418
  (usage.cacheRead > 0 || usage.cacheWrite > 0) && usage.cacheHitRate !== undefined,
293
419
  render: ({ usage }, theme) =>
294
- theme.fg("muted", "CH") +
295
- value(theme, formatPercent(usage.cacheHitRate ?? 0), PERCENT_WIDTH),
420
+ theme.fg("muted", `CH ${formatPercent(usage.cacheHitRate ?? 0)}`),
421
+ },
422
+ {
423
+ keep: 3,
424
+ width: 2 * (1 + COUNT_WIDTH) + 1,
425
+ hasData: ({ usage }) => usage.input > 0 || usage.output > 0,
426
+ render: ({ usage }, theme) => counters(theme, ["↑", usage.input], ["↓", usage.output]),
296
427
  },
297
428
  {
298
429
  keep: 4,
299
430
  width: COST_WIDTH,
300
431
  hasData: ({ usage }) => usage.cost > 0,
301
- render: ({ usage }, theme) => value(theme, formatCost(usage.cost), COST_WIDTH),
432
+ render: ({ usage }, theme) => theme.fg("muted", formatCost(usage.cost)),
302
433
  },
303
434
  {
304
- keep: 6,
435
+ keep: 7,
305
436
  width: CONTEXT_WIDTH,
306
437
  hasData: () => true,
307
438
  render: (current, theme) => renderContextCell(current, theme),
@@ -309,7 +440,7 @@ function statSlots(status: DockStatus): StatSlot[] {
309
440
  ];
310
441
  if (status.autoCompact) {
311
442
  slots.push({
312
- keep: 5,
443
+ keep: 6,
313
444
  width: 6,
314
445
  hasData: () => true,
315
446
  render: (_current, theme) => theme.fg("accent", "(auto)"),
@@ -318,8 +449,9 @@ function statSlots(status: DockStatus): StatSlot[] {
318
449
  return slots;
319
450
  }
320
451
 
452
+ /** Every slot spends one separator, before it: the first one divides the statistics from the directory. */
321
453
  function slotsWidth(slots: readonly StatSlot[]): number {
322
- return slots.reduce((sum, slot) => sum + slot.width, 0) + SEPARATOR_WIDTH * (slots.length - 1);
454
+ return slots.reduce((sum, slot) => sum + SEPARATOR_WIDTH + slot.width, 0);
323
455
  }
324
456
 
325
457
  /**
@@ -335,15 +467,46 @@ function fitSlots(slots: StatSlot[], budget: number): StatSlot[] {
335
467
  return kept;
336
468
  }
337
469
 
338
- /** Keeps the trailing segments, which name the project, and elides the leading ones. */
339
- function shortenPath(path: string, width: number): string {
340
- if (visibleWidth(path) <= width) return path;
470
+ /** The full path first, then fewer leading segments, down to the folder that names the project. */
471
+ function pathVariants(path: string): string[] {
341
472
  const segments = path.split(sep);
473
+ const variants = [path];
342
474
  for (let count = segments.length - 1; count >= 1; count--) {
343
475
  const candidate = `…${sep}${segments.slice(-count).join(sep)}`;
344
- if (visibleWidth(candidate) <= width) return candidate;
476
+ if (visibleWidth(candidate) < visibleWidth(variants.at(-1)!)) variants.push(candidate);
345
477
  }
346
- return truncateToWidth(segments.at(-1) ?? path, Math.max(0, width));
478
+ return variants;
479
+ }
480
+
481
+ interface WorkspaceText {
482
+ folder: string;
483
+ branch: string;
484
+ session: string;
485
+ }
486
+
487
+ function branchOnly(status: DockStatus): WorkspaceText | undefined {
488
+ return status.branch
489
+ ? { folder: "", branch: ` ${BRANCH_ICON} (${status.branch})`, session: "" }
490
+ : undefined;
491
+ }
492
+
493
+ /**
494
+ * The directory side of the info row, richest first. Leading path segments go first, then the
495
+ * session name, then the project folder; the branch stays as long as anything is drawn.
496
+ */
497
+ function workspaceVariants(status: DockStatus): WorkspaceText[] {
498
+ const branch = status.branch ? ` ${BRANCH_ICON} (${status.branch})` : "";
499
+ const session = status.sessionName ? ` • ${status.sessionName}` : "";
500
+ const folders = pathVariants(status.cwd).map((path) => ` ${FOLDER_ICON} ${path}`);
501
+ const variants = folders.map((folder) => ({ folder, branch, session: "" }));
502
+ if (session) variants.unshift(...folders.map((folder) => ({ folder, branch, session })));
503
+ const bare = branchOnly(status);
504
+ if (bare) variants.push(bare);
505
+ return variants;
506
+ }
507
+
508
+ function workspaceWidth(text: WorkspaceText): number {
509
+ return visibleWidth(text.folder + text.branch + text.session);
347
510
  }
348
511
 
349
512
  export interface InfoRowParts {
@@ -352,15 +515,44 @@ export interface InfoRowParts {
352
515
  }
353
516
 
354
517
  /**
355
- * Room kept for the directory and branch before any statistic is placed. A fixed share, not the
356
- * current path, so a branch switch cannot make a counter appear or vanish.
518
+ * The most the project folder and branch claim before any statistic is placed. Past it only the
519
+ * branch is reserved, so a long branch name costs the folder, not a statistic.
520
+ */
521
+ const MAX_WORKSPACE_RESERVE = 40;
522
+
523
+ /**
524
+ * Room kept for the project folder and branch; the leading path segments and the session name
525
+ * only use what the statistics leave. Neither the folder nor the branch changes with the numbers,
526
+ * so a counter appears or vanishes only when the terminal width or the branch changes.
357
527
  */
358
- const MIN_WORKSPACE_WIDTH = 40;
528
+ function workspaceReserve(status: DockStatus): number {
529
+ const variants = workspaceVariants(status);
530
+ const project = variants.findLast((text) => text.folder !== "")!;
531
+ const bare = branchOnly(status);
532
+ return Math.min(
533
+ workspaceWidth(project),
534
+ Math.max(MAX_WORKSPACE_RESERVE, bare ? workspaceWidth(bare) : 0),
535
+ );
536
+ }
537
+
538
+ function reserveSlots(status: DockStatus, width: number, workspace: boolean): StatSlot[] {
539
+ return fitSlots(statSlots(status), width - (workspace ? workspaceReserve(status) : 0));
540
+ }
359
541
 
360
542
  /**
361
- * Working directory and branch on the left, usage statistics right-aligned in reserved slots.
362
- * The slots reserved follow from the terminal width alone, and a slot with no data yet is simply
363
- * not drawn. Changing numbers only ever rewrite the padding inside their own slot.
543
+ * Where the info row draws the bar before each reserved slot, counted in columns from the right
544
+ * edge, leftmost first. The dock row reuses one for its model divider so both rows share a bar.
545
+ */
546
+ export function statColumns(status: DockStatus, width: number, workspace: boolean): number[] {
547
+ const slots = reserveSlots(status, width, workspace);
548
+ return slots.map((_slot, index) => slotsWidth(slots.slice(index)));
549
+ }
550
+
551
+ /**
552
+ * Working directory and branch on the left, usage statistics on a grid of reserved slots against
553
+ * the right edge. The grid follows from the terminal width, project folder and branch, and every
554
+ * slot keeps its columns whether or not it has data, so arriving or changing numbers never move a
555
+ * bar or a label.
364
556
  */
365
557
  export function renderInfoRow(
366
558
  status: DockStatus,
@@ -368,46 +560,41 @@ export function renderInfoRow(
368
560
  theme: Theme,
369
561
  parts: InfoRowParts = { workspace: true, usage: true },
370
562
  ): string {
371
- const branch = status.branch ? ` ${BRANCH_ICON} (${status.branch})` : "";
372
- const session = status.sessionName ? ` • ${status.sessionName}` : "";
373
- const fixedWidth = visibleWidth(` ${FOLDER_ICON} ${branch}${session}`);
374
-
375
- const bar = parts.workspace ? theme.fg("dim", CELL_SEPARATOR) : "";
376
- const budget = width - (parts.workspace ? MIN_WORKSPACE_WIDTH + visibleWidth(bar) : 0);
377
- const reserved = parts.usage ? fitSlots(statSlots(status), budget) : [];
378
- const slots = reserved.filter((slot) => slot.hasData(status));
379
- // The right block is right-aligned, so a slot gaining data never moves the slots to its right;
380
- // the directory is shortened against the full reservation so it does not move either.
381
- const reservedWidth = reserved.length > 0 ? visibleWidth(bar) + slotsWidth(reserved) : 0;
563
+ const reserved = parts.usage ? reserveSlots(status, width, parts.workspace) : [];
564
+ const reservedWidth = slotsWidth(reserved);
565
+ const firstDrawn = reserved.findIndex((slot) => slot.hasData(status));
566
+ const grid = reserved
567
+ .map((slot, index) => {
568
+ if (!slot.hasData(status)) return " ".repeat(SEPARATOR_WIDTH + slot.width);
569
+ // With no directory beside it, the leftmost bar would divide the statistics from nothing.
570
+ const bar =
571
+ index === firstDrawn && !parts.workspace
572
+ ? " ".repeat(SEPARATOR_WIDTH)
573
+ : theme.fg("dim", CELL_SEPARATOR);
574
+ return bar + padEnd(slot.render(status, theme), slot.width);
575
+ })
576
+ .join("");
577
+ // Only the context slot is left once even it overflows; its blank leading columns give way first.
382
578
  const right =
383
- slots.length > 0
384
- ? truncateToWidth(
385
- bar +
386
- slots
387
- .map((slot) => slot.render(status, theme))
388
- .join(theme.fg("dim", CELL_SEPARATOR)),
389
- width,
390
- )
391
- : "";
579
+ firstDrawn < 0
580
+ ? ""
581
+ : visibleWidth(grid) > width
582
+ ? truncateToWidth(grid.trimStart(), width)
583
+ : grid;
392
584
 
393
585
  let left = "";
394
586
  if (parts.workspace) {
395
- const cwd = shortenPath(status.cwd, width - reservedWidth - fixedWidth);
396
- left =
397
- ` ${theme.fg("muted", `${FOLDER_ICON} ${cwd}`)}` +
398
- (branch && theme.fg("accent", branch)) +
399
- theme.fg("dim", session);
587
+ // Fitted against the whole grid, not the drawn slots, so the directory does not move either.
588
+ const room = width - reservedWidth;
589
+ const text = workspaceVariants(status).find((variant) => workspaceWidth(variant) <= room);
590
+ if (text) {
591
+ left =
592
+ (text.folder && theme.fg("muted", text.folder)) +
593
+ (text.branch && theme.fg("accent", text.branch)) +
594
+ (text.session && theme.fg("dim", text.session));
595
+ }
400
596
  }
401
- const clipped = truncateToWidth(
402
- left,
403
- Math.max(0, width - visibleWidth(right)),
404
- theme.fg("dim", "…"),
405
- );
406
- return (
407
- clipped +
408
- " ".repeat(Math.max(0, width - visibleWidth(clipped) - visibleWidth(right))) +
409
- right
410
- );
597
+ return left + " ".repeat(Math.max(0, width - visibleWidth(left) - visibleWidth(right))) + right;
411
598
  }
412
599
 
413
600
  /** Statuses set through `ctx.ui.setStatus()` lived in Pi's footer, so the dock keeps showing them. */
package/src/index.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
- import { bindSettings, registerSettingsPanel, scopedExtension } from "@lune_99/pi-lune-extensions-core";
2
+ import {
3
+ bindSettings,
4
+ registerSettingsPanel,
5
+ scopedExtension,
6
+ } from "@lune_99/pi-lune-extensions-core";
3
7
  import { openSettingsPanel } from "@lune_99/pi-lune-extensions-core/panel/tui";
4
8
  import { DockController } from "./dock-controller.ts";
5
9
  import { dockPanel } from "./dock-panel.ts";
@@ -31,7 +35,10 @@ export default scopedExtension((pi, resources) => {
31
35
  }),
32
36
  );
33
37
  resources.defer(pi.on("session_before_tree", () => dock.resetInteraction()));
34
- resources.defer(pi.on("session_tree", () => dock.invalidate()));
38
+ resources.defer(pi.on("session_tree", () => dock.resetTokenSpeed()));
39
+ resources.defer(pi.on("message_start", (event, ctx) => dock.observeMessage(event, ctx)));
40
+ resources.defer(pi.on("message_update", (event, ctx) => dock.observeMessage(event, ctx)));
41
+ resources.defer(pi.on("message_end", (event, ctx) => dock.observeMessage(event, ctx)));
35
42
 
36
43
  pi.registerCommand("dock", {
37
44
  description: "Open Lune Dock settings",