From aa3d8daae6ae57a713f3c5397966c8eacbccd149 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Fri, 18 Apr 2025 13:27:08 -0700 Subject: [PATCH 1/3] Support Alias --- shell/AIShell.Kernel/Command/ClearCommand.cs | 1 + shell/AIShell.Kernel/Command/CommandRunner.cs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/shell/AIShell.Kernel/Command/ClearCommand.cs b/shell/AIShell.Kernel/Command/ClearCommand.cs index 995a3189..91b92568 100644 --- a/shell/AIShell.Kernel/Command/ClearCommand.cs +++ b/shell/AIShell.Kernel/Command/ClearCommand.cs @@ -9,6 +9,7 @@ public ClearCommand() : base("cls", "Clear the screen.") { this.SetHandler(ClearAction); + this.AddAlias("clear"); } private void ClearAction() diff --git a/shell/AIShell.Kernel/Command/CommandRunner.cs b/shell/AIShell.Kernel/Command/CommandRunner.cs index 51048a72..f4161854 100644 --- a/shell/AIShell.Kernel/Command/CommandRunner.cs +++ b/shell/AIShell.Kernel/Command/CommandRunner.cs @@ -57,7 +57,17 @@ internal void LoadCommands(IEnumerable commands, string agentName) { command.Shell = _shell; command.Source = agentName; + + // TODO: need to think about how to handle command names/aliases collision. + // We don't handle collision today -- it will throw when collision happens. _commands.Add(command.Name, command); + foreach (string alias in command.Aliases) + { + if (!string.IsNullOrWhiteSpace(alias)) + { + _commands.Add(alias, command); + } + } } } @@ -79,7 +89,16 @@ internal void UnloadAgentCommands() foreach (var command in agentCommands) { + // TODO: need to update accordingly when we handle command names/aliases collision. _commands.Remove(command.Name); + foreach (string alias in command.Aliases) + { + if (!string.IsNullOrWhiteSpace(alias)) + { + _commands.Remove(alias); + } + } + command.Dispose(); } } From 8d5d2d2d8ab67843a74f82490ae681206adb9c70 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Fri, 18 Apr 2025 15:12:26 -0700 Subject: [PATCH 2/3] Fix issues --- shell/AIShell.Kernel/Command/CommandRunner.cs | 14 ++++---------- shell/AIShell.Kernel/Command/HelpCommand.cs | 2 +- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/shell/AIShell.Kernel/Command/CommandRunner.cs b/shell/AIShell.Kernel/Command/CommandRunner.cs index f4161854..515d430f 100644 --- a/shell/AIShell.Kernel/Command/CommandRunner.cs +++ b/shell/AIShell.Kernel/Command/CommandRunner.cs @@ -58,15 +58,12 @@ internal void LoadCommands(IEnumerable commands, string agentName) command.Shell = _shell; command.Source = agentName; + // The 'command.Name' is included in the 'command.Aliases' collection. // TODO: need to think about how to handle command names/aliases collision. // We don't handle collision today -- it will throw when collision happens. - _commands.Add(command.Name, command); foreach (string alias in command.Aliases) { - if (!string.IsNullOrWhiteSpace(alias)) - { - _commands.Add(alias, command); - } + _commands.Add(alias, command); } } } @@ -89,14 +86,11 @@ internal void UnloadAgentCommands() foreach (var command in agentCommands) { + // The 'command.Name' is included in the 'command.Aliases' collection. // TODO: need to update accordingly when we handle command names/aliases collision. - _commands.Remove(command.Name); foreach (string alias in command.Aliases) { - if (!string.IsNullOrWhiteSpace(alias)) - { - _commands.Remove(alias); - } + _commands.Remove(alias); } command.Dispose(); diff --git a/shell/AIShell.Kernel/Command/HelpCommand.cs b/shell/AIShell.Kernel/Command/HelpCommand.cs index 30a9751f..5ad0c29b 100644 --- a/shell/AIShell.Kernel/Command/HelpCommand.cs +++ b/shell/AIShell.Kernel/Command/HelpCommand.cs @@ -17,7 +17,7 @@ private void HelpAction() var host = shellImpl.Host; var commands = shellImpl.CommandRunner.Commands; - var list = commands.Values.Order(new CommandComparer()).ToList(); + var list = commands.Values.Distinct().Order(new CommandComparer()).ToList(); host.WriteLine(); host.MarkupLine("[bold white]-[/] Type then press [bold olive underline]Enter[/] to chat with the chosen AI agent."); From d36eb49281d25a24882d10a2448e8838eaf510fe Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Fri, 18 Apr 2025 15:23:35 -0700 Subject: [PATCH 3/3] Minor update --- shell/AIShell.Kernel/Command/ClearCommand.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/AIShell.Kernel/Command/ClearCommand.cs b/shell/AIShell.Kernel/Command/ClearCommand.cs index 91b92568..8f775e31 100644 --- a/shell/AIShell.Kernel/Command/ClearCommand.cs +++ b/shell/AIShell.Kernel/Command/ClearCommand.cs @@ -6,10 +6,10 @@ namespace AIShell.Kernel.Commands; internal sealed class ClearCommand : CommandBase { public ClearCommand() - : base("cls", "Clear the screen.") + : base("clear", "Clear the screen.") { this.SetHandler(ClearAction); - this.AddAlias("clear"); + this.AddAlias("cls"); } private void ClearAction()