-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
57 lines (41 loc) · 1.93 KB
/
Program.cs
File metadata and controls
57 lines (41 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// AI — A Terminal.Gui inline-mode CLI powered by the GitHub Copilot SDK.
//
// Requires: GitHub Copilot CLI installed and authenticated (gh extension install github/gh-copilot)
using System.CommandLine;
using System.CommandLine.Help;
using AI;
using GitHub.Copilot.SDK;
using Terminal.Gui.App;
Option<string> modelOption = new ("--model") { Description = "The Copilot model to use.", DefaultValueFactory = _ => "claude-opus-4.6" };
modelOption.Aliases.Add ("-m");
Argument<string?> promptArgument = new ("prompt") { Description = "Prompt text. If omitted, interactive chat mode starts.", DefaultValueFactory = _ => null };
promptArgument.Arity = ArgumentArity.ZeroOrOne;
RootCommand rootCommand = new ("Terminal.Gui inline-mode Copilot chat") { modelOption, promptArgument };
// Capture parsed values — SetAction runs synchronously, so we store and act after.
var parsedModel = "claude-opus-4.6";
string? parsedPrompt = null;
rootCommand.SetAction (context =>
{
parsedModel = context.GetRequiredValue (modelOption);
parsedPrompt = context.GetValue (promptArgument);
});
ParseResult parseResult = rootCommand.Parse (args);
if (parseResult.Errors.Count > 0 || parseResult.Action is HelpAction)
{
parseResult.Invoke ();
return parseResult.Errors.Count > 0 ? 1 : 0;
}
parseResult.Invoke ();
// ── Start Copilot SDK and run ────────────────────────────────────────────────
await using CopilotClient client = new ();
await client.StartAsync ();
Application.AppModel = AppModel.Inline;
IApplication app = Application.Create ().Init ();
if (parsedPrompt is { })
{
return SingleTurnView.Run (app, client, parsedModel, parsedPrompt);
}
ChatView chatView = new (app, client, parsedModel);
app.Run (chatView);
app.Dispose ();
return chatView.ExitCode;