@ai-setting/roy-agent-core 1.5.66 → 1.5.68

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.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  AgentComponent,
3
3
  AgentComponentConfigSchema
4
- } from "../../shared/@ai-setting/roy-agent-core-marga2es.js";
4
+ } from "../../shared/@ai-setting/roy-agent-core-08q02yz2.js";
5
5
  import"../../shared/@ai-setting/roy-agent-core-ecth1zak.js";
6
6
  import"../../shared/@ai-setting/roy-agent-core-e25xkv53.js";
7
7
  import"../../shared/@ai-setting/roy-agent-core-nx3c3ce2.js";
package/dist/env/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  BaseEnvironment
3
- } from "../shared/@ai-setting/roy-agent-core-v61w8cmf.js";
3
+ } from "../shared/@ai-setting/roy-agent-core-zm86k3rg.js";
4
4
  import {
5
5
  EventSourceComponent,
6
6
  builtInHandlers,
@@ -39,22 +39,22 @@ import"../shared/@ai-setting/roy-agent-core-1ce3fqrk.js";
39
39
  import {
40
40
  AgentComponent,
41
41
  AgentComponentConfigSchema
42
- } from "../shared/@ai-setting/roy-agent-core-marga2es.js";
42
+ } from "../shared/@ai-setting/roy-agent-core-08q02yz2.js";
43
43
  import"../shared/@ai-setting/roy-agent-core-ecth1zak.js";
44
44
  import"../shared/@ai-setting/roy-agent-core-e25xkv53.js";
45
45
  import {
46
46
  TaskComponent
47
- } from "../shared/@ai-setting/roy-agent-core-z2fxjh6k.js";
47
+ } from "../shared/@ai-setting/roy-agent-core-84vtpbw6.js";
48
48
  import"../shared/@ai-setting/roy-agent-core-8gxth0eh.js";
49
49
  import"../shared/@ai-setting/roy-agent-core-eq52jra7.js";
50
- import"../shared/@ai-setting/roy-agent-core-cgq7btak.js";
50
+ import"../shared/@ai-setting/roy-agent-core-r9y8ct0w.js";
51
51
  import"../shared/@ai-setting/roy-agent-core-nx3c3ce2.js";
52
52
  import {
53
53
  XDG_PATHS,
54
54
  getXDGPath,
55
55
  getXDGPaths
56
56
  } from "../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
57
- import"../shared/@ai-setting/roy-agent-core-3s9va046.js";
57
+ import"../shared/@ai-setting/roy-agent-core-7t0jen73.js";
58
58
  import"../shared/@ai-setting/roy-agent-core-t94ktchq.js";
59
59
  import"../shared/@ai-setting/roy-agent-core-92z6t4he.js";
60
60
  import {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  SessionComponent
3
- } from "../../shared/@ai-setting/roy-agent-core-hkeegfq0.js";
3
+ } from "../../shared/@ai-setting/roy-agent-core-jkzgmd1v.js";
4
4
  import"../../shared/@ai-setting/roy-agent-core-rvxg1wps.js";
5
5
  import {
6
6
  MemorySessionStore
@@ -5,7 +5,7 @@ import {
5
5
  TaskPriorityEnum,
6
6
  TaskStatusEnum,
7
7
  TaskTypeEnum
8
- } from "../../shared/@ai-setting/roy-agent-core-z2fxjh6k.js";
8
+ } from "../../shared/@ai-setting/roy-agent-core-84vtpbw6.js";
9
9
  import {
10
10
  TaskEntityEventTypes
11
11
  } from "../../shared/@ai-setting/roy-agent-core-8gxth0eh.js";
@@ -13,10 +13,10 @@ import"../../shared/@ai-setting/roy-agent-core-eq52jra7.js";
13
13
  import {
14
14
  SQLiteTaskStore,
15
15
  getDefaultTaskDbPath
16
- } from "../../shared/@ai-setting/roy-agent-core-cgq7btak.js";
16
+ } from "../../shared/@ai-setting/roy-agent-core-r9y8ct0w.js";
17
17
  import"../../shared/@ai-setting/roy-agent-core-nx3c3ce2.js";
18
18
  import"../../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
19
- import"../../shared/@ai-setting/roy-agent-core-3s9va046.js";
19
+ import"../../shared/@ai-setting/roy-agent-core-7t0jen73.js";
20
20
  import"../../shared/@ai-setting/roy-agent-core-t94ktchq.js";
