@ai-setting/roy-agent-core 1.6.11 → 1.6.13

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 (43) hide show
  1. package/dist/env/agent/index.js +3 -3
  2. package/dist/env/event-source/index.js +5 -5
  3. package/dist/env/index.js +19 -19
  4. package/dist/env/prompt/index.js +2 -2
  5. package/dist/env/task/delegate/index.js +4 -4
  6. package/dist/env/task/index.js +7 -7
  7. package/dist/env/task/plugins/index.js +4 -4
  8. package/dist/env/task/storage/index.js +2 -1
  9. package/dist/env/task/tools/operation/index.js +1 -1
  10. package/dist/env/tool/built-in/index.js +2 -2
  11. package/dist/env/tool/index.js +3 -3
  12. package/dist/env/workflow/engine/index.js +3 -3
  13. package/dist/env/workflow/index.js +7 -7
  14. package/dist/env/workflow/service/index.js +1 -1
  15. package/dist/env/workflow/tools/index.js +4 -4
  16. package/dist/env/workflow/utils/index.js +2 -2
  17. package/dist/index.js +132 -21
  18. package/dist/shared/@ai-setting/{roy-agent-core-0n2a8cbn.js → roy-agent-core-0crh2g0m.js} +594 -237
  19. package/dist/shared/@ai-setting/{roy-agent-core-0cftbg62.js → roy-agent-core-0pbmweh4.js} +1 -1
  20. package/dist/shared/@ai-setting/{roy-agent-core-jenchn33.js → roy-agent-core-24rmf17n.js} +8 -0
  21. package/dist/shared/@ai-setting/{roy-agent-core-2ek596yd.js → roy-agent-core-2b4078kz.js} +1 -1
  22. package/dist/shared/@ai-setting/{roy-agent-core-z7f8hyv7.js → roy-agent-core-6jqpdjr4.js} +1 -1
  23. package/dist/shared/@ai-setting/{roy-agent-core-38kbfarg.js → roy-agent-core-6qbyfzsw.js} +1 -1
  24. package/dist/shared/@ai-setting/{roy-agent-core-mb7b62sm.js → roy-agent-core-8cbsjkkx.js} +2 -2
  25. package/dist/shared/@ai-setting/roy-agent-core-9abv4ewh.js +1122 -0
  26. package/dist/shared/@ai-setting/{roy-agent-core-trdpar9f.js → roy-agent-core-apz6v22z.js} +419 -60
  27. package/dist/shared/@ai-setting/{roy-agent-core-y5ymc4f8.js → roy-agent-core-deqpzcg7.js} +46 -14
  28. package/dist/shared/@ai-setting/{roy-agent-core-m38q2azm.js → roy-agent-core-fvkyv5j6.js} +4 -2
  29. package/dist/shared/@ai-setting/{roy-agent-core-3rs38pf7.js → roy-agent-core-fwxqevpf.js} +11 -8
  30. package/dist/shared/@ai-setting/{roy-agent-core-pzeexnhf.js → roy-agent-core-nv4yfy3m.js} +4 -3
  31. package/dist/shared/@ai-setting/roy-agent-core-rn57psp0.js +396 -0
  32. package/dist/shared/@ai-setting/{roy-agent-core-wqe84f84.js → roy-agent-core-v5nknfh0.js} +30 -8
  33. package/dist/shared/@ai-setting/{roy-agent-core-06574wqa.js → roy-agent-core-v77pp20w.js} +4 -4
  34. package/dist/shared/@ai-setting/roy-agent-core-vcjq65nz.js +436 -0
  35. package/dist/shared/@ai-setting/{roy-agent-core-8wd3qwx5.js → roy-agent-core-wjve1qr5.js} +1 -1
  36. package/dist/shared/@ai-setting/{roy-agent-core-5w9a1eqa.js → roy-agent-core-wpw37qqf.js} +88 -3
  37. package/dist/shared/@ai-setting/{roy-agent-core-p6x6n3k4.js → roy-agent-core-x7fgze6s.js} +1 -1
  38. package/dist/shared/@ai-setting/{roy-agent-core-p2vpsd1d.js → roy-agent-core-ywtmc0bh.js} +166 -6
  39. package/package.json +1 -1
  40. package/dist/shared/@ai-setting/roy-agent-core-4yq23m5g.js +0 -421
  41. package/dist/shared/@ai-setting/roy-agent-core-9xby523m.js +0 -961
  42. package/dist/shared/@ai-setting/roy-agent-core-t94ktchq.js +0 -213
  43. /package/dist/shared/@ai-setting/{roy-agent-core-zs31w092.js → roy-agent-core-9nhwdq9r.js} +0 -0
