@duckmind/dm-windows-x64 0.63.4 → 0.63.9

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 (121) hide show
  1. package/dm.exe +0 -0
  2. package/extensions/.dm-extensions.json +236 -13
  3. package/extensions/dm-context/package.json +1 -1
  4. package/extensions/dm-context/skills/context-management/SKILL.md +173 -223
  5. package/extensions/dm-context/skills/context-management/references/development-and-troubleshooting.md +75 -0
  6. package/extensions/dm-context/skills/context-management/references/interleaved-async-work.md +143 -0
  7. package/extensions/dm-context/skills/context-management/references/planning-and-execution.md +81 -0
  8. package/extensions/dm-context/skills/context-management/references/repeated-items-and-batch-work.md +69 -0
  9. package/extensions/dm-context/skills/context-management/references/retry-branch-and-pivot.md +80 -0
  10. package/extensions/dm-context/skills/context-management/references/search-research-and-reading.md +103 -0
  11. package/extensions/dm-context/skills/context-management/references/task-switching-and-cleanup.md +73 -0
  12. package/extensions/dm-context/src/context.js +3 -2
  13. package/extensions/dm-context/src/index.js +168 -84
  14. package/extensions/dm-mcp-adapter/OAUTH.md +3 -0
  15. package/extensions/dm-mcp-adapter/THIRD_PARTY_NOTICES.md +4 -0
  16. package/extensions/dm-mcp-adapter/abort.js +35 -0
  17. package/extensions/dm-mcp-adapter/agent-dir.js +45 -0
  18. package/extensions/dm-mcp-adapter/agent-plugin-loader.js +349 -0
  19. package/extensions/dm-mcp-adapter/app-bridge.bundle.js +5843 -0
  20. package/extensions/dm-mcp-adapter/cli.js +354 -0
  21. package/extensions/dm-mcp-adapter/commands.js +619 -0
  22. package/extensions/dm-mcp-adapter/config.js +1060 -0
  23. package/extensions/dm-mcp-adapter/consent-manager.js +60 -0
  24. package/extensions/dm-mcp-adapter/direct-tools.js +544 -0
  25. package/extensions/dm-mcp-adapter/dist/agent-dir.js +45 -0
  26. package/extensions/dm-mcp-adapter/dist/agent-plugin-loader.js +349 -0
  27. package/extensions/dm-mcp-adapter/dist/config.js +1060 -0
  28. package/extensions/dm-mcp-adapter/dist/mcp-bearer-store.js +311 -0
  29. package/extensions/dm-mcp-adapter/dist/metadata-cache.js +285 -0
  30. package/extensions/dm-mcp-adapter/dist/package-mcp-loader.js +144 -0
  31. package/extensions/dm-mcp-adapter/dist/resource-tools.js +7 -0
  32. package/extensions/dm-mcp-adapter/dist/types.js +247 -0
  33. package/extensions/dm-mcp-adapter/dist/ui-app-bridge-helpers.js +36 -0
  34. package/extensions/dm-mcp-adapter/dist/ui-stream-types.js +58 -0
  35. package/extensions/dm-mcp-adapter/dist/ui-tool-visibility.js +26 -0
  36. package/extensions/dm-mcp-adapter/dist/utils.js +307 -0
  37. package/extensions/dm-mcp-adapter/elicitation-handler.js +306 -0
  38. package/extensions/dm-mcp-adapter/error-signal.js +16 -0
  39. package/extensions/dm-mcp-adapter/errors.js +225 -0
  40. package/extensions/dm-mcp-adapter/failure-backoff.js +19 -0
  41. package/extensions/dm-mcp-adapter/glimpse-ui.js +61 -0
  42. package/extensions/dm-mcp-adapter/host-html-template.js +464 -0
  43. package/extensions/dm-mcp-adapter/index.js +1079 -0
  44. package/extensions/dm-mcp-adapter/init.js +624 -0
  45. package/extensions/dm-mcp-adapter/json-schema-validator.js +53 -0
  46. package/extensions/dm-mcp-adapter/lifecycle.js +385 -0
  47. package/extensions/dm-mcp-adapter/logger.js +115 -0
  48. package/extensions/dm-mcp-adapter/mcp-auth-flow.js +824 -0
  49. package/extensions/dm-mcp-adapter/mcp-auth.js +732 -0
  50. package/extensions/dm-mcp-adapter/mcp-bearer-store.js +311 -0
  51. package/extensions/dm-mcp-adapter/mcp-callback-server.js +388 -0
  52. package/extensions/dm-mcp-adapter/mcp-code.js +291 -0
  53. package/extensions/dm-mcp-adapter/mcp-keyring-helper.cjs +88 -0
  54. package/extensions/dm-mcp-adapter/mcp-oauth-provider.js +490 -0
  55. package/extensions/dm-mcp-adapter/mcp-output-guard.js +386 -0
  56. package/extensions/dm-mcp-adapter/mcp-panel.js +951 -0
  57. package/extensions/dm-mcp-adapter/mcp-probe.js +151 -0
  58. package/extensions/dm-mcp-adapter/mcp-references.js +263 -0
  59. package/extensions/dm-mcp-adapter/mcp-script-worker.mjs +126 -0
  60. package/extensions/dm-mcp-adapter/mcp-setup-panel.js +578 -0
  61. package/extensions/dm-mcp-adapter/mcp-status.js +80 -0
  62. package/extensions/dm-mcp-adapter/mcp-trace.js +215 -0
  63. package/extensions/dm-mcp-adapter/metadata-cache.js +292 -0
  64. package/extensions/dm-mcp-adapter/namespace-tools.js +155 -0
  65. package/extensions/dm-mcp-adapter/npx-resolver.js +465 -0
  66. package/extensions/dm-mcp-adapter/oauth-handler.js +17 -0
  67. package/extensions/dm-mcp-adapter/oauth.js +17 -0
  68. package/extensions/dm-mcp-adapter/onboarding-state.js +62 -0
  69. package/extensions/dm-mcp-adapter/package-mcp-loader.js +144 -0
  70. package/extensions/dm-mcp-adapter/package.json +68 -0
  71. package/extensions/dm-mcp-adapter/panel-keys.js +26 -0
  72. package/extensions/dm-mcp-adapter/prompts.js +258 -0
  73. package/extensions/dm-mcp-adapter/proxy-modes.js +1336 -0
  74. package/extensions/dm-mcp-adapter/request-headers-command.js +293 -0
  75. package/extensions/dm-mcp-adapter/resource-tools.js +7 -0
  76. package/extensions/dm-mcp-adapter/runtime-owner.js +79 -0
  77. package/extensions/dm-mcp-adapter/sampling-handler.js +222 -0
  78. package/extensions/dm-mcp-adapter/sandbox-proxy-template.js +190 -0
  79. package/extensions/dm-mcp-adapter/search-ranking.js +198 -0
  80. package/extensions/dm-mcp-adapter/server-manager.js +1258 -0
  81. package/extensions/dm-mcp-adapter/session-recovery.js +82 -0
  82. package/extensions/dm-mcp-adapter/skills/mcp-scripting/SKILL.md +39 -0
  83. package/extensions/dm-mcp-adapter/state.js +0 -0
  84. package/extensions/dm-mcp-adapter/test-runner.mjs +18 -0
  85. package/extensions/dm-mcp-adapter/tool-approval.js +151 -0
  86. package/extensions/dm-mcp-adapter/tool-metadata.js +247 -0
  87. package/extensions/dm-mcp-adapter/tool-registrar.js +212 -0
  88. package/extensions/dm-mcp-adapter/tool-result-renderer.js +355 -0
  89. package/extensions/dm-mcp-adapter/ts-shape.js +157 -0
  90. package/extensions/dm-mcp-adapter/types.js +264 -0
  91. package/extensions/dm-mcp-adapter/ui-app-bridge-helpers.js +36 -0
  92. package/extensions/dm-mcp-adapter/ui-resource-handler.js +209 -0
  93. package/extensions/dm-mcp-adapter/ui-server.js +815 -0
  94. package/extensions/dm-mcp-adapter/ui-session.js +455 -0
  95. package/extensions/dm-mcp-adapter/ui-stream-types.js +58 -0
  96. package/extensions/dm-mcp-adapter/ui-tool-visibility.js +26 -0
  97. package/extensions/dm-mcp-adapter/unix-socket-transport.js +83 -0
  98. package/extensions/dm-mcp-adapter/utils.js +307 -0
  99. package/extensions/dm-skills-manager/THIRD_PARTY_NOTICES.md +27 -0
  100. package/extensions/dm-skills-manager/extensions/skills-manager/components.js +265 -0
  101. package/extensions/dm-skills-manager/extensions/skills-manager/constants.js +31 -0
  102. package/extensions/dm-skills-manager/extensions/skills-manager/creation-fallback.js +20 -0
  103. package/extensions/dm-skills-manager/extensions/skills-manager/creation.js +145 -0
  104. package/extensions/dm-skills-manager/extensions/skills-manager/dialog.js +738 -0
  105. package/extensions/dm-skills-manager/extensions/skills-manager/dm-ai-compat.js +15 -0
  106. package/extensions/dm-skills-manager/extensions/skills-manager/format.js +125 -0
  107. package/extensions/dm-skills-manager/extensions/skills-manager/glyphs.js +142 -0
  108. package/extensions/dm-skills-manager/extensions/skills-manager/layout.js +93 -0
  109. package/extensions/dm-skills-manager/extensions/skills-manager/paths.js +76 -0
  110. package/extensions/dm-skills-manager/extensions/skills-manager/registry.js +95 -0
  111. package/extensions/dm-skills-manager/extensions/skills-manager/settings.js +93 -0
  112. package/extensions/dm-skills-manager/extensions/skills-manager/startup.js +32 -0
  113. package/extensions/dm-skills-manager/extensions/skills-manager/toggle.js +54 -0
  114. package/extensions/dm-skills-manager/extensions/skills-manager/types.js +14 -0
  115. package/extensions/dm-skills-manager/extensions/skills-manager/ui.js +121 -0
  116. package/extensions/dm-skills-manager/extensions/skills-manager.js +111 -0
  117. package/extensions/dm-skills-manager/package.json +121 -0
  118. package/package.json +13 -1
  119. package/extensions/dm-localllm-provider/detect.test.js +0 -1051
  120. package/extensions/dm-localllm-provider/index.test.js +0 -149
  121. package/extensions/dm-localllm-provider/keychain.test.js +0 -61
