ai-dev-requirements 0.1.6 → 0.1.8
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/dist/index.cjs +257 -26
- package/dist/index.mjs +257 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -123,7 +123,7 @@ const SEARCH_TASKS_QUERY = `
|
|
|
123
123
|
key
|
|
124
124
|
tasks(filterGroup: $filterGroup, orderBy: $orderBy, limit: $limit, includeAncestors: { pathField: "path" }) {
|
|
125
125
|
key uuid number name
|
|
126
|
-
issueType { uuid name }
|
|
126
|
+
issueType { uuid name detailType }
|
|
127
127
|
status { uuid name category }
|
|
128
128
|
priority { value }
|
|
129
129
|
assign { uuid name }
|
|
@@ -132,6 +132,15 @@ const SEARCH_TASKS_QUERY = `
|
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
`;
|
|
135
|
+
const ISSUE_TYPES_QUERY = `
|
|
136
|
+
query IssueTypes($orderBy: OrderBy) {
|
|
137
|
+
issueTypes(orderBy: $orderBy) {
|
|
138
|
+
uuid
|
|
139
|
+
name
|
|
140
|
+
detailType
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
`;
|
|
135
144
|
const TASK_BY_NUMBER_QUERY = SEARCH_TASKS_QUERY;
|
|
136
145
|
const RELATED_TASKS_QUERY = `
|
|
137
146
|
query Task($key: Key) {
|
|
@@ -193,6 +202,68 @@ const DEFAULT_STATUS_NOT_IN = [
|
|
|
193
202
|
"Dn3k8ffK",
|
|
194
203
|
"TbmY2So5"
|
|
195
204
|
];
|
|
205
|
+
function parseOnesSearchIntent(query) {
|
|
206
|
+
if (!query) return "keyword";
|
|
207
|
+
const normalized = query.toLowerCase();
|
|
208
|
+
if (query.includes("缺陷") || normalized.includes("bug")) return "all_bugs";
|
|
209
|
+
if (query.includes("任务")) return "all_tasks";
|
|
210
|
+
return "keyword";
|
|
211
|
+
}
|
|
212
|
+
function extractAssigneeName(query, intent) {
|
|
213
|
+
if (intent === "keyword") return null;
|
|
214
|
+
const trimmed = query.trim();
|
|
215
|
+
if (!trimmed) return null;
|
|
216
|
+
const ownerStyleMatch = trimmed.match(/\u8D1F\u8D23\u4EBA\u4E3A(.+?)\u7684?(?:\u7F3A\u9677|bug)$/i);
|
|
217
|
+
if (ownerStyleMatch?.[1]) return ownerStyleMatch[1].trim();
|
|
218
|
+
const candidate = trimmed.match(/^(查询)?(.+?)的(?:缺陷|bug|任务)$/i)?.[2]?.trim();
|
|
219
|
+
if (!candidate || candidate.includes("我")) return null;
|
|
220
|
+
return candidate;
|
|
221
|
+
}
|
|
222
|
+
function extractNamedAssignee(query, intent) {
|
|
223
|
+
if (intent === "keyword") return null;
|
|
224
|
+
const compact = query.replace(/\s+/g, "").trim();
|
|
225
|
+
if (!compact) return null;
|
|
226
|
+
const ownerStyleMatch = compact.match(/(?:\u8D1F\u8D23\u4EBA\u4E3A|\u8D1F\u8D23\u4EBA\u662F|\u6307\u6D3E\u7ED9|\u5206\u914D\u7ED9)(.+?)\u7684?(?:\u7F3A\u9677|bug|\u4EFB\u52A1)$/i);
|
|
227
|
+
if (ownerStyleMatch?.[1]) return ownerStyleMatch[1].trim();
|
|
228
|
+
const candidate = compact.match(/^(?:\u67E5\u8BE2|\u67E5\u627E|\u641C\u7D22)?(.+?)\u7684?(?:\u7F3A\u9677|bug|\u4EFB\u52A1)$/i)?.[1]?.trim();
|
|
229
|
+
if (!candidate || candidate.startsWith("我") || /^(?:\u6211|\u6211\u7684|\u6211\u6240\u6709|\u6211\u5168\u90E8|\u672C\u4EBA|\u5F53\u524D\u7528\u6237)$/.test(candidate)) return null;
|
|
230
|
+
return candidate;
|
|
231
|
+
}
|
|
232
|
+
function getBugStatusPriority(task) {
|
|
233
|
+
if (task.status?.category === "to_do") return 0;
|
|
234
|
+
if (task.status?.category === "in_progress") return 1;
|
|
235
|
+
return Number.POSITIVE_INFINITY;
|
|
236
|
+
}
|
|
237
|
+
function isOpenOrInProgressBug(task) {
|
|
238
|
+
const category = task.status?.category;
|
|
239
|
+
return category === "to_do" || category === "in_progress";
|
|
240
|
+
}
|
|
241
|
+
function extractTeamUsers(payload) {
|
|
242
|
+
const record = payload && typeof payload === "object" ? payload : null;
|
|
243
|
+
if (!record) return [];
|
|
244
|
+
const rawUsers = [
|
|
245
|
+
record.users,
|
|
246
|
+
record.items,
|
|
247
|
+
record.list,
|
|
248
|
+
record.results,
|
|
249
|
+
record.data?.users,
|
|
250
|
+
record.data?.items,
|
|
251
|
+
record.data?.list,
|
|
252
|
+
record.data?.results
|
|
253
|
+
].find(Array.isArray);
|
|
254
|
+
if (!rawUsers) return [];
|
|
255
|
+
return rawUsers.map((item) => {
|
|
256
|
+
const user = item && typeof item === "object" ? item : null;
|
|
257
|
+
if (!user) return null;
|
|
258
|
+
const uuid = user.uuid ?? user.user?.uuid ?? user.orgUser?.uuid ?? user.orgUserUuid ?? user.org_user_uuid ?? user.org_user?.org_user_uuid;
|
|
259
|
+
const name = user.name ?? user.user?.name ?? user.orgUser?.name ?? user.org_user?.name;
|
|
260
|
+
if (!uuid || !name) return null;
|
|
261
|
+
return {
|
|
262
|
+
uuid,
|
|
263
|
+
name
|
|
264
|
+
};
|
|
265
|
+
}).filter((item) => item !== null);
|
|
266
|
+
}
|
|
196
267
|
function base64Url(buffer) {
|
|
197
268
|
return buffer.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
198
269
|
}
|
|
@@ -223,6 +294,7 @@ function toRequirement(task, description = "") {
|
|
|
223
294
|
}
|
|
224
295
|
var OnesAdapter = class extends BaseAdapter {
|
|
225
296
|
session = null;
|
|
297
|
+
issueTypesCache = null;
|
|
226
298
|
constructor(sourceType, config, resolvedAuth) {
|
|
227
299
|
super(sourceType, config, resolvedAuth);
|
|
228
300
|
}
|
|
@@ -383,6 +455,42 @@ var OnesAdapter = class extends BaseAdapter {
|
|
|
383
455
|
}
|
|
384
456
|
return response.json();
|
|
385
457
|
}
|
|
458
|
+
async fetchIssueTypes() {
|
|
459
|
+
if (this.issueTypesCache) return this.issueTypesCache;
|
|
460
|
+
this.issueTypesCache = (await this.graphql(ISSUE_TYPES_QUERY, { orderBy: { namePinyin: "ASC" } }, "issueTypes")).data?.issueTypes ?? [];
|
|
461
|
+
return this.issueTypesCache;
|
|
462
|
+
}
|
|
463
|
+
async searchTeamUsers(keyword) {
|
|
464
|
+
const session = await this.login();
|
|
465
|
+
const url = `${this.config.apiBase}/project/api/project/team/${session.teamUuid}/users/search`;
|
|
466
|
+
const response = await fetch(url, {
|
|
467
|
+
method: "POST",
|
|
468
|
+
headers: {
|
|
469
|
+
"Authorization": `Bearer ${session.accessToken}`,
|
|
470
|
+
"Content-Type": "application/json"
|
|
471
|
+
},
|
|
472
|
+
body: JSON.stringify({
|
|
473
|
+
keyword,
|
|
474
|
+
status: [1],
|
|
475
|
+
team_member_status: [1, 4],
|
|
476
|
+
types: [1, 10]
|
|
477
|
+
})
|
|
478
|
+
});
|
|
479
|
+
if (!response.ok) {
|
|
480
|
+
const text = await response.text().catch(() => "");
|
|
481
|
+
throw new Error(`ONES user search error: ${response.status} ${text}`);
|
|
482
|
+
}
|
|
483
|
+
return extractTeamUsers(await response.json());
|
|
484
|
+
}
|
|
485
|
+
async resolveAssigneeUuid(name) {
|
|
486
|
+
const trimmed = name.trim();
|
|
487
|
+
if (!trimmed) return null;
|
|
488
|
+
const users = await this.searchTeamUsers(trimmed);
|
|
489
|
+
const exactMatch = users.find((user) => user.name === trimmed);
|
|
490
|
+
if (exactMatch) return exactMatch.uuid;
|
|
491
|
+
const normalizedTarget = trimmed.toLowerCase();
|
|
492
|
+
return users.find((user) => user.name.toLowerCase().includes(normalizedTarget))?.uuid ?? null;
|
|
493
|
+
}
|
|
386
494
|
/**
|
|
387
495
|
* Fetch task info via REST API (includes description/rich fields not available in GraphQL).
|
|
388
496
|
* Reference: ones/packages/core/src/tasks.ts → fetchTaskInfo
|
|
@@ -395,6 +503,68 @@ var OnesAdapter = class extends BaseAdapter {
|
|
|
395
503
|
return response.json();
|
|
396
504
|
}
|
|
397
505
|
/**
|
|
506
|
+
* Resolve a fresh signed URL for an attachment resource via ONES attachment API.
|
|
507
|
+
* Endpoint: /project/api/project/team/{teamUuid}/res/attachment/{resourceUuid}
|
|
508
|
+
* Returns a redirect URL with a fresh OSS signature.
|
|
509
|
+
*/
|
|
510
|
+
async getAttachmentUrl(resourceUuid) {
|
|
511
|
+
const session = await this.login();
|
|
512
|
+
const url = `${this.config.apiBase}/project/api/project/team/${session.teamUuid}/res/attachment/${resourceUuid}?op=${encodeURIComponent("imageMogr2/auto-orient")}`;
|
|
513
|
+
try {
|
|
514
|
+
const manualRes = await fetch(url, {
|
|
515
|
+
headers: { Authorization: `Bearer ${session.accessToken}` },
|
|
516
|
+
redirect: "manual"
|
|
517
|
+
});
|
|
518
|
+
if (manualRes.status === 302 || manualRes.status === 301) {
|
|
519
|
+
const location = manualRes.headers.get("location");
|
|
520
|
+
if (location) return location;
|
|
521
|
+
}
|
|
522
|
+
const followRes = await fetch(url, {
|
|
523
|
+
headers: { Authorization: `Bearer ${session.accessToken}` },
|
|
524
|
+
redirect: "follow"
|
|
525
|
+
});
|
|
526
|
+
if (followRes.url && followRes.url !== url) return followRes.url;
|
|
527
|
+
if (followRes.ok) {
|
|
528
|
+
const text = await followRes.text();
|
|
529
|
+
if (text.startsWith("http")) return text.trim();
|
|
530
|
+
try {
|
|
531
|
+
return JSON.parse(text).url ?? null;
|
|
532
|
+
} catch {
|
|
533
|
+
return null;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
console.error(`[getAttachmentUrl] Failed for resource ${resourceUuid}: status ${followRes.status}`);
|
|
537
|
+
return null;
|
|
538
|
+
} catch (err) {
|
|
539
|
+
console.error(`[getAttachmentUrl] Error for resource ${resourceUuid}:`, err);
|
|
540
|
+
return null;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Replace stale image URLs in HTML with fresh signed URLs from the attachment API.
|
|
545
|
+
* Extracts data-uuid from <img> tags and resolves fresh URLs in parallel.
|
|
546
|
+
*/
|
|
547
|
+
async refreshImageUrls(html) {
|
|
548
|
+
if (!html) return html;
|
|
549
|
+
const matches = Array.from(html.matchAll(/<img\s[^>]*data-uuid="([^"]+)"[^>]*>/g));
|
|
550
|
+
if (matches.length === 0) return html;
|
|
551
|
+
const replacements = await Promise.all(matches.map(async (match) => {
|
|
552
|
+
const dataUuid = match[1];
|
|
553
|
+
const freshUrl = await this.getAttachmentUrl(dataUuid);
|
|
554
|
+
return {
|
|
555
|
+
fullMatch: match[0],
|
|
556
|
+
dataUuid,
|
|
557
|
+
freshUrl
|
|
558
|
+
};
|
|
559
|
+
}));
|
|
560
|
+
let result = html;
|
|
561
|
+
for (const { fullMatch, freshUrl } of replacements) if (freshUrl) {
|
|
562
|
+
const updatedImg = fullMatch.replace(/src="[^"]*"/, `src="${freshUrl}"`);
|
|
563
|
+
result = result.replace(fullMatch, updatedImg);
|
|
564
|
+
}
|
|
565
|
+
return result;
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
398
568
|
* Fetch wiki page content via REST API.
|
|
399
569
|
* Endpoint: /wiki/api/wiki/team/{teamUuid}/online_page/{wikiUuid}/content
|
|
400
570
|
*/
|
|
@@ -485,6 +655,27 @@ var OnesAdapter = class extends BaseAdapter {
|
|
|
485
655
|
async searchRequirements(params) {
|
|
486
656
|
const page = params.page ?? 1;
|
|
487
657
|
const pageSize = params.pageSize ?? 50;
|
|
658
|
+
const intent = parseOnesSearchIntent(params.query);
|
|
659
|
+
const assigneeName = extractNamedAssignee(params.query, intent) ?? extractAssigneeName(params.query, intent);
|
|
660
|
+
const assigneeUuid = assigneeName ? await this.resolveAssigneeUuid(assigneeName) : null;
|
|
661
|
+
if (assigneeName && !assigneeUuid) return {
|
|
662
|
+
items: [],
|
|
663
|
+
total: 0,
|
|
664
|
+
page,
|
|
665
|
+
pageSize
|
|
666
|
+
};
|
|
667
|
+
let bugTypeUuids = [];
|
|
668
|
+
let taskTypeUuids = [];
|
|
669
|
+
if (intent === "all_bugs" || intent === "all_tasks") {
|
|
670
|
+
const issueTypes = await this.fetchIssueTypes();
|
|
671
|
+
bugTypeUuids = issueTypes.filter((item) => item.detailType === 3).map((item) => item.uuid);
|
|
672
|
+
taskTypeUuids = issueTypes.filter((item) => item.detailType === 2).map((item) => item.uuid);
|
|
673
|
+
}
|
|
674
|
+
const filter = { status_notIn: DEFAULT_STATUS_NOT_IN };
|
|
675
|
+
if (assigneeName) filter.assign_in = [assigneeUuid];
|
|
676
|
+
else filter.assign_in = ["${currentUser}"];
|
|
677
|
+
if (intent === "all_bugs") filter.issueType_in = bugTypeUuids;
|
|
678
|
+
if (intent === "all_tasks") filter.issueType_in = taskTypeUuids;
|
|
488
679
|
let tasks = (await this.graphql(SEARCH_TASKS_QUERY, {
|
|
489
680
|
groupBy: { tasks: {} },
|
|
490
681
|
groupOrderBy: null,
|
|
@@ -492,10 +683,7 @@ var OnesAdapter = class extends BaseAdapter {
|
|
|
492
683
|
position: "ASC",
|
|
493
684
|
createTime: "DESC"
|
|
494
685
|
},
|
|
495
|
-
filterGroup: [
|
|
496
|
-
assign_in: ["${currentUser}"],
|
|
497
|
-
status_notIn: DEFAULT_STATUS_NOT_IN
|
|
498
|
-
}],
|
|
686
|
+
filterGroup: [filter],
|
|
499
687
|
search: null,
|
|
500
688
|
pagination: {
|
|
501
689
|
limit: pageSize * page,
|
|
@@ -503,8 +691,11 @@ var OnesAdapter = class extends BaseAdapter {
|
|
|
503
691
|
},
|
|
504
692
|
limit: 1e3
|
|
505
693
|
}, "group-task-data")).data?.buckets?.flatMap((b) => b.tasks ?? []) ?? [];
|
|
506
|
-
if (
|
|
507
|
-
|
|
694
|
+
if (intent === "all_bugs") tasks = tasks.filter((task) => task.issueType?.uuid ? bugTypeUuids.includes(task.issueType.uuid) : false).filter((task) => isOpenOrInProgressBug(task)).sort((a, b) => getBugStatusPriority(a) - getBugStatusPriority(b));
|
|
695
|
+
if (intent === "all_tasks") tasks = tasks.filter((task) => task.issueType?.uuid ? taskTypeUuids.includes(task.issueType.uuid) : false);
|
|
696
|
+
if (assigneeUuid) tasks = tasks.filter((task) => task.assign?.uuid === assigneeUuid);
|
|
697
|
+
if (intent === "keyword" && params.query) {
|
|
698
|
+
const keyword = params.query.trim();
|
|
508
699
|
const lower = keyword.toLowerCase();
|
|
509
700
|
const numMatch = keyword.match(/^#?(\d+)$/);
|
|
510
701
|
if (numMatch) tasks = tasks.filter((t) => t.number === Number.parseInt(numMatch[1], 10));
|
|
@@ -566,12 +757,17 @@ var OnesAdapter = class extends BaseAdapter {
|
|
|
566
757
|
} else issueKey = params.issueId.startsWith("task-") ? params.issueId : `task-${params.issueId}`;
|
|
567
758
|
const task = (await this.graphql(ISSUE_DETAIL_QUERY, { key: issueKey }, "Task")).data?.task;
|
|
568
759
|
if (!task) throw new Error(`ONES: Issue "${issueKey}" not found`);
|
|
760
|
+
const taskInfo = await this.fetchTaskInfo(task.uuid);
|
|
761
|
+
const rawDescription = taskInfo.desc ?? task.description ?? "";
|
|
762
|
+
const rawDescRich = taskInfo.desc_rich ?? task.desc_rich ?? "";
|
|
763
|
+
const freshDescription = await this.refreshImageUrls(rawDescription);
|
|
764
|
+
const freshDescRich = await this.refreshImageUrls(rawDescRich);
|
|
569
765
|
return {
|
|
570
766
|
key: task.key,
|
|
571
767
|
uuid: task.uuid,
|
|
572
768
|
name: task.name,
|
|
573
|
-
description:
|
|
574
|
-
descriptionRich:
|
|
769
|
+
description: freshDescription,
|
|
770
|
+
descriptionRich: freshDescRich,
|
|
575
771
|
descriptionText: task.descriptionText ?? "",
|
|
576
772
|
issueTypeName: task.issueType?.name ?? "Unknown",
|
|
577
773
|
statusName: task.status?.name ?? "Unknown",
|
|
@@ -759,15 +955,50 @@ const GetIssueDetailSchema = zod_v4.z.object({
|
|
|
759
955
|
issueId: zod_v4.z.string().describe("The issue task ID or key (e.g. \"6W9vW3y8J9DO66Pu\" or \"task-6W9vW3y8J9DO66Pu\")"),
|
|
760
956
|
source: zod_v4.z.string().optional().describe("Source to fetch from. If omitted, uses the default source.")
|
|
761
957
|
});
|
|
958
|
+
/**
|
|
959
|
+
* Download an image from URL and return as base64 data URI.
|
|
960
|
+
* Returns null if download fails.
|
|
961
|
+
*/
|
|
962
|
+
async function downloadImageAsBase64(url) {
|
|
963
|
+
try {
|
|
964
|
+
const res = await fetch(url, { redirect: "follow" });
|
|
965
|
+
if (!res.ok) return null;
|
|
966
|
+
const mimeType = (res.headers.get("content-type") ?? "image/png").split(";")[0].trim();
|
|
967
|
+
return {
|
|
968
|
+
base64: Buffer.from(await res.arrayBuffer()).toString("base64"),
|
|
969
|
+
mimeType
|
|
970
|
+
};
|
|
971
|
+
} catch {
|
|
972
|
+
return null;
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
/**
|
|
976
|
+
* Extract image URLs from HTML string.
|
|
977
|
+
*/
|
|
978
|
+
function extractImageUrls(html) {
|
|
979
|
+
return Array.from(html.matchAll(/<img[^>]+src="([^"]+)"[^>]*>/g), (m) => m[1]).map((url) => url.replace(/&/g, "&"));
|
|
980
|
+
}
|
|
762
981
|
async function handleGetIssueDetail(input, adapters, defaultSource) {
|
|
763
982
|
const sourceType = input.source ?? defaultSource;
|
|
764
983
|
if (!sourceType) throw new Error("No source specified and no default source configured");
|
|
765
984
|
const adapter = adapters.get(sourceType);
|
|
766
985
|
if (!adapter) throw new Error(`Source "${sourceType}" is not configured. Available: ${[...adapters.keys()].join(", ")}`);
|
|
767
|
-
|
|
986
|
+
const detail = await adapter.getIssueDetail({ issueId: input.issueId });
|
|
987
|
+
const imageUrls = detail.descriptionRich ? extractImageUrls(detail.descriptionRich) : [];
|
|
988
|
+
const imageResults = await Promise.all(imageUrls.map((url) => downloadImageAsBase64(url)));
|
|
989
|
+
const content = [{
|
|
768
990
|
type: "text",
|
|
769
|
-
text: formatIssueDetail(
|
|
770
|
-
}]
|
|
991
|
+
text: formatIssueDetail(detail)
|
|
992
|
+
}];
|
|
993
|
+
for (let i = 0; i < imageResults.length; i++) {
|
|
994
|
+
const img = imageResults[i];
|
|
995
|
+
if (img) content.push({
|
|
996
|
+
type: "image",
|
|
997
|
+
data: img.base64,
|
|
998
|
+
mimeType: img.mimeType
|
|
999
|
+
});
|
|
1000
|
+
}
|
|
1001
|
+
return { content };
|
|
771
1002
|
}
|
|
772
1003
|
function formatIssueDetail(detail) {
|
|
773
1004
|
const lines = [
|
|
@@ -787,14 +1018,8 @@ function formatIssueDetail(detail) {
|
|
|
787
1018
|
if (detail.sprintName) lines.push(`- **Sprint**: ${detail.sprintName}`);
|
|
788
1019
|
if (detail.deadline) lines.push(`- **Deadline**: ${detail.deadline}`);
|
|
789
1020
|
lines.push("", "## Description", "");
|
|
790
|
-
if (detail.descriptionRich)
|
|
791
|
-
|
|
792
|
-
const images = Array.from(detail.descriptionRich.matchAll(/<img[^>]+src="([^"]+)"[^>]*>/g), (m) => m[1]);
|
|
793
|
-
if (images.length > 0) {
|
|
794
|
-
lines.push("", "## Images", "");
|
|
795
|
-
for (const url of images) lines.push(`- `);
|
|
796
|
-
}
|
|
797
|
-
} else if (detail.descriptionText) lines.push(detail.descriptionText);
|
|
1021
|
+
if (detail.descriptionRich) lines.push(detail.descriptionRich);
|
|
1022
|
+
else if (detail.descriptionText) lines.push(detail.descriptionText);
|
|
798
1023
|
else lines.push("_No description_");
|
|
799
1024
|
return lines.join("\n");
|
|
800
1025
|
}
|
|
@@ -914,6 +1139,9 @@ const SearchRequirementsSchema = zod_v4.z.object({
|
|
|
914
1139
|
page: zod_v4.z.number().int().min(1).optional().describe("Page number (default: 1)"),
|
|
915
1140
|
pageSize: zod_v4.z.number().int().min(1).max(50).optional().describe("Results per page (default: 20, max: 50)")
|
|
916
1141
|
});
|
|
1142
|
+
function formatStatusMarker(status) {
|
|
1143
|
+
return `[${status.toUpperCase()}]`;
|
|
1144
|
+
}
|
|
917
1145
|
async function handleSearchRequirements(input, adapters, defaultSource) {
|
|
918
1146
|
const sourceType = input.source ?? defaultSource;
|
|
919
1147
|
if (!sourceType) throw new Error("No source specified and no default source configured");
|
|
@@ -924,15 +1152,18 @@ async function handleSearchRequirements(input, adapters, defaultSource) {
|
|
|
924
1152
|
page: input.page,
|
|
925
1153
|
pageSize: input.pageSize
|
|
926
1154
|
});
|
|
927
|
-
const lines = [`Found **${result.total}**
|
|
1155
|
+
const lines = [`Found **${result.total}** items (page ${result.page}/${Math.ceil(result.total / result.pageSize) || 1}):`, ""];
|
|
1156
|
+
if (/\u6211.*\u7F3A\u9677|bug|\u6211.*\u4EFB\u52A1/i.test(input.query)) {
|
|
1157
|
+
lines.push(`Query: ${input.query}`);
|
|
1158
|
+
lines.push("Use an item ID or number in the next step to fetch detail.");
|
|
1159
|
+
lines.push("");
|
|
1160
|
+
}
|
|
928
1161
|
for (const item of result.items) {
|
|
929
|
-
lines.push(`### ${item.id}: ${item.title}`);
|
|
1162
|
+
lines.push(`### ${formatStatusMarker(item.status)} ${item.id}: ${item.title}`);
|
|
930
1163
|
lines.push(`- Status: ${item.status} | Priority: ${item.priority} | Type: ${item.type}`);
|
|
931
1164
|
lines.push(`- Assignee: ${item.assignee ?? "Unassigned"}`);
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
lines.push(`- ${desc}`);
|
|
935
|
-
}
|
|
1165
|
+
const desc = item.description ? item.description.length > 200 ? `${item.description.slice(0, 200)}...` : item.description : "(empty)";
|
|
1166
|
+
lines.push(`- Content: ${desc}`);
|
|
936
1167
|
lines.push("");
|
|
937
1168
|
}
|
|
938
1169
|
return { content: [{
|
package/dist/index.mjs
CHANGED
|
@@ -95,7 +95,7 @@ const SEARCH_TASKS_QUERY = `
|
|
|
95
95
|
key
|
|
96
96
|
tasks(filterGroup: $filterGroup, orderBy: $orderBy, limit: $limit, includeAncestors: { pathField: "path" }) {
|
|
97
97
|
key uuid number name
|
|
98
|
-
issueType { uuid name }
|
|
98
|
+
issueType { uuid name detailType }
|
|
99
99
|
status { uuid name category }
|
|
100
100
|
priority { value }
|
|
101
101
|
assign { uuid name }
|
|
@@ -104,6 +104,15 @@ const SEARCH_TASKS_QUERY = `
|
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
`;
|
|
107
|
+
const ISSUE_TYPES_QUERY = `
|
|
108
|
+
query IssueTypes($orderBy: OrderBy) {
|
|
109
|
+
issueTypes(orderBy: $orderBy) {
|
|
110
|
+
uuid
|
|
111
|
+
name
|
|
112
|
+
detailType
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
`;
|
|
107
116
|
const TASK_BY_NUMBER_QUERY = SEARCH_TASKS_QUERY;
|
|
108
117
|
const RELATED_TASKS_QUERY = `
|
|
109
118
|
query Task($key: Key) {
|
|
@@ -165,6 +174,68 @@ const DEFAULT_STATUS_NOT_IN = [
|
|
|
165
174
|
"Dn3k8ffK",
|
|
166
175
|
"TbmY2So5"
|
|
167
176
|
];
|
|
177
|
+
function parseOnesSearchIntent(query) {
|
|
178
|
+
if (!query) return "keyword";
|
|
179
|
+
const normalized = query.toLowerCase();
|
|
180
|
+
if (query.includes("缺陷") || normalized.includes("bug")) return "all_bugs";
|
|
181
|
+
if (query.includes("任务")) return "all_tasks";
|
|
182
|
+
return "keyword";
|
|
183
|
+
}
|
|
184
|
+
function extractAssigneeName(query, intent) {
|
|
185
|
+
if (intent === "keyword") return null;
|
|
186
|
+
const trimmed = query.trim();
|
|
187
|
+
if (!trimmed) return null;
|
|
188
|
+
const ownerStyleMatch = trimmed.match(/\u8D1F\u8D23\u4EBA\u4E3A(.+?)\u7684?(?:\u7F3A\u9677|bug)$/i);
|
|
189
|
+
if (ownerStyleMatch?.[1]) return ownerStyleMatch[1].trim();
|
|
190
|
+
const candidate = trimmed.match(/^(查询)?(.+?)的(?:缺陷|bug|任务)$/i)?.[2]?.trim();
|
|
191
|
+
if (!candidate || candidate.includes("我")) return null;
|
|
192
|
+
return candidate;
|
|
193
|
+
}
|
|
194
|
+
function extractNamedAssignee(query, intent) {
|
|
195
|
+
if (intent === "keyword") return null;
|
|
196
|
+
const compact = query.replace(/\s+/g, "").trim();
|
|
197
|
+
if (!compact) return null;
|
|
198
|
+
const ownerStyleMatch = compact.match(/(?:\u8D1F\u8D23\u4EBA\u4E3A|\u8D1F\u8D23\u4EBA\u662F|\u6307\u6D3E\u7ED9|\u5206\u914D\u7ED9)(.+?)\u7684?(?:\u7F3A\u9677|bug|\u4EFB\u52A1)$/i);
|
|
199
|
+
if (ownerStyleMatch?.[1]) return ownerStyleMatch[1].trim();
|
|
200
|
+
const candidate = compact.match(/^(?:\u67E5\u8BE2|\u67E5\u627E|\u641C\u7D22)?(.+?)\u7684?(?:\u7F3A\u9677|bug|\u4EFB\u52A1)$/i)?.[1]?.trim();
|
|
201
|
+
if (!candidate || candidate.startsWith("我") || /^(?:\u6211|\u6211\u7684|\u6211\u6240\u6709|\u6211\u5168\u90E8|\u672C\u4EBA|\u5F53\u524D\u7528\u6237)$/.test(candidate)) return null;
|
|
202
|
+
return candidate;
|
|
203
|
+
}
|
|
204
|
+
function getBugStatusPriority(task) {
|
|
205
|
+
if (task.status?.category === "to_do") return 0;
|
|
206
|
+
if (task.status?.category === "in_progress") return 1;
|
|
207
|
+
return Number.POSITIVE_INFINITY;
|
|
208
|
+
}
|
|
209
|
+
function isOpenOrInProgressBug(task) {
|
|
210
|
+
const category = task.status?.category;
|
|
211
|
+
return category === "to_do" || category === "in_progress";
|
|
212
|
+
}
|
|
213
|
+
function extractTeamUsers(payload) {
|
|
214
|
+
const record = payload && typeof payload === "object" ? payload : null;
|
|
215
|
+
if (!record) return [];
|
|
216
|
+
const rawUsers = [
|
|
217
|
+
record.users,
|
|
218
|
+
record.items,
|
|
219
|
+
record.list,
|
|
220
|
+
record.results,
|
|
221
|
+
record.data?.users,
|
|
222
|
+
record.data?.items,
|
|
223
|
+
record.data?.list,
|
|
224
|
+
record.data?.results
|
|
225
|
+
].find(Array.isArray);
|
|
226
|
+
if (!rawUsers) return [];
|
|
227
|
+
return rawUsers.map((item) => {
|
|
228
|
+
const user = item && typeof item === "object" ? item : null;
|
|
229
|
+
if (!user) return null;
|
|
230
|
+
const uuid = user.uuid ?? user.user?.uuid ?? user.orgUser?.uuid ?? user.orgUserUuid ?? user.org_user_uuid ?? user.org_user?.org_user_uuid;
|
|
231
|
+
const name = user.name ?? user.user?.name ?? user.orgUser?.name ?? user.org_user?.name;
|
|
232
|
+
if (!uuid || !name) return null;
|
|
233
|
+
return {
|
|
234
|
+
uuid,
|
|
235
|
+
name
|
|
236
|
+
};
|
|
237
|
+
}).filter((item) => item !== null);
|
|
238
|
+
}
|
|
168
239
|
function base64Url(buffer) {
|
|
169
240
|
return buffer.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
170
241
|
}
|
|
@@ -195,6 +266,7 @@ function toRequirement(task, description = "") {
|
|
|
195
266
|
}
|
|
196
267
|
var OnesAdapter = class extends BaseAdapter {
|
|
197
268
|
session = null;
|
|
269
|
+
issueTypesCache = null;
|
|
198
270
|
constructor(sourceType, config, resolvedAuth) {
|
|
199
271
|
super(sourceType, config, resolvedAuth);
|
|
200
272
|
}
|
|
@@ -355,6 +427,42 @@ var OnesAdapter = class extends BaseAdapter {
|
|
|
355
427
|
}
|
|
356
428
|
return response.json();
|
|
357
429
|
}
|
|
430
|
+
async fetchIssueTypes() {
|
|
431
|
+
if (this.issueTypesCache) return this.issueTypesCache;
|
|
432
|
+
this.issueTypesCache = (await this.graphql(ISSUE_TYPES_QUERY, { orderBy: { namePinyin: "ASC" } }, "issueTypes")).data?.issueTypes ?? [];
|
|
433
|
+
return this.issueTypesCache;
|
|
434
|
+
}
|
|
435
|
+
async searchTeamUsers(keyword) {
|
|
436
|
+
const session = await this.login();
|
|
437
|
+
const url = `${this.config.apiBase}/project/api/project/team/${session.teamUuid}/users/search`;
|
|
438
|
+
const response = await fetch(url, {
|
|
439
|
+
method: "POST",
|
|
440
|
+
headers: {
|
|
441
|
+
"Authorization": `Bearer ${session.accessToken}`,
|
|
442
|
+
"Content-Type": "application/json"
|
|
443
|
+
},
|
|
444
|
+
body: JSON.stringify({
|
|
445
|
+
keyword,
|
|
446
|
+
status: [1],
|
|
447
|
+
team_member_status: [1, 4],
|
|
448
|
+
types: [1, 10]
|
|
449
|
+
})
|
|
450
|
+
});
|
|
451
|
+
if (!response.ok) {
|
|
452
|
+
const text = await response.text().catch(() => "");
|
|
453
|
+
throw new Error(`ONES user search error: ${response.status} ${text}`);
|
|
454
|
+
}
|
|
455
|
+
return extractTeamUsers(await response.json());
|
|
456
|
+
}
|
|
457
|
+
async resolveAssigneeUuid(name) {
|
|
458
|
+
const trimmed = name.trim();
|
|
459
|
+
if (!trimmed) return null;
|
|
460
|
+
const users = await this.searchTeamUsers(trimmed);
|
|
461
|
+
const exactMatch = users.find((user) => user.name === trimmed);
|
|
462
|
+
if (exactMatch) return exactMatch.uuid;
|
|
463
|
+
const normalizedTarget = trimmed.toLowerCase();
|
|
464
|
+
return users.find((user) => user.name.toLowerCase().includes(normalizedTarget))?.uuid ?? null;
|
|
465
|
+
}
|
|
358
466
|
/**
|
|
359
467
|
* Fetch task info via REST API (includes description/rich fields not available in GraphQL).
|
|
360
468
|
* Reference: ones/packages/core/src/tasks.ts → fetchTaskInfo
|
|
@@ -367,6 +475,68 @@ var OnesAdapter = class extends BaseAdapter {
|
|
|
367
475
|
return response.json();
|
|
368
476
|
}
|
|
369
477
|
/**
|
|
478
|
+
* Resolve a fresh signed URL for an attachment resource via ONES attachment API.
|
|
479
|
+
* Endpoint: /project/api/project/team/{teamUuid}/res/attachment/{resourceUuid}
|
|
480
|
+
* Returns a redirect URL with a fresh OSS signature.
|
|
481
|
+
*/
|
|
482
|
+
async getAttachmentUrl(resourceUuid) {
|
|
483
|
+
const session = await this.login();
|
|
484
|
+
const url = `${this.config.apiBase}/project/api/project/team/${session.teamUuid}/res/attachment/${resourceUuid}?op=${encodeURIComponent("imageMogr2/auto-orient")}`;
|
|
485
|
+
try {
|
|
486
|
+
const manualRes = await fetch(url, {
|
|
487
|
+
headers: { Authorization: `Bearer ${session.accessToken}` },
|
|
488
|
+
redirect: "manual"
|
|
489
|
+
});
|
|
490
|
+
if (manualRes.status === 302 || manualRes.status === 301) {
|
|
491
|
+
const location = manualRes.headers.get("location");
|
|
492
|
+
if (location) return location;
|
|
493
|
+
}
|
|
494
|
+
const followRes = await fetch(url, {
|
|
495
|
+
headers: { Authorization: `Bearer ${session.accessToken}` },
|
|
496
|
+
redirect: "follow"
|
|
497
|
+
});
|
|
498
|
+
if (followRes.url && followRes.url !== url) return followRes.url;
|
|
499
|
+
if (followRes.ok) {
|
|
500
|
+
const text = await followRes.text();
|
|
501
|
+
if (text.startsWith("http")) return text.trim();
|
|
502
|
+
try {
|
|
503
|
+
return JSON.parse(text).url ?? null;
|
|
504
|
+
} catch {
|
|
505
|
+
return null;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
console.error(`[getAttachmentUrl] Failed for resource ${resourceUuid}: status ${followRes.status}`);
|
|
509
|
+
return null;
|
|
510
|
+
} catch (err) {
|
|
511
|
+
console.error(`[getAttachmentUrl] Error for resource ${resourceUuid}:`, err);
|
|
512
|
+
return null;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Replace stale image URLs in HTML with fresh signed URLs from the attachment API.
|
|
517
|
+
* Extracts data-uuid from <img> tags and resolves fresh URLs in parallel.
|
|
518
|
+
*/
|
|
519
|
+
async refreshImageUrls(html) {
|
|
520
|
+
if (!html) return html;
|
|
521
|
+
const matches = Array.from(html.matchAll(/<img\s[^>]*data-uuid="([^"]+)"[^>]*>/g));
|
|
522
|
+
if (matches.length === 0) return html;
|
|
523
|
+
const replacements = await Promise.all(matches.map(async (match) => {
|
|
524
|
+
const dataUuid = match[1];
|
|
525
|
+
const freshUrl = await this.getAttachmentUrl(dataUuid);
|
|
526
|
+
return {
|
|
527
|
+
fullMatch: match[0],
|
|
528
|
+
dataUuid,
|
|
529
|
+
freshUrl
|
|
530
|
+
};
|
|
531
|
+
}));
|
|
532
|
+
let result = html;
|
|
533
|
+
for (const { fullMatch, freshUrl } of replacements) if (freshUrl) {
|
|
534
|
+
const updatedImg = fullMatch.replace(/src="[^"]*"/, `src="${freshUrl}"`);
|
|
535
|
+
result = result.replace(fullMatch, updatedImg);
|
|
536
|
+
}
|
|
537
|
+
return result;
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
370
540
|
* Fetch wiki page content via REST API.
|
|
371
541
|
* Endpoint: /wiki/api/wiki/team/{teamUuid}/online_page/{wikiUuid}/content
|
|
372
542
|
*/
|
|
@@ -457,6 +627,27 @@ var OnesAdapter = class extends BaseAdapter {
|
|
|
457
627
|
async searchRequirements(params) {
|
|
458
628
|
const page = params.page ?? 1;
|
|
459
629
|
const pageSize = params.pageSize ?? 50;
|
|
630
|
+
const intent = parseOnesSearchIntent(params.query);
|
|
631
|
+
const assigneeName = extractNamedAssignee(params.query, intent) ?? extractAssigneeName(params.query, intent);
|
|
632
|
+
const assigneeUuid = assigneeName ? await this.resolveAssigneeUuid(assigneeName) : null;
|
|
633
|
+
if (assigneeName && !assigneeUuid) return {
|
|
634
|
+
items: [],
|
|
635
|
+
total: 0,
|
|
636
|
+
page,
|
|
637
|
+
pageSize
|
|
638
|
+
};
|
|
639
|
+
let bugTypeUuids = [];
|
|
640
|
+
let taskTypeUuids = [];
|
|
641
|
+
if (intent === "all_bugs" || intent === "all_tasks") {
|
|
642
|
+
const issueTypes = await this.fetchIssueTypes();
|
|
643
|
+
bugTypeUuids = issueTypes.filter((item) => item.detailType === 3).map((item) => item.uuid);
|
|
644
|
+
taskTypeUuids = issueTypes.filter((item) => item.detailType === 2).map((item) => item.uuid);
|
|
645
|
+
}
|
|
646
|
+
const filter = { status_notIn: DEFAULT_STATUS_NOT_IN };
|
|
647
|
+
if (assigneeName) filter.assign_in = [assigneeUuid];
|
|
648
|
+
else filter.assign_in = ["${currentUser}"];
|
|
649
|
+
if (intent === "all_bugs") filter.issueType_in = bugTypeUuids;
|
|
650
|
+
if (intent === "all_tasks") filter.issueType_in = taskTypeUuids;
|
|
460
651
|
let tasks = (await this.graphql(SEARCH_TASKS_QUERY, {
|
|
461
652
|
groupBy: { tasks: {} },
|
|
462
653
|
groupOrderBy: null,
|
|
@@ -464,10 +655,7 @@ var OnesAdapter = class extends BaseAdapter {
|
|
|
464
655
|
position: "ASC",
|
|
465
656
|
createTime: "DESC"
|
|
466
657
|
},
|
|
467
|
-
filterGroup: [
|
|
468
|
-
assign_in: ["${currentUser}"],
|
|
469
|
-
status_notIn: DEFAULT_STATUS_NOT_IN
|
|
470
|
-
}],
|
|
658
|
+
filterGroup: [filter],
|
|
471
659
|
search: null,
|
|
472
660
|
pagination: {
|
|
473
661
|
limit: pageSize * page,
|
|
@@ -475,8 +663,11 @@ var OnesAdapter = class extends BaseAdapter {
|
|
|
475
663
|
},
|
|
476
664
|
limit: 1e3
|
|
477
665
|
}, "group-task-data")).data?.buckets?.flatMap((b) => b.tasks ?? []) ?? [];
|
|
478
|
-
if (
|
|
479
|
-
|
|
666
|
+
if (intent === "all_bugs") tasks = tasks.filter((task) => task.issueType?.uuid ? bugTypeUuids.includes(task.issueType.uuid) : false).filter((task) => isOpenOrInProgressBug(task)).sort((a, b) => getBugStatusPriority(a) - getBugStatusPriority(b));
|
|
667
|
+
if (intent === "all_tasks") tasks = tasks.filter((task) => task.issueType?.uuid ? taskTypeUuids.includes(task.issueType.uuid) : false);
|
|
668
|
+
if (assigneeUuid) tasks = tasks.filter((task) => task.assign?.uuid === assigneeUuid);
|
|
669
|
+
if (intent === "keyword" && params.query) {
|
|
670
|
+
const keyword = params.query.trim();
|
|
480
671
|
const lower = keyword.toLowerCase();
|
|
481
672
|
const numMatch = keyword.match(/^#?(\d+)$/);
|
|
482
673
|
if (numMatch) tasks = tasks.filter((t) => t.number === Number.parseInt(numMatch[1], 10));
|
|
@@ -538,12 +729,17 @@ var OnesAdapter = class extends BaseAdapter {
|
|
|
538
729
|
} else issueKey = params.issueId.startsWith("task-") ? params.issueId : `task-${params.issueId}`;
|
|
539
730
|
const task = (await this.graphql(ISSUE_DETAIL_QUERY, { key: issueKey }, "Task")).data?.task;
|
|
540
731
|
if (!task) throw new Error(`ONES: Issue "${issueKey}" not found`);
|
|
732
|
+
const taskInfo = await this.fetchTaskInfo(task.uuid);
|
|
733
|
+
const rawDescription = taskInfo.desc ?? task.description ?? "";
|
|
734
|
+
const rawDescRich = taskInfo.desc_rich ?? task.desc_rich ?? "";
|
|
735
|
+
const freshDescription = await this.refreshImageUrls(rawDescription);
|
|
736
|
+
const freshDescRich = await this.refreshImageUrls(rawDescRich);
|
|
541
737
|
return {
|
|
542
738
|
key: task.key,
|
|
543
739
|
uuid: task.uuid,
|
|
544
740
|
name: task.name,
|
|
545
|
-
description:
|
|
546
|
-
descriptionRich:
|
|
741
|
+
description: freshDescription,
|
|
742
|
+
descriptionRich: freshDescRich,
|
|
547
743
|
descriptionText: task.descriptionText ?? "",
|
|
548
744
|
issueTypeName: task.issueType?.name ?? "Unknown",
|
|
549
745
|
statusName: task.status?.name ?? "Unknown",
|
|
@@ -731,15 +927,50 @@ const GetIssueDetailSchema = z.object({
|
|
|
731
927
|
issueId: z.string().describe("The issue task ID or key (e.g. \"6W9vW3y8J9DO66Pu\" or \"task-6W9vW3y8J9DO66Pu\")"),
|
|
732
928
|
source: z.string().optional().describe("Source to fetch from. If omitted, uses the default source.")
|
|
733
929
|
});
|
|
930
|
+
/**
|
|
931
|
+
* Download an image from URL and return as base64 data URI.
|
|
932
|
+
* Returns null if download fails.
|
|
933
|
+
*/
|
|
934
|
+
async function downloadImageAsBase64(url) {
|
|
935
|
+
try {
|
|
936
|
+
const res = await fetch(url, { redirect: "follow" });
|
|
937
|
+
if (!res.ok) return null;
|
|
938
|
+
const mimeType = (res.headers.get("content-type") ?? "image/png").split(";")[0].trim();
|
|
939
|
+
return {
|
|
940
|
+
base64: Buffer.from(await res.arrayBuffer()).toString("base64"),
|
|
941
|
+
mimeType
|
|
942
|
+
};
|
|
943
|
+
} catch {
|
|
944
|
+
return null;
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
/**
|
|
948
|
+
* Extract image URLs from HTML string.
|
|
949
|
+
*/
|
|
950
|
+
function extractImageUrls(html) {
|
|
951
|
+
return Array.from(html.matchAll(/<img[^>]+src="([^"]+)"[^>]*>/g), (m) => m[1]).map((url) => url.replace(/&/g, "&"));
|
|
952
|
+
}
|
|
734
953
|
async function handleGetIssueDetail(input, adapters, defaultSource) {
|
|
735
954
|
const sourceType = input.source ?? defaultSource;
|
|
736
955
|
if (!sourceType) throw new Error("No source specified and no default source configured");
|
|
737
956
|
const adapter = adapters.get(sourceType);
|
|
738
957
|
if (!adapter) throw new Error(`Source "${sourceType}" is not configured. Available: ${[...adapters.keys()].join(", ")}`);
|
|
739
|
-
|
|
958
|
+
const detail = await adapter.getIssueDetail({ issueId: input.issueId });
|
|
959
|
+
const imageUrls = detail.descriptionRich ? extractImageUrls(detail.descriptionRich) : [];
|
|
960
|
+
const imageResults = await Promise.all(imageUrls.map((url) => downloadImageAsBase64(url)));
|
|
961
|
+
const content = [{
|
|
740
962
|
type: "text",
|
|
741
|
-
text: formatIssueDetail(
|
|
742
|
-
}]
|
|
963
|
+
text: formatIssueDetail(detail)
|
|
964
|
+
}];
|
|
965
|
+
for (let i = 0; i < imageResults.length; i++) {
|
|
966
|
+
const img = imageResults[i];
|
|
967
|
+
if (img) content.push({
|
|
968
|
+
type: "image",
|
|
969
|
+
data: img.base64,
|
|
970
|
+
mimeType: img.mimeType
|
|
971
|
+
});
|
|
972
|
+
}
|
|
973
|
+
return { content };
|
|
743
974
|
}
|
|
744
975
|
function formatIssueDetail(detail) {
|
|
745
976
|
const lines = [
|
|
@@ -759,14 +990,8 @@ function formatIssueDetail(detail) {
|
|
|
759
990
|
if (detail.sprintName) lines.push(`- **Sprint**: ${detail.sprintName}`);
|
|
760
991
|
if (detail.deadline) lines.push(`- **Deadline**: ${detail.deadline}`);
|
|
761
992
|
lines.push("", "## Description", "");
|
|
762
|
-
if (detail.descriptionRich)
|
|
763
|
-
|
|
764
|
-
const images = Array.from(detail.descriptionRich.matchAll(/<img[^>]+src="([^"]+)"[^>]*>/g), (m) => m[1]);
|
|
765
|
-
if (images.length > 0) {
|
|
766
|
-
lines.push("", "## Images", "");
|
|
767
|
-
for (const url of images) lines.push(`- `);
|
|
768
|
-
}
|
|
769
|
-
} else if (detail.descriptionText) lines.push(detail.descriptionText);
|
|
993
|
+
if (detail.descriptionRich) lines.push(detail.descriptionRich);
|
|
994
|
+
else if (detail.descriptionText) lines.push(detail.descriptionText);
|
|
770
995
|
else lines.push("_No description_");
|
|
771
996
|
return lines.join("\n");
|
|
772
997
|
}
|
|
@@ -886,6 +1111,9 @@ const SearchRequirementsSchema = z.object({
|
|
|
886
1111
|
page: z.number().int().min(1).optional().describe("Page number (default: 1)"),
|
|
887
1112
|
pageSize: z.number().int().min(1).max(50).optional().describe("Results per page (default: 20, max: 50)")
|
|
888
1113
|
});
|
|
1114
|
+
function formatStatusMarker(status) {
|
|
1115
|
+
return `[${status.toUpperCase()}]`;
|
|
1116
|
+
}
|
|
889
1117
|
async function handleSearchRequirements(input, adapters, defaultSource) {
|
|
890
1118
|
const sourceType = input.source ?? defaultSource;
|
|
891
1119
|
if (!sourceType) throw new Error("No source specified and no default source configured");
|
|
@@ -896,15 +1124,18 @@ async function handleSearchRequirements(input, adapters, defaultSource) {
|
|
|
896
1124
|
page: input.page,
|
|
897
1125
|
pageSize: input.pageSize
|
|
898
1126
|
});
|
|
899
|
-
const lines = [`Found **${result.total}**
|
|
1127
|
+
const lines = [`Found **${result.total}** items (page ${result.page}/${Math.ceil(result.total / result.pageSize) || 1}):`, ""];
|
|
1128
|
+
if (/\u6211.*\u7F3A\u9677|bug|\u6211.*\u4EFB\u52A1/i.test(input.query)) {
|
|
1129
|
+
lines.push(`Query: ${input.query}`);
|
|
1130
|
+
lines.push("Use an item ID or number in the next step to fetch detail.");
|
|
1131
|
+
lines.push("");
|
|
1132
|
+
}
|
|
900
1133
|
for (const item of result.items) {
|
|
901
|
-
lines.push(`### ${item.id}: ${item.title}`);
|
|
1134
|
+
lines.push(`### ${formatStatusMarker(item.status)} ${item.id}: ${item.title}`);
|
|
902
1135
|
lines.push(`- Status: ${item.status} | Priority: ${item.priority} | Type: ${item.type}`);
|
|
903
1136
|
lines.push(`- Assignee: ${item.assignee ?? "Unassigned"}`);
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
lines.push(`- ${desc}`);
|
|
907
|
-
}
|
|
1137
|
+
const desc = item.description ? item.description.length > 200 ? `${item.description.slice(0, 200)}...` : item.description : "(empty)";
|
|
1138
|
+
lines.push(`- Content: ${desc}`);
|
|
908
1139
|
lines.push("");
|
|
909
1140
|
}
|
|
910
1141
|
return { content: [{
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/utils/map-status.ts","../src/adapters/base.ts","../src/adapters/ones.ts","../src/adapters/index.ts","../src/config/loader.ts","../src/tools/get-issue-detail.ts","../src/tools/get-related-issues.ts","../src/tools/get-requirement.ts","../src/tools/list-sources.ts","../src/tools/search-requirements.ts","../src/index.ts"],"sourcesContent":["import type { RequirementPriority, RequirementStatus, RequirementType } from '../types/requirement.js'\n\n// --- ONES status mapping ---\nconst ONES_STATUS_MAP: Record<string, RequirementStatus> = {\n to_do: 'open',\n in_progress: 'in_progress',\n done: 'done',\n closed: 'closed',\n}\n\n// --- Priority mappings ---\nconst ONES_PRIORITY_MAP: Record<string, RequirementPriority> = {\n urgent: 'critical',\n high: 'high',\n normal: 'medium',\n medium: 'medium',\n low: 'low',\n}\n\n// --- Type mappings ---\nconst ONES_TYPE_MAP: Record<string, RequirementType> = {\n demand: 'feature',\n 需求: 'feature',\n task: 'task',\n 任务: 'task',\n bug: 'bug',\n 缺陷: 'bug',\n story: 'story',\n 子任务: 'task',\n 工单: 'task',\n 测试任务: 'task',\n}\n\nexport function mapOnesStatus(status: string): RequirementStatus {\n return ONES_STATUS_MAP[status.toLowerCase()] ?? 'open'\n}\n\nexport function mapOnesPriority(priority: string): RequirementPriority {\n return ONES_PRIORITY_MAP[priority.toLowerCase()] ?? 'medium'\n}\n\nexport function mapOnesType(type: string): RequirementType {\n return ONES_TYPE_MAP[type.toLowerCase()] ?? 'task'\n}\n","import type { SourceConfig } from '../types/config.js'\nimport type { IssueDetail, RelatedIssue, Requirement, SearchResult, SourceType } from '../types/requirement.js'\n\nexport interface GetRequirementParams {\n id: string\n}\n\nexport interface SearchRequirementsParams {\n query: string\n page?: number\n pageSize?: number\n}\n\nexport interface GetRelatedIssuesParams {\n taskId: string\n}\n\nexport interface GetIssueDetailParams {\n issueId: string\n}\n\n/**\n * Abstract base class for source adapters.\n * Each adapter implements platform-specific logic for fetching requirements.\n */\nexport abstract class BaseAdapter {\n readonly sourceType: SourceType\n protected readonly config: SourceConfig\n protected readonly resolvedAuth: Record<string, string>\n\n constructor(\n sourceType: SourceType,\n config: SourceConfig,\n resolvedAuth: Record<string, string>,\n ) {\n this.sourceType = sourceType\n this.config = config\n this.resolvedAuth = resolvedAuth\n }\n\n /**\n * Fetch a single requirement by its ID.\n */\n abstract getRequirement(params: GetRequirementParams): Promise<Requirement>\n\n /**\n * Search requirements by query string.\n */\n abstract searchRequirements(params: SearchRequirementsParams): Promise<SearchResult>\n\n abstract getRelatedIssues(params: GetRelatedIssuesParams): Promise<RelatedIssue[]>\n\n abstract getIssueDetail(params: GetIssueDetailParams): Promise<IssueDetail>\n}\n","import type { SourceConfig } from '../types/config.js'\nimport type { IssueDetail, RelatedIssue, Requirement, SearchResult, SourceType } from '../types/requirement.js'\n\nimport type { GetIssueDetailParams, GetRelatedIssuesParams, GetRequirementParams, SearchRequirementsParams } from './base.js'\nimport crypto from 'node:crypto'\nimport { mapOnesPriority, mapOnesStatus, mapOnesType } from '../utils/map-status.js'\nimport { BaseAdapter } from './base.js'\n\n// ============ ONES GraphQL types ============\n\ninterface OnesTaskNode {\n key?: string\n uuid: string\n number: number\n name: string\n status: { uuid: string, name: string, category?: string }\n priority?: { value: string }\n issueType?: { uuid: string, name: string }\n assign?: { uuid: string, name: string } | null\n owner?: { uuid: string, name: string } | null\n project?: { uuid: string, name: string }\n parent?: { uuid: string, number?: number, issueType?: { uuid: string, name: string } } | null\n relatedTasks?: OnesRelatedTask[]\n relatedWikiPages?: OnesWikiPage[]\n relatedWikiPagesCount?: number\n path?: string\n}\n\ninterface OnesWikiPage {\n uuid: string\n title: string\n referenceType?: number\n subReferenceType?: string\n errorMessage?: string\n}\n\ninterface OnesRelatedTask {\n uuid: string\n number: number\n name: string\n issueType: { uuid: string, name: string }\n status: { uuid: string, name: string, category?: string }\n assign?: { uuid: string, name: string } | null\n}\n\ninterface OnesTokenResponse {\n access_token: string\n token_type: string\n expires_in: number\n}\n\ninterface OnesLoginResponse {\n sid: string\n auth_user_uuid: string\n org_users: Array<{\n region_uuid: string\n org_uuid: string\n org_user: { org_user_uuid: string, name: string }\n org: { org_uuid: string, name: string }\n }>\n}\n\ninterface OnesSession {\n accessToken: string\n teamUuid: string\n orgUuid: string\n userUuid: string\n expiresAt: number\n}\n\n// ============ GraphQL queries ============\n\nconst TASK_DETAIL_QUERY = `\n query Task($key: Key) {\n task(key: $key) {\n key uuid number name\n issueType { uuid name }\n status { uuid name category }\n priority { value }\n assign { uuid name }\n owner { uuid name }\n project { uuid name }\n parent { uuid number issueType { uuid name } }\n relatedTasks {\n uuid number name\n issueType { uuid name }\n status { uuid name category }\n assign { uuid name }\n }\n relatedWikiPages {\n uuid\n title\n referenceType\n subReferenceType\n errorMessage\n }\n relatedWikiPagesCount\n }\n }\n`\n\nconst SEARCH_TASKS_QUERY = `\n query GROUP_TASK_DATA($groupBy: GroupBy, $groupOrderBy: OrderBy, $orderBy: OrderBy, $filterGroup: [Filter!], $search: Search, $pagination: Pagination, $limit: Int) {\n buckets(groupBy: $groupBy, orderBy: $groupOrderBy, pagination: $pagination, filter: $search) {\n key\n tasks(filterGroup: $filterGroup, orderBy: $orderBy, limit: $limit, includeAncestors: { pathField: \"path\" }) {\n key uuid number name\n issueType { uuid name }\n status { uuid name category }\n priority { value }\n assign { uuid name }\n project { uuid name }\n }\n }\n }\n`\n\n// Query to find a task by its number\nconst TASK_BY_NUMBER_QUERY = SEARCH_TASKS_QUERY\nconst RELATED_TASKS_QUERY = `\n query Task($key: Key) {\n task(key: $key) {\n key\n relatedTasks {\n key\n uuid\n name\n path\n deadline\n project { uuid name }\n priority { value }\n issueType {\n key uuid name detailType\n }\n subIssueType {\n key uuid name detailType\n }\n status {\n uuid name category\n }\n assign {\n uuid name\n }\n sprint {\n name uuid\n }\n statusCategory\n }\n }\n }\n`\n\nconst ISSUE_DETAIL_QUERY = `\n query Task($key: Key) {\n task(key: $key) {\n key uuid\n description\n descriptionText\n desc_rich: description\n name\n issueType { key uuid name detailType }\n subIssueType { key uuid name detailType }\n status { uuid name category }\n priority { value }\n assign { uuid name }\n owner { uuid name }\n solver { uuid name }\n project { uuid name }\n severityLevel { value }\n deadline(unit: ONESDATE)\n sprint { name uuid }\n }\n }\n`\n\nconst DEFAULT_STATUS_NOT_IN = ['FgMGkcaq', 'NvRwHBSo', 'Dn3k8ffK', 'TbmY2So5']\n\n// ============ Helpers ============\n\nfunction base64Url(buffer: Buffer): string {\n return buffer.toString('base64').replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/g, '')\n}\n\nfunction getSetCookies(response: Response): string[] {\n const headers = response.headers as unknown as { getSetCookie?: () => string[] }\n if (headers.getSetCookie) {\n return headers.getSetCookie()\n }\n const raw = response.headers.get('set-cookie')\n return raw ? [raw] : []\n}\n\nfunction toRequirement(task: OnesTaskNode, description = ''): Requirement {\n return {\n id: task.uuid,\n source: 'ones',\n title: `#${task.number} ${task.name}`,\n description,\n status: mapOnesStatus(task.status?.category ?? 'to_do'),\n priority: mapOnesPriority(task.priority?.value ?? 'normal'),\n type: mapOnesType(task.issueType?.name ?? '任务'),\n labels: [],\n reporter: '',\n assignee: task.assign?.name ?? null,\n // ONES GraphQL does not return timestamps; these are fetch-time placeholders\n createdAt: '',\n updatedAt: '',\n dueDate: null,\n attachments: [],\n raw: task as unknown as Record<string, unknown>,\n }\n}\n\n// ============ ONES Adapter ============\n\nexport class OnesAdapter extends BaseAdapter {\n private session: OnesSession | null = null\n\n constructor(\n sourceType: SourceType,\n config: SourceConfig,\n resolvedAuth: Record<string, string>,\n ) {\n super(sourceType, config, resolvedAuth)\n }\n\n /**\n * ONES OAuth2 PKCE login flow.\n * Reference: D:\\company code\\ones\\packages\\core\\src\\auth.ts\n */\n private async login(): Promise<OnesSession> {\n if (this.session && Date.now() < this.session.expiresAt) {\n return this.session\n }\n\n const baseUrl = this.config.apiBase\n const email = this.resolvedAuth.email\n const password = this.resolvedAuth.password\n\n if (!email || !password) {\n throw new Error('ONES auth requires email and password (ones-pkce auth type)')\n }\n\n // 1. Get encryption certificate\n const certRes = await fetch(`${baseUrl}/identity/api/encryption_cert`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: '{}',\n })\n if (!certRes.ok) {\n throw new Error(`ONES: Failed to get encryption cert: ${certRes.status}`)\n }\n const cert = (await certRes.json()) as { public_key: string }\n\n // 2. Encrypt password with RSA public key\n const encrypted = crypto.publicEncrypt(\n { key: cert.public_key, padding: crypto.constants.RSA_PKCS1_PADDING },\n Buffer.from(password, 'utf-8'),\n )\n const encryptedPassword = encrypted.toString('base64')\n\n // 3. Login\n const loginRes = await fetch(`${baseUrl}/identity/api/login`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ email, password: encryptedPassword }),\n })\n if (!loginRes.ok) {\n const text = await loginRes.text().catch(() => '')\n throw new Error(`ONES: Login failed: ${loginRes.status} ${text}`)\n }\n\n const cookies = getSetCookies(loginRes)\n .map(cookie => cookie.split(';')[0])\n .join('; ')\n const loginData = (await loginRes.json()) as OnesLoginResponse\n\n // Pick org user (first one, or match by config option)\n const orgUuid = this.config.options?.orgUuid as string | undefined\n let orgUser = loginData.org_users[0]\n if (orgUuid) {\n const match = loginData.org_users.find(u => u.org_uuid === orgUuid)\n if (match)\n orgUser = match\n }\n\n // 4. PKCE: generate code verifier + challenge\n const codeVerifier = base64Url(crypto.randomBytes(32))\n const codeChallenge = base64Url(\n crypto.createHash('sha256').update(codeVerifier).digest(),\n )\n\n // 5. Authorize\n const authorizeParams = new URLSearchParams({\n client_id: 'ones.v1',\n scope: `openid offline_access ones:org:${orgUser.region_uuid}:${orgUser.org_uuid}:${orgUser.org_user.org_user_uuid}`,\n response_type: 'code',\n code_challenge_method: 'S256',\n code_challenge: codeChallenge,\n redirect_uri: `${baseUrl}/auth/authorize/callback`,\n state: `org_uuid=${orgUser.org_uuid}`,\n })\n\n const authorizeRes = await fetch(`${baseUrl}/identity/authorize`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n 'Cookie': cookies,\n },\n body: authorizeParams.toString(),\n redirect: 'manual',\n })\n\n const authorizeLocation = authorizeRes.headers.get('location')\n if (!authorizeLocation) {\n throw new Error('ONES: Authorize response missing location header')\n }\n const authRequestId = new URL(authorizeLocation).searchParams.get('id')\n if (!authRequestId) {\n throw new Error('ONES: Cannot parse auth_request_id from authorize redirect')\n }\n\n // 6. Finalize auth request\n const finalizeRes = await fetch(`${baseUrl}/identity/api/auth_request/finalize`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json;charset=UTF-8',\n 'Cookie': cookies,\n },\n body: JSON.stringify({\n auth_request_id: authRequestId,\n region_uuid: orgUser.region_uuid,\n org_uuid: orgUser.org_uuid,\n org_user_uuid: orgUser.org_user.org_user_uuid,\n }),\n })\n if (!finalizeRes.ok) {\n const text = await finalizeRes.text().catch(() => '')\n throw new Error(`ONES: Finalize failed: ${finalizeRes.status} ${text}`)\n }\n\n // 7. Callback to get authorization code\n const callbackRes = await fetch(\n `${baseUrl}/identity/authorize/callback?id=${authRequestId}&lang=zh`,\n {\n method: 'GET',\n headers: { Cookie: cookies },\n redirect: 'manual',\n },\n )\n\n const callbackLocation = callbackRes.headers.get('location')\n if (!callbackLocation) {\n throw new Error('ONES: Callback response missing location header')\n }\n const code = new URL(callbackLocation).searchParams.get('code')\n if (!code) {\n throw new Error('ONES: Cannot parse authorization code from callback redirect')\n }\n\n // 8. Exchange code for token\n const tokenRes = await fetch(`${baseUrl}/identity/oauth/token`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n 'Cookie': cookies,\n },\n body: new URLSearchParams({\n grant_type: 'authorization_code',\n client_id: 'ones.v1',\n code,\n code_verifier: codeVerifier,\n redirect_uri: `${baseUrl}/auth/authorize/callback`,\n }).toString(),\n })\n if (!tokenRes.ok) {\n const text = await tokenRes.text().catch(() => '')\n throw new Error(`ONES: Token exchange failed: ${tokenRes.status} ${text}`)\n }\n\n const token = (await tokenRes.json()) as OnesTokenResponse\n\n // 9. Get teams to find teamUuid\n const teamsRes = await fetch(\n `${baseUrl}/project/api/project/organization/${orgUser.org_uuid}/stamps/data?t=org_my_team`,\n {\n method: 'POST',\n headers: {\n 'Authorization': `Bearer ${token.access_token}`,\n 'Content-Type': 'application/json;charset=UTF-8',\n },\n body: JSON.stringify({ org_my_team: 0 }),\n },\n )\n if (!teamsRes.ok) {\n throw new Error(`ONES: Failed to fetch teams: ${teamsRes.status}`)\n }\n\n const teamsData = (await teamsRes.json()) as {\n org_my_team?: { teams?: Array<{ uuid: string, name: string }> }\n }\n const teams = teamsData.org_my_team?.teams ?? []\n\n // Pick team by config option or default to first\n const configTeamUuid = this.config.options?.teamUuid as string | undefined\n let teamUuid = teams[0]?.uuid\n if (configTeamUuid) {\n const match = teams.find(t => t.uuid === configTeamUuid)\n if (match)\n teamUuid = match.uuid\n }\n\n if (!teamUuid) {\n throw new Error('ONES: No teams found for this user')\n }\n\n this.session = {\n accessToken: token.access_token,\n teamUuid,\n orgUuid: orgUser.org_uuid,\n userUuid: orgUser.org_user.org_user_uuid,\n expiresAt: Date.now() + (token.expires_in - 60) * 1000, // refresh 60s early\n }\n\n return this.session\n }\n\n /**\n * Execute a GraphQL query against ONES project API.\n */\n private async graphql<T>(query: string, variables: Record<string, unknown>, tag?: string): Promise<T> {\n const session = await this.login()\n const url = `${this.config.apiBase}/project/api/project/team/${session.teamUuid}/items/graphql${tag ? `?t=${encodeURIComponent(tag)}` : ''}`\n\n const response = await fetch(url, {\n method: 'POST',\n headers: {\n 'Authorization': `Bearer ${session.accessToken}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({ query, variables }),\n })\n\n if (!response.ok) {\n const text = await response.text().catch(() => '')\n throw new Error(`ONES GraphQL error: ${response.status} ${text}`)\n }\n\n return response.json() as Promise<T>\n }\n\n /**\n * Fetch task info via REST API (includes description/rich fields not available in GraphQL).\n * Reference: ones/packages/core/src/tasks.ts → fetchTaskInfo\n */\n private async fetchTaskInfo(taskUuid: string): Promise<Record<string, unknown>> {\n const session = await this.login()\n const url = `${this.config.apiBase}/project/api/project/team/${session.teamUuid}/task/${taskUuid}/info`\n\n const response = await fetch(url, {\n headers: { Authorization: `Bearer ${session.accessToken}` },\n })\n\n if (!response.ok) {\n return {}\n }\n\n return response.json() as Promise<Record<string, unknown>>\n }\n\n /**\n * Fetch wiki page content via REST API.\n * Endpoint: /wiki/api/wiki/team/{teamUuid}/online_page/{wikiUuid}/content\n */\n private async fetchWikiContent(wikiUuid: string): Promise<string> {\n const session = await this.login()\n const url = `${this.config.apiBase}/wiki/api/wiki/team/${session.teamUuid}/online_page/${wikiUuid}/content`\n\n const response = await fetch(url, {\n headers: { Authorization: `Bearer ${session.accessToken}` },\n })\n\n if (!response.ok) {\n return ''\n }\n\n const data = await response.json() as { content?: string }\n return data.content ?? ''\n }\n\n /**\n * Fetch a single task by UUID or number (e.g. \"#95945\" or \"95945\").\n * If a number is given, searches first to resolve the UUID.\n */\n async getRequirement(params: GetRequirementParams): Promise<Requirement> {\n let taskUuid = params.id\n\n // If the ID looks like a number (with or without #), search to find the UUID\n const numMatch = taskUuid.match(/^#?(\\d+)$/)\n if (numMatch) {\n const taskNumber = Number.parseInt(numMatch[1], 10)\n const searchData = await this.graphql<{\n data?: { buckets?: Array<{ tasks?: OnesTaskNode[] }> }\n }>(\n TASK_BY_NUMBER_QUERY,\n {\n groupBy: { tasks: {} },\n groupOrderBy: null,\n orderBy: { createTime: 'DESC' },\n filterGroup: [{ number_in: [taskNumber] }],\n search: null,\n pagination: { limit: 10, preciseCount: false },\n limit: 10,\n },\n 'group-task-data',\n )\n\n const allTasks = searchData.data?.buckets?.flatMap(b => b.tasks ?? []) ?? []\n const found = allTasks.find(t => t.number === taskNumber)\n\n if (!found) {\n throw new Error(`ONES: Task #${taskNumber} not found in current team`)\n }\n taskUuid = found.uuid\n }\n\n // Fetch GraphQL data (structure, relations, wiki pages)\n const graphqlData = await this.graphql<{ data?: { task?: OnesTaskNode } }>(\n TASK_DETAIL_QUERY,\n { key: `task-${taskUuid}` },\n 'Task',\n )\n\n const task = graphqlData.data?.task\n if (!task) {\n throw new Error(`ONES: Task \"${taskUuid}\" not found`)\n }\n\n // Fetch wiki page content for related requirement docs (in parallel)\n const wikiPages = task.relatedWikiPages ?? []\n const wikiContents = await Promise.all(\n wikiPages\n .filter(w => !w.errorMessage)\n .map(async (wiki) => {\n const content = await this.fetchWikiContent(wiki.uuid)\n return { title: wiki.title, uuid: wiki.uuid, content }\n }),\n )\n\n // Build description: task info + wiki requirement docs\n const parts: string[] = []\n\n // Task basic info\n parts.push(`# #${task.number} ${task.name}`)\n parts.push('')\n parts.push(`- **Type**: ${task.issueType?.name ?? 'Unknown'}`)\n parts.push(`- **Status**: ${task.status?.name ?? 'Unknown'}`)\n parts.push(`- **Assignee**: ${task.assign?.name ?? 'Unassigned'}`)\n if (task.owner?.name) {\n parts.push(`- **Owner**: ${task.owner.name}`)\n }\n if (task.project?.name) {\n parts.push(`- **Project**: ${task.project.name}`)\n }\n parts.push(`- **UUID**: ${task.uuid}`)\n\n // Related tasks\n if (task.relatedTasks?.length) {\n parts.push('')\n parts.push('## Related Tasks')\n for (const related of task.relatedTasks) {\n const assignee = related.assign?.name ?? 'Unassigned'\n parts.push(`- #${related.number} ${related.name} [${related.issueType?.name}] (${related.status?.name}) — ${assignee}`)\n }\n }\n\n // Parent task\n if (task.parent?.uuid) {\n parts.push('')\n parts.push('## Parent Task')\n parts.push(`- UUID: ${task.parent.uuid}`)\n if (task.parent.number) {\n parts.push(`- Number: #${task.parent.number}`)\n }\n }\n\n // Wiki requirement documents (the core requirement content)\n if (wikiContents.length > 0) {\n parts.push('')\n parts.push('---')\n parts.push('')\n parts.push('## Requirement Documents')\n for (const wiki of wikiContents) {\n parts.push('')\n parts.push(`### ${wiki.title}`)\n parts.push('')\n if (wiki.content) {\n parts.push(wiki.content)\n }\n else {\n parts.push('(No content available)')\n }\n }\n }\n\n const req = toRequirement(task, parts.join('\\n'))\n\n return req\n }\n\n /**\n * Search tasks assigned to current user via GraphQL.\n * Uses keyword-based local filtering (matching ONES reference implementation).\n */\n async searchRequirements(params: SearchRequirementsParams): Promise<SearchResult> {\n const page = params.page ?? 1\n const pageSize = params.pageSize ?? 50\n\n const data = await this.graphql<{\n data?: {\n buckets?: Array<{\n key: string\n tasks?: OnesTaskNode[]\n }>\n }\n }>(\n SEARCH_TASKS_QUERY,\n {\n groupBy: { tasks: {} },\n groupOrderBy: null,\n orderBy: { position: 'ASC', createTime: 'DESC' },\n filterGroup: [\n {\n assign_in: ['${currentUser}'],\n status_notIn: DEFAULT_STATUS_NOT_IN,\n },\n ],\n search: null,\n pagination: { limit: pageSize * page, preciseCount: false },\n limit: 1000,\n },\n 'group-task-data',\n )\n\n let tasks = data.data?.buckets?.flatMap(b => b.tasks ?? []) ?? []\n\n // Local keyword filter (matching ones-api.ts behavior)\n if (params.query) {\n const keyword = params.query\n const lower = keyword.toLowerCase()\n const numMatch = keyword.match(/^#?(\\d+)$/)\n\n if (numMatch) {\n tasks = tasks.filter(t => t.number === Number.parseInt(numMatch[1], 10))\n }\n else {\n tasks = tasks.filter(t => t.name.toLowerCase().includes(lower))\n }\n }\n\n // Paginate locally\n const total = tasks.length\n const start = (page - 1) * pageSize\n const paged = tasks.slice(start, start + pageSize)\n\n return {\n items: paged.map(t => toRequirement(t)),\n total,\n page,\n pageSize,\n }\n }\n\n async getRelatedIssues(params: GetRelatedIssuesParams): Promise<RelatedIssue[]> {\n const session = await this.login()\n\n const taskKey = params.taskId.startsWith('task-')\n ? params.taskId\n : `task-${params.taskId}`\n\n const data = await this.graphql<{\n data?: {\n task?: {\n key: string\n relatedTasks: Array<{\n key: string\n uuid: string\n name: string\n issueType: { key: string, uuid: string, name: string, detailType: number }\n subIssueType?: { key: string, uuid: string, name: string, detailType: number } | null\n status: { uuid: string, name: string, category: string }\n assign?: { uuid: string, name: string } | null\n priority?: { value: string } | null\n project?: { uuid: string, name: string } | null\n }>\n }\n }\n }>(RELATED_TASKS_QUERY, { key: taskKey }, 'Task')\n\n const relatedTasks = data.data?.task?.relatedTasks ?? []\n\n // Filter: detailType === 3 (defect) + status.category === \"to_do\" (pending)\n // Returns ALL pending defects, not just current user's\n const filtered = relatedTasks.filter((t) => {\n const isDefect = t.issueType?.detailType === 3\n || t.subIssueType?.detailType === 3\n const isTodo = t.status?.category === 'to_do'\n return isDefect && isTodo\n })\n\n // Sort: current user's defects first\n const currentUserUuid = session.userUuid\n filtered.sort((a, b) => {\n const aIsCurrent = a.assign?.uuid === currentUserUuid ? 0 : 1\n const bIsCurrent = b.assign?.uuid === currentUserUuid ? 0 : 1\n return aIsCurrent - bIsCurrent\n })\n\n return filtered.map(t => ({\n key: t.key,\n uuid: t.uuid,\n name: t.name,\n issueTypeName: t.issueType?.name ?? 'Unknown',\n statusName: t.status?.name ?? 'Unknown',\n statusCategory: t.status?.category ?? 'unknown',\n assignName: t.assign?.name ?? null,\n assignUuid: t.assign?.uuid ?? null,\n priorityValue: t.priority?.value ?? null,\n projectName: t.project?.name ?? null,\n }))\n }\n\n async getIssueDetail(params: GetIssueDetailParams): Promise<IssueDetail> {\n let issueKey: string\n\n // Support number lookup (e.g. \"98086\" or \"#98086\")\n const numMatch = params.issueId.match(/^#?(\\d+)$/)\n if (numMatch) {\n const taskNumber = Number.parseInt(numMatch[1], 10)\n const searchData = await this.graphql<{\n data?: { buckets?: Array<{ tasks?: Array<{ uuid: string, number: number }> }> }\n }>(\n SEARCH_TASKS_QUERY,\n {\n groupBy: { tasks: {} },\n groupOrderBy: null,\n orderBy: { createTime: 'DESC' },\n filterGroup: [{ number_in: [taskNumber] }],\n search: null,\n pagination: { limit: 10, preciseCount: false },\n limit: 10,\n },\n 'group-task-data',\n )\n\n const allTasks = searchData.data?.buckets?.flatMap(b => b.tasks ?? []) ?? []\n const found = allTasks.find(t => t.number === taskNumber)\n if (!found) {\n throw new Error(`ONES: Issue #${taskNumber} not found in current team`)\n }\n issueKey = `task-${found.uuid}`\n }\n else {\n issueKey = params.issueId.startsWith('task-')\n ? params.issueId\n : `task-${params.issueId}`\n }\n\n const data = await this.graphql<{\n data?: {\n task?: {\n key: string\n uuid: string\n name: string\n description: string\n descriptionText: string\n desc_rich: string\n issueType: { name: string }\n status: { name: string, category: string }\n priority?: { value: string } | null\n assign?: { uuid: string, name: string } | null\n owner?: { uuid: string, name: string } | null\n solver?: { uuid: string, name: string } | null\n project?: { uuid: string, name: string } | null\n severityLevel?: { value: string } | null\n deadline?: string | null\n sprint?: { name: string } | null\n }\n }\n }>(ISSUE_DETAIL_QUERY, { key: issueKey }, 'Task')\n\n const task = data.data?.task\n if (!task) {\n throw new Error(`ONES: Issue \"${issueKey}\" not found`)\n }\n\n return {\n key: task.key,\n uuid: task.uuid,\n name: task.name,\n description: task.description ?? '',\n descriptionRich: task.desc_rich ?? '',\n descriptionText: task.descriptionText ?? '',\n issueTypeName: task.issueType?.name ?? 'Unknown',\n statusName: task.status?.name ?? 'Unknown',\n statusCategory: task.status?.category ?? 'unknown',\n assignName: task.assign?.name ?? null,\n ownerName: task.owner?.name ?? null,\n solverName: task.solver?.name ?? null,\n priorityValue: task.priority?.value ?? null,\n severityLevel: task.severityLevel?.value ?? null,\n projectName: task.project?.name ?? null,\n deadline: task.deadline ?? null,\n sprintName: task.sprint?.name ?? null,\n raw: task as unknown as Record<string, unknown>,\n }\n }\n}\n","import type { SourceConfig } from '../types/config.js'\nimport type { SourceType } from '../types/requirement.js'\nimport type { BaseAdapter } from './base.js'\nimport { OnesAdapter } from './ones.js'\n\nconst ADAPTER_MAP: Record<string, new (\n sourceType: SourceType,\n config: SourceConfig,\n resolvedAuth: Record<string, string>,\n) => BaseAdapter> = {\n ones: OnesAdapter,\n}\n\n/**\n * Factory function to create the appropriate adapter based on source type.\n */\nexport function createAdapter(\n sourceType: SourceType,\n config: SourceConfig,\n resolvedAuth: Record<string, string>,\n): BaseAdapter {\n const AdapterClass = ADAPTER_MAP[sourceType]\n if (!AdapterClass) {\n throw new Error(\n `Unsupported source type: \"${sourceType}\". Supported: ${Object.keys(ADAPTER_MAP).join(', ')}`,\n )\n }\n return new AdapterClass(sourceType, config, resolvedAuth)\n}\n\nexport { BaseAdapter } from './base.js'\nexport { OnesAdapter } from './ones.js'\n","import type { AuthConfig } from '../types/auth.js'\nimport type { McpConfig, SourceConfig } from '../types/config.js'\nimport type { SourceType } from '../types/requirement.js'\nimport { existsSync, readFileSync } from 'node:fs'\nimport { dirname, resolve } from 'node:path'\nimport { z } from 'zod/v4'\n\nconst AuthSchema = z.discriminatedUnion('type', [\n z.object({\n type: z.literal('token'),\n tokenEnv: z.string(),\n }),\n z.object({\n type: z.literal('basic'),\n usernameEnv: z.string(),\n passwordEnv: z.string(),\n }),\n z.object({\n type: z.literal('oauth2'),\n clientIdEnv: z.string(),\n clientSecretEnv: z.string(),\n tokenUrl: z.string().url(),\n }),\n z.object({\n type: z.literal('cookie'),\n cookieEnv: z.string(),\n }),\n z.object({\n type: z.literal('custom'),\n headerName: z.string(),\n valueEnv: z.string(),\n }),\n z.object({\n type: z.literal('ones-pkce'),\n emailEnv: z.string(),\n passwordEnv: z.string(),\n }),\n])\n\nconst SourceConfigSchema = z.object({\n enabled: z.boolean(),\n apiBase: z.string().url(),\n auth: AuthSchema,\n headers: z.record(z.string(), z.string()).optional(),\n options: z.record(z.string(), z.unknown()).optional(),\n})\n\nconst SourcesSchema = z.object({\n ones: SourceConfigSchema.optional(),\n})\n\nconst McpConfigSchema = z.object({\n sources: SourcesSchema,\n defaultSource: z.enum(['ones']).optional(),\n})\n\nconst CONFIG_FILENAME = '.requirements-mcp.json'\n\n/**\n * Search for config file starting from `startDir` and walking up to the root.\n */\nfunction findConfigFile(startDir: string): string | null {\n let dir = resolve(startDir)\n while (true) {\n const candidate = resolve(dir, CONFIG_FILENAME)\n if (existsSync(candidate)) {\n return candidate\n }\n const parent = dirname(dir)\n if (parent === dir)\n break\n dir = parent\n }\n return null\n}\n\n/**\n * Resolve environment variable references in auth config.\n * Reads actual env var values for fields ending with \"Env\".\n */\nfunction resolveAuthEnv(auth: AuthConfig): Record<string, string> {\n const resolved: Record<string, string> = {}\n\n for (const [key, value] of Object.entries(auth)) {\n if (key === 'type')\n continue\n if (key.endsWith('Env') && typeof value === 'string') {\n const envValue = process.env[value]\n if (!envValue) {\n throw new Error(`Environment variable \"${value}\" is not set (required by auth.${key})`)\n }\n // Strip the \"Env\" suffix for the resolved key\n const resolvedKey = key.slice(0, -3)\n resolved[resolvedKey] = envValue\n }\n else if (typeof value === 'string') {\n resolved[key] = value\n }\n }\n\n return resolved\n}\n\nexport interface ResolvedSource {\n type: SourceType\n config: SourceConfig\n resolvedAuth: Record<string, string>\n}\n\nexport interface LoadConfigResult {\n config: McpConfig\n sources: ResolvedSource[]\n configPath: string\n}\n\n/**\n * Try to build config purely from environment variables.\n * Required env vars: ONES_API_BASE, ONES_ACCOUNT, ONES_PASSWORD\n * Returns null if the required env vars are not all present.\n */\nfunction loadConfigFromEnv(): McpConfig | null {\n const apiBase = process.env.ONES_API_BASE\n const account = process.env.ONES_ACCOUNT\n const password = process.env.ONES_PASSWORD\n\n if (!apiBase || !account || !password) {\n return null\n }\n\n return {\n sources: {\n ones: {\n enabled: true,\n apiBase,\n auth: {\n type: 'ones-pkce',\n emailEnv: 'ONES_ACCOUNT',\n passwordEnv: 'ONES_PASSWORD',\n },\n },\n },\n defaultSource: 'ones',\n }\n}\n\n/**\n * Load and validate the MCP config.\n * Priority: env vars (ONES_API_BASE + ONES_ACCOUNT + ONES_PASSWORD) > config file (.requirements-mcp.json).\n * Searches from `startDir` (defaults to cwd) upward for the file.\n */\nexport function loadConfig(startDir?: string): LoadConfigResult {\n // 1. Try environment variables first (simplest setup for MCP)\n const envConfig = loadConfigFromEnv()\n if (envConfig) {\n const sources: ResolvedSource[] = []\n for (const [type, sourceConfig] of Object.entries(envConfig.sources)) {\n if (sourceConfig && sourceConfig.enabled) {\n const resolvedAuth = resolveAuthEnv(sourceConfig.auth)\n sources.push({\n type: type as SourceType,\n config: sourceConfig,\n resolvedAuth,\n })\n }\n }\n return { config: envConfig, sources, configPath: 'env' }\n }\n\n // 2. Fall back to config file\n const dir = startDir ?? process.cwd()\n const configPath = findConfigFile(dir)\n\n if (!configPath) {\n throw new Error(\n `Config not found. Either set env vars (ONES_API_BASE, ONES_ACCOUNT, ONES_PASSWORD) `\n + `or create \"${CONFIG_FILENAME}\" based on .requirements-mcp.json.example`,\n )\n }\n\n const raw = readFileSync(configPath, 'utf-8')\n let parsed: unknown\n try {\n parsed = JSON.parse(raw)\n }\n catch {\n throw new Error(`Invalid JSON in ${configPath}`)\n }\n\n const result = McpConfigSchema.safeParse(parsed)\n if (!result.success) {\n throw new Error(\n `Invalid config in ${configPath}:\\n${result.error.issues.map(i => ` - ${i.path.join('.')}: ${i.message}`).join('\\n')}`,\n )\n }\n\n const config = result.data as McpConfig\n\n // Resolve enabled sources\n const sources: ResolvedSource[] = []\n for (const [type, sourceConfig] of Object.entries(config.sources)) {\n if (sourceConfig && sourceConfig.enabled) {\n const resolvedAuth = resolveAuthEnv(sourceConfig.auth)\n sources.push({\n type: type as SourceType,\n config: sourceConfig,\n resolvedAuth,\n })\n }\n }\n\n if (sources.length === 0) {\n throw new Error('No enabled sources found in config. Enable at least one source.')\n }\n\n return { config, sources, configPath }\n}\n\nexport { findConfigFile, loadConfigFromEnv, resolveAuthEnv }\n","import type { BaseAdapter } from '../adapters/base.js'\nimport type { IssueDetail } from '../types/requirement.js'\nimport { z } from 'zod/v4'\n\nexport const GetIssueDetailSchema = z.object({\n issueId: z.string().describe('The issue task ID or key (e.g. \"6W9vW3y8J9DO66Pu\" or \"task-6W9vW3y8J9DO66Pu\")'),\n source: z.string().optional().describe('Source to fetch from. If omitted, uses the default source.'),\n})\n\nexport type GetIssueDetailInput = z.infer<typeof GetIssueDetailSchema>\n\nexport async function handleGetIssueDetail(\n input: GetIssueDetailInput,\n adapters: Map<string, BaseAdapter>,\n defaultSource?: string,\n) {\n const sourceType = input.source ?? defaultSource\n if (!sourceType) {\n throw new Error('No source specified and no default source configured')\n }\n\n const adapter = adapters.get(sourceType)\n if (!adapter) {\n throw new Error(\n `Source \"${sourceType}\" is not configured. Available: ${[...adapters.keys()].join(', ')}`,\n )\n }\n\n const detail = await adapter.getIssueDetail({ issueId: input.issueId })\n\n return {\n content: [{ type: 'text' as const, text: formatIssueDetail(detail) }],\n }\n}\n\nfunction formatIssueDetail(detail: IssueDetail): string {\n const lines = [\n `# ${detail.name}`,\n '',\n `- **Key**: ${detail.key}`,\n `- **UUID**: ${detail.uuid}`,\n `- **Type**: ${detail.issueTypeName}`,\n `- **Status**: ${detail.statusName} (${detail.statusCategory})`,\n `- **Priority**: ${detail.priorityValue ?? 'N/A'}`,\n `- **Severity**: ${detail.severityLevel ?? 'N/A'}`,\n `- **Assignee**: ${detail.assignName ?? 'Unassigned'}`,\n `- **Owner**: ${detail.ownerName ?? 'Unknown'}`,\n `- **Solver**: ${detail.solverName ?? 'Unassigned'}`,\n ]\n\n if (detail.projectName)\n lines.push(`- **Project**: ${detail.projectName}`)\n if (detail.sprintName)\n lines.push(`- **Sprint**: ${detail.sprintName}`)\n if (detail.deadline)\n lines.push(`- **Deadline**: ${detail.deadline}`)\n\n lines.push('', '## Description', '')\n if (detail.descriptionRich) {\n lines.push(detail.descriptionRich)\n\n // Extract image URLs from rich text\n const imgRegex = /<img[^>]+src=\"([^\"]+)\"[^>]*>/g\n const images = Array.from(detail.descriptionRich.matchAll(imgRegex), m => m[1])\n if (images.length > 0) {\n lines.push('', '## Images', '')\n for (const url of images) {\n lines.push(`- `)\n }\n }\n }\n else if (detail.descriptionText) {\n lines.push(detail.descriptionText)\n }\n else {\n lines.push('_No description_')\n }\n\n return lines.join('\\n')\n}\n","import type { BaseAdapter } from '../adapters/base.js'\nimport type { RelatedIssue } from '../types/requirement.js'\nimport { z } from 'zod/v4'\n\nexport const GetRelatedIssuesSchema = z.object({\n taskId: z.string().describe('The parent task ID or key (e.g. \"HRL2p8rTX4mQ9xMv\" or \"task-HRL2p8rTX4mQ9xMv\")'),\n source: z.string().optional().describe('Source to fetch from. If omitted, uses the default source.'),\n})\n\nexport type GetRelatedIssuesInput = z.infer<typeof GetRelatedIssuesSchema>\n\nexport async function handleGetRelatedIssues(\n input: GetRelatedIssuesInput,\n adapters: Map<string, BaseAdapter>,\n defaultSource?: string,\n) {\n const sourceType = input.source ?? defaultSource\n if (!sourceType) {\n throw new Error('No source specified and no default source configured')\n }\n\n const adapter = adapters.get(sourceType)\n if (!adapter) {\n throw new Error(\n `Source \"${sourceType}\" is not configured. Available: ${[...adapters.keys()].join(', ')}`,\n )\n }\n\n const issues = await adapter.getRelatedIssues({ taskId: input.taskId })\n\n return {\n content: [{ type: 'text' as const, text: formatRelatedIssues(issues) }],\n }\n}\n\nfunction formatRelatedIssues(issues: RelatedIssue[]): string {\n const lines = [\n `Found **${issues.length}** pending defects:`,\n '',\n ]\n\n if (issues.length === 0) {\n lines.push('No pending defects found for this task.')\n return lines.join('\\n')\n }\n\n // Group by assignee name\n const grouped = new Map<string, RelatedIssue[]>()\n for (const issue of issues) {\n const assignee = issue.assignName ?? 'Unassigned'\n if (!grouped.has(assignee))\n grouped.set(assignee, [])\n grouped.get(assignee)!.push(issue)\n }\n\n for (const [assignee, group] of grouped) {\n lines.push(`## ${assignee} (${group.length})`)\n lines.push('')\n for (const issue of group) {\n lines.push(`### ${issue.key}: ${issue.name}`)\n lines.push(`- Status: ${issue.statusName} | Priority: ${issue.priorityValue ?? 'N/A'}`)\n if (issue.projectName) {\n lines.push(`- Project: ${issue.projectName}`)\n }\n lines.push('')\n }\n }\n\n return lines.join('\\n')\n}\n","import type { BaseAdapter } from '../adapters/base.js'\nimport { z } from 'zod/v4'\n\nexport const GetRequirementSchema = z.object({\n id: z.string().describe('The requirement/issue ID'),\n source: z.string().optional().describe('Source to fetch from. If omitted, uses the default source.'),\n})\n\nexport type GetRequirementInput = z.infer<typeof GetRequirementSchema>\n\nexport async function handleGetRequirement(\n input: GetRequirementInput,\n adapters: Map<string, BaseAdapter>,\n defaultSource?: string,\n) {\n const sourceType = input.source ?? defaultSource\n if (!sourceType) {\n throw new Error('No source specified and no default source configured')\n }\n\n const adapter = adapters.get(sourceType)\n if (!adapter) {\n throw new Error(\n `Source \"${sourceType}\" is not configured. Available: ${[...adapters.keys()].join(', ')}`,\n )\n }\n\n const requirement = await adapter.getRequirement({ id: input.id })\n\n return {\n content: [\n {\n type: 'text' as const,\n text: formatRequirement(requirement),\n },\n ],\n }\n}\n\nfunction formatRequirement(req: import('../types/requirement.js').Requirement): string {\n const lines = [\n `# ${req.title}`,\n '',\n `- **ID**: ${req.id}`,\n `- **Source**: ${req.source}`,\n `- **Status**: ${req.status}`,\n `- **Priority**: ${req.priority}`,\n `- **Type**: ${req.type}`,\n `- **Assignee**: ${req.assignee ?? 'Unassigned'}`,\n `- **Reporter**: ${req.reporter || 'Unknown'}`,\n ]\n\n if (req.createdAt) {\n lines.push(`- **Created**: ${req.createdAt}`)\n }\n if (req.updatedAt) {\n lines.push(`- **Updated**: ${req.updatedAt}`)\n }\n\n if (req.dueDate) {\n lines.push(`- **Due**: ${req.dueDate}`)\n }\n\n if (req.labels.length > 0) {\n lines.push(`- **Labels**: ${req.labels.join(', ')}`)\n }\n\n lines.push('', '## Description', '', req.description || '_No description_')\n\n if (req.attachments.length > 0) {\n lines.push('', '## Attachments')\n for (const att of req.attachments) {\n lines.push(`- [${att.name}](${att.url}) (${att.mimeType}, ${att.size} bytes)`)\n }\n }\n\n return lines.join('\\n')\n}\n","import type { BaseAdapter } from '../adapters/base.js'\nimport type { McpConfig } from '../types/config.js'\n\nexport async function handleListSources(\n adapters: Map<string, BaseAdapter>,\n config: McpConfig,\n) {\n const lines = ['# Configured Sources', '']\n\n if (adapters.size === 0) {\n lines.push('No sources configured.')\n return {\n content: [{ type: 'text' as const, text: lines.join('\\n') }],\n }\n }\n\n for (const [type, adapter] of adapters) {\n const isDefault = config.defaultSource === type\n const sourceConfig = config.sources[adapter.sourceType]\n lines.push(`## ${type}${isDefault ? ' (default)' : ''}`)\n lines.push(`- **API Base**: ${sourceConfig?.apiBase ?? 'N/A'}`)\n lines.push(`- **Auth Type**: ${sourceConfig?.auth.type ?? 'N/A'}`)\n lines.push('')\n }\n\n if (config.defaultSource) {\n lines.push(`> Default source: **${config.defaultSource}**`)\n }\n\n return {\n content: [{ type: 'text' as const, text: lines.join('\\n') }],\n }\n}\n","import type { BaseAdapter } from '../adapters/base.js'\nimport { z } from 'zod/v4'\n\nexport const SearchRequirementsSchema = z.object({\n query: z.string().describe('Search keywords'),\n source: z.string().optional().describe('Source to search. If omitted, searches the default source.'),\n page: z.number().int().min(1).optional().describe('Page number (default: 1)'),\n pageSize: z.number().int().min(1).max(50).optional().describe('Results per page (default: 20, max: 50)'),\n})\n\nexport type SearchRequirementsInput = z.infer<typeof SearchRequirementsSchema>\n\nexport async function handleSearchRequirements(\n input: SearchRequirementsInput,\n adapters: Map<string, BaseAdapter>,\n defaultSource?: string,\n) {\n const sourceType = input.source ?? defaultSource\n if (!sourceType) {\n throw new Error('No source specified and no default source configured')\n }\n\n const adapter = adapters.get(sourceType)\n if (!adapter) {\n throw new Error(\n `Source \"${sourceType}\" is not configured. Available: ${[...adapters.keys()].join(', ')}`,\n )\n }\n\n const result = await adapter.searchRequirements({\n query: input.query,\n page: input.page,\n pageSize: input.pageSize,\n })\n\n const lines = [\n `Found **${result.total}** results (page ${result.page}/${Math.ceil(result.total / result.pageSize) || 1}):`,\n '',\n ]\n\n for (const item of result.items) {\n lines.push(`### ${item.id}: ${item.title}`)\n lines.push(`- Status: ${item.status} | Priority: ${item.priority} | Type: ${item.type}`)\n lines.push(`- Assignee: ${item.assignee ?? 'Unassigned'}`)\n if (item.description) {\n const desc = item.description.length > 200\n ? `${item.description.slice(0, 200)}...`\n : item.description\n lines.push(`- ${desc}`)\n }\n lines.push('')\n }\n\n return {\n content: [\n {\n type: 'text' as const,\n text: lines.join('\\n'),\n },\n ],\n }\n}\n","import type { BaseAdapter } from './adapters/index.js'\nimport type { LoadConfigResult } from './config/loader.js'\nimport { existsSync, readFileSync } from 'node:fs'\nimport { dirname, resolve } from 'node:path'\nimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'\nimport { createAdapter } from './adapters/index.js'\nimport { loadConfig } from './config/loader.js'\nimport { GetIssueDetailSchema, handleGetIssueDetail } from './tools/get-issue-detail.js'\nimport { GetRelatedIssuesSchema, handleGetRelatedIssues } from './tools/get-related-issues.js'\nimport { GetRequirementSchema, handleGetRequirement } from './tools/get-requirement.js'\nimport { handleListSources } from './tools/list-sources.js'\nimport { handleSearchRequirements, SearchRequirementsSchema } from './tools/search-requirements.js'\n\n/**\n * Load .env file into process.env (if it exists).\n * Searches from cwd upward, same as config loader.\n */\nfunction loadEnvFile() {\n let dir = process.cwd()\n while (true) {\n const envPath = resolve(dir, '.env')\n if (existsSync(envPath)) {\n const content = readFileSync(envPath, 'utf-8')\n for (const line of content.split('\\n')) {\n const trimmed = line.trim()\n if (!trimmed || trimmed.startsWith('#'))\n continue\n const eqIndex = trimmed.indexOf('=')\n if (eqIndex === -1)\n continue\n const key = trimmed.slice(0, eqIndex).trim()\n let value = trimmed.slice(eqIndex + 1).trim()\n // Strip surrounding quotes\n if ((value.startsWith('\"') && value.endsWith('\"')) || (value.startsWith('\\'') && value.endsWith('\\''))) {\n value = value.slice(1, -1)\n }\n if (!process.env[key]) {\n process.env[key] = value\n }\n }\n return\n }\n const parent = dirname(dir)\n if (parent === dir)\n break\n dir = parent\n }\n}\n\nasync function main() {\n // Load .env before anything else\n loadEnvFile()\n\n // Load config\n let config: LoadConfigResult\n try {\n config = loadConfig()\n }\n catch (err) {\n console.error(`[requirements-mcp] ${(err as Error).message}`)\n process.exit(1)\n }\n\n // Create adapters for enabled sources\n const adapters = new Map<string, BaseAdapter>()\n for (const source of config.sources) {\n const adapter = createAdapter(source.type, source.config, source.resolvedAuth)\n adapters.set(source.type, adapter)\n }\n\n // Create MCP server\n const server = new McpServer({\n name: 'ai-dev-requirements',\n version: '0.1.0',\n })\n\n // Register tools\n server.tool(\n 'get_requirement',\n 'Fetch a single requirement/issue by its ID from a configured source (ONES)',\n GetRequirementSchema.shape,\n async (params) => {\n try {\n return await handleGetRequirement(params, adapters, config.config.defaultSource)\n }\n catch (err) {\n return {\n content: [{ type: 'text', text: `Error: ${(err as Error).message}` }],\n isError: true,\n }\n }\n },\n )\n\n server.tool(\n 'search_requirements',\n 'Search for requirements/issues by keywords across a configured source',\n SearchRequirementsSchema.shape,\n async (params) => {\n try {\n return await handleSearchRequirements(params, adapters, config.config.defaultSource)\n }\n catch (err) {\n return {\n content: [{ type: 'text', text: `Error: ${(err as Error).message}` }],\n isError: true,\n }\n }\n },\n )\n\n server.tool(\n 'list_sources',\n 'List all configured requirement sources and their status',\n {},\n async () => {\n try {\n return await handleListSources(adapters, config.config)\n }\n catch (err) {\n return {\n content: [{ type: 'text', text: `Error: ${(err as Error).message}` }],\n isError: true,\n }\n }\n },\n )\n\n server.tool(\n 'get_related_issues',\n 'Get pending defect issues (bugs) related to a requirement task. Returns all pending defects grouped by assignee (current user first).',\n GetRelatedIssuesSchema.shape,\n async (params) => {\n try {\n return await handleGetRelatedIssues(params, adapters, config.config.defaultSource)\n }\n catch (err) {\n return {\n content: [{ type: 'text', text: `Error: ${(err as Error).message}` }],\n isError: true,\n }\n }\n },\n )\n\n server.tool(\n 'get_issue_detail',\n 'Get detailed information about a specific issue/defect including description, rich text, and images',\n GetIssueDetailSchema.shape,\n async (params) => {\n try {\n return await handleGetIssueDetail(params, adapters, config.config.defaultSource)\n }\n catch (err) {\n return {\n content: [{ type: 'text', text: `Error: ${(err as Error).message}` }],\n isError: true,\n }\n }\n },\n )\n\n // Start stdio transport\n const transport = new StdioServerTransport()\n await server.connect(transport)\n}\n\nmain().catch((err) => {\n console.error('[requirements-mcp] Fatal error:', err)\n process.exit(1)\n})\n"],"mappings":";;;;;;;;;AAGA,MAAM,kBAAqD;CACzD,OAAO;CACP,aAAa;CACb,MAAM;CACN,QAAQ;CACT;AAGD,MAAM,oBAAyD;CAC7D,QAAQ;CACR,MAAM;CACN,QAAQ;CACR,QAAQ;CACR,KAAK;CACN;AAGD,MAAM,gBAAiD;CACrD,QAAQ;CACR,IAAI;CACJ,MAAM;CACN,IAAI;CACJ,KAAK;CACL,IAAI;CACJ,OAAO;CACP,KAAK;CACL,IAAI;CACJ,MAAM;CACP;AAED,SAAgB,cAAc,QAAmC;AAC/D,QAAO,gBAAgB,OAAO,aAAa,KAAK;;AAGlD,SAAgB,gBAAgB,UAAuC;AACrE,QAAO,kBAAkB,SAAS,aAAa,KAAK;;AAGtD,SAAgB,YAAY,MAA+B;AACzD,QAAO,cAAc,KAAK,aAAa,KAAK;;;;;;;;;ACjB9C,IAAsB,cAAtB,MAAkC;CAChC,AAAS;CACT,AAAmB;CACnB,AAAmB;CAEnB,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AQ,MAAM,UAAW,IAAc;KAAW,CAAC;IACrE,SAAS;IACV;;GAGN;CAGD,MAAM,YAAY,IAAI,sBAAsB;AAC5C,OAAM,OAAO,QAAQ,UAAU;;AAGjC,MAAM,CAAC,OAAO,QAAQ;AACpB,SAAQ,MAAM,mCAAmC,IAAI;AACrD,SAAQ,KAAK,EAAE;EACf"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/utils/map-status.ts","../src/adapters/base.ts","../src/adapters/ones.ts","../src/adapters/index.ts","../src/config/loader.ts","../src/tools/get-issue-detail.ts","../src/tools/get-related-issues.ts","../src/tools/get-requirement.ts","../src/tools/list-sources.ts","../src/tools/search-requirements.ts","../src/index.ts"],"sourcesContent":["import type { RequirementPriority, RequirementStatus, RequirementType } from '../types/requirement.js'\n\n// --- ONES status mapping ---\nconst ONES_STATUS_MAP: Record<string, RequirementStatus> = {\n to_do: 'open',\n in_progress: 'in_progress',\n done: 'done',\n closed: 'closed',\n}\n\n// --- Priority mappings ---\nconst ONES_PRIORITY_MAP: Record<string, RequirementPriority> = {\n urgent: 'critical',\n high: 'high',\n normal: 'medium',\n medium: 'medium',\n low: 'low',\n}\n\n// --- Type mappings ---\nconst ONES_TYPE_MAP: Record<string, RequirementType> = {\n demand: 'feature',\n 需求: 'feature',\n task: 'task',\n 任务: 'task',\n bug: 'bug',\n 缺陷: 'bug',\n story: 'story',\n 子任务: 'task',\n 工单: 'task',\n 测试任务: 'task',\n}\n\nexport function mapOnesStatus(status: string): RequirementStatus {\n return ONES_STATUS_MAP[status.toLowerCase()] ?? 'open'\n}\n\nexport function mapOnesPriority(priority: string): RequirementPriority {\n return ONES_PRIORITY_MAP[priority.toLowerCase()] ?? 'medium'\n}\n\nexport function mapOnesType(type: string): RequirementType {\n return ONES_TYPE_MAP[type.toLowerCase()] ?? 'task'\n}\n","import type { SourceConfig } from '../types/config.js'\nimport type { IssueDetail, RelatedIssue, Requirement, SearchResult, SourceType } from '../types/requirement.js'\n\nexport interface GetRequirementParams {\n id: string\n}\n\nexport interface SearchRequirementsParams {\n query: string\n page?: number\n pageSize?: number\n}\n\nexport interface GetRelatedIssuesParams {\n taskId: string\n}\n\nexport interface GetIssueDetailParams {\n issueId: string\n}\n\n/**\n * Abstract base class for source adapters.\n * Each adapter implements platform-specific logic for fetching requirements.\n */\nexport abstract class BaseAdapter {\n readonly sourceType: SourceType\n protected readonly config: SourceConfig\n protected readonly resolvedAuth: Record<string, string>\n\n constructor(\n sourceType: SourceType,\n config: SourceConfig,\n resolvedAuth: Record<string, string>,\n ) {\n this.sourceType = sourceType\n this.config = config\n this.resolvedAuth = resolvedAuth\n }\n\n /**\n * Fetch a single requirement by its ID.\n */\n abstract getRequirement(params: GetRequirementParams): Promise<Requirement>\n\n /**\n * Search requirements by query string.\n */\n abstract searchRequirements(params: SearchRequirementsParams): Promise<SearchResult>\n\n abstract getRelatedIssues(params: GetRelatedIssuesParams): Promise<RelatedIssue[]>\n\n abstract getIssueDetail(params: GetIssueDetailParams): Promise<IssueDetail>\n}\n","import type { SourceConfig } from '../types/config.js'\nimport type { IssueDetail, RelatedIssue, Requirement, SearchResult, SourceType } from '../types/requirement.js'\n\nimport type { GetIssueDetailParams, GetRelatedIssuesParams, GetRequirementParams, SearchRequirementsParams } from './base.js'\nimport crypto from 'node:crypto'\nimport { mapOnesPriority, mapOnesStatus, mapOnesType } from '../utils/map-status.js'\nimport { BaseAdapter } from './base.js'\n\n// ============ ONES GraphQL types ============\n\ninterface OnesTaskNode {\n key?: string\n uuid: string\n number: number\n name: string\n status: { uuid: string, name: string, category?: string }\n priority?: { value: string }\n issueType?: { uuid: string, name: string, detailType?: number }\n assign?: { uuid: string, name: string } | null\n owner?: { uuid: string, name: string } | null\n project?: { uuid: string, name: string }\n parent?: { uuid: string, number?: number, issueType?: { uuid: string, name: string } } | null\n relatedTasks?: OnesRelatedTask[]\n relatedWikiPages?: OnesWikiPage[]\n relatedWikiPagesCount?: number\n path?: string\n}\n\ninterface OnesWikiPage {\n uuid: string\n title: string\n referenceType?: number\n subReferenceType?: string\n errorMessage?: string\n}\n\ninterface OnesRelatedTask {\n uuid: string\n number: number\n name: string\n issueType: { uuid: string, name: string }\n status: { uuid: string, name: string, category?: string }\n assign?: { uuid: string, name: string } | null\n}\n\ninterface OnesIssueTypeNode {\n uuid: string\n name: string\n detailType: number\n}\n\ninterface OnesTeamUserNode {\n uuid?: string\n name?: string\n user?: {\n uuid?: string\n name?: string\n }\n org_user?: {\n org_user_uuid?: string\n name?: string\n }\n orgUser?: {\n uuid?: string\n name?: string\n }\n orgUserUuid?: string\n org_user_uuid?: string\n}\n\ninterface OnesTokenResponse {\n access_token: string\n token_type: string\n expires_in: number\n}\n\ninterface OnesLoginResponse {\n sid: string\n auth_user_uuid: string\n org_users: Array<{\n region_uuid: string\n org_uuid: string\n org_user: { org_user_uuid: string, name: string }\n org: { org_uuid: string, name: string }\n }>\n}\n\ninterface OnesSession {\n accessToken: string\n teamUuid: string\n orgUuid: string\n userUuid: string\n expiresAt: number\n}\n\n// ============ GraphQL queries ============\n\nconst TASK_DETAIL_QUERY = `\n query Task($key: Key) {\n task(key: $key) {\n key uuid number name\n issueType { uuid name }\n status { uuid name category }\n priority { value }\n assign { uuid name }\n owner { uuid name }\n project { uuid name }\n parent { uuid number issueType { uuid name } }\n relatedTasks {\n uuid number name\n issueType { uuid name }\n status { uuid name category }\n assign { uuid name }\n }\n relatedWikiPages {\n uuid\n title\n referenceType\n subReferenceType\n errorMessage\n }\n relatedWikiPagesCount\n }\n }\n`\n\nconst SEARCH_TASKS_QUERY = `\n query GROUP_TASK_DATA($groupBy: GroupBy, $groupOrderBy: OrderBy, $orderBy: OrderBy, $filterGroup: [Filter!], $search: Search, $pagination: Pagination, $limit: Int) {\n buckets(groupBy: $groupBy, orderBy: $groupOrderBy, pagination: $pagination, filter: $search) {\n key\n tasks(filterGroup: $filterGroup, orderBy: $orderBy, limit: $limit, includeAncestors: { pathField: \"path\" }) {\n key uuid number name\n issueType { uuid name detailType }\n status { uuid name category }\n priority { value }\n assign { uuid name }\n project { uuid name }\n }\n }\n }\n`\n\nconst ISSUE_TYPES_QUERY = `\n query IssueTypes($orderBy: OrderBy) {\n issueTypes(orderBy: $orderBy) {\n uuid\n name\n detailType\n }\n }\n`\n\n// Query to find a task by its number\nconst TASK_BY_NUMBER_QUERY = SEARCH_TASKS_QUERY\nconst RELATED_TASKS_QUERY = `\n query Task($key: Key) {\n task(key: $key) {\n key\n relatedTasks {\n key\n uuid\n name\n path\n deadline\n project { uuid name }\n priority { value }\n issueType {\n key uuid name detailType\n }\n subIssueType {\n key uuid name detailType\n }\n status {\n uuid name category\n }\n assign {\n uuid name\n }\n sprint {\n name uuid\n }\n statusCategory\n }\n }\n }\n`\n\nconst ISSUE_DETAIL_QUERY = `\n query Task($key: Key) {\n task(key: $key) {\n key uuid\n description\n descriptionText\n desc_rich: description\n name\n issueType { key uuid name detailType }\n subIssueType { key uuid name detailType }\n status { uuid name category }\n priority { value }\n assign { uuid name }\n owner { uuid name }\n solver { uuid name }\n project { uuid name }\n severityLevel { value }\n deadline(unit: ONESDATE)\n sprint { name uuid }\n }\n }\n`\n\nconst DEFAULT_STATUS_NOT_IN = ['FgMGkcaq', 'NvRwHBSo', 'Dn3k8ffK', 'TbmY2So5']\n\n// ============ Helpers ============\n\nfunction _getTaskStatusPriority(task: Pick<OnesTaskNode, 'status'>): number {\n const category = task.status?.category\n const name = task.status?.name\n\n if (category === 'to_do')\n return 0\n\n if (category === 'in_progress' && name === '修复中')\n return 1\n\n return Number.POSITIVE_INFINITY\n}\n\nfunction _isCommonTaskIssueType(task: Pick<OnesTaskNode, 'issueType'>): boolean {\n const detailType = task.issueType?.detailType\n\n if (detailType === 2 || detailType === 3)\n return true\n\n return task.issueType?.name === '任务' || task.issueType?.name === '缺陷'\n}\n\ntype OnesSearchIntent = 'all_bugs' | 'all_tasks' | 'keyword'\n\nfunction parseOnesSearchIntent(query: string): OnesSearchIntent {\n if (!query)\n return 'keyword'\n\n const normalized = query.toLowerCase()\n\n if (query.includes('\\u7F3A\\u9677') || normalized.includes('bug'))\n return 'all_bugs'\n\n if (query.includes('\\u4EFB\\u52A1'))\n return 'all_tasks'\n\n return 'keyword'\n}\n\nfunction extractAssigneeName(query: string, intent: OnesSearchIntent): string | null {\n if (intent === 'keyword')\n return null\n\n const trimmed = query.trim()\n if (!trimmed)\n return null\n\n const ownerStyleMatch = trimmed.match(/\\u8D1F\\u8D23\\u4EBA\\u4E3A(.+?)\\u7684?(?:\\u7F3A\\u9677|bug)$/i)\n if (ownerStyleMatch?.[1]) {\n return ownerStyleMatch[1].trim()\n }\n\n const genericMatch = trimmed.match(/^(查询)?(.+?)的(?:缺陷|bug|任务)$/i)\n const candidate = genericMatch?.[2]?.trim()\n if (!candidate || candidate.includes('我')) {\n return null\n }\n\n return candidate\n}\n\nfunction extractNamedAssignee(query: string, intent: OnesSearchIntent): string | null {\n if (intent === 'keyword')\n return null\n\n const compact = query.replace(/\\s+/g, '').trim()\n if (!compact)\n return null\n\n const ownerStyleMatch = compact.match(/(?:\\u8D1F\\u8D23\\u4EBA\\u4E3A|\\u8D1F\\u8D23\\u4EBA\\u662F|\\u6307\\u6D3E\\u7ED9|\\u5206\\u914D\\u7ED9)(.+?)\\u7684?(?:\\u7F3A\\u9677|bug|\\u4EFB\\u52A1)$/i)\n if (ownerStyleMatch?.[1]) {\n return ownerStyleMatch[1].trim()\n }\n\n const genericMatch = compact.match(/^(?:\\u67E5\\u8BE2|\\u67E5\\u627E|\\u641C\\u7D22)?(.+?)\\u7684?(?:\\u7F3A\\u9677|bug|\\u4EFB\\u52A1)$/i)\n const candidate = genericMatch?.[1]?.trim()\n\n if (\n !candidate\n || candidate.startsWith('\\u6211')\n || /^(?:\\u6211|\\u6211\\u7684|\\u6211\\u6240\\u6709|\\u6211\\u5168\\u90E8|\\u672C\\u4EBA|\\u5F53\\u524D\\u7528\\u6237)$/.test(candidate)\n ) {\n return null\n }\n\n return candidate\n}\n\nfunction getBugStatusPriority(task: Pick<OnesTaskNode, 'status'>): number {\n if (task.status?.category === 'to_do')\n return 0\n\n if (task.status?.category === 'in_progress')\n return 1\n\n return Number.POSITIVE_INFINITY\n}\n\nfunction isOpenOrInProgressBug(task: Pick<OnesTaskNode, 'status'>): boolean {\n const category = task.status?.category\n return category === 'to_do' || category === 'in_progress'\n}\n\nfunction extractTeamUsers(payload: unknown): Array<{ uuid: string, name: string }> {\n const record = payload && typeof payload === 'object'\n ? payload as Record<string, unknown>\n : null\n\n if (!record)\n return []\n\n const candidates = [\n record.users,\n record.items,\n record.list,\n record.results,\n (record.data as Record<string, unknown> | undefined)?.users,\n (record.data as Record<string, unknown> | undefined)?.items,\n (record.data as Record<string, unknown> | undefined)?.list,\n (record.data as Record<string, unknown> | undefined)?.results,\n ]\n\n const rawUsers = candidates.find(Array.isArray)\n if (!rawUsers)\n return []\n\n return rawUsers\n .map((item) => {\n const user = item && typeof item === 'object'\n ? item as OnesTeamUserNode\n : null\n\n if (!user)\n return null\n\n const uuid = user.uuid\n ?? user.user?.uuid\n ?? user.orgUser?.uuid\n ?? user.orgUserUuid\n ?? user.org_user_uuid\n ?? user.org_user?.org_user_uuid\n\n const name = user.name\n ?? user.user?.name\n ?? user.orgUser?.name\n ?? user.org_user?.name\n\n if (!uuid || !name)\n return null\n\n return { uuid, name }\n })\n .filter((item): item is { uuid: string, name: string } => item !== null)\n}\n\nfunction base64Url(buffer: Buffer): string {\n return buffer.toString('base64').replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/g, '')\n}\n\nfunction getSetCookies(response: Response): string[] {\n const headers = response.headers as unknown as { getSetCookie?: () => string[] }\n if (headers.getSetCookie) {\n return headers.getSetCookie()\n }\n const raw = response.headers.get('set-cookie')\n return raw ? [raw] : []\n}\n\nfunction toRequirement(task: OnesTaskNode, description = ''): Requirement {\n return {\n id: task.uuid,\n source: 'ones',\n title: `#${task.number} ${task.name}`,\n description,\n status: mapOnesStatus(task.status?.category ?? 'to_do'),\n priority: mapOnesPriority(task.priority?.value ?? 'normal'),\n type: mapOnesType(task.issueType?.name ?? '任务'),\n labels: [],\n reporter: '',\n assignee: task.assign?.name ?? null,\n // ONES GraphQL does not return timestamps; these are fetch-time placeholders\n createdAt: '',\n updatedAt: '',\n dueDate: null,\n attachments: [],\n raw: task as unknown as Record<string, unknown>,\n }\n}\n\n// ============ ONES Adapter ============\n\nexport class OnesAdapter extends BaseAdapter {\n private session: OnesSession | null = null\n private issueTypesCache: OnesIssueTypeNode[] | null = null\n\n constructor(\n sourceType: SourceType,\n config: SourceConfig,\n resolvedAuth: Record<string, string>,\n ) {\n super(sourceType, config, resolvedAuth)\n }\n\n /**\n * ONES OAuth2 PKCE login flow.\n * Reference: D:\\company code\\ones\\packages\\core\\src\\auth.ts\n */\n private async login(): Promise<OnesSession> {\n if (this.session && Date.now() < this.session.expiresAt) {\n return this.session\n }\n\n const baseUrl = this.config.apiBase\n const email = this.resolvedAuth.email\n const password = this.resolvedAuth.password\n\n if (!email || !password) {\n throw new Error('ONES auth requires email and password (ones-pkce auth type)')\n }\n\n // 1. Get encryption certificate\n const certRes = await fetch(`${baseUrl}/identity/api/encryption_cert`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: '{}',\n })\n if (!certRes.ok) {\n throw new Error(`ONES: Failed to get encryption cert: ${certRes.status}`)\n }\n const cert = (await certRes.json()) as { public_key: string }\n\n // 2. Encrypt password with RSA public key\n const encrypted = crypto.publicEncrypt(\n { key: cert.public_key, padding: crypto.constants.RSA_PKCS1_PADDING },\n Buffer.from(password, 'utf-8'),\n )\n const encryptedPassword = encrypted.toString('base64')\n\n // 3. Login\n const loginRes = await fetch(`${baseUrl}/identity/api/login`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ email, password: encryptedPassword }),\n })\n if (!loginRes.ok) {\n const text = await loginRes.text().catch(() => '')\n throw new Error(`ONES: Login failed: ${loginRes.status} ${text}`)\n }\n\n const cookies = getSetCookies(loginRes)\n .map(cookie => cookie.split(';')[0])\n .join('; ')\n const loginData = (await loginRes.json()) as OnesLoginResponse\n\n // Pick org user (first one, or match by config option)\n const orgUuid = this.config.options?.orgUuid as string | undefined\n let orgUser = loginData.org_users[0]\n if (orgUuid) {\n const match = loginData.org_users.find(u => u.org_uuid === orgUuid)\n if (match)\n orgUser = match\n }\n\n // 4. PKCE: generate code verifier + challenge\n const codeVerifier = base64Url(crypto.randomBytes(32))\n const codeChallenge = base64Url(\n crypto.createHash('sha256').update(codeVerifier).digest(),\n )\n\n // 5. Authorize\n const authorizeParams = new URLSearchParams({\n client_id: 'ones.v1',\n scope: `openid offline_access ones:org:${orgUser.region_uuid}:${orgUser.org_uuid}:${orgUser.org_user.org_user_uuid}`,\n response_type: 'code',\n code_challenge_method: 'S256',\n code_challenge: codeChallenge,\n redirect_uri: `${baseUrl}/auth/authorize/callback`,\n state: `org_uuid=${orgUser.org_uuid}`,\n })\n\n const authorizeRes = await fetch(`${baseUrl}/identity/authorize`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n 'Cookie': cookies,\n },\n body: authorizeParams.toString(),\n redirect: 'manual',\n })\n\n const authorizeLocation = authorizeRes.headers.get('location')\n if (!authorizeLocation) {\n throw new Error('ONES: Authorize response missing location header')\n }\n const authRequestId = new URL(authorizeLocation).searchParams.get('id')\n if (!authRequestId) {\n throw new Error('ONES: Cannot parse auth_request_id from authorize redirect')\n }\n\n // 6. Finalize auth request\n const finalizeRes = await fetch(`${baseUrl}/identity/api/auth_request/finalize`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json;charset=UTF-8',\n 'Cookie': cookies,\n },\n body: JSON.stringify({\n auth_request_id: authRequestId,\n region_uuid: orgUser.region_uuid,\n org_uuid: orgUser.org_uuid,\n org_user_uuid: orgUser.org_user.org_user_uuid,\n }),\n })\n if (!finalizeRes.ok) {\n const text = await finalizeRes.text().catch(() => '')\n throw new Error(`ONES: Finalize failed: ${finalizeRes.status} ${text}`)\n }\n\n // 7. Callback to get authorization code\n const callbackRes = await fetch(\n `${baseUrl}/identity/authorize/callback?id=${authRequestId}&lang=zh`,\n {\n method: 'GET',\n headers: { Cookie: cookies },\n redirect: 'manual',\n },\n )\n\n const callbackLocation = callbackRes.headers.get('location')\n if (!callbackLocation) {\n throw new Error('ONES: Callback response missing location header')\n }\n const code = new URL(callbackLocation).searchParams.get('code')\n if (!code) {\n throw new Error('ONES: Cannot parse authorization code from callback redirect')\n }\n\n // 8. Exchange code for token\n const tokenRes = await fetch(`${baseUrl}/identity/oauth/token`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n 'Cookie': cookies,\n },\n body: new URLSearchParams({\n grant_type: 'authorization_code',\n client_id: 'ones.v1',\n code,\n code_verifier: codeVerifier,\n redirect_uri: `${baseUrl}/auth/authorize/callback`,\n }).toString(),\n })\n if (!tokenRes.ok) {\n const text = await tokenRes.text().catch(() => '')\n throw new Error(`ONES: Token exchange failed: ${tokenRes.status} ${text}`)\n }\n\n const token = (await tokenRes.json()) as OnesTokenResponse\n\n // 9. Get teams to find teamUuid\n const teamsRes = await fetch(\n `${baseUrl}/project/api/project/organization/${orgUser.org_uuid}/stamps/data?t=org_my_team`,\n {\n method: 'POST',\n headers: {\n 'Authorization': `Bearer ${token.access_token}`,\n 'Content-Type': 'application/json;charset=UTF-8',\n },\n body: JSON.stringify({ org_my_team: 0 }),\n },\n )\n if (!teamsRes.ok) {\n throw new Error(`ONES: Failed to fetch teams: ${teamsRes.status}`)\n }\n\n const teamsData = (await teamsRes.json()) as {\n org_my_team?: { teams?: Array<{ uuid: string, name: string }> }\n }\n const teams = teamsData.org_my_team?.teams ?? []\n\n // Pick team by config option or default to first\n const configTeamUuid = this.config.options?.teamUuid as string | undefined\n let teamUuid = teams[0]?.uuid\n if (configTeamUuid) {\n const match = teams.find(t => t.uuid === configTeamUuid)\n if (match)\n teamUuid = match.uuid\n }\n\n if (!teamUuid) {\n throw new Error('ONES: No teams found for this user')\n }\n\n this.session = {\n accessToken: token.access_token,\n teamUuid,\n orgUuid: orgUser.org_uuid,\n userUuid: orgUser.org_user.org_user_uuid,\n expiresAt: Date.now() + (token.expires_in - 60) * 1000, // refresh 60s early\n }\n\n return this.session\n }\n\n /**\n * Execute a GraphQL query against ONES project API.\n */\n private async graphql<T>(query: string, variables: Record<string, unknown>, tag?: string): Promise<T> {\n const session = await this.login()\n const url = `${this.config.apiBase}/project/api/project/team/${session.teamUuid}/items/graphql${tag ? `?t=${encodeURIComponent(tag)}` : ''}`\n\n const response = await fetch(url, {\n method: 'POST',\n headers: {\n 'Authorization': `Bearer ${session.accessToken}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({ query, variables }),\n })\n\n if (!response.ok) {\n const text = await response.text().catch(() => '')\n throw new Error(`ONES GraphQL error: ${response.status} ${text}`)\n }\n\n return response.json() as Promise<T>\n }\n\n private async fetchIssueTypes(): Promise<OnesIssueTypeNode[]> {\n if (this.issueTypesCache)\n return this.issueTypesCache\n\n const data = await this.graphql<{ data?: { issueTypes?: OnesIssueTypeNode[] } }>(\n ISSUE_TYPES_QUERY,\n { orderBy: { namePinyin: 'ASC' } },\n 'issueTypes',\n )\n\n this.issueTypesCache = data.data?.issueTypes ?? []\n return this.issueTypesCache\n }\n\n private async searchTeamUsers(keyword: string): Promise<Array<{ uuid: string, name: string }>> {\n const session = await this.login()\n const url = `${this.config.apiBase}/project/api/project/team/${session.teamUuid}/users/search`\n\n const response = await fetch(url, {\n method: 'POST',\n headers: {\n 'Authorization': `Bearer ${session.accessToken}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n keyword,\n status: [1],\n team_member_status: [1, 4],\n types: [1, 10],\n }),\n })\n\n if (!response.ok) {\n const text = await response.text().catch(() => '')\n throw new Error(`ONES user search error: ${response.status} ${text}`)\n }\n\n return extractTeamUsers(await response.json())\n }\n\n private async resolveAssigneeUuid(name: string): Promise<string | null> {\n const trimmed = name.trim()\n if (!trimmed)\n return null\n\n const users = await this.searchTeamUsers(trimmed)\n const exactMatch = users.find(user => user.name === trimmed)\n if (exactMatch)\n return exactMatch.uuid\n\n const normalizedTarget = trimmed.toLowerCase()\n const fuzzyMatch = users.find(user => user.name.toLowerCase().includes(normalizedTarget))\n return fuzzyMatch?.uuid ?? null\n }\n\n /**\n * Fetch task info via REST API (includes description/rich fields not available in GraphQL).\n * Reference: ones/packages/core/src/tasks.ts → fetchTaskInfo\n */\n private async fetchTaskInfo(taskUuid: string): Promise<Record<string, unknown>> {\n const session = await this.login()\n const url = `${this.config.apiBase}/project/api/project/team/${session.teamUuid}/task/${taskUuid}/info`\n\n const response = await fetch(url, {\n headers: { Authorization: `Bearer ${session.accessToken}` },\n })\n\n if (!response.ok) {\n return {}\n }\n\n return response.json() as Promise<Record<string, unknown>>\n }\n\n /**\n * Resolve a fresh signed URL for an attachment resource via ONES attachment API.\n * Endpoint: /project/api/project/team/{teamUuid}/res/attachment/{resourceUuid}\n * Returns a redirect URL with a fresh OSS signature.\n */\n private async getAttachmentUrl(resourceUuid: string): Promise<string | null> {\n const session = await this.login()\n const url = `${this.config.apiBase}/project/api/project/team/${session.teamUuid}/res/attachment/${resourceUuid}?op=${encodeURIComponent('imageMogr2/auto-orient')}`\n\n try {\n // First try with redirect: 'manual' to capture 302 Location header\n const manualRes = await fetch(url, {\n headers: { Authorization: `Bearer ${session.accessToken}` },\n redirect: 'manual',\n })\n\n if (manualRes.status === 302 || manualRes.status === 301) {\n const location = manualRes.headers.get('location')\n if (location)\n return location\n }\n\n // Fallback: follow redirects and use the final URL\n const followRes = await fetch(url, {\n headers: { Authorization: `Bearer ${session.accessToken}` },\n redirect: 'follow',\n })\n\n // If redirected, response.url will be the final signed URL\n if (followRes.url && followRes.url !== url) {\n return followRes.url\n }\n\n if (followRes.ok) {\n const text = await followRes.text()\n if (text.startsWith('http')) {\n return text.trim()\n }\n try {\n const data = JSON.parse(text) as { url?: string }\n return data.url ?? null\n }\n catch {\n return null\n }\n }\n\n console.error(`[getAttachmentUrl] Failed for resource ${resourceUuid}: status ${followRes.status}`)\n return null\n }\n catch (err) {\n console.error(`[getAttachmentUrl] Error for resource ${resourceUuid}:`, err)\n return null\n }\n }\n\n /**\n * Replace stale image URLs in HTML with fresh signed URLs from the attachment API.\n * Extracts data-uuid from <img> tags and resolves fresh URLs in parallel.\n */\n private async refreshImageUrls(html: string): Promise<string> {\n if (!html)\n return html\n\n // Extract all img tags with data-uuid\n const imgRegex = /<img\\s[^>]*data-uuid=\"([^\"]+)\"[^>]*>/g\n const matches = Array.from(html.matchAll(imgRegex))\n\n if (matches.length === 0)\n return html\n\n // Resolve fresh URLs in parallel\n const replacements = await Promise.all(\n matches.map(async (match) => {\n const dataUuid = match[1]\n const freshUrl = await this.getAttachmentUrl(dataUuid)\n return { fullMatch: match[0], dataUuid, freshUrl }\n }),\n )\n\n let result = html\n for (const { fullMatch, freshUrl } of replacements) {\n if (freshUrl) {\n // Replace the src attribute in the img tag with the fresh URL\n const updatedImg = fullMatch.replace(/src=\"[^\"]*\"/, `src=\"${freshUrl}\"`)\n result = result.replace(fullMatch, updatedImg)\n }\n }\n\n return result\n }\n\n /**\n * Fetch wiki page content via REST API.\n * Endpoint: /wiki/api/wiki/team/{teamUuid}/online_page/{wikiUuid}/content\n */\n private async fetchWikiContent(wikiUuid: string): Promise<string> {\n const session = await this.login()\n const url = `${this.config.apiBase}/wiki/api/wiki/team/${session.teamUuid}/online_page/${wikiUuid}/content`\n\n const response = await fetch(url, {\n headers: { Authorization: `Bearer ${session.accessToken}` },\n })\n\n if (!response.ok) {\n return ''\n }\n\n const data = await response.json() as { content?: string }\n return data.content ?? ''\n }\n\n /**\n * Fetch a single task by UUID or number (e.g. \"#95945\" or \"95945\").\n * If a number is given, searches first to resolve the UUID.\n */\n async getRequirement(params: GetRequirementParams): Promise<Requirement> {\n let taskUuid = params.id\n\n // If the ID looks like a number (with or without #), search to find the UUID\n const numMatch = taskUuid.match(/^#?(\\d+)$/)\n if (numMatch) {\n const taskNumber = Number.parseInt(numMatch[1], 10)\n const searchData = await this.graphql<{\n data?: { buckets?: Array<{ tasks?: OnesTaskNode[] }> }\n }>(\n TASK_BY_NUMBER_QUERY,\n {\n groupBy: { tasks: {} },\n groupOrderBy: null,\n orderBy: { createTime: 'DESC' },\n filterGroup: [{ number_in: [taskNumber] }],\n search: null,\n pagination: { limit: 10, preciseCount: false },\n limit: 10,\n },\n 'group-task-data',\n )\n\n const allTasks = searchData.data?.buckets?.flatMap(b => b.tasks ?? []) ?? []\n const found = allTasks.find(t => t.number === taskNumber)\n\n if (!found) {\n throw new Error(`ONES: Task #${taskNumber} not found in current team`)\n }\n taskUuid = found.uuid\n }\n\n // Fetch GraphQL data (structure, relations, wiki pages)\n const graphqlData = await this.graphql<{ data?: { task?: OnesTaskNode } }>(\n TASK_DETAIL_QUERY,\n { key: `task-${taskUuid}` },\n 'Task',\n )\n\n const task = graphqlData.data?.task\n if (!task) {\n throw new Error(`ONES: Task \"${taskUuid}\" not found`)\n }\n\n // Fetch wiki page content for related requirement docs (in parallel)\n const wikiPages = task.relatedWikiPages ?? []\n const wikiContents = await Promise.all(\n wikiPages\n .filter(w => !w.errorMessage)\n .map(async (wiki) => {\n const content = await this.fetchWikiContent(wiki.uuid)\n return { title: wiki.title, uuid: wiki.uuid, content }\n }),\n )\n\n // Build description: task info + wiki requirement docs\n const parts: string[] = []\n\n // Task basic info\n parts.push(`# #${task.number} ${task.name}`)\n parts.push('')\n parts.push(`- **Type**: ${task.issueType?.name ?? 'Unknown'}`)\n parts.push(`- **Status**: ${task.status?.name ?? 'Unknown'}`)\n parts.push(`- **Assignee**: ${task.assign?.name ?? 'Unassigned'}`)\n if (task.owner?.name) {\n parts.push(`- **Owner**: ${task.owner.name}`)\n }\n if (task.project?.name) {\n parts.push(`- **Project**: ${task.project.name}`)\n }\n parts.push(`- **UUID**: ${task.uuid}`)\n\n // Related tasks\n if (task.relatedTasks?.length) {\n parts.push('')\n parts.push('## Related Tasks')\n for (const related of task.relatedTasks) {\n const assignee = related.assign?.name ?? 'Unassigned'\n parts.push(`- #${related.number} ${related.name} [${related.issueType?.name}] (${related.status?.name}) — ${assignee}`)\n }\n }\n\n // Parent task\n if (task.parent?.uuid) {\n parts.push('')\n parts.push('## Parent Task')\n parts.push(`- UUID: ${task.parent.uuid}`)\n if (task.parent.number) {\n parts.push(`- Number: #${task.parent.number}`)\n }\n }\n\n // Wiki requirement documents (the core requirement content)\n if (wikiContents.length > 0) {\n parts.push('')\n parts.push('---')\n parts.push('')\n parts.push('## Requirement Documents')\n for (const wiki of wikiContents) {\n parts.push('')\n parts.push(`### ${wiki.title}`)\n parts.push('')\n if (wiki.content) {\n parts.push(wiki.content)\n }\n else {\n parts.push('(No content available)')\n }\n }\n }\n\n const req = toRequirement(task, parts.join('\\n'))\n\n return req\n }\n\n /**\n * Search tasks assigned to current user via GraphQL.\n * Uses keyword-based local filtering (matching ONES reference implementation).\n */\n async searchRequirements(params: SearchRequirementsParams): Promise<SearchResult> {\n const page = params.page ?? 1\n const pageSize = params.pageSize ?? 50\n const intent = parseOnesSearchIntent(params.query)\n const assigneeName = extractNamedAssignee(params.query, intent) ?? extractAssigneeName(params.query, intent)\n const assigneeUuid = assigneeName\n ? await this.resolveAssigneeUuid(assigneeName)\n : null\n\n if (assigneeName && !assigneeUuid) {\n return {\n items: [],\n total: 0,\n page,\n pageSize,\n }\n }\n\n let bugTypeUuids: string[] = []\n let taskTypeUuids: string[] = []\n\n if (intent === 'all_bugs' || intent === 'all_tasks') {\n const issueTypes = await this.fetchIssueTypes()\n bugTypeUuids = issueTypes.filter(item => item.detailType === 3).map(item => item.uuid)\n taskTypeUuids = issueTypes.filter(item => item.detailType === 2).map(item => item.uuid)\n }\n\n const filter: Record<string, unknown> = {\n status_notIn: DEFAULT_STATUS_NOT_IN,\n }\n\n if (assigneeName) {\n filter.assign_in = [assigneeUuid]\n }\n else {\n filter.assign_in = ['${currentUser}']\n }\n\n if (intent === 'all_bugs')\n filter.issueType_in = bugTypeUuids\n\n if (intent === 'all_tasks')\n filter.issueType_in = taskTypeUuids\n\n const data = await this.graphql<{\n data?: {\n buckets?: Array<{\n key: string\n tasks?: OnesTaskNode[]\n }>\n }\n }>(\n SEARCH_TASKS_QUERY,\n {\n groupBy: { tasks: {} },\n groupOrderBy: null,\n orderBy: { position: 'ASC', createTime: 'DESC' },\n filterGroup: [filter],\n search: null,\n pagination: { limit: pageSize * page, preciseCount: false },\n limit: 1000,\n },\n 'group-task-data',\n )\n\n let tasks = data.data?.buckets?.flatMap(b => b.tasks ?? []) ?? []\n\n if (intent === 'all_bugs') {\n tasks = tasks\n .filter(task => task.issueType?.uuid ? bugTypeUuids.includes(task.issueType.uuid) : false)\n .filter(task => isOpenOrInProgressBug(task))\n .sort((a, b) => getBugStatusPriority(a) - getBugStatusPriority(b))\n }\n\n if (intent === 'all_tasks') {\n // detailType = 1 的需求不属于“我的任务”列表入口。\n // 需求详情查询继续走 getRequirement(id/number),因为需求通常由产品负责人维护,\n // 当前登录用户不一定能通过 assign_in: ['${currentUser}'] 查到需求项。\n tasks = tasks.filter(task => task.issueType?.uuid ? taskTypeUuids.includes(task.issueType.uuid) : false)\n }\n\n if (assigneeUuid) {\n tasks = tasks.filter(task => task.assign?.uuid === assigneeUuid)\n }\n\n // Local keyword filter (matching ones-api.ts behavior)\n if (intent === 'keyword' && params.query) {\n const keyword = params.query.trim()\n const lower = keyword.toLowerCase()\n const numMatch = keyword.match(/^#?(\\d+)$/)\n\n if (numMatch) {\n tasks = tasks.filter(t => t.number === Number.parseInt(numMatch[1], 10))\n }\n else {\n tasks = tasks.filter(t => t.name.toLowerCase().includes(lower))\n }\n }\n\n // Paginate locally\n const total = tasks.length\n const start = (page - 1) * pageSize\n const paged = tasks.slice(start, start + pageSize)\n\n return {\n items: paged.map(t => toRequirement(t)),\n total,\n page,\n pageSize,\n }\n }\n\n async getRelatedIssues(params: GetRelatedIssuesParams): Promise<RelatedIssue[]> {\n const session = await this.login()\n\n const taskKey = params.taskId.startsWith('task-')\n ? params.taskId\n : `task-${params.taskId}`\n\n const data = await this.graphql<{\n data?: {\n task?: {\n key: string\n relatedTasks: Array<{\n key: string\n uuid: string\n name: string\n issueType: { key: string, uuid: string, name: string, detailType: number }\n subIssueType?: { key: string, uuid: string, name: string, detailType: number } | null\n status: { uuid: string, name: string, category: string }\n assign?: { uuid: string, name: string } | null\n priority?: { value: string } | null\n project?: { uuid: string, name: string } | null\n }>\n }\n }\n }>(RELATED_TASKS_QUERY, { key: taskKey }, 'Task')\n\n const relatedTasks = data.data?.task?.relatedTasks ?? []\n\n // Filter: detailType === 3 (defect) + status.category === \"to_do\" (pending)\n // Returns ALL pending defects, not just current user's\n const filtered = relatedTasks.filter((t) => {\n const isDefect = t.issueType?.detailType === 3\n || t.subIssueType?.detailType === 3\n const isTodo = t.status?.category === 'to_do'\n return isDefect && isTodo\n })\n\n // Sort: current user's defects first\n const currentUserUuid = session.userUuid\n filtered.sort((a, b) => {\n const aIsCurrent = a.assign?.uuid === currentUserUuid ? 0 : 1\n const bIsCurrent = b.assign?.uuid === currentUserUuid ? 0 : 1\n return aIsCurrent - bIsCurrent\n })\n\n return filtered.map(t => ({\n key: t.key,\n uuid: t.uuid,\n name: t.name,\n issueTypeName: t.issueType?.name ?? 'Unknown',\n statusName: t.status?.name ?? 'Unknown',\n statusCategory: t.status?.category ?? 'unknown',\n assignName: t.assign?.name ?? null,\n assignUuid: t.assign?.uuid ?? null,\n priorityValue: t.priority?.value ?? null,\n projectName: t.project?.name ?? null,\n }))\n }\n\n async getIssueDetail(params: GetIssueDetailParams): Promise<IssueDetail> {\n let issueKey: string\n\n // Support number lookup (e.g. \"98086\" or \"#98086\")\n const numMatch = params.issueId.match(/^#?(\\d+)$/)\n if (numMatch) {\n const taskNumber = Number.parseInt(numMatch[1], 10)\n const searchData = await this.graphql<{\n data?: { buckets?: Array<{ tasks?: Array<{ uuid: string, number: number }> }> }\n }>(\n SEARCH_TASKS_QUERY,\n {\n groupBy: { tasks: {} },\n groupOrderBy: null,\n orderBy: { createTime: 'DESC' },\n filterGroup: [{ number_in: [taskNumber] }],\n search: null,\n pagination: { limit: 10, preciseCount: false },\n limit: 10,\n },\n 'group-task-data',\n )\n\n const allTasks = searchData.data?.buckets?.flatMap(b => b.tasks ?? []) ?? []\n const found = allTasks.find(t => t.number === taskNumber)\n if (!found) {\n throw new Error(`ONES: Issue #${taskNumber} not found in current team`)\n }\n issueKey = `task-${found.uuid}`\n }\n else {\n issueKey = params.issueId.startsWith('task-')\n ? params.issueId\n : `task-${params.issueId}`\n }\n\n const data = await this.graphql<{\n data?: {\n task?: {\n key: string\n uuid: string\n name: string\n description: string\n descriptionText: string\n desc_rich: string\n issueType: { name: string }\n status: { name: string, category: string }\n priority?: { value: string } | null\n assign?: { uuid: string, name: string } | null\n owner?: { uuid: string, name: string } | null\n solver?: { uuid: string, name: string } | null\n project?: { uuid: string, name: string } | null\n severityLevel?: { value: string } | null\n deadline?: string | null\n sprint?: { name: string } | null\n }\n }\n }>(ISSUE_DETAIL_QUERY, { key: issueKey }, 'Task')\n\n const task = data.data?.task\n if (!task) {\n throw new Error(`ONES: Issue \"${issueKey}\" not found`)\n }\n\n // Fetch fresh description via REST API\n const taskInfo = await this.fetchTaskInfo(task.uuid)\n const rawDescription = (taskInfo.desc as string) ?? task.description ?? ''\n const rawDescRich = (taskInfo.desc_rich as string) ?? task.desc_rich ?? ''\n\n // Refresh image URLs via attachment API (signed URLs expire after 1 hour)\n const freshDescription = await this.refreshImageUrls(rawDescription)\n const freshDescRich = await this.refreshImageUrls(rawDescRich)\n\n return {\n key: task.key,\n uuid: task.uuid,\n name: task.name,\n description: freshDescription,\n descriptionRich: freshDescRich,\n descriptionText: task.descriptionText ?? '',\n issueTypeName: task.issueType?.name ?? 'Unknown',\n statusName: task.status?.name ?? 'Unknown',\n statusCategory: task.status?.category ?? 'unknown',\n assignName: task.assign?.name ?? null,\n ownerName: task.owner?.name ?? null,\n solverName: task.solver?.name ?? null,\n priorityValue: task.priority?.value ?? null,\n severityLevel: task.severityLevel?.value ?? null,\n projectName: task.project?.name ?? null,\n deadline: task.deadline ?? null,\n sprintName: task.sprint?.name ?? null,\n raw: task as unknown as Record<string, unknown>,\n }\n }\n}\n","import type { SourceConfig } from '../types/config.js'\nimport type { SourceType } from '../types/requirement.js'\nimport type { BaseAdapter } from './base.js'\nimport { OnesAdapter } from './ones.js'\n\nconst ADAPTER_MAP: Record<string, new (\n sourceType: SourceType,\n config: SourceConfig,\n resolvedAuth: Record<string, string>,\n) => BaseAdapter> = {\n ones: OnesAdapter,\n}\n\n/**\n * Factory function to create the appropriate adapter based on source type.\n */\nexport function createAdapter(\n sourceType: SourceType,\n config: SourceConfig,\n resolvedAuth: Record<string, string>,\n): BaseAdapter {\n const AdapterClass = ADAPTER_MAP[sourceType]\n if (!AdapterClass) {\n throw new Error(\n `Unsupported source type: \"${sourceType}\". Supported: ${Object.keys(ADAPTER_MAP).join(', ')}`,\n )\n }\n return new AdapterClass(sourceType, config, resolvedAuth)\n}\n\nexport { BaseAdapter } from './base.js'\nexport { OnesAdapter } from './ones.js'\n","import type { AuthConfig } from '../types/auth.js'\nimport type { McpConfig, SourceConfig } from '../types/config.js'\nimport type { SourceType } from '../types/requirement.js'\nimport { existsSync, readFileSync } from 'node:fs'\nimport { dirname, resolve } from 'node:path'\nimport { z } from 'zod/v4'\n\nconst AuthSchema = z.discriminatedUnion('type', [\n z.object({\n type: z.literal('token'),\n tokenEnv: z.string(),\n }),\n z.object({\n type: z.literal('basic'),\n usernameEnv: z.string(),\n passwordEnv: z.string(),\n }),\n z.object({\n type: z.literal('oauth2'),\n clientIdEnv: z.string(),\n clientSecretEnv: z.string(),\n tokenUrl: z.string().url(),\n }),\n z.object({\n type: z.literal('cookie'),\n cookieEnv: z.string(),\n }),\n z.object({\n type: z.literal('custom'),\n headerName: z.string(),\n valueEnv: z.string(),\n }),\n z.object({\n type: z.literal('ones-pkce'),\n emailEnv: z.string(),\n passwordEnv: z.string(),\n }),\n])\n\nconst SourceConfigSchema = z.object({\n enabled: z.boolean(),\n apiBase: z.string().url(),\n auth: AuthSchema,\n headers: z.record(z.string(), z.string()).optional(),\n options: z.record(z.string(), z.unknown()).optional(),\n})\n\nconst SourcesSchema = z.object({\n ones: SourceConfigSchema.optional(),\n})\n\nconst McpConfigSchema = z.object({\n sources: SourcesSchema,\n defaultSource: z.enum(['ones']).optional(),\n})\n\nconst CONFIG_FILENAME = '.requirements-mcp.json'\n\n/**\n * Search for config file starting from `startDir` and walking up to the root.\n */\nfunction findConfigFile(startDir: string): string | null {\n let dir = resolve(startDir)\n while (true) {\n const candidate = resolve(dir, CONFIG_FILENAME)\n if (existsSync(candidate)) {\n return candidate\n }\n const parent = dirname(dir)\n if (parent === dir)\n break\n dir = parent\n }\n return null\n}\n\n/**\n * Resolve environment variable references in auth config.\n * Reads actual env var values for fields ending with \"Env\".\n */\nfunction resolveAuthEnv(auth: AuthConfig): Record<string, string> {\n const resolved: Record<string, string> = {}\n\n for (const [key, value] of Object.entries(auth)) {\n if (key === 'type')\n continue\n if (key.endsWith('Env') && typeof value === 'string') {\n const envValue = process.env[value]\n if (!envValue) {\n throw new Error(`Environment variable \"${value}\" is not set (required by auth.${key})`)\n }\n // Strip the \"Env\" suffix for the resolved key\n const resolvedKey = key.slice(0, -3)\n resolved[resolvedKey] = envValue\n }\n else if (typeof value === 'string') {\n resolved[key] = value\n }\n }\n\n return resolved\n}\n\nexport interface ResolvedSource {\n type: SourceType\n config: SourceConfig\n resolvedAuth: Record<string, string>\n}\n\nexport interface LoadConfigResult {\n config: McpConfig\n sources: ResolvedSource[]\n configPath: string\n}\n\n/**\n * Try to build config purely from environment variables.\n * Required env vars: ONES_API_BASE, ONES_ACCOUNT, ONES_PASSWORD\n * Returns null if the required env vars are not all present.\n */\nfunction loadConfigFromEnv(): McpConfig | null {\n const apiBase = process.env.ONES_API_BASE\n const account = process.env.ONES_ACCOUNT\n const password = process.env.ONES_PASSWORD\n\n if (!apiBase || !account || !password) {\n return null\n }\n\n return {\n sources: {\n ones: {\n enabled: true,\n apiBase,\n auth: {\n type: 'ones-pkce',\n emailEnv: 'ONES_ACCOUNT',\n passwordEnv: 'ONES_PASSWORD',\n },\n },\n },\n defaultSource: 'ones',\n }\n}\n\n/**\n * Load and validate the MCP config.\n * Priority: env vars (ONES_API_BASE + ONES_ACCOUNT + ONES_PASSWORD) > config file (.requirements-mcp.json).\n * Searches from `startDir` (defaults to cwd) upward for the file.\n */\nexport function loadConfig(startDir?: string): LoadConfigResult {\n // 1. Try environment variables first (simplest setup for MCP)\n const envConfig = loadConfigFromEnv()\n if (envConfig) {\n const sources: ResolvedSource[] = []\n for (const [type, sourceConfig] of Object.entries(envConfig.sources)) {\n if (sourceConfig && sourceConfig.enabled) {\n const resolvedAuth = resolveAuthEnv(sourceConfig.auth)\n sources.push({\n type: type as SourceType,\n config: sourceConfig,\n resolvedAuth,\n })\n }\n }\n return { config: envConfig, sources, configPath: 'env' }\n }\n\n // 2. Fall back to config file\n const dir = startDir ?? process.cwd()\n const configPath = findConfigFile(dir)\n\n if (!configPath) {\n throw new Error(\n `Config not found. Either set env vars (ONES_API_BASE, ONES_ACCOUNT, ONES_PASSWORD) `\n + `or create \"${CONFIG_FILENAME}\" based on .requirements-mcp.json.example`,\n )\n }\n\n const raw = readFileSync(configPath, 'utf-8')\n let parsed: unknown\n try {\n parsed = JSON.parse(raw)\n }\n catch {\n throw new Error(`Invalid JSON in ${configPath}`)\n }\n\n const result = McpConfigSchema.safeParse(parsed)\n if (!result.success) {\n throw new Error(\n `Invalid config in ${configPath}:\\n${result.error.issues.map(i => ` - ${i.path.join('.')}: ${i.message}`).join('\\n')}`,\n )\n }\n\n const config = result.data as McpConfig\n\n // Resolve enabled sources\n const sources: ResolvedSource[] = []\n for (const [type, sourceConfig] of Object.entries(config.sources)) {\n if (sourceConfig && sourceConfig.enabled) {\n const resolvedAuth = resolveAuthEnv(sourceConfig.auth)\n sources.push({\n type: type as SourceType,\n config: sourceConfig,\n resolvedAuth,\n })\n }\n }\n\n if (sources.length === 0) {\n throw new Error('No enabled sources found in config. Enable at least one source.')\n }\n\n return { config, sources, configPath }\n}\n\nexport { findConfigFile, loadConfigFromEnv, resolveAuthEnv }\n","import type { BaseAdapter } from '../adapters/base.js'\nimport type { IssueDetail } from '../types/requirement.js'\nimport { z } from 'zod/v4'\n\nexport const GetIssueDetailSchema = z.object({\n issueId: z.string().describe('The issue task ID or key (e.g. \"6W9vW3y8J9DO66Pu\" or \"task-6W9vW3y8J9DO66Pu\")'),\n source: z.string().optional().describe('Source to fetch from. If omitted, uses the default source.'),\n})\n\nexport type GetIssueDetailInput = z.infer<typeof GetIssueDetailSchema>\n\n/**\n * Download an image from URL and return as base64 data URI.\n * Returns null if download fails.\n */\nasync function downloadImageAsBase64(url: string): Promise<{ base64: string, mimeType: string } | null> {\n try {\n const res = await fetch(url, { redirect: 'follow' })\n if (!res.ok)\n return null\n\n const contentType = res.headers.get('content-type') ?? 'image/png'\n const mimeType = contentType.split(';')[0].trim()\n const buffer = Buffer.from(await res.arrayBuffer())\n return { base64: buffer.toString('base64'), mimeType }\n }\n catch {\n return null\n }\n}\n\n/**\n * Extract image URLs from HTML string.\n */\nfunction extractImageUrls(html: string): string[] {\n const imgRegex = /<img[^>]+src=\"([^\"]+)\"[^>]*>/g\n return Array.from(html.matchAll(imgRegex), m => m[1])\n .map(url => url.replace(/&/g, '&'))\n}\n\nexport async function handleGetIssueDetail(\n input: GetIssueDetailInput,\n adapters: Map<string, BaseAdapter>,\n defaultSource?: string,\n) {\n const sourceType = input.source ?? defaultSource\n if (!sourceType) {\n throw new Error('No source specified and no default source configured')\n }\n\n const adapter = adapters.get(sourceType)\n if (!adapter) {\n throw new Error(\n `Source \"${sourceType}\" is not configured. Available: ${[...adapters.keys()].join(', ')}`,\n )\n }\n\n const detail = await adapter.getIssueDetail({ issueId: input.issueId })\n\n // Extract and download images from description\n const imageUrls = detail.descriptionRich ? extractImageUrls(detail.descriptionRich) : []\n const imageResults = await Promise.all(imageUrls.map(url => downloadImageAsBase64(url)))\n\n // Build MCP content: text first, then embedded images\n const content: Array<{ type: 'text', text: string } | { type: 'image', data: string, mimeType: string }> = [\n { type: 'text' as const, text: formatIssueDetail(detail) },\n ]\n\n for (let i = 0; i < imageResults.length; i++) {\n const img = imageResults[i]\n if (img) {\n content.push({\n type: 'image' as const,\n data: img.base64,\n mimeType: img.mimeType,\n })\n }\n }\n\n return { content }\n}\n\nfunction formatIssueDetail(detail: IssueDetail): string {\n const lines = [\n `# ${detail.name}`,\n '',\n `- **Key**: ${detail.key}`,\n `- **UUID**: ${detail.uuid}`,\n `- **Type**: ${detail.issueTypeName}`,\n `- **Status**: ${detail.statusName} (${detail.statusCategory})`,\n `- **Priority**: ${detail.priorityValue ?? 'N/A'}`,\n `- **Severity**: ${detail.severityLevel ?? 'N/A'}`,\n `- **Assignee**: ${detail.assignName ?? 'Unassigned'}`,\n `- **Owner**: ${detail.ownerName ?? 'Unknown'}`,\n `- **Solver**: ${detail.solverName ?? 'Unassigned'}`,\n ]\n\n if (detail.projectName)\n lines.push(`- **Project**: ${detail.projectName}`)\n if (detail.sprintName)\n lines.push(`- **Sprint**: ${detail.sprintName}`)\n if (detail.deadline)\n lines.push(`- **Deadline**: ${detail.deadline}`)\n\n lines.push('', '## Description', '')\n if (detail.descriptionRich) {\n lines.push(detail.descriptionRich)\n }\n else if (detail.descriptionText) {\n lines.push(detail.descriptionText)\n }\n else {\n lines.push('_No description_')\n }\n\n return lines.join('\\n')\n}\n","import type { BaseAdapter } from '../adapters/base.js'\nimport type { RelatedIssue } from '../types/requirement.js'\nimport { z } from 'zod/v4'\n\nexport const GetRelatedIssuesSchema = z.object({\n taskId: z.string().describe('The parent task ID or key (e.g. \"HRL2p8rTX4mQ9xMv\" or \"task-HRL2p8rTX4mQ9xMv\")'),\n source: z.string().optional().describe('Source to fetch from. If omitted, uses the default source.'),\n})\n\nexport type GetRelatedIssuesInput = z.infer<typeof GetRelatedIssuesSchema>\n\nexport async function handleGetRelatedIssues(\n input: GetRelatedIssuesInput,\n adapters: Map<string, BaseAdapter>,\n defaultSource?: string,\n) {\n const sourceType = input.source ?? defaultSource\n if (!sourceType) {\n throw new Error('No source specified and no default source configured')\n }\n\n const adapter = adapters.get(sourceType)\n if (!adapter) {\n throw new Error(\n `Source \"${sourceType}\" is not configured. Available: ${[...adapters.keys()].join(', ')}`,\n )\n }\n\n const issues = await adapter.getRelatedIssues({ taskId: input.taskId })\n\n return {\n content: [{ type: 'text' as const, text: formatRelatedIssues(issues) }],\n }\n}\n\nfunction formatRelatedIssues(issues: RelatedIssue[]): string {\n const lines = [\n `Found **${issues.length}** pending defects:`,\n '',\n ]\n\n if (issues.length === 0) {\n lines.push('No pending defects found for this task.')\n return lines.join('\\n')\n }\n\n // Group by assignee name\n const grouped = new Map<string, RelatedIssue[]>()\n for (const issue of issues) {\n const assignee = issue.assignName ?? 'Unassigned'\n if (!grouped.has(assignee))\n grouped.set(assignee, [])\n grouped.get(assignee)!.push(issue)\n }\n\n for (const [assignee, group] of grouped) {\n lines.push(`## ${assignee} (${group.length})`)\n lines.push('')\n for (const issue of group) {\n lines.push(`### ${issue.key}: ${issue.name}`)\n lines.push(`- Status: ${issue.statusName} | Priority: ${issue.priorityValue ?? 'N/A'}`)\n if (issue.projectName) {\n lines.push(`- Project: ${issue.projectName}`)\n }\n lines.push('')\n }\n }\n\n return lines.join('\\n')\n}\n","import type { BaseAdapter } from '../adapters/base.js'\nimport { z } from 'zod/v4'\n\nexport const GetRequirementSchema = z.object({\n id: z.string().describe('The requirement/issue ID'),\n source: z.string().optional().describe('Source to fetch from. If omitted, uses the default source.'),\n})\n\nexport type GetRequirementInput = z.infer<typeof GetRequirementSchema>\n\nexport async function handleGetRequirement(\n input: GetRequirementInput,\n adapters: Map<string, BaseAdapter>,\n defaultSource?: string,\n) {\n const sourceType = input.source ?? defaultSource\n if (!sourceType) {\n throw new Error('No source specified and no default source configured')\n }\n\n const adapter = adapters.get(sourceType)\n if (!adapter) {\n throw new Error(\n `Source \"${sourceType}\" is not configured. Available: ${[...adapters.keys()].join(', ')}`,\n )\n }\n\n const requirement = await adapter.getRequirement({ id: input.id })\n\n return {\n content: [\n {\n type: 'text' as const,\n text: formatRequirement(requirement),\n },\n ],\n }\n}\n\nfunction formatRequirement(req: import('../types/requirement.js').Requirement): string {\n const lines = [\n `# ${req.title}`,\n '',\n `- **ID**: ${req.id}`,\n `- **Source**: ${req.source}`,\n `- **Status**: ${req.status}`,\n `- **Priority**: ${req.priority}`,\n `- **Type**: ${req.type}`,\n `- **Assignee**: ${req.assignee ?? 'Unassigned'}`,\n `- **Reporter**: ${req.reporter || 'Unknown'}`,\n ]\n\n if (req.createdAt) {\n lines.push(`- **Created**: ${req.createdAt}`)\n }\n if (req.updatedAt) {\n lines.push(`- **Updated**: ${req.updatedAt}`)\n }\n\n if (req.dueDate) {\n lines.push(`- **Due**: ${req.dueDate}`)\n }\n\n if (req.labels.length > 0) {\n lines.push(`- **Labels**: ${req.labels.join(', ')}`)\n }\n\n lines.push('', '## Description', '', req.description || '_No description_')\n\n if (req.attachments.length > 0) {\n lines.push('', '## Attachments')\n for (const att of req.attachments) {\n lines.push(`- [${att.name}](${att.url}) (${att.mimeType}, ${att.size} bytes)`)\n }\n }\n\n return lines.join('\\n')\n}\n","import type { BaseAdapter } from '../adapters/base.js'\nimport type { McpConfig } from '../types/config.js'\n\nexport async function handleListSources(\n adapters: Map<string, BaseAdapter>,\n config: McpConfig,\n) {\n const lines = ['# Configured Sources', '']\n\n if (adapters.size === 0) {\n lines.push('No sources configured.')\n return {\n content: [{ type: 'text' as const, text: lines.join('\\n') }],\n }\n }\n\n for (const [type, adapter] of adapters) {\n const isDefault = config.defaultSource === type\n const sourceConfig = config.sources[adapter.sourceType]\n lines.push(`## ${type}${isDefault ? ' (default)' : ''}`)\n lines.push(`- **API Base**: ${sourceConfig?.apiBase ?? 'N/A'}`)\n lines.push(`- **Auth Type**: ${sourceConfig?.auth.type ?? 'N/A'}`)\n lines.push('')\n }\n\n if (config.defaultSource) {\n lines.push(`> Default source: **${config.defaultSource}**`)\n }\n\n return {\n content: [{ type: 'text' as const, text: lines.join('\\n') }],\n }\n}\n","import type { BaseAdapter } from '../adapters/base.js'\nimport { z } from 'zod/v4'\n\nexport const SearchRequirementsSchema = z.object({\n query: z.string().describe('Search keywords'),\n source: z.string().optional().describe('Source to search. If omitted, searches the default source.'),\n page: z.number().int().min(1).optional().describe('Page number (default: 1)'),\n pageSize: z.number().int().min(1).max(50).optional().describe('Results per page (default: 20, max: 50)'),\n})\n\nexport type SearchRequirementsInput = z.infer<typeof SearchRequirementsSchema>\n\nfunction formatStatusMarker(status: string): string {\n return `[${status.toUpperCase()}]`\n}\n\nexport async function handleSearchRequirements(\n input: SearchRequirementsInput,\n adapters: Map<string, BaseAdapter>,\n defaultSource?: string,\n) {\n const sourceType = input.source ?? defaultSource\n if (!sourceType) {\n throw new Error('No source specified and no default source configured')\n }\n\n const adapter = adapters.get(sourceType)\n if (!adapter) {\n throw new Error(\n `Source \"${sourceType}\" is not configured. Available: ${[...adapters.keys()].join(', ')}`,\n )\n }\n\n const result = await adapter.searchRequirements({\n query: input.query,\n page: input.page,\n pageSize: input.pageSize,\n })\n\n const lines = [\n `Found **${result.total}** items (page ${result.page}/${Math.ceil(result.total / result.pageSize) || 1}):`,\n '',\n ]\n\n if (/\\u6211.*\\u7F3A\\u9677|bug|\\u6211.*\\u4EFB\\u52A1/i.test(input.query)) {\n lines.push(`Query: ${input.query}`)\n lines.push('Use an item ID or number in the next step to fetch detail.')\n lines.push('')\n }\n\n for (const item of result.items) {\n lines.push(`### ${formatStatusMarker(item.status)} ${item.id}: ${item.title}`)\n lines.push(`- Status: ${item.status} | Priority: ${item.priority} | Type: ${item.type}`)\n lines.push(`- Assignee: ${item.assignee ?? 'Unassigned'}`)\n const desc = item.description\n ? (item.description.length > 200 ? `${item.description.slice(0, 200)}...` : item.description)\n : '(empty)'\n lines.push(`- Content: ${desc}`)\n lines.push('')\n }\n\n return {\n content: [\n {\n type: 'text' as const,\n text: lines.join('\\n'),\n },\n ],\n }\n}\n","import type { BaseAdapter } from './adapters/index.js'\nimport type { LoadConfigResult } from './config/loader.js'\nimport { existsSync, readFileSync } from 'node:fs'\nimport { dirname, resolve } from 'node:path'\nimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'\nimport { createAdapter } from './adapters/index.js'\nimport { loadConfig } from './config/loader.js'\nimport { GetIssueDetailSchema, handleGetIssueDetail } from './tools/get-issue-detail.js'\nimport { GetRelatedIssuesSchema, handleGetRelatedIssues } from './tools/get-related-issues.js'\nimport { GetRequirementSchema, handleGetRequirement } from './tools/get-requirement.js'\nimport { handleListSources } from './tools/list-sources.js'\nimport { handleSearchRequirements, SearchRequirementsSchema } from './tools/search-requirements.js'\n\n/**\n * Load .env file into process.env (if it exists).\n * Searches from cwd upward, same as config loader.\n */\nfunction loadEnvFile() {\n let dir = process.cwd()\n while (true) {\n const envPath = resolve(dir, '.env')\n if (existsSync(envPath)) {\n const content = readFileSync(envPath, 'utf-8')\n for (const line of content.split('\\n')) {\n const trimmed = line.trim()\n if (!trimmed || trimmed.startsWith('#'))\n continue\n const eqIndex = trimmed.indexOf('=')\n if (eqIndex === -1)\n continue\n const key = trimmed.slice(0, eqIndex).trim()\n let value = trimmed.slice(eqIndex + 1).trim()\n // Strip surrounding quotes\n if ((value.startsWith('\"') && value.endsWith('\"')) || (value.startsWith('\\'') && value.endsWith('\\''))) {\n value = value.slice(1, -1)\n }\n if (!process.env[key]) {\n process.env[key] = value\n }\n }\n return\n }\n const parent = dirname(dir)\n if (parent === dir)\n break\n dir = parent\n }\n}\n\nasync function main() {\n // Load .env before anything else\n loadEnvFile()\n\n // Load config\n let config: LoadConfigResult\n try {\n config = loadConfig()\n }\n catch (err) {\n console.error(`[requirements-mcp] ${(err as Error).message}`)\n process.exit(1)\n }\n\n // Create adapters for enabled sources\n const adapters = new Map<string, BaseAdapter>()\n for (const source of config.sources) {\n const adapter = createAdapter(source.type, source.config, source.resolvedAuth)\n adapters.set(source.type, adapter)\n }\n\n // Create MCP server\n const server = new McpServer({\n name: 'ai-dev-requirements',\n version: '0.1.0',\n })\n\n // Register tools\n server.tool(\n 'get_requirement',\n 'Fetch a single requirement/issue by its ID from a configured source (ONES)',\n GetRequirementSchema.shape,\n async (params) => {\n try {\n return await handleGetRequirement(params, adapters, config.config.defaultSource)\n }\n catch (err) {\n return {\n content: [{ type: 'text', text: `Error: ${(err as Error).message}` }],\n isError: true,\n }\n }\n },\n )\n\n server.tool(\n 'search_requirements',\n 'Search for requirements/issues by keywords across a configured source',\n SearchRequirementsSchema.shape,\n async (params) => {\n try {\n return await handleSearchRequirements(params, adapters, config.config.defaultSource)\n }\n catch (err) {\n return {\n content: [{ type: 'text', text: `Error: ${(err as Error).message}` }],\n isError: true,\n }\n }\n },\n )\n\n server.tool(\n 'list_sources',\n 'List all configured requirement sources and their status',\n {},\n async () => {\n try {\n return await handleListSources(adapters, config.config)\n }\n catch (err) {\n return {\n content: [{ type: 'text', text: `Error: ${(err as Error).message}` }],\n isError: true,\n }\n }\n },\n )\n\n server.tool(\n 'get_related_issues',\n 'Get pending defect issues (bugs) related to a requirement task. Returns all pending defects grouped by assignee (current user first).',\n GetRelatedIssuesSchema.shape,\n async (params) => {\n try {\n return await handleGetRelatedIssues(params, adapters, config.config.defaultSource)\n }\n catch (err) {\n return {\n content: [{ type: 'text', text: `Error: ${(err as Error).message}` }],\n isError: true,\n }\n }\n },\n )\n\n server.tool(\n 'get_issue_detail',\n 'Get detailed information about a specific issue/defect including description, rich text, and images',\n GetIssueDetailSchema.shape,\n async (params) => {\n try {\n return await handleGetIssueDetail(params, adapters, config.config.defaultSource)\n }\n catch (err) {\n return {\n content: [{ type: 'text', text: `Error: ${(err as Error).message}` }],\n isError: true,\n }\n }\n },\n )\n\n // Start stdio transport\n const transport = new StdioServerTransport()\n await server.connect(transport)\n}\n\nmain().catch((err) => {\n console.error('[requirements-mcp] Fatal error:', err)\n process.exit(1)\n})\n"],"mappings":";;;;;;;;;AAGA,MAAM,kBAAqD;CACzD,OAAO;CACP,aAAa;CACb,MAAM;CACN,QAAQ;CACT;AAGD,MAAM,oBAAyD;CAC7D,QAAQ;CACR,MAAM;CACN,QAAQ;CACR,QAAQ;CACR,KAAK;CACN;AAGD,MAAM,gBAAiD;CACrD,QAAQ;CACR,IAAI;CACJ,MAAM;CACN,IAAI;CACJ,KAAK;CACL,IAAI;CACJ,OAAO;CACP,KAAK;CACL,IAAI;CACJ,MAAM;CACP;AAED,SAAgB,cAAc,QAAmC;AAC/D,QAAO,gBAAgB,OAAO,aAAa,KAAK;;AAGlD,SAAgB,gBAAgB,UAAuC;AACrE,QAAO,kBAAkB,SAAS,aAAa,KAAK;;AAGtD,SAAgB,YAAY,MAA+B;AACzD,QAAO,cAAc,KAAK,aAAa,KAAK;;;;;;;;;ACjB9C,IAAsB,cAAtB,MAAkC;CAChC,AAAS;CACT,AAAmB;CACnB,AAAmB;CAEnB,YACE,YACA,QACA,cACA;AACA,OAAK,aAAa;AAClB,OAAK,SAAS;AACd,OAAK,eAAe;;;;;;AC4DxB,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6B1B,MAAM,qBAAqB;;;;;;;;;;;;;;;AAgB3B,MAAM,oBAAoB;;;;;;;;;AAW1B,MAAM,uBAAuB;AAC7B,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiC5B,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;AAuB3B,MAAM,wBAAwB;CAAC;CAAY;CAAY;CAAY;CAAW;AA4B9E,SAAS,sBAAsB,OAAiC;AAC9D,KAAI,CAAC,MACH,QAAO;CAET,MAAM,aAAa,MAAM,aAAa;AAEtC,KAAI,MAAM,SAAS,KAAe,IAAI,WAAW,SAAS,MAAM,C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M,YAAY,IAAI,sBAAsB;AAC5C,OAAM,OAAO,QAAQ,UAAU;;AAGjC,MAAM,CAAC,OAAO,QAAQ;AACpB,SAAQ,MAAM,mCAAmC,IAAI;AACrD,SAAQ,KAAK,EAAE;EACf"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai-dev-requirements",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"packageManager": "pnpm@10.28.1",
|
|
5
5
|
"description": "MCP server for fetching requirements from ONES, bundled with a parallel task framework for AI-assisted development",
|
|
6
6
|
"type": "module",
|