@github-tools/sdk 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +126 -13
- package/dist/agents-Cdb0a8CP.mjs +1455 -0
- package/dist/agents-Cdb0a8CP.mjs.map +1 -0
- package/dist/agents-CnwdZ0Wk.d.mts +692 -0
- package/dist/agents-CnwdZ0Wk.d.mts.map +1 -0
- package/dist/index.d.mts +250 -427
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +77 -776
- package/dist/index.mjs.map +1 -1
- package/dist/workflow.d.mts +649 -0
- package/dist/workflow.d.mts.map +1 -0
- package/dist/workflow.mjs +55 -0
- package/dist/workflow.mjs.map +1 -0
- package/package.json +22 -4
|
@@ -0,0 +1,1455 @@
|
|
|
1
|
+
import { createGithubTools } from "./index.mjs";
|
|
2
|
+
import { ToolLoopAgent, tool } from "ai";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { Octokit } from "octokit";
|
|
5
|
+
|
|
6
|
+
//#region src/client.ts
|
|
7
|
+
function createOctokit(token) {
|
|
8
|
+
return new Octokit({ auth: token });
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/tools/repository.ts
|
|
13
|
+
async function getRepositoryStep({ token, owner, repo }) {
|
|
14
|
+
"use step";
|
|
15
|
+
const { data } = await createOctokit(token).rest.repos.get({
|
|
16
|
+
owner,
|
|
17
|
+
repo
|
|
18
|
+
});
|
|
19
|
+
return {
|
|
20
|
+
name: data.name,
|
|
21
|
+
fullName: data.full_name,
|
|
22
|
+
description: data.description,
|
|
23
|
+
url: data.html_url,
|
|
24
|
+
defaultBranch: data.default_branch,
|
|
25
|
+
stars: data.stargazers_count,
|
|
26
|
+
forks: data.forks_count,
|
|
27
|
+
openIssues: data.open_issues_count,
|
|
28
|
+
language: data.language,
|
|
29
|
+
private: data.private,
|
|
30
|
+
createdAt: data.created_at,
|
|
31
|
+
updatedAt: data.updated_at
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const getRepository = (token) => tool({
|
|
35
|
+
description: "Get information about a GitHub repository including description, stars, forks, language, and default branch",
|
|
36
|
+
inputSchema: z.object({
|
|
37
|
+
owner: z.string().describe("Repository owner (user or organization)"),
|
|
38
|
+
repo: z.string().describe("Repository name")
|
|
39
|
+
}),
|
|
40
|
+
execute: async (args) => getRepositoryStep({
|
|
41
|
+
token,
|
|
42
|
+
...args
|
|
43
|
+
})
|
|
44
|
+
});
|
|
45
|
+
async function listBranchesStep({ token, owner, repo, perPage }) {
|
|
46
|
+
"use step";
|
|
47
|
+
const { data } = await createOctokit(token).rest.repos.listBranches({
|
|
48
|
+
owner,
|
|
49
|
+
repo,
|
|
50
|
+
per_page: perPage
|
|
51
|
+
});
|
|
52
|
+
return data.map((branch) => ({
|
|
53
|
+
name: branch.name,
|
|
54
|
+
sha: branch.commit.sha,
|
|
55
|
+
protected: branch.protected
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
const listBranches = (token) => tool({
|
|
59
|
+
description: "List branches in a GitHub repository",
|
|
60
|
+
inputSchema: z.object({
|
|
61
|
+
owner: z.string().describe("Repository owner"),
|
|
62
|
+
repo: z.string().describe("Repository name"),
|
|
63
|
+
perPage: z.number().optional().default(30).describe("Number of branches to return (max 100)")
|
|
64
|
+
}),
|
|
65
|
+
execute: async (args) => listBranchesStep({
|
|
66
|
+
token,
|
|
67
|
+
...args
|
|
68
|
+
})
|
|
69
|
+
});
|
|
70
|
+
async function getFileContentStep({ token, owner, repo, path, ref }) {
|
|
71
|
+
"use step";
|
|
72
|
+
const { data } = await createOctokit(token).rest.repos.getContent({
|
|
73
|
+
owner,
|
|
74
|
+
repo,
|
|
75
|
+
path,
|
|
76
|
+
ref
|
|
77
|
+
});
|
|
78
|
+
if (Array.isArray(data)) return {
|
|
79
|
+
type: "directory",
|
|
80
|
+
entries: data.map((e) => ({
|
|
81
|
+
name: e.name,
|
|
82
|
+
type: e.type,
|
|
83
|
+
path: e.path
|
|
84
|
+
}))
|
|
85
|
+
};
|
|
86
|
+
if (data.type !== "file") return {
|
|
87
|
+
type: data.type,
|
|
88
|
+
path: data.path
|
|
89
|
+
};
|
|
90
|
+
const content = Buffer.from(data.content, "base64").toString("utf-8");
|
|
91
|
+
return {
|
|
92
|
+
type: "file",
|
|
93
|
+
path: data.path,
|
|
94
|
+
sha: data.sha,
|
|
95
|
+
size: data.size,
|
|
96
|
+
content
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
const getFileContent = (token) => tool({
|
|
100
|
+
description: "Get the content of a file from a GitHub repository",
|
|
101
|
+
inputSchema: z.object({
|
|
102
|
+
owner: z.string().describe("Repository owner"),
|
|
103
|
+
repo: z.string().describe("Repository name"),
|
|
104
|
+
path: z.string().describe("Path to the file in the repository"),
|
|
105
|
+
ref: z.string().optional().describe("Branch, tag, or commit SHA (defaults to the default branch)")
|
|
106
|
+
}),
|
|
107
|
+
execute: async (args) => getFileContentStep({
|
|
108
|
+
token,
|
|
109
|
+
...args
|
|
110
|
+
})
|
|
111
|
+
});
|
|
112
|
+
async function createBranchStep({ token, owner, repo, branch, from }) {
|
|
113
|
+
"use step";
|
|
114
|
+
const octokit = createOctokit(token);
|
|
115
|
+
let sha = from;
|
|
116
|
+
if (!sha || !sha.match(/^[0-9a-f]{40}$/i)) {
|
|
117
|
+
const { data: ref } = await octokit.rest.git.getRef({
|
|
118
|
+
owner,
|
|
119
|
+
repo,
|
|
120
|
+
ref: `heads/${from || (await octokit.rest.repos.get({
|
|
121
|
+
owner,
|
|
122
|
+
repo
|
|
123
|
+
})).data.default_branch}`
|
|
124
|
+
});
|
|
125
|
+
sha = ref.object.sha;
|
|
126
|
+
}
|
|
127
|
+
const { data } = await octokit.rest.git.createRef({
|
|
128
|
+
owner,
|
|
129
|
+
repo,
|
|
130
|
+
ref: `refs/heads/${branch}`,
|
|
131
|
+
sha
|
|
132
|
+
});
|
|
133
|
+
return {
|
|
134
|
+
ref: data.ref,
|
|
135
|
+
sha: data.object.sha,
|
|
136
|
+
url: data.url
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
const createBranch = (token, { needsApproval = true } = {}) => tool({
|
|
140
|
+
description: "Create a new branch in a GitHub repository from an existing branch or commit SHA",
|
|
141
|
+
needsApproval,
|
|
142
|
+
inputSchema: z.object({
|
|
143
|
+
owner: z.string().describe("Repository owner"),
|
|
144
|
+
repo: z.string().describe("Repository name"),
|
|
145
|
+
branch: z.string().describe("Name for the new branch"),
|
|
146
|
+
from: z.string().optional().describe("Source branch name or commit SHA to branch from (defaults to the default branch)")
|
|
147
|
+
}),
|
|
148
|
+
execute: async (args) => createBranchStep({
|
|
149
|
+
token,
|
|
150
|
+
...args
|
|
151
|
+
})
|
|
152
|
+
});
|
|
153
|
+
async function forkRepositoryStep({ token, owner, repo, organization, name }) {
|
|
154
|
+
"use step";
|
|
155
|
+
const { data } = await createOctokit(token).rest.repos.createFork({
|
|
156
|
+
owner,
|
|
157
|
+
repo,
|
|
158
|
+
organization,
|
|
159
|
+
name
|
|
160
|
+
});
|
|
161
|
+
return {
|
|
162
|
+
name: data.name,
|
|
163
|
+
fullName: data.full_name,
|
|
164
|
+
url: data.html_url,
|
|
165
|
+
cloneUrl: data.clone_url,
|
|
166
|
+
sshUrl: data.ssh_url,
|
|
167
|
+
defaultBranch: data.default_branch,
|
|
168
|
+
private: data.private,
|
|
169
|
+
parent: data.parent ? {
|
|
170
|
+
fullName: data.parent.full_name,
|
|
171
|
+
url: data.parent.html_url
|
|
172
|
+
} : null
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
const forkRepository = (token, { needsApproval = true } = {}) => tool({
|
|
176
|
+
description: "Fork a GitHub repository to the authenticated user account or a specified organization",
|
|
177
|
+
needsApproval,
|
|
178
|
+
inputSchema: z.object({
|
|
179
|
+
owner: z.string().describe("Repository owner to fork from"),
|
|
180
|
+
repo: z.string().describe("Repository name to fork"),
|
|
181
|
+
organization: z.string().optional().describe("Organization to fork into (omit to fork to your personal account)"),
|
|
182
|
+
name: z.string().optional().describe("Name for the forked repository (defaults to the original name)")
|
|
183
|
+
}),
|
|
184
|
+
execute: async (args) => forkRepositoryStep({
|
|
185
|
+
token,
|
|
186
|
+
...args
|
|
187
|
+
})
|
|
188
|
+
});
|
|
189
|
+
async function createRepositoryStep({ token, name, description, isPrivate, autoInit, gitignoreTemplate, licenseTemplate, org }) {
|
|
190
|
+
"use step";
|
|
191
|
+
const octokit = createOctokit(token);
|
|
192
|
+
const params = {
|
|
193
|
+
name,
|
|
194
|
+
description,
|
|
195
|
+
private: isPrivate,
|
|
196
|
+
auto_init: autoInit,
|
|
197
|
+
gitignore_template: gitignoreTemplate,
|
|
198
|
+
license_template: licenseTemplate
|
|
199
|
+
};
|
|
200
|
+
const { data } = org ? await octokit.rest.repos.createInOrg({
|
|
201
|
+
org,
|
|
202
|
+
...params
|
|
203
|
+
}) : await octokit.rest.repos.createForAuthenticatedUser(params);
|
|
204
|
+
return {
|
|
205
|
+
name: data.name,
|
|
206
|
+
fullName: data.full_name,
|
|
207
|
+
description: data.description,
|
|
208
|
+
url: data.html_url,
|
|
209
|
+
cloneUrl: data.clone_url,
|
|
210
|
+
sshUrl: data.ssh_url,
|
|
211
|
+
defaultBranch: data.default_branch,
|
|
212
|
+
private: data.private,
|
|
213
|
+
createdAt: data.created_at
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
const createRepository = (token, { needsApproval = true } = {}) => tool({
|
|
217
|
+
description: "Create a new GitHub repository for the authenticated user or a specified organization",
|
|
218
|
+
needsApproval,
|
|
219
|
+
inputSchema: z.object({
|
|
220
|
+
name: z.string().describe("Repository name"),
|
|
221
|
+
description: z.string().optional().describe("A short description of the repository"),
|
|
222
|
+
isPrivate: z.boolean().optional().default(false).describe("Whether the repository is private"),
|
|
223
|
+
autoInit: z.boolean().optional().default(false).describe("Create an initial commit with a README"),
|
|
224
|
+
gitignoreTemplate: z.string().optional().describe("Gitignore template to use (e.g. \"Node\", \"Python\")"),
|
|
225
|
+
licenseTemplate: z.string().optional().describe("License keyword (e.g. \"mit\", \"apache-2.0\")"),
|
|
226
|
+
org: z.string().optional().describe("Organization to create the repository in (omit for personal repo)")
|
|
227
|
+
}),
|
|
228
|
+
execute: async (args) => createRepositoryStep({
|
|
229
|
+
token,
|
|
230
|
+
...args
|
|
231
|
+
})
|
|
232
|
+
});
|
|
233
|
+
async function createOrUpdateFileStep({ token, owner, repo, path, message, content, branch, sha }) {
|
|
234
|
+
"use step";
|
|
235
|
+
const octokit = createOctokit(token);
|
|
236
|
+
const encoded = Buffer.from(content).toString("base64");
|
|
237
|
+
const { data } = await octokit.rest.repos.createOrUpdateFileContents({
|
|
238
|
+
owner,
|
|
239
|
+
repo,
|
|
240
|
+
path,
|
|
241
|
+
message,
|
|
242
|
+
content: encoded,
|
|
243
|
+
branch,
|
|
244
|
+
sha
|
|
245
|
+
});
|
|
246
|
+
return {
|
|
247
|
+
path: data.content?.path,
|
|
248
|
+
sha: data.content?.sha,
|
|
249
|
+
commitSha: data.commit.sha,
|
|
250
|
+
commitUrl: data.commit.html_url
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
const createOrUpdateFile = (token, { needsApproval = true } = {}) => tool({
|
|
254
|
+
description: "Create or update a file in a GitHub repository. Provide the SHA when updating an existing file.",
|
|
255
|
+
needsApproval,
|
|
256
|
+
inputSchema: z.object({
|
|
257
|
+
owner: z.string().describe("Repository owner"),
|
|
258
|
+
repo: z.string().describe("Repository name"),
|
|
259
|
+
path: z.string().describe("Path to the file in the repository"),
|
|
260
|
+
message: z.string().describe("Commit message"),
|
|
261
|
+
content: z.string().describe("File content (plain text, will be base64-encoded automatically)"),
|
|
262
|
+
branch: z.string().optional().describe("Branch to commit to (defaults to the default branch)"),
|
|
263
|
+
sha: z.string().optional().describe("SHA of the file being replaced (required when updating an existing file)")
|
|
264
|
+
}),
|
|
265
|
+
execute: async (args) => createOrUpdateFileStep({
|
|
266
|
+
token,
|
|
267
|
+
...args
|
|
268
|
+
})
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
//#endregion
|
|
272
|
+
//#region src/tools/pull-requests.ts
|
|
273
|
+
async function listPullRequestsStep({ token, owner, repo, state, perPage }) {
|
|
274
|
+
"use step";
|
|
275
|
+
const { data } = await createOctokit(token).rest.pulls.list({
|
|
276
|
+
owner,
|
|
277
|
+
repo,
|
|
278
|
+
state,
|
|
279
|
+
per_page: perPage
|
|
280
|
+
});
|
|
281
|
+
return data.map((pr) => ({
|
|
282
|
+
number: pr.number,
|
|
283
|
+
title: pr.title,
|
|
284
|
+
state: pr.state,
|
|
285
|
+
url: pr.html_url,
|
|
286
|
+
author: pr.user?.login,
|
|
287
|
+
branch: pr.head.ref,
|
|
288
|
+
base: pr.base.ref,
|
|
289
|
+
draft: pr.draft,
|
|
290
|
+
createdAt: pr.created_at,
|
|
291
|
+
updatedAt: pr.updated_at
|
|
292
|
+
}));
|
|
293
|
+
}
|
|
294
|
+
const listPullRequests = (token) => tool({
|
|
295
|
+
description: "List pull requests for a GitHub repository",
|
|
296
|
+
inputSchema: z.object({
|
|
297
|
+
owner: z.string().describe("Repository owner"),
|
|
298
|
+
repo: z.string().describe("Repository name"),
|
|
299
|
+
state: z.enum([
|
|
300
|
+
"open",
|
|
301
|
+
"closed",
|
|
302
|
+
"all"
|
|
303
|
+
]).optional().default("open").describe("Filter by state"),
|
|
304
|
+
perPage: z.number().optional().default(30).describe("Number of results to return (max 100)")
|
|
305
|
+
}),
|
|
306
|
+
execute: async (args) => listPullRequestsStep({
|
|
307
|
+
token,
|
|
308
|
+
...args
|
|
309
|
+
})
|
|
310
|
+
});
|
|
311
|
+
async function getPullRequestStep({ token, owner, repo, pullNumber }) {
|
|
312
|
+
"use step";
|
|
313
|
+
const { data } = await createOctokit(token).rest.pulls.get({
|
|
314
|
+
owner,
|
|
315
|
+
repo,
|
|
316
|
+
pull_number: pullNumber
|
|
317
|
+
});
|
|
318
|
+
return {
|
|
319
|
+
number: data.number,
|
|
320
|
+
title: data.title,
|
|
321
|
+
body: data.body,
|
|
322
|
+
state: data.state,
|
|
323
|
+
url: data.html_url,
|
|
324
|
+
author: data.user?.login,
|
|
325
|
+
branch: data.head.ref,
|
|
326
|
+
base: data.base.ref,
|
|
327
|
+
draft: data.draft,
|
|
328
|
+
merged: data.merged,
|
|
329
|
+
mergeable: data.mergeable,
|
|
330
|
+
additions: data.additions,
|
|
331
|
+
deletions: data.deletions,
|
|
332
|
+
changedFiles: data.changed_files,
|
|
333
|
+
createdAt: data.created_at,
|
|
334
|
+
updatedAt: data.updated_at,
|
|
335
|
+
mergedAt: data.merged_at
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
const getPullRequest = (token) => tool({
|
|
339
|
+
description: "Get detailed information about a specific pull request",
|
|
340
|
+
inputSchema: z.object({
|
|
341
|
+
owner: z.string().describe("Repository owner"),
|
|
342
|
+
repo: z.string().describe("Repository name"),
|
|
343
|
+
pullNumber: z.number().describe("Pull request number")
|
|
344
|
+
}),
|
|
345
|
+
execute: async (args) => getPullRequestStep({
|
|
346
|
+
token,
|
|
347
|
+
...args
|
|
348
|
+
})
|
|
349
|
+
});
|
|
350
|
+
async function createPullRequestStep({ token, owner, repo, title, body, head, base, draft }) {
|
|
351
|
+
"use step";
|
|
352
|
+
const { data } = await createOctokit(token).rest.pulls.create({
|
|
353
|
+
owner,
|
|
354
|
+
repo,
|
|
355
|
+
title,
|
|
356
|
+
body,
|
|
357
|
+
head,
|
|
358
|
+
base,
|
|
359
|
+
draft
|
|
360
|
+
});
|
|
361
|
+
return {
|
|
362
|
+
number: data.number,
|
|
363
|
+
title: data.title,
|
|
364
|
+
url: data.html_url,
|
|
365
|
+
state: data.state,
|
|
366
|
+
draft: data.draft,
|
|
367
|
+
branch: data.head.ref,
|
|
368
|
+
base: data.base.ref
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
const createPullRequest = (token, { needsApproval = true } = {}) => tool({
|
|
372
|
+
description: "Create a new pull request in a GitHub repository",
|
|
373
|
+
needsApproval,
|
|
374
|
+
inputSchema: z.object({
|
|
375
|
+
owner: z.string().describe("Repository owner"),
|
|
376
|
+
repo: z.string().describe("Repository name"),
|
|
377
|
+
title: z.string().describe("Pull request title"),
|
|
378
|
+
body: z.string().optional().describe("Pull request description (supports Markdown)"),
|
|
379
|
+
head: z.string().describe("Branch containing the changes (format: branch or username:branch)"),
|
|
380
|
+
base: z.string().describe("Branch to merge into"),
|
|
381
|
+
draft: z.boolean().optional().default(false).describe("Create as draft pull request")
|
|
382
|
+
}),
|
|
383
|
+
execute: async (args) => createPullRequestStep({
|
|
384
|
+
token,
|
|
385
|
+
...args
|
|
386
|
+
})
|
|
387
|
+
});
|
|
388
|
+
async function mergePullRequestStep({ token, owner, repo, pullNumber, commitTitle, commitMessage, mergeMethod }) {
|
|
389
|
+
"use step";
|
|
390
|
+
const { data } = await createOctokit(token).rest.pulls.merge({
|
|
391
|
+
owner,
|
|
392
|
+
repo,
|
|
393
|
+
pull_number: pullNumber,
|
|
394
|
+
commit_title: commitTitle,
|
|
395
|
+
commit_message: commitMessage,
|
|
396
|
+
merge_method: mergeMethod
|
|
397
|
+
});
|
|
398
|
+
return {
|
|
399
|
+
merged: data.merged,
|
|
400
|
+
message: data.message,
|
|
401
|
+
sha: data.sha
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
const mergePullRequest = (token, { needsApproval = true } = {}) => tool({
|
|
405
|
+
description: "Merge a pull request",
|
|
406
|
+
needsApproval,
|
|
407
|
+
inputSchema: z.object({
|
|
408
|
+
owner: z.string().describe("Repository owner"),
|
|
409
|
+
repo: z.string().describe("Repository name"),
|
|
410
|
+
pullNumber: z.number().describe("Pull request number"),
|
|
411
|
+
commitTitle: z.string().optional().describe("Title for the automatic merge commit"),
|
|
412
|
+
commitMessage: z.string().optional().describe("Extra detail to append to automatic commit message"),
|
|
413
|
+
mergeMethod: z.enum([
|
|
414
|
+
"merge",
|
|
415
|
+
"squash",
|
|
416
|
+
"rebase"
|
|
417
|
+
]).optional().default("merge").describe("Merge strategy")
|
|
418
|
+
}),
|
|
419
|
+
execute: async (args) => mergePullRequestStep({
|
|
420
|
+
token,
|
|
421
|
+
...args
|
|
422
|
+
})
|
|
423
|
+
});
|
|
424
|
+
async function addPullRequestCommentStep({ token, owner, repo, pullNumber, body }) {
|
|
425
|
+
"use step";
|
|
426
|
+
const { data } = await createOctokit(token).rest.issues.createComment({
|
|
427
|
+
owner,
|
|
428
|
+
repo,
|
|
429
|
+
issue_number: pullNumber,
|
|
430
|
+
body
|
|
431
|
+
});
|
|
432
|
+
return {
|
|
433
|
+
id: data.id,
|
|
434
|
+
url: data.html_url,
|
|
435
|
+
body: data.body,
|
|
436
|
+
author: data.user?.login,
|
|
437
|
+
createdAt: data.created_at
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
const addPullRequestComment = (token, { needsApproval = true } = {}) => tool({
|
|
441
|
+
description: "Add a comment to a pull request",
|
|
442
|
+
needsApproval,
|
|
443
|
+
inputSchema: z.object({
|
|
444
|
+
owner: z.string().describe("Repository owner"),
|
|
445
|
+
repo: z.string().describe("Repository name"),
|
|
446
|
+
pullNumber: z.number().describe("Pull request number"),
|
|
447
|
+
body: z.string().describe("Comment text (supports Markdown)")
|
|
448
|
+
}),
|
|
449
|
+
execute: async (args) => addPullRequestCommentStep({
|
|
450
|
+
token,
|
|
451
|
+
...args
|
|
452
|
+
})
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
//#endregion
|
|
456
|
+
//#region src/tools/issues.ts
|
|
457
|
+
async function listIssuesStep({ token, owner, repo, state, labels, perPage }) {
|
|
458
|
+
"use step";
|
|
459
|
+
const { data } = await createOctokit(token).rest.issues.listForRepo({
|
|
460
|
+
owner,
|
|
461
|
+
repo,
|
|
462
|
+
state,
|
|
463
|
+
labels,
|
|
464
|
+
per_page: perPage
|
|
465
|
+
});
|
|
466
|
+
return data.filter((issue) => !issue.pull_request).map((issue) => ({
|
|
467
|
+
number: issue.number,
|
|
468
|
+
title: issue.title,
|
|
469
|
+
state: issue.state,
|
|
470
|
+
url: issue.html_url,
|
|
471
|
+
author: issue.user?.login,
|
|
472
|
+
labels: issue.labels.map((l) => typeof l === "string" ? l : l.name),
|
|
473
|
+
createdAt: issue.created_at,
|
|
474
|
+
updatedAt: issue.updated_at
|
|
475
|
+
}));
|
|
476
|
+
}
|
|
477
|
+
const listIssues = (token) => tool({
|
|
478
|
+
description: "List issues for a GitHub repository (excludes pull requests)",
|
|
479
|
+
inputSchema: z.object({
|
|
480
|
+
owner: z.string().describe("Repository owner"),
|
|
481
|
+
repo: z.string().describe("Repository name"),
|
|
482
|
+
state: z.enum([
|
|
483
|
+
"open",
|
|
484
|
+
"closed",
|
|
485
|
+
"all"
|
|
486
|
+
]).optional().default("open").describe("Filter by state"),
|
|
487
|
+
labels: z.string().optional().describe("Comma-separated list of label names to filter by"),
|
|
488
|
+
perPage: z.number().optional().default(30).describe("Number of results to return (max 100)")
|
|
489
|
+
}),
|
|
490
|
+
execute: async (args) => listIssuesStep({
|
|
491
|
+
token,
|
|
492
|
+
...args
|
|
493
|
+
})
|
|
494
|
+
});
|
|
495
|
+
async function getIssueStep({ token, owner, repo, issueNumber }) {
|
|
496
|
+
"use step";
|
|
497
|
+
const { data } = await createOctokit(token).rest.issues.get({
|
|
498
|
+
owner,
|
|
499
|
+
repo,
|
|
500
|
+
issue_number: issueNumber
|
|
501
|
+
});
|
|
502
|
+
return {
|
|
503
|
+
number: data.number,
|
|
504
|
+
title: data.title,
|
|
505
|
+
body: data.body,
|
|
506
|
+
state: data.state,
|
|
507
|
+
url: data.html_url,
|
|
508
|
+
author: data.user?.login,
|
|
509
|
+
assignees: data.assignees?.map((a) => a.login),
|
|
510
|
+
labels: data.labels.map((l) => typeof l === "string" ? l : l.name),
|
|
511
|
+
comments: data.comments,
|
|
512
|
+
createdAt: data.created_at,
|
|
513
|
+
updatedAt: data.updated_at,
|
|
514
|
+
closedAt: data.closed_at
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
const getIssue = (token) => tool({
|
|
518
|
+
description: "Get detailed information about a specific issue",
|
|
519
|
+
inputSchema: z.object({
|
|
520
|
+
owner: z.string().describe("Repository owner"),
|
|
521
|
+
repo: z.string().describe("Repository name"),
|
|
522
|
+
issueNumber: z.number().describe("Issue number")
|
|
523
|
+
}),
|
|
524
|
+
execute: async (args) => getIssueStep({
|
|
525
|
+
token,
|
|
526
|
+
...args
|
|
527
|
+
})
|
|
528
|
+
});
|
|
529
|
+
async function createIssueStep({ token, owner, repo, title, body, labels, assignees }) {
|
|
530
|
+
"use step";
|
|
531
|
+
const { data } = await createOctokit(token).rest.issues.create({
|
|
532
|
+
owner,
|
|
533
|
+
repo,
|
|
534
|
+
title,
|
|
535
|
+
body,
|
|
536
|
+
labels,
|
|
537
|
+
assignees
|
|
538
|
+
});
|
|
539
|
+
return {
|
|
540
|
+
number: data.number,
|
|
541
|
+
title: data.title,
|
|
542
|
+
url: data.html_url,
|
|
543
|
+
state: data.state,
|
|
544
|
+
labels: data.labels.map((l) => typeof l === "string" ? l : l.name)
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
const createIssue = (token, { needsApproval = true } = {}) => tool({
|
|
548
|
+
description: "Create a new issue in a GitHub repository",
|
|
549
|
+
needsApproval,
|
|
550
|
+
inputSchema: z.object({
|
|
551
|
+
owner: z.string().describe("Repository owner"),
|
|
552
|
+
repo: z.string().describe("Repository name"),
|
|
553
|
+
title: z.string().describe("Issue title"),
|
|
554
|
+
body: z.string().optional().describe("Issue description (supports Markdown)"),
|
|
555
|
+
labels: z.array(z.string()).optional().describe("Labels to apply to the issue"),
|
|
556
|
+
assignees: z.array(z.string()).optional().describe("GitHub usernames to assign to the issue")
|
|
557
|
+
}),
|
|
558
|
+
execute: async (args) => createIssueStep({
|
|
559
|
+
token,
|
|
560
|
+
...args
|
|
561
|
+
})
|
|
562
|
+
});
|
|
563
|
+
async function addIssueCommentStep({ token, owner, repo, issueNumber, body }) {
|
|
564
|
+
"use step";
|
|
565
|
+
const { data } = await createOctokit(token).rest.issues.createComment({
|
|
566
|
+
owner,
|
|
567
|
+
repo,
|
|
568
|
+
issue_number: issueNumber,
|
|
569
|
+
body
|
|
570
|
+
});
|
|
571
|
+
return {
|
|
572
|
+
id: data.id,
|
|
573
|
+
url: data.html_url,
|
|
574
|
+
body: data.body,
|
|
575
|
+
author: data.user?.login,
|
|
576
|
+
createdAt: data.created_at
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
const addIssueComment = (token, { needsApproval = true } = {}) => tool({
|
|
580
|
+
description: "Add a comment to a GitHub issue",
|
|
581
|
+
needsApproval,
|
|
582
|
+
inputSchema: z.object({
|
|
583
|
+
owner: z.string().describe("Repository owner"),
|
|
584
|
+
repo: z.string().describe("Repository name"),
|
|
585
|
+
issueNumber: z.number().describe("Issue number"),
|
|
586
|
+
body: z.string().describe("Comment text (supports Markdown)")
|
|
587
|
+
}),
|
|
588
|
+
execute: async (args) => addIssueCommentStep({
|
|
589
|
+
token,
|
|
590
|
+
...args
|
|
591
|
+
})
|
|
592
|
+
});
|
|
593
|
+
async function closeIssueStep({ token, owner, repo, issueNumber, stateReason }) {
|
|
594
|
+
"use step";
|
|
595
|
+
const { data } = await createOctokit(token).rest.issues.update({
|
|
596
|
+
owner,
|
|
597
|
+
repo,
|
|
598
|
+
issue_number: issueNumber,
|
|
599
|
+
state: "closed",
|
|
600
|
+
state_reason: stateReason
|
|
601
|
+
});
|
|
602
|
+
return {
|
|
603
|
+
number: data.number,
|
|
604
|
+
title: data.title,
|
|
605
|
+
state: data.state,
|
|
606
|
+
url: data.html_url,
|
|
607
|
+
closedAt: data.closed_at
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
const closeIssue = (token, { needsApproval = true } = {}) => tool({
|
|
611
|
+
description: "Close an open GitHub issue",
|
|
612
|
+
needsApproval,
|
|
613
|
+
inputSchema: z.object({
|
|
614
|
+
owner: z.string().describe("Repository owner"),
|
|
615
|
+
repo: z.string().describe("Repository name"),
|
|
616
|
+
issueNumber: z.number().describe("Issue number to close"),
|
|
617
|
+
stateReason: z.enum(["completed", "not_planned"]).optional().default("completed").describe("Reason for closing")
|
|
618
|
+
}),
|
|
619
|
+
execute: async (args) => closeIssueStep({
|
|
620
|
+
token,
|
|
621
|
+
...args
|
|
622
|
+
})
|
|
623
|
+
});
|
|
624
|
+
|
|
625
|
+
//#endregion
|
|
626
|
+
//#region src/tools/search.ts
|
|
627
|
+
async function searchCodeStep({ token, query, perPage }) {
|
|
628
|
+
"use step";
|
|
629
|
+
const { data } = await createOctokit(token).rest.search.code({
|
|
630
|
+
q: query,
|
|
631
|
+
per_page: perPage
|
|
632
|
+
});
|
|
633
|
+
return {
|
|
634
|
+
totalCount: data.total_count,
|
|
635
|
+
items: data.items.map((item) => ({
|
|
636
|
+
name: item.name,
|
|
637
|
+
path: item.path,
|
|
638
|
+
url: item.html_url,
|
|
639
|
+
repository: item.repository.full_name,
|
|
640
|
+
sha: item.sha
|
|
641
|
+
}))
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
const searchCode = (token) => tool({
|
|
645
|
+
description: "Search for code in GitHub repositories. Use qualifiers like \"repo:owner/name\" to scope the search.",
|
|
646
|
+
inputSchema: z.object({
|
|
647
|
+
query: z.string().describe("Search query. Supports GitHub search qualifiers, e.g. \"useState repo:facebook/react\""),
|
|
648
|
+
perPage: z.number().optional().default(10).describe("Number of results to return (max 30)")
|
|
649
|
+
}),
|
|
650
|
+
execute: async (args) => searchCodeStep({
|
|
651
|
+
token,
|
|
652
|
+
...args
|
|
653
|
+
})
|
|
654
|
+
});
|
|
655
|
+
async function searchRepositoriesStep({ token, query, perPage, sort, order }) {
|
|
656
|
+
"use step";
|
|
657
|
+
const { data } = await createOctokit(token).rest.search.repos({
|
|
658
|
+
q: query,
|
|
659
|
+
per_page: perPage,
|
|
660
|
+
sort,
|
|
661
|
+
order
|
|
662
|
+
});
|
|
663
|
+
return {
|
|
664
|
+
totalCount: data.total_count,
|
|
665
|
+
items: data.items.map((repo) => ({
|
|
666
|
+
name: repo.name,
|
|
667
|
+
fullName: repo.full_name,
|
|
668
|
+
description: repo.description,
|
|
669
|
+
url: repo.html_url,
|
|
670
|
+
stars: repo.stargazers_count,
|
|
671
|
+
forks: repo.forks_count,
|
|
672
|
+
language: repo.language,
|
|
673
|
+
topics: repo.topics
|
|
674
|
+
}))
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
const searchRepositories = (token) => tool({
|
|
678
|
+
description: "Search for GitHub repositories by keyword, topic, language, or other qualifiers",
|
|
679
|
+
inputSchema: z.object({
|
|
680
|
+
query: z.string().describe("Search query. Supports GitHub search qualifiers, e.g. \"nuxt language:typescript stars:>1000\""),
|
|
681
|
+
perPage: z.number().optional().default(10).describe("Number of results to return (max 30)"),
|
|
682
|
+
sort: z.enum([
|
|
683
|
+
"stars",
|
|
684
|
+
"forks",
|
|
685
|
+
"help-wanted-issues",
|
|
686
|
+
"updated"
|
|
687
|
+
]).optional().describe("Sort field"),
|
|
688
|
+
order: z.enum(["asc", "desc"]).optional().default("desc").describe("Sort order")
|
|
689
|
+
}),
|
|
690
|
+
execute: async (args) => searchRepositoriesStep({
|
|
691
|
+
token,
|
|
692
|
+
...args
|
|
693
|
+
})
|
|
694
|
+
});
|
|
695
|
+
|
|
696
|
+
//#endregion
|
|
697
|
+
//#region src/tools/commits.ts
|
|
698
|
+
const BLAME_QUERY = `
|
|
699
|
+
query ($owner: String!, $name: String!, $expression: String!, $path: String!) {
|
|
700
|
+
repository(owner: $owner, name: $name) {
|
|
701
|
+
object(expression: $expression) {
|
|
702
|
+
... on Commit {
|
|
703
|
+
oid
|
|
704
|
+
blame(path: $path) {
|
|
705
|
+
ranges {
|
|
706
|
+
startingLine
|
|
707
|
+
endingLine
|
|
708
|
+
age
|
|
709
|
+
commit {
|
|
710
|
+
oid
|
|
711
|
+
abbreviatedOid
|
|
712
|
+
messageHeadline
|
|
713
|
+
authoredDate
|
|
714
|
+
url
|
|
715
|
+
author {
|
|
716
|
+
name
|
|
717
|
+
email
|
|
718
|
+
user {
|
|
719
|
+
login
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
`;
|
|
730
|
+
async function listCommitsStep({ token, owner, repo, path, sha, author, since, until, perPage }) {
|
|
731
|
+
"use step";
|
|
732
|
+
const { data } = await createOctokit(token).rest.repos.listCommits({
|
|
733
|
+
owner,
|
|
734
|
+
repo,
|
|
735
|
+
path,
|
|
736
|
+
sha,
|
|
737
|
+
author,
|
|
738
|
+
since,
|
|
739
|
+
until,
|
|
740
|
+
per_page: perPage
|
|
741
|
+
});
|
|
742
|
+
return data.map((commit) => ({
|
|
743
|
+
sha: commit.sha,
|
|
744
|
+
message: commit.commit.message,
|
|
745
|
+
author: commit.commit.author?.name,
|
|
746
|
+
authorLogin: commit.author?.login,
|
|
747
|
+
date: commit.commit.author?.date,
|
|
748
|
+
url: commit.html_url
|
|
749
|
+
}));
|
|
750
|
+
}
|
|
751
|
+
const listCommits = (token) => tool({
|
|
752
|
+
description: "List commits for a GitHub repository. Filter by file path to see commits that touched a file. For line-by-line attribution at a given ref, use getBlame instead.",
|
|
753
|
+
inputSchema: z.object({
|
|
754
|
+
owner: z.string().describe("Repository owner"),
|
|
755
|
+
repo: z.string().describe("Repository name"),
|
|
756
|
+
path: z.string().optional().describe("Only commits containing this file path"),
|
|
757
|
+
sha: z.string().optional().describe("Branch name or commit SHA to start listing from"),
|
|
758
|
+
author: z.string().optional().describe("GitHub username or email to filter commits by"),
|
|
759
|
+
since: z.string().optional().describe("Only commits after this date (ISO 8601 format)"),
|
|
760
|
+
until: z.string().optional().describe("Only commits before this date (ISO 8601 format)"),
|
|
761
|
+
perPage: z.number().optional().default(30).describe("Number of results to return (max 100)")
|
|
762
|
+
}),
|
|
763
|
+
execute: async (args) => listCommitsStep({
|
|
764
|
+
token,
|
|
765
|
+
...args
|
|
766
|
+
})
|
|
767
|
+
});
|
|
768
|
+
async function getCommitStep({ token, owner, repo, ref }) {
|
|
769
|
+
"use step";
|
|
770
|
+
const { data } = await createOctokit(token).rest.repos.getCommit({
|
|
771
|
+
owner,
|
|
772
|
+
repo,
|
|
773
|
+
ref
|
|
774
|
+
});
|
|
775
|
+
return {
|
|
776
|
+
sha: data.sha,
|
|
777
|
+
message: data.commit.message,
|
|
778
|
+
author: data.commit.author?.name,
|
|
779
|
+
authorLogin: data.author?.login,
|
|
780
|
+
date: data.commit.author?.date,
|
|
781
|
+
url: data.html_url,
|
|
782
|
+
stats: data.stats ? {
|
|
783
|
+
additions: data.stats.additions,
|
|
784
|
+
deletions: data.stats.deletions,
|
|
785
|
+
total: data.stats.total
|
|
786
|
+
} : null,
|
|
787
|
+
files: data.files?.map((file) => ({
|
|
788
|
+
filename: file.filename,
|
|
789
|
+
status: file.status,
|
|
790
|
+
additions: file.additions,
|
|
791
|
+
deletions: file.deletions,
|
|
792
|
+
patch: file.patch
|
|
793
|
+
}))
|
|
794
|
+
};
|
|
795
|
+
}
|
|
796
|
+
const getCommit = (token) => tool({
|
|
797
|
+
description: "Get detailed information about a specific commit, including the list of files changed with additions and deletions",
|
|
798
|
+
inputSchema: z.object({
|
|
799
|
+
owner: z.string().describe("Repository owner"),
|
|
800
|
+
repo: z.string().describe("Repository name"),
|
|
801
|
+
ref: z.string().describe("Commit SHA, branch name, or tag")
|
|
802
|
+
}),
|
|
803
|
+
execute: async (args) => getCommitStep({
|
|
804
|
+
token,
|
|
805
|
+
...args
|
|
806
|
+
})
|
|
807
|
+
});
|
|
808
|
+
async function getBlameStep({ token, owner, repo, path, ref, line, lineStart, lineEnd }) {
|
|
809
|
+
"use step";
|
|
810
|
+
const octokit = createOctokit(token);
|
|
811
|
+
let expression = ref;
|
|
812
|
+
if (!expression) {
|
|
813
|
+
const { data } = await octokit.rest.repos.get({
|
|
814
|
+
owner,
|
|
815
|
+
repo
|
|
816
|
+
});
|
|
817
|
+
expression = data.default_branch;
|
|
818
|
+
}
|
|
819
|
+
const data = await octokit.graphql(BLAME_QUERY, {
|
|
820
|
+
owner,
|
|
821
|
+
name: repo,
|
|
822
|
+
expression,
|
|
823
|
+
path
|
|
824
|
+
});
|
|
825
|
+
if (!data.repository) return { error: `Repository not found: ${owner}/${repo}` };
|
|
826
|
+
const obj = data.repository.object;
|
|
827
|
+
if (!obj?.oid || !obj?.blame) return { error: `Ref "${expression}" did not resolve to a commit for this repository (or the path is invalid). Pass a branch name, tag, or full commit SHA.` };
|
|
828
|
+
let ranges = obj.blame.ranges.map((r) => ({
|
|
829
|
+
startingLine: r.startingLine,
|
|
830
|
+
endingLine: r.endingLine,
|
|
831
|
+
age: r.age,
|
|
832
|
+
commit: {
|
|
833
|
+
sha: r.commit.oid,
|
|
834
|
+
abbreviatedSha: r.commit.abbreviatedOid,
|
|
835
|
+
messageHeadline: r.commit.messageHeadline,
|
|
836
|
+
authoredDate: r.commit.authoredDate,
|
|
837
|
+
url: r.commit.url,
|
|
838
|
+
authorName: r.commit.author?.name ?? null,
|
|
839
|
+
authorEmail: r.commit.author?.email ?? null,
|
|
840
|
+
authorLogin: r.commit.author?.user?.login ?? null
|
|
841
|
+
}
|
|
842
|
+
}));
|
|
843
|
+
if (line != null) ranges = ranges.filter((r) => line >= r.startingLine && line <= r.endingLine);
|
|
844
|
+
else if (lineStart != null || lineEnd != null) {
|
|
845
|
+
const start = lineStart ?? 1;
|
|
846
|
+
const end = lineEnd ?? Number.MAX_SAFE_INTEGER;
|
|
847
|
+
ranges = ranges.filter((r) => r.endingLine >= start && r.startingLine <= end);
|
|
848
|
+
}
|
|
849
|
+
return {
|
|
850
|
+
ref: expression,
|
|
851
|
+
tipSha: obj.oid,
|
|
852
|
+
path,
|
|
853
|
+
rangeCount: ranges.length,
|
|
854
|
+
ranges
|
|
855
|
+
};
|
|
856
|
+
}
|
|
857
|
+
const getBlame = (token) => tool({
|
|
858
|
+
description: "Line-level git blame for a file at a commit-like ref (branch, tag, or SHA). Returns contiguous ranges mapping lines to the commits that last modified them — use this to see who introduced a line and when (GitHub GraphQL API).",
|
|
859
|
+
inputSchema: z.object({
|
|
860
|
+
owner: z.string().describe("Repository owner"),
|
|
861
|
+
repo: z.string().describe("Repository name"),
|
|
862
|
+
path: z.string().describe("Path to the file in the repository"),
|
|
863
|
+
ref: z.string().optional().describe("Branch name, tag, or commit SHA (defaults to the repository default branch)"),
|
|
864
|
+
line: z.number().int().positive().optional().describe("If set, only return blame ranges that include this line number"),
|
|
865
|
+
lineStart: z.number().int().positive().optional().describe("When used with lineEnd, only return ranges overlapping this window"),
|
|
866
|
+
lineEnd: z.number().int().positive().optional().describe("When used with lineStart, only return ranges overlapping this window")
|
|
867
|
+
}),
|
|
868
|
+
execute: async (args) => getBlameStep({
|
|
869
|
+
token,
|
|
870
|
+
...args
|
|
871
|
+
})
|
|
872
|
+
});
|
|
873
|
+
|
|
874
|
+
//#endregion
|
|
875
|
+
//#region src/tools/gists.ts
|
|
876
|
+
async function listGistsStep({ token, username, perPage, page }) {
|
|
877
|
+
"use step";
|
|
878
|
+
const octokit = createOctokit(token);
|
|
879
|
+
const { data } = username ? await octokit.rest.gists.listForUser({
|
|
880
|
+
username,
|
|
881
|
+
per_page: perPage,
|
|
882
|
+
page
|
|
883
|
+
}) : await octokit.rest.gists.list({
|
|
884
|
+
per_page: perPage,
|
|
885
|
+
page
|
|
886
|
+
});
|
|
887
|
+
return data.map((gist) => ({
|
|
888
|
+
id: gist.id,
|
|
889
|
+
description: gist.description,
|
|
890
|
+
public: gist.public,
|
|
891
|
+
url: gist.html_url,
|
|
892
|
+
files: Object.keys(gist.files ?? {}),
|
|
893
|
+
owner: gist.owner?.login,
|
|
894
|
+
comments: gist.comments,
|
|
895
|
+
createdAt: gist.created_at,
|
|
896
|
+
updatedAt: gist.updated_at
|
|
897
|
+
}));
|
|
898
|
+
}
|
|
899
|
+
const listGists = (token) => tool({
|
|
900
|
+
description: "List gists for the authenticated user or a specific user",
|
|
901
|
+
inputSchema: z.object({
|
|
902
|
+
username: z.string().optional().describe("GitHub username — omit to list your own gists"),
|
|
903
|
+
perPage: z.number().optional().default(30).describe("Number of results to return (max 100)"),
|
|
904
|
+
page: z.number().optional().default(1).describe("Page number for pagination")
|
|
905
|
+
}),
|
|
906
|
+
execute: async (args) => listGistsStep({
|
|
907
|
+
token,
|
|
908
|
+
...args
|
|
909
|
+
})
|
|
910
|
+
});
|
|
911
|
+
async function getGistStep({ token, gistId }) {
|
|
912
|
+
"use step";
|
|
913
|
+
const { data } = await createOctokit(token).rest.gists.get({ gist_id: gistId });
|
|
914
|
+
return {
|
|
915
|
+
id: data.id,
|
|
916
|
+
description: data.description,
|
|
917
|
+
public: data.public,
|
|
918
|
+
url: data.html_url,
|
|
919
|
+
owner: data.owner?.login,
|
|
920
|
+
files: Object.values(data.files ?? {}).map((file) => ({
|
|
921
|
+
filename: file?.filename,
|
|
922
|
+
language: file?.language,
|
|
923
|
+
size: file?.size,
|
|
924
|
+
content: file?.content
|
|
925
|
+
})),
|
|
926
|
+
comments: data.comments,
|
|
927
|
+
createdAt: data.created_at,
|
|
928
|
+
updatedAt: data.updated_at
|
|
929
|
+
};
|
|
930
|
+
}
|
|
931
|
+
const getGist = (token) => tool({
|
|
932
|
+
description: "Get a gist by ID, including file contents",
|
|
933
|
+
inputSchema: z.object({ gistId: z.string().describe("Gist ID") }),
|
|
934
|
+
execute: async (args) => getGistStep({
|
|
935
|
+
token,
|
|
936
|
+
...args
|
|
937
|
+
})
|
|
938
|
+
});
|
|
939
|
+
async function listGistCommentsStep({ token, gistId, perPage, page }) {
|
|
940
|
+
"use step";
|
|
941
|
+
const { data } = await createOctokit(token).rest.gists.listComments({
|
|
942
|
+
gist_id: gistId,
|
|
943
|
+
per_page: perPage,
|
|
944
|
+
page
|
|
945
|
+
});
|
|
946
|
+
return data.map((comment) => ({
|
|
947
|
+
id: comment.id,
|
|
948
|
+
body: comment.body,
|
|
949
|
+
author: comment.user?.login,
|
|
950
|
+
url: comment.url,
|
|
951
|
+
createdAt: comment.created_at,
|
|
952
|
+
updatedAt: comment.updated_at
|
|
953
|
+
}));
|
|
954
|
+
}
|
|
955
|
+
const listGistComments = (token) => tool({
|
|
956
|
+
description: "List comments on a gist",
|
|
957
|
+
inputSchema: z.object({
|
|
958
|
+
gistId: z.string().describe("Gist ID"),
|
|
959
|
+
perPage: z.number().optional().default(30).describe("Number of results to return (max 100)"),
|
|
960
|
+
page: z.number().optional().default(1).describe("Page number for pagination")
|
|
961
|
+
}),
|
|
962
|
+
execute: async (args) => listGistCommentsStep({
|
|
963
|
+
token,
|
|
964
|
+
...args
|
|
965
|
+
})
|
|
966
|
+
});
|
|
967
|
+
async function createGistStep({ token, description, files, isPublic }) {
|
|
968
|
+
"use step";
|
|
969
|
+
const { data } = await createOctokit(token).rest.gists.create({
|
|
970
|
+
description,
|
|
971
|
+
files,
|
|
972
|
+
public: isPublic
|
|
973
|
+
});
|
|
974
|
+
return {
|
|
975
|
+
id: data.id,
|
|
976
|
+
description: data.description,
|
|
977
|
+
public: data.public,
|
|
978
|
+
url: data.html_url,
|
|
979
|
+
files: Object.keys(data.files ?? {}),
|
|
980
|
+
owner: data.owner?.login
|
|
981
|
+
};
|
|
982
|
+
}
|
|
983
|
+
const createGist = (token, { needsApproval = true } = {}) => tool({
|
|
984
|
+
description: "Create a new gist with one or more files",
|
|
985
|
+
needsApproval,
|
|
986
|
+
inputSchema: z.object({
|
|
987
|
+
description: z.string().optional().describe("Gist description"),
|
|
988
|
+
files: z.record(z.string(), z.object({ content: z.string().describe("File content") })).describe("Files to include, keyed by filename"),
|
|
989
|
+
isPublic: z.boolean().optional().default(false).describe("Whether the gist is public")
|
|
990
|
+
}),
|
|
991
|
+
execute: async (args) => createGistStep({
|
|
992
|
+
token,
|
|
993
|
+
...args
|
|
994
|
+
})
|
|
995
|
+
});
|
|
996
|
+
async function updateGistStep({ token, gistId, description, files, filesToDelete }) {
|
|
997
|
+
"use step";
|
|
998
|
+
const octokit = createOctokit(token);
|
|
999
|
+
const fileUpdates = {};
|
|
1000
|
+
if (files) Object.assign(fileUpdates, files);
|
|
1001
|
+
if (filesToDelete) for (const name of filesToDelete) fileUpdates[name] = null;
|
|
1002
|
+
const { data } = await octokit.rest.gists.update({
|
|
1003
|
+
gist_id: gistId,
|
|
1004
|
+
description,
|
|
1005
|
+
files: fileUpdates
|
|
1006
|
+
});
|
|
1007
|
+
return {
|
|
1008
|
+
id: data.id,
|
|
1009
|
+
description: data.description,
|
|
1010
|
+
url: data.html_url,
|
|
1011
|
+
files: Object.keys(data.files ?? {})
|
|
1012
|
+
};
|
|
1013
|
+
}
|
|
1014
|
+
const updateGist = (token, { needsApproval = true } = {}) => tool({
|
|
1015
|
+
description: "Update an existing gist — edit description, update files, or remove files",
|
|
1016
|
+
needsApproval,
|
|
1017
|
+
inputSchema: z.object({
|
|
1018
|
+
gistId: z.string().describe("Gist ID"),
|
|
1019
|
+
description: z.string().optional().describe("New gist description"),
|
|
1020
|
+
files: z.record(z.string(), z.object({ content: z.string().describe("New file content") })).optional().describe("Files to add or update, keyed by filename"),
|
|
1021
|
+
filesToDelete: z.array(z.string()).optional().describe("Filenames to remove from the gist")
|
|
1022
|
+
}),
|
|
1023
|
+
execute: async (args) => updateGistStep({
|
|
1024
|
+
token,
|
|
1025
|
+
...args
|
|
1026
|
+
})
|
|
1027
|
+
});
|
|
1028
|
+
async function deleteGistStep({ token, gistId }) {
|
|
1029
|
+
"use step";
|
|
1030
|
+
await createOctokit(token).rest.gists.delete({ gist_id: gistId });
|
|
1031
|
+
return {
|
|
1032
|
+
deleted: true,
|
|
1033
|
+
gistId
|
|
1034
|
+
};
|
|
1035
|
+
}
|
|
1036
|
+
const deleteGist = (token, { needsApproval = true } = {}) => tool({
|
|
1037
|
+
description: "Delete a gist permanently",
|
|
1038
|
+
needsApproval,
|
|
1039
|
+
inputSchema: z.object({ gistId: z.string().describe("Gist ID to delete") }),
|
|
1040
|
+
execute: async (args) => deleteGistStep({
|
|
1041
|
+
token,
|
|
1042
|
+
...args
|
|
1043
|
+
})
|
|
1044
|
+
});
|
|
1045
|
+
async function createGistCommentStep({ token, gistId, body }) {
|
|
1046
|
+
"use step";
|
|
1047
|
+
const { data } = await createOctokit(token).rest.gists.createComment({
|
|
1048
|
+
gist_id: gistId,
|
|
1049
|
+
body
|
|
1050
|
+
});
|
|
1051
|
+
return {
|
|
1052
|
+
id: data.id,
|
|
1053
|
+
url: data.url,
|
|
1054
|
+
body: data.body,
|
|
1055
|
+
author: data.user?.login,
|
|
1056
|
+
createdAt: data.created_at
|
|
1057
|
+
};
|
|
1058
|
+
}
|
|
1059
|
+
const createGistComment = (token, { needsApproval = true } = {}) => tool({
|
|
1060
|
+
description: "Add a comment to a gist",
|
|
1061
|
+
needsApproval,
|
|
1062
|
+
inputSchema: z.object({
|
|
1063
|
+
gistId: z.string().describe("Gist ID"),
|
|
1064
|
+
body: z.string().describe("Comment text (supports Markdown)")
|
|
1065
|
+
}),
|
|
1066
|
+
execute: async (args) => createGistCommentStep({
|
|
1067
|
+
token,
|
|
1068
|
+
...args
|
|
1069
|
+
})
|
|
1070
|
+
});
|
|
1071
|
+
|
|
1072
|
+
//#endregion
|
|
1073
|
+
//#region src/tools/workflows.ts
|
|
1074
|
+
async function listWorkflowsStep({ token, owner, repo, perPage, page }) {
|
|
1075
|
+
"use step";
|
|
1076
|
+
const { data } = await createOctokit(token).rest.actions.listRepoWorkflows({
|
|
1077
|
+
owner,
|
|
1078
|
+
repo,
|
|
1079
|
+
per_page: perPage,
|
|
1080
|
+
page
|
|
1081
|
+
});
|
|
1082
|
+
return {
|
|
1083
|
+
totalCount: data.total_count,
|
|
1084
|
+
workflows: data.workflows.map((wf) => ({
|
|
1085
|
+
id: wf.id,
|
|
1086
|
+
name: wf.name,
|
|
1087
|
+
path: wf.path,
|
|
1088
|
+
state: wf.state,
|
|
1089
|
+
url: wf.html_url,
|
|
1090
|
+
createdAt: wf.created_at,
|
|
1091
|
+
updatedAt: wf.updated_at
|
|
1092
|
+
}))
|
|
1093
|
+
};
|
|
1094
|
+
}
|
|
1095
|
+
const listWorkflows = (token) => tool({
|
|
1096
|
+
description: "List GitHub Actions workflows in a repository",
|
|
1097
|
+
inputSchema: z.object({
|
|
1098
|
+
owner: z.string().describe("Repository owner"),
|
|
1099
|
+
repo: z.string().describe("Repository name"),
|
|
1100
|
+
perPage: z.number().optional().default(30).describe("Number of results to return (max 100)"),
|
|
1101
|
+
page: z.number().optional().default(1).describe("Page number for pagination")
|
|
1102
|
+
}),
|
|
1103
|
+
execute: async (args) => listWorkflowsStep({
|
|
1104
|
+
token,
|
|
1105
|
+
...args
|
|
1106
|
+
})
|
|
1107
|
+
});
|
|
1108
|
+
async function listWorkflowRunsStep({ token, owner, repo, workflowId, branch, event, status, perPage, page }) {
|
|
1109
|
+
"use step";
|
|
1110
|
+
const octokit = createOctokit(token);
|
|
1111
|
+
const { data } = workflowId ? await octokit.rest.actions.listWorkflowRuns({
|
|
1112
|
+
owner,
|
|
1113
|
+
repo,
|
|
1114
|
+
workflow_id: workflowId,
|
|
1115
|
+
per_page: perPage,
|
|
1116
|
+
page,
|
|
1117
|
+
...branch && { branch },
|
|
1118
|
+
...event && { event },
|
|
1119
|
+
...status && { status }
|
|
1120
|
+
}) : await octokit.rest.actions.listWorkflowRunsForRepo({
|
|
1121
|
+
owner,
|
|
1122
|
+
repo,
|
|
1123
|
+
per_page: perPage,
|
|
1124
|
+
page,
|
|
1125
|
+
...branch && { branch },
|
|
1126
|
+
...event && { event },
|
|
1127
|
+
...status && { status }
|
|
1128
|
+
});
|
|
1129
|
+
return {
|
|
1130
|
+
totalCount: data.total_count,
|
|
1131
|
+
runs: data.workflow_runs.map((run) => ({
|
|
1132
|
+
id: run.id,
|
|
1133
|
+
name: run.name,
|
|
1134
|
+
status: run.status,
|
|
1135
|
+
conclusion: run.conclusion,
|
|
1136
|
+
branch: run.head_branch,
|
|
1137
|
+
event: run.event,
|
|
1138
|
+
url: run.html_url,
|
|
1139
|
+
actor: run.actor?.login,
|
|
1140
|
+
createdAt: run.created_at,
|
|
1141
|
+
updatedAt: run.updated_at,
|
|
1142
|
+
runNumber: run.run_number,
|
|
1143
|
+
runAttempt: run.run_attempt
|
|
1144
|
+
}))
|
|
1145
|
+
};
|
|
1146
|
+
}
|
|
1147
|
+
const listWorkflowRuns = (token) => tool({
|
|
1148
|
+
description: "List workflow runs for a repository, optionally filtered by workflow, branch, status, or event",
|
|
1149
|
+
inputSchema: z.object({
|
|
1150
|
+
owner: z.string().describe("Repository owner"),
|
|
1151
|
+
repo: z.string().describe("Repository name"),
|
|
1152
|
+
workflowId: z.union([z.string(), z.number()]).optional().describe("Workflow ID or filename (e.g. \"ci.yml\") to filter by"),
|
|
1153
|
+
branch: z.string().optional().describe("Branch name to filter by"),
|
|
1154
|
+
event: z.string().optional().describe("Event type to filter by (e.g. \"push\", \"pull_request\")"),
|
|
1155
|
+
status: z.enum([
|
|
1156
|
+
"completed",
|
|
1157
|
+
"action_required",
|
|
1158
|
+
"cancelled",
|
|
1159
|
+
"failure",
|
|
1160
|
+
"neutral",
|
|
1161
|
+
"skipped",
|
|
1162
|
+
"stale",
|
|
1163
|
+
"success",
|
|
1164
|
+
"timed_out",
|
|
1165
|
+
"in_progress",
|
|
1166
|
+
"queued",
|
|
1167
|
+
"requested",
|
|
1168
|
+
"waiting",
|
|
1169
|
+
"pending"
|
|
1170
|
+
]).optional().describe("Status to filter by"),
|
|
1171
|
+
perPage: z.number().optional().default(30).describe("Number of results to return (max 100)"),
|
|
1172
|
+
page: z.number().optional().default(1).describe("Page number for pagination")
|
|
1173
|
+
}),
|
|
1174
|
+
execute: async (args) => listWorkflowRunsStep({
|
|
1175
|
+
token,
|
|
1176
|
+
...args
|
|
1177
|
+
})
|
|
1178
|
+
});
|
|
1179
|
+
async function getWorkflowRunStep({ token, owner, repo, runId }) {
|
|
1180
|
+
"use step";
|
|
1181
|
+
const { data } = await createOctokit(token).rest.actions.getWorkflowRun({
|
|
1182
|
+
owner,
|
|
1183
|
+
repo,
|
|
1184
|
+
run_id: runId
|
|
1185
|
+
});
|
|
1186
|
+
return {
|
|
1187
|
+
id: data.id,
|
|
1188
|
+
name: data.name,
|
|
1189
|
+
status: data.status,
|
|
1190
|
+
conclusion: data.conclusion,
|
|
1191
|
+
branch: data.head_branch,
|
|
1192
|
+
sha: data.head_sha,
|
|
1193
|
+
event: data.event,
|
|
1194
|
+
url: data.html_url,
|
|
1195
|
+
actor: data.actor?.login,
|
|
1196
|
+
runNumber: data.run_number,
|
|
1197
|
+
runAttempt: data.run_attempt,
|
|
1198
|
+
createdAt: data.created_at,
|
|
1199
|
+
updatedAt: data.updated_at,
|
|
1200
|
+
runStartedAt: data.run_started_at
|
|
1201
|
+
};
|
|
1202
|
+
}
|
|
1203
|
+
const getWorkflowRun = (token) => tool({
|
|
1204
|
+
description: "Get details of a specific workflow run including status, timing, and trigger info",
|
|
1205
|
+
inputSchema: z.object({
|
|
1206
|
+
owner: z.string().describe("Repository owner"),
|
|
1207
|
+
repo: z.string().describe("Repository name"),
|
|
1208
|
+
runId: z.number().describe("Workflow run ID")
|
|
1209
|
+
}),
|
|
1210
|
+
execute: async (args) => getWorkflowRunStep({
|
|
1211
|
+
token,
|
|
1212
|
+
...args
|
|
1213
|
+
})
|
|
1214
|
+
});
|
|
1215
|
+
async function listWorkflowJobsStep({ token, owner, repo, runId, filter, perPage, page }) {
|
|
1216
|
+
"use step";
|
|
1217
|
+
const { data } = await createOctokit(token).rest.actions.listJobsForWorkflowRun({
|
|
1218
|
+
owner,
|
|
1219
|
+
repo,
|
|
1220
|
+
run_id: runId,
|
|
1221
|
+
filter,
|
|
1222
|
+
per_page: perPage,
|
|
1223
|
+
page
|
|
1224
|
+
});
|
|
1225
|
+
return {
|
|
1226
|
+
totalCount: data.total_count,
|
|
1227
|
+
jobs: data.jobs.map((job) => ({
|
|
1228
|
+
id: job.id,
|
|
1229
|
+
name: job.name,
|
|
1230
|
+
status: job.status,
|
|
1231
|
+
conclusion: job.conclusion,
|
|
1232
|
+
url: job.html_url,
|
|
1233
|
+
startedAt: job.started_at,
|
|
1234
|
+
completedAt: job.completed_at,
|
|
1235
|
+
runnerName: job.runner_name,
|
|
1236
|
+
steps: job.steps?.map((step) => ({
|
|
1237
|
+
name: step.name,
|
|
1238
|
+
status: step.status,
|
|
1239
|
+
conclusion: step.conclusion,
|
|
1240
|
+
number: step.number,
|
|
1241
|
+
startedAt: step.started_at,
|
|
1242
|
+
completedAt: step.completed_at
|
|
1243
|
+
}))
|
|
1244
|
+
}))
|
|
1245
|
+
};
|
|
1246
|
+
}
|
|
1247
|
+
const listWorkflowJobs = (token) => tool({
|
|
1248
|
+
description: "List jobs for a workflow run, including step-level status and timing",
|
|
1249
|
+
inputSchema: z.object({
|
|
1250
|
+
owner: z.string().describe("Repository owner"),
|
|
1251
|
+
repo: z.string().describe("Repository name"),
|
|
1252
|
+
runId: z.number().describe("Workflow run ID"),
|
|
1253
|
+
filter: z.enum(["latest", "all"]).optional().default("latest").describe("Filter by the latest attempt or all attempts"),
|
|
1254
|
+
perPage: z.number().optional().default(30).describe("Number of results to return (max 100)"),
|
|
1255
|
+
page: z.number().optional().default(1).describe("Page number for pagination")
|
|
1256
|
+
}),
|
|
1257
|
+
execute: async (args) => listWorkflowJobsStep({
|
|
1258
|
+
token,
|
|
1259
|
+
...args
|
|
1260
|
+
})
|
|
1261
|
+
});
|
|
1262
|
+
async function triggerWorkflowStep({ token, owner, repo, workflowId, ref, inputs }) {
|
|
1263
|
+
"use step";
|
|
1264
|
+
await createOctokit(token).rest.actions.createWorkflowDispatch({
|
|
1265
|
+
owner,
|
|
1266
|
+
repo,
|
|
1267
|
+
workflow_id: workflowId,
|
|
1268
|
+
ref,
|
|
1269
|
+
inputs
|
|
1270
|
+
});
|
|
1271
|
+
return {
|
|
1272
|
+
triggered: true,
|
|
1273
|
+
workflowId,
|
|
1274
|
+
ref
|
|
1275
|
+
};
|
|
1276
|
+
}
|
|
1277
|
+
const triggerWorkflow = (token, { needsApproval = true } = {}) => tool({
|
|
1278
|
+
description: "Trigger a workflow via workflow_dispatch event",
|
|
1279
|
+
needsApproval,
|
|
1280
|
+
inputSchema: z.object({
|
|
1281
|
+
owner: z.string().describe("Repository owner"),
|
|
1282
|
+
repo: z.string().describe("Repository name"),
|
|
1283
|
+
workflowId: z.union([z.string(), z.number()]).describe("Workflow ID or filename (e.g. \"deploy.yml\")"),
|
|
1284
|
+
ref: z.string().describe("Git ref (branch or tag) to run the workflow on"),
|
|
1285
|
+
inputs: z.record(z.string(), z.string()).optional().describe("Input parameters defined in the workflow_dispatch trigger")
|
|
1286
|
+
}),
|
|
1287
|
+
execute: async (args) => triggerWorkflowStep({
|
|
1288
|
+
token,
|
|
1289
|
+
...args
|
|
1290
|
+
})
|
|
1291
|
+
});
|
|
1292
|
+
async function cancelWorkflowRunStep({ token, owner, repo, runId }) {
|
|
1293
|
+
"use step";
|
|
1294
|
+
await createOctokit(token).rest.actions.cancelWorkflowRun({
|
|
1295
|
+
owner,
|
|
1296
|
+
repo,
|
|
1297
|
+
run_id: runId
|
|
1298
|
+
});
|
|
1299
|
+
return {
|
|
1300
|
+
cancelled: true,
|
|
1301
|
+
runId
|
|
1302
|
+
};
|
|
1303
|
+
}
|
|
1304
|
+
const cancelWorkflowRun = (token, { needsApproval = true } = {}) => tool({
|
|
1305
|
+
description: "Cancel an in-progress workflow run",
|
|
1306
|
+
needsApproval,
|
|
1307
|
+
inputSchema: z.object({
|
|
1308
|
+
owner: z.string().describe("Repository owner"),
|
|
1309
|
+
repo: z.string().describe("Repository name"),
|
|
1310
|
+
runId: z.number().describe("Workflow run ID to cancel")
|
|
1311
|
+
}),
|
|
1312
|
+
execute: async (args) => cancelWorkflowRunStep({
|
|
1313
|
+
token,
|
|
1314
|
+
...args
|
|
1315
|
+
})
|
|
1316
|
+
});
|
|
1317
|
+
async function rerunWorkflowRunStep({ token, owner, repo, runId, onlyFailedJobs }) {
|
|
1318
|
+
"use step";
|
|
1319
|
+
const octokit = createOctokit(token);
|
|
1320
|
+
if (onlyFailedJobs) await octokit.rest.actions.reRunWorkflowFailedJobs({
|
|
1321
|
+
owner,
|
|
1322
|
+
repo,
|
|
1323
|
+
run_id: runId
|
|
1324
|
+
});
|
|
1325
|
+
else await octokit.rest.actions.reRunWorkflow({
|
|
1326
|
+
owner,
|
|
1327
|
+
repo,
|
|
1328
|
+
run_id: runId
|
|
1329
|
+
});
|
|
1330
|
+
return {
|
|
1331
|
+
rerun: true,
|
|
1332
|
+
runId,
|
|
1333
|
+
onlyFailedJobs
|
|
1334
|
+
};
|
|
1335
|
+
}
|
|
1336
|
+
const rerunWorkflowRun = (token, { needsApproval = true } = {}) => tool({
|
|
1337
|
+
description: "Re-run a workflow run, optionally only the failed jobs",
|
|
1338
|
+
needsApproval,
|
|
1339
|
+
inputSchema: z.object({
|
|
1340
|
+
owner: z.string().describe("Repository owner"),
|
|
1341
|
+
repo: z.string().describe("Repository name"),
|
|
1342
|
+
runId: z.number().describe("Workflow run ID to re-run"),
|
|
1343
|
+
onlyFailedJobs: z.boolean().optional().default(false).describe("Only re-run failed jobs instead of the entire workflow")
|
|
1344
|
+
}),
|
|
1345
|
+
execute: async (args) => rerunWorkflowRunStep({
|
|
1346
|
+
token,
|
|
1347
|
+
...args
|
|
1348
|
+
})
|
|
1349
|
+
});
|
|
1350
|
+
|
|
1351
|
+
//#endregion
|
|
1352
|
+
//#region src/agents.ts
|
|
1353
|
+
const SHARED_RULES = `When a tool execution is denied by the user, do not retry it. Briefly acknowledge the decision and move on.`;
|
|
1354
|
+
const DEFAULT_INSTRUCTIONS = `You are a helpful GitHub assistant. You can read and explore repositories, issues, pull requests, commits, code, gists, and workflows. You can also create issues, pull requests, comments, gists, trigger workflows, and update files when asked.
|
|
1355
|
+
|
|
1356
|
+
${SHARED_RULES}`;
|
|
1357
|
+
const PRESET_INSTRUCTIONS = {
|
|
1358
|
+
"code-review": `You are a code review assistant. Your job is to review pull requests thoroughly and provide constructive feedback.
|
|
1359
|
+
|
|
1360
|
+
When reviewing a PR:
|
|
1361
|
+
- Read the PR description and changed files carefully
|
|
1362
|
+
- To trace why a specific line exists or who last touched it, use getBlame on the file path and ref (branch or merge commit), then follow up with getCommit if you need the full patch
|
|
1363
|
+
- Check for bugs, logic errors, and edge cases
|
|
1364
|
+
- Suggest improvements when you spot issues
|
|
1365
|
+
- Be constructive — explain why something is a problem and how to fix it
|
|
1366
|
+
- Post your review as PR comments when asked
|
|
1367
|
+
|
|
1368
|
+
${SHARED_RULES}`,
|
|
1369
|
+
"issue-triage": `You are an issue triage assistant. Your job is to help manage and organize GitHub issues.
|
|
1370
|
+
|
|
1371
|
+
When triaging issues:
|
|
1372
|
+
- Read issue descriptions carefully to understand the problem
|
|
1373
|
+
- Identify duplicates when possible
|
|
1374
|
+
- Help categorize and prioritize issues
|
|
1375
|
+
- Respond to users with clear, helpful information
|
|
1376
|
+
- Create new issues when asked, with clear titles and descriptions
|
|
1377
|
+
|
|
1378
|
+
${SHARED_RULES}`,
|
|
1379
|
+
"ci-ops": `You are a CI/CD operations assistant. Your job is to help monitor and manage GitHub Actions workflows.
|
|
1380
|
+
|
|
1381
|
+
When working with workflows:
|
|
1382
|
+
- Check workflow run status and report failures clearly
|
|
1383
|
+
- Inspect job steps to identify exactly where a run failed
|
|
1384
|
+
- Re-run failed workflows when asked
|
|
1385
|
+
- Trigger workflow dispatches with the correct inputs and branch
|
|
1386
|
+
- Be careful with cancel and re-run operations — confirm the target run
|
|
1387
|
+
- Summarize run history and trends when asked
|
|
1388
|
+
|
|
1389
|
+
${SHARED_RULES}`,
|
|
1390
|
+
"repo-explorer": `You are a repository explorer. Your job is to help users understand codebases and find information across GitHub repositories.
|
|
1391
|
+
|
|
1392
|
+
When exploring repos:
|
|
1393
|
+
- Answer questions about code structure and organization
|
|
1394
|
+
- Use getBlame when the user asks about history or ownership of specific lines in a file
|
|
1395
|
+
- Summarize recent activity (commits, PRs, issues)
|
|
1396
|
+
- Find specific files, functions, or patterns in code
|
|
1397
|
+
- Explain how different parts of the codebase work together
|
|
1398
|
+
- You have read-only access — you cannot make changes
|
|
1399
|
+
|
|
1400
|
+
${SHARED_RULES}`,
|
|
1401
|
+
"maintainer": `You are a repository maintainer assistant. You have full access to manage repositories, issues, pull requests, gists, and workflows.
|
|
1402
|
+
|
|
1403
|
+
When maintaining repos:
|
|
1404
|
+
- Be careful with write operations — review before acting
|
|
1405
|
+
- Create well-structured issues and PRs with clear descriptions
|
|
1406
|
+
- Use merge strategies appropriate for the repository
|
|
1407
|
+
- Keep commit messages clean and descriptive
|
|
1408
|
+
- When closing issues, provide a clear reason
|
|
1409
|
+
|
|
1410
|
+
${SHARED_RULES}`
|
|
1411
|
+
};
|
|
1412
|
+
function resolveInstructions(options) {
|
|
1413
|
+
const defaultPrompt = options.preset && !Array.isArray(options.preset) ? PRESET_INSTRUCTIONS[options.preset] : DEFAULT_INSTRUCTIONS;
|
|
1414
|
+
if (options.instructions) return options.instructions;
|
|
1415
|
+
if (options.additionalInstructions) return `${defaultPrompt}\n\n${options.additionalInstructions}`;
|
|
1416
|
+
return defaultPrompt;
|
|
1417
|
+
}
|
|
1418
|
+
/**
|
|
1419
|
+
* Create a pre-configured GitHub agent powered by the AI SDK's `ToolLoopAgent`.
|
|
1420
|
+
*
|
|
1421
|
+
* Returns a `ToolLoopAgent` instance with `.generate()` and `.stream()` methods.
|
|
1422
|
+
*
|
|
1423
|
+
* @example
|
|
1424
|
+
* ```ts
|
|
1425
|
+
* import { createGithubAgent } from '@github-tools/sdk'
|
|
1426
|
+
*
|
|
1427
|
+
* const agent = createGithubAgent({
|
|
1428
|
+
* model: 'anthropic/claude-sonnet-4.6',
|
|
1429
|
+
* token: process.env.GITHUB_TOKEN!,
|
|
1430
|
+
* preset: 'code-review',
|
|
1431
|
+
* })
|
|
1432
|
+
*
|
|
1433
|
+
* const result = await agent.generate({ prompt: 'Review PR #42 on vercel/ai' })
|
|
1434
|
+
* ```
|
|
1435
|
+
*/
|
|
1436
|
+
function createGithubAgent({ token, preset, requireApproval, instructions, additionalInstructions, ...agentOptions }) {
|
|
1437
|
+
const tools = createGithubTools({
|
|
1438
|
+
token,
|
|
1439
|
+
requireApproval,
|
|
1440
|
+
preset
|
|
1441
|
+
});
|
|
1442
|
+
return new ToolLoopAgent({
|
|
1443
|
+
...agentOptions,
|
|
1444
|
+
tools,
|
|
1445
|
+
instructions: resolveInstructions({
|
|
1446
|
+
preset,
|
|
1447
|
+
instructions,
|
|
1448
|
+
additionalInstructions
|
|
1449
|
+
})
|
|
1450
|
+
});
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
//#endregion
|
|
1454
|
+
export { listPullRequests as A, closeIssue as C, addPullRequestComment as D, listIssues as E, forkRepository as F, getFileContent as I, getRepository as L, createBranch as M, createOrUpdateFile as N, createPullRequest as O, createRepository as P, listBranches as R, addIssueComment as S, getIssue as T, getBlame as _, listWorkflowJobs as a, searchCode as b, rerunWorkflowRun as c, createGistComment as d, deleteGist as f, updateGist as g, listGists as h, getWorkflowRun as i, mergePullRequest as j, getPullRequest as k, triggerWorkflow as l, listGistComments as m, resolveInstructions as n, listWorkflowRuns as o, getGist as p, cancelWorkflowRun as r, listWorkflows as s, createGithubAgent as t, createGist as u, getCommit as v, createIssue as w, searchRepositories as x, listCommits as y, createOctokit as z };
|
|
1455
|
+
//# sourceMappingURL=agents-Cdb0a8CP.mjs.map
|