21
21
  import"../../shared/@ai-setting/roy-agent-core-92z6t4he.js";
22
22
  import"../../shared/@ai-setting/roy-agent-core-qxhq8ven.js";
@@ -2,7 +2,7 @@ import {
2
2
  SQLiteTaskStore,
3
3
  getDefaultDataDir,
4
4
  getDefaultTaskDbPath
5
- } from "../../../shared/@ai-setting/roy-agent-core-cgq7btak.js";
5
+ } from "../../../shared/@ai-setting/roy-agent-core-r9y8ct0w.js";
6
6
  import"../../../shared/@ai-setting/roy-agent-core-shme7set.js";
7
7
  import"../../../shared/@ai-setting/roy-agent-core-7z9b1fm8.js";
8
8
  import"../../../shared/@ai-setting/roy-agent-core-c6592r3c.js";
@@ -8,7 +8,7 @@ import {
8
8
  listTasksTool,
9
9
  searchTasksTool,
10
10
  updateTaskTool
11
- } from "../../../shared/@ai-setting/roy-agent-core-3s9va046.js";
11
+ } from "../../../shared/@ai-setting/roy-agent-core-7t0jen73.js";
12
12
  import"../../../shared/@ai-setting/roy-agent-core-y5d04fm3.js";
13
13
  import"../../../shared/@ai-setting/roy-agent-core-k05v31rc.js";
14
14
  import"../../../shared/@ai-setting/roy-agent-core-shme7set.js";
package/dist/index.js CHANGED
@@ -57,7 +57,7 @@ import {
57
57
  BaseEnvironment,
58
58
  generateDescendingId,
59
59
  generateId
60
- } from "./shared/@ai-setting/roy-agent-core-v61w8cmf.js";
60
+ } from "./shared/@ai-setting/roy-agent-core-zm86k3rg.js";
61
61
  import {
62
62
  EventSourceComponent,
63
63
  builtInHandlers,
@@ -116,7 +116,7 @@ import"./shared/@ai-setting/roy-agent-core-1ce3fqrk.js";
116
116
  import {
117
117
  AgentComponent,
118
118
  AgentComponentConfigSchema
119
- } from "./shared/@ai-setting/roy-agent-core-marga2es.js";
119
+ } from "./shared/@ai-setting/roy-agent-core-08q02yz2.js";
120
120
  import {
121
121
  createInvokeConfig,
122
122
  invoke,
@@ -129,13 +129,13 @@ import {
129
129
  } from "./shared/@ai-setting/roy-agent-core-e25xkv53.js";
130
130
  import {
131
131
  TaskComponent
132
- } from "./shared/@ai-setting/roy-agent-core-z2fxjh6k.js";
132
+ } from "./shared/@ai-setting/roy-agent-core-84vtpbw6.js";
133
133
  import"./shared/@ai-setting/roy-agent-core-8gxth0eh.js";
134
134
  import"./shared/@ai-setting/roy-agent-core-eq52jra7.js";
135
135
  import {
136
136
  SQLiteTaskStore,
137
137
  getDefaultTaskDbPath
138
- } from "./shared/@ai-setting/roy-agent-core-cgq7btak.js";
138
+ } from "./shared/@ai-setting/roy-agent-core-r9y8ct0w.js";
139
139
  import {
140
140
  AgentRegistry
141
141
  } from "./shared/@ai-setting/roy-agent-core-nx3c3ce2.js";
@@ -144,7 +144,7 @@ import {
144
144
  getXDGPath,
145
145
  getXDGPaths
146
146
  } from "./shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
147
- import"./shared/@ai-setting/roy-agent-core-3s9va046.js";
147
+ import"./shared/@ai-setting/roy-agent-core-7t0jen73.js";
148
148
  import"./shared/@ai-setting/roy-agent-core-t94ktchq.js";
149
149
  import {
150
150
  TaskHookPoints
@@ -171,7 +171,7 @@ import"./shared/@ai-setting/roy-agent-core-fnv3ev18.js";
171
171
  import"./shared/@ai-setting/roy-agent-core-djtkntar.js";
172
172
  import {
173
173
  SessionComponent
174
- } from "./shared/@ai-setting/roy-agent-core-hkeegfq0.js";
174
+ } from "./shared/@ai-setting/roy-agent-core-jkzgmd1v.js";
175
175
  import"./shared/@ai-setting/roy-agent-core-rvxg1wps.js";
