@humain/terminal 0.1.1 → 0.2.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.
Files changed (193) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/bundle/chunks/{anthropic-messages-XULXUBIG.js → anthropic-messages-QFCEKGI3.js} +1 -1
  3. package/dist/bundle/chunks/{azure-openai-responses-JEG2XOYC.js → azure-openai-responses-G4ZMHV37.js} +1 -1
  4. package/dist/bundle/chunks/chunk-7T6XCLJF.js +22 -0
  5. package/dist/bundle/chunks/chunk-D6HHRSB5.js +103 -0
  6. package/dist/bundle/chunks/chunk-EY4DWHQU.js +2 -0
  7. package/dist/bundle/chunks/{chunk-LYAMSPR2.js → chunk-I47ZWR55.js} +483 -506
  8. package/dist/bundle/chunks/{chunk-JUPSJTFQ.js → chunk-K4JAZYQH.js} +1 -1
  9. package/dist/bundle/chunks/{chunk-HPPQHK3J.js → chunk-KKIB2TVR.js} +1 -1
  10. package/dist/bundle/chunks/chunk-LI2YVPWP.js +2 -0
  11. package/dist/bundle/chunks/{chunk-BZQ53VGE.js → chunk-XSR434CO.js} +1 -1
  12. package/dist/bundle/chunks/compat-QCV26HNS.js +2 -0
  13. package/dist/bundle/chunks/dist-PRPIUY3U.js +2 -0
  14. package/dist/bundle/chunks/esm-E7UVEYTO.js +4 -0
  15. package/dist/bundle/chunks/{extract-TRW5FBY6.js → extract-CTIFQZDJ.js} +15 -14
  16. package/dist/bundle/chunks/{google-generative-ai-OX6VSCA6.js → google-generative-ai-RSUU4MWO.js} +1 -1
  17. package/dist/bundle/chunks/{google-vertex-GW76GSS2.js → google-vertex-CKQPOITO.js} +1 -1
  18. package/dist/bundle/chunks/host-WP3MVKS2.js +2 -0
  19. package/dist/bundle/chunks/{node-KOIP55YZ.js → node-NF43OPII.js} +1 -1
  20. package/dist/bundle/chunks/{node-XY3CBY3C.js → node-UMFM7CDZ.js} +1 -1
  21. package/dist/bundle/chunks/{openai-codex-responses-NPLWP6ZC.js → openai-codex-responses-S34V5ZSD.js} +1 -1
  22. package/dist/bundle/chunks/{openai-completions-OT2GTJKC.js → openai-completions-T2IGVUEI.js} +1 -1
  23. package/dist/bundle/chunks/{openai-responses-5A6CR7GI.js → openai-responses-GYZODCT3.js} +1 -1
  24. package/dist/bundle/chunks/readability-LAGF34IB.js +3 -0
  25. package/dist/bundle/chunks/turndown.cjs-HRMZVRUL.js +2 -0
  26. package/dist/bundle/cli.js +1 -1
  27. package/dist/bundle/index.js +1 -1
  28. package/dist/bundle/rpc-entry.js +1 -1
  29. package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
  30. package/dist/core/tools/file-mutation-queue.js +21 -8
  31. package/dist/core/tools/file-mutation-queue.js.map +1 -1
  32. package/dist/core/tools/subagent-env.d.ts +18 -0
  33. package/dist/core/tools/subagent-env.d.ts.map +1 -0
  34. package/dist/core/tools/subagent-env.js +43 -0
  35. package/dist/core/tools/subagent-env.js.map +1 -0
  36. package/dist/core/tools/subagent-scheduler.d.ts +31 -0
  37. package/dist/core/tools/subagent-scheduler.d.ts.map +1 -0
  38. package/dist/core/tools/subagent-scheduler.js +203 -0
  39. package/dist/core/tools/subagent-scheduler.js.map +1 -0
  40. package/dist/core/tools/subagent.d.ts +83 -3
  41. package/dist/core/tools/subagent.d.ts.map +1 -1
  42. package/dist/core/tools/subagent.js +214 -76
  43. package/dist/core/tools/subagent.js.map +1 -1
  44. package/dist/humain/mcp-adapter/vendor/CHANGELOG.md +78 -0
  45. package/dist/humain/mcp-adapter/vendor/README.md +125 -19
  46. package/dist/humain/mcp-adapter/vendor/agent-plugin-loader.ts +69 -30
  47. package/dist/humain/mcp-adapter/vendor/agent-plugin-provenance.ts +36 -0
  48. package/dist/humain/mcp-adapter/vendor/claude-plugin-loader.ts +365 -0
  49. package/dist/humain/mcp-adapter/vendor/commands.ts +13 -15
  50. package/dist/humain/mcp-adapter/vendor/config.ts +198 -30
  51. package/dist/humain/mcp-adapter/vendor/consent-manager.ts +40 -9
  52. package/dist/humain/mcp-adapter/vendor/direct-tool-surface.ts +250 -0
  53. package/dist/humain/mcp-adapter/vendor/direct-tools.ts +9 -228
  54. package/dist/humain/mcp-adapter/vendor/dist/agent-plugin-loader.js +74 -32
  55. package/dist/humain/mcp-adapter/vendor/dist/agent-plugin-loader.js.map +1 -1
  56. package/dist/humain/mcp-adapter/vendor/dist/agent-plugin-provenance.d.ts +1 -0
  57. package/dist/humain/mcp-adapter/vendor/dist/agent-plugin-provenance.js +31 -0
  58. package/dist/humain/mcp-adapter/vendor/dist/agent-plugin-provenance.js.map +1 -0
  59. package/dist/humain/mcp-adapter/vendor/dist/claude-plugin-loader.d.ts +9 -0
  60. package/dist/humain/mcp-adapter/vendor/dist/claude-plugin-loader.js +362 -0
  61. package/dist/humain/mcp-adapter/vendor/dist/claude-plugin-loader.js.map +1 -0
  62. package/dist/humain/mcp-adapter/vendor/dist/config.d.ts +3 -1
  63. package/dist/humain/mcp-adapter/vendor/dist/config.js +189 -27
  64. package/dist/humain/mcp-adapter/vendor/dist/config.js.map +1 -1
  65. package/dist/humain/mcp-adapter/vendor/dist/metadata-cache.js +7 -16
  66. package/dist/humain/mcp-adapter/vendor/dist/metadata-cache.js.map +1 -1
  67. package/dist/humain/mcp-adapter/vendor/dist/package-mcp-loader.js +5 -17
  68. package/dist/humain/mcp-adapter/vendor/dist/package-mcp-loader.js.map +1 -1
  69. package/dist/humain/mcp-adapter/vendor/dist/types.d.ts +30 -4
  70. package/dist/humain/mcp-adapter/vendor/dist/types.js +26 -0
  71. package/dist/humain/mcp-adapter/vendor/dist/types.js.map +1 -1
  72. package/dist/humain/mcp-adapter/vendor/dist/utils.d.ts +6 -0
  73. package/dist/humain/mcp-adapter/vendor/dist/utils.js +65 -6
  74. package/dist/humain/mcp-adapter/vendor/dist/utils.js.map +1 -1
  75. package/dist/humain/mcp-adapter/vendor/host-html-template.ts +20 -19
  76. package/dist/humain/mcp-adapter/vendor/http-ca.ts +84 -0
  77. package/dist/humain/mcp-adapter/vendor/index.bundle.mjs +37102 -15103
  78. package/dist/humain/mcp-adapter/vendor/index.ts +828 -164
  79. package/dist/humain/mcp-adapter/vendor/init.ts +48 -10
  80. package/dist/humain/mcp-adapter/vendor/lazy-loader.ts +7 -0
  81. package/dist/humain/mcp-adapter/vendor/mcp-auth-fetch.ts +113 -0
  82. package/dist/humain/mcp-adapter/vendor/mcp-auth-flow.ts +256 -77
  83. package/dist/humain/mcp-adapter/vendor/mcp-auth.ts +316 -54
  84. package/dist/humain/mcp-adapter/vendor/mcp-code.ts +45 -18
  85. package/dist/humain/mcp-adapter/vendor/mcp-install.ts +60 -0
  86. package/dist/humain/mcp-adapter/vendor/mcp-oauth-provider.ts +70 -6
  87. package/dist/humain/mcp-adapter/vendor/mcp-output-guard.ts +53 -42
  88. package/dist/humain/mcp-adapter/vendor/mcp-panel-theme.ts +105 -0
  89. package/dist/humain/mcp-adapter/vendor/mcp-panel.ts +366 -331
  90. package/dist/humain/mcp-adapter/vendor/mcp-references.ts +9 -14
  91. package/dist/humain/mcp-adapter/vendor/mcp-script-worker.mjs +3 -1
  92. package/dist/humain/mcp-adapter/vendor/mcp-setup-panel.ts +383 -341
  93. package/dist/humain/mcp-adapter/vendor/mcp-status.ts +5 -0
  94. package/dist/humain/mcp-adapter/vendor/metadata-cache.ts +7 -16
  95. package/dist/humain/mcp-adapter/vendor/namespace-tools.ts +61 -3
  96. package/dist/humain/mcp-adapter/vendor/oauth.ts +6 -2
  97. package/dist/humain/mcp-adapter/vendor/package-mcp-loader.ts +5 -17
  98. package/dist/humain/mcp-adapter/vendor/package.json +13 -3
  99. package/dist/humain/mcp-adapter/vendor/prompts.ts +35 -3
  100. package/dist/humain/mcp-adapter/vendor/proxy-modes.ts +108 -7
  101. package/dist/humain/mcp-adapter/vendor/runtime-owner.ts +16 -1
  102. package/dist/humain/mcp-adapter/vendor/sampling-handler.ts +9 -32
  103. package/dist/humain/mcp-adapter/vendor/sandbox-proxy-template.ts +20 -93
  104. package/dist/humain/mcp-adapter/vendor/server-manager.ts +227 -40
  105. package/dist/humain/mcp-adapter/vendor/session-approvals.ts +187 -0
  106. package/dist/humain/mcp-adapter/vendor/skills/mcp-scripting/SKILL.md +9 -1
  107. package/dist/humain/mcp-adapter/vendor/state.ts +10 -1
  108. package/dist/humain/mcp-adapter/vendor/tool-approval.ts +10 -22
  109. package/dist/humain/mcp-adapter/vendor/tool-metadata.ts +14 -0
  110. package/dist/humain/mcp-adapter/vendor/types.ts +57 -4
  111. package/dist/humain/mcp-adapter/vendor/ui-server.ts +36 -28
  112. package/dist/humain/mcp-adapter/vendor/utils.ts +64 -6
  113. package/dist/humain/web-access/vendor/abortable.d.ts +3 -0
  114. package/dist/humain/web-access/vendor/abortable.d.ts.map +1 -0
  115. package/dist/humain/web-access/vendor/abortable.js +22 -0
  116. package/dist/humain/web-access/vendor/abortable.js.map +1 -0
  117. package/dist/humain/web-access/vendor/crawl4ai.d.ts +9 -0
  118. package/dist/humain/web-access/vendor/crawl4ai.d.ts.map +1 -0
  119. package/dist/humain/web-access/vendor/crawl4ai.js +187 -0
  120. package/dist/humain/web-access/vendor/crawl4ai.js.map +1 -0
  121. package/dist/humain/web-access/vendor/credential-source.d.ts.map +1 -1
  122. package/dist/humain/web-access/vendor/credential-source.js +1 -0
  123. package/dist/humain/web-access/vendor/credential-source.js.map +1 -1
  124. package/dist/humain/web-access/vendor/curator-page.d.ts.map +1 -1
  125. package/dist/humain/web-access/vendor/curator-page.js +20 -2
  126. package/dist/humain/web-access/vendor/curator-page.js.map +1 -1
  127. package/dist/humain/web-access/vendor/curator-run.d.ts +11 -0
  128. package/dist/humain/web-access/vendor/curator-run.d.ts.map +1 -0
  129. package/dist/humain/web-access/vendor/curator-run.js +38 -0
  130. package/dist/humain/web-access/vendor/curator-run.js.map +1 -0
  131. package/dist/humain/web-access/vendor/curator-server.d.ts +1 -0
  132. package/dist/humain/web-access/vendor/curator-server.d.ts.map +1 -1
  133. package/dist/humain/web-access/vendor/curator-server.js +2 -0
  134. package/dist/humain/web-access/vendor/curator-server.js.map +1 -1
  135. package/dist/humain/web-access/vendor/duckduckgo.d.ts.map +1 -1
  136. package/dist/humain/web-access/vendor/duckduckgo.js +1 -1
  137. package/dist/humain/web-access/vendor/duckduckgo.js.map +1 -1
  138. package/dist/humain/web-access/vendor/extract.d.ts +1 -1
  139. package/dist/humain/web-access/vendor/extract.d.ts.map +1 -1
  140. package/dist/humain/web-access/vendor/extract.js +58 -11
  141. package/dist/humain/web-access/vendor/extract.js.map +1 -1
  142. package/dist/humain/web-access/vendor/fetch-params.js +1 -1
  143. package/dist/humain/web-access/vendor/fetch-params.js.map +1 -1
  144. package/dist/humain/web-access/vendor/gemini-search.d.ts +2 -2
  145. package/dist/humain/web-access/vendor/gemini-search.d.ts.map +1 -1
  146. package/dist/humain/web-access/vendor/gemini-search.js +12 -5
  147. package/dist/humain/web-access/vendor/gemini-search.js.map +1 -1
  148. package/dist/humain/web-access/vendor/index.d.ts.map +1 -1
  149. package/dist/humain/web-access/vendor/index.js +23 -19
  150. package/dist/humain/web-access/vendor/index.js.map +1 -1
  151. package/dist/humain/web-access/vendor/openai-search.d.ts.map +1 -1
  152. package/dist/humain/web-access/vendor/openai-search.js +40 -14
  153. package/dist/humain/web-access/vendor/openai-search.js.map +1 -1
  154. package/dist/humain/web-access/vendor/page-query.d.ts.map +1 -1
  155. package/dist/humain/web-access/vendor/page-query.js +6 -2
  156. package/dist/humain/web-access/vendor/page-query.js.map +1 -1
  157. package/dist/humain/web-access/vendor/query-rewrite.d.ts.map +1 -1
  158. package/dist/humain/web-access/vendor/query-rewrite.js +6 -2
  159. package/dist/humain/web-access/vendor/query-rewrite.js.map +1 -1
  160. package/dist/humain/web-access/vendor/serpapi.d.ts +4 -0
  161. package/dist/humain/web-access/vendor/serpapi.d.ts.map +1 -0
  162. package/dist/humain/web-access/vendor/serpapi.js +215 -0
  163. package/dist/humain/web-access/vendor/serpapi.js.map +1 -0
  164. package/dist/humain/web-access/vendor/ssrf-protection.d.ts.map +1 -1
  165. package/dist/humain/web-access/vendor/ssrf-protection.js +5 -1
  166. package/dist/humain/web-access/vendor/ssrf-protection.js.map +1 -1
  167. package/dist/humain/web-access/vendor/storage.d.ts.map +1 -1
  168. package/dist/humain/web-access/vendor/storage.js +9 -0
  169. package/dist/humain/web-access/vendor/storage.js.map +1 -1
  170. package/dist/humain/web-access/vendor/summary-review.d.ts +1 -1
  171. package/dist/humain/web-access/vendor/summary-review.d.ts.map +1 -1
  172. package/dist/humain/web-access/vendor/summary-review.js +35 -24
  173. package/dist/humain/web-access/vendor/summary-review.js.map +1 -1
  174. package/dist/humain/web-access/vendor/utils.d.ts.map +1 -1
  175. package/dist/humain/web-access/vendor/utils.js +5 -3
  176. package/dist/humain/web-access/vendor/utils.js.map +1 -1
  177. package/dist/modes/json-event.d.ts +8 -0
  178. package/dist/modes/json-event.d.ts.map +1 -1
  179. package/dist/modes/json-event.js +17 -0
  180. package/dist/modes/json-event.js.map +1 -1
  181. package/dist/modes/print-mode.d.ts.map +1 -1
  182. package/dist/modes/print-mode.js +3 -2
  183. package/dist/modes/print-mode.js.map +1 -1
  184. package/docs/environment-variables.md +8 -0
  185. package/docs/json.md +16 -0
  186. package/npm-shrinkwrap.json +6 -6
  187. package/package.json +2 -2
  188. package/src/humain/mcp-adapter/UPSTREAM.md +56 -7
  189. package/src/humain/mcp-adapter/upstream.json +6 -4
  190. package/src/humain/mcp-adapter/vendor/CHANGELOG.md +78 -0
  191. package/src/humain/web-access/UPSTREAM.md +18 -8
  192. package/src/humain/web-access/upstream.json +6 -5
  193. package/dist/bundle/chunks/chunk-2LC3S3VV.js +0 -105
