@giantswarm-io/pro 1.3.1
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/LICENSE +201 -0
- package/README.md +317 -0
- package/bin/index.js +65 -0
- package/package.json +40 -0
- package/src/index.js +49 -0
- package/src/lib/api.js +87 -0
- package/src/lib/auth/provider.js +395 -0
- package/src/lib/fields.js +111 -0
- package/src/lib/items.js +426 -0
- package/src/lib/logger.js +40 -0
- package/src/lib/mcp/http.js +233 -0
- package/src/lib/mcp/resources.js +304 -0
- package/src/lib/mcp/server.js +156 -0
- package/src/lib/mcp/sub-issues.js +580 -0
- package/src/lib/mcp/tools.js +601 -0
- package/src/lib/project.js +406 -0
- package/src/lib/rest-api.js +141 -0
- package/src/lib/selfupdate.js +107 -0
- package/src/lib/sub-issues.js +100 -0
- package/src/lib/utils.js +23 -0
- package/src/lib/version.js +19 -0
|
@@ -0,0 +1,580 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Sub-Issues Tools
|
|
3
|
+
*
|
|
4
|
+
* Exposes 6 tools for managing GitHub sub-issues (parent/child relationships):
|
|
5
|
+
* - list_sub_issues: List sub-issues of a parent issue
|
|
6
|
+
* - add_sub_issue: Add a sub-issue to a parent
|
|
7
|
+
* - remove_sub_issue: Remove a sub-issue from a parent
|
|
8
|
+
* - get_parent_issue: Get the parent of an issue
|
|
9
|
+
* - reprioritize_sub_issue: Reorder a sub-issue within its parent
|
|
10
|
+
* - migrate_task_list_to_sub_issues: Convert markdown task lists to sub-issues
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { getOctokit, parseIssueRef, resolveIssueId } from '../rest-api.js';
|
|
14
|
+
import {
|
|
15
|
+
listSubIssues,
|
|
16
|
+
addSubIssue,
|
|
17
|
+
removeSubIssue,
|
|
18
|
+
getParentIssue,
|
|
19
|
+
reprioritizeSubIssue
|
|
20
|
+
} from '../sub-issues.js';
|
|
21
|
+
import { logger } from '../logger.js';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Extract the GitHub token from MCP request extra context.
|
|
25
|
+
* @param {Object} [extra] - MCP request extra context
|
|
26
|
+
* @returns {string|undefined}
|
|
27
|
+
*/
|
|
28
|
+
function extractToken(extra) {
|
|
29
|
+
return extra?.authInfo?.token;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Resolve owner/repo/issue_number from flexible tool args.
|
|
34
|
+
* Accepts either an `issueUrl` string or explicit `owner`/`repo`/`issue_number`.
|
|
35
|
+
*/
|
|
36
|
+
function resolveIssueArgs(args, urlKey = 'issueUrl') {
|
|
37
|
+
if (args[urlKey]) {
|
|
38
|
+
return parseIssueRef(args[urlKey]);
|
|
39
|
+
}
|
|
40
|
+
if (args.owner && args.repo && args.issue_number) {
|
|
41
|
+
return { owner: args.owner, repo: args.repo, issue_number: Number(args.issue_number) };
|
|
42
|
+
}
|
|
43
|
+
throw new Error(`Provide either '${urlKey}' (URL or owner/repo#num) or 'owner', 'repo', and 'issue_number'.`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function compactIssue(issue) {
|
|
47
|
+
return {
|
|
48
|
+
number: issue.number,
|
|
49
|
+
title: issue.title,
|
|
50
|
+
url: issue.html_url,
|
|
51
|
+
state: issue.state,
|
|
52
|
+
repository: issue.repository
|
|
53
|
+
? `${issue.repository.owner?.login ?? issue.repository.owner}/${issue.repository.name}`
|
|
54
|
+
: undefined,
|
|
55
|
+
sub_issues_summary: issue.sub_issues_summary ?? undefined
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// ---------------------------------------------------------------------------
|
|
60
|
+
// Tool: list_sub_issues
|
|
61
|
+
// ---------------------------------------------------------------------------
|
|
62
|
+
|
|
63
|
+
export const listSubIssuesTool = {
|
|
64
|
+
name: 'list_sub_issues',
|
|
65
|
+
description: 'List the sub-issues of a GitHub issue. Provide the parent issue as a URL (e.g. "https://github.com/owner/repo/issues/1"), short ref ("owner/repo#1"), or explicit owner/repo/issue_number.',
|
|
66
|
+
inputSchema: {
|
|
67
|
+
type: 'object',
|
|
68
|
+
properties: {
|
|
69
|
+
issueUrl: {
|
|
70
|
+
type: 'string',
|
|
71
|
+
description: 'Issue URL or short ref (owner/repo#num)'
|
|
72
|
+
},
|
|
73
|
+
owner: { type: 'string', description: 'Repository owner' },
|
|
74
|
+
repo: { type: 'string', description: 'Repository name' },
|
|
75
|
+
issue_number: { type: 'number', description: 'Issue number' },
|
|
76
|
+
per_page: {
|
|
77
|
+
type: 'number',
|
|
78
|
+
description: 'Results per page (max 100, default 30)'
|
|
79
|
+
},
|
|
80
|
+
page: {
|
|
81
|
+
type: 'number',
|
|
82
|
+
description: 'Page number (default 1)'
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export async function handleListSubIssues(args, extra) {
|
|
89
|
+
try {
|
|
90
|
+
const token = extractToken(extra);
|
|
91
|
+
const { owner, repo, issue_number } = resolveIssueArgs(args);
|
|
92
|
+
logger.info('MCP: Listing sub-issues', { owner, repo, issue_number });
|
|
93
|
+
|
|
94
|
+
const data = await listSubIssues(
|
|
95
|
+
{
|
|
96
|
+
owner,
|
|
97
|
+
repo,
|
|
98
|
+
issue_number,
|
|
99
|
+
per_page: args.per_page || 30,
|
|
100
|
+
page: args.page || 1
|
|
101
|
+
},
|
|
102
|
+
token
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
content: [{
|
|
107
|
+
type: 'text',
|
|
108
|
+
text: JSON.stringify({
|
|
109
|
+
count: data.length,
|
|
110
|
+
sub_issues: data.map(compactIssue)
|
|
111
|
+
})
|
|
112
|
+
}]
|
|
113
|
+
};
|
|
114
|
+
} catch (error) {
|
|
115
|
+
logger.error('MCP: Error listing sub-issues', { error: error.message });
|
|
116
|
+
return { error: error.message };
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// ---------------------------------------------------------------------------
|
|
121
|
+
// Tool: add_sub_issue
|
|
122
|
+
// ---------------------------------------------------------------------------
|
|
123
|
+
|
|
124
|
+
export const addSubIssueTool = {
|
|
125
|
+
name: 'add_sub_issue',
|
|
126
|
+
description: 'Add a sub-issue to a parent issue. Provide the parent issue and the child issue to add. The child can be specified as a URL/ref (subIssueUrl) or integer ID (subIssueId).',
|
|
127
|
+
inputSchema: {
|
|
128
|
+
type: 'object',
|
|
129
|
+
properties: {
|
|
130
|
+
issueUrl: {
|
|
131
|
+
type: 'string',
|
|
132
|
+
description: 'Parent issue URL or short ref (owner/repo#num)'
|
|
133
|
+
},
|
|
134
|
+
owner: { type: 'string', description: 'Parent repository owner' },
|
|
135
|
+
repo: { type: 'string', description: 'Parent repository name' },
|
|
136
|
+
issue_number: { type: 'number', description: 'Parent issue number' },
|
|
137
|
+
subIssueUrl: {
|
|
138
|
+
type: 'string',
|
|
139
|
+
description: 'Child issue URL or short ref to add as sub-issue'
|
|
140
|
+
},
|
|
141
|
+
subIssueId: {
|
|
142
|
+
type: 'number',
|
|
143
|
+
description: 'Child issue integer ID (use instead of subIssueUrl if already known)'
|
|
144
|
+
},
|
|
145
|
+
replaceParent: {
|
|
146
|
+
type: 'boolean',
|
|
147
|
+
description: 'If true, replaces the child\'s existing parent (if any). Default false.'
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
export async function handleAddSubIssue(args, extra) {
|
|
154
|
+
try {
|
|
155
|
+
const token = extractToken(extra);
|
|
156
|
+
const { owner, repo, issue_number } = resolveIssueArgs(args);
|
|
157
|
+
logger.info('MCP: Adding sub-issue', { owner, repo, issue_number });
|
|
158
|
+
|
|
159
|
+
let subIssueId = args.subIssueId;
|
|
160
|
+
if (!subIssueId) {
|
|
161
|
+
if (!args.subIssueUrl) {
|
|
162
|
+
return { error: 'Provide either subIssueUrl or subIssueId for the child issue.' };
|
|
163
|
+
}
|
|
164
|
+
const resolved = await resolveIssueId(args.subIssueUrl, { token });
|
|
165
|
+
subIssueId = resolved.id;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const data = await addSubIssue(
|
|
169
|
+
{
|
|
170
|
+
owner,
|
|
171
|
+
repo,
|
|
172
|
+
issue_number,
|
|
173
|
+
subIssueId,
|
|
174
|
+
replaceParent: args.replaceParent || false
|
|
175
|
+
},
|
|
176
|
+
token
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
return {
|
|
180
|
+
content: [{
|
|
181
|
+
type: 'text',
|
|
182
|
+
text: JSON.stringify({
|
|
183
|
+
success: true,
|
|
184
|
+
parent: compactIssue(data)
|
|
185
|
+
})
|
|
186
|
+
}]
|
|
187
|
+
};
|
|
188
|
+
} catch (error) {
|
|
189
|
+
logger.error('MCP: Error adding sub-issue', { error: error.message });
|
|
190
|
+
return { error: error.message };
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// ---------------------------------------------------------------------------
|
|
195
|
+
// Tool: remove_sub_issue
|
|
196
|
+
// ---------------------------------------------------------------------------
|
|
197
|
+
|
|
198
|
+
export const removeSubIssueTool = {
|
|
199
|
+
name: 'remove_sub_issue',
|
|
200
|
+
description: 'Remove a sub-issue from a parent issue. Provide the parent issue and the child issue to remove.',
|
|
201
|
+
inputSchema: {
|
|
202
|
+
type: 'object',
|
|
203
|
+
properties: {
|
|
204
|
+
issueUrl: {
|
|
205
|
+
type: 'string',
|
|
206
|
+
description: 'Parent issue URL or short ref (owner/repo#num)'
|
|
207
|
+
},
|
|
208
|
+
owner: { type: 'string', description: 'Parent repository owner' },
|
|
209
|
+
repo: { type: 'string', description: 'Parent repository name' },
|
|
210
|
+
issue_number: { type: 'number', description: 'Parent issue number' },
|
|
211
|
+
subIssueUrl: {
|
|
212
|
+
type: 'string',
|
|
213
|
+
description: 'Child issue URL or short ref to remove'
|
|
214
|
+
},
|
|
215
|
+
subIssueId: {
|
|
216
|
+
type: 'number',
|
|
217
|
+
description: 'Child issue integer ID (use instead of subIssueUrl if already known)'
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
export async function handleRemoveSubIssue(args, extra) {
|
|
224
|
+
try {
|
|
225
|
+
const token = extractToken(extra);
|
|
226
|
+
const { owner, repo, issue_number } = resolveIssueArgs(args);
|
|
227
|
+
logger.info('MCP: Removing sub-issue', { owner, repo, issue_number });
|
|
228
|
+
|
|
229
|
+
let subIssueId = args.subIssueId;
|
|
230
|
+
if (!subIssueId) {
|
|
231
|
+
if (!args.subIssueUrl) {
|
|
232
|
+
return { error: 'Provide either subIssueUrl or subIssueId for the child issue.' };
|
|
233
|
+
}
|
|
234
|
+
const resolved = await resolveIssueId(args.subIssueUrl, { token });
|
|
235
|
+
subIssueId = resolved.id;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
await removeSubIssue({ owner, repo, issue_number, subIssueId }, token);
|
|
239
|
+
|
|
240
|
+
return {
|
|
241
|
+
content: [{
|
|
242
|
+
type: 'text',
|
|
243
|
+
text: JSON.stringify({ success: true, removed: subIssueId })
|
|
244
|
+
}]
|
|
245
|
+
};
|
|
246
|
+
} catch (error) {
|
|
247
|
+
logger.error('MCP: Error removing sub-issue', { error: error.message });
|
|
248
|
+
return { error: error.message };
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// ---------------------------------------------------------------------------
|
|
253
|
+
// Tool: get_parent_issue
|
|
254
|
+
// ---------------------------------------------------------------------------
|
|
255
|
+
|
|
256
|
+
export const getParentIssueTool = {
|
|
257
|
+
name: 'get_parent_issue',
|
|
258
|
+
description: 'Get the parent issue of a given issue. Returns null if the issue has no parent.',
|
|
259
|
+
inputSchema: {
|
|
260
|
+
type: 'object',
|
|
261
|
+
properties: {
|
|
262
|
+
issueUrl: {
|
|
263
|
+
type: 'string',
|
|
264
|
+
description: 'Child issue URL or short ref (owner/repo#num)'
|
|
265
|
+
},
|
|
266
|
+
owner: { type: 'string', description: 'Repository owner' },
|
|
267
|
+
repo: { type: 'string', description: 'Repository name' },
|
|
268
|
+
issue_number: { type: 'number', description: 'Issue number' }
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
export async function handleGetParentIssue(args, extra) {
|
|
274
|
+
try {
|
|
275
|
+
const token = extractToken(extra);
|
|
276
|
+
const { owner, repo, issue_number } = resolveIssueArgs(args);
|
|
277
|
+
logger.info('MCP: Getting parent issue', { owner, repo, issue_number });
|
|
278
|
+
|
|
279
|
+
const data = await getParentIssue({ owner, repo, issue_number }, token);
|
|
280
|
+
|
|
281
|
+
return {
|
|
282
|
+
content: [{
|
|
283
|
+
type: 'text',
|
|
284
|
+
text: JSON.stringify({ parent: data ? compactIssue(data) : null })
|
|
285
|
+
}]
|
|
286
|
+
};
|
|
287
|
+
} catch (error) {
|
|
288
|
+
logger.error('MCP: Error getting parent issue', { error: error.message });
|
|
289
|
+
return { error: error.message };
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// ---------------------------------------------------------------------------
|
|
294
|
+
// Tool: reprioritize_sub_issue
|
|
295
|
+
// ---------------------------------------------------------------------------
|
|
296
|
+
|
|
297
|
+
export const reprioritizeSubIssueTool = {
|
|
298
|
+
name: 'reprioritize_sub_issue',
|
|
299
|
+
description: 'Reorder a sub-issue within its parent\'s sub-issue list. Specify either afterUrl/afterId (place after that issue) or beforeUrl/beforeId (place before that issue).',
|
|
300
|
+
inputSchema: {
|
|
301
|
+
type: 'object',
|
|
302
|
+
properties: {
|
|
303
|
+
issueUrl: {
|
|
304
|
+
type: 'string',
|
|
305
|
+
description: 'Parent issue URL or short ref (owner/repo#num)'
|
|
306
|
+
},
|
|
307
|
+
owner: { type: 'string', description: 'Parent repository owner' },
|
|
308
|
+
repo: { type: 'string', description: 'Parent repository name' },
|
|
309
|
+
issue_number: { type: 'number', description: 'Parent issue number' },
|
|
310
|
+
subIssueUrl: {
|
|
311
|
+
type: 'string',
|
|
312
|
+
description: 'Sub-issue URL or short ref to reorder'
|
|
313
|
+
},
|
|
314
|
+
subIssueId: {
|
|
315
|
+
type: 'number',
|
|
316
|
+
description: 'Sub-issue integer ID (use instead of subIssueUrl if already known)'
|
|
317
|
+
},
|
|
318
|
+
afterUrl: {
|
|
319
|
+
type: 'string',
|
|
320
|
+
description: 'Place the sub-issue after this issue (URL or short ref)'
|
|
321
|
+
},
|
|
322
|
+
afterId: {
|
|
323
|
+
type: 'number',
|
|
324
|
+
description: 'Place the sub-issue after this issue (integer ID)'
|
|
325
|
+
},
|
|
326
|
+
beforeUrl: {
|
|
327
|
+
type: 'string',
|
|
328
|
+
description: 'Place the sub-issue before this issue (URL or short ref)'
|
|
329
|
+
},
|
|
330
|
+
beforeId: {
|
|
331
|
+
type: 'number',
|
|
332
|
+
description: 'Place the sub-issue before this issue (integer ID)'
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
export async function handleReprioritizeSubIssue(args, extra) {
|
|
339
|
+
try {
|
|
340
|
+
const token = extractToken(extra);
|
|
341
|
+
const { owner, repo, issue_number } = resolveIssueArgs(args);
|
|
342
|
+
logger.info('MCP: Reprioritizing sub-issue', { owner, repo, issue_number });
|
|
343
|
+
|
|
344
|
+
let subIssueId = args.subIssueId;
|
|
345
|
+
if (!subIssueId) {
|
|
346
|
+
if (!args.subIssueUrl) {
|
|
347
|
+
return { error: 'Provide either subIssueUrl or subIssueId for the sub-issue to reorder.' };
|
|
348
|
+
}
|
|
349
|
+
const resolved = await resolveIssueId(args.subIssueUrl, { token });
|
|
350
|
+
subIssueId = resolved.id;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
let afterId = args.afterId;
|
|
354
|
+
if (!afterId && args.afterUrl) {
|
|
355
|
+
const resolved = await resolveIssueId(args.afterUrl, { token });
|
|
356
|
+
afterId = resolved.id;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
let beforeId = args.beforeId;
|
|
360
|
+
if (!beforeId && args.beforeUrl) {
|
|
361
|
+
const resolved = await resolveIssueId(args.beforeUrl, { token });
|
|
362
|
+
beforeId = resolved.id;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
if (!afterId && !beforeId) {
|
|
366
|
+
return { error: 'Provide either afterUrl/afterId or beforeUrl/beforeId to specify the new position.' };
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
await reprioritizeSubIssue({ owner, repo, issue_number, subIssueId, afterId, beforeId }, token);
|
|
370
|
+
|
|
371
|
+
return {
|
|
372
|
+
content: [{
|
|
373
|
+
type: 'text',
|
|
374
|
+
text: JSON.stringify({ success: true, sub_issue_id: subIssueId })
|
|
375
|
+
}]
|
|
376
|
+
};
|
|
377
|
+
} catch (error) {
|
|
378
|
+
logger.error('MCP: Error reprioritizing sub-issue', { error: error.message });
|
|
379
|
+
return { error: error.message };
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// ---------------------------------------------------------------------------
|
|
384
|
+
// Tool: migrate_task_list_to_sub_issues
|
|
385
|
+
// ---------------------------------------------------------------------------
|
|
386
|
+
|
|
387
|
+
const TASK_LINE_RE = /^(\s*-\s*\[[ xX]\])\s+(.+)$/;
|
|
388
|
+
|
|
389
|
+
const EMBEDDED_ISSUE_URL_RE = /https?:\/\/github\.com\/([^/]+)\/([^/]+)\/issues\/(\d+)\/?/;
|
|
390
|
+
const MARKDOWN_LINK_ISSUE_RE = /\[([^\]]*)\]\(https?:\/\/github\.com\/([^/]+)\/([^/]+)\/issues\/(\d+)\/?[^)]*\)/;
|
|
391
|
+
const BARE_SHORT_REF_RE = /^([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)#(\d+)$/;
|
|
392
|
+
const BARE_SAME_REPO_RE = /^#(\d+)$/;
|
|
393
|
+
const LEADING_SHORT_REF_RE = /^([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)#(\d+)(?:[\s),.;:!?~]|$)/;
|
|
394
|
+
const EMBEDDED_SHORT_REF_RE = /(?:^|[\s(~])([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)#(\d+)(?:[\s),.;:!?~]|$)/;
|
|
395
|
+
const EMBEDDED_SAME_REPO_RE = /(?:^|[\s(~])#(\d+)(?:[\s),.;:!?~]|$)/;
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Extract an issue reference from a task-list item's text content.
|
|
399
|
+
* Strips leading ~~ (strikethrough) before matching. Tries in priority order:
|
|
400
|
+
* 1. Bare (exact-match) refs: entire text is a URL, short ref, or #N
|
|
401
|
+
* 2. Leading short ref: text starts with owner/repo#N (before checking deeper)
|
|
402
|
+
* 3. Markdown links to issues: [text](https://github.com/o/r/issues/N)
|
|
403
|
+
* 4. Embedded URLs: descriptive text containing a github issue URL
|
|
404
|
+
* 5. Embedded short refs: text containing owner/repo#N
|
|
405
|
+
* 6. Embedded same-repo refs: text containing #N
|
|
406
|
+
*
|
|
407
|
+
* @param {string} text - The text after the checkbox
|
|
408
|
+
* @param {string} fallbackOwner - Owner to use for same-repo (#N) refs
|
|
409
|
+
* @param {string} fallbackRepo - Repo to use for same-repo (#N) refs
|
|
410
|
+
* @returns {{ owner: string, repo: string, issue_number: number } | null}
|
|
411
|
+
*/
|
|
412
|
+
export function extractIssueRef(text, fallbackOwner, fallbackRepo) {
|
|
413
|
+
const trimmed = text.trim();
|
|
414
|
+
|
|
415
|
+
const stripped = trimmed.replace(/^~~\s*/, '').replace(/\s*~~$/, '');
|
|
416
|
+
|
|
417
|
+
const bareUrlMatch = stripped.match(/^https?:\/\/github\.com\/([^/]+)\/([^/]+)\/issues\/(\d+)\/?$/);
|
|
418
|
+
if (bareUrlMatch) {
|
|
419
|
+
return { owner: bareUrlMatch[1], repo: bareUrlMatch[2], issue_number: parseInt(bareUrlMatch[3], 10) };
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
const bareShortMatch = stripped.match(BARE_SHORT_REF_RE);
|
|
423
|
+
if (bareShortMatch) {
|
|
424
|
+
return { owner: bareShortMatch[1], repo: bareShortMatch[2], issue_number: parseInt(bareShortMatch[3], 10) };
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
const bareSameRepoMatch = stripped.match(BARE_SAME_REPO_RE);
|
|
428
|
+
if (bareSameRepoMatch && fallbackOwner && fallbackRepo) {
|
|
429
|
+
return { owner: fallbackOwner, repo: fallbackRepo, issue_number: parseInt(bareSameRepoMatch[1], 10) };
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// Check for a short ref at the START of the text before trying markdown links
|
|
433
|
+
// or embedded URLs. This ensures that when text starts with owner/repo#N (e.g.
|
|
434
|
+
// after stripping ~~), it takes priority over a markdown link deeper in the text.
|
|
435
|
+
const leadingShortMatch = stripped.match(LEADING_SHORT_REF_RE);
|
|
436
|
+
if (leadingShortMatch) {
|
|
437
|
+
return { owner: leadingShortMatch[1], repo: leadingShortMatch[2], issue_number: parseInt(leadingShortMatch[3], 10) };
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
const mdLinkMatch = stripped.match(MARKDOWN_LINK_ISSUE_RE);
|
|
441
|
+
if (mdLinkMatch) {
|
|
442
|
+
return { owner: mdLinkMatch[2], repo: mdLinkMatch[3], issue_number: parseInt(mdLinkMatch[4], 10) };
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
const embeddedUrlMatch = stripped.match(EMBEDDED_ISSUE_URL_RE);
|
|
446
|
+
if (embeddedUrlMatch) {
|
|
447
|
+
return { owner: embeddedUrlMatch[1], repo: embeddedUrlMatch[2], issue_number: parseInt(embeddedUrlMatch[3], 10) };
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
const embeddedShortMatch = stripped.match(EMBEDDED_SHORT_REF_RE);
|
|
451
|
+
if (embeddedShortMatch) {
|
|
452
|
+
return { owner: embeddedShortMatch[1], repo: embeddedShortMatch[2], issue_number: parseInt(embeddedShortMatch[3], 10) };
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
const embeddedSameRepoMatch = stripped.match(EMBEDDED_SAME_REPO_RE);
|
|
456
|
+
if (embeddedSameRepoMatch && fallbackOwner && fallbackRepo) {
|
|
457
|
+
return { owner: fallbackOwner, repo: fallbackRepo, issue_number: parseInt(embeddedSameRepoMatch[1], 10) };
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
return null;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
export const migrateTaskListTool = {
|
|
464
|
+
name: 'migrate_task_list_to_sub_issues',
|
|
465
|
+
description: 'Convert markdown task-list items in an issue body into sub-issues. Parses lines like "- [ ] https://github.com/o/r/issues/1", "- [x] owner/repo#1", or "- [ ] #1" (same-repo). Optionally removes converted lines from the issue body.',
|
|
466
|
+
inputSchema: {
|
|
467
|
+
type: 'object',
|
|
468
|
+
properties: {
|
|
469
|
+
issueUrl: {
|
|
470
|
+
type: 'string',
|
|
471
|
+
description: 'The epic/parent issue URL or short ref containing the task list'
|
|
472
|
+
},
|
|
473
|
+
owner: { type: 'string', description: 'Repository owner' },
|
|
474
|
+
repo: { type: 'string', description: 'Repository name' },
|
|
475
|
+
issue_number: { type: 'number', description: 'Issue number' },
|
|
476
|
+
removeTaskList: {
|
|
477
|
+
type: 'boolean',
|
|
478
|
+
description: 'If true, remove converted task-list lines from the issue body after migration. Default false.'
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
export async function handleMigrateTaskList(args, extra) {
|
|
485
|
+
try {
|
|
486
|
+
const token = extractToken(extra);
|
|
487
|
+
const client = getOctokit(token);
|
|
488
|
+
const { owner, repo, issue_number } = resolveIssueArgs(args);
|
|
489
|
+
logger.info('MCP: Migrating task list to sub-issues', { owner, repo, issue_number });
|
|
490
|
+
|
|
491
|
+
const { data: issue } = await client.rest.issues.get({ owner, repo, issue_number });
|
|
492
|
+
const body = (issue.body || '').replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
493
|
+
const lines = body.split('\n');
|
|
494
|
+
|
|
495
|
+
const converted = [];
|
|
496
|
+
const failed = [];
|
|
497
|
+
const skipped = [];
|
|
498
|
+
const convertedLineIndices = new Set();
|
|
499
|
+
|
|
500
|
+
for (let i = 0; i < lines.length; i++) {
|
|
501
|
+
const line = lines[i];
|
|
502
|
+
const taskMatch = line.match(TASK_LINE_RE);
|
|
503
|
+
if (!taskMatch) continue;
|
|
504
|
+
|
|
505
|
+
const text = taskMatch[2];
|
|
506
|
+
const issueRef = extractIssueRef(text, owner, repo);
|
|
507
|
+
|
|
508
|
+
if (!issueRef) {
|
|
509
|
+
skipped.push({ line: i + 1, text: text.trim(), reason: 'not an issue reference' });
|
|
510
|
+
continue;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
const { owner: childOwner, repo: childRepo, issue_number: childNumber } = issueRef;
|
|
514
|
+
|
|
515
|
+
try {
|
|
516
|
+
const resolved = await resolveIssueId(childOwner, childRepo, childNumber, { token });
|
|
517
|
+
await addSubIssue(
|
|
518
|
+
{ owner, repo, issue_number, subIssueId: resolved.id, replaceParent: false },
|
|
519
|
+
token
|
|
520
|
+
);
|
|
521
|
+
converted.push({
|
|
522
|
+
number: resolved.number,
|
|
523
|
+
title: resolved.title,
|
|
524
|
+
url: resolved.html_url,
|
|
525
|
+
repository: `${childOwner}/${childRepo}`
|
|
526
|
+
});
|
|
527
|
+
convertedLineIndices.add(i);
|
|
528
|
+
} catch (err) {
|
|
529
|
+
failed.push({
|
|
530
|
+
ref: `${childOwner}/${childRepo}#${childNumber}`,
|
|
531
|
+
error: err.message
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
if (args.removeTaskList && convertedLineIndices.size > 0) {
|
|
537
|
+
const newBody = lines
|
|
538
|
+
.filter((_, i) => !convertedLineIndices.has(i))
|
|
539
|
+
.join('\n');
|
|
540
|
+
await client.rest.issues.update({ owner, repo, issue_number, body: newBody });
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
return {
|
|
544
|
+
content: [{
|
|
545
|
+
type: 'text',
|
|
546
|
+
text: JSON.stringify({
|
|
547
|
+
converted,
|
|
548
|
+
failed,
|
|
549
|
+
skipped,
|
|
550
|
+
summary: `${converted.length} converted, ${failed.length} failed, ${skipped.length} skipped`
|
|
551
|
+
})
|
|
552
|
+
}]
|
|
553
|
+
};
|
|
554
|
+
} catch (error) {
|
|
555
|
+
logger.error('MCP: Error migrating task list', { error: error.message });
|
|
556
|
+
return { error: error.message };
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
// ---------------------------------------------------------------------------
|
|
561
|
+
// Exports
|
|
562
|
+
// ---------------------------------------------------------------------------
|
|
563
|
+
|
|
564
|
+
export const subIssueTools = [
|
|
565
|
+
listSubIssuesTool,
|
|
566
|
+
addSubIssueTool,
|
|
567
|
+
removeSubIssueTool,
|
|
568
|
+
getParentIssueTool,
|
|
569
|
+
reprioritizeSubIssueTool,
|
|
570
|
+
migrateTaskListTool
|
|
571
|
+
];
|
|
572
|
+
|
|
573
|
+
export const subIssueToolHandlers = {
|
|
574
|
+
list_sub_issues: handleListSubIssues,
|
|
575
|
+
add_sub_issue: handleAddSubIssue,
|
|
576
|
+
remove_sub_issue: handleRemoveSubIssue,
|
|
577
|
+
get_parent_issue: handleGetParentIssue,
|
|
578
|
+
reprioritize_sub_issue: handleReprioritizeSubIssue,
|
|
579
|
+
migrate_task_list_to_sub_issues: handleMigrateTaskList
|
|
580
|
+
};
|