@ai-setting/roy-agent-core 1.6.3 → 1.6.4

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.
@@ -10,7 +10,7 @@ import {
10
10
  larkCliHandler,
11
11
  resolveBountyIMSystemPrompt,
12
12
  timerHandler
13
- } from "../../shared/@ai-setting/roy-agent-core-45tvcwwz.js";
13
+ } from "../../shared/@ai-setting/roy-agent-core-bferdaw6.js";
14
14
  import {
15
15
  BUILT_IN_EVENT_SOURCE_TYPES,
16
16
  BUILT_IN_EVENT_SOURCE_TYPE_LIST,
@@ -21,7 +21,7 @@ import {
21
21
  validateEventSourceConfig
22
22
  } from "../../shared/@ai-setting/roy-agent-core-ds5f75pg.js";
23
23
  import"../../shared/@ai-setting/roy-agent-core-wmkx79b1.js";
24
- import"../../shared/@ai-setting/roy-agent-core-6ve6tsm5.js";
24
+ import"../../shared/@ai-setting/roy-agent-core-aa0tdfb2.js";
25
25
  import"../../shared/@ai-setting/roy-agent-core-az13yzmc.js";
26
26
  import"../../shared/@ai-setting/roy-agent-core-8wd3qwx5.js";
27
27
  import"../../shared/@ai-setting/roy-agent-core-4yq23m5g.js";
package/dist/env/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  BaseEnvironment
3
- } from "../shared/@ai-setting/roy-agent-core-anhvbnrc.js";
3
+ } from "../shared/@ai-setting/roy-agent-core-hd5xrr2q.js";
4
4
  import {
5
5
  EventSourceComponent,
6
6
  builtInHandlers,
7
7
  larkCliHandler
8
- } from "../shared/@ai-setting/roy-agent-core-45tvcwwz.js";
8
+ } from "../shared/@ai-setting/roy-agent-core-bferdaw6.js";
9
9
  import {
10
10
  EventSourceInitHooks,
11
11
  getDefaultConfigForType,
@@ -17,13 +17,13 @@ import"../shared/@ai-setting/roy-agent-core-wmkx79b1.js";
17
17
  import {
18
18
  PluginComponent
19
19
  } from "../shared/@ai-setting/roy-agent-core-z7dxedn6.js";
20
- import"../shared/@ai-setting/roy-agent-core-6ve6tsm5.js";
20
+ import"../shared/@ai-setting/roy-agent-core-aa0tdfb2.js";
21
21
  import"../shared/@ai-setting/roy-agent-core-az13yzmc.js";
22
22
  import {
23
23
  WorkflowComponent
24
- } from "../shared/@ai-setting/roy-agent-core-8mqahsj5.js";
24
+ } from "../shared/@ai-setting/roy-agent-core-2xpstxhz.js";
25
25
  import"../shared/@ai-setting/roy-agent-core-xgnpr28w.js";
26
- import"../shared/@ai-setting/roy-agent-core-78m47x1d.js";
26
+ import"../shared/@ai-setting/roy-agent-core-kf3mw79k.js";
27
27
  import"../shared/@ai-setting/roy-agent-core-6atd905e.js";
28
28
  import"../shared/@ai-setting/roy-agent-core-vf72n6qn.js";
29
29
  import"../shared/@ai-setting/roy-agent-core-q88vxmx5.js";
@@ -48,7 +48,7 @@ import"../shared/@ai-setting/roy-agent-core-5h49ct1a.js";
48
48
  import"../shared/@ai-setting/roy-agent-core-e25xkv53.js";
49
49
  import {
50
50
  TaskComponent
51
- } from "../shared/@ai-setting/roy-agent-core-pr7f94gn.js";
51
+ } from "../shared/@ai-setting/roy-agent-core-tyqzn10b.js";
52
52
  import"../shared/@ai-setting/roy-agent-core-amkqnyzy.js";
53
53
  import"../shared/@ai-setting/roy-agent-core-8gxth0eh.js";
54
54
  import"../shared/@ai-setting/roy-agent-core-7afcdb2m.js";
@@ -61,7 +61,7 @@ import {
61
61
  getXDGPath,
62
62
  getXDGPaths
63
63
  } from "../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
