forked from github/copilot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
72 lines (65 loc) · 2.26 KB
/
Copy pathProgram.cs
File metadata and controls
72 lines (65 loc) · 2.26 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using GitHub.Copilot;
using GitHub.Copilot.Rpc;
var hookLog = new List<string>();
using var client = new CopilotClient();
await client.StartAsync();
try
{
await using var session = await client.CreateSessionAsync(new SessionConfig
{
Model = "claude-haiku-4.5",
OnPermissionRequest = (request, invocation) =>
Task.FromResult<PermissionDecision>(PermissionDecision.ApproveOnce()),
Hooks = new SessionHooks
{
OnSessionStart = (input, invocation) =>
{
hookLog.Add("onSessionStart");
return Task.FromResult<SessionStartHookOutput?>(null);
},
OnSessionEnd = (input, invocation) =>
{
hookLog.Add("onSessionEnd");
return Task.FromResult<SessionEndHookOutput?>(null);
},
OnPreToolUse = (input, invocation) =>
{
hookLog.Add($"onPreToolUse:{input.ToolName}");
return Task.FromResult<PreToolUseHookOutput?>(new PreToolUseHookOutput { PermissionDecision = "allow" });
},
OnPostToolUse = (input, invocation) =>
{
hookLog.Add($"onPostToolUse:{input.ToolName}");
return Task.FromResult<PostToolUseHookOutput?>(null);
},
OnUserPromptSubmitted = (input, invocation) =>
{
hookLog.Add("onUserPromptSubmitted");
return Task.FromResult<UserPromptSubmittedHookOutput?>(null);
},
OnErrorOccurred = (input, invocation) =>
{
hookLog.Add($"onErrorOccurred:{input.Error}");
return Task.FromResult<ErrorOccurredHookOutput?>(null);
},
},
});
var response = await session.SendAndWaitAsync(new MessageOptions
{
Prompt = "List the files in the current directory using the glob tool with pattern '*.md'.",
});
if (response != null)
{
Console.WriteLine(response.Data?.Content);
}
Console.WriteLine("\n--- Hook execution log ---");
foreach (var entry in hookLog)
{
Console.WriteLine($" {entry}");
}
Console.WriteLine($"\nTotal hooks fired: {hookLog.Count}");
}
finally
{
await client.StopAsync();
}