176
176
  import {
177
177
  MemorySessionStore
@@ -794,7 +794,7 @@ class AgentComponent extends BaseComponent {
794
794
  } catch (error) {
795
795
  logger.error(`Iteration ${iteration} error`, { error });
796
796
  hookCtx.error = error instanceof Error ? error : new Error(String(error));
797
- if (error instanceof Error && error instanceof ContextError && error.llmOutput) {
797
+ if (error instanceof ContextError && error.llmOutput) {
798
798
  const llmOutput = error.llmOutput;
799
799
  if (llmOutput.toolCalls?.length) {
800
800
  const assistantParts = [];
@@ -877,6 +877,9 @@ class AgentComponent extends BaseComponent {
877
877
  result.error = `__ASK_USER_ERROR__:${JSON.stringify(errorInfo)}`;
878
878
  } else {
879
879
  result.error = hookCtx.error.message;
880
+ if (error instanceof Error) {
881
+ result.originalError = error;
882
+ }
880
883
  if (error?.name === "AbortError") {
881
884
  hookCtx._stopReason = hookCtx._stopReason || "aborted";
882
885
  } else {
@@ -18,7 +18,15 @@ var CreateTaskToolSchema = z.object({
18
18
  due_date: z.string().optional().describe("Due date (ISO format)"),
19
19
  tags: z.array(z.string()).optional().describe("Task tags (for search, stored in task.tags JSON field)"),
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
- parent_task_id: z.number().optional().describe("父任务 ID(可选,用于构建任务树)"),
21
+ parent_task_id: z.number().describe(`父任务 ID(必填)。所有新任务都必须挂载到某个父任务下,以维护良好的任务树结构。
22
+ ` + `为什么 parent_task_id 是必填的:
23
+ ` + ` 1. 任务聚类:将相关任务聚合到同一父任务下,便于管理和追踪
24
+ ` + ` 2. 维护任务树:保持根任务数量可控(≤10个),深度适中(≤5层)
25
+ ` + `如何选择合适的父任务:
26
+ ` + ` 1. 使用 task_list(depth=0) 查看当前所有根任务
27
+ ` + ` 2. 使用 task_search 搜索与当前任务相关的父任务
28
+ ` + ` 3. 按主题归类:将相似主题的任务挂载到同一个父任务下
29
+ ` + "如果确实找不到合适的父任务,可以先创建一个合适的父任务,再创建子任务。"),
22
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!")
23
31
  });
24
32
  var GetTaskToolSchema = z.object({
@@ -114,6 +122,29 @@ function createTaskTool(taskComponent) {
114
122
  {"type": "unknown"}
115
123
 
116
124
  **DO NOT leave this as plain text** - it must be valid JSON!
125
+
126
+ ## ⚠️ parent_task_id is REQUIRED
127
+
128
+ All new tasks MUST have a parent_task_id. This is critical for:
129
+
130
+ 1. **Task Tree Structure**: Every task must be attached to a parent,
131
+ maintaining a clean hierarchy (根任务 ≤10, 深度 ≤5).
132
+
133
+ 2. **Task Clustering**: Related tasks are grouped under the same parent,
134
+ making it easy to track progress and find related work.
135
+
136
+ **How to choose a parent task:**
137
+
138
+ 1. First, use \`task_list(depth=0)\` to see all root tasks (top-level tasks).
139
+ 2. Use \`task_search\` with relevant keywords to find existing tasks
140
+ that could serve as the parent.
141
+ 3. Group by topic: put similar tasks under the same parent.
142
+ 4. If no suitable parent exists, create a parent task first,
143
+ then create the child task with that parent_task_id.
144
+
145
+ **Example:**
146
+ - First: task_list(depth=0) → find root task #619 "roy-agent"
147
+ - Then: task_create(title="New feature", parent_task_id=619, ...)
117
148
  `,
118
149
  parameters: CreateTaskToolSchema,
119
150
  execute: async (args, ctx) => {
@@ -9,7 +9,7 @@ import {
9
9
  import {
10
10
  SQLiteTaskStore,
11
11
  getDefaultTaskDbPath
12
- } from "./roy-agent-core-cgq7btak.js";
12
+ } from "./roy-agent-core-r9y8ct0w.js";
13
13
  import {
14
14
  batchArchiveTaskTool,
15
15
  batchDeleteTaskTool,
@@ -20,7 +20,7 @@ import {
20
20
  listTasksTool,
21
21
  searchTasksTool,
22
22
  updateTaskTool
23
- } from "./roy-agent-core-3s9va046.js";
23
+ } from "./roy-agent-core-7t0jen73.js";
24
24
  import {
25
25
  createOperationTool,
26
26
  deleteOperationTool,
@@ -358,6 +358,13 @@ class TaskComponent extends BaseComponent {
358
358
  }
359
359
  async createTask(options) {
360
360
  const sessionId = options.sessionId;
361
+ if (options.parent_task_id === undefined || options.parent_task_id === null) {
362
+ throw new Error("parent_task_id is required. All tasks must be attached to a parent task. " + "Use task_list(depth=0) to find root tasks, or create a parent task first.");
363
+ }
364
+ const parentTask = await this.store.getTask(options.parent_task_id);
365
+ if (!parentTask) {
366
+ throw new Error(`Parent task #${options.parent_task_id} not found. ` + "Please provide a valid parent_task_id. Use task_list(depth=0) to see all root tasks.");
367
+ }
361
368
  const createCtx = {
362
369
  options: { ...options },
363
370
  sessionId,
@@ -450,12 +450,19 @@ class SessionComponent extends BaseComponent {
450
450
  const recentMessages = this.extractRecentMessages(messages, 2);
451
451
  this.ensureSummaryAgent();
452
452
  await this.executeBeforeHooks("compact", { session, options });
453
- const summaryResult = await this.summaryAgent.run({
454
- messages: messages.map((m) => ({ role: m.role, content: m.content })),
455
- userContext: options?.summary,
456
- outputFormat: "json",
457
- scenarioHint: options?.scenarioHint
458
- });
453
+ let summaryResult;
454
+ try {
455
+ summaryResult = await this.summaryAgent.run({
456
+ messages: messages.map((m) => ({ role: m.role, content: m.content })),
457
+ userContext: options?.summary,
458
+ outputFormat: "json",
459
+ scenarioHint: options?.scenarioHint
460
+ });
461
+ } catch (error) {
462
+ const errorMessage = error instanceof Error ? error.message : String(error);
463
+ logger.error(`[SessionComponent] SummaryAgent.run failed: ${errorMessage}`);
464
+ throw new Error(`Session compaction failed: SummaryAgent error - ${errorMessage}`);
465
+ }
459
466
  const checkpointId = `cp_${Date.now().toString(36)}_${Math.random().toString(36).substring(2, 8)}`;
460
467
  const checkpoint = {
461
468
  id: checkpointId,
@@ -476,9 +483,9 @@ class SessionComponent extends BaseComponent {
476
483
  recentMessages
477
484
  };
478
485
  await this.store.saveCheckpoint(sessionId, checkpoint);
479
- await this.store.archiveMessages(sessionId, checkpointId, messages.length);
480
486
  const checkpointMessage = this.createCheckpointMessage(checkpoint);
481
487
  await this.store.addMessage(sessionId, checkpointMessage);
488
+ await this.store.archiveMessages(sessionId, checkpointId, messages.length);
482
489
  const updatedSession = await this.get(sessionId);
483
490
  const remainingMessageCount = updatedSession?.messageCount ?? 0;
484
491
  const checkpointCount = updatedSession?.metadata?.checkpoints?.checkpoints?.length ?? 0;
@@ -940,6 +940,8 @@ class SQLiteTaskStore {
940
940
  this.db = null;
941
941
  this.initialized = false;
942
942
  }
943
+ this.tasksCache.clear();
944
+ this.operationsCache.clear();
943
945
  }
944
946
  }
945
947
  var logger;
@@ -225,6 +225,9 @@ class BaseEnvironment extends BaseComponent {
225
225
  }
226
226
  const result = await agentComponent.run(agent.name, query, context);
227
227
  if (result.error) {
228
+ if (result.originalError instanceof ContextError) {
229
+ throw result.originalError;
230
+ }
228
231
  const errorMsg = result.error.toLowerCase();
229
232
  if (errorMsg.includes("context") || errorMsg.includes("threshold") || errorMsg.includes("token") || result.error.includes("CTX_001")) {
230
233
  const usageMatch = result.error.match(/(\d+)\/(\d+)\s*\(([\d.]+)%\)/);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-setting/roy-agent-core",
3
- "version": "1.5.66",
3
+ "version": "1.5.68",
4
4
  "type": "module",
5
5
  "description": "Core SDK for roy-agent - Environment, Components, Tools, Sessions, Tasks",
6
6
  "main": "./dist/index.js",