64
- import"../shared/@ai-setting/roy-agent-core-0ye4q2jj.js";
64
+ import"../shared/@ai-setting/roy-agent-core-ktbkp661.js";
65
65
  import"../shared/@ai-setting/roy-agent-core-t94ktchq.js";
66
66
  import"../shared/@ai-setting/roy-agent-core-1pg0fepg.js";
67
67
  import {
@@ -5,7 +5,7 @@ import {
5
5
  TaskPriorityEnum,
6
6
  TaskStatusEnum,
7
7
  TaskTypeEnum
8
- } from "../../shared/@ai-setting/roy-agent-core-pr7f94gn.js";
8
+ } from "../../shared/@ai-setting/roy-agent-core-tyqzn10b.js";
9
9
  import"../../shared/@ai-setting/roy-agent-core-amkqnyzy.js";
10
10
  import {
11
11
  TaskEntityEventTypes
@@ -19,7 +19,7 @@ import {
19
19
  import"../../shared/@ai-setting/roy-agent-core-z9m38ytb.js";
20
20
  import"../../shared/@ai-setting/roy-agent-core-as3phr7n.js";
21
21
  import"../../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
22
- import"../../shared/@ai-setting/roy-agent-core-0ye4q2jj.js";
22
+ import"../../shared/@ai-setting/roy-agent-core-ktbkp661.js";
23
23
  import"../../shared/@ai-setting/roy-agent-core-t94ktchq.js";
24
24
  import"../../shared/@ai-setting/roy-agent-core-1pg0fepg.js";
25
25
  import"../../shared/@ai-setting/roy-agent-core-qxhq8ven.js";
@@ -8,7 +8,7 @@ import {
8
8
  formatExtractorInput,
9
9
  formatExtractorInputFromDescription,
10
10
  parseExtractorOutput
11
- } from "../../../shared/@ai-setting/roy-agent-core-6ve6tsm5.js";
11
+ } from "../../../shared/@ai-setting/roy-agent-core-aa0tdfb2.js";
12
12
  import"../../../shared/@ai-setting/roy-agent-core-az13yzmc.js";
13
13
  import"../../../shared/@ai-setting/roy-agent-core-8wd3qwx5.js";
14
14
  import"../../../shared/@ai-setting/roy-agent-core-4yq23m5g.js";
@@ -7,8 +7,9 @@ import {
7
7
  getTaskTool,
8
8
  listTasksTool,
9
9
  searchTasksTool,
10
+ treeTasksTool,
10
11
  updateTaskTool
11
- } from "../../../shared/@ai-setting/roy-agent-core-0ye4q2jj.js";
12
+ } from "../../../shared/@ai-setting/roy-agent-core-ktbkp661.js";
12
13
  import"../../../shared/@ai-setting/roy-agent-core-scp0afxg.js";
13
14
  import"../../../shared/@ai-setting/roy-agent-core-cg146hmg.js";
14
15
  import"../../../shared/@ai-setting/roy-agent-core-vyygk314.js";
@@ -17,6 +18,7 @@ import"../../../shared/@ai-setting/roy-agent-core-c6592r3c.js";
17
18
  import"../../../shared/@ai-setting/roy-agent-core-fs0mn2jk.js";
18
19
  export {
19
20
  updateTaskTool,
21
+ treeTasksTool,
20
22
  searchTasksTool,
21
23
  listTasksTool,
22
24
  getTaskTool,
@@ -5,7 +5,7 @@ import {
5
5
  Scheduler,
6
6
  WorkflowEngine,
7
7
  init_engine
8
- } from "../../../shared/@ai-setting/roy-agent-core-78m47x1d.js";
8
+ } from "../../../shared/@ai-setting/roy-agent-core-kf3mw79k.js";
9
9
  import"../../../shared/@ai-setting/roy-agent-core-6atd905e.js";
10
10
  import"../../../shared/@ai-setting/roy-agent-core-vf72n6qn.js";
11
11
  import"../../../shared/@ai-setting/roy-agent-core-q88vxmx5.js";
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  WorkflowComponent
3
- } from "../../shared/@ai-setting/roy-agent-core-8mqahsj5.js";
3
+ } from "../../shared/@ai-setting/roy-agent-core-2xpstxhz.js";
4
4
  import"../../shared/@ai-setting/roy-agent-core-xgnpr28w.js";
