Skip to content

Commit 68df308

Browse files
committed
Support built-in tools for AIShell
1 parent 210d438 commit 68df308

File tree

10 files changed

+534
-59
lines changed

10 files changed

+534
-59
lines changed

shell/AIShell.Abstraction/NamedPipe.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public enum ContextType : int
4343
/// <summary>
4444
/// Ask for the current working directory of the shell.
4545
/// </summary>
46-
WorkingDirectory = 0,
46+
CurrentLocation = 0,
4747

4848
/// <summary>
4949
/// Ask for the command history of the shell session.

shell/AIShell.Integration/Channel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ private PostContextMessage OnAskContext(AskContextMessage askContextMessage)
368368
string contextInfo;
369369
switch (type)
370370
{
371-
case ContextType.WorkingDirectory:
371+
case ContextType.CurrentLocation:
372372
contextInfo = JsonSerializer.Serialize(
373373
new { Provider = _currentLocation.Provider.Name, _currentLocation.Path });
374374
break;

shell/AIShell.Integration/Commands/InvokeAishCommand.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public class InvokeAIShellCommand : PSCmdlet
1717
/// <summary>
1818
/// Sets and gets the query to be sent to AIShell
1919
/// </summary>
20-
[Parameter(Mandatory = true, ValueFromRemainingArguments = true, ParameterSetName = DefaultSet)]
21-
[Parameter(Mandatory = true, ValueFromRemainingArguments = true, ParameterSetName = ClipboardSet)]
20+
[Parameter(Position = 0, ParameterSetName = DefaultSet)]
21+
[Parameter(Position = 0, ParameterSetName = ClipboardSet)]
2222
public string[] Query { get; set; }
2323

2424
/// <summary>
@@ -88,6 +88,26 @@ protected override void EndProcessing()
8888
message = "/exit";
8989
break;
9090
default:
91+
if (Query is not null)
92+
{
93+
message = string.Join(' ', Query);
94+
}
95+
else
96+
{
97+
Host.UI.Write("Query: ");
98+
message = Host.UI.ReadLine();
99+
}
100+
101+
if (string.IsNullOrEmpty(message))
102+
{
103+
ThrowTerminatingError(
104+
new ErrorRecord(
105+
new ArgumentException("A query message is required."),
106+
"QueryIsMissing",
107+
ErrorCategory.InvalidArgument,
108+
targetObject: null));
109+
}
110+
91111
Collection<string> results = null;
92112
if (_contextObjects is not null)
93113
{
@@ -107,7 +127,6 @@ protected override void EndProcessing()
107127
}
108128

109129
context = results?.Count > 0 ? results[0] : null;
110-
message = string.Join(' ', Query);
111130
break;
112131
}
113132

shell/AIShell.Kernel/Command/CodeCommand.cs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@ public CodeCommand()
3636
copy.SetHandler(CopyAction, nth);
3737
save.SetHandler(SaveAction, file, append);
3838
post.SetHandler(PostAction, nth);
39-
40-
var get = new Command("get", "Post context information.");
41-
var ctx = new Argument<string>("context");
42-
get.AddArgument(ctx);
43-
get.SetHandler(GetAction, ctx);
44-
AddCommand(get);
4539
}
4640

4741
private static string GetCodeText(Shell shell, int index)
@@ -187,29 +181,4 @@ private void PostAction(int nth)
187181
host.WriteErrorLine(e.Message);
188182
}
189183
}
190-
191-
private async Task GetAction(string context)
192-
{
193-
var shell = (Shell)Shell;
194-
var host = shell.Host;
195-
196-
if (shell.Channel is null)
197-
{
198-
host.WriteErrorLine("Cannot get context information because the bi-directional channel was not established.");
199-
return;
200-
}
201-
202-
try
203-
{
204-
var type = Enum.Parse<ContextType>(context);
205-
var message = new AskContextMessage(type);
206-
207-
PostContextMessage response = await shell.Channel.AskContext(message, shell.CancellationToken);
208-
host.WriteLine(response.ContextInfo);
209-
}
210-
catch (Exception e)
211-
{
212-
host.WriteErrorLine(e.Message);
213-
}
214-
}
215184
}

shell/AIShell.Kernel/Command/McpCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ private void ShowMCPData()
2828
{
2929
var shell = (Shell)Shell;
3030
var host = shell.Host;
31+
var mcpManager = shell.McpManager;
3132

32-
if (shell.McpManager.McpServers.Count is 0)
33+
if (mcpManager.McpServers.Count is 0 && mcpManager.BuiltInTools is null)
3334
{
3435
host.WriteErrorLine("No MCP server is available.");
3536
return;

shell/AIShell.Kernel/Host.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,20 @@ internal void RenderMcpServersAndTools(McpManager mcpManager)
662662
}
663663
}
664664

665+
if (mcpManager.BuiltInTools is { Count: > 0 })
666+
{
667+
if (toolTable.Rows is { Count: > 0 })
668+
{
669+
toolTable.AddEmptyRow();
670+
}
671+
672+
toolTable.AddRow($"[olive underline]{McpManager.BuiltInServerName}[/]", "[green]\u2713 Ready[/]", string.Empty);
673+
foreach (var item in mcpManager.BuiltInTools)
674+
{
675+
toolTable.AddRow(string.Empty, item.Key.EscapeMarkup(), item.Value.Description.EscapeMarkup());
676+
}
677+
}
678+
665679
if (readyServers is not null)
666680
{
667681
foreach (var (name, status, info) in readyServers)

0 commit comments

Comments
 (0)