@xagent-ai/cli 1.3.1 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/checkpoint.ts CHANGED
@@ -6,6 +6,7 @@ import { promisify } from 'util';
6
6
  import crypto from 'crypto';
7
7
  import { Checkpoint, ChatMessage, ToolCall } from './types.js';
8
8
  import { output as logOutput } from './output-util.js';
9
+ import { icons } from './theme.js';
9
10
 
10
11
  const execAsync = promisify(exec);
11
12
 
@@ -95,7 +96,7 @@ export class CheckpointManager {
95
96
  this.checkpoints.set(checkpointId, checkpoint);
96
97
  await this.cleanupOldCheckpoints();
97
98
 
98
- console.log(`�?Checkpoint created: ${checkpointId}`);
99
+ console.log(`${icons.success} Checkpoint created: ${checkpointId}`);
99
100
  await logOutput('success', `Checkpoint created: ${checkpointId}`);
100
101
  return checkpoint;
101
102
  }
@@ -130,7 +131,7 @@ export class CheckpointManager {
130
131
 
131
132
  await this.restoreGitSnapshot(checkpointId);
132
133
 
133
- console.log('�?Checkpoint restored successfully');
134
+ console.log(`${icons.success} Checkpoint restored successfully`);
134
135
  await logOutput('success', `Checkpoint restored successfully: ${checkpointId}`);
135
136
  }
136
137
 
@@ -172,7 +173,7 @@ export class CheckpointManager {
172
173
  }
173
174
 
174
175
  this.checkpoints.delete(checkpointId);
175
- console.log(`�?Checkpoint deleted: ${checkpointId}`);
176
+ console.log(`${icons.success} Checkpoint deleted: ${checkpointId}`);
176
177
  await logOutput('success', `Checkpoint deleted: ${checkpointId}`);
177
178
  } catch (error) {
178
179
  console.error('Failed to delete checkpoint:', error);
@@ -215,7 +216,7 @@ export class CheckpointManager {
215
216
  this.checkpoints.delete(checkpoint.id);
216
217
  }
217
218
 
218
- console.log('�?Checkpoint data cleaned up');
219
+ console.log(`${icons.success} Checkpoint data cleaned up`);
219
220
  await logOutput('success', 'Checkpoint data cleaned up');
220
221
  } catch (error) {
221
222
  console.error('Failed to cleanup checkpoint data:', error);
@@ -236,7 +237,7 @@ export class CheckpointManager {
236
237
  await fs.rm(this.snapshotsDir, { recursive: true, force: true });
237
238
  await fs.rm(this.checkpointsDir, { recursive: true, force: true });
238
239
  this.checkpoints.clear();
239
- console.log('�?Checkpoint data cleaned up');
240
+ console.log(`${icons.success} Checkpoint data cleaned up`);
240
241
  } catch (error) {
241
242
  console.error('Failed to cleanup checkpoint data:', error);
242
243
  }
package/src/cli.ts CHANGED
@@ -57,6 +57,16 @@ setConfigProvider(() => {
57
57
  };
58
58
  });
59
59
 
60
+ // Helper function to disconnect all MCP servers and exit
61
+ function disconnectAndExit(mcpManager: any, code: number): void {
62
+ try {
63
+ mcpManager.disconnectAllServers();
64
+ } catch {
65
+ // Ignore cleanup errors
66
+ }
67
+ process.exit(code);
68
+ }
69
+
60
70
  const program = new Command();
61
71
 
