-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinstruction_directories.cpp
More file actions
55 lines (47 loc) · 1.92 KB
/
Copy pathinstruction_directories.cpp
File metadata and controls
55 lines (47 loc) · 1.92 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
// Copyright (c) 2025 Elias Bachaalany
// SPDX-License-Identifier: MIT
/// @file instruction_directories.cpp
/// @brief Compile-only demo for the v0.1.49 `instructionDirectories` field on
/// `SessionConfig` and `ResumeSessionConfig`.
///
/// Builds a `SessionConfig` populated with per-session instruction directories
/// and dumps the resulting `session.create` request payload that the SDK would
/// send to the Copilot CLI. No network or CLI is required: this example
/// exercises the public `build_session_create_request` helper so the API is
/// exercised at build time and the JSON envelope is human-inspectable.
///
/// Background: instructionDirectories (upstream nodejs PR #1190) lets a host
/// application supplement the global instruction set with additional
/// directories scoped to a single session — useful for ephemeral or
/// workspace-specific guidance without mutating the user's CLI config.
#include <copilot/copilot.hpp>
#include <iostream>
int main()
{
using namespace copilot;
SessionConfig cfg;
cfg.client_name = "instruction-dirs-demo";
cfg.instruction_directories = std::vector<std::string>{
"/etc/copilot/instructions",
"./workspace/.copilot/instructions",
};
cfg.enable_config_discovery = true;
cfg.streaming = false;
json request = build_session_create_request(cfg);
std::cout << "session.create request payload:\n";
std::cout << request.dump(2) << "\n";
// Sanity-check the fields actually round-tripped through the builder.
if (!request.contains("instructionDirectories") ||
!request["instructionDirectories"].is_array() ||
request["instructionDirectories"].size() != 2)
{
std::cerr << "instructionDirectories field missing or malformed\n";
return 1;
}
if (request.value("clientName", std::string{}) != "instruction-dirs-demo")
{
std::cerr << "clientName missing\n";
return 1;
}
return 0;
}