ework3-task-mcp 0.1.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +170 -152
  2. package/dist/index.js +1982 -92
  3. package/package.json +41 -41
package/dist/index.js CHANGED
@@ -21560,6 +21560,24 @@ var StdioServerTransport = class {
21560
21560
  }
21561
21561
  };
21562
21562
 
21563
+ // ../../packages/core/src/async.ts
21564
+ async function mapLimit(items, limit, fn) {
21565
+ const results = new Array(items.length);
21566
+ let next = 0;
21567
+ const workers = Array.from(
21568
+ { length: Math.min(Math.max(limit, 1), items.length) },
21569
+ async () => {
21570
+ while (next < items.length) {
21571
+ const index = next;
21572
+ next += 1;
21573
+ results[index] = await fn(items[index], index);
21574
+ }
21575
+ }
21576
+ );
21577
+ await Promise.all(workers);
21578
+ return results;
21579
+ }
21580
+
21563
21581
  // ../../packages/core/src/config.ts
21564
21582
  var DEFAULT_BASE_URL = "https://eazytec.ygzuo.com";
21565
21583
  function loadConfig(env = process.env) {
@@ -22820,6 +22838,551 @@ function toNumericId(value) {
22820
22838
  return Number.isFinite(numeric) ? numeric : value;
22821
22839
  }
22822
22840
 
22841
+ // src/domain/groups.ts
22842
+ var MAX_GROUPS_FOR_COUNTS = 30;
22843
+ var MAX_GROUPS_FOR_LOOKUP = 30;
22844
+ var MAX_BATCH_TASKS = 50;
22845
+ var GROUP_LOOKUP_CONCURRENCY = 10;
22846
+ var GROUP_NAME_MAX_LENGTH = 30;
22847
+ function isNoGroupTarget(value) {
22848
+ const text = value.trim().toLowerCase();
22849
+ return text === "" || text === "\u672A\u5206\u7EC4" || text === "none" || text === "no_group";
22850
+ }
22851
+ function validateGroupName(value, label = "\u5206\u7EC4\u540D\u79F0") {
22852
+ const name = value.trim();
22853
+ if (!name) {
22854
+ throw new EworkError(`${label}\u4E0D\u80FD\u4E3A\u7A7A`);
22855
+ }
22856
+ if (name.length > GROUP_NAME_MAX_LENGTH) {
22857
+ throw new EworkError(
22858
+ `${label}\u8FC7\u957F\uFF08${name.length} \u5B57\u7B26\uFF09\uFF0C\u6700\u591A ${GROUP_NAME_MAX_LENGTH} \u5B57\u7B26`
22859
+ );
22860
+ }
22861
+ return name;
22862
+ }
22863
+ function findDuplicateGroup(groups, name, excludeId) {
22864
+ const target = name.trim();
22865
+ return groups.find(
22866
+ (group) => String(group.id ?? "") !== excludeId && String(group.groupName ?? "").trim() === target
22867
+ );
22868
+ }
22869
+ function matchGroup(input, groups) {
22870
+ const value = input.trim();
22871
+ if (!value) {
22872
+ return {
22873
+ ok: false,
22874
+ message: "\u8BF7\u63D0\u4F9B\u5206\u7EC4\u540D\u79F0\u6216\u5206\u7EC4 id",
22875
+ candidates: [],
22876
+ available: groups.map(toCandidate)
22877
+ };
22878
+ }
22879
+ const byId = groups.filter((group) => String(group.id ?? "") === value);
22880
+ if (byId.length === 1) {
22881
+ return { ok: true, group: byId[0] };
22882
+ }
22883
+ const byName = groups.filter(
22884
+ (group) => String(group.groupName ?? "").trim() === value
22885
+ );
22886
+ if (byName.length === 1) {
22887
+ return { ok: true, group: byName[0] };
22888
+ }
22889
+ if (byName.length > 1) {
22890
+ return {
22891
+ ok: false,
22892
+ message: `\u5206\u7EC4\u540D\u79F0\u300C${value}\u300D\u6709 ${byName.length} \u4E2A\u540C\u540D\u5206\u7EC4\uFF0C\u8BF7\u6539\u7528\u5206\u7EC4 id \u6307\u5B9A`,
22893
+ candidates: byName.map(toCandidate)
22894
+ };
22895
+ }
22896
+ if (!groups.length) {
22897
+ return {
22898
+ ok: false,
22899
+ message: `\u6CA1\u6709\u627E\u5230\u5206\u7EC4\u300C${value}\u300D\uFF1B\u5F53\u524D\u5458\u5DE5\u8FD8\u6CA1\u6709\u5206\u7EC4\uFF0C\u53EF\u7528 manage_task_group \u521B\u5EFA`,
22900
+ candidates: [],
22901
+ available: []
22902
+ };
22903
+ }
22904
+ return {
22905
+ ok: false,
22906
+ message: `\u6CA1\u6709\u627E\u5230\u5206\u7EC4\u300C${value}\u300D`,
22907
+ candidates: [],
22908
+ available: groups.map(toCandidate)
22909
+ };
22910
+ }
22911
+ async function resolveTaskGroup(ctx, input) {
22912
+ const groups = await loadPersonalGroups(ctx);
22913
+ return matchGroup(input, groups);
22914
+ }
22915
+ async function loadPersonalGroups(ctx) {
22916
+ const raw = await ctx.client.requestRaw(
22917
+ "POST",
22918
+ "/external/home/task/setting/loadEmpGroups",
22919
+ { json: { type: "T" }, write: false }
22920
+ );
22921
+ return raw.result ?? [];
22922
+ }
22923
+ async function groupTaskCount(ctx, groupId) {
22924
+ const raw = await ctx.client.requestRaw(
22925
+ "POST",
22926
+ "/external/home/task/v2/query/loadByParamsInPage",
22927
+ {
22928
+ json: {
22929
+ groupId,
22930
+ isTopTask: "N",
22931
+ current: 1,
22932
+ size: 1
22933
+ },
22934
+ write: false
22935
+ }
22936
+ );
22937
+ return Number(raw.total ?? 0);
22938
+ }
22939
+ async function taskGroupMembership(ctx, taskIds, groups) {
22940
+ if (groups.length > MAX_GROUPS_FOR_LOOKUP) {
22941
+ throw new EworkError(
22942
+ `\u5206\u7EC4\u6570\u91CF\u8D85\u8FC7 ${MAX_GROUPS_FOR_LOOKUP} \u4E2A\uFF0C\u65E0\u6CD5\u81EA\u52A8\u786E\u8BA4\u4EFB\u52A1\u6240\u5C5E\u5206\u7EC4\uFF1B\u8BF7\u5148\u5728\u7F51\u9875\u6574\u7406\u5206\u7EC4\uFF0C\u6216\u5206\u6B21\u5904\u7406`
22943
+ );
22944
+ }
22945
+ const result = /* @__PURE__ */ new Map();
22946
+ for (const taskId of taskIds) {
22947
+ result.set(taskId, []);
22948
+ }
22949
+ if (!taskIds.length) {
22950
+ return result;
22951
+ }
22952
+ const wanted = new Set(taskIds);
22953
+ const groupIds = groups.map((group) => String(group.id ?? "")).filter(Boolean);
22954
+ await mapLimit(groupIds, GROUP_LOOKUP_CONCURRENCY, async (groupId) => {
22955
+ const raw = await ctx.client.requestRaw(
22956
+ "POST",
22957
+ "/external/home/task/v2/query/loadByParamsInPage",
22958
+ {
22959
+ json: {
22960
+ groupId,
22961
+ taskIds,
22962
+ isTopTask: "N",
22963
+ current: 1,
22964
+ size: taskIds.length
22965
+ },
22966
+ write: false
22967
+ }
22968
+ );
22969
+ for (const item of raw.result ?? []) {
22970
+ const taskId = String(item.id ?? "");
22971
+ if (wanted.has(taskId)) {
22972
+ result.get(taskId)?.push(groupId);
22973
+ }
22974
+ }
22975
+ });
22976
+ for (const ids of result.values()) {
22977
+ ids.sort();
22978
+ }
22979
+ return result;
22980
+ }
22981
+ async function isTaskInGroup(ctx, taskId, groupId) {
22982
+ const membership = await taskGroupMembership(ctx, [taskId], [{ id: groupId }]);
22983
+ return (membership.get(taskId) ?? []).includes(groupId);
22984
+ }
22985
+ function dedupeTaskIds(taskIds) {
22986
+ return Array.from(
22987
+ new Set(taskIds.map((taskId) => taskId.trim()).filter(Boolean))
22988
+ ).sort();
22989
+ }
22990
+ function planGroupAssignments(tasks, membership, targetGroupId) {
22991
+ return tasks.map((task) => {
22992
+ const sourceGroupIds = Array.from(
22993
+ new Set(membership.get(task.taskId) ?? [])
22994
+ ).sort();
22995
+ let action;
22996
+ if (targetGroupId) {
22997
+ if (sourceGroupIds.length === 1 && sourceGroupIds[0] === targetGroupId) {
22998
+ action = "unchanged";
22999
+ } else {
23000
+ action = sourceGroupIds.length === 0 ? "add" : "move";
23001
+ }
23002
+ } else {
23003
+ action = sourceGroupIds.length === 0 ? "unchanged" : "remove";
23004
+ }
23005
+ return { ...task, sourceGroupIds, action };
23006
+ });
23007
+ }
23008
+ function sameGroupIds(actual, expected) {
23009
+ if (actual.length !== expected.length) {
23010
+ return false;
23011
+ }
23012
+ const set = new Set(actual);
23013
+ return expected.every((id) => set.has(id));
23014
+ }
23015
+ function formatGroupCandidate(group) {
23016
+ const count = group.taskCount === void 0 ? "" : ` \u4EFB\u52A1 ${group.taskCount} \u6761`;
23017
+ return `- ${group.name || "\uFF08\u65E0\u540D\u79F0\uFF09"}\uFF08${group.id}\uFF09${count}`;
23018
+ }
23019
+ function formatGroupFailure(resolution) {
23020
+ const lines = [resolution.message];
23021
+ if (resolution.candidates.length) {
23022
+ lines.push("\u5019\u9009\u5206\u7EC4\uFF1A");
23023
+ lines.push(...resolution.candidates.map(formatGroupCandidate));
23024
+ }
23025
+ if (resolution.available?.length) {
23026
+ lines.push("\u53EF\u7528\u5206\u7EC4\uFF1A");
23027
+ lines.push(...resolution.available.map(formatGroupCandidate));
23028
+ }
23029
+ return lines.join("\n");
23030
+ }
23031
+ function groupToCandidate(group, taskCount) {
23032
+ return {
23033
+ id: String(group.id ?? ""),
23034
+ name: String(group.groupName ?? ""),
23035
+ seq: group.seq,
23036
+ taskCount
23037
+ };
23038
+ }
23039
+ function toCandidate(group) {
23040
+ return groupToCandidate(group);
23041
+ }
23042
+
23043
+ // src/tools/assignTaskGroup.ts
23044
+ var DETAIL_CONCURRENCY = 10;
23045
+ var MAX_TEXT_LINES = 20;
23046
+ function registerAssignTaskToGroup(server, ctx) {
23047
+ server.registerTool(
23048
+ "assign_task_to_group",
23049
+ {
23050
+ title: "\u628A\u4EFB\u52A1\u79FB\u5165\u6216\u79FB\u51FA\u5206\u7EC4",
23051
+ description: "\u628A\u4EFB\u52A1\u79FB\u5165\u5F53\u524D API Key \u5458\u5DE5\u7684\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\u3001\u5728\u5206\u7EC4\u95F4\u79FB\u52A8\uFF0C\u6216\u79FB\u51FA\u5206\u7EC4\u3002\u5355\u4E2A\u4EFB\u52A1\u7528 taskId/url\uFF0C\u6279\u91CF\u7528 taskIds\uFF08\u6700\u591A 50 \u4E2A\uFF09\uFF1Bgroup \u4F20\u5206\u7EC4\u540D\u79F0\u6216 id\uFF0C\u4F20\u300C\u672A\u5206\u7EC4\u300D\u300Cnone\u300D\u6216\u7A7A\u4E32\u8868\u793A\u79FB\u51FA\u6240\u6709\u5206\u7EC4\u3002\u53EA\u8981\u6C42\u4EFB\u52A1\u5BF9\u5F53\u524D\u5458\u5DE5\u53EF\u89C1\uFF1B\u5206\u7EC4\u53EA\u6539\u4E2A\u4EBA\u770B\u677F\uFF0C\u4E0D\u6539\u4EFB\u52A1\u672C\u8EAB\u3002\u5FC5\u987B\u5148\u4E0D\u5E26 confirm \u8C03\u7528\u62FF previewToken\uFF0C\u628A\u9884\u6F14\u5C55\u793A\u7ED9\u7528\u6237\u5E76\u53D6\u5F97\u660E\u786E\u540C\u610F\u540E\uFF0C\u518D\u5E26 previewToken \u548C confirm=true \u6267\u884C\u3002",
23052
+ inputSchema: {
23053
+ taskId: external_exports.string().optional().describe("\u5355\u4E2A\u4EFB\u52A1\u7F16\u53F7\uFF1B\u6279\u91CF\u7528 taskIds"),
23054
+ url: external_exports.string().optional().describe("\u5355\u4E2A\u4EFB\u52A1\u94FE\u63A5\uFF1B\u6279\u91CF\u7528 taskIds"),
23055
+ taskIds: external_exports.array(external_exports.string()).optional().describe("\u6279\u91CF\u4EFB\u52A1\u7F16\u53F7\uFF08\u6700\u591A 50 \u4E2A\uFF09\uFF1B\u4E0E taskId/url \u4E8C\u9009\u4E00"),
23056
+ group: external_exports.string().describe("\u76EE\u6807\u5206\u7EC4\u540D\u79F0\u6216 id\uFF1B\u4F20\u300C\u672A\u5206\u7EC4\u300D\u300Cnone\u300D\u6216\u7A7A\u4E32\u8868\u793A\u79FB\u51FA\u5206\u7EC4"),
23057
+ confirm: external_exports.boolean().optional().describe("true \u624D\u771F\u6B63\u5199\u5165\uFF1B\u7F3A\u7701\u53EA\u9884\u6F14"),
23058
+ previewToken: external_exports.string().optional().describe("\u9884\u6F14\u8FD4\u56DE\u7684\u4EE4\u724C\uFF1Bconfirm=true \u65F6\u5FC5\u586B")
23059
+ },
23060
+ annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false }
23061
+ },
23062
+ async (args) => {
23063
+ try {
23064
+ return await handleAssign(ctx, args);
23065
+ } catch (error2) {
23066
+ return fail(error2);
23067
+ }
23068
+ }
23069
+ );
23070
+ }
23071
+ async function handleAssign(ctx, args) {
23072
+ const taskIds = resolveTaskIds(ctx, args);
23073
+ const groups = await loadPersonalGroups(ctx);
23074
+ const target = resolveTargetGroup(args.group, groups);
23075
+ const membership = await taskGroupMembership(ctx, taskIds, groups);
23076
+ const details = await mapLimit(taskIds, DETAIL_CONCURRENCY, async (taskId) => ({
23077
+ taskId,
23078
+ title: taskTitle(await loadDetail(ctx, taskId))
23079
+ }));
23080
+ const items = planGroupAssignments(details, membership, target?.id ?? null);
23081
+ const changedItems = items.filter((item) => item.action !== "unchanged");
23082
+ if (!changedItems.length) {
23083
+ return ok(formatUnchangedText(taskIds, target), {
23084
+ taskIds,
23085
+ ...singleTaskField(taskIds),
23086
+ targetGroup: target ?? null,
23087
+ changed: false,
23088
+ verified: true,
23089
+ unchanged: taskIds,
23090
+ items: toOutputItems(items, groups)
23091
+ });
23092
+ }
23093
+ const payload = {
23094
+ action: target ? "assign" : "remove",
23095
+ targetGroupId: target?.id ?? null,
23096
+ items: items.map((item) => ({
23097
+ taskId: item.taskId,
23098
+ sourceGroupIds: item.sourceGroupIds
23099
+ }))
23100
+ };
23101
+ const preview = formatAssignPreview(items, target, groups);
23102
+ if (!args.confirm) {
23103
+ const previewToken = createPreviewToken(
23104
+ "assign_task_to_group",
23105
+ taskIds.join(","),
23106
+ payload
23107
+ );
23108
+ return ok(`${preview}
23109
+ previewToken\uFF1A${previewToken}
23110
+ \u8BF7\u786E\u8BA4\u540E\u5E26 previewToken \u4E0E confirm=true \u6267\u884C\u3002`, {
23111
+ taskIds,
23112
+ ...singleTaskField(taskIds),
23113
+ targetGroup: target ?? null,
23114
+ items: toOutputItems(items, groups),
23115
+ previewToken,
23116
+ expiresInSeconds: previewTtlSeconds()
23117
+ });
23118
+ }
23119
+ consumePreviewToken(
23120
+ args.previewToken,
23121
+ "assign_task_to_group",
23122
+ taskIds.join(","),
23123
+ payload
23124
+ );
23125
+ const failures = [];
23126
+ for (const item of changedItems) {
23127
+ try {
23128
+ await writeAssignment(ctx, item, target);
23129
+ } catch (error2) {
23130
+ failures.push({
23131
+ taskId: item.taskId,
23132
+ message: error2 instanceof Error ? error2.message : String(error2)
23133
+ });
23134
+ }
23135
+ }
23136
+ let afterGroups = [];
23137
+ let afterMembership = /* @__PURE__ */ new Map();
23138
+ let verifyError;
23139
+ try {
23140
+ afterGroups = await loadPersonalGroups(ctx);
23141
+ afterMembership = await taskGroupMembership(ctx, taskIds, afterGroups);
23142
+ } catch (error2) {
23143
+ verifyError = error2 instanceof Error ? error2.message : String(error2);
23144
+ }
23145
+ const expectedGroupIds = target ? [target.id] : [];
23146
+ const failureIds = new Set(failures.map((failure) => failure.taskId));
23147
+ const mismatched = verifyError ? [] : changedItems.filter((item) => !failureIds.has(item.taskId)).filter(
23148
+ (item) => !sameGroupIds(
23149
+ afterMembership.get(item.taskId) ?? [],
23150
+ expectedGroupIds
23151
+ )
23152
+ ).map((item) => ({
23153
+ taskId: item.taskId,
23154
+ after: describeGroups(
23155
+ afterGroups,
23156
+ afterMembership.get(item.taskId) ?? []
23157
+ )
23158
+ }));
23159
+ const verified = !verifyError && failures.length === 0 && mismatched.length === 0;
23160
+ const text = formatAssignResult({
23161
+ items,
23162
+ target,
23163
+ failures,
23164
+ mismatched,
23165
+ verifyError
23166
+ });
23167
+ return ok(text, {
23168
+ taskIds,
23169
+ ...singleTaskField(taskIds),
23170
+ targetGroup: target ?? null,
23171
+ changed: changedItems.map((item) => item.taskId),
23172
+ unchanged: items.filter((item) => item.action === "unchanged").map((item) => item.taskId),
23173
+ failed: failures,
23174
+ ...verifyError ? { verifyError } : {},
23175
+ verified,
23176
+ items: items.map((item) => ({
23177
+ taskId: item.taskId,
23178
+ title: item.title,
23179
+ action: item.action,
23180
+ beforeGroups: describeGroups(groups, item.sourceGroupIds),
23181
+ ...verifyError ? {} : {
23182
+ afterGroups: describeGroups(
23183
+ afterGroups,
23184
+ afterMembership.get(item.taskId) ?? []
23185
+ )
23186
+ }
23187
+ }))
23188
+ });
23189
+ }
23190
+ function resolveTaskIds(ctx, args) {
23191
+ const batch = dedupeTaskIds(args.taskIds ?? []);
23192
+ if (batch.length && (args.taskId?.trim() || args.url?.trim())) {
23193
+ throw new EworkError(
23194
+ "taskIds \u4E0E taskId/url \u53EA\u80FD\u4E8C\u9009\u4E00\uFF1A\u6279\u91CF\u7528 taskIds\uFF0C\u5355\u6761\u7528 taskId \u6216 url"
23195
+ );
23196
+ }
23197
+ if (batch.length) {
23198
+ if (batch.length > MAX_BATCH_TASKS) {
23199
+ throw new EworkError(
23200
+ `\u4E00\u6B21\u6700\u591A\u5904\u7406 ${MAX_BATCH_TASKS} \u4E2A\u4EFB\u52A1\uFF08\u6536\u5230 ${batch.length} \u4E2A\uFF09\uFF1B\u8BF7\u5206\u6279\u5904\u7406`
23201
+ );
23202
+ }
23203
+ return batch.map((taskId) => resolveTaskId(taskId, void 0, ctx.baseUrl));
23204
+ }
23205
+ return [resolveTaskInput(ctx, args.taskId, args.url)];
23206
+ }
23207
+ function resolveTargetGroup(input, groups) {
23208
+ if (isNoGroupTarget(input)) {
23209
+ return void 0;
23210
+ }
23211
+ const resolution = matchGroup(input, groups);
23212
+ if (!resolution.ok) {
23213
+ throw new EworkError(formatGroupFailure(resolution));
23214
+ }
23215
+ const id = String(resolution.group.id ?? "").trim();
23216
+ if (!id) {
23217
+ throw new EworkError(`\u5206\u7EC4\u300C${resolution.group.groupName ?? input}\u300D\u7F3A\u5C11\u5206\u7EC4 id\uFF0C\u65E0\u6CD5\u5199\u5165`);
23218
+ }
23219
+ return {
23220
+ id,
23221
+ name: String(resolution.group.groupName ?? "")
23222
+ };
23223
+ }
23224
+ async function writeAssignment(ctx, item, target) {
23225
+ if (!target) {
23226
+ for (const sourceGroupId of item.sourceGroupIds) {
23227
+ await removeTaskFromGroup(ctx, sourceGroupId, item.taskId);
23228
+ }
23229
+ return;
23230
+ }
23231
+ if (!item.sourceGroupIds.length) {
23232
+ await addTaskToGroup(ctx, target.id, item.taskId);
23233
+ return;
23234
+ }
23235
+ const moveIndex = item.sourceGroupIds.findIndex((id) => id !== target.id);
23236
+ const fromGroupId = moveIndex >= 0 ? item.sourceGroupIds[moveIndex] : item.sourceGroupIds[0];
23237
+ const restSources = item.sourceGroupIds.filter(
23238
+ (id, index) => index !== moveIndex && id !== target.id
23239
+ );
23240
+ await moveTaskBetweenGroups(ctx, fromGroupId, target.id, item.taskId);
23241
+ for (const sourceGroupId of restSources) {
23242
+ await removeTaskFromGroup(ctx, sourceGroupId, item.taskId);
23243
+ }
23244
+ }
23245
+ async function addTaskToGroup(ctx, groupId, taskId) {
23246
+ await ctx.client.post("/external/home/task/setting/addTaskInGroup", {
23247
+ groupId,
23248
+ relId: taskId
23249
+ });
23250
+ }
23251
+ async function removeTaskFromGroup(ctx, groupId, taskId) {
23252
+ await ctx.client.post("/external/home/task/setting/removeTaskInGroup", {
23253
+ groupId,
23254
+ relId: taskId
23255
+ });
23256
+ }
23257
+ async function moveTaskBetweenGroups(ctx, fromGroupId, toGroupId, taskId) {
23258
+ await ctx.client.post("/external/home/task/setting/fromToTaskInGroup", {
23259
+ type: "GROUP",
23260
+ fromGroupId,
23261
+ groupId: toGroupId,
23262
+ relId: taskId
23263
+ });
23264
+ }
23265
+ function describeGroups(groups, groupIds) {
23266
+ return groupIds.map((id) => {
23267
+ const group = groups.find((item) => String(item.id ?? "") === id);
23268
+ return { id, name: String(group?.groupName ?? "").trim() || id };
23269
+ });
23270
+ }
23271
+ function singleTaskField(taskIds) {
23272
+ return taskIds.length === 1 ? { taskId: taskIds[0] } : {};
23273
+ }
23274
+ function toOutputItems(items, groups) {
23275
+ return items.map((item) => ({
23276
+ taskId: item.taskId,
23277
+ title: item.title,
23278
+ action: item.action,
23279
+ beforeGroups: describeGroups(groups, item.sourceGroupIds)
23280
+ }));
23281
+ }
23282
+ function formatUnchangedText(taskIds, target) {
23283
+ const multiple = taskIds.length > 1;
23284
+ if (target) {
23285
+ return multiple ? `${taskIds.length} \u6761\u4EFB\u52A1\u90FD\u5DF2\u5728\u5206\u7EC4\u300C${target.name}\u300D\u4E2D\uFF0C\u65E0\u9700\u4FEE\u6539\u3002` : `\u4EFB\u52A1 ${taskIds[0]} \u5DF2\u7ECF\u5728\u5206\u7EC4\u300C${target.name}\u300D\u4E2D\uFF0C\u65E0\u9700\u4FEE\u6539\u3002`;
23286
+ }
23287
+ return multiple ? `${taskIds.length} \u6761\u4EFB\u52A1\u672C\u6765\u5C31\u4E0D\u5728\u4EFB\u4F55\u4E2A\u4EBA\u5206\u7EC4\u4E2D\uFF0C\u65E0\u9700\u4FEE\u6539\u3002` : `\u4EFB\u52A1 ${taskIds[0]} \u672C\u6765\u5C31\u4E0D\u5728\u4EFB\u4F55\u4E2A\u4EBA\u5206\u7EC4\u4E2D\uFF0C\u65E0\u9700\u4FEE\u6539\u3002`;
23288
+ }
23289
+ function formatAssignPreview(items, target, groups) {
23290
+ const lines = [
23291
+ "\u4EFB\u52A1\u5206\u7EC4\u9884\u6F14\uFF08\u672A\u5199\u5165\uFF09\uFF1A",
23292
+ target ? `\u76EE\u6807\u5206\u7EC4\uFF1A${target.name}\uFF08${target.id}\uFF09` : "\u76EE\u6807\u5206\u7EC4\uFF1A\u672A\u5206\u7EC4\uFF08\u79FB\u51FA\u6240\u6709\u5206\u7EC4\uFF09"
23293
+ ];
23294
+ for (const item of items.slice(0, MAX_TEXT_LINES)) {
23295
+ const sources = describeGroups(groups, item.sourceGroupIds);
23296
+ lines.push(
23297
+ `- [${actionLabel(item.action)}] ${item.title}\uFF08${item.taskId}\uFF09 \u5F53\u524D\uFF1A${sources.length ? formatGroupNames(sources) : "\u672A\u5206\u7EC4"}`
23298
+ );
23299
+ }
23300
+ if (items.length > MAX_TEXT_LINES) {
23301
+ lines.push(`\u2026\u53E6\u6709 ${items.length - MAX_TEXT_LINES} \u6761\u672A\u5C55\u5F00`);
23302
+ }
23303
+ lines.push(summaryText(items));
23304
+ lines.push("\u4EFB\u52A1\u53EA\u80FD\u4FDD\u7559\u4E00\u4E2A\u4E2A\u4EBA\u5206\u7EC4\uFF1B\u786E\u8BA4\u540E\u4F1A\u4ECE\u5176\u4ED6\u5206\u7EC4\u79FB\u9664\u3002");
23305
+ return lines.join("\n");
23306
+ }
23307
+ function formatAssignResult(params) {
23308
+ const { items, target, failures, mismatched, verifyError } = params;
23309
+ const failureIds = new Set(failures.map((failure) => failure.taskId));
23310
+ const changedItems = items.filter((item) => item.action !== "unchanged");
23311
+ const succeededCount = changedItems.filter(
23312
+ (item) => !failureIds.has(item.taskId)
23313
+ ).length;
23314
+ const unchangedCount = items.length - changedItems.length;
23315
+ const lines = [];
23316
+ if (changedItems.length) {
23317
+ const failureSuffix = failures.length ? `\uFF0C${failures.length} \u6761\u5199\u5165\u5931\u8D25` : "";
23318
+ lines.push(
23319
+ target ? `\u5DF2\u628A ${succeededCount} \u6761\u4EFB\u52A1\u79FB\u5230\u5206\u7EC4\u300C${target.name}\u300D${failureSuffix}\u3002` : `\u5DF2\u628A ${succeededCount} \u6761\u4EFB\u52A1\u79FB\u51FA\u6240\u6709\u4E2A\u4EBA\u5206\u7EC4${failureSuffix}\u3002`
23320
+ );
23321
+ } else {
23322
+ lines.push("\u6CA1\u6709\u9700\u8981\u4FEE\u6539\u7684\u4EFB\u52A1\u3002");
23323
+ }
23324
+ if (unchangedCount) {
23325
+ lines.push(`${unchangedCount} \u6761\u4EFB\u52A1\u65E0\u9700\u4FEE\u6539\u3002`);
23326
+ }
23327
+ if (failures.length) {
23328
+ lines.push("\u5931\u8D25\uFF1A");
23329
+ for (const failure of failures.slice(0, MAX_TEXT_LINES)) {
23330
+ lines.push(`- ${failure.taskId}\uFF1A${failure.message}`);
23331
+ }
23332
+ if (failures.length > MAX_TEXT_LINES) {
23333
+ lines.push(`\u2026\u53E6\u6709 ${failures.length - MAX_TEXT_LINES} \u6761\u5931\u8D25\u672A\u5C55\u5F00`);
23334
+ }
23335
+ }
23336
+ if (verifyError) {
23337
+ lines.push(`\u5199\u5165\u5DF2\u63D0\u4EA4\uFF0C\u4F46\u56DE\u8BFB\u5931\u8D25\uFF1A${verifyError}\uFF1B\u8BF7\u624B\u52A8\u68C0\u67E5\u3002`);
23338
+ } else if (mismatched.length) {
23339
+ lines.push("\u56DE\u8BFB\u4E0E\u9884\u671F\u4E0D\u4E00\u81F4\uFF0C\u8BF7\u624B\u52A8\u68C0\u67E5\uFF1A");
23340
+ for (const item of mismatched.slice(0, MAX_TEXT_LINES)) {
23341
+ lines.push(
23342
+ `- ${item.taskId} \u5F53\u524D\u5728\uFF1A${item.after.length ? formatGroupNames(item.after) : "\u672A\u5206\u7EC4"}`
23343
+ );
23344
+ }
23345
+ if (mismatched.length > MAX_TEXT_LINES) {
23346
+ lines.push(`\u2026\u53E6\u6709 ${mismatched.length - MAX_TEXT_LINES} \u6761\u672A\u5C55\u5F00`);
23347
+ }
23348
+ } else if (changedItems.length) {
23349
+ lines.push("\u56DE\u8BFB\u5DF2\u786E\u8BA4\u3002");
23350
+ }
23351
+ return lines.join("\n");
23352
+ }
23353
+ function summaryText(items) {
23354
+ const counts = {
23355
+ add: 0,
23356
+ move: 0,
23357
+ remove: 0,
23358
+ unchanged: 0
23359
+ };
23360
+ for (const item of items) {
23361
+ counts[item.action] += 1;
23362
+ }
23363
+ const parts = [];
23364
+ if (counts.add) parts.push(`\u52A0\u5165 ${counts.add}`);
23365
+ if (counts.move) parts.push(`\u79FB\u52A8 ${counts.move}`);
23366
+ if (counts.remove) parts.push(`\u79FB\u51FA ${counts.remove}`);
23367
+ if (counts.unchanged) parts.push(`\u65E0\u9700\u4FEE\u6539 ${counts.unchanged}`);
23368
+ return `\u5171 ${items.length} \u6761\uFF1A${parts.join("\u3001")}`;
23369
+ }
23370
+ function actionLabel(action) {
23371
+ switch (action) {
23372
+ case "add":
23373
+ return "\u52A0\u5165";
23374
+ case "move":
23375
+ return "\u79FB\u52A8";
23376
+ case "remove":
23377
+ return "\u79FB\u51FA";
23378
+ default:
23379
+ return "\u65E0\u9700\u4FEE\u6539";
23380
+ }
23381
+ }
23382
+ function formatGroupNames(groups) {
23383
+ return groups.map((group) => `${group.name}\uFF08${group.id}\uFF09`).join("\u3001");
23384
+ }
23385
+
22823
23386
  // src/domain/members.ts