5
- import"../../shared/@ai-setting/roy-agent-core-78m47x1d.js";
5
+ import"../../shared/@ai-setting/roy-agent-core-kf3mw79k.js";
6
6
  import"../../shared/@ai-setting/roy-agent-core-6atd905e.js";
7
7
  import"../../shared/@ai-setting/roy-agent-core-vf72n6qn.js";
8
8
  import"../../shared/@ai-setting/roy-agent-core-q88vxmx5.js";
package/dist/index.js CHANGED
@@ -62,7 +62,7 @@ import {
62
62
  BaseEnvironment,
63
63
  generateDescendingId,
64
64
  generateId
65
- } from "./shared/@ai-setting/roy-agent-core-anhvbnrc.js";
65
+ } from "./shared/@ai-setting/roy-agent-core-hd5xrr2q.js";
66
66
  import {
67
67
  BountyIMInstance,
68
68
  EventSourceComponent,
@@ -74,7 +74,7 @@ import {
74
74
  larkCliHandler,
75
75
  resolveBountyIMSystemPrompt,
76
76
  timerHandler
77
- } from "./shared/@ai-setting/roy-agent-core-45tvcwwz.js";
77
+ } from "./shared/@ai-setting/roy-agent-core-bferdaw6.js";
78
78
  import {
79
79
  BUILT_IN_EVENT_SOURCE_TYPES,
80
80
  BUILT_IN_EVENT_SOURCE_TYPE_LIST,
@@ -94,18 +94,18 @@ import {
94
94
  import {
95
95
  TaskTagPlugin,
96
96
  createAutoTaskPlugin
97
- } from "./shared/@ai-setting/roy-agent-core-6ve6tsm5.js";
97
+ } from "./shared/@ai-setting/roy-agent-core-aa0tdfb2.js";
98
98
  import {
99
99
  BasePlugin
100
100
  } from "./shared/@ai-setting/roy-agent-core-az13yzmc.js";
101
101
  import {
102
102
  WorkflowComponent
103
- } from "./shared/@ai-setting/roy-agent-core-8mqahsj5.js";
103
+ } from "./shared/@ai-setting/roy-agent-core-2xpstxhz.js";
104
104
  import {
105
105
  init_node_registry_helper,
106
106
  registerDecoratorNodeType
107
107
  } from "./shared/@ai-setting/roy-agent-core-xgnpr28w.js";
108
- import"./shared/@ai-setting/roy-agent-core-78m47x1d.js";
108
+ import"./shared/@ai-setting/roy-agent-core-kf3mw79k.js";
109
109
  import"./shared/@ai-setting/roy-agent-core-6atd905e.js";
110
110
  import"./shared/@ai-setting/roy-agent-core-vf72n6qn.js";
111
111
  import"./shared/@ai-setting/roy-agent-core-q88vxmx5.js";
@@ -148,7 +148,7 @@ import {
148
148
  } from "./shared/@ai-setting/roy-agent-core-e25xkv53.js";
149
149
  import {
150
150
  TaskComponent
151
- } from "./shared/@ai-setting/roy-agent-core-pr7f94gn.js";
151
+ } from "./shared/@ai-setting/roy-agent-core-tyqzn10b.js";
152
152
  import"./shared/@ai-setting/roy-agent-core-amkqnyzy.js";
153
153
  import"./shared/@ai-setting/roy-agent-core-8gxth0eh.js";
154
154
  import"./shared/@ai-setting/roy-agent-core-7afcdb2m.js";
@@ -169,7 +169,7 @@ import {
169
169
  getXDGPath,
170
170
  getXDGPaths
171
171
  } from "./shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
172
- import"./shared/@ai-setting/roy-agent-core-0ye4q2jj.js";
172
+ import"./shared/@ai-setting/roy-agent-core-ktbkp661.js";
173
173
  import"./shared/@ai-setting/roy-agent-core-t94ktchq.js";