@@ -0,0 +1,578 @@
1
+ import { matchesKey, truncateToWidth, visibleWidth } from "@duckmind/dm-tui";
2
+ import { createPanelKeys } from "./panel-keys.js";
3
+ import { getConfigDirName } from "./agent-dir.js";
4
+ import { KNOWN_SERVER_PRESETS } from "./config.js";
5
+ const DEFAULT_THEME = {
6
+ border: "2",
7
+ title: "36",
8
+ selected: "32",
9
+ hint: "2",
10
+ success: "32",
11
+ warning: "33",
12
+ muted: "2;3"
13
+ };
14
+ const MIN_PANEL_WIDTH = 24;
15
+ const COMPACT_WIDTH = 60;
16
+ const COMPACT_ACTION_ROWS = 7;
17
+ const DESKTOP_PREVIEW_WIDTH = 74;
18
+ function fg(code, text) {
19
+ return code ? `\x1B[${code}m${text}\x1B[0m` : text;
20
+ }
21
+ function wrapText(text, width) {
22
+ if (width <= 8)
23
+ return [text];
24
+ const words = text.split(/\s+/).filter(Boolean);
25
+ const lines = [];
26
+ let current = "";
27
+ for (const word of words) {
28
+ const candidate = current ? `${current} ${word}` : word;
29
+ if (visibleWidth(candidate) <= width) {
30
+ current = candidate;
31
+ continue;
32
+ }
33
+ if (current)
34
+ lines.push(current);
35
+ current = word;
36
+ }
37
+ if (current)
38
+ lines.push(current);
39
+ return lines.length > 0 ? lines : [""];
40
+ }
41
+
42
+ export class McpSetupPanel {
43
+ discovery;
44
+ callbacks;
45
+ options;
46
+ done;
47
+ screen;
48
+ actionCursor = 0;
49
+ importCursor = 0;
50
+ pathCursor = 0;
51
+ sharedConfigTarget = "project";
52
+ selectedImports = new Set;
53
+ busy = false;
54
+ notice = null;
55
+ tui;
56
+ t = DEFAULT_THEME;
57
+ keys;
58
+ inactivityTimeout = null;
59
+ static INACTIVITY_MS = 60000;
60
+ constructor(discovery, callbacks, options, tui, done) {
61
+ this.discovery = discovery;
62
+ this.callbacks = callbacks;
63
+ this.options = options;
64
+ this.done = done;
65
+ this.tui = tui;
66
+ this.keys = createPanelKeys(options.keybindings);
67
+ this.screen = options.mode;
68
+ for (const entry of discovery.imports) {
69
+ this.selectedImports.add(entry.kind);
70
+ }
71
+ this.resetInactivityTimeout();
72
+ }
73
+ resetInactivityTimeout() {
74
+ if (this.inactivityTimeout)
75
+ clearTimeout(this.inactivityTimeout);
76
+ this.inactivityTimeout = setTimeout(() => {
77
+ this.cleanup();
78
+ this.done();
79
+ }, McpSetupPanel.INACTIVITY_MS);
80
+ }
81
+ cleanup() {
82
+ if (this.inactivityTimeout) {
83
+ clearTimeout(this.inactivityTimeout);
84
+ this.inactivityTimeout = null;
85
+ }
86
+ }
87
+ getActions() {
88
+ const actions = [];
89
+ if (this.screen === "empty") {
90
+ actions.push({ id: "run-setup", label: "Run setup", description: "Inspect detected configs, adopt imports, and scaffold a minimal `.mcp.json`." });
91
+ }
92
+ if (this.discovery.imports.length > 0) {
93
+ actions.push({ id: "adopt-imports", label: "Adopt detected compatibility imports", description: `Choose which host-specific MCP configs DM should import into its own override file. ${this.discovery.imports.length} source${this.discovery.imports.length === 1 ? "" : "s"} found.` });
94
+ }
95
+ actions.push({ 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" }, { 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" });
96
+ actions.push({ id: "view-example", label: "View example shared config", description: "Preview a working shared MCP config you can paste or adapt." });
97
+ if (!this.selectedSharedConfigExists()) {
98
+ actions.push({ id: "scaffold-shared-config", label: `Scaffold ${this.sharedTargetLabel()}`, description: "Write a minimal config at the selected normal MCP setup path, then reload DM." });
99
+ }
100
+ actions.push({ id: "show-precedence", label: "Explain config precedence", description: "Show the read order and where DM writes compatibility settings." });
101
+ if (this.getDetectedPaths().length > 0) {
102
+ actions.push({ id: "open-paths", label: "Open detected config paths", description: "Browse the actual config files that DM discovered on this machine." });
103
+ }
104
+ for (const preset of KNOWN_SERVER_PRESETS) {
105
+ actions.push({ id: "add-known-server", label: preset.name, description: preset.summary, preset });
106
+ }
107
+ if (!this.discovery.repoPrompt.configured && this.discovery.repoPrompt.executablePath && this.discovery.repoPrompt.targetPath && this.discovery.repoPrompt.entry && this.discovery.repoPrompt.serverName) {
108
+ 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." });
109
+ }
110
+ actions.push({ id: "close", label: "Close", description: "Exit the onboarding flow." });
111
+ return actions;
112
+ }
113
+ getDetectedPaths() {
114
+ const paths = [
115
+ ...this.discovery.sources.filter((source) => source.exists).map((source) => source.path),
116
+ ...this.discovery.imports.map((entry) => entry.path)
117
+ ];
118
+ return [...new Set(paths)];
119
+ }
120
+ sharedTargetLabel() {
121
+ return this.sharedConfigTarget === "project" ? "project .mcp.json" : "global ~/.config/mcp/mcp.json";
122
+ }
123
+ selectedSharedConfigExists() {
124
+ const sourceId = this.sharedConfigTarget === "project" ? "shared-project" : "shared-global";
125
+ return this.discovery.sources.some((source) => source.id === sourceId && source.exists);
126
+ }
127
+ getSelectedAction() {
128
+ const actions = this.getActions();
129
+ return actions[this.actionCursor];
130
+ }
131
+ handleInput(data) {
132
+ this.resetInactivityTimeout();
133
+ if (!this.busy)
134
+ this.notice = null;
135
+ if (matchesKey(data, "ctrl+c")) {
136
+ this.cleanup();
137
+ this.done();
138
+ return;
139
+ }
140
+ if (matchesKey(data, "escape")) {
141
+ if (this.screen === "imports" || this.screen === "paths") {
142
+ this.screen = this.discovery.hasAnyConfig ? "setup" : "empty";
143
+ this.tui.requestRender();
144
+ return;
145
+ }
146
+ this.cleanup();
147
+ this.done();
148
+ return;
149
+ }
150
+ if (this.busy)
151
+ return;
152
+ if (this.screen === "imports") {
153
+ this.handleImportsInput(data);
154
+ return;
155
+ }
156
+ if (this.screen === "paths") {
157
+ this.handlePathsInput(data);
158
+ return;
159
+ }
160
+ const actions = this.getActions();
161
+ if (this.keys.selectUp(data)) {
162
+ this.actionCursor = Math.max(0, this.actionCursor - 1);
163
+ this.tui.requestRender();
164
+ return;
165
+ }
166
+ if (this.keys.selectDown(data)) {
167
+ this.actionCursor = Math.min(actions.length - 1, this.actionCursor + 1);
168
+ this.tui.requestRender();
169
+ return;
170
+ }
171
+ if (this.keys.selectConfirm(data)) {
172
+ const selected = this.getSelectedAction();
173
+ if (selected)
174
+ this.runAction(selected);
175
+ }
176
+ }
177
+ handleImportsInput(data) {
178
+ const imports = this.discovery.imports;
179
+ if (this.keys.selectUp(data)) {
180
+ this.importCursor = Math.max(0, this.importCursor - 1);
181
+ this.tui.requestRender();
182
+ return;
183
+ }
184
+ if (this.keys.selectDown(data)) {
185
+ this.importCursor = Math.min(imports.length - 1, this.importCursor + 1);
186
+ this.tui.requestRender();
187
+ return;
188
+ }
189
+ if (matchesKey(data, "space")) {
190
+ const current = imports[this.importCursor];
191
+ if (!current)
192
+ return;
193
+ if (this.selectedImports.has(current.kind)) {
194
+ this.selectedImports.delete(current.kind);
195
+ } else {
196
+ this.selectedImports.add(current.kind);
197
+ }
198
+ this.tui.requestRender();
199
+ return;
200
+ }
201
+ if (this.keys.selectConfirm(data)) {
202
+ this.applySelectedImports();
203
+ }
204
+ }
205
+ handlePathsInput(data) {
206
+ const paths = this.getDetectedPaths();
207
+ if (this.keys.selectUp(data)) {
208
+ this.pathCursor = Math.max(0, this.pathCursor - 1);
209
+ this.tui.requestRender();
210
+ return;
211
+ }
212
+ if (this.keys.selectDown(data)) {
213
+ this.pathCursor = Math.min(paths.length - 1, this.pathCursor + 1);
214
+ this.tui.requestRender();
215
+ return;
216
+ }
217
+ if (this.keys.selectConfirm(data)) {
218
+ const selected = paths[this.pathCursor];
219
+ if (!selected)
220
+ return;
221
+ this.runBusy(async () => {
222
+ await this.callbacks.openPath(selected);
223
+ this.notice = { text: `Opened ${selected}`, tone: "success" };
224
+ });
225
+ }
226
+ }
227
+ async runAction(action) {
228
+ if (action.id === "run-setup") {
229
+ this.screen = "setup";
230
+ this.actionCursor = 0;
231
+ this.tui.requestRender();
232
+ return;
233
+ }
234
+ if (action.id === "adopt-imports") {
235
+ this.screen = "imports";
236
+ this.importCursor = 0;
237
+ this.tui.requestRender();
238
+ return;
239
+ }
240
+ if (action.id === "open-paths") {
241
+ this.screen = "paths";
242
+ this.pathCursor = 0;
243
+ this.tui.requestRender();
244
+ return;
245
+ }
246
+ if (action.id === "select-shared-target" && action.target) {
247
+ this.sharedConfigTarget = action.target;
248
+ this.notice = { text: `New shared servers will be written to ${this.sharedTargetLabel()}.`, tone: "muted" };
249
+ this.tui.requestRender();
250
+ return;
251
+ }
252
+ if (action.id === "scaffold-shared-config") {
253
+ await this.runBusy(async () => {
254
+ const result = await this.callbacks.scaffoldConfig(this.sharedConfigTarget);
255
+ this.callbacks.markSetupCompleted();
256
+ this.notice = { text: `Wrote starter config to ${result.path}. DM will reload after this panel closes.`, tone: "success" };
257
+ });
258
+ return;
259
+ }
260
+ if (action.id === "add-repoprompt") {
261
+ await this.runBusy(async () => {
262
+ const result = await this.callbacks.addRepoPrompt(this.sharedConfigTarget);
263
+ this.callbacks.markSetupCompleted();
264
+ this.notice = { text: `Added ${result.serverName} to ${result.path}. DM will reload after this panel closes.`, tone: "success" };
265
+ });
266
+ return;
267
+ }
268
+ if (action.id === "add-known-server" && action.preset) {
269
+ const preset = action.preset;
270
+ await this.runBusy(async () => {
271
+ const result = await this.callbacks.addKnownServer(preset, this.sharedConfigTarget);
272
+ this.callbacks.markSetupCompleted();
273
+ this.notice = { text: `Added ${result.serverName} to ${result.path}. DM will reload after this panel closes.`, tone: "success" };
274
+ });
275
+ return;
276
+ }
277
+ if (action.id === "close") {
278
+ this.cleanup();
279
+ this.done();
280
+ return;
281
+ }
282
+ this.notice = { text: "Review the details below. Press Enter on an action with a side effect to apply it.", tone: "muted" };
283
+ this.tui.requestRender();
284
+ }
285
+ async applySelectedImports() {
286
+ const selected = this.discovery.imports.filter((entry) => this.selectedImports.has(entry.kind)).map((entry) => entry.kind);
287
+ if (selected.length === 0) {
288
+ this.notice = { text: "Select at least one compatibility import first.", tone: "warning" };
289
+ this.tui.requestRender();
290
+ return;
291
+ }
292
+ await this.runBusy(async () => {
293
+ const result = await this.callbacks.adoptImports(selected);
294
+ this.callbacks.markSetupCompleted();
295
+ this.notice = result.added.length > 0 ? { text: `Added ${result.added.join(", ")} to ${result.path}. DM will reload after this panel closes.`, tone: "success" } : { text: `No changes needed in ${result.path}.`, tone: "muted" };
296
+ this.screen = this.discovery.hasAnyConfig ? "setup" : "empty";
297
+ this.actionCursor = 0;
298
+ });
299
+ }
300
+ async runBusy(fn) {
301
+ this.busy = true;
302
+ this.notice = { text: "Working...", tone: "muted" };
303
+ this.tui.requestRender();
304
+ try {
305
+ await fn();
306
+ } catch (error) {
307
+ this.notice = {
308
+ text: error instanceof Error ? error.message : String(error),
309
+ tone: "warning"
310
+ };
311
+ } finally {
312
+ this.busy = false;
313
+ this.tui.requestRender();
314
+ }
315
+ }
316
+ render(width) {
317
+ const panelW = Math.max(MIN_PANEL_WIDTH, width);
318
+ const innerW = panelW - 2;
319
+ const contentW = this.contentWidth(innerW);
320
+ const lines = [];
321
+ const border = fg(this.t.border, "─".repeat(innerW));
322
+ lines.push(`┌${border}┐`);
323
+ lines.push(this.padLine(fg(this.t.title, "MCP setup"), innerW));
324
+ for (const line of wrapText(this.discoverySummaryLine(), contentW)) {
325
+ lines.push(this.padLine(line, innerW));
326
+ }
327
+ for (const line of wrapText(this.secondarySummaryLine(), contentW)) {
328
+ lines.push(this.padLine(fg(this.t.muted, line), innerW));
329
+ }
330
+ lines.push(this.padLine("", innerW));
331
+ if (this.notice) {
332
+ const tone = this.notice.tone === "success" ? this.t.success : this.notice.tone === "warning" ? this.t.warning : this.t.hint;
333
+ for (const line of wrapText(this.notice.text, contentW)) {
334
+ lines.push(this.padLine(fg(tone, line), innerW));
335
+ }
336
+ lines.push(this.padLine("", innerW));
337
+ }
338
+ lines.push(`├${border}┤`);
339
+ if (this.screen === "imports") {
340
+ lines.push(...this.renderImports(innerW));
341
+ } else if (this.screen === "paths") {
342
+ lines.push(...this.renderPaths(innerW));
343
+ } else {
344
+ lines.push(...this.renderActions(innerW));
345
+ }
346
+ lines.push(`└${border}┘`);
347
+ return lines;
348
+ }
349
+ renderActions(innerW) {
350
+ const lines = [];
351
+ const actions = this.getActions();
352
+ const compact = innerW < COMPACT_WIDTH;
353
+ const { start, end } = compact ? this.visibleActionRange(actions.length) : { start: 0, end: actions.length };
354
+ if (start > 0) {
355
+ lines.push(this.padLine(fg(this.t.muted, `… ${start} more above`), innerW));
356
+ }
357
+ for (let index = start;index < end; index++) {
358
+ const action = actions[index];
359
+ if (!action)
360
+ continue;
361
+ if (action.id === "select-shared-target" && (index === start || actions[index - 1]?.id !== "select-shared-target")) {
362
+ lines.push(this.padLine(fg(this.t.title, "Choose where new shared servers go"), innerW));
363
+ }
364
+ if (action.id === "add-known-server" && (index === start || actions[index - 1]?.id !== "add-known-server")) {
365
+ lines.push(this.padLine(fg(this.t.title, `Add a known server to ${this.sharedTargetLabel()}`), innerW));
366
+ }
367
+ const selected = index === this.actionCursor;
368
+ const cursor = selected ? fg(this.t.selected, "›") : " ";
369
+ lines.push(this.padLine(`${cursor} ${truncateToWidth(action.label, this.contentWidth(innerW) - 2)}`, innerW));
370
+ }
371
+ if (end < actions.length) {
372
+ lines.push(this.padLine(fg(this.t.muted, `… ${actions.length - end} more below`), innerW));
373
+ }
374
+ lines.push(this.padLine("", innerW));
375
+ const preview = this.getActionPreview(this.getSelectedAction(), this.previewWidth(innerW));
376
+ for (const line of preview) {
377
+ lines.push(this.padLine(line, innerW));
378
+ }
379
+ lines.push(this.padLine("", innerW));
380
+ const hint = compact ? "Enter select · Esc back" : "Enter selects, Esc goes back, Ctrl+C closes.";
381
+ lines.push(this.padLine(fg(this.t.muted, hint), innerW));
382
+ return lines;
383
+ }
384
+ renderImports(innerW) {
385
+ const lines = [];
386
+ lines.push(this.padLine("Select compatibility imports. Space toggles, Enter saves, Esc goes back.", innerW));
387
+ lines.push(this.padLine("", innerW));
388
+ for (let index = 0;index < this.discovery.imports.length; index++) {
389
+ const entry = this.discovery.imports[index];
390
+ if (!entry)
391
+ continue;
392
+ const selected = this.selectedImports.has(entry.kind) ? "[x]" : "[ ]";
393
+ const cursor = index === this.importCursor ? fg(this.t.selected, "›") : " ";
394
+ lines.push(this.padLine(`${cursor} ${selected} ${entry.kind} ${entry.path}`, innerW));
395
+ }
396
+ lines.push(this.padLine("", innerW));
397
+ const selected = this.discovery.imports.filter((entry) => this.selectedImports.has(entry.kind)).map((entry) => entry.kind);
398
+ const preview = this.callbacks.previewImports(selected);
399
+ for (const line of this.formatWritePreview("Compatibility import write preview", preview, [], this.previewWidth(innerW))) {
400
+ lines.push(this.padLine(line, innerW));
401
+ }
402
+ return lines;
403
+ }
404
+ renderPaths(innerW) {
405
+ const lines = [];
406
+ lines.push(this.padLine("Select a detected config path to open. Enter opens it, Esc goes back.", innerW));
407
+ lines.push(this.padLine("", innerW));
408
+ const paths = this.getDetectedPaths();
409
+ for (let index = 0;index < paths.length; index++) {
410
+ const cursor = index === this.pathCursor ? fg(this.t.selected, "›") : " ";
411
+ const path = paths[index];
412
+ if (path !== undefined)
413
+ lines.push(this.padLine(`${cursor} ${path}`, innerW));
414
+ }
415
+ return lines;
416
+ }
417
+ discoverySummaryLine() {
418
+ if (!this.discovery.hasAnyConfig) {
419
+ return fg(this.t.warning, this.options.onboardingState.setupCompleted ? "No MCP servers are active right now." : "No MCP config is active yet.");
420
+ }
421
+ if (this.discovery.totalServerCount === 0 && (this.discovery.imports.length > 0 || !!this.discovery.repoPrompt.executablePath)) {
422
+ return fg(this.t.warning, "DM found MCP-related setup options, but none are active in DM yet.");
423
+ }
424
+ const shared = this.discovery.sources.filter((source) => source.kind === "shared" && source.serverCount > 0).length;
425
+ const piOwned = this.discovery.sources.filter((source) => source.kind === "pi" && source.serverCount > 0).length;
426
+ return fg(this.t.hint, `Detected ${this.discovery.totalServerCount} configured servers across ${shared} shared and ${piOwned} DM-owned source${shared + piOwned === 1 ? "" : "s"}.`);
427
+ }
428
+ secondarySummaryLine() {
429
+ const hostNote = this.discovery.hostConfigs.length > 0 ? ` Host discovery is ${this.discovery.hostConfigDiscovery}; ${this.discovery.hostConfigs.length} host source${this.discovery.hostConfigs.length === 1 ? "" : "s"} detected.` : "";
430
+ const conflictNote = this.discovery.conflicts.length > 0 ? ` ${this.discovery.conflicts.length} same-name conflict${this.discovery.conflicts.length === 1 ? "" : "s"} reported.` : "";
431
+ if (!this.discovery.hasAnyConfig) {
432
+ 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}`;
433
+ }
434
+ if (this.discovery.totalServerCount === 0 && this.discovery.imports.length > 0) {
435
+ return `Detected ${this.discovery.imports.length} compatibility import source${this.discovery.imports.length === 1 ? "" : "s"}. Adopt them into DM or inspect the underlying files.${hostNote}${conflictNote}`;
436
+ }
437
+ return `Use .mcp.json for project/team servers or ~/.config/mcp/mcp.json for all projects. DM-owned files are for compatibility imports and adapter-specific overrides, not another normal setup path.${hostNote}${conflictNote}`;
438
+ }
439
+ visibleActionRange(total) {
440
+ if (total <= COMPACT_ACTION_ROWS)
441
+ return { start: 0, end: total };
442
+ const half = Math.floor(COMPACT_ACTION_ROWS / 2);
443
+ const start = Math.min(Math.max(0, this.actionCursor - half), Math.max(0, total - COMPACT_ACTION_ROWS));
444
+ return { start, end: Math.min(total, start + COMPACT_ACTION_ROWS) };
445
+ }
446
+ contentWidth(innerW) {
447
+ return Math.max(8, innerW - 4);
448
+ }
449
+ previewWidth(innerW) {
450
+ return Math.max(12, Math.min(DESKTOP_PREVIEW_WIDTH, this.contentWidth(innerW)));
451
+ }
452
+ getActionPreview(action, previewW = DESKTOP_PREVIEW_WIDTH) {
453
+ switch (action?.id) {
454
+ case "run-setup":
455
+ return this.formatPreview([
456
+ "Run setup to adopt host-specific imports, inspect detected paths, and scaffold a minimal `.mcp.json` if needed."
457
+ ], previewW);
458
+ case "adopt-imports":
459
+ return this.formatWritePreview("Compatibility import write preview", this.callbacks.previewImports(this.discovery.imports.filter((entry) => this.selectedImports.has(entry.kind)).map((entry) => entry.kind)), [
460
+ `Detected imports: ${this.discovery.imports.map((entry) => `${entry.kind} (${entry.serverCount} servers)`).join(", ")}`,
461
+ "Selected imports are written into the DM agent dir config as DM-owned compatibility state."
462
+ ], previewW);
463
+ case "select-shared-target":
464
+ return this.formatPreview([
465
+ action.target === "project" ? "Project target: .mcp.json" : "Global target: ~/.config/mcp/mcp.json",
466
+ "Known server presets and starter configs will be written to the selected normal MCP setup path.",
467
+ "DM-owned mcp.json files remain compatibility and adapter-only override state."
468
+ ], previewW);
469
+ case "view-example":
470
+ return this.formatPreview([
471
+ "Example shared `.mcp.json`:",
472
+ "{",
473
+ ' "mcpServers": {',
474
+ ' "chrome-devtools": {',
475
+ ' "command": "npx",',
476
+ ' "args": ["-y", "chrome-devtools-mcp@1.6.0"]',
477
+ " }",
478
+ " }",
479
+ "}",
480
+ "",
481
+ "Use Scaffold selected config when you want a safe empty shell instead of a live example server."
482
+ ], previewW);
483
+ case "show-precedence":
484
+ return this.formatPreview([
485
+ "Recommended shared config:",
486
+ " project/team: .mcp.json",
487
+ " all projects: ~/.config/mcp/mcp.json",
488
+ "",
489
+ "Advanced compatibility and DM-owned layers:",
490
+ " host imports, .agents files, package MCP manifests, and DM overrides",
491
+ "",
492
+ "Read order (later entries win):",
493
+ "0. detected host configs (opt-in lowest-precedence fallback)",
494
+ "1. ~/.config/mcp/mcp.json",
495
+ "2. ~/.agents/mcp.json",
496
+ "3. ~/.agents/mcp/mcp.json",
497
+ "4. <DM agent dir>/mcp.json",
498
+ "5. .mcp.json",
499
+ `6. ${getConfigDirName()}/mcp.json`,
500
+ `Host discovery: ${this.discovery.hostConfigDiscovery}. Conflicts reported: ${this.discovery.conflicts.length}.`,
501
+ ...this.discovery.conflicts.slice(0, 8).map((conflict) => `${conflict.serverName}: ${conflict.sources.map((source) => source.path).join(" -> ")} (winner: ${conflict.winner.path})`),
502
+ "DM writes compatibility imports and adapter-only overrides to DM-owned files."
503
+ ], previewW);
504
+ case "open-paths":
505
+ return this.formatPreview(this.getDetectedPaths().length > 0 ? ["Detected paths:", ...this.getDetectedPaths()] : ["No config paths were detected."], previewW);
506
+ case "add-repoprompt": {
507
+ const repoPrompt = this.discovery.repoPrompt;
508
+ const preview = this.callbacks.previewRepoPrompt(this.sharedConfigTarget);
509
+ if (!preview) {
510
+ return this.formatPreview(["RepoPrompt is not available to add from this setup screen."], previewW);
511
+ }
512
+ return this.formatWritePreview("RepoPrompt write preview", preview, [
513
+ `Executable: ${repoPrompt.executablePath ?? "not found"}`,
514
+ `Target: ${this.sharedTargetLabel()}`,
515
+ `Server name: ${repoPrompt.serverName ?? "repoprompt"}`
516
+ ], previewW);
517
+ }
518
+ case "add-known-server": {
519
+ const preset = action.preset;
520
+ if (!preset)
521
+ return this.formatPreview(["Known server preset is unavailable."], previewW);
522
+ return this.formatWritePreview(`${preset.name} write preview`, this.callbacks.previewKnownServer(preset, this.sharedConfigTarget), [preset.summary, `Target: ${this.sharedTargetLabel()}`], previewW);
523
+ }
524
+ case "scaffold-shared-config":
525
+ return this.formatWritePreview(`${this.sharedTargetLabel()} starter write preview`, this.callbacks.previewStarterConfig(this.sharedConfigTarget), [
526
+ "This writes a minimal config at the selected normal MCP setup path.",
527
+ "It intentionally avoids adding a fake placeholder server that would fail on first reload."
528
+ ], previewW);
529
+ case "close":
530
+ default:
531
+ return this.formatPreview(["Close the setup flow."], previewW);
532
+ }
533
+ }
534
+ formatPreview(lines, width = DESKTOP_PREVIEW_WIDTH) {
535
+ const preview = [];
536
+ for (const line of lines) {
537
+ preview.push(...wrapText(line, width));
538
+ }
539
+ return preview;
540
+ }
541
+ formatWritePreview(title, preview, intro = [], width = DESKTOP_PREVIEW_WIDTH) {
542
+ const lines = [];
543
+ for (const line of intro) {
544
+ lines.push(...wrapText(line, width));
545
+ }
546
+ if (intro.length > 0)
547
+ lines.push("");
548
+ lines.push(...wrapText(`${title}: ${preview.path}`, width));
549
+ lines.push(...wrapText(preview.existed ? "Existing file detected. Showing exact before/after diff." : "New file will be created. Showing exact content diff.", width));
550
+ lines.push("");
551
+ const diffLines = preview.diffText.split(`
552
+ `);
553
+ const maxLines = 18;
554
+ const shown = diffLines.slice(0, maxLines);
555
+ for (const line of shown) {
556
+ lines.push(...wrapText(line, width));
557
+ }
558
+ if (diffLines.length > maxLines) {
559
+ lines.push(...wrapText(`… ${diffLines.length - maxLines} more diff line${diffLines.length - maxLines === 1 ? "" : "s"}`, width));
560
+ }
561
+ return lines;
562
+ }
563
+ padLine(text, innerW) {
564
+ const inset = 2;
565
+ const contentW = Math.max(0, innerW - inset * 2);
566
+ const fitted = truncateToWidth(text, contentW, "…", true);
567
+ const plainWidth = visibleWidth(fitted);
568
+ const padding = Math.max(0, contentW - plainWidth);
569
+ return `│${" ".repeat(inset)}${fitted}${" ".repeat(padding)}${" ".repeat(inset)}│`;
570
+ }
571
+ invalidate() {}
572
+ dispose() {
573
+ this.cleanup();
574
+ }
575
+ }
576
+ export function createMcpSetupPanel(discovery, callbacks, options, tui, done) {
577
+ return new McpSetupPanel(discovery, callbacks, options, tui, done);
578
+ }
@@ -0,0 +1,80 @@
1
+ import {
2
+ MCP_STATUS_EVENT,
3
+ MCP_STATUS_SNAPSHOT_VERSION
4
+ } from "./types.js";
5
+ import { getFailureAgeSeconds, isServerInActiveFailureBackoff } from "./failure-backoff.js";
6
+ export function createMcpStatusSnapshot(state) {
7
+ const servers = [];
8
+ let totalTools = 0;
9
+ let totalResources = 0;
10
+ let connectedCount = 0;
11
+ let disabledCount = 0;
12
+ for (const name of Object.keys(state.config.mcpServers)) {
13
+ const definition = state.config.mcpServers[name];
14
+ const disabled = definition?.disabled === true;
15
+ const connection = disabled ? undefined : state.manager.getConnection(name);
16
+ const failedAgoSeconds = disabled ? null : getFailureAgeSeconds(state, name);
17
+ const activeFailure = !disabled && isServerInActiveFailureBackoff(state, name);
18
+ const metadata = disabled || activeFailure ? undefined : state.toolMetadata.get(name);
19
+ const toolCount = metadata?.length ?? (connection?.status === "connected" ? connection.tools.length : 0);
20
+ const resourceCount = disabled || activeFailure ? undefined : state.resourceCounts?.get(name) ?? (connection?.status === "connected" ? connection.resources.length : undefined);
21
+ let status = "not-connected";
22
+ if (disabled) {
23
+ status = "disabled";
24
+ disabledCount++;
25
+ } else if (connection?.status === "connected") {
26
+ status = "connected";
27
+ connectedCount++;
28
+ } else if (connection?.status === "needs-auth") {
29
+ status = "needs-auth";
30
+ } else if (activeFailure) {
31
+ status = "failed";
32
+ } else if (metadata !== undefined) {
33
+ status = "cached";
34
+ }
35
+ totalTools += disabled ? 0 : toolCount;
36
+ if (!disabled && resourceCount !== undefined)
37
+ totalResources += resourceCount;
38
+ servers.push({
39
+ name,
40
+ status,
41
+ listenState: connection?.status === "connected" ? connection.listenState : "disconnected",
42
+ toolCount,
43
+ ...connection?.status === "connected" && connection.listenCatalogStale ? { catalogStale: true } : {},
44
+ ...resourceCount !== undefined ? { resourceCount } : {},
45
+ ...status === "failed" && failedAgoSeconds !== null ? { failedAgoSeconds } : {},
46
+ disabled
47
+ });
48
+ }
49
+ return {
50
+ version: MCP_STATUS_SNAPSHOT_VERSION,
51
+ servers,
52
+ totalTools,
53
+ totalResources,
54
+ connectedCount,
55
+ disabledCount
56
+ };
57
+ }
58
+ export function publishMcpStatusSnapshot(state, snapshot) {
59
+ const events = state.statusEvents;
60
+ if (!events)
61
+ return;
62
+ try {
63
+ events.emit(MCP_STATUS_EVENT, snapshot ?? createMcpStatusSnapshot(state));
64
+ } catch {}
65
+ }
66
+ export function publishMcpStatusShutdown(events) {
67
+ if (!events)
68
+ return;
69
+ try {
70
+ events.emit(MCP_STATUS_EVENT, {
71
+ version: MCP_STATUS_SNAPSHOT_VERSION,
72
+ servers: [],
73
+ totalTools: 0,
74
+ totalResources: 0,
75
+ connectedCount: 0,
76
+ disabledCount: 0
77
+ });
78
+ } catch {}
79
+ }
80
+ export { MCP_STATUS_EVENT, MCP_STATUS_SNAPSHOT_VERSION } from "./types.js";