22824
23387
  function collectMembers(detail) {
22825
23388
  const members = [];
@@ -22855,6 +23418,62 @@ function dedupe(members) {
22855
23418
  return result;
22856
23419
  }
22857
23420
 
23421
+ // src/domain/employees.ts
23422
+ async function resolveEmployee(ctx, input) {
23423
+ const keyword = input.trim();
23424
+ if (!keyword) {
23425
+ return { ok: false, message: "\u8BF7\u63D0\u4F9B\u5458\u5DE5\u59D3\u540D\u6216 empId", candidates: [] };
23426
+ }
23427
+ const list = await ctx.client.get("/external/base/sel2/emp", { queryKey: keyword }) ?? [];
23428
+ const byId = list.find((emp) => emp.id === keyword);
23429
+ if (byId) {
23430
+ return { ok: true, emp: byId };
23431
+ }
23432
+ const sameName = list.filter((emp) => emp.name === keyword);
23433
+ if (sameName.length === 1) {
23434
+ return { ok: true, emp: sameName[0] };
23435
+ }
23436
+ if (sameName.length > 1) {
23437
+ return {
23438
+ ok: false,
23439
+ message: `\u300C${keyword}\u300D\u6709 ${sameName.length} \u4E2A\u540C\u540D\u5458\u5DE5\uFF0C\u8BF7\u6539\u7528 empId \u6307\u5B9A`,
23440
+ candidates: sameName
23441
+ };
23442
+ }
23443
+ if (list.length === 1) {
23444
+ return {
23445
+ ok: false,
23446
+ message: `\u6CA1\u6709\u7CBE\u786E\u5339\u914D\u5230\u5458\u5DE5\u300C${keyword}\u300D\uFF1B\u53EA\u627E\u5230\u4E00\u4E2A\u76F8\u8FD1\u7ED3\u679C\uFF0C\u8BF7\u786E\u8BA4\u59D3\u540D\u6216\u6539\u7528 empId`,
23447
+ candidates: list
23448
+ };
23449
+ }
23450
+ return {
23451
+ ok: false,
23452
+ message: list.length ? `\u300C${keyword}\u300D\u5339\u914D\u5230\u591A\u4E2A\u5458\u5DE5\uFF0C\u8BF7\u6539\u7528 empId \u6307\u5B9A` : `\u6CA1\u6709\u627E\u5230\u5458\u5DE5\u300C${keyword}\u300D\uFF1B\u8BF7\u63D0\u4F9B\u66F4\u5B8C\u6574\u7684\u59D3\u540D\uFF0C\u6216\u5148\u7528 search_employee \u67E5\u8BE2`,
23453
+ candidates: list
23454
+ };
23455
+ }
23456
+ async function resolveEmployeeOrThrow(ctx, input) {
23457
+ const resolution = await resolveEmployee(ctx, input);
23458
+ if (!resolution.ok) {
23459
+ throw new EworkError(
23460
+ resolution.candidates.length ? `${resolution.message}
23461
+ \u5019\u9009\uFF1A
23462
+ ${formatCandidates(resolution.candidates)}` : resolution.message
23463
+ );
23464
+ }
23465
+ return resolution.emp;
23466
+ }
23467
+ function formatCandidates(list) {
23468
+ return list.map((emp) => `- ${emp.name || "-"}\uFF08${emp.id || "-"}\uFF09${emp.departmentFullName || ""}`).join("\n");
23469
+ }
23470
+ function describeEmployee(emp) {
23471
+ const name = emp.name || emp.id || "";
23472
+ const id = emp.id ? `\uFF08${emp.id}\uFF09` : "";
23473
+ const department = emp.departmentFullName ? ` ${emp.departmentFullName}` : "";
23474
+ return `${name}${id}${department}`.trim();
23475
+ }
23476
+
22858
23477
  // src/tools/changeOwner.ts
22859
23478
  function registerChangeOwner(server, ctx) {
22860
23479
  server.registerTool(
@@ -22951,49 +23570,15 @@ ${formatCandidates(resolution.candidates)}` : resolution.message
22951
23570
  }
22952
23571
  );
22953
23572
  }
22954
- async function resolveEmployee(ctx, input) {
22955
- const keyword = input.trim();
22956
- if (!keyword) {
22957
- return { ok: false, message: "\u8BF7\u63D0\u4F9B\u5458\u5DE5\u59D3\u540D\u6216 empId", candidates: [] };
23573
+ function buildNameMap(detail, target) {
23574
+ const map = /* @__PURE__ */ new Map();
23575
+ for (const emp of [...detail.ownEmps ?? [], ...detail.patEmps ?? [], ...detail.cpyEmps ?? []]) {
23576
+ if (emp.empId) {
23577
+ map.set(emp.empId, emp.empName || emp.empId);
23578
+ }
22958
23579
  }
22959
- const list = await ctx.client.get("/external/base/sel2/emp", { queryKey: keyword }) ?? [];
22960
- const byId = list.find((emp) => emp.id === keyword);
22961
- if (byId) {
22962
- return { ok: true, emp: byId };
22963
- }
22964
- const sameName = list.filter((emp) => emp.name === keyword);
22965
- if (sameName.length === 1) {
22966
- return { ok: true, emp: sameName[0] };
22967
- }
22968
- if (sameName.length > 1) {
22969
- return {
22970
- ok: false,
22971
- message: `\u300C${keyword}\u300D\u6709 ${sameName.length} \u4E2A\u540C\u540D\u5458\u5DE5\uFF0C\u8BF7\u6539\u7528 empId \u6307\u5B9A`,
22972
- candidates: sameName
22973
- };
22974
- }
22975
- if (list.length === 1) {
22976
- return {
22977
- ok: false,
22978
- message: `\u6CA1\u6709\u7CBE\u786E\u5339\u914D\u5230\u5458\u5DE5\u300C${keyword}\u300D\uFF1B\u53EA\u627E\u5230\u4E00\u4E2A\u76F8\u8FD1\u7ED3\u679C\uFF0C\u8BF7\u786E\u8BA4\u59D3\u540D\u6216\u6539\u7528 empId`,
22979
- candidates: list
22980
- };
22981
- }
22982
- return {
22983
- ok: false,
22984
- message: list.length ? `\u300C${keyword}\u300D\u5339\u914D\u5230\u591A\u4E2A\u5458\u5DE5\uFF0C\u8BF7\u6539\u7528 empId \u6307\u5B9A` : `\u6CA1\u6709\u627E\u5230\u5458\u5DE5\u300C${keyword}\u300D\uFF1B\u8BF7\u63D0\u4F9B\u66F4\u5B8C\u6574\u7684\u59D3\u540D\uFF0C\u6216\u5148\u7528 search_employee \u67E5\u8BE2`,
22985
- candidates: list
22986
- };
22987
- }
22988
- function buildNameMap(detail, target) {
22989
- const map = /* @__PURE__ */ new Map();
22990
- for (const emp of [...detail.ownEmps ?? [], ...detail.patEmps ?? [], ...detail.cpyEmps ?? []]) {
22991
- if (emp.empId) {
22992
- map.set(emp.empId, emp.empName || emp.empId);
22993
- }
22994
- }
22995
- if (target.id) {
22996
- map.set(target.id, target.name || target.id);
23580
+ if (target.id) {
23581
+ map.set(target.id, target.name || target.id);
22997
23582
  }
22998
23583
  return map;
22999
23584
  }
@@ -23014,15 +23599,6 @@ function roleLabel(role) {
23014
23599
  if (role === "C") return "\u6284\u9001\u4EBA";
23015
23600
  return role;
23016
23601
  }
23017
- function describeEmployee(emp) {
23018
- const name = emp.name || emp.id || "";
23019
- const id = emp.id ? `\uFF08${emp.id}\uFF09` : "";
23020
- const department = emp.departmentFullName ? ` ${emp.departmentFullName}` : "";
23021
- return `${name}${id}${department}`.trim();
23022
- }
23023
- function formatCandidates(list) {
23024
- return list.map((emp) => `- ${emp.name || "-"}\uFF08${emp.id || "-"}\uFF09${emp.departmentFullName || ""}`).join("\n");
23025
- }
23026
23602
 
23027
23603
  // src/tools/changeStatus.ts
23028
23604
  function registerChangeStatus(server, ctx) {
@@ -23129,6 +23705,860 @@ function formatPreview3(preview, previewToken) {
23129
23705
  ].join("\n");
23130
23706
  }
23131
23707
 
23708
+ // src/domain/createTask.ts
23709
+ var DATE_INPUT_PATTERN = /^(\d{4})[/-](\d{1,2})[/-](\d{1,2})$/;
23710
+ var MEMBER_RANK = { O: 0, P: 1, C: 2 };
23711
+ var TEMPLATE_TITLES = {
23712
+ BIS: ["\u4E1A\u52A1\u7C7B\u4EFB\u52A1", "\u6807\u51C6\u884C\u52A8\u8BA1\u5212-\u4E1A\u52A1-\u4EFB\u52A1"],
23713
+ MGR: ["\u7BA1\u7406\u7C7B\u4EFB\u52A1", "\u6807\u51C6\u884C\u52A8\u8BA1\u5212-\u7BA1\u7406-\u4EFB\u52A1"]
23714
+ };
23715
+ var PRIORITY_CODES = {
23716
+ "\u975E\u5E38\u7D27\u6025": "3-VH",
23717
+ "3-VH": "3-VH",
23718
+ "3VH": "3-VH",
23719
+ "\u7D27\u6025": "2-H",
23720
+ "2-H": "2-H",
23721
+ H: "2-H",
23722
+ "\u666E\u901A": "1-M",
23723
+ "1-M": "1-M",
23724
+ M: "1-M",
23725
+ "\u8F83\u4F4E": "0-L",
23726
+ "0-L": "0-L",
23727
+ L: "0-L"
23728
+ };
23729
+ function todayDateString(now = /* @__PURE__ */ new Date()) {
23730
+ return `${now.getFullYear()}/${pad2(now.getMonth() + 1)}/${pad2(now.getDate())}`;
23731
+ }
23732
+ function normalizeDateInput(value, label = "\u65E5\u671F") {
23733
+ const text = value.trim();
23734
+ const match = DATE_INPUT_PATTERN.exec(text);
23735
+ if (!match) {
23736
+ throw new EworkError(`${label}\u683C\u5F0F\u4E0D\u6B63\u786E\uFF08${text}\uFF09\uFF1A\u8BF7\u7528 yyyy/MM/dd \u6216 yyyy-MM-dd`);
23737
+ }
23738
+ const year = Number(match[1]);
23739
+ const month = Number(match[2]);
23740
+ const day = Number(match[3]);
23741
+ const date3 = new Date(year, month - 1, day);
23742
+ if (date3.getFullYear() !== year || date3.getMonth() !== month - 1 || date3.getDate() !== day) {
23743
+ throw new EworkError(`${label}\u4E0D\u662F\u6709\u6548\u65E5\u671F\uFF1A${text}`);
23744
+ }
23745
+ return `${year}/${pad2(month)}/${pad2(day)}`;
23746
+ }
23747
+ function normalizePriority(value) {
23748
+ const text = value?.trim();
23749
+ if (!text) {
23750
+ return "1-M";
23751
+ }
23752
+ const code = PRIORITY_CODES[text] ?? PRIORITY_CODES[text.toUpperCase()];
23753
+ if (!code) {
23754
+ throw new EworkError(
23755
+ `\u4F18\u5148\u7EA7\u300C${text}\u300D\u4E0D\u8BA4\u8BC6\uFF1A\u8BF7\u7528 \u975E\u5E38\u7D27\u6025/\u7D27\u6025/\u666E\u901A/\u8F83\u4F4E\uFF0C\u6216 3-VH/2-H/1-M/0-L`
23756
+ );
23757
+ }
23758
+ return code;
23759
+ }
23760
+ function dedupeMembers(members) {
23761
+ const byEmpId = /* @__PURE__ */ new Map();
23762
+ for (const member of members) {
23763
+ const empId = member.empId.trim();
23764
+ if (!empId) {
23765
+ continue;
23766
+ }
23767
+ const existing = byEmpId.get(empId);
23768
+ if (!existing || MEMBER_RANK[member.role] < MEMBER_RANK[existing.role]) {
23769
+ byEmpId.set(empId, { empId, role: member.role });
23770
+ }
23771
+ }
23772
+ return Array.from(byEmpId.values()).sort(
23773
+ (a, b) => MEMBER_RANK[a.role] - MEMBER_RANK[b.role]
23774
+ );
23775
+ }
23776
+ function selectTemplate(templates, businessCode, explicitId) {
23777
+ const available = templates.filter(
23778
+ (template) => String(template.category ?? "") === "T" && template.id
23779
+ );
23780
+ const sameBusiness = available.filter(
23781
+ (template) => String(template.business ?? "") === businessCode
23782
+ );
23783
+ const specified = explicitId?.trim();
23784
+ if (specified) {
23785
+ const matched = available.filter((template) => String(template.id) === specified);
23786
+ if (matched.length === 1) {
23787
+ const templateBusiness = String(matched[0].business ?? "");
23788
+ if (businessCode && templateBusiness && templateBusiness !== businessCode) {
23789
+ return {
23790
+ ok: false,
23791
+ message: `\u6307\u5B9A\u7684\u6807\u51C6\u884C\u52A8\u8BA1\u5212\u5C5E\u4E8E\u300C${templateBusiness}\u300D\uFF0C\u4E0E\u8BA1\u5212\u4E1A\u52A1\u300C${businessCode}\u300D\u4E0D\u4E00\u81F4`,
23792
+ candidates: sameBusiness.length ? sameBusiness : available
23793
+ };
23794
+ }
23795
+ return { ok: true, template: matched[0], automatic: false };
23796
+ }
23797
+ return {
23798
+ ok: false,
23799
+ message: `\u6307\u5B9A\u7684\u6807\u51C6\u884C\u52A8\u8BA1\u5212\u4E0D\u5B58\u5728\u6216\u5F53\u524D\u5458\u5DE5\u4E0D\u53EF\u89C1\uFF1A${specified}`,
23800
+ candidates: available
23801
+ };
23802
+ }
23803
+ for (const title of TEMPLATE_TITLES[businessCode] ?? []) {
23804
+ const matched = sameBusiness.filter(
23805
+ (template) => String(template.title ?? "").trim() === title
23806
+ );
23807
+ if (matched.length === 1) {
23808
+ return { ok: true, template: matched[0], automatic: true };
23809
+ }
23810
+ if (matched.length > 1) {
23811
+ return {
23812
+ ok: false,
23813
+ message: `\u6807\u51C6\u884C\u52A8\u8BA1\u5212\u300C${title}\u300D\u6709 ${matched.length} \u4E2A\u540C\u540D\u6A21\u677F\uFF0C\u8BF7\u7528 template \u6307\u5B9A id`,
23814
+ candidates: matched
23815
+ };
23816
+ }
23817
+ }
23818
+ if (sameBusiness.length === 1) {
23819
+ return { ok: true, template: sameBusiness[0], automatic: true };
23820
+ }
23821
+ if (sameBusiness.length > 1) {
23822
+ return {
23823
+ ok: false,
23824
+ message: `\u8BA1\u5212\u4E1A\u52A1\u300C${businessCode}\u300D\u4E0B\u5339\u914D\u5230 ${sameBusiness.length} \u4E2A\u6807\u51C6\u884C\u52A8\u8BA1\u5212\uFF0C\u8BF7\u7528 template \u6307\u5B9A id`,
23825
+ candidates: sameBusiness
23826
+ };
23827
+ }
23828
+ return {
23829
+ ok: false,
23830
+ message: `\u6CA1\u6709\u627E\u5230\u8BA1\u5212\u4E1A\u52A1\u300C${businessCode}\u300D\u53EF\u7528\u7684\u6807\u51C6\u884C\u52A8\u8BA1\u5212\uFF0C\u8BF7\u7528 template \u6307\u5B9A id`,
23831
+ candidates: available
23832
+ };
23833
+ }
23834
+ function buildAddTaskPayload(input) {
23835
+ const payload = {
23836
+ template: input.template,
23837
+ planId: input.planId,
23838
+ planTaskCategoryId: input.planTaskCategoryId,
23839
+ title: input.title,
23840
+ status: input.status,
23841
+ priority: input.priority,
23842
+ startTime: input.startTime,
23843
+ endTime: input.endTime,
23844
+ isFullDay: "Y",
23845
+ emps: input.members.map((member) => ({
23846
+ empId: member.empId,
23847
+ role: member.role
23848
+ }))
23849
+ };
23850
+ if (input.detailsHtml) {
23851
+ payload.details = input.detailsHtml;
23852
+ }
23853
+ if (input.father) {
23854
+ payload.father = input.father;
23855
+ }
23856
+ if (input.projectId) {
23857
+ payload.projectId = input.projectId;
23858
+ }
23859
+ if (input.subProjectId) {
23860
+ payload.subProjectId = input.subProjectId;
23861
+ }
23862
+ if (input.groupId) {
23863
+ payload.groupId = input.groupId;
23864
+ }
23865
+ if (input.tagIds.length) {
23866
+ payload.taskTags = input.tagIds.map((tagId) => ({ tagId }));
23867
+ }
23868
+ return payload;
23869
+ }
23870
+ function templateLabel(template) {
23871
+ const title = template.title || "\uFF08\u672A\u547D\u540D\u6A21\u677F\uFF09";
23872
+ const id = template.id ? `\uFF08${template.id}\uFF09` : "";
23873
+ return `${title}${id}`;
23874
+ }
23875
+ function memberRoleLabel(role) {
23876
+ if (role === "O") return "\u8D1F\u8D23\u4EBA";
23877
+ if (role === "P") return "\u53C2\u4E0E\u4EBA";
23878
+ return "\u6284\u9001\u4EBA";
23879
+ }
23880
+ function pad2(value) {
23881
+ return String(value).padStart(2, "0");
23882
+ }
23883
+
23884
+ // src/domain/plans.ts
23885
+ var PLAN_ID_PATTERN = /^[0-9a-fA-F]{32}$/;
23886
+ var UNSAFE_PLAN_NAME = /['"\\;%_]|--/;
23887
+ var MAX_PLAN_NAME_LENGTH = 100;
23888
+ var PLAN_LOOKUP_SIZE = 100;
23889
+ var PLAN_AVAILABLE_SIZE = 20;
23890
+ function isPlanId(value) {
23891
+ return PLAN_ID_PATTERN.test(value.trim());
23892
+ }
23893
+ function normalizePlanName(value) {
23894
+ const name = value.trim();
23895
+ if (!name) {
23896
+ throw new EworkError("\u8BA1\u5212\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A");
23897
+ }
23898
+ if (name.length > MAX_PLAN_NAME_LENGTH) {
23899
+ throw new EworkError(`\u8BA1\u5212\u540D\u79F0\u8FC7\u957F\uFF08${name.length} \u5B57\u7B26\uFF09\uFF0C\u6700\u591A ${MAX_PLAN_NAME_LENGTH} \u5B57\u7B26`);
23900
+ }
23901
+ if (UNSAFE_PLAN_NAME.test(name)) {
23902
+ throw new EworkError(
23903
+ `\u8BA1\u5212\u540D\u79F0\u5305\u542B\u4E0D\u652F\u6301\u7684\u5B57\u7B26\uFF08' " \\ ; % _ \u6216 --\uFF09\uFF0C\u8BF7\u6539\u7528 32 \u4F4D\u8BA1\u5212 id\uFF0C\u6216\u7B80\u5316\u8BA1\u5212\u540D\u79F0`
23904
+ );
23905
+ }
23906
+ return name;
23907
+ }
23908
+ async function resolvePlan(ctx, input) {
23909
+ const value = input.trim();
23910
+ if (!value) {
23911
+ throw new EworkError("\u8BF7\u63D0\u4F9B\u8BA1\u5212\u540D\u79F0\u6216 32 \u4F4D\u8BA1\u5212 id");
23912
+ }
23913
+ if (isPlanId(value)) {
23914
+ const plan = await loadPlanBase(ctx, value);
23915
+ if (!plan) {
23916
+ throw new EworkError(`\u8BA1\u5212\u4E0D\u5B58\u5728\u6216\u5DF2\u5220\u9664\uFF1A${value}`);
23917
+ }
23918
+ return { ok: true, plan, matchedBy: "id" };
23919
+ }
23920
+ const name = normalizePlanName(value);
23921
+ const page = await loadPlanPage(ctx, name, PLAN_LOOKUP_SIZE);
23922
+ const exact = page.items.filter((item) => String(item.title ?? "") === name);
23923
+ if (exact.length === 1) {
23924
+ const plan = await loadPlanBase(ctx, exact[0].id ?? "");
23925
+ if (!plan) {
23926
+ throw new EworkError(`\u8BA1\u5212\u4E0D\u5B58\u5728\u6216\u5DF2\u5220\u9664\uFF1A${exact[0].id ?? name}`);
23927
+ }
23928
+ return { ok: true, plan, matchedBy: "exact" };
23929
+ }
23930
+ if (exact.length > 1) {
23931
+ return {
23932
+ ok: false,
23933
+ message: `\u8BA1\u5212\u540D\u79F0\u300C${name}\u300D\u6709 ${exact.length} \u4E2A\u540C\u540D\u8BA1\u5212\uFF0C\u8BF7\u6539\u7528\u8BA1\u5212 id \u6307\u5B9A${pageNote(page)}`,
23934
+ candidates: exact.map(toCandidate2)
23935
+ };
23936
+ }
23937
+ if (page.items.length === 1) {
23938
+ const plan = await loadPlanBase(ctx, page.items[0].id ?? "");
23939
+ if (!plan) {
23940
+ throw new EworkError(`\u8BA1\u5212\u4E0D\u5B58\u5728\u6216\u5DF2\u5220\u9664\uFF1A${page.items[0].id ?? name}`);
23941
+ }
23942
+ return { ok: true, plan, matchedBy: "fuzzy" };
23943
+ }
23944
+ if (page.items.length > 1) {
23945
+ return {
23946
+ ok: false,
23947
+ message: `\u8BA1\u5212\u540D\u79F0\u300C${name}\u300D\u6A21\u7CCA\u5339\u914D\u5230 ${page.items.length} \u4E2A\u8BA1\u5212\uFF0C\u8BF7\u6539\u7528\u8BA1\u5212 id \u6307\u5B9A${pageNote(page)}`,
23948
+ candidates: page.items.map(toCandidate2)
23949
+ };
23950
+ }
23951
+ const available = await loadPlanPage(ctx, "", PLAN_AVAILABLE_SIZE);
23952
+ return {
23953
+ ok: false,
23954
+ message: `\u6CA1\u6709\u627E\u5230\u8BA1\u5212\u300C${name}\u300D${pageNote(page)}${available.items.length ? "\u3002\u5F53\u524D\u53EF\u7528\u7684\u8BA1\u5212\u89C1 availablePlans" : "\uFF0C\u5F53\u524D\u5458\u5DE5\u4E5F\u6CA1\u6709\u53EF\u89C1\u8BA1\u5212"}`,
23955
+ candidates: [],
23956
+ available: available.items.map(toCandidate2)
23957
+ };
23958
+ }
23959
+ function pageNote(page) {
23960
+ return page.total > page.items.length ? `\uFF08\u5339\u914D\u7ED3\u679C\u5171 ${page.total} \u6761\uFF0C\u4EC5\u5C55\u793A\u524D ${page.items.length} \u6761\uFF0C\u5EFA\u8BAE\u7528\u66F4\u5B8C\u6574\u7684\u540D\u79F0\u6216\u8BA1\u5212 id\uFF09` : "";
23961
+ }
23962
+ function formatPlanFailure(resolution) {
23963
+ const lines = [resolution.message];
23964
+ if (resolution.candidates.length) {
23965
+ lines.push("\u5019\u9009\u8BA1\u5212\uFF1A");
23966
+ lines.push(...resolution.candidates.map(formatPlanCandidate));
23967
+ }
23968
+ if (resolution.available?.length) {
23969
+ lines.push("\u5F53\u524D\u53EF\u7528\u7684\u8BA1\u5212\uFF1A");
23970
+ lines.push(...resolution.available.map(formatPlanCandidate));
23971
+ }
23972
+ return lines.join("\n");
23973
+ }
23974
+ function formatPlanCandidate(plan) {
23975
+ const archive = plan.isArchive ? "\uFF08\u5DF2\u5F52\u6863\uFF09" : "";
23976
+ const creator = plan.creatorName ? ` \u521B\u5EFA\u4EBA ${plan.creatorName}` : "";
23977
+ return `- ${plan.title || "\uFF08\u65E0\u6807\u9898\uFF09"}\uFF08${plan.id}\uFF09${archive}${creator}`;
23978
+ }
23979
+ async function loadPlanPage(ctx, title, size) {
23980
+ const taskPlan = { isDel: "N" };
23981
+ if (title) {
23982
+ taskPlan.title = title;
23983
+ }
23984
+ const raw = await ctx.client.requestRaw(
23985
+ "POST",
23986
+ "/external/home/task/plan/query/loadByParamsInPage",
23987
+ {
23988
+ json: {
23989
+ taskPlan,
23990
+ queryFollowers: "Y",
23991
+ current: 1,
23992
+ size
23993
+ },
23994
+ write: false
23995
+ }
23996
+ );
23997
+ return { items: raw.result ?? [], total: Number(raw.total ?? 0) };
23998
+ }
23999
+ async function loadPlanBase(ctx, planId) {
24000
+ if (!planId) {
24001
+ return null;
24002
+ }
24003
+ const raw = await ctx.client.get(
24004
+ "/external/home/task/plan/query/loadBaseById",
24005
+ { id: planId }
24006
+ );
24007
+ if (!raw || raw.isDel === "Y") {
24008
+ return null;
24009
+ }
24010
+ return toPlanInfo(raw);
24011
+ }
24012
+ function toPlanInfo(raw) {
24013
+ const business = String(raw.business ?? "");
24014
+ const parsed = parseBusiness(business);
24015
+ return {
24016
+ id: String(raw.id ?? ""),
24017
+ title: String(raw.title ?? ""),
24018
+ business,
24019
+ businessCode: parsed.businessCode,
24020
+ isArchive: raw.isArchive === "Y",
24021
+ isMember: raw.isMember === "Y",
24022
+ isAdmin: raw.isAdmin === "Y",
24023
+ projectId: parsed.projectId ?? idOf(raw.projectBase?.id),
24024
+ subProjectId: parsed.subProjectId ?? idOf(raw.subProjectBase?.id),
24025
+ creatorName: raw.creatorName
24026
+ };
24027
+ }
24028
+ function parseBusiness(business) {
24029
+ const parts = business.split("/");
24030
+ const businessCode = parts[0] ?? "";
24031
+ if (parts.length === 3 && parts[1] === "PROJECT") {
24032
+ return { businessCode, projectId: parts[2] };
24033
+ }
24034
+ if (parts.length === 3 && parts[1] === "SUBPROJECT") {
24035
+ return { businessCode, subProjectId: parts[2] };
24036
+ }
24037
+ return { businessCode };
24038
+ }
24039
+ function toCandidate2(item) {
24040
+ return {
24041
+ id: String(item.id ?? ""),
24042
+ title: String(item.title ?? ""),
24043
+ business: String(item.business ?? ""),
24044
+ isArchive: item.isArchive === "Y"
24045
+ };
24046
+ }
24047
+ function idOf(value) {
24048
+ if (value === void 0 || value === null || value === "") {
24049
+ return void 0;
24050
+ }
24051
+ return String(value);
24052
+ }
24053
+
24054
+ // src/tools/createTask.ts
24055
+ var PRIORITY_LABELS = {
24056
+ "3-VH": "\u975E\u5E38\u7D27\u6025",
24057
+ "2-H": "\u7D27\u6025",
24058
+ "1-M": "\u666E\u901A",
24059
+ "0-L": "\u8F83\u4F4E"
24060
+ };
24061
+ var MAX_DUPLICATE_HITS = 10;
24062
+ function registerCreateTask(server, ctx) {
24063
+ server.registerTool(
24064
+ "create_task",
24065
+ {
24066
+ title: "\u5728\u8BA1\u5212\u4E0B\u521B\u5EFA\u4EFB\u52A1",
24067
+ description: "\u5728\u6307\u5B9A\u8BA1\u5212\u4E0B\u521B\u5EFA\u4EFB\u52A1\u3002\u5FC5\u586B plan\uFF08\u8BA1\u5212\u540D\u79F0\u6216 32 \u4F4D id\uFF09\u3001taskType\uFF08\u4EFB\u52A1\u7C7B\u578B\u540D\u79F0\u6216 id\uFF0C\u5982 \u4EFB\u52A1/\u9700\u6C42/\u7F3A\u9677\uFF09\u3001title\u3001dueDate\uFF08yyyy/MM/dd \u6216 yyyy-MM-dd\uFF09\u3002\u9ED8\u8BA4\u8D1F\u8D23\u4EBA\u4E3A\u5F53\u524D API Key \u5458\u5DE5\u3001\u5F00\u59CB\u65E5\u671F\u4E3A\u4ECA\u5929\u3001\u4F18\u5148\u7EA7\u666E\u901A\u3001\u72B6\u6001\u4E3A\u5DE5\u4F5C\u6D41\u8D77\u59CB\u8282\u70B9\u3001\u5168\u5929\u4EFB\u52A1\u3002\u53EF\u9009\u6B63\u6587\u3001\u53C2\u4E0E\u4EBA\u3001\u6284\u9001\u4EBA\u3001\u4F18\u5148\u7EA7\u3001\u8BA1\u5212\u5185\u6807\u7B7E\u3001\u7236\u4EFB\u52A1\u3001\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\u548C template\u3002\u5FC5\u987B\u5148\u4E0D\u5E26 confirm \u8C03\u7528\u62FF previewToken\uFF0C\u628A\u9884\u6F14\u5C55\u793A\u7ED9\u7528\u6237\u5E76\u53D6\u5F97\u660E\u786E\u540C\u610F\u540E\uFF0C\u518D\u5E26 previewToken \u548C confirm=true \u6267\u884C\u3002\u53EA\u652F\u6301\u8BA1\u5212\u4EFB\u52A1\u3002",
24068
+ inputSchema: {
24069
+ plan: external_exports.string().describe("\u8BA1\u5212\u540D\u79F0\u6216 32 \u4F4D\u8BA1\u5212 id"),
24070
+ taskType: external_exports.string().describe("\u4EFB\u52A1\u7C7B\u578B\u540D\u79F0\u6216 id\uFF0C\u5982 \u4EFB\u52A1\u3001\u9700\u6C42\u3001\u7F3A\u9677"),
24071
+ title: external_exports.string().describe("\u4EFB\u52A1\u6807\u9898"),
24072
+ dueDate: external_exports.string().describe("\u622A\u6B62\u65E5\u671F\uFF0Cyyyy/MM/dd \u6216 yyyy-MM-dd"),
24073
+ content: external_exports.string().optional().describe("\u6B63\u6587\uFF08\u7EAF\u6587\u672C/Markdown\uFF0C\u4F1A\u8F6C\u6210\u7B80\u5355 HTML\uFF09"),
24074
+ participants: external_exports.array(external_exports.string()).optional().describe("\u53C2\u4E0E\u4EBA\u59D3\u540D\u6216 empId \u6570\u7EC4"),
24075
+ cc: external_exports.array(external_exports.string()).optional().describe("\u6284\u9001\u4EBA\u59D3\u540D\u6216 empId \u6570\u7EC4"),
24076
+ priority: external_exports.string().optional().describe("\u4F18\u5148\u7EA7\uFF1A\u975E\u5E38\u7D27\u6025/\u7D27\u6025/\u666E\u901A/\u8F83\u4F4E\uFF0C\u6216 3-VH/2-H/1-M/0-L\uFF1B\u9ED8\u8BA4\u666E\u901A"),
24077
+ tags: external_exports.array(external_exports.string()).optional().describe("\u8BA1\u5212\u5185\u6807\u7B7E\u540D\u6216 id \u6570\u7EC4"),
24078
+ group: external_exports.string().optional().describe("\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\u540D\u79F0\u6216 id\uFF1B\u521B\u5EFA\u540E\u76F4\u63A5\u52A0\u5165\u8BE5\u5206\u7EC4"),
24079
+ parentTaskId: external_exports.string().optional().describe("\u7236\u4EFB\u52A1 taskId\uFF1B\u4E0E parentUrl \u4E8C\u9009\u4E00"),
24080
+ parentUrl: external_exports.string().optional().describe("\u7236\u4EFB\u52A1\u94FE\u63A5\uFF1B\u4E0E parentTaskId \u4E8C\u9009\u4E00"),
24081
+ template: external_exports.string().optional().describe("\u6807\u51C6\u884C\u52A8\u8BA1\u5212 id\uFF1B\u901A\u5E38\u81EA\u52A8\u9009\u62E9\uFF0C\u89E3\u6790\u5931\u8D25\u65F6\u518D\u7528\u5B83\u6307\u5B9A"),
24082
+ confirm: external_exports.boolean().optional().describe("true \u624D\u771F\u6B63\u521B\u5EFA\uFF1B\u7F3A\u7701\u53EA\u9884\u6F14"),
24083
+ previewToken: external_exports.string().optional().describe("\u9884\u6F14\u8FD4\u56DE\u7684\u4EE4\u724C\uFF1Bconfirm=true \u65F6\u5FC5\u586B")
24084
+ },
24085
+ annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false }
24086
+ },
24087
+ async (args) => {
24088
+ try {
24089
+ return await handleCreate(ctx, args);
24090
+ } catch (error2) {
24091
+ return fail(error2);
24092
+ }
24093
+ }
24094
+ );
24095
+ }
24096
+ async function handleCreate(ctx, args) {
24097
+ const title = args.title.trim();
24098
+ if (!title) {
24099
+ throw new EworkError("\u4EFB\u52A1\u6807\u9898\u4E0D\u80FD\u4E3A\u7A7A");
24100
+ }
24101
+ const planResolution = await resolvePlan(ctx, args.plan);
24102
+ if (!planResolution.ok) {
24103
+ throw new EworkError(formatPlanFailure(planResolution));
24104
+ }
24105
+ const plan = planResolution.plan;
24106
+ if (plan.isArchive) {
24107
+ throw new EworkError(`\u8BA1\u5212\u300C${plan.title}\u300D\u5DF2\u5F52\u6863\uFF0C\u4E0D\u80FD\u5728\u5F52\u6863\u8BA1\u5212\u4E0B\u521B\u5EFA\u4EFB\u52A1`);
24108
+ }
24109
+ if (!plan.isMember) {
24110
+ throw new EworkError(
24111
+ `\u5F53\u524D\u5458\u5DE5\u4E0D\u662F\u8BA1\u5212\u300C${plan.title}\u300D\u7684\u6210\u5458\uFF0C\u4E0D\u80FD\u5728\u8BE5\u8BA1\u5212\u4E0B\u521B\u5EFA\u4EFB\u52A1\uFF1B\u8BF7\u8BA9\u8BA1\u5212\u7BA1\u7406\u5458\u6DFB\u52A0\u6210\u5458`
24112
+ );
24113
+ }
24114
+ const employee = await loadCurrentEmployee(ctx);
24115
+ const categories = await loadCategories(ctx, plan.id);
24116
+ const category = resolveCategory(categories, args.taskType);
24117
+ if (!category.id) {
24118
+ throw new EworkError(`\u4EFB\u52A1\u7C7B\u578B\u300C${category.name}\u300D\u7F3A\u5C11 id\uFF0C\u65E0\u6CD5\u521B\u5EFA`);
24119
+ }
24120
+ const requiredFields = (category.configFieldList ?? []).filter((field) => field.required === "Y" && field.isDel !== "Y").map((field) => String(field.name ?? "").trim()).filter(Boolean);
24121
+ if (requiredFields.length) {
24122
+ throw new EworkError(
24123
+ `\u4EFB\u52A1\u7C7B\u578B\u300C${category.name}\u300D\u6709\u5FC5\u586B\u81EA\u5B9A\u4E49\u5B57\u6BB5\uFF1A${requiredFields.join("\u3001")}\u3002MCP \u6682\u4E0D\u652F\u6301\u586B\u5199\u81EA\u5B9A\u4E49\u5B57\u6BB5\uFF0C\u8BF7\u5728\u7F51\u9875\u521B\u5EFA`
24124
+ );
24125
+ }
24126
+ const startStatus = (category.flowItemList ?? []).find(
24127
+ (item) => item.type === "S" && item.id
24128
+ );
24129
+ if (!startStatus?.id) {
24130
+ throw new EworkError(`\u4EFB\u52A1\u7C7B\u578B\u300C${category.name}\u300D\u6CA1\u6709\u8D77\u59CB\u72B6\u6001\u8282\u70B9\uFF0C\u65E0\u6CD5\u521B\u5EFA`);
24131
+ }
24132
+ const templates = await loadTemplates(ctx, employee.id);
24133
+ const templateResolution = selectTemplate(
24134
+ templates,
24135
+ plan.businessCode,
24136
+ args.template
24137
+ );
24138
+ if (!templateResolution.ok) {
24139
+ throw new EworkError(
24140
+ `${templateResolution.message}
24141
+ \u53EF\u7528\u6A21\u677F\uFF1A
24142
+ ${formatTemplates(templateResolution.candidates)}`
24143
+ );
24144
+ }
24145
+ const template = templateResolution.template;
24146
+ if (!template.id) {
24147
+ throw new EworkError("\u6807\u51C6\u884C\u52A8\u8BA1\u5212 id \u4E3A\u7A7A\uFF0C\u65E0\u6CD5\u521B\u5EFA");
24148
+ }
24149
+ const priority = normalizePriority(args.priority);
24150
+ const startDate = todayDateString();
24151
+ const dueDate = normalizeDateInput(args.dueDate, "\u622A\u6B62\u65E5\u671F");
24152
+ if (dueDate < startDate) {
24153
+ throw new EworkError(`\u622A\u6B62\u65E5\u671F ${dueDate} \u65E9\u4E8E\u5F00\u59CB\u65E5\u671F ${startDate}\uFF0C\u8BF7\u8C03\u6574`);
24154
+ }
24155
+ const ownerMember = { emp: employee, role: "O" };
24156
+ const participantMembers = await resolveMembers(
24157
+ ctx,
24158
+ args.participants ?? [],
24159
+ "P"
24160
+ );
24161
+ const ccMembers = await resolveMembers(ctx, args.cc ?? [], "C");
24162
+ const members = dedupeMembers(
24163
+ toMemberInputs([ownerMember, ...participantMembers, ...ccMembers])
24164
+ );
24165
+ const nameByEmpId = buildNameMap2([ownerMember, ...participantMembers, ...ccMembers]);
24166
+ const memberViews = members.map((member) => ({
24167
+ empId: member.empId,
24168
+ name: nameByEmpId.get(member.empId) || member.empId,
24169
+ role: member.role,
24170
+ roleLabel: memberRoleLabel(member.role)
24171
+ }));
24172
+ const planTags = await loadPlanTags(ctx, plan.id);
24173
+ const selectedTags = resolveTags(args.tags ?? [], planTags);
24174
+ let group;
24175
+ if (args.group?.trim() && !isNoGroupTarget(args.group)) {
24176
+ const groupResolution = await resolveTaskGroup(ctx, args.group);
24177
+ if (!groupResolution.ok) {
24178
+ throw new EworkError(formatGroupFailure(groupResolution));
24179
+ }
24180
+ if (!String(groupResolution.group.id ?? "").trim()) {
24181
+ throw new EworkError(
24182
+ `\u5206\u7EC4\u300C${String(groupResolution.group.groupName ?? args.group)}\u300D\u7F3A\u5C11\u5206\u7EC4 id\uFF0C\u65E0\u6CD5\u5165\u7EC4`
24183
+ );
24184
+ }
24185
+ group = groupResolution.group;
24186
+ }
24187
+ let parent;
24188
+ if (args.parentTaskId || args.parentUrl) {
24189
+ parent = await resolveParent(ctx, args.parentTaskId, args.parentUrl, plan);
24190
+ }
24191
+ const duplicate = await findDuplicateTitles(ctx, plan.id, title);
24192
+ const detailsHtml = args.content !== void 0 ? textToHtml(args.content) : void 0;
24193
+ const payload = buildAddTaskPayload({
24194
+ template: template.id,
24195
+ planId: plan.id,
24196
+ planTaskCategoryId: String(category.id ?? ""),
24197
+ title,
24198
+ detailsHtml,
24199
+ status: String(startStatus.id),
24200
+ priority,
24201
+ startTime: startDate,
24202
+ endTime: dueDate,
24203
+ father: parent?.taskId,
24204
+ projectId: plan.projectId,
24205
+ subProjectId: plan.subProjectId,
24206
+ groupId: group ? String(group.id ?? "") : void 0,
24207
+ members,
24208
+ tagIds: selectedTags.map((tag) => String(tag.id))
24209
+ });
24210
+ const preview = {
24211
+ plan: { id: plan.id, title: plan.title, business: plan.business },
24212
+ category: { id: String(category.id ?? ""), name: String(category.name ?? "") },
24213
+ template: {
24214
+ id: String(template.id),
24215
+ title: String(template.title ?? ""),
24216
+ automatic: templateResolution.automatic
24217
+ },
24218
+ title,
24219
+ contentText: detailsHtml ? htmlToText(detailsHtml).slice(0, 500) : "",
24220
+ dates: { start: startDate, end: dueDate, fullDay: true },
24221
+ priority: { code: priority, label: PRIORITY_LABELS[priority] ?? priority },
24222
+ members: memberViews,
24223
+ tags: selectedTags.map((tag) => ({
24224
+ id: String(tag.id),
24225
+ name: String(tag.name ?? "")
24226
+ })),
24227
+ parent,
24228
+ group: group ? {
24229
+ id: String(group.id ?? ""),
24230
+ name: String(group.groupName ?? "")
24231
+ } : void 0,
24232
+ project: plan.projectId || plan.subProjectId ? { projectId: plan.projectId, subProjectId: plan.subProjectId } : void 0,
24233
+ duplicateTaskIds: duplicate.taskIds,
24234
+ duplicateNote: duplicate.note
24235
+ };
24236
+ if (!args.confirm) {
24237
+ const previewToken = createPreviewToken("create_task", plan.id, payload);
24238
+ return ok(formatPreview4(preview, previewToken), {
24239
+ ...preview,
24240
+ planMatchedBy: planResolution.matchedBy,
24241
+ previewToken,
24242
+ expiresInSeconds: previewTtlSeconds(),
24243
+ payload
24244
+ });
24245
+ }
24246
+ consumePreviewToken(args.previewToken, "create_task", plan.id, payload);
24247
+ const taskId = String(
24248
+ await ctx.client.post("/external/home/task/addTask", payload) ?? ""
24249
+ ).trim();
24250
+ if (!taskId) {
24251
+ throw new EworkError("\u521B\u5EFA\u63A5\u53E3\u6CA1\u6709\u8FD4\u56DE taskId\uFF0C\u8BF7\u5230\u7F51\u9875\u786E\u8BA4\u4EFB\u52A1\u662F\u5426\u5DF2\u521B\u5EFA");
24252
+ }
24253
+ const url = `${ctx.baseUrl.replace(/\/$/, "")}/workPlan/plan?taskId=${taskId}`;
24254
+ const expected = {
24255
+ title,
24256
+ planId: plan.id,
24257
+ categoryId: String(category.id ?? ""),
24258
+ statusId: String(startStatus.id),
24259
+ startTime: startDate,
24260
+ endTime: dueDate,
24261
+ ownerId: employee.id,
24262
+ participantIds: members.filter((member) => member.role === "P").map((m) => m.empId),
24263
+ ccIds: members.filter((member) => member.role === "C").map((m) => m.empId),
24264
+ tagIds: selectedTags.map((tag) => String(tag.id)),
24265
+ father: parent?.taskId,
24266
+ projectId: plan.projectId,
24267
+ subProjectId: plan.subProjectId
24268
+ };
24269
+ try {
24270
+ const after = await loadDetail(ctx, taskId);
24271
+ const verification = verifyCreatedTask(after, expected);
24272
+ if (group) {
24273
+ const groupId = String(group.id ?? "");
24274
+ const inGroup = groupId ? await isTaskInGroup(ctx, taskId, groupId) : false;
24275
+ if (!inGroup) {
24276
+ verification.mismatches.push("\u5206\u7EC4");
24277
+ verification.verified = false;
24278
+ }
24279
+ }
24280
+ return ok(
24281
+ [
24282
+ `\u5DF2\u521B\u5EFA\u4EFB\u52A1 ${taskId}\uFF08${title}\uFF09\u3002`,
24283
+ `\u8BA1\u5212\uFF1A${plan.title}\uFF1B\u4EFB\u52A1\u7C7B\u578B\uFF1A${category.name}\uFF1B\u72B6\u6001\uFF1A${startStatus.name || startStatus.id}\uFF1B\u8D1F\u8D23\u4EBA\uFF1A${describeEmployee(employee)}\u3002`,
24284
+ group ? `\u5206\u7EC4\uFF1A${String(group.groupName ?? "")}\uFF08${String(group.id ?? "")}\uFF09\u3002` : "\u5206\u7EC4\uFF1A\u672A\u5206\u7EC4\u3002",
24285
+ verification.verified ? "\u56DE\u8BFB\u786E\u8BA4\u6210\u529F\u3002" : `\u5199\u5165\u5DF2\u63D0\u4EA4\uFF0C\u4F46\u56DE\u8BFB\u672A\u786E\u8BA4\uFF08${verification.mismatches.join("\u3001")}\uFF09\uFF0C\u8BF7\u624B\u52A8\u68C0\u67E5\u3002`,
24286
+ `\u94FE\u63A5\uFF1A${url}`
24287
+ ].join("\n"),
24288
+ {
24289
+ ...preview,
24290
+ created: true,
24291
+ taskId,
24292
+ url,
24293
+ verified: verification.verified,
24294
+ mismatches: verification.mismatches
24295
+ }
24296
+ );
24297
+ } catch (error2) {
24298
+ return ok(
24299
+ [
24300
+ `\u4EFB\u52A1\u5DF2\u63D0\u4EA4\u521B\u5EFA\uFF0C\u4F46\u56DE\u8BFB\u5931\u8D25\uFF1A${error2 instanceof Error ? error2.message : String(error2)}`,
24301
+ `taskId\uFF1A${taskId}`,
24302
+ `\u94FE\u63A5\uFF1A${url}`,
24303
+ "\u8BF7\u5230\u7F51\u9875\u786E\u8BA4\u4EFB\u52A1\u662F\u5426\u5DF2\u521B\u5EFA\u3002"
24304
+ ].join("\n"),
24305
+ { ...preview, created: true, taskId, url, verified: false }
24306
+ );
24307
+ }
24308
+ }
24309
+ async function loadCurrentEmployee(ctx) {
24310
+ const info = await ctx.client.get("/external/base/plt/userInfo");
24311
+ const id = String(info?.base?.id ?? "").trim();
24312
+ if (!id) {
24313
+ throw new EworkError("\u65E0\u6CD5\u83B7\u53D6\u5F53\u524D\u5458\u5DE5\u4FE1\u606F\uFF1B\u8BF7\u786E\u8BA4 API Key \u7ED1\u5B9A\u5458\u5DE5\u6709\u6548");
24314
+ }
24315
+ return { id, name: String(info?.base?.name ?? "") };
24316
+ }
24317
+ async function loadCategories(ctx, planId) {
24318
+ const list = await ctx.client.get(
24319
+ "/external/home/task/plan/query/loadTaskCategoryListByPlanId",
24320
+ { planId }
24321
+ ) ?? [];
24322
+ return list;
24323
+ }
24324
+ async function loadPlanTags(ctx, planId) {
24325
+ const list = await ctx.client.get(
24326
+ "/external/home/task/plan/query/loadTaskTagListByPlanId",
24327
+ { planId }
24328
+ ) ?? [];
24329
+ return list;
24330
+ }
24331
+ async function loadTemplates(ctx, empId) {
24332
+ const list = await ctx.client.get(
24333
+ "/external/home/task/query/loadTplsByEmpId",
24334
+ { empId }
24335
+ ) ?? [];
24336
+ return list;
24337
+ }
24338
+ function resolveCategory(categories, input) {
24339
+ const value = input.trim();
24340
+ if (!value) {
24341
+ throw new EworkError("\u8BF7\u63D0\u4F9B\u4EFB\u52A1\u7C7B\u578B\u540D\u79F0\u6216 id");
24342
+ }
24343
+ const byId = categories.filter((category) => String(category.id ?? "") === value);
24344
+ const byName = categories.filter(
24345
+ (category) => String(category.name ?? "").trim() === value
24346
+ );
24347
+ const matched = byId.length ? byId : byName;
24348
+ if (matched.length === 1) {
24349
+ return matched[0];
24350
+ }
24351
+ if (matched.length > 1) {
24352
+ throw new EworkError(
24353
+ `\u4EFB\u52A1\u7C7B\u578B\u300C${value}\u300D\u6709 ${matched.length} \u4E2A\u540C\u540D\u9879\uFF0C\u8BF7\u7528\u4EFB\u52A1\u7C7B\u578B id \u6307\u5B9A\u3002
24354
+ ${formatCategories(matched)}`
24355
+ );
24356
+ }
24357
+ throw new EworkError(
24358
+ `\u6CA1\u6709\u627E\u5230\u4EFB\u52A1\u7C7B\u578B\u300C${value}\u300D\u3002\u8BE5\u8BA1\u5212\u7684\u53EF\u7528\u7C7B\u578B\uFF1A
24359
+ ${categories.length ? formatCategories(categories) : "\u65E0"}`
24360
+ );
24361
+ }
24362
+ async function resolveMembers(ctx, inputs, role) {
24363
+ const members = [];
24364
+ for (const input of inputs) {
24365
+ const value = input.trim();
24366
+ if (!value) {
24367
+ continue;
24368
+ }
24369
+ members.push({ emp: await resolveEmployeeOrThrow(ctx, value), role });
24370
+ }
24371
+ return members;
24372
+ }
24373
+ function toMemberInputs(members) {
24374
+ return members.map((member) => ({
24375
+ empId: String(member.emp.id ?? "").trim(),
24376
+ role: member.role
24377
+ })).filter((member) => member.empId);
24378
+ }
24379
+ function buildNameMap2(members) {
24380
+ const map = /* @__PURE__ */ new Map();
24381
+ for (const member of members) {
24382
+ const empId = String(member.emp.id ?? "").trim();
24383
+ if (empId) {
24384
+ map.set(empId, member.emp.name || empId);
24385
+ }
24386
+ }
24387
+ return map;
24388
+ }
24389
+ function resolveTags(inputs, available) {
24390
+ const selected = [];
24391
+ const problems = [];
24392
+ for (const input of inputs) {
24393
+ const value = input.trim();
24394
+ if (!value) {
24395
+ continue;
24396
+ }
24397
+ const byId = available.filter((tag) => String(tag.id ?? "") === value);
24398
+ const matched = byId.length ? byId : available.filter((tag) => String(tag.name ?? "") === value);
24399
+ if (matched.length === 1) {
24400
+ const tagId = String(matched[0].id ?? "");
24401
+ if (!selected.some((tag) => String(tag.id ?? "") === tagId)) {
24402
+ selected.push(matched[0]);
24403
+ }
24404
+ } else if (matched.length === 0) {
24405
+ problems.push(`\u6807\u7B7E\u300C${value}\u300D\u4E0D\u5728\u8BE5\u8BA1\u5212\u4E0B`);
24406
+ } else {
24407
+ problems.push(`\u6807\u7B7E\u300C${value}\u300D\u6709 ${matched.length} \u4E2A\u540C\u540D\u9879\uFF0C\u8BF7\u7528\u6807\u7B7E id \u6307\u5B9A`);
24408
+ }
24409
+ }
24410
+ if (problems.length) {
24411
+ throw new EworkError(
24412
+ `${problems.join("\uFF1B")}\u3002\u8BE5\u8BA1\u5212\u53EF\u7528\u6807\u7B7E\uFF1A
24413
+ ${available.length ? formatTags(available) : "\u65E0"}`
24414
+ );
24415
+ }
24416
+ return selected;
24417
+ }
24418
+ async function resolveParent(ctx, parentTaskId, parentUrl, plan) {
24419
+ const taskId = resolveTaskInput(ctx, parentTaskId, parentUrl);
24420
+ const detail = await loadDetail(ctx, taskId);
24421
+ const parentPlanId = String(detail.task?.planId ?? "");
24422
+ if (parentPlanId !== plan.id) {
24423
+ throw new EworkError(
24424
+ `\u7236\u4EFB\u52A1 ${taskId} \u5C5E\u4E8E\u5176\u4ED6\u8BA1\u5212\uFF08${parentPlanId || "\u65E0\u8BA1\u5212"}\uFF09\uFF0C\u5FC5\u987B\u4E0E\u65B0\u5EFA\u4EFB\u52A1\u540C\u8BA1\u5212`
24425
+ );
24426
+ }
24427
+ if (String(detail.task?.isCycle ?? "N").toUpperCase() === "Y") {
24428
+ throw new EworkError(`\u7236\u4EFB\u52A1 ${taskId} \u662F\u5468\u671F\u4EFB\u52A1\uFF0C\u4E0D\u80FD\u4F5C\u4E3A\u7236\u4EFB\u52A1`);
24429
+ }
24430
+ return { taskId, title: String(detail.task?.title ?? "") };
24431
+ }
24432
+ async function findDuplicateTitles(ctx, planId, title) {
24433
+ try {
24434
+ const raw = await ctx.client.requestRaw(
24435
+ "POST",
24436
+ "/external/home/task/v2/query/loadByParamsInPage",
24437
+ {
24438
+ json: {
24439
+ empRoles: [],
24440
+ isTopTask: "N",
24441
+ containsTaskEmps: "N",
24442
+ containsTaskTags: "N",
24443
+ task: { planId, title },
24444
+ current: 1,
24445
+ size: MAX_DUPLICATE_HITS
24446
+ },
24447
+ write: false
24448
+ }
24449
+ );
24450
+ const taskIds = (raw.result ?? []).filter((item) => String(item.title ?? "") === title).map((item) => String(item.id ?? "")).filter(Boolean);
24451
+ return { taskIds };
24452
+ } catch {
24453
+ return { taskIds: [], note: "\u540C\u540D\u4EFB\u52A1\u68C0\u67E5\u5931\u8D25\uFF08\u4E0D\u5F71\u54CD\u521B\u5EFA\uFF09" };
24454
+ }
24455
+ }
24456
+ function verifyCreatedTask(detail, expected) {
24457
+ const task = detail.task ?? {};
24458
+ const mismatches = [];
24459
+ if (String(task.title ?? "") !== expected.title) mismatches.push("\u6807\u9898");
24460
+ if (String(task.planId ?? "") !== expected.planId) mismatches.push("\u8BA1\u5212");
24461
+ if (String(task.planTaskCategoryId ?? "") !== expected.categoryId) {
24462
+ mismatches.push("\u4EFB\u52A1\u7C7B\u578B");
24463
+ }
24464
+ if (String(task.status ?? "") !== expected.statusId) mismatches.push("\u72B6\u6001");
24465
+ if (!sameDate(task.startTime, expected.startTime)) mismatches.push("\u5F00\u59CB\u65E5\u671F");
24466
+ if (!sameDate(task.endTime, expected.endTime)) mismatches.push("\u622A\u6B62\u65E5\u671F");
24467
+ const owners = (detail.ownEmps ?? []).map((emp) => String(emp.empId ?? ""));
24468
+ if (!owners.includes(expected.ownerId)) mismatches.push("\u8D1F\u8D23\u4EBA");
24469
+ if (!sameIdSet(
24470
+ (detail.patEmps ?? []).map((emp) => String(emp.empId ?? "")),
24471
+ expected.participantIds
24472
+ )) {
24473
+ mismatches.push("\u53C2\u4E0E\u4EBA");
24474
+ }
24475
+ if (!sameIdSet(
24476
+ (detail.cpyEmps ?? []).map((emp) => String(emp.empId ?? "")),
24477
+ expected.ccIds
24478
+ )) {
24479
+ mismatches.push("\u6284\u9001\u4EBA");
24480
+ }
24481
+ if (expected.tagIds.length) {
24482
+ const actualTagIds = (detail.tagClassifyList ?? []).map(
24483
+ (tag) => String(tag.id ?? "")
24484
+ );
24485
+ if (!expected.tagIds.every((id) => actualTagIds.includes(id))) {
24486
+ mismatches.push("\u6807\u7B7E");
24487
+ }
24488
+ }
24489
+ if (expected.father && String(task.father ?? "") !== expected.father) {
24490
+ mismatches.push("\u7236\u4EFB\u52A1");
24491
+ }
24492
+ if (expected.projectId && String(detail.projectId ?? "") !== expected.projectId) {
24493
+ mismatches.push("\u9879\u76EE");
24494
+ }
24495
+ if (expected.subProjectId && String(detail.subProjectId ?? "") !== expected.subProjectId) {
24496
+ mismatches.push("\u5B50\u9879\u76EE");
24497
+ }
24498
+ return { verified: mismatches.length === 0, mismatches };
24499
+ }
24500
+ function sameDate(actual, expected) {
24501
+ const text = String(actual ?? "").slice(0, 10).replace(/-/g, "/");
24502
+ return text === expected;
24503
+ }
24504
+ function sameIdSet(actual, expected) {
24505
+ if (actual.length !== expected.length) {
24506
+ return false;
24507
+ }
24508
+ const set = new Set(actual);
24509
+ return expected.every((id) => set.has(id));
24510
+ }
24511
+ function formatPreview4(preview, previewToken) {
24512
+ const lines = [
24513
+ `\u5728\u8BA1\u5212\u300C${preview.plan.title}\u300D\uFF08${preview.plan.id}\uFF09\u521B\u5EFA\u4EFB\u52A1\u9884\u6F14\uFF08\u672A\u5199\u5165\uFF09\uFF1A`,
24514
+ `\u6807\u9898\uFF1A${preview.title}`,
24515
+ `\u4EFB\u52A1\u7C7B\u578B\uFF1A${preview.category.name}\uFF08${preview.category.id}\uFF09`,
24516
+ `\u6807\u51C6\u884C\u52A8\u8BA1\u5212\uFF1A${preview.template.title}\uFF08${preview.template.id}\uFF0C${preview.template.automatic ? "\u81EA\u52A8\u9009\u62E9" : "\u7528\u6237\u6307\u5B9A"}\uFF09`,
24517
+ `\u65E5\u671F\uFF1A${preview.dates.start} ~ ${preview.dates.end}\uFF08\u5168\u5929\uFF09`,
24518
+ `\u4F18\u5148\u7EA7\uFF1A${preview.priority.label}\uFF08${preview.priority.code}\uFF09`,
24519
+ `\u6210\u5458\uFF1A${formatMembers(preview.members)}`
24520
+ ];
24521
+ if (preview.contentText) {
24522
+ lines.push(`\u6B63\u6587\u9884\u89C8\uFF1A${preview.contentText}`);
24523
+ }
24524
+ lines.push(`\u6807\u7B7E\uFF1A${preview.tags.map((tag) => tag.name).join("\u3001") || "\u65E0"}`);
24525
+ lines.push(
24526
+ `\u5206\u7EC4\uFF1A${preview.group ? `${preview.group.name}\uFF08${preview.group.id}\uFF09` : "\u672A\u5206\u7EC4"}`
24527
+ );
24528
+ lines.push(`\u7236\u4EFB\u52A1\uFF1A${preview.parent ? `${preview.parent.title}\uFF08${preview.parent.taskId}\uFF09` : "\u65E0"}`);
24529
+ if (preview.project) {
24530
+ const project = preview.project.projectId ? `\u9879\u76EE ${preview.project.projectId}` : `\u5B50\u9879\u76EE ${preview.project.subProjectId}`;
24531
+ lines.push(`\u5F52\u5C5E\uFF1A${project}`);
24532
+ }
24533
+ if (preview.duplicateTaskIds.length) {
24534
+ lines.push(
24535
+ `\u540C\u540D\u4EFB\u52A1\u63D0\u793A\uFF1A\u540C\u8BA1\u5212\u4E0B\u5DF2\u6709 ${preview.duplicateTaskIds.length} \u6761\u540C\u540D\u4EFB\u52A1\uFF08${preview.duplicateTaskIds.join("\u3001")}\uFF09\uFF0C\u4EC5\u63D0\u793A\uFF0C\u4E0D\u963B\u65AD`
24536
+ );
24537
+ } else if (preview.duplicateNote) {
24538
+ lines.push(preview.duplicateNote);
24539
+ }
24540
+ lines.push(`previewToken\uFF1A${previewToken}`);
24541
+ lines.push(
24542
+ "\u8BF7\u5148\u628A\u4EE5\u4E0A\u6539\u52A8\u5C55\u793A\u7ED9\u7528\u6237\uFF0C\u5F97\u5230\u660E\u786E\u540C\u610F\u540E\uFF0C\u518D\u5E26 previewToken \u4E0E confirm=true \u8C03\u7528\u3002"
24543
+ );
24544
+ return lines.join("\n");
24545
+ }
24546
+ function formatMembers(members) {
24547
+ if (!members.length) {
24548
+ return "\u65E0";
24549
+ }
24550
+ return members.map((member) => `${member.roleLabel} ${member.name}\uFF08${member.empId}\uFF09`).join("\uFF1B");
24551
+ }
24552
+ function formatCategories(categories) {
24553
+ return categories.map((category) => `- ${category.name || "-"}\uFF08${category.id || "-"}\uFF09`).join("\n");
24554
+ }
24555
+ function formatTags(tags) {
24556
+ return tags.map((tag) => `- ${tag.name || "-"}\uFF08${tag.id || "-"}\uFF09`).join("\n");
24557
+ }
24558
+ function formatTemplates(templates) {
24559
+ return templates.map((template) => `- ${templateLabel(template)}`).join("\n");
24560
+ }
24561
+
23132
24562
  // src/tools/getTask.ts