174
174
  import {
175
175
  TaskHookPoints
@@ -6,7 +6,7 @@ import {
6
6
  WorkflowEngine,
7
7
  exports_engine,
8
8
  init_engine
9
- } from "./roy-agent-core-78m47x1d.js";
9
+ } from "./roy-agent-core-kf3mw79k.js";
10
10
  import {
11
11
  askUserTool,
12
12
  createRunWorkflowTool,
@@ -331,7 +331,7 @@ function createAutoTaskPlugin(config) {
331
331
  lastProcessedTraceId = traceId;
332
332
  logger2.debug(`[AutoTaskPlugin] new query detected (traceId=${traceId.slice(0, 20)}...)`);
333
333
  const reminderContent = `⚠️ **系统提醒**: 你已经调用了 ${ctx.iteration} 次工具,达到 iteration 阈值(默认 ${threshold})。
334
- ` + `当前请求较为复杂,建议通过 \`delegate_task\` 工具将整个任务委托给 \`roy\` sub-agent 处理。`;
334
+ ` + `当前请求较为复杂,建议通过 \`delegate_task\` 工具将整个任务委托给 \`roy\` sub-agent 处理。` + `注意,需要让roy为这个任务调用task create工具来创建任务进行跟踪,这个是必走程序哈。`;
335
335
  if (!ctx.toolResult) {
336
336
  logger2.warn(`[AutoTaskPlugin] toolResult missing, skip meta-protocol (iteration=${ctx.iteration})`);
337
337
  return { continue: true };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  TaskTagPlugin,
3
3
  createLarkCliTaskNotifyHook
4
- } from "./roy-agent-core-6ve6tsm5.js";
4
+ } from "./roy-agent-core-aa0tdfb2.js";
5
5
  import {
6
6
  envKeyToConfigKey
7
7
  } from "./roy-agent-core-qxhq8ven.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createAutoTaskPlugin
3
- } from "./roy-agent-core-6ve6tsm5.js";
3
+ } from "./roy-agent-core-aa0tdfb2.js";
4
4
  import {
5
5
  ContextError,
6
6
  ErrorCodes
@@ -1029,6 +1029,8 @@ var init_agent_node = __esm(() => {
1029
1029
  let inheritedModel;
1030
1030
  let inheritedAllowedTools;
1031
1031
  let inheritedDeniedTools;
1032
+ let inheritedFromAgentName = false;
1033
+ let agentTypeAllowsAllTools = false;
1032
1034
  if (agentName && this.agentRunner.hasAgent && this.agentRunner.getAgentConfig) {
1033
1035
  if (this.agentRunner.hasAgent(agentName)) {
1034
1036
  const agentConfig2 = this.agentRunner.getAgentConfig(agentName);
@@ -1037,6 +1039,7 @@ var init_agent_node = __esm(() => {
1037
1039
  inheritedModel = agentConfig2.model;
1038
1040
  inheritedAllowedTools = agentConfig2.allowedTools;
1039
1041
  inheritedDeniedTools = agentConfig2.deniedTools;
1042
+ inheritedFromAgentName = true;
1040
1043
  }
1041
1044
  }
1042
1045
  }
@@ -1049,6 +1052,24 @@ var init_agent_node = __esm(() => {
1049
1052
  });
1050
1053
  }
1051
1054
  }
1055
+ if (!inheritedFromAgentName && this.agentRunner.hasAgent && this.agentRunner.getAgentConfig) {
1056
+ if (this.agentRunner.hasAgent(resolvedAgentType)) {
1057
+ const typeConfig = this.agentRunner.getAgentConfig(resolvedAgentType);
1058
+ if (typeConfig) {
1059
+ if (inheritedModel === undefined && typeConfig.model !== undefined) {
1060
+ inheritedModel = typeConfig.model;
1061
+ }
1062
+ if (inheritedDeniedTools === undefined && typeConfig.deniedTools !== undefined) {
1063
+ inheritedDeniedTools = typeConfig.deniedTools;
1064
+ }
1065
+ if (typeConfig.allowedTools === undefined) {
1066
+ agentTypeAllowsAllTools = true;
1067
+ } else if (inheritedAllowedTools === undefined) {
1068
+ inheritedAllowedTools = typeConfig.allowedTools;
1069
+ }
1070
+ }
1071
+ }
1072
+ }
1052
1073
  const userQuery = context.input?.userQuery ?? context.workflowInput?.userQuery;
1053
1074
  let agentSessionId = context.agentSessionId;
1054
1075
  if (!agentSessionId && context.sessionComponent) {
@@ -1065,7 +1086,7 @@ var init_agent_node = __esm(() => {
1065
1086
  }
1066
1087
  }
1067
1088
  const effectiveModel = options.model || inheritedModel;
1068
- const effectiveAllowedTools = options.allowedTools?.length ? options.allowedTools : inheritedAllowedTools?.length ? inheritedAllowedTools : ["ask_user"];
1089
+ const effectiveAllowedTools = options.allowedTools?.length ? options.allowedTools : agentTypeAllowsAllTools ? undefined : inheritedAllowedTools?.length ? inheritedAllowedTools : ["ask_user"];
1069
1090
  const effectiveDeniedTools = options.deniedTools?.length ? options.deniedTools : inheritedDeniedTools;
1070
1091
  const agentConfig = {
1071
1092
  type: resolvedAgentType,
@@ -20,11 +20,13 @@ var CreateTaskToolSchema = z.object({
20
20
  project_path: z.string().describe("Project root path for task positioning. " + "Used to locate the project space for this task. " + "Use 'unknown' if unknown."),
21
21
  parent_task_id: z.union([z.number(), z.null()]).optional().describe(`父任务 ID(可选)。不传或传 null 时,创建根任务(root task)。
22
22
  ` + `如需将任务挂载到某个父任务下,传入对应父任务 ID。
23
- ` + `如何选择合适的父任务:
24
- ` + ` 1. 使用 task_list(depth=0) 查看当前所有根任务
25
- ` + ` 2. 使用 task_search 搜索与当前任务相关的父任务
26
- ` + ` 3. 按主题归类:将相似主题的任务挂载到同一个父任务下
27
- ` + "如果确实找不到合适的父任务,可以直接创建根任务(不传 parent_task_id)。"),
23
+ ` + `**调用前必须先调用 task_tree(depth=2)** 查看现有任务树结构,避免重复创建根任务、避免孤儿任务。
24
+ ` + `决策路径(按顺序匹配):
25
+ ` + ` A. 归属到现有 longterm 根(如「[Longterm] X 生态」)→ parent_task_id = 该根 ID
26
+ ` + ` B. 归属到现有主题聚类(非 longterm 根,但同主题)→ parent_task_id = 该根 ID
27
+ ` + ` C. 新建根任务 → 省略 parent_task_id(让树根 ≤10)
28
+ ` + `如何找到 parent_task_id:使用 task_tree(depth=2) 获取的树形结构,
29
+ ` + "根据节点 id 选择合适的父任务 ID(来自 tree 输出,**不要硬编码**数字)。"),
28
30
  context: z.string().describe("JSON string with time-space positioning information for task continuity. " + "This field is crucial for Agent task handoff. " + "Core fields: worktree_path (git worktree path), branch (current branch), type (feature/bug/refactor/chore). " + 'Example for coding: {"worktree_path": "/path/worktree", "branch": "feature/xyz", "type": "feature"}. ' + 'Example for other: {"type": "general"}. ' + `If unknown, use '{}' or '{"type":"unknown"}'. ` + "IMPORTANT: Must be a valid JSON string!")
29
31
  });
30
32
  var GetTaskToolSchema = z.object({
@@ -77,6 +79,14 @@ var BatchArchiveToolSchema = z.object({
77
79
  var BatchDeleteToolSchema = z.object({
78
80
  task_ids: z.array(z.number()).describe("要删除的任务 ID 列表")
79
81
  });
82
+ var TreeTasksToolSchema = z.object({
83
+ depth: z.number().optional().default(2).describe("树的展开深度。默认 2 (根 + 一层子任务 + 二层孙任务)。" + "0 = 只返回根任务,不展开任何子节点。" + "-1 或负数 = 无限层级(全部展开)。"),
84
+ parent_task_id: z.number().optional().describe("只看指定父任务的子树。不传则从所有根任务(forest)开始。"),
85
+ status: z.enum(["todo", "active", "completed", "paused", "cancelled", "archived"]).optional().describe("按状态过滤(与 task_list 一致)。"),
86
+ priority: z.enum(["low", "medium", "high"]).optional().describe("按优先级过滤。"),
87
+ type: z.enum(["normal", "cycle", "longterm"]).optional().describe("按任务类型过滤。"),
88
+ include_archived: z.boolean().optional().default(false).describe("是否包含已归档任务(默认 false,与 task_list 一致)。")
89
+ });
80
90
 
81
91
  // src/env/task/tools/create-tool.ts
82
92
  init_env_context();
@@ -87,63 +97,84 @@ function createTaskTool(taskComponent) {
87
97
  name: "task_create",
88
98
  description: `
89
99
  Create a new task for tracking work.
90
-
100
+
101
+ ## ⚠️ CALL task_tree(depth=2) BEFORE THIS TOOL
102
+
103
+ Before calling \`task_create\`, you **MUST** first call
104
+ \`task_tree(depth=2)\` to inspect the existing task hierarchy.
105
+ This is critical because:
106
+
107
+ 1. Avoid duplicating root tasks (root tasks should stay ≤ 10).
108
+ 2. Find the right \`parent_task_id\` to attach under.
109
+ 3. Avoid creating stranded/orphan tasks.
110
+
111
+ Workflow:
112
+ step 1: task_tree({depth: 2})
113
+ step 2: read the tree, then decide per "Decision Tree" below
114
+ step 3: task_create({...})
115
+
116
+ ## Decision Tree — How to choose parent_task_id
117
+
118
+ Walk these paths in order:
119
+
120
+ **Path A — Attach under a longterm root.**
121
+ The task belongs to a theme whose longterm root already exists
122
+ (e.g. "[Longterm] X ecosystem"). Set \`parent_task_id\` to that
123
+ root's id. This is the **preferred** path for incremental work
124
+ inside an established theme.
125
+
126
+ **Path B — Attach under an existing topic cluster.**
127
+ A non-longterm root already aggregates similar tasks and yours
128
+ belongs in the same cluster. Set \`parent_task_id\` to that root.
129
+
130
+ **Path C — Create a new root.**
131
+ Neither A nor B fits (cross-cutting work, or root count already
132
+ ≥ ~10). **Omit** \`parent_task_id\` (or pass \`null\`) and the
133
+ task becomes a new root.
134
+
135
+ ## Tree Hygiene Principles
136
+
137
+ Apply these when deciding parent_task_id:
138
+
139
+ - Root tasks ≤ 10 (keep tree width manageable)
140
+ - Depth ≤ 5 (avoid deep nesting)
141
+ - Same-theme tasks cluster under one parent
142
+ - Long-tail/stranded tasks should be archived or merged
143
+
91
144
  ## IMPORTANT: Task Continuity Fields
92
-
93
- This tool creates persistent task records that can be picked up by a
94
- Task Manager Agent to continue推进未完成的任务.
95
-
145
+
146
+ This tool creates persistent task records that can be picked up by a
147
+ Task Manager Agent to continue advancing unfinished work.
148
+
96
149
  The following fields are critical for task context preservation:
97
-
150
+
98
151
  - project_path: The project root path where this task belongs.
99
152
  Used to locate the project space for this task.
100
153
  If unknown, use 'unknown'.
101
-
154
+
102
155
  - context: A JSON string containing time-space positioning information.
103
156
  This field is crucial for Agent task handoff.
104
-
157
+
105
158
  **Required format**: Valid JSON string (parseable).
106
-
159
+
107
160
  **Core fields**:
108
161
  - worktree_path: Git worktree path (for code development)
109
162
  - branch: Current branch name
110
163
  - type: Work type classification (feature/bug/refactor/chore).
111
164
  ⚠️ NOTE: This is the **context.type** (work classification), NOT the
112
165
  task's type field (normal/cycle/longterm). They are independent concepts.
113
-
166
+
114
167
  **Example for coding tasks**:
115
- {"worktree_path": "/path/to/worktree", "branch": "feature/xyz", "type": "feature", "parent_branch": "main"}
116
-
168
+ {"worktree_path": "<worktree-path>", "branch": "<branch-name>", "type": "feature", "parent_branch": "main"}
169
+
117
170
  **Example for other tasks**:
118
171
  {"type": "general"}
119
-
172
+
120
173
  If unable to fill in details, use at minimum:
121
174
  {"type": "unknown"}
122
-
175
+
123
176
  **DO NOT leave this as plain text** - it must be valid JSON!
124
-
125
- ## parent_task_id is OPTIONAL
126
-
127
- Creating a root task (top-level task) is allowed and common. To create a root task,
128
- simply **omit** \`parent_task_id\` (or pass \`null\`).
129
-
130
- To create a child task, provide an existing parent's \`parent_task_id\`. Best practices:
131
-
132
- 1. First, use \`task_list(depth=0)\` to see all root tasks (top-level tasks).
133
- 2. Use \`task_search\` with relevant keywords to find existing tasks
134
- that could serve as the parent.
135
- 3. Group by topic: put similar tasks under the same parent.
136
- 4. If no suitable parent exists, create a root task first (omit \`parent_task_id\`),
137
- then create the child task with that root task's id.
138
-
139
- **Examples:**
140
- - Root task: \`task_create(title="New project", ...)\` (no parent_task_id)
141
- - Child task: \`task_create(title="New feature", parent_task_id=<root_task_id>, ...)\`
142
- where \`<root_task_id>\` is the id returned by task_list, NOT a hardcoded number.
143
-
144
- **Hierarchy guidance** (not enforced):
145
- - 根任务 ≤10 (keep root tasks manageable)
146
- - 深度 ≤5 (avoid deep nesting)
177
+
147
178
  `,
148
179
  parameters: CreateTaskToolSchema,
149
180
  execute: async (args, ctx) => {
@@ -626,4 +657,142 @@ function completeTaskTool(taskComponent) {
626
657
  }
627
658
  };
628
659
  }
629
- export { createTaskTool, getTaskTool, listTasksTool, searchTasksTool, batchArchiveTaskTool, batchDeleteTaskTool, updateTaskTool, deleteTaskTool, completeTaskTool };
660
+ // src/env/task/tools/task-tree-tool.ts
661
+ function compareTasksDesc(a, b) {
662
+ if (a.updatedAt < b.updatedAt)
663
+ return 1;
664
+ if (a.updatedAt > b.updatedAt)
665
+ return -1;
666
+ if (a.id < b.id)
667
+ return 1;
668
+ if (a.id > b.id)
669
+ return -1;
670
+ return 0;
671
+ }
672
+ function trimToDepth(nodes, depth) {
673
+ if (depth < 0)
674
+ return nodes;
675
+ if (depth === 0) {
676
+ return nodes.map((n) => ({ ...n, children: [] }));
677
+ }
678
+ return nodes.map((n) => ({
679
+ ...n,
680
+ children: trimToDepth(n.children, depth - 1)
681
+ }));
682
+ }
683
+ function countNodes(nodes) {
684
+ let n = 0;
685
+ for (const node of nodes)
686
+ n += 1 + countNodes(node.children);
687
+ return n;
688
+ }
689
+ function buildTaskNodes(tasks) {
690
+ const nodeById = new Map;
691
+ const byParent = new Map;
692
+ const roots = [];
693
+ for (const t of tasks) {
694
+ nodeById.set(t.id, {
695
+ id: t.id,
696
+ title: t.title,
697
+ status: t.status,
698
+ type: t.type,
699
+ priority: t.priority,
700
+ progress: t.progress,
701
+ children: []
702
+ });
703
+ }
704
+ for (const t of tasks) {
705
+ const pid = t.parent_task_id;
706
+ if (pid !== undefined && pid !== null && nodeById.has(pid)) {
707
+ const list = byParent.get(pid) || [];
708
+ list.push(t);
709
+ byParent.set(pid, list);
710
+ } else {
711
+ roots.push(t);
712
+ }
713
+ }
714
+ for (const [parentId, children] of byParent.entries()) {
715
+ const parentNode = nodeById.get(parentId);
716
+ children.sort(compareTasksDesc);
717
+ parentNode.children = children.map((c) => nodeById.get(c.id));
718
+ }
719
+ roots.sort(compareTasksDesc);
720
+ return roots.map((r) => nodeById.get(r.id));
721
+ }
722
+ function treeTasksTool(taskComponent) {
723
+ return {
724
+ name: "task_tree",
725
+ description: "View the task tree (forest) with optional filters. " + "Use this BEFORE task_create to decide whether to create a root task " + "(omit parent_task_id) or attach to an existing parent. " + "depth: 0=只根任务, 1=根+一层子任务, 2=根+二层子任务 (default), " + "-1 or omitted as -1=无限层级. " + `Returns { total, truncated, depth, parent_task_id, nodes } where:
726
+ ` + ` - total: count of ALL tasks in the returned tree (incl. descendants)
727
+ ` + ` - truncated: always false for now (no pagination cap on tree)
728
+ ` + ` - depth: the resolved depth value
729
+ ` + ` - parent_task_id: the root's id, or null for forest mode
730
+ ` + ` - nodes: TaskNode[] with { id, title, status, type, priority, progress, children }
731
+ ` + "Note: `total` is the FIRST field in the response so it survives " + "tail-truncation by ToolComponent.truncateOutput.",
732
+ parameters: TreeTasksToolSchema,
733
+ execute: async (args, _ctx) => {
734
+ const params = TreeTasksToolSchema.parse(args);
735
+ try {
736
+ let flat = [];
737
+ let parent_task_id = params.parent_task_id ?? null;
738
+ if (params.parent_task_id !== undefined && params.parent_task_id !== null) {
739
+ const root = await taskComponent.getTask(params.parent_task_id);
740
+ if (!root) {
741
+ flat = [];
742
+ } else {
743
+ const descendants = await taskComponent.getTaskTree(params.parent_task_id, params.depth === -1 ? -1 : Math.max(0, params.depth - 1));
744
+ flat = [root, ...descendants];
745
+ }
746
+ } else {
747
+ const result = await taskComponent.listTasks({
748
+ status: params.status,
749
+ priority: params.priority,
750
+ type: params.type,
751
+ include_archived: params.include_archived,
752
+ limit: 9999,
753
+ offset: 0
754
+ });
755
+ flat = result.tasks;
756
+ }
757
+ if (params.parent_task_id !== undefined && params.parent_task_id !== null) {
758
+ if (params.status) {
759
+ flat = flat.filter((t) => t.status === params.status);
760
+ }
761
+ if (params.priority) {
762
+ flat = flat.filter((t) => t.priority === params.priority);
763
+ }
764
+ if (params.type) {
765
+ flat = flat.filter((t) => t.type === params.type);
766
+ }
767
+ if (!params.include_archived) {
768
+ flat = flat.filter((t) => t.status !== "archived");
769
+ }
770
+ }
771
+ let nodes = buildTaskNodes(flat);
772
+ if (params.parent_task_id === undefined || params.parent_task_id === null) {
773
+ nodes = trimToDepth(nodes, params.depth);
774
+ }
775
+ const total = countNodes(nodes);
776
+ return {
777
+ success: true,
778
+ output: JSON.stringify({
779
+ total,
780
+ truncated: false,
781
+ depth: params.depth,
782
+ parent_task_id,
783
+ nodes
784
+ }),
785
+ metadata: { execution_time_ms: 0 }
786
+ };
787
+ } catch (error) {
788
+ return {
789
+ success: false,
790
+ output: "",
791
+ error: error instanceof Error ? error.message : String(error),
792
+ metadata: { execution_time_ms: 0 }
793
+ };
794
+ }
795
+ }
796
+ };
797
+ }
798
+ export { createTaskTool, getTaskTool, listTasksTool, searchTasksTool, batchArchiveTaskTool, batchDeleteTaskTool, updateTaskTool, deleteTaskTool, completeTaskTool, treeTasksTool };
@@ -22,8 +22,9 @@ import {
22
22
  getTaskTool,
23
23
  listTasksTool,
24
24
  searchTasksTool,
25
+ treeTasksTool,
25
26
  updateTaskTool
26
- } from "./roy-agent-core-0ye4q2jj.js";
27
+ } from "./roy-agent-core-ktbkp661.js";
27
28
  import {
28
29
  createOperationTool,
29
30
  deleteOperationTool,
@@ -352,6 +353,7 @@ class TaskComponent extends BaseComponent {
352
353
  createTaskTool(this),
353
354
  getTaskTool(this),
354
355
  listTasksTool(this),
356
+ treeTasksTool(this),
355
357
  searchTasksTool(this),
356
358
  batchArchiveTaskTool(this),
357
359
  batchDeleteTaskTool(this),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-setting/roy-agent-core",
3
- "version": "1.6.3",
3
+ "version": "1.6.4",
4
4
  "type": "module",
5
5
  "description": "Core SDK for roy-agent - Environment, Components, Tools, Sessions, Tasks",
6
6
  "main": "./dist/index.js",