@@ -3,10 +3,10 @@ import {
3
3
  } from "./roy-agent-core-az13yzmc.js";
4
4
  import {
5
5
  validateWorkflowDefinition
6
- } from "./roy-agent-core-8wd3qwx5.js";
6
+ } from "./roy-agent-core-wjve1qr5.js";
7
7
  import {
8
8
  WORKFLOW_EXTRACT_PROMPT
9
- } from "./roy-agent-core-trdpar9f.js";
9
+ } from "./roy-agent-core-apz6v22z.js";
10
10
  import {
11
11
  TaskHookPoints
12
12
  } from "./roy-agent-core-1pg0fepg.js";
@@ -495,7 +495,7 @@ class LarkCliTaskNotifyHook {
495
495
  await this.sendNotify({
496
496
  type: "operation_created" /* OPERATION_CREATED */,
497
497
  title: this.getNotifyTitle("operation_created" /* OPERATION_CREATED */),
498
- content: this.formatOperationCreated(operation),
498
+ content: await this.formatOperationCreated(operation),
499
499
  _hookContext: ctx
500
500
  });
501
501
  }
@@ -588,6 +588,16 @@ ${content}`;
588
588
  });
589
589
  });
590
590
  }
591
+ truncate(text, maxLen) {
592
+ if (text.length <= maxLen)
593
+ return text;
594
+ return text.substring(0, maxLen) + "...";
595
+ }
596
+ appendProjectPathLine(lines, task) {
597
+ if (task?.project_path) {
598
+ lines.push(`- **项目路径**: \`${task.project_path}\``);
599
+ }
600
+ }
591
601
  shouldNotify(type) {
592
602
  const { notifyTypes } = this.config;
593
603
  if (notifyTypes && notifyTypes.length === 0)
@@ -621,12 +631,12 @@ ${content}`;
621
631
  lines.push(`- **标题**: ${task.title}`);
622
632
  }
623
633
  if (task.description) {
624
- const desc = task.description.substring(0, 100) + (task.description.length > 100 ? "..." : "");
625
- lines.push(`- **描述**: ${desc}`);
634
+ lines.push(`- **描述**: ${this.truncate(task.description, 100)}`);
626
635
  }
627
636
  if (task.priority) {
628
637
  lines.push(`- **优先级**: ${task.priority}`);
629
638
  }
639
+ this.appendProjectPathLine(lines, task);
630
640
  return lines.join(`
631
641
  `);
632
642
  }
@@ -645,6 +655,7 @@ ${content}`;
645
655
  if (changes?.current_status) {
646
656
  lines.push(`- **当前状态**: ${changes.current_status}`);
647
657
  }
658
+ this.appendProjectPathLine(lines, task);
648
659
  const changeKeys = Object.keys(changes || {}).filter((k) => !["status", "progress", "current_status"].includes(k));
649
660
  if (changeKeys.length > 0) {
650
661
  lines.push(`- **变更**: ${changeKeys.join(", ")}`);
@@ -667,28 +678,49 @@ ${content}`;
667
678
  this.lastNotifyTimestamps.set(key, now);
668
679
  return false;
669
680
  }
670
- formatOperationCreated(operation) {
681
+ async formatOperationCreated(operation, task) {
682
+ const resolvedTask = task ?? await this.resolveTaskForOperation(operation);
671
683
  const lines = [];
684
+ if (resolvedTask?.title) {
685
+ lines.push(`- **任务**: ${resolvedTask.title}`);
686
+ }
672
687
  if (operation.taskId !== undefined && operation.taskId !== null) {
673
688
  lines.push(`- **任务 ID**: #${operation.taskId}`);
674
689
  }
675
- if (operation.actionType) {
676
- lines.push(`- **操作类型**: ${operation.actionType}`);
690
+ if (operation.milestoneType) {
691
+ lines.push(`- **里程碑类型**: ${operation.milestoneType}`);
677
692
  }
678
- if (operation.actionTitle) {
679
- lines.push(`- **标题**: ${operation.actionTitle}`);
693
+ if (operation.milestoneTitle) {
694
+ lines.push(`- **标题**: ${operation.milestoneTitle}`);
680
695
  }
681
- if (operation.actionDescription) {
682
- const desc = String(operation.actionDescription);
683
- const truncated = desc.substring(0, 200) + (desc.length > 200 ? "..." : "");
684
- lines.push(`- **描述**: ${truncated}`);
696
+ if (operation.milestoneDescription) {
697
+ lines.push(`- **里程碑描述**: ${this.truncate(String(operation.milestoneDescription), 200)}`);
685
698
  }
699
+ if (operation.processDescription) {
700
+ lines.push(`- **过程概要**: ${this.truncate(String(operation.processDescription), 200)}`);
701
+ }
702
+ this.appendProjectPathLine(lines, resolvedTask);
686
703
  if (operation.sessionId) {
687
704
  lines.push(`- **Session**: \`${operation.sessionId}\``);
688
705
  }
689
706
  return lines.join(`
690
707
  `);
691
708
  }
709
+ async resolveTaskForOperation(operation) {
710
+ if (operation.taskId === undefined || operation.taskId === null) {
711
+ return;
712
+ }
713
+ const fetch = this.config.fetchTaskById;
714
+ if (!fetch) {
715
+ return;
716
+ }
717
+ try {
718
+ return await fetch(operation.taskId);
719
+ } catch (error) {
720
+ logger3.warn(`fetchTaskById failed for task #${operation.taskId}: ${error}`);
721
+ return;
722
+ }
723
+ }
692
724
  }
693
725
  __legacyDecorateClassTS([
694
726
  TracedAs("lark-cli-task-notify.execute")
@@ -3,14 +3,14 @@ import {
3
3
  } from "./roy-agent-core-dcd1s7ct.js";
4
4
  import {
5
5
  truncateOutputInline
6
- } from "./roy-agent-core-zs31w092.js";
6
+ } from "./roy-agent-core-9nhwdq9r.js";
7
7
  import {
8
8
  AskUserError,
9
9
  init_workflow_hil
10
10
  } from "./roy-agent-core-e25xkv53.js";
11
11
  import {
12
12
  AgentRegistry
13
- } from "./roy-agent-core-wqe84f84.js";
13
+ } from "./roy-agent-core-v5nknfh0.js";
14
14
  import {
15
15
  ContextError
16
16
  } from "./roy-agent-core-ctdhjv68.js";
@@ -365,6 +365,8 @@ class AgentComponent extends BaseComponent {
365
365
  logger.info("[AgentComponent] Registered built-in workflow-runner");
366
366
  this.registry.registerJsonExtractAgent();
367
367
  logger.info("[AgentComponent] Registered built-in json-extract agent");
368
+ this.registry.registerWorkflowCreator();
369
+ logger.info("[AgentComponent] Registered built-in workflow-creator");
368
370
  this.registry.registerWorkflowExtractAgent();
369
371
  logger.info("[AgentComponent] Registered built-in workflow-extract agent");
370
372
  this.registry.registerCompactAgent();
@@ -8,11 +8,11 @@ import {
8
8
  BackgroundTaskManager,
9
9
  createDelegateTool,
10
10
  createStopTool
11
- } from "./roy-agent-core-5w9a1eqa.js";
11
+ } from "./roy-agent-core-wpw37qqf.js";
12
12
  import {
13
13
  SQLiteTaskStore,
14
14
  getDefaultTaskDbPath
15
- } from "./roy-agent-core-9xby523m.js";
15
+ } from "./roy-agent-core-9abv4ewh.js";
16
16
  import {
17
17
  batchArchiveTaskTool,
18
18
  batchDeleteTaskTool,
@@ -31,7 +31,7 @@ import {
31
31
  getOperationTool,
32
32
  listOperationsTool,
33
33
  updateOperationTool
34
- } from "./roy-agent-core-t94ktchq.js";
34
+ } from "./roy-agent-core-rn57psp0.js";
35
35
  import {
36
36
  TaskHookPoints
37
37
  } from "./roy-agent-core-1pg0fepg.js";
@@ -193,6 +193,9 @@ class TaskComponent extends BaseComponent {
193
193
  configComponent;
194
194
  tagService;
195
195
  plugins = new Map;
196
+ getBackgroundTaskManager() {
197
+ return this.backgroundTaskManager;
198
+ }
196
199
  publishEvent(type, payload, sessionId) {
197
200
  if (this.env?.pushEnvEvent) {
198
201
  this.env.pushEnvEvent({
@@ -406,9 +409,9 @@ class TaskComponent extends BaseComponent {
406
409
  await this.store.createOperation({
407
410
  taskId: task.id,
408
411
  sessionId,
409
- actionType: "create",
410
- actionTitle: `Task created: ${task.title}`,
411
- actionDescription: task.description || ""
412
+ milestoneType: "create",
413
+ milestoneTitle: `Task created: ${task.title}`,
414
+ milestoneDescription: task.description || ""
412
415
  });
413
416
  const resultCtx = {
414
417
  task,
@@ -499,8 +502,8 @@ class TaskComponent extends BaseComponent {
499
502
  await this.createOperation({
500
503
  taskId: id,
501
504
  sessionId,
502
- actionType: "completed",
503
- actionTitle: "Task completed"
505
+ milestoneType: "completed",
506
+ milestoneTitle: "Task completed"
504
507
  });
505
508
  this.publishEvent(TaskEntityEventTypes.COMPLETED, { task, sessionId }, sessionId);
506
509
  logger2.info(`[TaskComponent] Task completed: ${id}`);
@@ -173,12 +173,13 @@ class ProcessRegistry {
173
173
  try {
174
174
  const result = await killProcessTree(pid, { retry: 3, retryDelayMs: 500 });
175
175
  if (result.stillAlive) {
176
- logger2.error(`进程 PID ${pid} 经过 ${result.attempts} 次重试后仍未杀死!可能存在孤儿进程泄漏!`);
176
+ logger2.error(`进程 PID ${pid} 经过 ${result.attempts} 次重试后仍未杀死!保留 PID 供后续 forceStopAll 重试。`);
177
+ } else {
178
+ this.pids.delete(pid);
177
179
  }
178
180
  } catch {}
179
181
  }
180
- this.pids.clear();
181
- logger2.info(`[bg-process:killAll-done]`);
182
+ logger2.info(`[bg-process:killAll-done] remaining=${this.pids.size}`);
182
183
  }
183
184
  }
184
185
  var processRegistryStorage = new AsyncLocalStorage;
@@ -0,0 +1,396 @@
1
+ // src/env/task/tools/operation/create-tool.ts
2
+ import { ZodError } from "zod";
3
+
4
+ // src/env/task/tools/operation/operation-types.ts
5
+ import { z } from "zod";
6
+ var ActionTypeEnum = z.enum([
7
+ "create",
8
+ "progress",
9
+ "milestone",
10
+ "problem",
11
+ "solution",
12
+ "decision",
13
+ "review",
14
+ "completed",
15
+ "workflow_extracted"
16
+ ]);
17
+ var PROCESS_DESCRIPTION_MIN_LENGTH = 100;
18
+ var PROCESS_DESCRIPTION_MAX_LENGTH = 150;
19
+ var MILESTONE_DESCRIPTION_MAX_LENGTH = 5000;
20
+ var MILESTONE_TITLE_MIN_LENGTH = 1;
21
+ var MILESTONE_TITLE_MAX_LENGTH = 200;
22
+ var ProcessDescriptionSchema = z.string().min(PROCESS_DESCRIPTION_MIN_LENGTH, {
23
+ message: `process_description 太短(少于 ${PROCESS_DESCRIPTION_MIN_LENGTH} 字符),无法表达过程概要;如无过程信息请省略该字段,细节请回查 sessionId。`
24
+ }).max(PROCESS_DESCRIPTION_MAX_LENGTH, {
25
+ message: `process_description 太长(超过 ${PROCESS_DESCRIPTION_MAX_LENGTH} 字符),会退化为日志细节;操作记录只承担 milestone 概要,完整细节请通过 sessionId 回查 session。`
26
+ }).describe("过程概要(process_description):采取的策略 + 工具步骤概要;" + `严格控制 ${PROCESS_DESCRIPTION_MIN_LENGTH}-${PROCESS_DESCRIPTION_MAX_LENGTH} 字符。` + "操作记录是节点阶段 milestone 摘要,完整过程通过 sessionId 回查 session;" + "milestone_description 才是达成的状态/结果描述。");
27
+ var MilestoneTitleSchema = z.string().min(MILESTONE_TITLE_MIN_LENGTH, { message: "milestone_title 不能为空" }).max(MILESTONE_TITLE_MAX_LENGTH, {
28
+ message: `milestone_title 超过 ${MILESTONE_TITLE_MAX_LENGTH} 字符,建议精简(一行标题即可)。`
29
+ }).describe("里程碑标题(milestone_title):达成的里程碑/状态的一句话标题;" + "必填,1-200 字符。");
30
+ var MilestoneDescriptionSchema = z.string().max(MILESTONE_DESCRIPTION_MAX_LENGTH, {
31
+ message: `milestone_description 超过 ${MILESTONE_DESCRIPTION_MAX_LENGTH} 字符;如需更详细的过程,请改用 process_description。`
32
+ }).optional().describe("状态/结果描述(milestone_description):达成的状态或结果描述;" + "可长可短;过程概要应放在 process_description,不要与本字段重复。");
33
+ var CreateOperationInputSchema = z.object({
34
+ task_id: z.number().describe("Task ID"),
35
+ milestone_type: ActionTypeEnum.optional(),
36
+ milestone_title: MilestoneTitleSchema.optional(),
37
+ milestone_description: MilestoneDescriptionSchema,
38
+ process_description: ProcessDescriptionSchema.optional(),
39
+ action_type: ActionTypeEnum.optional(),
40
+ action_title: z.string().min(1).max(MILESTONE_TITLE_MAX_LENGTH).optional(),
41
+ action_description: z.string().max(MILESTONE_DESCRIPTION_MAX_LENGTH).optional(),
42
+ md_path: z.string().optional().describe("Path to detailed markdown documentation")
43
+ });
44
+ var CreateOperationToolSchema = CreateOperationInputSchema.transform((input) => {
45
+ const deprecatedFields = [];
46
+ let milestoneType = input.milestone_type;
47
+ let milestoneTitle = input.milestone_title;
48
+ let milestoneDescription = input.milestone_description;
49
+ if (!milestoneType && input.action_type) {
50
+ milestoneType = input.action_type;
51
+ deprecatedFields.push("action_type");
52
+ }
53
+ if (!milestoneTitle && input.action_title) {
54
+ milestoneTitle = input.action_title;
55
+ deprecatedFields.push("action_title");
56
+ }
57
+ if (milestoneDescription === undefined && input.action_description !== undefined) {
58
+ milestoneDescription = input.action_description;
59
+ deprecatedFields.push("action_description");
60
+ }
61
+ return {
62
+ task_id: input.task_id,
63
+ milestone_type: milestoneType,
64
+ milestone_title: milestoneTitle,
65
+ milestone_description: milestoneDescription,
66
+ process_description: input.process_description,
67
+ md_path: input.md_path,
68
+ _deprecated_fields_used: deprecatedFields
69
+ };
70
+ });
71
+ var GetOperationToolSchema = z.object({
72
+ operation_id: z.number().describe("Operation ID")
73
+ });
74
+ var ListOperationsToolSchema = z.object({
75
+ task_id: z.number().describe("Task ID"),
76
+ milestone_type: ActionTypeEnum.optional(),
77
+ action_type: ActionTypeEnum.optional(),
78
+ limit: z.number().optional().default(20),
79
+ offset: z.number().optional().default(0)
80
+ }).transform((input) => {
81
+ const deprecatedFields = [];
82
+ let milestoneType = input.milestone_type;
83
+ if (!milestoneType && input.action_type) {
84
+ milestoneType = input.action_type;
85
+ deprecatedFields.push("action_type");
86
+ }
87
+ return {
88
+ task_id: input.task_id,
89
+ milestone_type: milestoneType,
90
+ limit: input.limit,
91
+ offset: input.offset,
92
+ _deprecated_fields_used: deprecatedFields
93
+ };
94
+ });
95
+ var UpdateOperationInputSchema = z.object({
96
+ operation_id: z.number().describe("Operation ID"),
97
+ milestone_title: MilestoneTitleSchema.optional(),
98
+ milestone_description: MilestoneDescriptionSchema,
99
+ process_description: ProcessDescriptionSchema.optional(),
100
+ action_title: z.string().min(1).max(MILESTONE_TITLE_MAX_LENGTH).optional(),
101
+ action_description: z.string().max(MILESTONE_DESCRIPTION_MAX_LENGTH).optional()
102
+ });
103
+ var UpdateOperationToolSchema = UpdateOperationInputSchema.transform((input) => {
104
+ const deprecatedFields = [];
105
+ let milestoneTitle = input.milestone_title;
106
+ let milestoneDescription = input.milestone_description;
107
+ if (!milestoneTitle && input.action_title) {
108
+ milestoneTitle = input.action_title;
109
+ deprecatedFields.push("action_title");
110
+ }
111
+ if (milestoneDescription === undefined && input.action_description !== undefined) {
112
+ milestoneDescription = input.action_description;
113
+ deprecatedFields.push("action_description");
114
+ }
115
+ return {
116
+ operation_id: input.operation_id,
117
+ milestone_title: milestoneTitle,
118
+ milestone_description: milestoneDescription,
119
+ process_description: input.process_description,
120
+ _deprecated_fields_used: deprecatedFields
121
+ };
122
+ });
123
+ var DeleteOperationToolSchema = z.object({
124
+ operation_id: z.number().describe("Operation ID")
125
+ });
126
+
127
+ // src/env/task/tools/operation/create-tool.ts
128
+ function formatZodError(err) {
129
+ const parts = err.issues.map((i) => `${i.path.join(".") || "<root>"}: ${i.message}`);
130
+ return `Invalid parameters: ${parts.join("; ")}`;
131
+ }
132
+ function ensureRequiredMilestoneFields(params) {
133
+ if (!params.milestone_type) {
134
+ return {
135
+ ok: false,
136
+ error: "milestone_type is required (or action_type for backward compatibility). " + "Use one of: create, progress, milestone, problem, solution, decision, review, completed, workflow_extracted."
137
+ };
138
+ }
139
+ if (!params.milestone_title) {
140
+ return {
141
+ ok: false,
142
+ error: "milestone_title is required (or action_title for backward compatibility)."
143
+ };
144
+ }
145
+ return { ok: true, milestoneType: params.milestone_type, milestoneTitle: params.milestone_title };
146
+ }
147
+ function createOperationTool(taskComponent) {
148
+ return {
149
+ name: "task_operation_create",
150
+ description: "Create an operation record for a task. Tracks milestones (state/result) and process (strategy + tool steps). " + "Dual-dimension schema: milestone_type/title/description captures WHAT milestone was reached; " + "process_description (100-150 chars) captures HOW. " + "Legacy action_* fields are accepted as deprecated aliases.",
151
+ parameters: CreateOperationToolSchema,
152
+ execute: async (args, ctx) => {
153
+ let params;
154
+ try {
155
+ const parsed = CreateOperationToolSchema.parse(args);
156
+ params = parsed;
157
+ } catch (e) {
158
+ if (e instanceof ZodError) {
159
+ return {
160
+ success: false,
161
+ output: "",
162
+ error: formatZodError(e),
163
+ metadata: { execution_time_ms: 0 }
164
+ };
165
+ }
166
+ throw e;
167
+ }
168
+ const check = ensureRequiredMilestoneFields(params);
169
+ if (!check.ok) {
170
+ return {
171
+ success: false,
172
+ output: "",
173
+ error: check.error,
174
+ metadata: { execution_time_ms: 0 }
175
+ };
176
+ }
177
+ const sessionId = ctx.session_id || "unknown";
178
+ try {
179
+ const operation = await taskComponent.createOperation({
180
+ taskId: params.task_id,
181
+ sessionId,
182
+ milestoneType: check.milestoneType,
183
+ milestoneTitle: check.milestoneTitle,
184
+ milestoneDescription: params.milestone_description,
185
+ processDescription: params.process_description,
186
+ mdPath: params.md_path
187
+ });
188
+ let output = `Operation created: #${operation.id} for task #${operation.taskId} ` + `[milestone=${operation.milestoneType}] ${operation.milestoneTitle}`;
189
+ const deprecationWarnings = [];
190
+ if (params._deprecated_fields_used.length > 0) {
191
+ deprecationWarnings.push(`⚠️ DEPRECATION NOTICE: 你使用了旧的 action_* 字段 (${params._deprecated_fields_used.join(", ")}),已自动映射到 milestone_* 字段。` + "请尽快迁移到 milestone_type / milestone_title / milestone_description 主字段。");
192
+ }
193
+ if (deprecationWarnings.length > 0) {
194
+ output += `
195
+
196
+ ` + deprecationWarnings.join(`
197
+ `);
198
+ }
199
+ return {
200
+ success: true,
201
+ output,
202
+ metadata: {
203
+ execution_time_ms: 0,
204
+ operation_id: operation.id,
205
+ task_id: operation.taskId,
206
+ session_id: operation.sessionId,
207
+ deprecated_fields_used: params._deprecated_fields_used
208
+ }
209
+ };
210
+ } catch (error) {
211
+ return {
212
+ success: false,
213
+ output: "",
214
+ error: error instanceof Error ? error.message : String(error),
215
+ metadata: { execution_time_ms: 0 }
216
+ };
217
+ }
218
+ }
219
+ };
220
+ }
221
+ // src/env/task/tools/operation/get-tool.ts
222
+ function getOperationTool(taskComponent) {
223
+ return {
224
+ name: "task_operation_get",
225
+ description: "Get a single operation record by ID.",
226
+ parameters: GetOperationToolSchema,
227
+ execute: async (args, ctx) => {
228
+ const params = GetOperationToolSchema.parse(args);
229
+ try {
230
+ const operation = await taskComponent.getOperation(params.operation_id);
231
+ if (!operation) {
232
+ return {
233
+ success: false,
234
+ output: "",
235
+ error: `Operation not found: ${params.operation_id}`,
236
+ metadata: { execution_time_ms: 0 }
237
+ };
238
+ }
239
+ return {
240
+ success: true,
241
+ output: JSON.stringify(operation, null, 2),
242
+ metadata: { execution_time_ms: 0 }
243
+ };
244
+ } catch (error) {
245
+ return {
246
+ success: false,
247
+ output: "",
248
+ error: error instanceof Error ? error.message : String(error),
249
+ metadata: { execution_time_ms: 0 }
250
+ };
251
+ }
252
+ }
253
+ };
254
+ }
255
+ // src/env/task/tools/operation/list-tool.ts
256
+ function listOperationsTool(taskComponent) {
257
+ return {
258
+ name: "task_operation_list",
259
+ description: "List operation records for a task with optional filters. " + "Use milestone_type (canonical) or action_type (deprecated, auto-mapped).",
260
+ parameters: ListOperationsToolSchema,
261
+ execute: async (args, ctx) => {
262
+ const parsed = ListOperationsToolSchema.parse(args);
263
+ try {
264
+ const operations = await taskComponent.listOperations({
265
+ taskId: parsed.task_id,
266
+ milestoneType: parsed.milestone_type,
267
+ limit: parsed.limit,
268
+ offset: parsed.offset
269
+ });
270
+ let output = JSON.stringify({ operations, count: operations.length });
271
+ if (parsed._deprecated_fields_used.length > 0) {
272
+ output = `⚠️ DEPRECATION NOTICE: 你使用了旧的 action_type 字段,已自动映射到 milestone_type。
273
+
274
+ ` + output;
275
+ }
276
+ return {
277
+ success: true,
278
+ output,
279
+ metadata: {
280
+ execution_time_ms: 0,
281
+ deprecated_fields_used: parsed._deprecated_fields_used
282
+ }
283
+ };
284
+ } catch (error) {
285
+ return {
286
+ success: false,
287
+ output: "",
288
+ error: error instanceof Error ? error.message : String(error),
289
+ metadata: { execution_time_ms: 0 }
290
+ };
291
+ }
292
+ }
293
+ };
294
+ }
295
+ // src/env/task/tools/operation/update-tool.ts
296
+ import { ZodError as ZodError2 } from "zod";
297
+ function formatZodError2(err) {
298
+ const parts = err.issues.map((i) => `${i.path.join(".") || "<root>"}: ${i.message}`);
299
+ return `Invalid parameters: ${parts.join("; ")}`;
300
+ }
301
+ function updateOperationTool(taskComponent) {
302
+ return {
303
+ name: "task_operation_update",
304
+ description: "Update an operation record. Use milestone_title / milestone_description (canonical) " + "or action_title / action_description (deprecated, auto-mapped). " + "process_description captures the process (100-150 chars).",
305
+ parameters: UpdateOperationToolSchema,
306
+ execute: async (args, ctx) => {
307
+ let params;
308
+ try {
309
+ const parsed = UpdateOperationToolSchema.parse(args);
310
+ params = parsed;
311
+ } catch (e) {
312
+ if (e instanceof ZodError2) {
313
+ return {
314
+ success: false,
315
+ output: "",
316
+ error: formatZodError2(e),
317
+ metadata: { execution_time_ms: 0 }
318
+ };
319
+ }
320
+ throw e;
321
+ }
322
+ try {
323
+ const operation = await taskComponent.updateOperation(params.operation_id, {
324
+ milestoneTitle: params.milestone_title,
325
+ milestoneDescription: params.milestone_description,
326
+ processDescription: params.process_description
327
+ });
328
+ if (!operation) {
329
+ return {
330
+ success: false,
331
+ output: "",
332
+ error: `Operation not found: ${params.operation_id}`,
333
+ metadata: { execution_time_ms: 0 }
334
+ };
335
+ }
336
+ let output = `Operation updated: #${operation.id}`;
337
+ if (params._deprecated_fields_used.length > 0) {
338
+ output += `
339
+
340
+ ⚠️ DEPRECATION NOTICE: 你使用了旧的 action_* 字段 (${params._deprecated_fields_used.join(", ")}),已自动映射到 milestone_* 字段。` + "请尽快迁移到 milestone_* 字段。";
341
+ }
342
+ return {
343
+ success: true,
344
+ output,
345
+ metadata: {
346
+ execution_time_ms: 0,
347
+ operation,
348
+ deprecated_fields_used: params._deprecated_fields_used
349
+ }
350
+ };
351
+ } catch (error) {
352
+ return {
353
+ success: false,
354
+ output: "",
355
+ error: error instanceof Error ? error.message : String(error),
356
+ metadata: { execution_time_ms: 0 }
357
+ };
358
+ }
359
+ }
360
+ };
361
+ }
362
+ // src/env/task/tools/operation/delete-tool.ts
363
+ function deleteOperationTool(taskComponent) {
364
+ return {
365
+ name: "task_operation_delete",
366
+ description: "Delete an operation record.",
367
+ parameters: DeleteOperationToolSchema,
368
+ execute: async (args, ctx) => {
369
+ const params = DeleteOperationToolSchema.parse(args);
370
+ try {
371
+ const deleted = await taskComponent.deleteOperation(params.operation_id);
372
+ if (!deleted) {
373
+ return {
374
+ success: false,
375
+ output: "",
376
+ error: `Operation not found: ${params.operation_id}`,
377
+ metadata: { execution_time_ms: 0 }
378
+ };
379
+ }
380
+ return {
381
+ success: true,
382
+ output: `Operation deleted: #${params.operation_id}`,
383
+ metadata: { execution_time_ms: 0 }
384
+ };
385
+ } catch (error) {
386
+ return {
387
+ success: false,
388
+ output: "",
389
+ error: error instanceof Error ? error.message : String(error),
390
+ metadata: { execution_time_ms: 0 }
391
+ };
392
+ }
393
+ }
394
+ };
395
+ }
396
+ export { createOperationTool, getOperationTool, listOperationsTool, updateOperationTool, deleteOperationTool };
@@ -165,15 +165,8 @@ class AgentRegistry {
165
165
  const agent = {
166
166
  name,
167
167
  type: "sub",
168
- description: "Workflow runner — 负责调用 workflow_run 启动 workflow,支持 session resume 和 stop",
168
+ description: "Workflow runner — 负责调用 workflow_run 启动 workflow,支持 session resume 和 stop;失败接管由 prompt 推理触发 (Task #2251 简化版)。",
169
169
  systemPromptRef: "workflow-runner",
170
- allowedTools: [
171
- "workflow_get",
172
- "workflow_list",
173
- "workflow_run",
174
- "workflow_run_status",
175
- "workflow_run_stop"
176
- ],
177
170
  deniedTools: ["delegate_task", "stop_task"],
178
171
  maxIterations: 30
179
172
  };
@@ -216,6 +209,28 @@ class AgentRegistry {
216
209
  };
217
210
  this.agents.set(name, agent);
218
211
  }
212
+ registerWorkflowCreator() {
213
+ const name = "workflow-creator";
214
+ if (this.agents.has(name))
215
+ return;
216
+ const agent = {
217
+ name,
218
+ type: "sub",
219
+ description: "Workflow 构建子智能体 — 与用户多轮交互式协作设计、验证并注册 workflow",
220
+ systemPromptRef: "workflow-creator",
221
+ allowedTools: [
222
+ "workflow_list",
223
+ "workflow_get",
224
+ "workflow_search",
225
+ "workflow_tag_list",
226
+ "workflow_validate",
227
+ "workflow_add"
228
+ ],
229
+ deniedTools: ["delegate_task", "stop_task"],
230
+ maxIterations: 30
231
+ };
232
+ this.agents.set(name, agent);
233
+ }
219
234
  registerCompactAgent() {
220
235
  const name = "compact";
221
236
  if (this.agents.has(name))
@@ -430,6 +445,13 @@ __legacyDecorateClassTS([
430
445
  log: true
431
446
  })
432
447
  ], AgentRegistry.prototype, "registerWorkflowRunner", null);
448
+ __legacyDecorateClassTS([
449
+ TracedAs("agent.registry.registerWorkflowCreator", {
450
+ recordParams: false,
451
+ recordResult: true,
452
+ log: true
453
+ })
454
+ ], AgentRegistry.prototype, "registerWorkflowCreator", null);
433
455
  __legacyDecorateClassTS([
434
456
  TracedAs("agent.registry.load", { recordParams: false, recordResult: true, log: true })
435
457
  ], AgentRegistry.prototype, "load", null);