@@ -1,39 +1,17 @@
1
- import { matchesKey, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
1
+ import { Container, Text, matchesKey, truncateToWidth, visibleWidth, type Component } from "@earendil-works/pi-tui";
2
+ import type { Theme } from "@earendil-works/pi-coding-agent";
3
+ import { createMcpPanelTheme, McpPanelFrame, type McpPanelTheme } from "./mcp-panel-theme.ts";
2
4
  import { createPanelKeys, type PanelKeybindings, type PanelKeys } from "./panel-keys.ts";
3
5
  import type { ImportKind } from "./types.ts";
4
6
  import { getConfigDirName } from "./agent-dir.ts";
5
7
  import { KNOWN_SERVER_PRESETS, type ConfigWritePreview, type KnownServerPreset, type McpDiscoverySummary, type SharedConfigTarget } from "./config.ts";
6
8
  import type { McpOnboardingState } from "./onboarding-state.ts";
7
9
 
8
- interface SetupTheme {
9
- border: string;
10
- title: string;
11
- selected: string;
12
- hint: string;
13
- success: string;
14
- warning: string;
15
- muted: string;
16
- }
17
-
18
- const DEFAULT_THEME: SetupTheme = {
19
- border: "2",
20
- title: "36",
21
- selected: "32",
22
- hint: "2",
23
- success: "32",
24
- warning: "33",
25
- muted: "2;3",
26
- };
27
-
28
10
  const MIN_PANEL_WIDTH = 24;
29
11
  const COMPACT_WIDTH = 60;
30
12
  const COMPACT_ACTION_ROWS = 7;
31
13
  const DESKTOP_PREVIEW_WIDTH = 74;
32
14
 
33
- function fg(code: string, text: string): string {
34
- return code ? `\x1b[${code}m${text}\x1b[0m` : text;
35
- }
36
-
37
15
  function wrapText(text: string, width: number): string[] {
38
16
  if (width <= 8) return [text];
39
17
  const words = text.split(/\s+/).filter(Boolean);
@@ -69,6 +47,7 @@ export interface SetupPanelOptions {
69
47
  mode: "empty" | "setup";
70
48
  onboardingState: McpOnboardingState;
71
49
  keybindings?: PanelKeybindings;
50
+ theme?: Theme;
72
51
  }
73
52
 
74
53
  type Screen = "empty" | "setup" | "imports" | "paths";
@@ -88,11 +67,357 @@ type ActionId =
88
67
  interface Action {
89
68
  id: ActionId;
90
69
  label: string;
91
- description: string;
92
70
  preset?: KnownServerPreset;
93
71
  target?: SharedConfigTarget;
94
72
  }
95
73
 
74
+ interface McpSetupPanelViewState {
75
+ screen: Screen;
76
+ actionCursor: number;
77
+ importCursor: number;
78
+ pathCursor: number;
79
+ sharedConfigTarget: SharedConfigTarget;
80
+ selectedImports: ReadonlySet<ImportKind>;
81
+ notice: { text: string; tone: "success" | "warning" | "muted" } | null;
82
+ onboardingState: McpOnboardingState;
83
+ discovery: McpDiscoverySummary;
84
+ actions: readonly Action[];
85
+ detectedPaths: readonly string[];
86
+ }
87
+
88
+ /**
89
+ * The setup view owns component composition and display formatting. The panel
90
+ * below remains the controller for input routing, async actions, and timers.
91
+ */
92
+ class McpSetupPanelView implements Component {
93
+ private readonly container = new Container();
94
+
95
+ constructor(
96
+ private readonly getState: () => McpSetupPanelViewState,
97
+ private readonly callbacks: SetupPanelCallbacks,
98
+ private readonly theme: McpPanelTheme,
99
+ ) {}
100
+
101
+ render(width: number): string[] {
102
+ const panelWidth = Math.max(MIN_PANEL_WIDTH, width);
103
+ const innerWidth = panelWidth - 2;
104
+ const contentWidth = this.contentWidth(innerWidth);
105
+ const state = this.getState();
106
+ this.container.clear();
107
+
108
+ this.addFrame("┌", "┐");
109
+ this.addRow(this.theme.title("MCP setup"), innerWidth);
110
+ let discoveryTone = this.theme.hint;
111
+ if (!state.discovery.hasAnyConfig || (state.discovery.totalServerCount === 0 && (state.discovery.imports.length > 0 || !!state.discovery.repoPrompt.executablePath))) {
112
+ discoveryTone = this.theme.needsAuth;
113
+ }
114
+ for (const line of wrapText(this.discoverySummaryLine(state), contentWidth)) {
115
+ this.addRow(discoveryTone(line), innerWidth);
116
+ }
117
+ for (const line of wrapText(this.secondarySummaryLine(state), contentWidth)) {
118
+ this.addRow(this.theme.description(this.theme.italic(line)), innerWidth);
119
+ }
120
+ this.addRow("", innerWidth);
121
+
122
+ if (state.notice) {
123
+ let tone = this.theme.hint;
124
+ if (state.notice.tone === "success") {
125
+ tone = this.theme.confirm;
126
+ } else if (state.notice.tone === "warning") {
127
+ tone = this.theme.needsAuth;
128
+ }
129
+ for (const line of wrapText(state.notice.text, contentWidth)) {
130
+ this.addRow(tone(line), innerWidth);
131
+ }
132
+ this.addRow("", innerWidth);
133
+ }
134
+
135
+ this.addFrame("├", "┤");
136
+ if (state.screen === "imports") {
137
+ for (const line of this.renderImports(state, innerWidth)) this.addRow(line, innerWidth);
138
+ } else if (state.screen === "paths") {
139
+ for (const line of this.renderPaths(state)) this.addRow(line, innerWidth);
140
+ } else {
141
+ for (const line of this.renderActions(state, innerWidth)) this.addRow(line, innerWidth);
142
+ }
143
+ this.addFrame("└", "┘");
144
+ return this.container.render(panelWidth);
145
+ }
146
+
147
+ invalidate(): void {
148
+ this.container.invalidate();
149
+ }
150
+
151
+ private addFrame(left: string, right: string): void {
152
+ this.container.addChild(new McpPanelFrame(this.theme, left, right));
153
+ }
154
+
155
+ private addRow(content: string, innerWidth: number): void {
156
+ this.container.addChild(new Text(this.padLine(content, innerWidth), 0, 0));
157
+ }
158
+
159
+ private renderActions(state: McpSetupPanelViewState, innerWidth: number): string[] {
160
+ const lines: string[] = [];
161
+ const actions = state.actions;
162
+ const compact = innerWidth < COMPACT_WIDTH;
163
+ const { start, end } = compact
164
+ ? this.visibleActionRange(actions.length, state.actionCursor)
165
+ : { start: 0, end: actions.length };
166
+
167
+ if (start > 0) {
168
+ lines.push(this.theme.description(`… ${start} more above`));
169
+ }
170
+ for (let index = start; index < end; index++) {
171
+ const action = actions[index];
172
+ if (!action) continue;
173
+ if (action.id === "select-shared-target" && (index === start || actions[index - 1]?.id !== "select-shared-target")) {
174
+ lines.push(this.theme.title("Choose where new shared servers go"));
175
+ }
176
+ if (action.id === "add-known-server" && (index === start || actions[index - 1]?.id !== "add-known-server")) {
177
+ lines.push(this.theme.title(`Add a known server to ${this.sharedTargetLabel(state)}`));
178
+ }
179
+ const selected = index === state.actionCursor;
180
+ const cursor = selected ? this.theme.selected("›") : " ";
181
+ lines.push(`${cursor} ${truncateToWidth(action.label, this.contentWidth(innerWidth) - 2)}`);
182
+ }
183
+ if (end < actions.length) {
184
+ lines.push(this.theme.description(`… ${actions.length - end} more below`));
185
+ }
186
+ lines.push("");
187
+
188
+ const preview = this.getActionPreview(state, actions[state.actionCursor], this.previewWidth(innerWidth));
189
+ lines.push(...preview);
190
+ lines.push("");
191
+ const hint = compact ? "Enter select · Esc back" : "Enter selects, Esc goes back, Ctrl+C closes.";
192
+ lines.push(this.theme.description(hint));
193
+ return lines;
194
+ }
195
+
196
+ private renderImports(state: McpSetupPanelViewState, innerWidth: number): string[] {
197
+ const lines: string[] = [];
198
+ lines.push("Select compatibility imports. Space toggles, Enter saves, Esc goes back.");
199
+ lines.push("");
200
+ for (let index = 0; index < state.discovery.imports.length; index++) {
201
+ const entry = state.discovery.imports[index];
202
+ if (!entry) continue;
203
+ const selected = state.selectedImports.has(entry.kind) ? "[x]" : "[ ]";
204
+ const cursor = index === state.importCursor ? this.theme.selected("›") : " ";
205
+ lines.push(`${cursor} ${selected} ${entry.kind} ${entry.path}`);
206
+ }
207
+ lines.push("");
208
+ const selected = state.discovery.imports
209
+ .filter((entry) => state.selectedImports.has(entry.kind))
210
+ .map((entry) => entry.kind);
211
+ const preview = this.callbacks.previewImports(selected);
212
+ lines.push(...this.formatWritePreview("Compatibility import write preview", preview, [], this.previewWidth(innerWidth)));
213
+ return lines;
214
+ }
215
+
216
+ private renderPaths(state: McpSetupPanelViewState): string[] {
217
+ const lines: string[] = [];
218
+ lines.push("Select a detected config path to open. Enter opens it, Esc goes back.");
219
+ lines.push("");
220
+ for (let index = 0; index < state.detectedPaths.length; index++) {
221
+ const path = state.detectedPaths[index];
222
+ const cursor = index === state.pathCursor ? this.theme.selected("›") : " ";
223
+ if (path !== undefined) lines.push(`${cursor} ${path}`);
224
+ }
225
+ return lines;
226
+ }
227
+
228
+ private discoverySummaryLine(state: McpSetupPanelViewState): string {
229
+ if (!state.discovery.hasAnyConfig) {
230
+ return state.onboardingState.setupCompleted
231
+ ? "No MCP servers are active right now."
232
+ : "No MCP config is active yet.";
233
+ }
234
+
235
+ if (state.discovery.totalServerCount === 0 && (state.discovery.imports.length > 0 || !!state.discovery.repoPrompt.executablePath)) {
236
+ return "Pi found MCP-related setup options, but none are active in Pi yet.";
237
+ }
238
+
239
+ const shared = state.discovery.sources.filter((source) => source.kind === "shared" && source.serverCount > 0).length;
240
+ const piOwned = state.discovery.sources.filter((source) => source.kind === "pi" && source.serverCount > 0).length;
241
+ return `Detected ${state.discovery.totalServerCount} configured servers across ${shared} shared and ${piOwned} Pi-owned source${shared + piOwned === 1 ? "" : "s"}.`;
242
+ }
243
+
244
+ private secondarySummaryLine(state: McpSetupPanelViewState): string {
245
+ const hostNote = state.discovery.hostConfigs.length > 0
246
+ ? ` Host discovery is ${state.discovery.hostConfigDiscovery}; ${state.discovery.hostConfigs.length} host source${state.discovery.hostConfigs.length === 1 ? "" : "s"} detected.`
247
+ : "";
248
+ const conflictNote = state.discovery.conflicts.length > 0
249
+ ? ` ${state.discovery.conflicts.length} same-name conflict${state.discovery.conflicts.length === 1 ? "" : "s"} reported.`
250
+ : "";
251
+ if (!state.discovery.hasAnyConfig) {
252
+ return `Add shared servers to .mcp.json for this project/team or ~/.config/mcp/mcp.json for all projects. Adopt host imports or quick-add RepoPrompt from this screen.${hostNote}${conflictNote}`;
253
+ }
254
+ if (state.discovery.totalServerCount === 0 && state.discovery.imports.length > 0) {
255
+ return `Detected ${state.discovery.imports.length} compatibility import source${state.discovery.imports.length === 1 ? "" : "s"}. Adopt them into Pi or inspect the underlying files.${hostNote}${conflictNote}`;
256
+ }
257
+ return `Use .mcp.json for project/team servers or ~/.config/mcp/mcp.json for all projects. Pi-owned files are for compatibility imports and adapter-specific overrides, not another normal setup path.${hostNote}${conflictNote}`;
258
+ }
259
+
260
+ private visibleActionRange(total: number, cursor: number): { start: number; end: number } {
261
+ if (total <= COMPACT_ACTION_ROWS) return { start: 0, end: total };
262
+ const half = Math.floor(COMPACT_ACTION_ROWS / 2);
263
+ const start = Math.min(Math.max(0, cursor - half), Math.max(0, total - COMPACT_ACTION_ROWS));
264
+ return { start, end: Math.min(total, start + COMPACT_ACTION_ROWS) };
265
+ }
266
+
267
+ private contentWidth(innerWidth: number): number {
268
+ return Math.max(8, innerWidth - 4);
269
+ }
270
+
271
+ private previewWidth(innerWidth: number): number {
272
+ return Math.max(12, Math.min(DESKTOP_PREVIEW_WIDTH, this.contentWidth(innerWidth)));
273
+ }
274
+
275
+ private sharedTargetLabel(state: McpSetupPanelViewState): string {
276
+ return state.sharedConfigTarget === "project" ? "project .mcp.json" : "global ~/.config/mcp/mcp.json";
277
+ }
278
+
279
+ private getActionPreview(state: McpSetupPanelViewState, action?: Action, previewW = DESKTOP_PREVIEW_WIDTH): string[] {
280
+ switch (action?.id) {
281
+ case "run-setup":
282
+ return this.formatPreview([
283
+ "Run setup to adopt host-specific imports, inspect detected paths, and scaffold a minimal `.mcp.json` if needed.",
284
+ ], previewW);
285
+ case "adopt-imports":
286
+ return this.formatWritePreview(
287
+ "Compatibility import write preview",
288
+ this.callbacks.previewImports(state.discovery.imports
289
+ .filter((entry) => state.selectedImports.has(entry.kind))
290
+ .map((entry) => entry.kind)),
291
+ [
292
+ `Detected imports: ${state.discovery.imports.map((entry) => `${entry.kind} (${entry.serverCount} servers)`).join(", ")}`,
293
+ "Selected imports are written into the Pi agent dir config as Pi-owned compatibility state.",
294
+ ],
295
+ previewW,
296
+ );
297
+ case "select-shared-target":
298
+ return this.formatPreview([
299
+ action.target === "project" ? "Project target: .mcp.json" : "Global target: ~/.config/mcp/mcp.json",
300
+ "Known server presets and starter configs will be written to the selected normal MCP setup path.",
301
+ "Pi-owned mcp.json files remain compatibility and adapter-only override state.",
302
+ ], previewW);
303
+ case "view-example":
304
+ return this.formatPreview([
305
+ "Example shared `.mcp.json`:",
306
+ "{",
307
+ ' "mcpServers": {',
308
+ ' "chrome-devtools": {',
309
+ ' "command": "npx",',
310
+ ' "args": ["-y", "chrome-devtools-mcp@1.6.0"]',
311
+ " }",
312
+ " }",
313
+ "}",
314
+ "",
315
+ "Use Scaffold selected config when you want a safe empty shell instead of a live example server.",
316
+ ], previewW);
317
+ case "show-precedence":
318
+ return this.formatPreview([
319
+ "Recommended shared config:",
320
+ " project/team: .mcp.json",
321
+ " all projects: ~/.config/mcp/mcp.json",
322
+ "",
323
+ "Advanced compatibility and Pi-owned layers:",
324
+ " host imports, .agents files, package MCP manifests, and Pi overrides",
325
+ "",
326
+ "Read order (later entries win):",
327
+ "0. detected host configs (opt-in lowest-precedence fallback)",
328
+ "1. ~/.config/mcp/mcp.json",
329
+ "2. ~/.agents/mcp.json",
330
+ "3. ~/.agents/mcp/mcp.json",
331
+ "4. <Pi agent dir>/mcp.json",
332
+ "5. configured ancestor root to parent(cwd), farthest first (opt-in)",
333
+ ` per directory: .mcp.json, then ${getConfigDirName()}/mcp.json`,
334
+ "6. cwd/.mcp.json",
335
+ `7. cwd/${getConfigDirName()}/mcp.json`,
336
+ `Host discovery: ${state.discovery.hostConfigDiscovery}. Conflicts reported: ${state.discovery.conflicts.length}.`,
337
+ ...state.discovery.conflicts.slice(0, 8).map((conflict) =>
338
+ `${conflict.serverName}: ${conflict.sources.map((source) => source.path).join(" -> ")} (winner: ${conflict.winner.path})`,
339
+ ),
340
+ "Pi writes compatibility imports and adapter-only overrides to Pi-owned files.",
341
+ ], previewW);
342
+ case "open-paths":
343
+ return this.formatPreview(state.detectedPaths.length > 0
344
+ ? ["Detected paths:", ...state.detectedPaths]
345
+ : ["No config paths were detected."], previewW);
346
+ case "add-repoprompt": {
347
+ const repoPrompt = state.discovery.repoPrompt;
348
+ const preview = this.callbacks.previewRepoPrompt(state.sharedConfigTarget);
349
+ if (!preview) {
350
+ return this.formatPreview(["RepoPrompt is not available to add from this setup screen."], previewW);
351
+ }
352
+ return this.formatWritePreview(
353
+ "RepoPrompt write preview",
354
+ preview,
355
+ [
356
+ `Executable: ${repoPrompt.executablePath ?? "not found"}`,
357
+ `Target: ${this.sharedTargetLabel(state)}`,
358
+ `Server name: ${repoPrompt.serverName ?? "repoprompt"}`,
359
+ ],
360
+ previewW,
361
+ );
362
+ }
363
+ case "add-known-server": {
364
+ const preset = action.preset;
365
+ if (!preset) return this.formatPreview(["Known server preset is unavailable."], previewW);
366
+ return this.formatWritePreview(
367
+ `${preset.name} write preview`,
368
+ this.callbacks.previewKnownServer(preset, state.sharedConfigTarget),
369
+ [preset.summary, `Target: ${this.sharedTargetLabel(state)}`],
370
+ previewW,
371
+ );
372
+ }
373
+ case "scaffold-shared-config":
374
+ return this.formatWritePreview(
375
+ `${this.sharedTargetLabel(state)} starter write preview`,
376
+ this.callbacks.previewStarterConfig(state.sharedConfigTarget),
377
+ [
378
+ "This writes a minimal config at the selected normal MCP setup path.",
379
+ "It intentionally avoids adding a fake placeholder server that would fail on first reload.",
380
+ ],
381
+ previewW,
382
+ );
383
+ case "close":
384
+ default:
385
+ return this.formatPreview(["Close the setup flow."], previewW);
386
+ }
387
+ }
388
+
389
+ private formatPreview(lines: string[], width = DESKTOP_PREVIEW_WIDTH): string[] {
390
+ const preview: string[] = [];
391
+ for (const line of lines) preview.push(...wrapText(line, width));
392
+ return preview;
393
+ }
394
+
395
+ private formatWritePreview(title: string, preview: ConfigWritePreview, intro: string[] = [], width = DESKTOP_PREVIEW_WIDTH): string[] {
396
+ const lines: string[] = [];
397
+ for (const line of intro) lines.push(...wrapText(line, width));
398
+ if (intro.length > 0) lines.push("");
399
+ lines.push(...wrapText(`${title}: ${preview.path}`, width));
400
+ lines.push(...wrapText(preview.existed ? "Existing file detected. Showing exact before/after diff." : "New file will be created. Showing exact content diff.", width));
401
+ lines.push("");
402
+ const diffLines = preview.diffText.split("\n");
403
+ const maxLines = 18;
404
+ const shown = diffLines.slice(0, maxLines);
405
+ for (const line of shown) lines.push(...wrapText(line, width));
406
+ if (diffLines.length > maxLines) {
407
+ lines.push(...wrapText(`… ${diffLines.length - maxLines} more diff line${diffLines.length - maxLines === 1 ? "" : "s"}`, width));
408
+ }
409
+ return lines;
410
+ }
411
+
412
+ private padLine(text: string, innerWidth: number): string {
413
+ const inset = 2;
414
+ const contentWidth = Math.max(0, innerWidth - inset * 2);
415
+ const fitted = truncateToWidth(text, contentWidth, "…", true);
416
+ const padding = Math.max(0, contentWidth - visibleWidth(fitted));
417
+ return `${this.theme.border("│")}${" ".repeat(inset)}${fitted}${" ".repeat(padding)}${" ".repeat(inset)}${this.theme.border("│")}`;
418
+ }
419
+ }
420
+
96
421
  export class McpSetupPanel {
97
422
  private screen: Screen;
98
423
  private actionCursor = 0;
@@ -103,7 +428,7 @@ export class McpSetupPanel {
103
428
  private busy = false;
104
429
  private notice: { text: string; tone: "success" | "warning" | "muted" } | null = null;
105
430
  private tui: { requestRender(): void };
106
- private t = DEFAULT_THEME;
431
+ private readonly view: McpSetupPanelView;
107
432
  private keys: PanelKeys;
108
433
  private inactivityTimeout: ReturnType<typeof setTimeout> | null = null;
109
434
  private static readonly INACTIVITY_MS = 60_000;
@@ -117,6 +442,7 @@ export class McpSetupPanel {
117
442
  ) {
118
443
  this.tui = tui;
119
444
  this.keys = createPanelKeys(options.keybindings);
445
+ this.view = new McpSetupPanelView(() => this.getViewState(), callbacks, createMcpPanelTheme(options.theme));
120
446
  this.screen = options.mode;
121
447
  for (const entry of discovery.imports) {
122
448
  this.selectedImports.add(entry.kind);
@@ -142,30 +468,30 @@ export class McpSetupPanel {
142
468
  private getActions(): Action[] {
143
469
  const actions: Action[] = [];
144
470
  if (this.screen === "empty") {
145
- actions.push({ id: "run-setup", label: "Run setup", description: "Inspect detected configs, adopt imports, and scaffold a minimal `.mcp.json`." });
471
+ actions.push({ id: "run-setup", label: "Run setup" });
146
472
  }
147
473
  if (this.discovery.imports.length > 0) {
148
- actions.push({ id: "adopt-imports", label: "Adopt detected compatibility imports", description: `Choose which host-specific MCP configs Pi should import into its own override file. ${this.discovery.imports.length} source${this.discovery.imports.length === 1 ? "" : "s"} found.` });
474
+ actions.push({ id: "adopt-imports", label: "Adopt detected compatibility imports" });
149
475
  }
150
476
  actions.push(
151
- { id: "select-shared-target", label: `${this.sharedConfigTarget === "project" ? "●" : "○"} Add to this project (.mcp.json)`, description: "Write new shared MCP servers to the project/team config.", target: "project" },
152
- { id: "select-shared-target", label: `${this.sharedConfigTarget === "global" ? "●" : "○"} Add globally (~/.config/mcp/mcp.json)`, description: "Write new shared MCP servers to your all-projects config.", target: "global" },
477
+ { id: "select-shared-target", label: `${this.sharedConfigTarget === "project" ? "●" : "○"} Add to this project (.mcp.json)`, target: "project" },
478
+ { id: "select-shared-target", label: `${this.sharedConfigTarget === "global" ? "●" : "○"} Add globally (~/.config/mcp/mcp.json)`, target: "global" },
153
479
  );
154
- actions.push({ id: "view-example", label: "View example shared config", description: "Preview a working shared MCP config you can paste or adapt." });
480
+ actions.push({ id: "view-example", label: "View example shared config" });
155
481
  if (!this.selectedSharedConfigExists()) {
156
- actions.push({ id: "scaffold-shared-config", label: `Scaffold ${this.sharedTargetLabel()}`, description: "Write a minimal config at the selected normal MCP setup path, then reload Pi." });
482
+ actions.push({ id: "scaffold-shared-config", label: `Scaffold ${this.sharedTargetLabel()}` });
157
483
  }
158
- actions.push({ id: "show-precedence", label: "Explain config precedence", description: "Show the read order and where Pi writes compatibility settings." });
484
+ actions.push({ id: "show-precedence", label: "Explain config precedence" });
159
485
  if (this.getDetectedPaths().length > 0) {
160
- actions.push({ id: "open-paths", label: "Open detected config paths", description: "Browse the actual config files that Pi discovered on this machine." });
486
+ actions.push({ id: "open-paths", label: "Open detected config paths" });
161
487
  }
162
488
  for (const preset of KNOWN_SERVER_PRESETS) {
163
- actions.push({ id: "add-known-server", label: preset.name, description: preset.summary, preset });
489
+ actions.push({ id: "add-known-server", label: preset.name, preset });
164
490
  }
165
491
  if (!this.discovery.repoPrompt.configured && this.discovery.repoPrompt.executablePath && this.discovery.repoPrompt.targetPath && this.discovery.repoPrompt.entry && this.discovery.repoPrompt.serverName) {
166
- actions.push({ id: "add-repoprompt", label: "Add RepoPrompt to selected shared config", description: "Write a standard MCP entry for RepoPrompt to the selected normal setup path, then reload MCP in-session." });
492
+ actions.push({ id: "add-repoprompt", label: "Add RepoPrompt to selected shared config" });
167
493
  }
168
- actions.push({ id: "close", label: "Close", description: "Exit the onboarding flow." });
494
+ actions.push({ id: "close", label: "Close" });
169
495
  return actions;
170
496
  }
171
497
 
@@ -186,11 +512,6 @@ export class McpSetupPanel {
186
512
  return this.discovery.sources.some((source) => source.id === sourceId && source.exists);
187
513
  }
188
514
 
189
- private getSelectedAction(): Action | undefined {
190
- const actions = this.getActions();
191
- return actions[this.actionCursor];
192
- }
193
-
194
515
  handleInput(data: string): void {
195
516
  this.resetInactivityTimeout();
196
517
  if (!this.busy) this.notice = null;
@@ -235,7 +556,7 @@ export class McpSetupPanel {
235
556
  return;
236
557
  }
237
558
  if (this.keys.selectConfirm(data)) {
238
- const selected = this.getSelectedAction();
559
+ const selected = actions[this.actionCursor];
239
560
  if (selected) void this.runAction(selected);
240
561
  }
241
562
  }
@@ -386,309 +707,30 @@ export class McpSetupPanel {
386
707
  }
387
708
  }
388
709
 
389
- render(width: number): string[] {
390
- const panelW = Math.max(MIN_PANEL_WIDTH, width);
391
- const innerW = panelW - 2;
392
- const contentW = this.contentWidth(innerW);
393
- const lines: string[] = [];
394
- const border = fg(this.t.border, "─".repeat(innerW));
395
- lines.push(`┌${border}┐`);
396
- lines.push(this.padLine(fg(this.t.title, "MCP setup"), innerW));
397
- for (const line of wrapText(this.discoverySummaryLine(), contentW)) {
398
- lines.push(this.padLine(line, innerW));
399
- }
400
- for (const line of wrapText(this.secondarySummaryLine(), contentW)) {
401
- lines.push(this.padLine(fg(this.t.muted, line), innerW));
402
- }
403
- lines.push(this.padLine("", innerW));
404
-
405
- if (this.notice) {
406
- const tone = this.notice.tone === "success" ? this.t.success : this.notice.tone === "warning" ? this.t.warning : this.t.hint;
407
- for (const line of wrapText(this.notice.text, contentW)) {
408
- lines.push(this.padLine(fg(tone, line), innerW));
409
- }
410
- lines.push(this.padLine("", innerW));
411
- }
412
-
413
- lines.push(`├${border}┤`);
414
-
415
- if (this.screen === "imports") {
416
- lines.push(...this.renderImports(innerW));
417
- } else if (this.screen === "paths") {
418
- lines.push(...this.renderPaths(innerW));
419
- } else {
420
- lines.push(...this.renderActions(innerW));
421
- }
422
-
423
- lines.push(`└${border}┘`);
424
- return lines;
425
- }
426
-
427
- private renderActions(innerW: number): string[] {
428
- const lines: string[] = [];
429
- const actions = this.getActions();
430
- const compact = innerW < COMPACT_WIDTH;
431
- const { start, end } = compact
432
- ? this.visibleActionRange(actions.length)
433
- : { start: 0, end: actions.length };
434
-
435
- if (start > 0) {
436
- lines.push(this.padLine(fg(this.t.muted, `… ${start} more above`), innerW));
437
- }
438
- for (let index = start; index < end; index++) {
439
- const action = actions[index];
440
- if (!action) continue;
441
- if (action.id === "select-shared-target" && (index === start || actions[index - 1]?.id !== "select-shared-target")) {
442
- lines.push(this.padLine(fg(this.t.title, "Choose where new shared servers go"), innerW));
443
- }
444
- if (action.id === "add-known-server" && (index === start || actions[index - 1]?.id !== "add-known-server")) {
445
- lines.push(this.padLine(fg(this.t.title, `Add a known server to ${this.sharedTargetLabel()}`), innerW));
446
- }
447
- const selected = index === this.actionCursor;
448
- const cursor = selected ? fg(this.t.selected, "›") : " ";
449
- lines.push(this.padLine(`${cursor} ${truncateToWidth(action.label, this.contentWidth(innerW) - 2)}`, innerW));
450
- }
451
- if (end < actions.length) {
452
- lines.push(this.padLine(fg(this.t.muted, `… ${actions.length - end} more below`), innerW));
453
- }
454
- lines.push(this.padLine("", innerW));
455
-
456
- const preview = this.getActionPreview(this.getSelectedAction(), this.previewWidth(innerW));
457
- for (const line of preview) {
458
- lines.push(this.padLine(line, innerW));
459
- }
460
- lines.push(this.padLine("", innerW));
461
- const hint = compact ? "Enter select · Esc back" : "Enter selects, Esc goes back, Ctrl+C closes.";
462
- lines.push(this.padLine(fg(this.t.muted, hint), innerW));
463
- return lines;
710
+ private getViewState(): McpSetupPanelViewState {
711
+ return {
712
+ screen: this.screen,
713
+ actionCursor: this.actionCursor,
714
+ importCursor: this.importCursor,
715
+ pathCursor: this.pathCursor,
716
+ sharedConfigTarget: this.sharedConfigTarget,
717
+ selectedImports: this.selectedImports,
718
+ notice: this.notice,
719
+ onboardingState: this.options.onboardingState,
720
+ discovery: this.discovery,
721
+ actions: this.getActions(),
722
+ detectedPaths: this.getDetectedPaths(),
723
+ };
464
724
  }
465
725
 
466
- private renderImports(innerW: number): string[] {
467
- const lines: string[] = [];
468
- lines.push(this.padLine("Select compatibility imports. Space toggles, Enter saves, Esc goes back.", innerW));
469
- lines.push(this.padLine("", innerW));
470
- for (let index = 0; index < this.discovery.imports.length; index++) {
471
- const entry = this.discovery.imports[index];
472
- if (!entry) continue;
473
- const selected = this.selectedImports.has(entry.kind) ? "[x]" : "[ ]";
474
- const cursor = index === this.importCursor ? fg(this.t.selected, "›") : " ";
475
- lines.push(this.padLine(`${cursor} ${selected} ${entry.kind} ${entry.path}`, innerW));
476
- }
477
- lines.push(this.padLine("", innerW));
478
- const selected = this.discovery.imports.filter((entry) => this.selectedImports.has(entry.kind)).map((entry) => entry.kind);
479
- const preview = this.callbacks.previewImports(selected);
480
- for (const line of this.formatWritePreview("Compatibility import write preview", preview, [], this.previewWidth(innerW))) {
481
- lines.push(this.padLine(line, innerW));
482
- }
483
- return lines;
484
- }
485
-
486
- private renderPaths(innerW: number): string[] {
487
- const lines: string[] = [];
488
- lines.push(this.padLine("Select a detected config path to open. Enter opens it, Esc goes back.", innerW));
489
- lines.push(this.padLine("", innerW));
490
- const paths = this.getDetectedPaths();
491
- for (let index = 0; index < paths.length; index++) {
492
- const cursor = index === this.pathCursor ? fg(this.t.selected, "›") : " ";
493
- const path = paths[index];
494
- if (path !== undefined) lines.push(this.padLine(`${cursor} ${path}`, innerW));
495
- }
496
- return lines;
497
- }
498
-
499
- private discoverySummaryLine(): string {
500
- if (!this.discovery.hasAnyConfig) {
501
- return fg(this.t.warning, this.options.onboardingState.setupCompleted
502
- ? "No MCP servers are active right now."
503
- : "No MCP config is active yet.");
504
- }
505
-
506
- if (this.discovery.totalServerCount === 0 && (this.discovery.imports.length > 0 || !!this.discovery.repoPrompt.executablePath)) {
507
- return fg(this.t.warning, "Pi found MCP-related setup options, but none are active in Pi yet.");
508
- }
509
-
510
- const shared = this.discovery.sources.filter((source) => source.kind === "shared" && source.serverCount > 0).length;
511
- const piOwned = this.discovery.sources.filter((source) => source.kind === "pi" && source.serverCount > 0).length;
512
- return fg(this.t.hint, `Detected ${this.discovery.totalServerCount} configured servers across ${shared} shared and ${piOwned} Pi-owned source${shared + piOwned === 1 ? "" : "s"}.`);
513
- }
514
-
515
- private secondarySummaryLine(): string {
516
- const hostNote = this.discovery.hostConfigs.length > 0
517
- ? ` Host discovery is ${this.discovery.hostConfigDiscovery}; ${this.discovery.hostConfigs.length} host source${this.discovery.hostConfigs.length === 1 ? "" : "s"} detected.`
518
- : "";
519
- const conflictNote = this.discovery.conflicts.length > 0
520
- ? ` ${this.discovery.conflicts.length} same-name conflict${this.discovery.conflicts.length === 1 ? "" : "s"} reported.`
521
- : "";
522
- if (!this.discovery.hasAnyConfig) {
523
- return `Add shared servers to .mcp.json for this project/team or ~/.config/mcp/mcp.json for all projects. Adopt host imports or quick-add RepoPrompt from this screen.${hostNote}${conflictNote}`;
524
- }
525
- if (this.discovery.totalServerCount === 0 && this.discovery.imports.length > 0) {
526
- return `Detected ${this.discovery.imports.length} compatibility import source${this.discovery.imports.length === 1 ? "" : "s"}. Adopt them into Pi or inspect the underlying files.${hostNote}${conflictNote}`;
527
- }
528
- return `Use .mcp.json for project/team servers or ~/.config/mcp/mcp.json for all projects. Pi-owned files are for compatibility imports and adapter-specific overrides, not another normal setup path.${hostNote}${conflictNote}`;
529
- }
530
-
531
- private visibleActionRange(total: number): { start: number; end: number } {
532
- if (total <= COMPACT_ACTION_ROWS) return { start: 0, end: total };
533
- const half = Math.floor(COMPACT_ACTION_ROWS / 2);
534
- const start = Math.min(Math.max(0, this.actionCursor - half), Math.max(0, total - COMPACT_ACTION_ROWS));
535
- return { start, end: Math.min(total, start + COMPACT_ACTION_ROWS) };
536
- }
537
-
538
- private contentWidth(innerW: number): number {
539
- return Math.max(8, innerW - 4);
540
- }
541
-
542
- private previewWidth(innerW: number): number {
543
- return Math.max(12, Math.min(DESKTOP_PREVIEW_WIDTH, this.contentWidth(innerW)));
544
- }
545
-
546
- private getActionPreview(action?: Action, previewW = DESKTOP_PREVIEW_WIDTH): string[] {
547
- switch (action?.id) {
548
- case "run-setup":
549
- return this.formatPreview([
550
- "Run setup to adopt host-specific imports, inspect detected paths, and scaffold a minimal `.mcp.json` if needed.",
551
- ], previewW);
552
- case "adopt-imports":
553
- return this.formatWritePreview(
554
- "Compatibility import write preview",
555
- this.callbacks.previewImports(this.discovery.imports.filter((entry) => this.selectedImports.has(entry.kind)).map((entry) => entry.kind)),
556
- [
557
- `Detected imports: ${this.discovery.imports.map((entry) => `${entry.kind} (${entry.serverCount} servers)`).join(", ")}`,
558
- "Selected imports are written into the Pi agent dir config as Pi-owned compatibility state.",
559
- ],
560
- previewW,
561
- );
562
- case "select-shared-target":
563
- return this.formatPreview([
564
- action.target === "project" ? "Project target: .mcp.json" : "Global target: ~/.config/mcp/mcp.json",
565
- "Known server presets and starter configs will be written to the selected normal MCP setup path.",
566
- "Pi-owned mcp.json files remain compatibility and adapter-only override state.",
567
- ], previewW);
568
- case "view-example":
569
- return this.formatPreview([
570
- "Example shared `.mcp.json`:",
571
- "{",
572
- ' "mcpServers": {',
573
- ' "chrome-devtools": {',
574
- ' "command": "npx",',
575
- ' "args": ["-y", "chrome-devtools-mcp@1.6.0"]',
576
- " }",
577
- " }",
578
- "}",
579
- "",
580
- "Use Scaffold selected config when you want a safe empty shell instead of a live example server.",
581
- ], previewW);
582
- case "show-precedence":
583
- return this.formatPreview([
584
- "Recommended shared config:",
585
- " project/team: .mcp.json",
586
- " all projects: ~/.config/mcp/mcp.json",
587
- "",
588
- "Advanced compatibility and Pi-owned layers:",
589
- " host imports, .agents files, package MCP manifests, and Pi overrides",
590
- "",
591
- "Read order (later entries win):",
592
- "0. detected host configs (opt-in lowest-precedence fallback)",
593
- "1. ~/.config/mcp/mcp.json",
594
- "2. ~/.agents/mcp.json",
595
- "3. ~/.agents/mcp/mcp.json",
596
- "4. <Pi agent dir>/mcp.json",
597
- "5. .mcp.json",
598
- `6. ${getConfigDirName()}/mcp.json`,
599
- `Host discovery: ${this.discovery.hostConfigDiscovery}. Conflicts reported: ${this.discovery.conflicts.length}.`,
600
- ...this.discovery.conflicts.slice(0, 8).map((conflict) =>
601
- `${conflict.serverName}: ${conflict.sources.map((source) => source.path).join(" -> ")} (winner: ${conflict.winner.path})`,
602
- ),
603
- "Pi writes compatibility imports and adapter-only overrides to Pi-owned files."
604
- ], previewW);
605
- case "open-paths":
606
- return this.formatPreview(this.getDetectedPaths().length > 0
607
- ? ["Detected paths:", ...this.getDetectedPaths()]
608
- : ["No config paths were detected."], previewW);
609
- case "add-repoprompt": {
610
- const repoPrompt = this.discovery.repoPrompt;
611
- const preview = this.callbacks.previewRepoPrompt(this.sharedConfigTarget);
612
- if (!preview) {
613
- return this.formatPreview(["RepoPrompt is not available to add from this setup screen."], previewW);
614
- }
615
- return this.formatWritePreview(
616
- "RepoPrompt write preview",
617
- preview,
618
- [
619
- `Executable: ${repoPrompt.executablePath ?? "not found"}`,
620
- `Target: ${this.sharedTargetLabel()}`,
621
- `Server name: ${repoPrompt.serverName ?? "repoprompt"}`,
622
- ],
623
- previewW,
624
- );
625
- }
626
- case "add-known-server": {
627
- const preset = action.preset;
628
- if (!preset) return this.formatPreview(["Known server preset is unavailable."], previewW);
629
- return this.formatWritePreview(
630
- `${preset.name} write preview`,
631
- this.callbacks.previewKnownServer(preset, this.sharedConfigTarget),
632
- [preset.summary, `Target: ${this.sharedTargetLabel()}`],
633
- previewW,
634
- );
635
- }
636
- case "scaffold-shared-config":
637
- return this.formatWritePreview(
638
- `${this.sharedTargetLabel()} starter write preview`,
639
- this.callbacks.previewStarterConfig(this.sharedConfigTarget),
640
- [
641
- "This writes a minimal config at the selected normal MCP setup path.",
642
- "It intentionally avoids adding a fake placeholder server that would fail on first reload.",
643
- ],
644
- previewW,
645
- );
646
- case "close":
647
- default:
648
- return this.formatPreview(["Close the setup flow."], previewW);
649
- }
650
- }
651
-
652
- private formatPreview(lines: string[], width = DESKTOP_PREVIEW_WIDTH): string[] {
653
- const preview: string[] = [];
654
- for (const line of lines) {
655
- preview.push(...wrapText(line, width));
656
- }
657
- return preview;
658
- }
659
-
660
- private formatWritePreview(title: string, preview: ConfigWritePreview, intro: string[] = [], width = DESKTOP_PREVIEW_WIDTH): string[] {
661
- const lines: string[] = [];
662
- for (const line of intro) {
663
- lines.push(...wrapText(line, width));
664
- }
665
- if (intro.length > 0) lines.push("");
666
- lines.push(...wrapText(`${title}: ${preview.path}`, width));
667
- lines.push(...wrapText(preview.existed ? "Existing file detected. Showing exact before/after diff." : "New file will be created. Showing exact content diff.", width));
668
- lines.push("");
669
- const diffLines = preview.diffText.split("\n");
670
- const maxLines = 18;
671
- const shown = diffLines.slice(0, maxLines);
672
- for (const line of shown) {
673
- lines.push(...wrapText(line, width));
674
- }
675
- if (diffLines.length > maxLines) {
676
- lines.push(...wrapText(`… ${diffLines.length - maxLines} more diff line${diffLines.length - maxLines === 1 ? "" : "s"}`, width));
677
- }
678
- return lines;
726
+ render(width: number): string[] {
727
+ return this.view.render(width);
679
728
  }
680
729
 
681
- private padLine(text: string, innerW: number): string {
682
- const inset = 2;
683
- const contentW = Math.max(0, innerW - inset * 2);
684
- const fitted = truncateToWidth(text, contentW, "…", true);
685
- const plainWidth = visibleWidth(fitted);
686
- const padding = Math.max(0, contentW - plainWidth);
687
- return `│${" ".repeat(inset)}${fitted}${" ".repeat(padding)}${" ".repeat(inset)}│`;
730
+ invalidate(): void {
731
+ this.view.invalidate();
688
732
  }
689
733
 
690
- invalidate(): void {}
691
-
692
734
  dispose(): void {
693
735
  this.cleanup();
694
736
  }