pi-soly 2.5.0 → 2.5.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.
package/mcp/mcp-panel.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { matchesKey, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
2
2
  import { createPanelKeys, type PanelKeybindings, type PanelKeys } from "../visual/panel-keys.ts";
3
+ import { fuzzyScore } from "../visual/fuzzy.ts";
4
+ import { borderTop, borderBottom, borderDivider, borderRow, borderEmpty, type BorderStyler } from "../visual/border.ts";
3
5
  import { isToolExcluded } from "./types.ts";
4
6
  import type { McpConfig, McpPanelCallbacks, McpPanelResult, ServerProvenance } from "./types.ts";
5
7
  import { resourceNameToToolName } from "./resource-tools.ts";
@@ -55,24 +57,7 @@ function rainbowProgress(filled: number, total: number): string {
55
57
  return dots.join(" ");
56
58
  }
57
59
 
58
- function fuzzyScore(query: string, text: string): number {
59
- const lq = query.toLowerCase();
60
- const lt = text.toLowerCase();
61
- if (lt.includes(lq)) return 100 + (lq.length / lt.length) * 50;
62
- let score = 0;
63
- let qi = 0;
64
- let consecutive = 0;
65
- for (let i = 0; i < lt.length && qi < lq.length; i++) {
66
- if (lt[i] === lq[qi]) {
67
- score += 10 + consecutive;
68
- consecutive += 5;
69
- qi++;
70
- } else {
71
- consecutive = 0;
72
- }
73
- }
74
- return qi === lq.length ? score : 0;
75
- }
60
+ // fuzzyScore moved to ../visual/fuzzy.ts imported above.
76
61
 
77
62
  function estimateTokens(tool: CachedTool): number {
78
63
  const schemaLen = JSON.stringify(tool.inputSchema ?? {}).length;
@@ -599,18 +584,15 @@ class McpPanel {
599
584
  const italic = (s: string) => `\x1b[3m${s}\x1b[23m`;
600
585
  const inverse = (s: string) => `\x1b[7m${s}\x1b[27m`;
601
586
 
602
- const row = (content: string) =>
603
- fg(t.border, "│") + truncateToWidth(" " + content, innerW, "…", true) + fg(t.border, "│");
604
- const emptyRow = () => fg(t.border, "│") + " ".repeat(innerW) + fg(t.border, "│");
605
- const divider = () => fg(t.border, "├" + "─".repeat(innerW) + "┤");
587
+ // Shared border styler colors border chars via the panel theme.
588
+ const borderS: BorderStyler = (s: string) => fg(t.border, s);
589
+ const titleS: BorderStyler = (s: string) => fg(t.title, s);
590
+ const row = (content: string) => borderRow(content, innerW, borderS);
591
+ const emptyRow = () => borderEmpty(innerW, borderS);
592
+ const divider = () => borderDivider(innerW, borderS);
606
593
 
607
- const titleText = this.authOnly ? " MCP OAuth " : " MCP Servers ";
608
- const borderLen = innerW - visibleWidth(titleText);
609
- const leftB = Math.floor(borderLen / 2);
610
- const rightB = borderLen - leftB;
611
- lines.push(fg(t.border, "╭" + "─".repeat(leftB)) + fg(t.title, titleText) + fg(t.border, "─".repeat(rightB) + "╮"));
612
-
613
- lines.push(emptyRow());
594
+ const titleText = this.authOnly ? "MCP OAuth" : "MCP Servers";
595
+ lines.push(borderTop(titleText, innerW, borderS, titleS));
614
596
 
615
597
  const cursor = fg(t.selected, "│");
616
598
  const searchIcon = fg(t.border, "◎");
@@ -622,27 +604,21 @@ class McpPanel {
622
604
  lines.push(row(`${searchIcon} ${fg(t.placeholder, italic("search..."))}`));
623
605
  }
624
606
 
625
- lines.push(emptyRow());
626
607
  if (this.noticeLines.length > 0) {
627
608
  for (const notice of this.noticeLines) {
628
609
  lines.push(row(fg(t.hint, italic(notice))));
629
610
  }
630
- lines.push(emptyRow());
631
611
  }
632
612
  lines.push(divider());
633
613
 
634
614
  if (this.servers.length === 0) {
635
- lines.push(emptyRow());
636
615
  lines.push(row(fg(t.hint, italic(this.authOnly ? "No OAuth-capable MCP servers configured." : "No MCP servers configured."))));
637
- lines.push(emptyRow());
638
616
  } else {
639
617
  const maxVis = McpPanel.MAX_VISIBLE;
640
618
  const total = this.visibleItems.length;
641
619
  const startIdx = Math.max(0, Math.min(this.cursorIndex - Math.floor(maxVis / 2), total - maxVis));
642
620
  const endIdx = Math.min(startIdx + maxVis, total);
643
621
 
644
- lines.push(emptyRow());
645
-
646
622
  for (let i = startIdx; i < endIdx; i++) {
647
623
  const item = this.visibleItems[i];
648
624
  const isCursor = i === this.cursorIndex;
@@ -655,26 +631,20 @@ class McpPanel {
655
631
  }
656
632
  }
657
633
 
658
- lines.push(emptyRow());
659
-
660
634
  if (total > maxVis) {
661
635
  const prog = Math.round(((this.cursorIndex + 1) / total) * 10);
662
636
  lines.push(row(`${rainbowProgress(prog, 10)} ${fg(t.hint, `${this.cursorIndex + 1}/${total}`)}`));
663
- lines.push(emptyRow());
664
637
  }
665
638
 
666
639
  if (this.importNotice) {
667
640
  lines.push(row(fg(t.needsAuth, italic(this.importNotice))));
668
- lines.push(emptyRow());
669
641
  }
670
642
  if (this.authNotice) {
671
643
  lines.push(row(fg(t.needsAuth, italic(this.authNotice))));
672
- lines.push(emptyRow());
673
644
  }
674
645
  }
675
646
 
676
647
  lines.push(divider());
677
- lines.push(emptyRow());
678
648
 
679
649
  if (this.confirmingDiscard) {
680
650
  const discardBtn = this.discardSelected === 0
@@ -699,7 +669,6 @@ class McpPanel {
699
669
  }
700
670
  }
701
671
 
702
- lines.push(emptyRow());
703
672
  const hints = this.authOnly
704
673
  ? [
705
674
  italic("↑↓") + " navigate",
@@ -738,8 +707,7 @@ class McpPanel {
738
707
  }
739
708
  if (curLine) lines.push(row(fg(t.hint, curLine)));
740
709
 
741
- lines.push(fg(t.border, "╰" + "─".repeat(innerW) + "╯"));
742
-
710
+ lines.push(borderBottom(innerW, borderS));
743
711
  return lines;
744
712
  }
745
713
 
@@ -1,5 +1,6 @@
1
1
  import { matchesKey, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
2
2
  import { createPanelKeys, type PanelKeybindings, type PanelKeys } from "../visual/panel-keys.ts";
3
+ import { borderTop, borderBottom, borderDivider, borderRow, borderEmpty, type BorderStyler } from "../visual/border.ts";
3
4
  import type { ImportKind } from "./types.ts";
4
5
  import type { ConfigWritePreview, McpDiscoverySummary } from "./config.ts";
5
6
  import type { McpOnboardingState } from "./onboarding-state.ts";
@@ -345,22 +346,24 @@ export class McpSetupPanel {
345
346
  render(width: number): string[] {
346
347
  const innerW = Math.max(40, width - 2);
347
348
  const lines: string[] = [];
348
- const border = fg(this.t.border, "─".repeat(innerW));
349
- lines.push(`┌${border}┐`);
350
- lines.push(this.padLine(fg(this.t.title, "MCP setup"), innerW));
351
- lines.push(this.padLine(this.discoverySummaryLine(), innerW));
352
- lines.push(this.padLine(fg(this.t.muted, this.secondarySummaryLine()), innerW));
353
- lines.push(this.padLine("", innerW));
349
+ const borderS: BorderStyler = (s: string) => fg(this.t.border, s);
350
+ const row = (content: string) => borderRow(content, innerW, borderS);
351
+
352
+ lines.push(borderTop("", innerW, borderS));
353
+ lines.push(row(fg(this.t.title, "MCP setup")));
354
+ lines.push(row(this.discoverySummaryLine()));
355
+ lines.push(row(fg(this.t.muted, this.secondarySummaryLine())));
356
+ lines.push(borderEmpty(innerW, borderS));
354
357
 
355
358
  if (this.notice) {
356
359
  const tone = this.notice.tone === "success" ? this.t.success : this.notice.tone === "warning" ? this.t.warning : this.t.hint;
357
360
  for (const line of wrapText(this.notice.text, innerW - 6)) {
358
- lines.push(this.padLine(fg(tone, line), innerW));
361
+ lines.push(row(fg(tone, line)));
359
362
  }
360
- lines.push(this.padLine("", innerW));
363
+ lines.push(borderEmpty(innerW, borderS));
361
364
  }
362
365
 
363
- lines.push(`├${border}┤`);
366
+ lines.push(borderDivider(innerW, borderS));
364
367
 
365
368
  if (this.screen === "imports") {
366
369
  lines.push(...this.renderImports(innerW));
@@ -370,7 +373,7 @@ export class McpSetupPanel {
370
373
  lines.push(...this.renderActions(innerW));
371
374
  }
372
375
 
373
- lines.push(`└${border}┘`);
376
+ lines.push(borderBottom(innerW, borderS));
374
377
  return lines;
375
378
  }
376
379
 
@@ -554,12 +557,7 @@ export class McpSetupPanel {
554
557
  }
555
558
 
556
559
  private padLine(text: string, innerW: number): string {
557
- const inset = 2;
558
- const contentW = Math.max(0, innerW - inset * 2);
559
- const fitted = truncateToWidth(text, contentW, "…", true);
560
- const plainWidth = visibleWidth(fitted);
561
- const padding = Math.max(0, contentW - plainWidth);
562
- return `│${" ".repeat(inset)}${fitted}${" ".repeat(padding)}${" ".repeat(inset)}│`;
560
+ return borderRow(text, innerW, (s) => fg(this.t.border, s));
563
561
  }
564
562
 
565
563
  invalidate(): void {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-soly",
3
- "version": "2.5.0",
3
+ "version": "2.5.1",
4
4
  "description": "Workflow + project management for pi-coding-agent. Plans, state, MANDATORY rules, self-review, multi-question picker. One npm install, zero config. LLM drives the workflow inline via the soly_workflow tool — no external subagent plugin.",
5
5
  "type": "module",
6
6
  "main": "index.ts",
@@ -0,0 +1,64 @@
1
+ // =============================================================================
2
+ // visual/border.ts — shared rounded-border renderer for modal panels
3
+ // =============================================================================
4
+ //
5
+ // All soly modal panels (ListPanel, McpPanel, McpSetupPanel) draw bordered
6
+ // boxes. Before this module, each had its own helpers:
7
+ // - list-panel: frame(), headerLine(), footerLine(), ruleLine() (┌┐└┘)
8
+ // - mcp-panel: row(), emptyRow(), divider() (╭╮╰╯ + raw ANSI)
9
+ // - mcp-setup: padLine() (┌┐└┘)
10
+ //
11
+ // This module unifies them under one API with rounded corners (╭╮╰╯├┤│─).
12
+ // Each function takes a `styler` ((s: string) => string) so it works with
13
+ // any color system — pi's Theme.fg(), mcp-panel's fg(), or identity in tests.
14
+ //
15
+ // All width math uses pi-tui's visibleWidth/truncateToWidth so ANSI color
16
+ // codes inside `content` never break alignment (same approach as list-panel).
17
+ // =============================================================================
18
+
19
+ import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
20
+
21
+ /** Colors the border characters. Identity (s => s) in tests. */
22
+ export type BorderStyler = (s: string) => string;
23
+
24
+ /** Top border with a centered title: `╭── title ──╮`. */
25
+ export function borderTop(title: string, innerW: number, styler: BorderStyler, titleStyler?: BorderStyler): string {
26
+ const ts = titleStyler ?? styler;
27
+ const titleW = visibleWidth(title);
28
+ const dashTotal = Math.max(0, innerW - titleW);
29
+ const leftDash = Math.floor(dashTotal / 2);
30
+ const rightDash = dashTotal - leftDash;
31
+ return styler("╭" + "─".repeat(leftDash)) + ts(title) + styler("─".repeat(rightDash) + "╮");
32
+ }
33
+
34
+ /** Bottom border: `╰──...──╯`. */
35
+ export function borderBottom(innerW: number, styler: BorderStyler): string {
36
+ return styler("╰" + "─".repeat(innerW) + "╯");
37
+ }
38
+
39
+ /** Mid-panel divider: `├──...──┤`. */
40
+ export function borderDivider(innerW: number, styler: BorderStyler): string {
41
+ return styler("├" + "─".repeat(innerW) + "┤");
42
+ }
43
+
44
+ /** Labelled divider inside the panel: `├── label ──┤`. */
45
+ export function borderLabelledDivider(label: string, innerW: number, styler: BorderStyler, labelStyler?: BorderStyler): string {
46
+ const ls = labelStyler ?? styler;
47
+ const head = `─ ${label} `;
48
+ const dashN = Math.max(0, innerW - visibleWidth(head) - 1);
49
+ return styler("├ ") + ls(head) + styler("─".repeat(dashN) + "┤");
50
+ }
51
+
52
+ /** Content row: `│ content │` (truncated with `…` if too wide, padded if short). */
53
+ export function borderRow(content: string, innerW: number, styler: BorderStyler): string {
54
+ const truncated = visibleWidth(content) > innerW
55
+ ? truncateToWidth(content, innerW, "…", true)
56
+ : content;
57
+ const pad = Math.max(0, innerW - visibleWidth(truncated));
58
+ return styler("│ ") + truncated + " ".repeat(pad) + styler(" │");
59
+ }
60
+
61
+ /** Empty row: `│ │`. */
62
+ export function borderEmpty(innerW: number, styler: BorderStyler): string {
63
+ return styler("│") + " ".repeat(innerW) + styler("│");
64
+ }
@@ -0,0 +1,26 @@
1
+ // =============================================================================
2
+ // visual/fuzzy.ts — shared subsequence fuzzy match scorer
3
+ // =============================================================================
4
+ //
5
+ // Extracted from list-panel.ts (where it was duplicated in mcp-panel.ts).
6
+ // Pure function, no deps — trivially testable.
7
+ //
8
+ // Scoring:
9
+ // - exact substring match: 100 + (queryLen / textLen) — highest
10
+ // - in-order subsequence: 1 — match but not contiguous
11
+ // - no match: 0
12
+ // =============================================================================
13
+
14
+ /** Subsequence fuzzy match: substring scores highest, then in-order chars.
15
+ * Returns 0 for no match, >0 for a match. */
16
+ export function fuzzyScore(query: string, text: string): number {
17
+ const q = query.toLowerCase();
18
+ const t = text.toLowerCase();
19
+ if (!q) return 1;
20
+ if (t.includes(q)) return 100 + q.length / t.length;
21
+ let qi = 0;
22
+ for (let i = 0; i < t.length && qi < q.length; i++) {
23
+ if (t[i] === q[qi]) qi++;
24
+ }
25
+ return qi === q.length ? 1 : 0;
26
+ }
@@ -16,6 +16,7 @@ import { matchesKey, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@ea
16
16
  import type { Component, TUI } from "@earendil-works/pi-tui";
17
17
  import type { Theme } from "@earendil-works/pi-coding-agent";
18
18
  import { createPanelKeys, type PanelKeybindings, type PanelKeys } from "./panel-keys.ts";
19
+ import { fuzzyScore } from "./fuzzy.ts";
19
20
  // (PanelKeybindings re-exported by re-export side below.)
20
21
 
21
22
  /** One row in the panel. `body` is shown in the preview pane when selected. */
@@ -60,15 +61,7 @@ const MAX_ROWS = 12; // list window height (render() has no viewport height)
60
61
  const PREVIEW_LINES = 4;
61
62
 
62
63
  /** Subsequence fuzzy match: substring scores highest, then in-order chars. */
63
- function fuzzyScore(query: string, text: string): number {
64
- const q = query.toLowerCase();
65
- const t = text.toLowerCase();
66
- if (!q) return 1;
67
- if (t.includes(q)) return 100 + q.length / t.length;
68
- let qi = 0;
69
- for (let i = 0; i < t.length && qi < q.length; i++) if (t[i] === q[qi]) qi++;
70
- return qi === q.length ? 1 : 0;
71
- }
64
+ // fuzzyScore moved to ./fuzzy.ts imported above.
72
65
 
73
66
  /** Index into `flatRows` (mixed item + group header rows). */
74
67
  type RowIndex = number;
@@ -253,7 +246,7 @@ export class ListPanel implements Component {
253
246
  const left = ` ${this.p.title} `;
254
247
  const right = this.p.headerRight ? ` ${this.p.headerRight} ` : "";
255
248
  const fillN = Math.max(1, inner + 2 - visibleWidth(left) - visibleWidth(right));
256
- return dim("") + muted(left) + dim("─".repeat(fillN)) + muted(right) + dim("");
249
+ return dim("") + muted(left) + dim("─".repeat(fillN)) + muted(right) + dim("");
257
250
  }
258
251
 
259
252
  private searchLine(inner: number, dim: (s: string) => string, muted: (s: string) => string): string {
@@ -289,6 +282,6 @@ export class ListPanel implements Component {
289
282
  const open = this.p.onSelect ? "⏎ open · " : "";
290
283
  const hint = ` ↑↓ move · ${open}/ search${acts ? " · " + acts : ""} · esc `;
291
284
  const fillN = Math.max(1, inner + 2 - visibleWidth(hint));
292
- return dim("") + dim(hint) + dim("─".repeat(fillN)) + dim("");
285
+ return dim("") + dim(hint) + dim("─".repeat(fillN)) + dim("");
293
286
  }
294
287
  }