Skip to content

Commit d5f6734

Browse files
authored
More extraction
1 parent 9402595 commit d5f6734

File tree

10 files changed

+2450
-21
lines changed

10 files changed

+2450
-21
lines changed

README.md

Lines changed: 82 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@ SDK for building engines on the GitHub Copilot agent platform.
44

55
## Overview
66

7-
The Copilot Engine SDK provides the building blocks for engines that run on the GitHub Copilot agent platform. It handles:
7+
The Copilot Engine SDK provides everything you need to build an engine that runs on the GitHub Copilot agent platform:
88

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
9+
- **Platform Client** — send structured events (assistant messages, tool executions, progress updates) to the platform API
10+
- **Git Utilities** — clone repositories, commit and push changes with secure credential handling
11+
- **MCP Server** — a Model Context Protocol server exposing `report_progress` and `reply_to_comment` tools
12+
- **MCP Proxy Discovery** — discover and connect to user-configured MCP servers
13+
- **Event Factories** — create typed platform events for custom event pipelines
14+
- **CLI** — local testing harness that simulates the platform for development
15+
- **[Integration Guide](docs/integration-guide.md)** — step-by-step guide to building an engine
16+
17+
> **📦 Reference Implementation** — See [`github/agent-platform-engine-example`](https://github.com/github/agent-platform-engine-example) for a complete working engine built with this SDK.
1218
1319
## Installation
1420

@@ -83,7 +89,7 @@ finalizeChanges(repoLocation, "Apply fixes");
8389

8490
### PlatformClient
8591

86-
The main client for communicating with the platform API.
92+
The main client for communicating with the platform API. Handles event reporting, progress updates, and history persistence.
8793

8894
```typescript
8995
const platform = new PlatformClient({
@@ -94,41 +100,60 @@ const platform = new PlatformClient({
94100
});
95101
```
96102

97-
**Methods:**
98-
- `sendAssistantMessage(opts)` — report an assistant response
103+
**Event Methods:**
104+
- `sendAssistantMessage(opts)` — report an assistant response with optional tool calls
105+
- `sendToolMessage(opts)` — report a tool result message
99106
- `sendToolExecution(opts)` — report a tool call and its result
100107
- `sendModelCallFailure(opts)` — report a model invocation failure
101108
- `sendTruncation(opts)` — report context truncation
102109
- `sendResponse(opts)` — report a final response
103-
- `sendReportProgress(opts)` — update PR description/progress
110+
111+
**Progress Methods:**
112+
- `sendReportProgress(opts)` — update PR title and description
113+
- `sendCommentReply(opts)` — reply to a PR comment
114+
115+
**History Methods:**
116+
- `sendRawProgress(payloads)` — send raw progress payloads (used for session history persistence)
117+
- `fetchProgress(opts)` — retrieve previously stored progress records
104118

105119
### Git Utilities
106120

121+
Secure git operations with credential handling via `http.extraHeader` (tokens never appear in URLs or process listings).
122+
107123
```typescript
108124
import { cloneRepo, commitAndPush, finalizeChanges } from "@github/copilot-engine-sdk";
109125

110126
// Clone a repository with branch setup
111127
const repoPath = cloneRepo({
112-
serverUrl: string;
128+
serverUrl: string; // e.g., "https://github.com"
113129
repository: string; // "owner/repo"
114-
gitToken: string;
115-
branchName: string;
116-
commitLogin: string;
117-
commitEmail: string;
130+
gitToken: string; // installation token
131+
branchName: string; // branch to checkout or create
132+
commitLogin: string; // git author name
133+
commitEmail: string; // git author email
118134
cloneDir?: string; // default: "/tmp/workspace"
119135
});
120136

121-
// Commit and push changes
137+
// Commit and push changes (force push for engine-owned branches)
122138
const result = commitAndPush(repoPath, "commit message");
123139

124-
// Finalize: commit + push any remaining uncommitted changes
140+
// Finalize: commit + push any remaining uncommitted changes (non-fatal)
125141
finalizeChanges(repoPath, "final commit message");
126142
```
127143

144+
**Branch handling:**
145+
- If the branch exists on remote, it checks out the existing branch
146+
- If the branch doesn't exist, it creates a new branch from the default branch
147+
- Uses `git ls-remote` to distinguish "branch not found" from auth/network errors
148+
128149
### MCP Server
129150

130151
The SDK includes an MCP server that can be used with any LLM SDK that supports the Model Context Protocol.
131152

153+
**Tools provided:**
154+
- `report_progress` — commits changes and updates the PR description with a progress checklist
155+
- `reply_to_comment` — replies to a PR review comment
156+
132157
```typescript
133158
import { createEngineMcpServer, startEngineMcpServer } from "@github/copilot-engine-sdk";
134159

@@ -149,26 +174,57 @@ await startEngineMcpServer(server);
149174
node dist/mcp-server.js /path/to/working-directory
150175
```
151176

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
177+
### MCP Proxy Discovery
178+
179+
Discover user-configured MCP servers passed to the engine via the platform.
180+
181+
```typescript
182+
import { discoverMCPServers, isMCPProxyAvailable } from "@github/copilot-engine-sdk";
183+
184+
// Check if MCP proxy is available
185+
if (isMCPProxyAvailable()) {
186+
const servers = discoverMCPServers();
187+
// Returns discovered MCP servers the user has configured
188+
}
189+
```
157190

158191
### Event Factories
159192

160-
For advanced usage, you can create event objects directly:
193+
For advanced usage, create event objects directly:
161194

162195
```typescript
163196
import {
164197
createAssistantMessageEvent,
198+
createToolMessageEvent,
165199
createToolExecutionEvent,
166200
createModelCallFailureEvent,
167201
createTruncationEvent,
168202
createResponseEvent,
169203
} from "@github/copilot-engine-sdk";
170204
```
171205

206+
## CLI — Local Testing
207+
208+
The SDK includes a CLI tool for testing engines locally without the full platform infrastructure. It simulates the platform API, clones a repo, and runs your engine command.
209+
210+
```bash
211+
cd cli && go build ./cmd/engine-cli
212+
213+
engine-cli run "node dist/index.js" \
214+
--repo https://github.com/owner/repo \
215+
--problem-statement "Fix the bug in auth.ts" \
216+
--action fix \
217+
--timeout 5m
218+
```
219+
220+
The CLI:
221+
- Clones the target repository to a temp directory
222+
- Starts a mock HTTP server that mimics the platform API
223+
- Spawns your engine with the required environment variables
224+
- Displays progress events in formatted output
225+
226+
See `engine-cli run --help` for all options.
227+
172228
## Environment Variables
173229

174230
Engines receive these environment variables from the platform:
@@ -183,6 +239,11 @@ Engines receive these environment variables from the platform:
183239
| `GITHUB_INFERENCE_URL` | Inference API endpoint |
184240
| `GITHUB_GIT_TOKEN` | Token for git operations |
185241

242+
## Documentation
243+
244+
- **[Integration Guide](docs/integration-guide.md)** — step-by-step guide to building an engine from scratch
245+
- **[Example Engine](https://github.com/github/agent-platform-engine-example)** — reference implementation
246+
186247
## License
187248

188249
MIT

0 commit comments

Comments
 (0)