@wonderwhy-er/desktop-commander 0.2.45 → 0.2.47

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.
@@ -41,10 +41,12 @@ try {
41
41
  process.exit(3); // Exit code 3 for auth error
42
42
  }
43
43
 
44
- // Update device status to offline
44
+ // Update device status to offline, stamping the exact shutdown moment so
45
+ // "last seen X ago" is precise for clean shutdowns (the periodic
46
+ // bookkeeping write only runs on the slow capable cadence).
45
47
  const { error } = await client
46
48
  .from('mcp_devices')
47
- .update({ status: 'offline' })
49
+ .update({ status: 'offline', last_seen: new Date().toISOString() })
48
50
  .eq('id', deviceId);
49
51
 
50
52
  clearTimeout(timeoutHandle);
package/dist/server.js CHANGED
@@ -19,7 +19,7 @@ import { trackToolCall } from './utils/trackTools.js';
19
19
  import { usageTracker } from './utils/usageTracker.js';
20
20
  import { processDockerPrompt } from './utils/dockerPrompt.js';
21
21
  import { toolHistory } from './utils/toolHistory.js';
22
- import { handleWelcomePageOnboarding } from './utils/welcome-onboarding.js';
22
+ import { handleWelcomePageOnboarding, skipWelcomePageOnboarding } from './utils/welcome-onboarding.js';
23
23
  import { VERSION } from './version.js';
24
24
  import { capture, capture_call_tool, runInUiOriginCallContext } from "./utils/capture.js";
25
25
  import { logToStderr, logger } from './utils/logger.js';