62
72
  /**
@@ -401,7 +411,7 @@ program
401
411
  console.log('');
402
412
  });
403
413
  }
404
- process.exit(0);
414
+ disconnectAndExit(mcpManager, 0);
405
415
  } else if (options.get) {
406
416
  const server = mcpManager.getServer(options.get);
407
417
 
@@ -410,7 +420,8 @@ program
410
420
  console.log(colors.error(`MCP server '${options.get}' not found`));
411
421
  console.log(colors.textMuted('Use "xagent mcp --list" to see all configured servers'));
412
422
  console.log('');
413
- process.exit(1);
423
+ disconnectAndExit(mcpManager, 1);
424
+ return;
414
425
  }
415
426
 
416
427
  const config = (server as any).config;
@@ -452,7 +463,7 @@ program
452
463
  }
453
464
 
454
465
  console.log('');
455
- process.exit(0);
466
+ disconnectAndExit(mcpManager, 0);
456
467
  } else if (options.add !== undefined) {
457
468
  // Check if running in non-interactive mode (transport and required params provided)
458
469
  const hasTransport = options.transport;
@@ -562,12 +573,12 @@ program
562
573
  console.log(colors.success(`✅ MCP server '${name}' added successfully`));
563
574
  }
564
575
  console.log('');
565
- process.exit(0);
576
+ disconnectAndExit(mcpManager, 0);
566
577
  } catch (error: any) {
567
578
  console.log('');
568
579
  console.log(colors.error(`Failed to add MCP server: ${error.message}`));
569
580
  console.log('');
570
- process.exit(1);
581
+ disconnectAndExit(mcpManager, 1);
571
582
  }
572
583
  } else {
573
584
  // Interactive mode
@@ -751,14 +762,14 @@ program
751
762
  console.log('');
752
763
  console.log(colors.success(`MCP server ${options.remove} removed successfully`));
753
764
  console.log('');
754
- process.exit(0);
765
+ disconnectAndExit(mcpManager, 0);
755
766
  } catch (error: any) {
756
767
  const { message, suggestion } = formatError(error);
757
768
  console.log('');
758
769
  console.log(colors.error(`Failed to remove MCP server: ${message}`));
759
770
  console.log(colors.textMuted(suggestion));
760
771
  console.log('');
761
- process.exit(1);
772
+ disconnectAndExit(mcpManager, 1);
762
773
  }
763
774
  } else {
764
775
  console.log('');
@@ -898,7 +898,7 @@ export class ContextCompressor {
898
898
  } else {
899
899
  // No user message in kept messages (rare case)
900
900
  // Insert summary as a user message, then add all kept messages
901
- // This ensures valid message order: user �?assistant �?tool �?tool...
901
+ // This ensures valid message order: user assistant tool tool...
902
902
  compressedMessages.push({
903
903
  role: 'user',
904
904
  content: `[Conversation Summary - ${messagesToSummarize.length} messages compressed]\n\n${summary}`,
package/src/mcp.ts CHANGED
@@ -2,6 +2,7 @@ import { spawn, ChildProcess } from 'child_process';
2
2
  import { MCPServerConfig } from './types.js';
3
3
  import { getSingletonSession } from './session.js';
4
4
  import { output as logOutput } from './output-util.js';
5
+ import { icons } from './theme.js';
5
6
 
6
7
  export interface MCPTool {
7
8
  name: string;
@@ -50,10 +51,10 @@ export class MCPServer {
50
51
  if (session?.getIsSdkMode()) {
51
52
  // SDK 模式下不输出
52
53
  } else {
53
- await logOutput('success', `�?MCP Server connected`);
54
+ await logOutput('success', `MCP Server connected`);
54
55
  }
55
56
  } catch (error) {
56
- await logOutput('error', `�?[mcp] Failed to connect MCP Server`, { error: error instanceof Error ? error.message : String(error) });
57
+ await logOutput('error', `[mcp] Failed to connect MCP Server`, { error: error instanceof Error ? error.message : String(error) });
57
58
  throw error;
58
59
  }
59
60
  }
@@ -284,11 +285,11 @@ export class MCPServer {
284
285
  clearTimeout(timeoutId);
285
286
  const serverInfo = this.config.url || this.config.command || 'MCP server';
286
287
  if (error.name === 'AbortError') {
287
- console.error(`\n�?SSE connection timed out`);
288
+ console.error(`\n${icons.error} SSE connection timed out`);
288
289
  console.error(` Server: ${serverInfo}`);
289
290
  console.error(` The server is not responding. Please try again later.`);
290
291
  } else {
291
- console.error(`\n�?SSE connection failed`);
292
+ console.error(`\n${icons.error} SSE connection failed`);
292
293
  console.error(` Server: ${serverInfo}`);
293
294
  console.error(` ${error.message}`);
294
295
  }
@@ -448,12 +449,12 @@ export class MCPServer {
448
449
  } else if (resultData?.tools) {
449
450
  this.handleToolsList(resultData);
450
451
  } else if (resultData?.error) {
451
- console.error(`\n�?MCP server returned an error`);
452
+ console.error(`\n${icons.error} MCP server returned an error`);
452
453
  console.error(` ${resultData.error.message || 'Unknown error'}`);
453
454
  }
454
455
  } catch (error: any) {
455
456
  const serverInfo = this.config.url || this.config.command || 'MCP server';
456
- console.error(`\n�?Failed to load MCP tools`);
457
+ console.error(`\n${icons.error} Failed to load MCP tools`);
457
458
  console.error(` Server: ${serverInfo}`);
458
459
  console.error(` ${error.message}`);
459
460
  }
package/src/session.ts CHANGED
@@ -2922,8 +2922,6 @@ export async function startInteractiveSession(): Promise<void> {
2922
2922
  } catch {
2923
2923
  // Silently ignore update check failures
2924
2924
  }
2925
-
2926
- await session.start();
2927
2925
  }
2928
2926
 
2929
2927
  // Singleton session instance for access from other modules
package/src/theme.ts CHANGED
@@ -272,7 +272,7 @@ export const styleHelpers = {
272
272
  // Animation effects
273
273
  animation: {
274
274
  spinner: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'],
275
- dots: ['⠁', '⠂', '⠄', '⡀', '⡈', '⡐', '⡠', '⣀', '⣁', '⣂', '⣄', '⣌', '⣔', '⣤', '⣥', ''],
275
+ dots: ['⠁', '⠂', '⠄', '⡀', '⡈', '⡐', '⡠', '⣀', '⣁', '⣂', '⣄', '⣌', '⣔', '⣤', '⣥', ''],
276
276
  bars: ['▁', '▂', '▃', '▄', '▅', '▆', '▇', '█'],
277
277
  arrows: ['←', '↖', '↑', '↗', '→', '↘', '↓', '↙']
278
278
  },