23133
24563
  function registerGetTask(server, ctx) {
23134
24564
  server.registerTool(
@@ -23166,9 +24596,9 @@ function registerGetTask(server, ctx) {
23166
24596
  // src/tools/query.ts
23167
24597
  var SCAN_PAGE_SIZE = 100;
23168
24598
  var MAX_SCAN_ITEMS = 2e3;
23169
- function buildOwnerQuery(options) {
24599
+ function buildTaskQuery(options) {
23170
24600
  const query = {
23171
- empRoles: ["O"],
24601
+ empRoles: [...options.empRoles],
23172
24602
  isTopTask: "N",
23173
24603
  containsTaskEmps: "Y",
23174
24604
  containsTaskTags: "Y",
@@ -23178,12 +24608,25 @@ function buildOwnerQuery(options) {
23178
24608
  if (options.statusType) {
23179
24609
  query.statusTypeList = [options.statusType];
23180
24610
  }
24611
+ if (options.groupId) {
24612
+ query.groupId = options.groupId;
24613
+ }
24614
+ if (options.isNotInGroup) {
24615
+ query.isNotInGroup = "Y";
24616
+ }
24617
+ const task = {};
24618
+ if (options.planId) {
24619
+ task.planId = options.planId;
24620
+ }
23181
24621
  if (options.keyword?.trim()) {
23182
- query.task = { title: options.keyword.trim() };
24622
+ task.title = options.keyword.trim();
24623
+ }
24624
+ if (Object.keys(task).length) {
24625
+ query.task = task;
23183
24626
  }
23184
24627
  return query;
23185
24628
  }
23186
- async function fetchOwnerPage(ctx, base, page, size) {
24629
+ async function fetchTaskPage(ctx, base, page, size) {
23187
24630
  const raw = await ctx.client.requestRaw(
23188
24631
  "POST",
23189
24632
  "/external/home/task/v2/query/loadByParamsInPage",
@@ -23191,14 +24634,14 @@ async function fetchOwnerPage(ctx, base, page, size) {
23191
24634
  );
23192
24635
  return { items: raw.result ?? [], total: Number(raw.total ?? 0) };
23193
24636
  }
23194
- async function scanOwnerTasks(ctx, base, predicate) {
24637
+ async function scanTasks(ctx, base, predicate) {
23195
24638
  const matched = [];
23196
24639
  const statusNames = /* @__PURE__ */ new Set();
23197
24640
  const tagNames = /* @__PURE__ */ new Set();
23198
24641
  let scanned = 0;
23199
24642
  let total = 0;
23200
24643
  for (let page = 1; page <= MAX_SCAN_ITEMS / SCAN_PAGE_SIZE; page += 1) {
23201
- const result = await fetchOwnerPage(ctx, base, page, SCAN_PAGE_SIZE);
24644
+ const result = await fetchTaskPage(ctx, base, page, SCAN_PAGE_SIZE);
23202
24645
  total = result.total;
23203
24646
  scanned += result.items.length;
23204
24647
  for (const item of result.items) {
@@ -23260,18 +24703,20 @@ function assertScanComplete(result, hint) {
23260
24703
  }
23261
24704
  }
23262
24705
 
23263
- // src/tools/listMyTasks.ts
23264
- function registerListMyTasks(server, ctx) {
24706
+ // src/tools/taskList.ts
24707
+ function registerTaskList(server, ctx, definition) {
23265
24708
  server.registerTool(
23266
- "list_my_tasks",
24709
+ definition.name,
23267
24710
  {
23268
- title: "\u67E5\u8BE2\u6211\u8D1F\u8D23\u7684\u4EFB\u52A1",
23269
- description: "\u67E5\u8BE2\u8D1F\u8D23\u4EBA\uFF08\u89D2\u8272 O\uFF09\u662F\u5F53\u524D API Key \u7ED1\u5B9A\u5458\u5DE5\u7684\u4EFB\u52A1\uFF0C\u4E0D\u542B\u53C2\u4E0E\u4EBA/\u6284\u9001\u4EBA\u89C6\u89D2\u3002\u652F\u6301\u6309\u72B6\u6001\u540D\u79F0\u3001\u72B6\u6001\u7C7B\u578B\u3001\u5173\u952E\u8BCD\u3001\u6807\u7B7E\u7B5B\u9009\u548C\u5206\u9875\u3002\u72B6\u6001\u540D\u79F0\u6309\u4EFB\u52A1\u5B9E\u9645\u72B6\u6001\u7CBE\u786E\u5339\u914D\uFF1BS/P/F/E \u662F\u72B6\u6001\u7C7B\u578B\uFF0C\u4E0D\u662F\u72B6\u6001\u540D\u3002\u6807\u7B7E\u6309\u540D\u79F0\u6216 id \u7CBE\u786E\u5339\u914D\uFF0C\u6570\u7EC4\u8868\u793A\u540C\u65F6\u5177\u5907\u3002",
24711
+ title: definition.title,
24712
+ description: definition.description,
23270
24713
  inputSchema: {
23271
24714
  statusName: external_exports.string().optional().describe("\u72B6\u6001\u4E2D\u6587\u540D\uFF0C\u5982 \u672A\u5F00\u59CB\u3001\u5F85\u5904\u7406\u3001\u5F85\u53D1\u5E03\u3001\u5DF2\u89E3\u51B3\uFF1B\u4E0D\u8981\u4F20 S/P/F/E"),
23272
24715
  statusType: external_exports.enum(["S", "P", "F", "E"]).optional().describe("\u72B6\u6001\u7C7B\u578B"),
23273
24716
  keyword: external_exports.string().optional().describe("\u6807\u9898\u5173\u952E\u8BCD"),
23274
24717
  tag: external_exports.union([external_exports.string(), external_exports.array(external_exports.string())]).optional().describe("\u6807\u7B7E\u540D\u6216\u6807\u7B7E id\uFF1B\u6570\u7EC4\u8868\u793A\u540C\u65F6\u5177\u5907"),
24718
+ plan: external_exports.string().optional().describe("\u8BA1\u5212\u540D\u79F0\u6216 32 \u4F4D\u8BA1\u5212 id\uFF1B\u540D\u79F0\u91CD\u540D\u65F6\u8FD4\u56DE\u5019\u9009"),
24719
+ group: external_exports.string().optional().describe("\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\u540D\u79F0\u6216 id\uFF1B\u4F20\u300C\u672A\u5206\u7EC4\u300D\u8868\u793A\u53EA\u770B\u672A\u5206\u7EC4\u4EFB\u52A1"),
23275
24720
  page: external_exports.number().int().optional().describe("\u9875\u7801\uFF0C\u9ED8\u8BA4 1\uFF1B\u5C0F\u4E8E 1 \u6309 1 \u5904\u7406"),
23276
24721
  size: external_exports.number().int().optional().describe("\u6BCF\u9875\u6761\u6570\uFF0C\u9ED8\u8BA4 20\uFF1B\u5927\u4E8E 100 \u6309 100 \u5904\u7406")
23277
24722
  },
@@ -23279,14 +24724,14 @@ function registerListMyTasks(server, ctx) {
23279
24724
  },
23280
24725
  async (args) => {
23281
24726
  try {
23282
- return await handleList(ctx, args);
24727
+ return await handleList(ctx, args, definition);
23283
24728
  } catch (error2) {
23284
24729
  return fail(error2);
23285
24730
  }
23286
24731
  }
23287
24732
  );
23288
24733
  }
23289
- async function handleList(ctx, args) {
24734
+ async function handleList(ctx, args, definition) {
23290
24735
  const notes = [];
23291
24736
  const page = normalizePage(args.page);
23292
24737
  const size = normalizeSize(args.size);
@@ -23301,26 +24746,90 @@ async function handleList(ctx, args) {
23301
24746
  `\u300C${args.statusName}\u300D\u662F\u72B6\u6001\u7C7B\u578B\uFF0C\u4E0D\u662F\u72B6\u6001\u540D\u3002\u6309\u7C7B\u578B\u7B5B\u9009\u8BF7\u7528 statusType\uFF0C\u6309\u540D\u79F0\u8BF7\u7528\u4E2D\u6587\u72B6\u6001\u540D\uFF08\u5982 \u672A\u5F00\u59CB\u3001\u5F85\u5904\u7406\u3001\u5DF2\u53D1\u5E03\u3001\u5DF2\u5B8C\u6210\uFF09`
23302
24747
  );
23303
24748
  }
24749
+ let plan;
24750
+ let matchedBy;
24751
+ if (args.plan?.trim()) {
24752
+ const resolution = await resolvePlan(ctx, args.plan);
24753
+ if (!resolution.ok) {
24754
+ return ok(formatPlanFailure(resolution), {
24755
+ items: [],
24756
+ total: 0,
24757
+ page,
24758
+ size,
24759
+ filtered: true,
24760
+ empRole: definition.empRoles[0],
24761
+ planResolutionFailed: true,
24762
+ planCandidates: resolution.candidates,
24763
+ availablePlans: resolution.available ?? [],
24764
+ ...notes.length ? { notes } : {}
24765
+ });
24766
+ }
24767
+ plan = resolution.plan;
24768
+ matchedBy = resolution.matchedBy;
24769
+ }
24770
+ let group;
24771
+ let ungrouped = false;
24772
+ let groupMatchedBy;
24773
+ if (args.group?.trim()) {
24774
+ if (isNoGroupTarget(args.group)) {
24775
+ ungrouped = true;
24776
+ groupMatchedBy = "none";
24777
+ } else {
24778
+ const resolution = await resolveTaskGroup(ctx, args.group);
24779
+ if (!resolution.ok) {
24780
+ return ok(formatGroupFailure(resolution), {
24781
+ items: [],
24782
+ total: 0,
24783
+ page,
24784
+ size,
24785
+ filtered: true,
24786
+ empRole: definition.empRoles[0],
24787
+ groupResolutionFailed: true,
24788
+ groupCandidates: resolution.candidates,
24789
+ availableGroups: resolution.available ?? [],
24790
+ ...notes.length ? { notes } : {}
24791
+ });
24792
+ }
24793
+ group = resolution.group;
24794
+ groupMatchedBy = String(group.id ?? "") === args.group.trim() ? "id" : "name";
24795
+ }
24796
+ }
23304
24797
  const tags = normalizeTags(args.tag);
23305
24798
  const needsClientFilter = Boolean(args.statusName) || tags.length > 0;
23306
- const base = buildOwnerQuery(args);
24799
+ const base = buildTaskQuery({
24800
+ empRoles: definition.empRoles,
24801
+ planId: plan?.id,
24802
+ groupId: group?.id,
24803
+ isNotInGroup: ungrouped,
24804
+ statusType: args.statusType,
24805
+ keyword: args.keyword
24806
+ });
23307
24807
  const start = (page - 1) * size;
23308
24808
  if (!needsClientFilter) {
23309
- const result = await fetchOwnerPage(ctx, base, page, size);
24809
+ const result = await fetchTaskPage(ctx, base, page, size);
23310
24810
  if (result.total > 0 && start >= result.total) {
23311
24811
  return pageOutOfRange(result.total, page, size, notes);
23312
24812
  }
23313
24813
  const items2 = result.items.map(summarizeListItem);
23314
- return ok(formatListText(items2, result.total, page, size, notes), {
23315
- items: items2,
23316
- total: result.total,
23317
- page,
23318
- size,
23319
- filtered: false,
23320
- ...notes.length ? { notes } : {}
23321
- });
24814
+ return ok(
24815
+ formatListText(items2, result.total, page, size, notes, definition.roleLabel, {
24816
+ planTitle: plan?.title,
24817
+ groupTitle: groupTitleValue(group, ungrouped)
24818
+ }),
24819
+ {
24820
+ items: items2,
24821
+ total: result.total,
24822
+ page,
24823
+ size,
24824
+ filtered: false,
24825
+ empRole: definition.empRoles[0],
24826
+ ...planOutput(plan, matchedBy),
24827
+ ...groupOutput(group, ungrouped, groupMatchedBy),
24828
+ ...notes.length ? { notes } : {}
24829
+ }
24830
+ );
23322
24831
  }
23323
- const scanned = await scanOwnerTasks(ctx, base, (item) => {
24832
+ const scanned = await scanTasks(ctx, base, (item) => {
23324
24833
  if (args.statusName && item.statusValue !== args.statusName) {
23325
24834
  return false;
23326
24835
  }
@@ -23336,6 +24845,14 @@ async function handleList(ctx, args) {
23336
24845
  }
23337
24846
  if (total === 0) {
23338
24847
  const hints = [];
24848
+ if (plan) {
24849
+ hints.push(`\u8BA1\u5212\u300C${plan.title}\u300D\u4E0B\u6CA1\u6709\u5339\u914D\u7684\u4EFB\u52A1\u3002`);
24850
+ }
24851
+ if (group || ungrouped) {
24852
+ hints.push(
24853
+ `\u5206\u7EC4\u300C${groupTitleValue(group, ungrouped)}\u300D\u4E0B\u6CA1\u6709\u5339\u914D\u7684\u4EFB\u52A1\u3002`
24854
+ );
24855
+ }
23339
24856
  if (args.statusName) {
23340
24857
  hints.push(
23341
24858
  `\u6CA1\u6709\u72B6\u6001\u4E3A\u300C${args.statusName}\u300D\u7684\u4EFB\u52A1\u3002\u4F60\u7684\u4EFB\u52A1\u5B9E\u9645\u72B6\u6001\u6709\uFF1A${scanned.statusNames.join("\u3001") || "\u65E0"}`
@@ -23353,16 +24870,21 @@ async function handleList(ctx, args) {
23353
24870
  page,
23354
24871
  size,
23355
24872
  filtered: true,
24873
+ empRole: definition.empRoles[0],
23356
24874
  scanned: scanned.scanned,
23357
24875
  availableStatusNames: scanned.statusNames,
23358
- availableTagNames: scanned.tagNames
24876
+ availableTagNames: scanned.tagNames,
24877
+ ...planOutput(plan, matchedBy),
24878
+ ...groupOutput(group, ungrouped, groupMatchedBy)
23359
24879
  });
23360
24880
  }
23361
24881
  const items = scanned.matched.slice(start, start + size).map(summarizeListItem);
23362
24882
  return ok(
23363
- formatListText(items, total, page, size, notes, {
24883
+ formatListText(items, total, page, size, notes, definition.roleLabel, {
23364
24884
  statusName: args.statusName,
23365
- tags
24885
+ tags,
24886
+ planTitle: plan?.title,
24887
+ groupTitle: groupTitleValue(group, ungrouped)
23366
24888
  }),
23367
24889
  {
23368
24890
  items,
@@ -23370,11 +24892,47 @@ async function handleList(ctx, args) {
23370
24892
  page,
23371
24893
  size,
23372
24894
  filtered: true,
24895
+ empRole: definition.empRoles[0],
23373
24896
  scanned: scanned.scanned,
24897
+ ...planOutput(plan, matchedBy),
24898
+ ...groupOutput(group, ungrouped, groupMatchedBy),
23374
24899
  ...notes.length ? { notes } : {}
23375
24900
  }
23376
24901
  );
23377
24902
  }
24903
+ function groupOutput(group, ungrouped, matchedBy) {
24904
+ if (ungrouped) {
24905
+ return {
24906
+ groupName: "\u672A\u5206\u7EC4",
24907
+ ungrouped: true,
24908
+ groupMatchedBy: matchedBy
24909
+ };
24910
+ }
24911
+ if (!group) {
24912
+ return {};
24913
+ }
24914
+ return {
24915
+ groupId: String(group.id ?? ""),
24916
+ groupName: String(group.groupName ?? ""),
24917
+ groupMatchedBy: matchedBy
24918
+ };
24919
+ }
24920
+ function groupTitleValue(group, ungrouped) {
24921
+ if (ungrouped) {
24922
+ return "\u672A\u5206\u7EC4";
24923
+ }
24924
+ return group ? String(group.groupName ?? "").trim() || void 0 : void 0;
24925
+ }
24926
+ function planOutput(plan, matchedBy) {
24927
+ if (!plan) {
24928
+ return {};
24929
+ }
24930
+ return {
24931
+ planId: plan.id,
24932
+ planTitle: plan.title,
24933
+ planMatchedBy: matchedBy
24934
+ };
24935
+ }
23378
24936
  function normalizePage(value) {
23379
24937
  return value !== void 0 && Number.isInteger(value) && value >= 1 ? value : 1;
23380
24938
  }
@@ -23396,14 +24954,25 @@ function pageOutOfRange(total, page, size, notes) {
23396
24954
  }
23397
24955
  );
23398
24956
  }
23399
- function formatListText(items, total, page, size, notes, filter) {
23400
- const headerParts = [`\u5171 ${total} \u6761`, `\u7B2C ${page} \u9875`, `\u6BCF\u9875 ${size} \u6761`];
24957
+ function formatListText(items, total, page, size, notes, roleLabel2, filter) {
24958
+ const headerParts = [
24959
+ `\u5171 ${total} \u6761`,
24960
+ `\u7B2C ${page} \u9875`,
24961
+ `\u6BCF\u9875 ${size} \u6761`,
24962
+ `\u89C6\u89D2=${roleLabel2}`
24963
+ ];
23401
24964
  if (filter?.statusName) {
23402
24965
  headerParts.push(`\u72B6\u6001=${filter.statusName}`);
23403
24966
  }
23404
24967
  if (filter?.tags?.length) {
23405
24968
  headerParts.push(`\u6807\u7B7E=${filter.tags.join("+")}`);
23406
24969
  }
24970
+ if (filter?.planTitle) {
24971
+ headerParts.push(`\u8BA1\u5212=${filter.planTitle}`);
24972
+ }
24973
+ if (filter?.groupTitle) {
24974
+ headerParts.push(`\u5206\u7EC4=${filter.groupTitle}`);
24975
+ }
23407
24976
  const lines = [...notes];
23408
24977
  if (!items.length) {
23409
24978
  lines.push(`${headerParts.join("\uFF0C")}`, "\u6CA1\u6709\u5339\u914D\u7684\u4EFB\u52A1\u3002");
@@ -23418,23 +24987,60 @@ function formatListText(items, total, page, size, notes, filter) {
23418
24987
  return lines.join("\n");
23419
24988
  }
23420
24989
 
24990
+ // src/tools/listCreatedTasks.ts
24991
+ function registerListCreatedTasks(server, ctx) {
24992
+ registerTaskList(server, ctx, {
24993
+ name: "list_created_tasks",
24994
+ title: "\u67E5\u8BE2\u6211\u521B\u5EFA\u7684\u4EFB\u52A1",
24995
+ description: "\u67E5\u8BE2\u521B\u5EFA\u4EBA\uFF08\u4EFB\u52A1\u6210\u5458\u89D2\u8272 R\uFF09\u662F\u5F53\u524D API Key \u7ED1\u5B9A\u5458\u5DE5\u7684\u4EFB\u52A1\uFF0C\u4E0D\u662F\u8D1F\u8D23\u4EBA\u89C6\u89D2\u3002\u652F\u6301\u6309\u72B6\u6001\u540D\u79F0\u3001\u72B6\u6001\u7C7B\u578B\u3001\u5173\u952E\u8BCD\u3001\u6807\u7B7E\u3001\u8BA1\u5212\u3001\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\u548C\u5206\u9875\u7B5B\u9009\u3002\u72B6\u6001\u540D\u79F0\u6309\u4EFB\u52A1\u5B9E\u9645\u72B6\u6001\u7CBE\u786E\u5339\u914D\uFF1BS/P/F/E \u662F\u72B6\u6001\u7C7B\u578B\uFF0C\u4E0D\u662F\u72B6\u6001\u540D\u3002\u6807\u7B7E\u6309\u540D\u79F0\u6216 id \u7CBE\u786E\u5339\u914D\uFF0C\u6570\u7EC4\u8868\u793A\u540C\u65F6\u5177\u5907\u3002\u8BA1\u5212\u53EF\u4F20\u540D\u79F0\u6216 32 \u4F4D id\uFF1B\u5206\u7EC4\u53EF\u4F20\u540D\u79F0\u6216 id\uFF0C\u4F20\u300C\u672A\u5206\u7EC4\u300D\u8868\u793A\u53EA\u770B\u672A\u5206\u7EC4\u4EFB\u52A1\uFF1B\u540D\u79F0\u91CD\u540D\u65F6\u8FD4\u56DE\u5019\u9009\uFF0C\u4E0D\u8FD4\u56DE\u4EFB\u52A1\u3002",
24996
+ empRoles: ["R"],
24997
+ roleLabel: "\u521B\u5EFA\u4EBA"
24998
+ });
24999
+ }
25000
+
25001
+ // src/tools/listMyTasks.ts
25002
+ function registerListMyTasks(server, ctx) {
25003
+ registerTaskList(server, ctx, {
25004
+ name: "list_my_tasks",
25005
+ title: "\u67E5\u8BE2\u6211\u8D1F\u8D23\u7684\u4EFB\u52A1",
25006
+ description: "\u67E5\u8BE2\u8D1F\u8D23\u4EBA\uFF08\u89D2\u8272 O\uFF09\u662F\u5F53\u524D API Key \u7ED1\u5B9A\u5458\u5DE5\u7684\u4EFB\u52A1\uFF0C\u4E0D\u542B\u53C2\u4E0E\u4EBA/\u6284\u9001\u4EBA\u89C6\u89D2\u3002\u652F\u6301\u6309\u72B6\u6001\u540D\u79F0\u3001\u72B6\u6001\u7C7B\u578B\u3001\u5173\u952E\u8BCD\u3001\u6807\u7B7E\u3001\u8BA1\u5212\u3001\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\u548C\u5206\u9875\u7B5B\u9009\u3002\u72B6\u6001\u540D\u79F0\u6309\u4EFB\u52A1\u5B9E\u9645\u72B6\u6001\u7CBE\u786E\u5339\u914D\uFF1BS/P/F/E \u662F\u72B6\u6001\u7C7B\u578B\uFF0C\u4E0D\u662F\u72B6\u6001\u540D\u3002\u6807\u7B7E\u6309\u540D\u79F0\u6216 id \u7CBE\u786E\u5339\u914D\uFF0C\u6570\u7EC4\u8868\u793A\u540C\u65F6\u5177\u5907\u3002\u8BA1\u5212\u53EF\u4F20\u540D\u79F0\u6216 32 \u4F4D id\uFF1B\u5206\u7EC4\u53EF\u4F20\u540D\u79F0\u6216 id\uFF0C\u4F20\u300C\u672A\u5206\u7EC4\u300D\u8868\u793A\u53EA\u770B\u672A\u5206\u7EC4\u4EFB\u52A1\uFF1B\u540D\u79F0\u91CD\u540D\u65F6\u8FD4\u56DE\u5019\u9009\uFF0C\u4E0D\u8FD4\u56DE\u4EFB\u52A1\u3002",
25007
+ empRoles: ["O"],
25008
+ roleLabel: "\u8D1F\u8D23\u4EBA"
25009
+ });
25010
+ }
25011
+
23421
25012
  // src/tools/myTaskStats.ts
23422
25013
  function registerMyTaskStats(server, ctx) {
23423
25014
  server.registerTool(
23424
25015
  "my_task_stats",
23425
25016
  {
23426
25017
  title: "\u7EDF\u8BA1\u6211\u8D1F\u8D23\u7684\u4EFB\u52A1",
23427
- description: "\u7EDF\u8BA1\u8D1F\u8D23\u4EBA\uFF08\u89D2\u8272 O\uFF09\u662F\u5F53\u524D API Key \u7ED1\u5B9A\u5458\u5DE5\u7684\u4EFB\u52A1\u6570\u91CF\uFF0C\u4E0D\u542B\u53C2\u4E0E\u4EBA/\u6284\u9001\u4EBA\u89C6\u89D2\u3002\u8FD4\u56DE\u6309\u72B6\u6001\u540D\u79F0\u548C\u6309\u72B6\u6001\u7C7B\u578B\uFF08S/P/F/E\uFF09\u4E24\u5C42\u6C47\u603B\uFF0C\u53EF\u9009\u6309\u6807\u7B7E\u8FC7\u6EE4\uFF1B\u6807\u7B7E\u6309\u540D\u79F0\u6216 id \u7CBE\u786E\u5339\u914D\u3002",
25018
+ description: "\u7EDF\u8BA1\u8D1F\u8D23\u4EBA\uFF08\u89D2\u8272 O\uFF09\u662F\u5F53\u524D API Key \u7ED1\u5B9A\u5458\u5DE5\u7684\u4EFB\u52A1\u6570\u91CF\uFF0C\u4E0D\u542B\u53C2\u4E0E\u4EBA/\u6284\u9001\u4EBA\u89C6\u89D2\u3002\u8FD4\u56DE\u6309\u72B6\u6001\u540D\u79F0\u548C\u6309\u72B6\u6001\u7C7B\u578B\uFF08S/P/F/E\uFF09\u4E24\u5C42\u6C47\u603B\uFF0C\u53EF\u9009\u6309\u6807\u7B7E\u3001\u8BA1\u5212\u8FC7\u6EE4\uFF1B\u6807\u7B7E\u6309\u540D\u79F0\u6216 id \u7CBE\u786E\u5339\u914D\uFF0C\u8BA1\u5212\u53EF\u4F20\u540D\u79F0\u6216 32 \u4F4D id\u3002\u8BA1\u5212\u540D\u91CD\u540D\u65F6\u8FD4\u56DE\u5019\u9009\uFF0C\u4E0D\u8FD4\u56DE\u7EDF\u8BA1\u6570\u5B57\u3002",
23428
25019
  inputSchema: {
23429
- tag: external_exports.union([external_exports.string(), external_exports.array(external_exports.string())]).optional().describe("\u6807\u7B7E\u540D\u6216\u6807\u7B7E id\uFF1B\u6570\u7EC4\u8868\u793A\u540C\u65F6\u5177\u5907")
25020
+ tag: external_exports.union([external_exports.string(), external_exports.array(external_exports.string())]).optional().describe("\u6807\u7B7E\u540D\u6216\u6807\u7B7E id\uFF1B\u6570\u7EC4\u8868\u793A\u540C\u65F6\u5177\u5907"),
25021
+ plan: external_exports.string().optional().describe("\u8BA1\u5212\u540D\u79F0\u6216 32 \u4F4D\u8BA1\u5212 id\uFF1B\u540D\u79F0\u91CD\u540D\u65F6\u8FD4\u56DE\u5019\u9009")
23430
25022
  },
23431
25023
  annotations: { readOnlyHint: true }
23432
25024
  },
23433
25025
  async (args) => {
23434
25026
  try {
25027
+ let plan;
25028
+ let matchedBy;
25029
+ if (args.plan?.trim()) {
25030
+ const resolution = await resolvePlan(ctx, args.plan);
25031
+ if (!resolution.ok) {
25032
+ return ok(formatPlanFailure(resolution), {
25033
+ planResolutionFailed: true,
25034
+ planCandidates: resolution.candidates,
25035
+ availablePlans: resolution.available ?? []
25036
+ });
25037
+ }
25038
+ plan = resolution.plan;
25039
+ matchedBy = resolution.matchedBy;
25040
+ }
23435
25041
  const tags = normalizeTags(args.tag);
23436
- const base = buildOwnerQuery({});
23437
- const scanned = await scanOwnerTasks(ctx, base, (item) => matchesTags(item, tags));
25042
+ const base = buildTaskQuery({ empRoles: ["O"], planId: plan?.id });
25043
+ const scanned = await scanTasks(ctx, base, (item) => matchesTags(item, tags));
23438
25044
  const byNameMap = /* @__PURE__ */ new Map();
23439
25045
  const byType = { S: 0, P: 0, F: 0, E: 0 };
23440
25046
  for (const item of scanned.matched) {
@@ -23465,20 +25071,22 @@ function registerMyTaskStats(server, ctx) {
23465
25071
  scanned: scanned.scanned,
23466
25072
  partial: scanned.partial,
23467
25073
  tag: tags,
23468
- availableTagNames: scanned.tagNames
25074
+ availableTagNames: scanned.tagNames,
25075
+ empRole: "O",
25076
+ ...plan ? { planId: plan.id, planTitle: plan.title, planMatchedBy: matchedBy } : {}
23469
25077
  };
23470
25078
  const hint = total === 0 && tags.length ? `
23471
25079
  \u6CA1\u6709\u6807\u7B7E\u4E3A\u300C${tags.join("+")}\u300D\u7684\u4EFB\u52A1\u3002\u626B\u63CF\u5230\u7684\u6807\u7B7E\u6709\uFF1A${scanned.tagNames.join("\u3001") || "\u65E0"}` : "";
23472
- return ok(`${formatStatsText(structured)}${hint}`, structured);
25080
+ return ok(`${formatStatsText(structured, plan?.title)}${hint}`, structured);
23473
25081
  } catch (error2) {
23474
25082
  return fail(error2);
23475
25083
  }
23476
25084
  }
23477
25085
  );
23478
25086
  }
23479
- function formatStatsText(stats) {
25087
+ function formatStatsText(stats, planTitle) {
23480
25088
  const lines = [
23481
- `\u6211\u7684\u4EFB\u52A1\u5171 ${stats.total} \u6761${stats.tag.length ? `\uFF08\u6807\u7B7E ${stats.tag.join("+")}\uFF09` : ""}\uFF0C\u626B\u63CF ${stats.scanned} \u6761`
25089
+ `${planTitle ? `\u8BA1\u5212\u300C${planTitle}\u300D\u5185` : ""}\u6211\u8D1F\u8D23\u7684\u4EFB\u52A1\u5171 ${stats.total} \u6761${stats.tag.length ? `\uFF08\u6807\u7B7E ${stats.tag.join("+")}\uFF09` : ""}\uFF0C\u626B\u63CF ${stats.scanned} \u6761`
23482
25090
  ];
23483
25091
  lines.push(
23484
25092
  `\u6309\u72B6\u6001\uFF1A${stats.byName.length ? stats.byName.map((item) => `${item.name}(${item.type || "-"}) ${item.count}`).join("\uFF1B") : "\u65E0"}`
@@ -23537,6 +25145,284 @@ function registerSearchEmployee(server, ctx) {
23537
25145
  );
23538
25146
  }
23539
25147
 
25148
+ // src/tools/taskGroups.ts
25149
+ function registerTaskGroups(server, ctx) {
25150
+ registerListTaskGroups(server, ctx);
25151
+ registerManageTaskGroup(server, ctx);
25152
+ }
25153
+ function registerListTaskGroups(server, ctx) {
25154
+ server.registerTool(
25155
+ "list_task_groups",
25156
+ {
25157
+ title: "\u67E5\u8BE2\u6211\u7684\u4EFB\u52A1\u5206\u7EC4",
25158
+ description: "\u5217\u51FA\u5F53\u524D API Key \u5458\u5DE5\u7684\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\uFF08\u300C\u6211\u7684\u4EFB\u52A1\u300D\u9875\u7684\u81EA\u5B9A\u4E49\u5206\u7EC4\uFF09\uFF0C\u8FD4\u56DE\u540D\u79F0\u3001id\u3001\u6392\u5E8F\u548C\u521B\u5EFA\u65F6\u95F4\u3002withCounts=true \u65F6\u9010\u7EC4\u8FD4\u56DE\u5F53\u524D\u5458\u5DE5\u53EF\u89C1\u7684\u4EFB\u52A1\u6570\uFF08\u4E0D\u9650\u89D2\u8272\uFF09\uFF1B\u5206\u7EC4\u8D85\u8FC7 30 \u4E2A\u65F6\u4E0D\u7EDF\u8BA1\u4EFB\u52A1\u6570\u3002\u4E0D\u542B\u8BA1\u5212\u5171\u4EAB\u5206\u7EC4\u3002",
25159
+ inputSchema: {
25160
+ withCounts: external_exports.boolean().optional().describe("true \u65F6\u8FD4\u56DE\u6BCF\u4E2A\u5206\u7EC4\u7684\u4EFB\u52A1\u6570\uFF1B\u9ED8\u8BA4 false\uFF0C\u53EA\u5217\u5206\u7EC4")
25161
+ },
25162
+ annotations: { readOnlyHint: true }
25163
+ },
25164
+ async (args) => {
25165
+ try {
25166
+ const groups = await loadPersonalGroups(ctx);
25167
+ if (!groups.length) {
25168
+ return ok("\u5F53\u524D\u5458\u5DE5\u8FD8\u6CA1\u6709\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\uFF1B\u53EF\u7528 manage_task_group \u521B\u5EFA\u3002", {
25169
+ total: 0,
25170
+ groups: [],
25171
+ countsOmitted: false
25172
+ });
25173
+ }
25174
+ const countsOmitted = Boolean(
25175
+ args.withCounts && groups.length > MAX_GROUPS_FOR_COUNTS
25176
+ );
25177
+ const items = [];
25178
+ for (const group of groups) {
25179
+ const id = String(group.id ?? "");
25180
+ const name = String(group.groupName ?? "");
25181
+ const taskCount = args.withCounts && !countsOmitted && id ? await groupTaskCount(ctx, id) : void 0;
25182
+ items.push({
25183
+ groupId: id,
25184
+ name,
25185
+ seq: group.seq,
25186
+ createTime: group.createTime,
25187
+ ...taskCount === void 0 ? {} : { taskCount }
25188
+ });
25189
+ }
25190
+ const lines = [`\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\u5171 ${items.length} \u4E2A`];
25191
+ if (countsOmitted) {
25192
+ lines.push(
25193
+ `\u5206\u7EC4\u8D85\u8FC7 ${MAX_GROUPS_FOR_COUNTS} \u4E2A\uFF0C\u672C\u6B21\u4E0D\u7EDF\u8BA1\u4EFB\u52A1\u6570\uFF1B\u53EF\u4F20 withCounts=false \u5148\u770B\u5206\u7EC4\u3002`
25194
+ );
25195
+ }
25196
+ for (const item of items) {
25197
+ const count = item.taskCount === void 0 ? "" : ` \u4EFB\u52A1 ${item.taskCount} \u6761`;
25198
+ lines.push(
25199
+ `- ${item.name || "\uFF08\u65E0\u540D\u79F0\uFF09"}\uFF08${item.groupId}\uFF09 \u6392\u5E8F=${item.seq ?? "-"}${count}`
25200
+ );
25201
+ }
25202
+ return ok(lines.join("\n"), {
25203
+ total: items.length,
25204
+ groups: items,
25205
+ countsOmitted
25206
+ });
25207
+ } catch (error2) {
25208
+ return fail(error2);
25209
+ }
25210
+ }
25211
+ );
25212
+ }
25213
+ function registerManageTaskGroup(server, ctx) {
25214
+ server.registerTool(
25215
+ "manage_task_group",
25216
+ {
25217
+ title: "\u7BA1\u7406\u6211\u7684\u4EFB\u52A1\u5206\u7EC4",
25218
+ description: "\u7BA1\u7406\u5F53\u524D API Key \u5458\u5DE5\u7684\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\uFF1Aaction=create \u521B\u5EFA\uFF08name \u5FC5\u586B\uFF09\uFF1Baction=rename \u91CD\u547D\u540D\uFF08group + newName\uFF09\uFF1Baction=delete \u5220\u9664\uFF08group\uFF0C\u53EF\u9009 force\uFF09\u3002\u5220\u9664\u9ED8\u8BA4\u8981\u6C42\u5206\u7EC4\u4E3A\u7A7A\uFF1Bforce=true \u65F6\u6574\u7EC4\u5220\u9664\uFF0C\u7EC4\u5185\u4EFB\u52A1\u53D8\u4E3A\u672A\u5206\u7EC4\uFF08\u4EFB\u52A1\u672C\u8EAB\u4E0D\u5220\u9664\uFF09\u3002\u6240\u6709\u5199\u64CD\u4F5C\u5FC5\u987B\u5148\u4E0D\u5E26 confirm \u8C03\u7528\u62FF previewToken\uFF0C\u628A\u9884\u6F14\u5C55\u793A\u7ED9\u7528\u6237\u5E76\u53D6\u5F97\u660E\u786E\u540C\u610F\u540E\uFF0C\u518D\u5E26 previewToken \u548C confirm=true \u6267\u884C\u3002",
25219
+ inputSchema: {
25220
+ action: external_exports.enum(["create", "rename", "delete"]).describe("\u64CD\u4F5C\u7C7B\u578B"),
25221
+ name: external_exports.string().optional().describe("create\uFF1A\u65B0\u5206\u7EC4\u540D\u79F0\uFF0C1\u201330 \u5B57\u7B26"),
25222
+ group: external_exports.string().optional().describe("rename/delete\uFF1A\u5206\u7EC4\u540D\u79F0\u6216\u5206\u7EC4 id"),
25223
+ newName: external_exports.string().optional().describe("rename\uFF1A\u65B0\u5206\u7EC4\u540D\u79F0\uFF0C1\u201330 \u5B57\u7B26"),
25224
+ force: external_exports.boolean().optional().describe("delete\uFF1Atrue \u65F6\u5373\u4F7F\u5206\u7EC4\u4E0B\u6709\u4EFB\u52A1\u4E5F\u5220\u9664\uFF0C\u4EFB\u52A1\u53D8\u4E3A\u672A\u5206\u7EC4"),
25225
+ confirm: external_exports.boolean().optional().describe("true \u624D\u771F\u6B63\u5199\u5165\uFF1B\u7F3A\u7701\u53EA\u9884\u6F14"),
25226
+ previewToken: external_exports.string().optional().describe("\u9884\u6F14\u8FD4\u56DE\u7684\u4EE4\u724C\uFF1Bconfirm=true \u65F6\u5FC5\u586B")
25227
+ },
25228
+ annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false }
25229
+ },
25230
+ async (args) => {
25231
+ try {
25232
+ return await handleManageGroup(ctx, args);
25233
+ } catch (error2) {
25234
+ return fail(error2);
25235
+ }
25236
+ }
25237
+ );
25238
+ }
25239
+ async function handleManageGroup(ctx, args) {
25240
+ if (args.action === "create") {
25241
+ return handleCreateGroup(ctx, args);
25242
+ }
25243
+ if (args.action === "rename") {
25244
+ return handleRenameGroup(ctx, args);
25245
+ }
25246
+ return handleDeleteGroup(ctx, args);
25247
+ }
25248
+ async function handleCreateGroup(ctx, args) {
25249
+ const name = validateGroupName(args.name ?? "", "\u65B0\u5206\u7EC4\u540D\u79F0");
25250
+ const groups = await loadPersonalGroups(ctx);
25251
+ const duplicate = findDuplicateGroup(groups, name);
25252
+ if (duplicate) {
25253
+ throw new EworkError(
25254
+ `\u5206\u7EC4\u300C${name}\u300D\u5DF2\u5B58\u5728\uFF08${duplicate.id ?? "-"}\uFF09\uFF1B\u8BF7\u6362\u4E00\u4E2A\u540D\u79F0\uFF0C\u6216\u76F4\u63A5\u7528\u5DF2\u6709\u5206\u7EC4`
25255
+ );
25256
+ }
25257
+ const payload = { action: "create", name };
25258
+ const preview = formatManagePreview(`\u521B\u5EFA\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\u300C${name}\u300D`);
25259
+ if (!args.confirm) {
25260
+ const previewToken = createPreviewToken("manage_task_group", "new", payload);
25261
+ return ok(`${preview}
25262
+ previewToken\uFF1A${previewToken}
25263
+ \u8BF7\u786E\u8BA4\u540E\u5E26 previewToken \u4E0E confirm=true \u6267\u884C\u3002`, {
25264
+ action: "create",
25265
+ name,
25266
+ previewToken,
25267
+ expiresInSeconds: previewTtlSeconds()
25268
+ });
25269
+ }
25270
+ consumePreviewToken(args.previewToken, "manage_task_group", "new", payload);
25271
+ const groupId = String(
25272
+ await ctx.client.post("/external/home/task/setting/createGroup", {
25273
+ groupName: name
25274
+ }) ?? ""
25275
+ ).trim();
25276
+ const after = await loadPersonalGroups(ctx);
25277
+ const created = after.find(
25278
+ (group) => groupId && String(group.id ?? "") === groupId || String(group.groupName ?? "").trim() === name
25279
+ );
25280
+ const verified = Boolean(created) && String(created?.groupName ?? "").trim() === name;
25281
+ const resultId = groupId || String(created?.id ?? "");
25282
+ return ok(
25283
+ [
25284
+ verified ? `\u5DF2\u521B\u5EFA\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\u300C${name}\u300D\uFF08${resultId || "-"}\uFF09\u3002` : `\u521B\u5EFA\u5DF2\u63D0\u4EA4\uFF0C\u4F46\u56DE\u8BFB\u672A\u786E\u8BA4\u5206\u7EC4\u300C${name}\u300D\uFF1B\u8BF7\u624B\u52A8\u68C0\u67E5\u3002`
25285
+ ].join("\n"),
25286
+ {
25287
+ action: "create",
25288
+ name,
25289
+ groupId: resultId,
25290
+ verified
25291
+ }
25292
+ );
25293
+ }
25294
+ async function handleRenameGroup(ctx, args) {
25295
+ const groupInput = String(args.group ?? "").trim();
25296
+ if (!groupInput) {
25297
+ throw new EworkError("\u8BF7\u63D0\u4F9B\u8981\u91CD\u547D\u540D\u7684\u5206\u7EC4\u540D\u79F0\u6216\u5206\u7EC4 id");
25298
+ }
25299
+ const newName = validateGroupName(args.newName ?? "", "\u65B0\u5206\u7EC4\u540D\u79F0");
25300
+ const groups = await loadPersonalGroups(ctx);
25301
+ const resolution = matchGroup(groupInput, groups);
25302
+ if (!resolution.ok) {
25303
+ throw new EworkError(formatGroupFailure(resolution));
25304
+ }
25305
+ const group = resolution.group;
25306
+ const groupId = String(group.id ?? "");
25307
+ const oldName = String(group.groupName ?? "");
25308
+ const duplicate = findDuplicateGroup(groups, newName, groupId);
25309
+ if (duplicate) {
25310
+ throw new EworkError(
25311
+ `\u5206\u7EC4\u300C${newName}\u300D\u5DF2\u5B58\u5728\uFF08${duplicate.id ?? "-"}\uFF09\uFF1B\u8BF7\u6362\u4E00\u4E2A\u540D\u79F0`
25312
+ );
25313
+ }
25314
+ if (oldName === newName) {
25315
+ return ok(`\u5206\u7EC4\u300C${oldName}\u300D\u540D\u79F0\u6CA1\u6709\u53D8\u5316\uFF0C\u672A\u6267\u884C\u5199\u5165\u3002`, {
25316
+ action: "rename",
25317
+ groupId,
25318
+ name: oldName,
25319
+ verified: true,
25320
+ changed: false
25321
+ });
25322
+ }
25323
+ const payload = { action: "rename", groupId, newName };
25324
+ const preview = formatManagePreview(
25325
+ `\u91CD\u547D\u540D\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\uFF1A${oldName}\uFF08${groupId}\uFF09 \u2192 ${newName}`
25326
+ );
25327
+ if (!args.confirm) {
25328
+ const previewToken = createPreviewToken("manage_task_group", groupId, payload);
25329
+ return ok(`${preview}
25330
+ previewToken\uFF1A${previewToken}
25331
+ \u8BF7\u786E\u8BA4\u540E\u5E26 previewToken \u4E0E confirm=true \u6267\u884C\u3002`, {
25332
+ action: "rename",
25333
+ groupId,
25334
+ before: oldName,
25335
+ after: newName,
25336
+ previewToken,
25337
+ expiresInSeconds: previewTtlSeconds()
25338
+ });
25339
+ }
25340
+ consumePreviewToken(args.previewToken, "manage_task_group", groupId, payload);
25341
+ await ctx.client.post("/external/home/task/setting/updateGroup", {
25342
+ id: groupId,
25343
+ groupName: newName
25344
+ });
25345
+ const after = await loadPersonalGroups(ctx);
25346
+ const updated = after.find((item) => String(item.id ?? "") === groupId);
25347
+ const verified = String(updated?.groupName ?? "").trim() === newName;
25348
+ return ok(
25349
+ verified ? `\u5DF2\u628A\u5206\u7EC4\u300C${oldName}\u300D\u91CD\u547D\u540D\u4E3A\u300C${newName}\u300D\u3002` : `\u91CD\u547D\u540D\u5DF2\u63D0\u4EA4\uFF0C\u4F46\u56DE\u8BFB\u672A\u786E\u8BA4\uFF1B\u5F53\u524D\u540D\u79F0\u4E3A\u300C${updated?.groupName ?? "-"}\u300D\uFF0C\u8BF7\u624B\u52A8\u68C0\u67E5\u3002`,
25350
+ {
25351
+ action: "rename",
25352
+ groupId,
25353
+ before: oldName,
25354
+ after: newName,
25355
+ verified
25356
+ }
25357
+ );
25358
+ }
25359
+ async function handleDeleteGroup(ctx, args) {
25360
+ const groupInput = String(args.group ?? "").trim();
25361
+ if (!groupInput) {
25362
+ throw new EworkError("\u8BF7\u63D0\u4F9B\u8981\u5220\u9664\u7684\u5206\u7EC4\u540D\u79F0\u6216\u5206\u7EC4 id");
25363
+ }
25364
+ const groups = await loadPersonalGroups(ctx);
25365
+ const resolution = matchGroup(groupInput, groups);
25366
+ if (!resolution.ok) {
25367
+ throw new EworkError(formatGroupFailure(resolution));
25368
+ }
25369
+ const group = resolution.group;
25370
+ const groupId = String(group.id ?? "");
25371
+ const groupName = String(group.groupName ?? "");
25372
+ const taskCount = await groupTaskCount(ctx, groupId);
25373
+ if (taskCount > 0 && !args.force) {
25374
+ throw new EworkError(
25375
+ `\u5206\u7EC4\u300C${groupName}\u300D\u4E0B\u8FD8\u6709 ${taskCount} \u6761\u4EFB\u52A1\uFF0C\u4E0D\u80FD\u5220\u9664\uFF1B\u8BF7\u5148\u628A\u4EFB\u52A1\u79FB\u51FA\u5206\u7EC4\uFF0C\u6216\u5728\u7F51\u9875\u5904\u7406\uFF1B\u786E\u8BA4\u6574\u7EC4\u5220\u9664\uFF08\u4EFB\u52A1\u53D8\u4E3A\u672A\u5206\u7EC4\uFF09\u53EF\u4F20 force=true`
25376
+ );
25377
+ }
25378
+ const payload = {
25379
+ action: "delete",
25380
+ groupId,
25381
+ force: Boolean(args.force),
25382
+ taskCount
25383
+ };
25384
+ const preview = formatManagePreview(
25385
+ taskCount > 0 ? `\u5220\u9664\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\u300C${groupName}\u300D\uFF08${groupId}\uFF0C${taskCount} \u6761\u4EFB\u52A1\uFF09\uFF1B\u5220\u9664\u540E\u8FD9\u4E9B\u4EFB\u52A1\u53D8\u4E3A\u672A\u5206\u7EC4\uFF0C\u4EFB\u52A1\u672C\u8EAB\u4E0D\u5220\u9664` : `\u5220\u9664\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\u300C${groupName}\u300D\uFF08${groupId}\uFF0C0 \u6761\u4EFB\u52A1\uFF09`
25386
+ );
25387
+ if (!args.confirm) {
25388
+ const previewToken = createPreviewToken("manage_task_group", groupId, payload);
25389
+ return ok(`${preview}
25390
+ previewToken\uFF1A${previewToken}
25391
+ \u8BF7\u786E\u8BA4\u540E\u5E26 previewToken \u4E0E confirm=true \u6267\u884C\u3002`, {
25392
+ action: "delete",
25393
+ groupId,
25394
+ name: groupName,
25395
+ taskCount,
25396
+ force: Boolean(args.force),
25397
+ previewToken,
25398
+ expiresInSeconds: previewTtlSeconds()
25399
+ });
25400
+ }
25401
+ consumePreviewToken(args.previewToken, "manage_task_group", groupId, payload);
25402
+ await ctx.client.post("/external/home/task/setting/removeGroup", {
25403
+ id: groupId
25404
+ });
25405
+ const after = await loadPersonalGroups(ctx);
25406
+ const stillExists = after.some((item) => String(item.id ?? "") === groupId);
25407
+ return ok(
25408
+ stillExists ? `\u5220\u9664\u5DF2\u63D0\u4EA4\uFF0C\u4F46\u56DE\u8BFB\u4ECD\u80FD\u67E5\u5230\u5206\u7EC4\u300C${groupName}\u300D\uFF08${groupId}\uFF09\uFF0C\u8BF7\u624B\u52A8\u68C0\u67E5\u3002` : taskCount > 0 ? `\u5DF2\u5220\u9664\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\u300C${groupName}\u300D\uFF08${groupId}\uFF09\uFF1B\u7EC4\u5185 ${taskCount} \u6761\u4EFB\u52A1\u5DF2\u53D8\u4E3A\u672A\u5206\u7EC4\u3002` : `\u5DF2\u5220\u9664\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\u300C${groupName}\u300D\uFF08${groupId}\uFF09\u3002`,
25409
+ {
25410
+ action: "delete",
25411
+ groupId,
25412
+ name: groupName,
25413
+ taskCount,
25414
+ force: Boolean(args.force),
25415
+ verified: !stillExists
25416
+ }
25417
+ );
25418
+ }
25419
+ function formatManagePreview(action) {
25420
+ return [
25421
+ `\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\u64CD\u4F5C\u9884\u6F14\uFF08\u672A\u5199\u5165\uFF09\uFF1A${action}`,
25422
+ "\u5206\u7EC4\u53EA\u5F71\u54CD\u5F53\u524D\u5458\u5DE5\u81EA\u5DF1\u7684\u300C\u6211\u7684\u4EFB\u52A1\u300D\u770B\u677F\uFF0C\u4E0D\u4F1A\u4FEE\u6539\u4EFB\u52A1\u672C\u8EAB\uFF0C\u4E5F\u4E0D\u4F1A\u540C\u6B65\u7ED9\u4ED6\u4EBA\u3002"
25423
+ ].join("\n");
25424
+ }
25425
+
23540
25426
  // src/tools/updateTask.ts
23541
25427
  function registerUpdateTask(server, ctx) {
23542
25428
  server.registerTool(
@@ -23600,7 +25486,7 @@ function registerUpdateTask(server, ctx) {
23600
25486
  };
23601
25487
  if (!args.confirm) {
23602
25488
  const previewToken = createPreviewToken("update_task", taskId, tokenPayload);
23603
- return ok(formatPreview4(preview, previewToken), {
25489
+ return ok(formatPreview5(preview, previewToken), {
23604
25490
  ...preview,
23605
25491
  previewToken,
23606
25492
  expiresInSeconds: previewTtlSeconds()
@@ -23634,7 +25520,7 @@ function registerUpdateTask(server, ctx) {
23634
25520
  }
23635
25521
  );
23636
25522
  }
23637
- function formatPreview4(preview, previewToken) {
25523
+ function formatPreview5(preview, previewToken) {
23638
25524
  const lines = [`\u4EFB\u52A1 ${preview.taskId} \u4FEE\u6539\u9884\u6F14\uFF08\u672A\u5199\u5165\uFF09\uFF1A`];
23639
25525
  if (preview.changed.title) {
23640
25526
  lines.push(`\u6807\u9898\uFF1A${preview.title.before || "-"} \u2192 ${preview.title.after || "-"}`);
@@ -23678,20 +25564,24 @@ async function main() {
23678
25564
  const server = new McpServer(
23679
25565
  {
23680
25566
  name: "task-mcp",
23681
- version: "0.1.0"
25567
+ version: "0.4.0"
23682
25568
  },
23683
25569
  {
23684
- instructions: "\u8FD9\u662F\u6613\u5DE5\u4F5C\u300C\u5DE5\u4F5C\u8BA1\u5212\u300D\u4EFB\u52A1\u5DE5\u5177\u3002'\u6211\u7684\u4EFB\u52A1/\u6211\u8D1F\u8D23\u7684\u4EFB\u52A1'\u53EA\u6307\u8D1F\u8D23\u4EBA\uFF08\u4EFB\u52A1\u6210\u5458\u89D2\u8272 O\uFF09\u662F\u5F53\u524D API Key \u5458\u5DE5\u7684\u4EFB\u52A1\uFF0C\u4E0D\u542B\u53C2\u4E0E\u4EBA/\u6284\u9001\u4EBA\u89C6\u89D2\u3002\u72B6\u6001\u540D\u6309\u4EFB\u52A1\u6240\u5C5E\u5DE5\u4F5C\u6D41\u7CBE\u786E\u5339\u914D\uFF1BS/P/F/E \u662F\u72B6\u6001\u7C7B\u578B\uFF0C\u4E0D\u662F\u72B6\u6001\u540D\uFF1B\u7CFB\u7EDF\u6CA1\u6709'\u672A\u5904\u7406/\u5904\u7406\u4E2D'\uFF0C\u5E38\u89C1\u72B6\u6001\u4E3A\u672A\u5F00\u59CB/\u8FDB\u884C\u4E2D/\u5DF2\u5B8C\u6210/\u5DF2\u53D6\u6D88\u6216\u5F85\u5904\u7406/\u4FEE\u590D\u4E2D/\u5F85\u53D1\u5E03/\u5DF2\u89E3\u51B3/\u5DF2\u5173\u95ED\u3002\u6240\u6709\u5199\u5DE5\u5177\u5FC5\u987B\u5148\u5728\u7528\u6237\u660E\u786E\u540C\u610F\u540E\uFF0C\u7528\u9884\u6F14\u8FD4\u56DE\u7684 previewToken \u548C confirm=true \u6267\u884C\uFF0C\u4E0D\u80FD\u8DF3\u8FC7\u9884\u6F14\u3002taskId \u5FC5\u987B\u6309\u5B57\u7B26\u4E32\u4F20\u9012\uFF1B\u4EFB\u52A1\u94FE\u63A5\u5FC5\u987B\u4E0E EWORK_BASE_URL \u540C\u4E00\u73AF\u5883\u3002"
25570
+ instructions: "\u8FD9\u662F\u6613\u5DE5\u4F5C\u300C\u5DE5\u4F5C\u8BA1\u5212\u300D\u4EFB\u52A1\u5DE5\u5177\u3002'\u6211\u7684\u4EFB\u52A1/\u6211\u8D1F\u8D23\u7684\u4EFB\u52A1'\u53EA\u6307\u8D1F\u8D23\u4EBA\uFF08\u4EFB\u52A1\u6210\u5458\u89D2\u8272 O\uFF09\u662F\u5F53\u524D API Key \u5458\u5DE5\u7684\u4EFB\u52A1\uFF0C\u4E0D\u542B\u53C2\u4E0E\u4EBA/\u6284\u9001\u4EBA\u89C6\u89D2\uFF1B'\u6211\u521B\u5EFA\u7684\u4EFB\u52A1'\u6307\u521B\u5EFA\u4EBA\uFF08\u89D2\u8272 R\uFF09\uFF0C\u7528 list_created_tasks\u3002list_my_tasks \u4E0E my_task_stats \u652F\u6301\u7528 plan \u53C2\u6570\u6309\u8BA1\u5212\u540D\u79F0\u6216 32 \u4F4D\u8BA1\u5212 id \u7B5B\u9009\uFF0C\u8BA1\u5212\u540D\u91CD\u540D\u65F6\u8FD4\u56DE\u5019\u9009\u3002\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\u7528 list_task_groups / manage_task_group / assign_task_to_group\uFF1Bassign_task_to_group \u652F\u6301 taskIds \u6279\u91CF\uFF08\u6700\u591A 50 \u4E2A\uFF09\uFF0Cmanage_task_group \u5220\u9664\u975E\u7A7A\u5206\u7EC4\u9700 force=true\uFF1B\u5206\u7EC4\u53EA\u5F71\u54CD\u5F53\u524D\u5458\u5DE5\u81EA\u5DF1\u7684\u770B\u677F\uFF0C\u4E0D\u662F\u8BA1\u5212\u5171\u4EAB\u5206\u7EC4\uFF1Blist_my_tasks / list_created_tasks \u53EF\u7528 group \u53C2\u6570\u7B5B\u9009\uFF0Ccreate_task \u53EF\u7528 group \u76F4\u63A5\u5165\u7EC4\u3002\u72B6\u6001\u540D\u6309\u4EFB\u52A1\u6240\u5C5E\u5DE5\u4F5C\u6D41\u7CBE\u786E\u5339\u914D\uFF1BS/P/F/E \u662F\u72B6\u6001\u7C7B\u578B\uFF0C\u4E0D\u662F\u72B6\u6001\u540D\uFF1B\u7CFB\u7EDF\u6CA1\u6709'\u672A\u5904\u7406/\u5904\u7406\u4E2D'\uFF0C\u5E38\u89C1\u72B6\u6001\u4E3A\u672A\u5F00\u59CB/\u8FDB\u884C\u4E2D/\u5DF2\u5B8C\u6210/\u5DF2\u53D6\u6D88\u6216\u5F85\u5904\u7406/\u4FEE\u590D\u4E2D/\u5F85\u53D1\u5E03/\u5DF2\u89E3\u51B3/\u5DF2\u5173\u95ED\u3002create_task \u53EA\u521B\u5EFA\u8BA1\u5212\u4EFB\u52A1\uFF0C\u5FC5\u586B\u8BA1\u5212\u3001\u4EFB\u52A1\u7C7B\u578B\u3001\u6807\u9898\u548C\u622A\u6B62\u65E5\u671F\uFF0C\u9ED8\u8BA4\u8D1F\u8D23\u4EBA\u4E3A\u5F53\u524D\u5458\u5DE5\u3001\u5F00\u59CB\u65E5\u671F\u4E3A\u4ECA\u5929\u3001\u5168\u5929\u4EFB\u52A1\u3002\u6240\u6709\u5199\u5DE5\u5177\u5FC5\u987B\u5148\u5728\u7528\u6237\u660E\u786E\u540C\u610F\u540E\uFF0C\u7528\u9884\u6F14\u8FD4\u56DE\u7684 previewToken \u548C confirm=true \u6267\u884C\uFF0C\u4E0D\u80FD\u8DF3\u8FC7\u9884\u6F14\u3002taskId \u5FC5\u987B\u6309\u5B57\u7B26\u4E32\u4F20\u9012\uFF1B\u4EFB\u52A1\u94FE\u63A5\u5FC5\u987B\u4E0E EWORK_BASE_URL \u540C\u4E00\u73AF\u5883\u3002"
23685
25571
  }
23686
25572
  );
23687
25573
  registerGetTask(server, ctx);
23688
25574
  registerListMyTasks(server, ctx);
25575
+ registerListCreatedTasks(server, ctx);
23689
25576
  registerMyTaskStats(server, ctx);
23690
25577
  registerUpdateTask(server, ctx);
23691
25578
  registerChangeOwner(server, ctx);
23692
25579
  registerChangeStatus(server, ctx);
23693
25580
  registerAddComment(server, ctx);
23694
25581
  registerSearchEmployee(server, ctx);
25582
+ registerCreateTask(server, ctx);
25583
+ registerTaskGroups(server, ctx);
25584
+ registerAssignTaskToGroup(server, ctx);
23695
25585
  const transport = new StdioServerTransport();
23696
25586
  await server.connect(transport);
23697
25587
  process.stderr.write(`[task-mcp] \u5DF2\u542F\u52A8\uFF0C\u7F51\u5173\u5730\u5740 ${config2.baseUrl}