@zhuxixi/pi-agent-board 0.13.0 → 0.13.1

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.
@@ -14,7 +14,7 @@ import { createJiggleRetryController } from "../core/pty-attach-jiggle-controlle
14
14
  import { createTerminalAttachClient } from "../core/terminal-attach-client.mjs";
15
15
  import { backgroundRgbFromTerminalColors, buildSettleSchemePatch, colorSchemeForBackgroundRgb, extractOscQuerySequences, resolveProbeApi, toColorSchemeReport } from "../core/terminal-query-sequences.mjs";
16
16
  import { REPLY_GUARD_WINDOW_MS, createReplyGuard, isReplyGuardEnabled } from "../core/terminal-reply-guard.mjs";
17
- import { clampInt, encodeWheelReport, fullscreenMouseEnableSequence, historyFloorAfterHydrate, resolveAttachMouseAction, resolveAttachWheelRoute, resolvePasteSelectionSource, resolveWheelLines, sameMousePoint, scrollableHistoryLines, scrollViewportTop, selectionDragScrollLines, selectionReleaseIsDrag, shouldMirrorSelectionToPrimary, shouldOwnOuterMouseMode, splitAttachInput, wheelScrollLinesUp } from "../core/pty-scroll.mjs";
17
+ import { clampInt, encodeWheelReport, fullscreenMouseEnableSequence, historyFloorAfterHydrate, isFullscreenSelectionEnd, resolveAttachMouseAction, resolveAttachWheelRoute, resolvePasteSelectionSource, resolveWheelLines, sameMousePoint, scrollableHistoryLines, scrollViewportTop, selectionDragScrollLines, selectionReleaseIsDrag, shouldOwnOuterMouseMode, splitAttachInput, wheelScrollLinesUp } from "../core/pty-scroll.mjs";
18
18
 
19
19
  export type PtyAttachResult = { action: "detached" } | { action: "closed"; exitCode?: number | null } | { action: "delete" };
20
20
 
@@ -23,6 +23,16 @@ type ThemeLike = {
23
23
  bold(text: string): string;
24
24
  };
25
25
 
26
+ /** The pi-tui members the attach view reads without a public typing contract:
27
+ * getActiveSelectionText / clearTextSelection are private in TuiAltScreen's d.ts
28
+ * (runtime-reachable plain methods), getCopyOnSelect is public. Every access is
29
+ * feature-detected so an older or newer pi-tui degrades instead of throwing. */
30
+ interface FullscreenSelectionHost {
31
+ getActiveSelectionText?: () => string | undefined;
32
+ getCopyOnSelect?: () => boolean;
33
+ clearTextSelection?: () => void;
34
+ }
35
+
26
36
  /** Diagnostic patch emitted at attach settle (DiagnosticEvent-compatible; built by buildSettleSchemePatch). */
27
37
  export interface AttachSettleDiagnosticPatch {
28
38
  source: string;
@@ -239,6 +249,9 @@ export class PtyAttachComponent implements Component {
239
249
  /** Injectable clock for desync gating (tests override this). */
240
250
  private nowFn: () => number = () => Date.now();
241
251
  private selection: MouseSelection | null = null;
252
+ /** Issue #172: bumped on every left press so a settle still queued for the previous
253
+ * gesture cannot read or clear a selection the next press has already started. */
254
+ private selectionGestureSerial = 0;
242
255
  private selectionDragging = false;
243
256
  private selectionAutoScrollTimer: ReturnType<typeof setInterval> | null = null;
244
257
  private selectionAutoScrollLines = 0;
@@ -520,11 +533,19 @@ export class PtyAttachComponent implements Component {
520
533
  return { handled: true, render: false };
521
534
  }
522
535
  const nativePasteEnabled = process.env.AGENT_BOARD_ATTACH_NATIVE_PASTE !== "0";
523
- if (shouldMirrorSelectionToPrimary(event, { nativePasteEnabled })) {
524
- // Observe only — pi's fullscreen selection keeps the event. Mirroring must
525
- // run after TuiAltScreen finalizes the selection for this event (overlays
526
- // are dispatched before the selection logic), hence the deferred tick.
527
- process.nextTick(() => this.mirrorFullscreenSelectionToPrimary());
536
+ // Issue #172: a press starts a new gesture. Two reports can share one stdin chunk
537
+ // (pi-tui emits them synchronously in a loop), so the settle queued by the previous
538
+ // release must not consume the selection this press just started.
539
+ if (event.type === "press" && event.button === "left") this.selectionGestureSerial += 1;
540
+ if (isFullscreenSelectionEnd(event)) {
541
+ // Observe only — pi's fullscreen selection keeps the event. Overlays are
542
+ // dispatched before TuiAltScreen finalizes (and copies) the selection for this
543
+ // event, so settling must run deferred (issue #174).
544
+ const serial = this.selectionGestureSerial;
545
+ process.nextTick(() => {
546
+ if (serial !== this.selectionGestureSerial) return;
547
+ this.settleFullscreenSelection(nativePasteEnabled);
548
+ });
528
549
  return undefined;
529
550
  }
530
551
  const action = resolveAttachMouseAction(event, { nativePasteEnabled });
@@ -1367,17 +1388,24 @@ export class PtyAttachComponent implements Component {
1367
1388
  }
1368
1389
  }
1369
1390
 
1370
- /** Issue #174 (B2): after a selection gesture ends inside this overlay, copy
1371
- * pi's final selection text into the X11 PRIMARY selection so the classic
1372
- * select-then-middle-click-paste loop works in fullscreen. Runs on nextTick
1373
- * because overlays are dispatched before TuiAltScreen finalizes the
1374
- * selection for the same event. No-op in regular mode (no
1375
- * getActiveSelectionText) and under the native-paste kill switch. */
1376
- private mirrorFullscreenSelectionToPrimary(): void {
1391
+ /** Issue #174 (B2) + #172: a selection gesture ended inside this overlay and pi has
1392
+ * finalized (and copied) its selection. Mirror the text into X11 PRIMARY so
1393
+ * middle-click paste closes the loop, then drop pi's selection so the inverse-video
1394
+ * highlight does not outlive the copy. Clearing is skipped when copy-on-select is
1395
+ * off (the user copies later with pi's Ctrl+X) and when the pi-tui method is absent
1396
+ * (older/newer runtime) — both degrade to the previous behaviour instead of throwing.
1397
+ * clearTextSelection preserves pi's multi-click history; resetTextSelection would
1398
+ * clear lastClick and break double-click word / triple-click line selection. */
1399
+ private settleFullscreenSelection(nativePasteEnabled: boolean): void {
1377
1400
  if (this.closed) return;
1378
- const alt = this.tui as { getActiveSelectionText?: () => string | undefined };
1401
+ const alt = this.tui as FullscreenSelectionHost;
1379
1402
  const text = alt.getActiveSelectionText?.();
1380
- if (typeof text === "string" && text.length > 0) this.writePrimarySelection(text);
1403
+ if (typeof text !== "string" || text.length === 0) return;
1404
+ if (nativePasteEnabled) this.writePrimarySelection(text);
1405
+ if (alt.getCopyOnSelect?.() === false) return;
1406
+ if (typeof alt.clearTextSelection !== "function") return;
1407
+ alt.clearTextSelection();
1408
+ this.scheduleRender();
1381
1409
  }
1382
1410
 
1383
1411
  /** Write `text` to the X11 PRIMARY selection so other apps can middle-click-paste it. */