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
56 lines (49 loc) · 1.66 KB
/
Copy pathProgram.cs
File metadata and controls
56 lines (49 loc) · 1.66 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
using GitHub.Copilot;
using GitHub.Copilot.Rpc;
var permissionLog = 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) =>
{
var toolName = request switch
{
PermissionRequestCustomTool ct => ct.ToolName,
PermissionRequestShell sh => "shell",
PermissionRequestWrite wr => wr.FileName ?? "write",
PermissionRequestRead rd => rd.Path ?? "read",
PermissionRequestMcp mcp => mcp.ToolName ?? "mcp",
_ => request.Kind,
};
permissionLog.Add($"approved:{toolName}");
return Task.FromResult<PermissionDecision>(PermissionDecision.ApproveOnce());
},
Hooks = new SessionHooks
{
OnPreToolUse = (input, invocation) =>
Task.FromResult<PreToolUseHookOutput?>(new PreToolUseHookOutput { PermissionDecision = "allow" }),
},
});
var response = await session.SendAndWaitAsync(new MessageOptions
{
Prompt = "List the files in the current directory using glob with pattern '*.md'.",
});
if (response != null)
{
Console.WriteLine(response.Data?.Content);
}
Console.WriteLine("\n--- Permission request log ---");
foreach (var entry in permissionLog)
{
Console.WriteLine($" {entry}");
}
Console.WriteLine($"\nTotal permission requests: {permissionLog.Count}");
}
finally
{
await client.StopAsync();
}