Skip to content

Commit c90f4a7

Browse files
authored
Initial commit
0 parents  commit c90f4a7

File tree

11 files changed

+3446
-0
lines changed

11 files changed

+3446
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
dist/
3+
*.tsbuildinfo

README.md

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
# @github/copilot-engine-sdk
2+
3+
SDK for building engines on the GitHub Copilot agent platform.
4+
5+
## Overview
6+
7+
The Copilot Engine SDK provides the building blocks for engines that run on the GitHub Copilot agent platform. It handles:
8+
9+
- **Platform event reporting** — send structured events (assistant messages, tool executions, model call failures) to the platform API
10+
- **Git utilities** — clone repositories, commit and push changes with proper credential configuration
11+
- **MCP server** — a Model Context Protocol server exposing `report_progress` and `reply_to_comment` tools for use with any LLM SDK
12+
13+
## Installation
14+
15+
This package is hosted as a private GitHub repository. Add it to your `package.json`:
16+
17+
```json
18+
{
19+
"dependencies": {
20+
"@github/copilot-engine-sdk": "github:github/copilot-engine-sdk#main"
21+
}
22+
}
23+
```
24+
25+
Then run `npm install`. Git credentials must be available for private repo access (e.g., `GITHUB_TOKEN`, SSH keys, or git credential helper).
26+
27+
### Local Development
28+
29+
For local development with a cloned copy of the SDK:
30+
31+
```bash
32+
# In the SDK directory — register for linking and build
33+
cd copilot-engine-sdk
34+
npm link
35+
36+
# In your engine directory — link to local SDK
37+
cd ../your-engine
38+
npm link @github/copilot-engine-sdk
39+
```
40+
41+
Changes to the SDK source are reflected immediately after running `npm run build` in the SDK directory.
42+
43+
## Quick Start
44+
45+
```typescript
46+
import {
47+
PlatformClient,
48+
cloneRepo,
49+
finalizeChanges,
50+
createEngineMcpServer,
51+
} from "@github/copilot-engine-sdk";
52+
53+
// Initialize the platform client for event reporting
54+
const platform = new PlatformClient({
55+
apiUrl: process.env.GITHUB_PLATFORM_API_URL!,
56+
jobId: process.env.GITHUB_JOB_ID!,
57+
token: process.env.GITHUB_PLATFORM_API_TOKEN!,
58+
});
59+
60+
// Clone the target repository
61+
const repoLocation = cloneRepo({
62+
serverUrl: "https://github.com",
63+
repository: "owner/repo",
64+
gitToken: process.env.GITHUB_GIT_TOKEN!,
65+
branchName: "copilot/fix-issue-123",
66+
commitLogin: "copilot[bot]",
67+
commitEmail: "copilot@github.com",
68+
});
69+
70+
// Send events to the platform
71+
await platform.sendAssistantMessage({
72+
turn: 1,
73+
callId: "call-123",
74+
content: "I'll help you with that.",
75+
toolCalls: [],
76+
});
77+
78+
// Finalize and push any remaining changes
79+
finalizeChanges(repoLocation, "Apply fixes");
80+
```
81+
82+
## API Reference
83+
84+
### PlatformClient
85+
86+
The main client for communicating with the platform API.
87+
88+
```typescript
89+
const platform = new PlatformClient({
90+
apiUrl: string; // Platform API URL
91+
jobId: string; // Job identifier
92+
token: string; // API authentication token
93+
nonce?: string; // Optional job nonce
94+
});
95+
```
96+
97+
**Methods:**
98+
- `sendAssistantMessage(opts)` — report an assistant response
99+
- `sendToolExecution(opts)` — report a tool call and its result
100+
- `sendModelCallFailure(opts)` — report a model invocation failure
101+
- `sendTruncation(opts)` — report context truncation
102+
- `sendResponse(opts)` — report a final response
103+
- `sendReportProgress(opts)` — update PR description/progress
104+
105+
### Git Utilities
106+
107+
```typescript
108+
import { cloneRepo, commitAndPush, finalizeChanges } from "@github/copilot-engine-sdk";
109+
110+
// Clone a repository with branch setup
111+
const repoPath = cloneRepo({
112+
serverUrl: string;
113+
repository: string; // "owner/repo"
114+
gitToken: string;
115+
branchName: string;
116+
commitLogin: string;
117+
commitEmail: string;
118+
cloneDir?: string; // default: "/tmp/workspace"
119+
});
120+
121+
// Commit and push changes
122+
const result = commitAndPush(repoPath, "commit message");
123+
124+
// Finalize: commit + push any remaining uncommitted changes
125+
finalizeChanges(repoPath, "final commit message");
126+
```
127+
128+
### MCP Server
129+
130+
The SDK includes an MCP server that can be used with any LLM SDK that supports the Model Context Protocol.
131+
132+
```typescript
133+
import { createEngineMcpServer, startEngineMcpServer } from "@github/copilot-engine-sdk";
134+
135+
const server = createEngineMcpServer({
136+
workingDir: "/path/to/repo",
137+
push: true, // push commits to remote (default: true)
138+
platformClient: platform, // optional: enables PR description updates
139+
logFile: "/tmp/mcp.log", // optional: log file path (default: /tmp/mcp-server.log)
140+
});
141+
142+
// Start as STDIO MCP server
143+
await startEngineMcpServer(server);
144+
```
145+
146+
**Standalone usage** (spawned as a child process):
147+
148+
```bash
149+
node dist/mcp-server.js /path/to/working-directory
150+
```
151+
152+
Environment variables read by the standalone server:
153+
- `GITHUB_PLATFORM_API_URL` — platform API endpoint
154+
- `GITHUB_JOB_ID` — job identifier
155+
- `GITHUB_PLATFORM_API_TOKEN` — API token
156+
- `GITHUB_JOB_NONCE` — optional job nonce
157+
158+
### Event Factories
159+
160+
For advanced usage, you can create event objects directly:
161+
162+
```typescript
163+
import {
164+
createAssistantMessageEvent,
165+
createToolExecutionEvent,
166+
createModelCallFailureEvent,
167+
createTruncationEvent,
168+
createResponseEvent,
169+
} from "@github/copilot-engine-sdk";
170+
```
171+
172+
## Environment Variables
173+
174+
Engines receive these environment variables from the platform:
175+
176+
| Variable | Description |
177+
|----------|-------------|
178+
| `GITHUB_JOB_ID` | Unique job identifier |
179+
| `GITHUB_PLATFORM_API_TOKEN` | Token for platform API authentication |
180+
| `GITHUB_PLATFORM_API_URL` | Platform API base URL |
181+
| `GITHUB_JOB_NONCE` | Job nonce for request signing |
182+
| `GITHUB_INFERENCE_TOKEN` | Token for LLM inference calls |
183+
| `GITHUB_INFERENCE_URL` | Inference API endpoint |
184+
| `GITHUB_GIT_TOKEN` | Token for git operations |
185+
186+
## License
187+
188+
MIT

0 commit comments

Comments
 (0)