@@ -139,16 +139,22 @@ server.setRequestHandler(InitializeRequestSchema, async (request) => {
139
139
  if (clientInfo) {
140
140
  await updateCurrentClient(clientInfo);
141
141
  // Welcome page for new users (A/B test controlled) — all clients except
142
- // the Desktop Commander app, remote contexts, and `claude-code`.
143
- // Claude Code and Claude Cowork plugin sessions both identify as
144
- // `claude-code` and provide their own onboarding surface.
145
- if (currentClient.name !== 'desktop-commander-app'
142
+ // the Desktop Commander app and remote contexts. Further exclusions are
143
+ // flag-served via welcome_page_excluded_clients (e.g. claude-code, which
144
+ // covers Claude Code and Cowork plugin sessions — both identify as
145
+ // `claude-code` and provide their own onboarding surface).
146
+ const isWelcomePageEligibleClient = currentClient.name !== 'desktop-commander-app'
146
147
  && currentClient.name !== 'desktop-commander'
147
148
  && !isRemoteClientContext(currentClient.name)
148
- && currentClient.name !== 'claude-code'
149
- && !global.disableOnboarding) {
149
+ && !global.disableOnboarding;
150
+ if (isWelcomePageEligibleClient) {
150
151
  await handleWelcomePageOnboarding(currentClient.name);
151
152
  }
153
+ else {
154
+ // Do not carry a first-run page over to a client that is made
155
+ // eligible in a later release.
156
+ await skipWelcomePageOnboarding();
157
+ }
152
158
  }
153
159
  // Raw host environment signals (no PII, undefined when absent). Some
154
160
  // hosts share a clientInfo name — Claude Code CLI, Claude Code inside
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Whether tools advertise interactive MCP UI widgets. Shown by default; a
3
+ * boolean showMcpUI config value is an explicit user override. Any non-boolean
4
+ * value (unset, or a stringly-typed "false") means the default applies.
5
+ */
6
+ export declare function mcpUiEnabledFor(userOverride: unknown): boolean;
7
+ export declare function shouldShowMcpUi(): Promise<boolean>;
@@ -0,0 +1,22 @@
1
+ import { configManager } from '../config-manager.js';
2
+ /**
3
+ * Whether tools advertise interactive MCP UI widgets. Shown by default; a
4
+ * boolean showMcpUI config value is an explicit user override. Any non-boolean
5
+ * value (unset, or a stringly-typed "false") means the default applies.
6
+ */
7
+ export function mcpUiEnabledFor(userOverride) {
8
+ return typeof userOverride === 'boolean' ? userOverride : true;
9
+ }
10
+ // Decided once per server process: a session must render consistently. Flipping
11
+ // tool UI _meta mid-session confuses hosts (open widgets / other threads sharing
12
+ // this server see tools lose their UI), so config changes made while the server
13
+ // is running take effect on the next restart.
14
+ let sessionDecision = null;
15
+ export async function shouldShowMcpUi() {
16
+ if (!sessionDecision) {
17
+ sessionDecision = configManager.getValue('showMcpUI')
18
+ .then(mcpUiEnabledFor)
19
+ .catch(() => true);
20
+ }
21
+ return sessionDecision;
22
+ }
@@ -12,6 +12,25 @@ interface FormattedToolCallRecord extends Omit<ToolCallRecord, 'timestamp'> {
12
12
  declare class ToolHistory {
13
13
  private history;
14
14
  private readonly MAX_ENTRIES;
15
+ /**
16
+ * Cap on the output kept per entry. Entries hold the FULL ServerResult, and
17
+ * get_recent_tool_calls serialises them straight back out, so without a cap
18
+ * the history is unbounded in two compounding ways:
19
+ *
20
+ * - a single large output (a big read_file, a wide list_directory) makes
21
+ * every later history dump that includes it large too, and
22
+ * - any tool whose output happens to CONTAIN a history dump — e.g.
23
+ * `cat`-ing a file a previous dump was written to — nests the whole
24
+ * history inside itself, and each nesting level roughly doubles the JSON
25
+ * escaping. Observed 2026-07-27: 83KB of arguments on disk produced a
26
+ * 1.89MB in-memory dump this way.
27
+ *
28
+ * Excluding more tool names cannot fix that, because the nesting arrives
29
+ * through ordinary tools. Capping the stored output does, and a preview is
30
+ * all this history is for — it is a "what happened recently" aid, not a
31
+ * result cache.
32
+ */
33
+ private readonly MAX_STORED_OUTPUT_BYTES;
15
34
  private readonly MAX_HISTORY_FILE_SIZE_BYTES;
16
35
  private readonly HISTORY_FILE_TRIM_TARGET_BYTES;
17
36
  private readonly historyFile;
@@ -49,6 +68,11 @@ declare class ToolHistory {
49
68
  /**
50
69
  * Add a tool call to history
51
70
  */
71
+ /**
72
+ * Replace an oversized output with a short marker. Keeps the record shape
73
+ * ({ content: [...] }) so readers and formatters need no special case.
74
+ */
75
+ private capOutput;
52
76
  addCall(toolName: string, args: any, output: ServerResult, duration?: number): void;
53
77
  /**
54
78
  * Get recent tool calls with filters
@@ -18,6 +18,25 @@ class ToolHistory {
18
18
  constructor() {
19
19
  this.history = [];
20
20
  this.MAX_ENTRIES = 1000;
21
+ /**
22
+ * Cap on the output kept per entry. Entries hold the FULL ServerResult, and
23
+ * get_recent_tool_calls serialises them straight back out, so without a cap
24
+ * the history is unbounded in two compounding ways:
25
+ *
26
+ * - a single large output (a big read_file, a wide list_directory) makes
27
+ * every later history dump that includes it large too, and
28
+ * - any tool whose output happens to CONTAIN a history dump — e.g.
29
+ * `cat`-ing a file a previous dump was written to — nests the whole
30
+ * history inside itself, and each nesting level roughly doubles the JSON
31
+ * escaping. Observed 2026-07-27: 83KB of arguments on disk produced a
32
+ * 1.89MB in-memory dump this way.
33
+ *
34
+ * Excluding more tool names cannot fix that, because the nesting arrives
35
+ * through ordinary tools. Capping the stored output does, and a preview is
36
+ * all this history is for — it is a "what happened recently" aid, not a
37
+ * result cache.
38
+ */
39
+ this.MAX_STORED_OUTPUT_BYTES = 4 * 1024;
21
40
  this.MAX_HISTORY_FILE_SIZE_BYTES = 5 * 1024 * 1024;
22
41
  // When the file exceeds the cap we trim it down to this target instead of
23
42
  // all the way to zero, so a single overflow doesn't cause every subsequent
@@ -61,8 +80,14 @@ class ToolHistory {
61
80
  // Silently skip invalid lines
62
81
  }
63
82
  }
64
- // Keep only last 1000 entries
65
- this.history = records.slice(-this.MAX_ENTRIES);
83
+ // Keep only last 1000 entries, and cap on the way IN as well as on the
84
+ // way out. Entries written before the cap existed are still on disk and
85
+ // are well under the whole-file trim threshold, so without this the cap
86
+ // does nothing for anyone upgrading with an existing history file — i.e.
87
+ // for everyone it was written for.
88
+ this.history = records
89
+ .slice(-this.MAX_ENTRIES)
90
+ .map(record => ({ ...record, output: this.capOutput(record.output) }));
66
91
  // If file is getting too large, trim it
67
92
  if (lines.length > this.MAX_ENTRIES * 2) {
68
93
  this.trimHistoryFile();
@@ -181,12 +206,39 @@ class ToolHistory {
181
206
  /**
182
207
  * Add a tool call to history
183
208
  */
209
+ /**
210
+ * Replace an oversized output with a short marker. Keeps the record shape
211
+ * ({ content: [...] }) so readers and formatters need no special case.
212
+ */
213
+ capOutput(output) {
214
+ let size;
215
+ try {
216
+ size = JSON.stringify(output)?.length ?? 0;
217
+ }
218
+ catch {
219
+ // Circular or otherwise unserialisable — it could never be returned to a
220
+ // client anyway, so don't retain it.
221
+ size = Number.POSITIVE_INFINITY;
222
+ }
223
+ if (size <= this.MAX_STORED_OUTPUT_BYTES)
224
+ return output;
225
+ const shown = Number.isFinite(size) ? `${size} bytes` : 'unserialisable';
226
+ return {
227
+ ...output,
228
+ content: [
229
+ {
230
+ type: 'text',
231
+ text: `[output omitted from history: ${shown}, over the ${this.MAX_STORED_OUTPUT_BYTES}-byte cap]`,
232
+ },
233
+ ],
234
+ };
235
+ }
184
236
  addCall(toolName, args, output, duration) {
185
237
  const record = {
186
238
  timestamp: new Date().toISOString(),
187
239
  toolName,
188
240
  arguments: args,
189
- output,
241
+ output: this.capOutput(output),
190
242
  duration
191
243
  };
192
244
  this.history.push(record);
@@ -1,3 +1,5 @@
1
+ /** Consume a pending welcome page when this client must never receive it. */
2
+ export declare function skipWelcomePageOnboarding(): Promise<void>;
1
3
  /**
2
4
  * Handle welcome page display for new users (A/B test controlled)
3
5
  *
@@ -4,6 +4,24 @@ import { featureFlagManager } from './feature-flags.js';
4
4
  import { openWelcomePage } from './open-browser.js';
5
5
  import { logToStderr } from './logger.js';
6
6
  import { capture } from './capture.js';
7
+ /** Consume a pending welcome page when this client must never receive it. */
8
+ export async function skipWelcomePageOnboarding() {
9
+ const pending = await configManager.getValue('pendingWelcomeOnboarding');
10
+ if (!pending) {
11
+ return;
12
+ }
13
+ await configManager.setValue('pendingWelcomeOnboarding', false);
14
+ logToStderr('debug', 'Welcome page skipped');
15
+ }
16
+ function isWelcomePageClientExcluded(clientName) {
17
+ const configuredClients = featureFlagManager.get('welcome_page_excluded_clients', []);
18
+ if (!Array.isArray(configuredClients) || !clientName) {
19
+ return false;
20
+ }
21
+ const normalizedClientName = clientName.trim().toLowerCase();
22
+ return configuredClients.some((configuredClient) => typeof configuredClient === 'string'
23
+ && configuredClient.trim().toLowerCase() === normalizedClientName);
24
+ }
7
25
  /**
8
26
  * Handle welcome page display for new users (A/B test controlled)
9
27
  *
@@ -13,6 +31,12 @@ import { capture } from './capture.js';
13
31
  * 3. Haven't seen it yet
14
32
  */
15
33
  export async function handleWelcomePageOnboarding(clientName) {
34
+ // Existing configs are migrated to false. Only configs created with the
35
+ // eligibility marker may receive this welcome-page campaign.
36
+ const eligible = await configManager.getValue('welcomeOnboardingEligible');
37
+ if (!eligible) {
38
+ return;
39
+ }
16
40
  // Check if this is a new install pending A/B decision
17
41
  // This flag is set when config is first created and survives process restarts
18
42
  const pending = await configManager.getValue('pendingWelcomeOnboarding');
@@ -28,6 +52,18 @@ export async function handleWelcomePageOnboarding(clientName) {
28
52
  logToStderr('debug', 'Waiting for feature flags to load...');
29
53
  await featureFlagManager.waitForFreshFlags();
30
54
  }
55
+ // Keep an MCP release compatible with an older flag document: only an
56
+ // explicit false disables. Absent or malformed values fail open so a flag
57
+ // file typo cannot permanently consume pending onboarding for new installs.
58
+ const enabled = featureFlagManager.get('welcome_page_enabled', true) !== false;
59
+ if (!enabled) {
60
+ await skipWelcomePageOnboarding();
61
+ return;
62
+ }
63
+ if (isWelcomePageClientExcluded(clientName)) {
64
+ await skipWelcomePageOnboarding();
65
+ return;
66
+ }
31
67
  // Check A/B test assignment
32
68
  const shouldShow = await hasFeature('showOnboardingPage');
33
69
  // Track the A/B decision
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.2.45";
1
+ export declare const VERSION = "0.2.47";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.2.45';
1
+ export const VERSION = '0.2.47';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wonderwhy-er/desktop-commander",
3
- "version": "0.2.45",
3
+ "version": "0.2.47",
4
4
  "description": "MCP server for terminal operations and file editing",
5
5
  "mcpName": "io.github.wonderwhy-er/desktop-commander",
6
6
  "license": "MIT",