Skip to content

Commit 417ceb0

Browse files
authored
Add suggestion to use /code post or /code copy after parameter injection (#279)
- Update `IShell` to expose whether a channel to a shell application has been established. - Add suggestion to use `/code post` or `/code copy` after placeholder replacement, depending on whether a connected shell is available.
1 parent 041921f commit 417ceb0

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

shell/AIShell.Abstraction/IShell.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ public interface IShell
1010
/// </summary>
1111
IHost Host { get; }
1212

13+
/// <summary>
14+
/// Indicates whether the bi-directional channel with an application (e.g. a PowerShell session) has been established.
15+
/// </summary>
16+
bool ChannelEstablished { get; }
17+
1318
/// <summary>
1419
/// The token to indicate cancellation when `Ctrl+c` is pressed by user.
1520
/// </summary>

shell/AIShell.Kernel/Shell.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ internal sealed class Shell : IShell
7777
#region IShell implementation
7878

7979
IHost IShell.Host => Host;
80+
bool IShell.ChannelEstablished => Channel is not null;
8081
CancellationToken IShell.CancellationToken => _cancellationSource.Token;
8182
List<CodeBlock> IShell.ExtractCodeBlocks(string text, out List<SourceInfo> sourceInfos) => Utils.ExtractCodeBlocks(text, out sourceInfos);
8283

shell/agents/Microsoft.Azure.Agent/AzureAgent.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ public async Task<bool> ChatAsync(string input, IShell shell)
265265
ArgPlaceholder = new ArgumentPlaceholder(input, data, _httpClient);
266266
}
267267

268-
string answer = data is null ? _copilotResponse.Text : GenerateAnswer(data);
268+
string answer = data is null ? _copilotResponse.Text : GenerateAnswer(data, shell);
269269
host.RenderFullResponse(answer);
270270
}
271271
}
@@ -503,8 +503,13 @@ internal void ReplaceKnownPlaceholders(ResponseData data)
503503
}
504504
}
505505

506-
internal string GenerateAnswer(ResponseData data)
506+
internal string GenerateAnswer(ResponseData data, IShell shell)
507507
{
508+
// Use green (0,195,0) on grey (48,48,48) for rendering commands in the markdown.
509+
// TODO: the color formatting should be exposed by the shell as utility method.
510+
const string CommandVTColor = "\x1b[38;2;0;195;0;48;2;48;48;48m";
511+
const string ResetVT = "\x1b[0m";
512+
508513
_buffer.Clear();
509514
string text = data.Text;
510515

@@ -528,7 +533,13 @@ internal string GenerateAnswer(ResponseData data)
528533
_buffer.Append(text.AsSpan(index, text.Length - index));
529534
}
530535

531-
if (data.PlaceholderSet is not null)
536+
if (data.PlaceholderSet is null)
537+
{
538+
_buffer.Append(shell.ChannelEstablished
539+
? $"\nRun {CommandVTColor} /code post {ResetVT} or press {CommandVTColor} Ctrl+d,Ctrl+d {ResetVT} to post the code to the connected shell.\n"
540+
: $"\nRun {CommandVTColor} /code copy {ResetVT} or press {CommandVTColor} Ctrl+d,Ctrl+c {ResetVT} to copy the code to clipboard.\n");
541+
}
542+
else
532543
{
533544
// Construct text about the placeholders if we successfully stripped the placeholder
534545
// section off from the original response.
@@ -547,7 +558,7 @@ internal string GenerateAnswer(ResponseData data)
547558

548559
// Use green (0,195,0) on grey (48,48,48) for rendering the command '/replace'.
549560
// TODO: the color formatting should be exposed by the shell as utility method.
550-
_buffer.Append("\nRun \x1b[38;2;0;195;0;48;2;48;48;48m /replace \x1b[0m to get assistance in placeholder replacement.\n");
561+
_buffer.Append($"\nRun {CommandVTColor} /replace {ResetVT} to get assistance in placeholder replacement.\n");
551562
}
552563
}
553564

shell/agents/Microsoft.Azure.Agent/Command.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,6 @@ private async Task<string> RegenerateAsync()
254254
_agent.ResetArgumentPlaceholder();
255255
}
256256

257-
return _agent.GenerateAnswer(data);
257+
return _agent.GenerateAnswer(data, Shell);
258258
}
259259
}

shell/shell.common.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<TargetFramework>net8.0</TargetFramework>
99
<ImplicitUsings>enable</ImplicitUsings>
1010
<LangVersion>12.0</LangVersion>
11-
<Version>0.1.0-alpha.19</Version>
11+
<Version>0.1.0-alpha.20</Version>
1212

1313
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1414
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

0 commit comments

Comments
 (0)