@ai-setting/roy-agent-core 1.6.12 → 1.6.14

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 (40) hide show
  1. package/dist/env/agent/index.js +3 -3
  2. package/dist/env/event-source/index.js +7 -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 +5 -5
  7. package/dist/env/task/plugins/index.js +6 -4
  8. package/dist/env/tool/built-in/index.js +2 -2
  9. package/dist/env/tool/index.js +3 -3
  10. package/dist/env/workflow/engine/index.js +5 -5
  11. package/dist/env/workflow/index.js +12 -10
  12. package/dist/env/workflow/service/index.js +1 -1
  13. package/dist/env/workflow/tools/index.js +5 -4
  14. package/dist/env/workflow/types/index.js +3 -1
  15. package/dist/env/workflow/utils/index.js +4 -4
  16. package/dist/index.js +132 -21
  17. package/dist/shared/@ai-setting/{roy-agent-core-jenchn33.js → roy-agent-core-24rmf17n.js} +8 -0
  18. package/dist/shared/@ai-setting/{roy-agent-core-z7f8hyv7.js → roy-agent-core-6jqpdjr4.js} +1 -1
  19. package/dist/shared/@ai-setting/{roy-agent-core-cxdnzn17.js → roy-agent-core-6qbyfzsw.js} +1 -1
  20. package/dist/shared/@ai-setting/{roy-agent-core-8wd3qwx5.js → roy-agent-core-80e4a3g5.js} +1 -1
  21. package/dist/shared/@ai-setting/{roy-agent-core-ms5dp89r.js → roy-agent-core-apz6v22z.js} +81 -40
  22. package/dist/shared/@ai-setting/{roy-agent-core-1bvv6s75.js → roy-agent-core-fvkyv5j6.js} +2 -2
  23. package/dist/shared/@ai-setting/{roy-agent-core-dntkpwqq.js → roy-agent-core-fwxqevpf.js} +4 -1
  24. package/dist/shared/@ai-setting/{roy-agent-core-qnrf2aw6.js → roy-agent-core-jrj30vq3.js} +33 -2
  25. package/dist/shared/@ai-setting/{roy-agent-core-q7rt3x8d.js → roy-agent-core-m0cnmg7b.js} +2 -2
  26. package/dist/shared/@ai-setting/roy-agent-core-mmb9484f.js +458 -0
  27. package/dist/shared/@ai-setting/{roy-agent-core-0n2a8cbn.js → roy-agent-core-nhncpbzz.js} +602 -245
  28. package/dist/shared/@ai-setting/{roy-agent-core-pzeexnhf.js → roy-agent-core-nv4yfy3m.js} +4 -3
  29. package/dist/shared/@ai-setting/{roy-agent-core-w22tzjj5.js → roy-agent-core-psfkwe4g.js} +93 -14
  30. package/dist/shared/@ai-setting/{roy-agent-core-q2bw3cwd.js → roy-agent-core-px8ghk4g.js} +1 -1
  31. package/dist/shared/@ai-setting/{roy-agent-core-mb7b62sm.js → roy-agent-core-r53regz9.js} +2 -2
  32. package/dist/shared/@ai-setting/{roy-agent-core-06574wqa.js → roy-agent-core-ra4y7e4p.js} +4 -4
  33. package/dist/shared/@ai-setting/{roy-agent-core-asp5p3zx.js → roy-agent-core-st9y9z07.js} +1 -1
  34. package/dist/shared/@ai-setting/{roy-agent-core-3bdpnmtg.js → roy-agent-core-v5nknfh0.js} +1 -8
  35. package/dist/shared/@ai-setting/{roy-agent-core-7a3gf3tw.js → roy-agent-core-wpw37qqf.js} +88 -3
  36. package/dist/shared/@ai-setting/{roy-agent-core-p6x6n3k4.js → roy-agent-core-x7fgze6s.js} +1 -1
  37. package/dist/shared/@ai-setting/{roy-agent-core-p2vpsd1d.js → roy-agent-core-ywtmc0bh.js} +166 -6
  38. package/package.json +1 -1
  39. package/dist/shared/@ai-setting/roy-agent-core-4yq23m5g.js +0 -421
  40. /package/dist/shared/@ai-setting/{roy-agent-core-zs31w092.js → roy-agent-core-9nhwdq9r.js} +0 -0
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  PromptComponent,
3
3
  PromptStore
4
- } from "./shared/@ai-setting/roy-agent-core-cxdnzn17.js";
4
+ } from "./shared/@ai-setting/roy-agent-core-6qbyfzsw.js";
5
5
  import {
6
6
  LLMComponent,
7
7
  LLMConfigSchema,
@@ -27,7 +27,7 @@ import {
27
27
  grepTool,
28
28
  readFileTool,
29
29
  writeFileTool
30
- } from "./shared/@ai-setting/roy-agent-core-p6x6n3k4.js";
30
+ } from "./shared/@ai-setting/roy-agent-core-x7fgze6s.js";
31
31
  import {
32
32
  ATTACH_FILE_MAX_BYTES,
33
33
  getUnderstandImageLLMProvider,
@@ -63,7 +63,7 @@ import {
63
63
  BaseEnvironment,
64
64
  generateDescendingId,
65
65
  generateId
66
- } from "./shared/@ai-setting/roy-agent-core-asp5p3zx.js";
66
+ } from "./shared/@ai-setting/roy-agent-core-st9y9z07.js";
67
67
  import {
68
68
  BountyIMInstance,
69
69
  EventSourceComponent,
@@ -75,7 +75,7 @@ import {
75
75
  larkCliHandler,
76
76
  resolveBountyIMSystemPrompt,
77
77
  timerHandler
78
- } from "./shared/@ai-setting/roy-agent-core-q2bw3cwd.js";
78
+ } from "./shared/@ai-setting/roy-agent-core-px8ghk4g.js";
79
79
  import {
80
80
  BUILT_IN_EVENT_SOURCE_TYPES,
81
81
  BUILT_IN_EVENT_SOURCE_TYPE_LIST,
@@ -95,30 +95,30 @@ import {
95
95
  import {
96
96
  TaskTagPlugin,
97
97
  createAutoTaskPlugin
98
- } from "./shared/@ai-setting/roy-agent-core-q7rt3x8d.js";
98
+ } from "./shared/@ai-setting/roy-agent-core-m0cnmg7b.js";
99
99
  import {
100
100
  BasePlugin
101
101
  } from "./shared/@ai-setting/roy-agent-core-az13yzmc.js";
102
102
  import {
103
103
  WorkflowComponent
104
- } from "./shared/@ai-setting/roy-agent-core-06574wqa.js";
104
+ } from "./shared/@ai-setting/roy-agent-core-ra4y7e4p.js";
105
105
  import {
106
106
  init_node_registry_helper,
107
107
  registerDecoratorNodeType
108
108
  } from "./shared/@ai-setting/roy-agent-core-htjag2nr.js";
109
- import"./shared/@ai-setting/roy-agent-core-0n2a8cbn.js";
109
+ import"./shared/@ai-setting/roy-agent-core-nhncpbzz.js";
110
110
  import"./shared/@ai-setting/roy-agent-core-6atd905e.js";
111
- import"./shared/@ai-setting/roy-agent-core-jenchn33.js";
112
- import"./shared/@ai-setting/roy-agent-core-w22tzjj5.js";
111
+ import"./shared/@ai-setting/roy-agent-core-24rmf17n.js";
112
+ import"./shared/@ai-setting/roy-agent-core-psfkwe4g.js";
113
113
  import"./shared/@ai-setting/roy-agent-core-ddwa0n6h.js";
114
114
  import"./shared/@ai-setting/roy-agent-core-hhrg314p.js";
115
115
  import"./shared/@ai-setting/roy-agent-core-resnbd2j.js";
116
- import"./shared/@ai-setting/roy-agent-core-qnrf2aw6.js";
117
- import"./shared/@ai-setting/roy-agent-core-mb7b62sm.js";
116
+ import"./shared/@ai-setting/roy-agent-core-r53regz9.js";
118
117
  import"./shared/@ai-setting/roy-agent-core-1db4vpc6.js";
119
- import"./shared/@ai-setting/roy-agent-core-p2vpsd1d.js";
120
- import"./shared/@ai-setting/roy-agent-core-8wd3qwx5.js";
121
- import"./shared/@ai-setting/roy-agent-core-4yq23m5g.js";
118
+ import"./shared/@ai-setting/roy-agent-core-ywtmc0bh.js";
119
+ import"./shared/@ai-setting/roy-agent-core-80e4a3g5.js";
120
+ import"./shared/@ai-setting/roy-agent-core-mmb9484f.js";
121
+ import"./shared/@ai-setting/roy-agent-core-jrj30vq3.js";
122
122
  import {
123
123
  Edge,
124
124
  NodeAs,
@@ -130,7 +130,7 @@ import"./shared/@ai-setting/roy-agent-core-1ce3fqrk.js";
130
130
  import {
131
131
  AgentComponent,
132
132
  AgentComponentConfigSchema
133
- } from "./shared/@ai-setting/roy-agent-core-1bvv6s75.js";
133
+ } from "./shared/@ai-setting/roy-agent-core-fvkyv5j6.js";
134
134
  import {
135
135
  createInvokeConfig,
136
136
  invoke,
@@ -141,7 +141,7 @@ import {
141
141
  ToolComponent,
142
142
  ToolRegistry,
143
143
  ToolValidator
144
- } from "./shared/@ai-setting/roy-agent-core-zs31w092.js";
144
+ } from "./shared/@ai-setting/roy-agent-core-9nhwdq9r.js";
145
145
  import"./shared/@ai-setting/roy-agent-core-5h49ct1a.js";
146
146
  import {
147
147
  AskUserError,
@@ -149,11 +149,11 @@ import {
149
149
  } from "./shared/@ai-setting/roy-agent-core-e25xkv53.js";
150
150
  import {
151
151
  TaskComponent
152
- } from "./shared/@ai-setting/roy-agent-core-dntkpwqq.js";
152
+ } from "./shared/@ai-setting/roy-agent-core-fwxqevpf.js";
153
153
  import"./shared/@ai-setting/roy-agent-core-amkqnyzy.js";
154
154
  import"./shared/@ai-setting/roy-agent-core-8gxth0eh.js";
155
- import"./shared/@ai-setting/roy-agent-core-7a3gf3tw.js";
156
- import"./shared/@ai-setting/roy-agent-core-pzeexnhf.js";
155
+ import"./shared/@ai-setting/roy-agent-core-wpw37qqf.js";
156
+ import"./shared/@ai-setting/roy-agent-core-nv4yfy3m.js";
157
157
  import {
158
158
  SQLiteTaskStore,
159
159
  getDefaultTaskDbPath
@@ -161,11 +161,11 @@ import {
161
161
  import {
162
162
  getBuiltInPrompt,
163
163
  getBuiltInPromptNames
164
- } from "./shared/@ai-setting/roy-agent-core-ms5dp89r.js";
164
+ } from "./shared/@ai-setting/roy-agent-core-apz6v22z.js";
165
165
  import"./shared/@ai-setting/roy-agent-core-c1v263jn.js";
166
166
  import {
167
167
  AgentRegistry
168
- } from "./shared/@ai-setting/roy-agent-core-3bdpnmtg.js";
168
+ } from "./shared/@ai-setting/roy-agent-core-v5nknfh0.js";
169
169
  import {
170
170
  XDG_PATHS,
171
171
  getXDGPath,
@@ -223,6 +223,7 @@ import {
223
223
  Traced,
224
224
  TracedAs,
225
225
  TracedLightweight,
226
+ init_decorator,
226
227
  wrapFunction
227
228
  } from "./shared/@ai-setting/roy-agent-core-fdm579b1.js";
228
229
  import {
@@ -230,6 +231,7 @@ import {
230
231
  getLogDir,
231
232
  getLogLevel,
232
233
  getLogLevels,
234
+ init_logger,
233
235
  isQuietMode,
234
236
  setConfigComponent,
235
237
  setLogDirOverride,
@@ -247,6 +249,114 @@ import {
247
249
  SQLiteSpanStorage
248
250
  } from "./shared/@ai-setting/roy-agent-core-c6592r3c.js";
249
251
  import"./shared/@ai-setting/roy-agent-core-fs0mn2jk.js";
252
+ // src/env/session-tree-stopper.ts
253
+ init_decorator();
254
+ init_logger();
255
+ var logger = createLogger("SessionTreeStopper");
256
+ var inflightCascades = new Map;
257
+ async function safeStage(stage, fn, fallback, errors) {
258
+ try {
259
+ return await fn();
260
+ } catch (err) {
261
+ const msg = err instanceof Error ? err.message : String(err);
262
+ const stack = err instanceof Error ? err.stack : undefined;
263
+ errors.push({ stage, error: msg, stack });
264
+ logger.warn(`[SessionTreeStopper] ${stage} failed: ${msg}`);
265
+ return fallback;
266
+ }
267
+ }
268
+ function cascadeStopSessionTreeImpl(env, parentSessionId, opts = {}) {
269
+ const force = !!opts.force;
270
+ if (!parentSessionId) {
271
+ return Promise.resolve({
272
+ stoppedTaskIds: [],
273
+ stoppedWorkflowSessionIds: [],
274
+ force: false,
275
+ errors: []
276
+ });
277
+ }
278
+ const existing = inflightCascades.get(parentSessionId);
279
+ if (existing) {
280
+ if (force)
281
+ existing.forceTriggered = true;
282
+ return existing.promise;
283
+ }
284
+ const state = {
285
+ promise: undefined,
286
+ forceTriggered: force,
287
+ firstCallForce: force
288
+ };
289
+ state.promise = (async () => {
290
+ const result = {
291
+ stoppedTaskIds: [],
292
+ stoppedWorkflowSessionIds: [],
293
+ force,
294
+ errors: []
295
+ };
296
+ if (!env) {
297
+ return result;
298
+ }
299
+ return runCascadeStages(env, parentSessionId, state, result);
300
+ })();
301
+ inflightCascades.set(parentSessionId, state);
302
+ state.promise.finally(() => {
303
+ inflightCascades.delete(parentSessionId);
304
+ });
305
+ return state.promise;
306
+ }
307
+ async function runCascadeStages(env, parentSessionId, state, result) {
308
+ const taskResult = await safeStage("task.stopAllForParent", async () => {
309
+ const taskComp = env.getComponent?.("task");
310
+ const legacyMgr = taskComp?.backgroundTaskManager;
311
+ const mgr = taskComp?.getBackgroundTaskManager?.() ?? (legacyMgr?.stopAllForParent ? legacyMgr : undefined);
312
+ if (!mgr || typeof mgr.stopAllForParent !== "function") {
313
+ return { stoppedTaskIds: [] };
314
+ }
315
+ return await mgr.stopAllForParent(parentSessionId);
316
+ }, { stoppedTaskIds: [] }, result.errors);
317
+ result.stoppedTaskIds = taskResult.stoppedTaskIds ?? [];
318
+ const workflowResult = await safeStage("workflow.stopAllForParent", async () => {
319
+ const workflowComp = env.getComponent?.("workflow");
320
+ const svc = workflowComp?.workflowService;
321
+ if (!svc || typeof svc.stopAllForParent !== "function") {
322
+ return { stoppedSessionIds: [] };
323
+ }
324
+ return await svc.stopAllForParent(parentSessionId);
325
+ }, { stoppedSessionIds: [] }, result.errors);
326
+ result.stoppedWorkflowSessionIds = workflowResult.stoppedSessionIds ?? [];
327
+ if (Array.isArray(workflowResult.errors)) {
328
+ for (const e of workflowResult.errors) {
329
+ result.errors.push({
330
+ stage: "workflow.stopAllForParent",
331
+ error: `${e.sessionId}: ${e.error}`,
332
+ stack: e.stack
333
+ });
334
+ }
335
+ }
336
+ if (state.forceTriggered) {
337
+ result.force = state.firstCallForce || true;
338
+ await safeStage("task.forceStopAll", async () => {
339
+ const taskComp = env.getComponent?.("task");
340
+ const mgr = taskComp?.backgroundTaskManager;
341
+ if (!mgr || typeof mgr.forceStopAll !== "function")
342
+ return;
343
+ await mgr.forceStopAll();
344
+ }, undefined, result.errors);
345
+ await safeStage("workflow.forceStopAll", async () => {
346
+ const workflowComp = env.getComponent?.("workflow");
347
+ const svc = workflowComp?.workflowService;
348
+ if (!svc || typeof svc.forceStopAll !== "function")
349
+ return;
350
+ await svc.forceStopAll();
351
+ }, undefined, result.errors);
352
+ }
353
+ return result;
354
+ }
355
+ var cascadeStopSessionTree = wrapFunction(cascadeStopSessionTreeImpl, "session.tree.cascadeStop", {
356
+ recordParams: true,
357
+ recordResult: true,
358
+ log: true
359
+ });
250
360
  // src/env/memory/tools/memory-agent-tools.ts
251
361
  import { z } from "zod";
252
362
  var SearchSessionsSchema = z.object({
@@ -424,6 +534,7 @@ export {
424
534
  createHook,
425
535
  createAutoTaskPlugin,
426
536
  closeDatabase,
537
+ cascadeStopSessionTree,
427
538
  builtInHandlers,
428
539
  buildDefaultBountyIMSystemPrompt,
429
540
  bountyIMHandler,
@@ -343,6 +343,14 @@ var init_agent_component_adapter = __esm(() => {
343
343
  } catch {}
344
344
  }
345
345
  context.additionInfo = additionInfo;
346
+ const ctxScope = config.cancellationScope;
347
+ if (ctxScope && typeof ctxScope.onForce === "function") {
348
+ ctxScope.onForce("agent-component-adapter-force", () => {
349
+ if (deadlineController && !deadlineController.signal.aborted) {
350
+ deadlineController.abort("force");
351
+ }
352
+ });
353
+ }
346
354
  const result = await this.agentComponent.run(config.type || "general", userInput, context);
347
355
  if (result.error?.startsWith("__ASK_USER_ERROR__:")) {
348
356
  const jsonStr = result.error.substring("__ASK_USER_ERROR__:".length);
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  AgentComponentAdapter,
3
3
  init_agent_component_adapter
4
- } from "./roy-agent-core-jenchn33.js";
4
+ } from "./roy-agent-core-24rmf17n.js";
5
5
  import"./roy-agent-core-1db4vpc6.js";
6
6
  import"./roy-agent-core-e25xkv53.js";
7
7
  import"./roy-agent-core-dbkkjmqz.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  builtInPrompts
3
- } from "./roy-agent-core-ms5dp89r.js";
3
+ } from "./roy-agent-core-apz6v22z.js";
4
4
  import {
5
5
  getXDGPath
6
6
  } from "./roy-agent-core-qxnbvgwe.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  DAGManager,
3
3
  init_dag_manager
4
- } from "./roy-agent-core-4yq23m5g.js";
4
+ } from "./roy-agent-core-mmb9484f.js";
5
5
 
6
6
  // src/env/workflow/utils/validate-workflow-definition.ts
7
7
  init_dag_manager();
@@ -1073,68 +1073,109 @@ When reusing an existing task, you MUST follow these rules:
1073
1073
  # 输出要求
1074
1074
  直接调用 write_memory 工具,写入新的全局记忆。
1075
1075
  输出格式为 Markdown,保持结构清晰。`,
1076
- "workflow-runner": `# Workflow Runner (workflow 执行子代理)
1076
+ "workflow-runner": `# Workflow Runnerworkflow 执行 + prompt-driven 失败接管)
1077
1077
 
1078
- ## 你的身份
1079
-
1080
- 你是 Roy 系统的 **workflow-runner** 子代理 (type=sub).
1081
- 调用你的 parent agent 会告诉你: 要运行哪个 workflow + 任务上下文.
1078
+ ## 身份与输入
1082
1079
 
1083
- ## 你的输入 (parent agent 会提供)
1080
+ 你是 Roy 的 **workflow-runner** 子代理(type=sub)。parent agent 会提供:
1084
1081
 
1085
1082
  \`\`\`
1086
1083
  <workflow_name>{WORKFLOW_NAME}</workflow_name>
1087
1084
  <task_description>{TASK_DESCRIPTION}</task_description>
1088
1085
  <original_prompt>{ORIGINAL_PROMPT}</original_prompt>
1086
+ <existing_sub_session_id?>{EXISTING_SUB_SESSION_ID}</existing_sub_session_id>
1089
1087
  \`\`\`
1090
1088
 
1091
- **重要**: workflow 名严格从 \`<workflow_name>\` 标签解析, 不要从上下文猜测.
1092
- 用法: \`prompt.match(/<workflow_name>([^<]+)<\\/workflow_name>/)?.[1]\`
1089
+ workflow 名必须从 \`<workflow_name>\` 标签读取,不得根据上下文猜测。
1090
+
1091
+ ## 可用工具
1093
1092
 
1094
- ## 你的工具 (5 个, 白名单强制)
1093
+ ### Workflow 工具
1095
1094
 
1096
1095
  | 工具 | 用途 |
1097
- |------|------|
1098
- | workflow_get | workflow 定义 (schema, 节点) |
1099
- | workflow_list | 列已注册 workflow |
1100
- | workflow_run | 启动 workflow (同步阻塞至完成) |
1101
- | workflow_run_status | run 状态 (resume 前必查) |
1102
- | workflow_run_stop | 停止 run (清理资源) |
1096
+ |---|---|
1097
+ | workflow_get | 读取真实 workflow 定义、输入 schema、节点与依赖 |
1098
+ | workflow_list | 列出已注册 workflow |
1099
+ | workflow_run | 启动或恢复 workflow |
1100
+ | workflow_run_status | 查询原 run_id 的真实状态与节点进度 |
1101
+ | workflow_run_stop | 按要求停止 run |
1103
1102
 
1104
- ## 核心流程
1103
+ ### 通用 ReAct 工具
1105
1104
 
1106
- 1. 解析 \`<workflow_name>\` → 得到 workflow 名 (例: \`strict-task-agent\`)
1107
- 2. \`workflow_get(<workflow_name>)\` 取 schema
1108
- 3. 从 \`<original_prompt>\` 提取符合 schema 的 input
1109
- 4. \`workflow_run(<workflow_name>, input)\` 启动 (同步阻塞)
1110
- 5. 把 output 原样回给 parent agent
1105
+ 接管时可用 \`bash\`、\`read_file\`、\`write_file\`、\`edit_file\`、\`grep\`、\`glob\`,
1106
+ 以及 \`task_create\`、\`task_update\`、\`task_operation_create\`、\`task_complete\`、
1107
+ \`recall_memory\`、\`record_memory\`。优先用内置工具获取证据并完成节点要求。
1111
1108
 
1112
- ## ⚡ Session Resume (重要, 长时间 workflow 必备)
1109
+ ### 禁止工具
1113
1110
 
1114
- 如果 parent agent 传了 \`existing_sub_session_id\` (= 之前的 runId),
1115
- **不要**重新跑 fresh workflow_run. 而是:
1111
+ - \`delegate_task\`:禁止递归委托,避免代理栈失控。
1112
+ - \`stop_task\`:禁止误杀 parent session。
1116
1113
 
1117
- \`\`\`bash
1118
- # 恢复之前的 run (runId 既是 run id 又是 session id)
1119
- roy-agent workflow run strict-task-agent -s workflow_run_1783407282099_1_ah8pho --input '{"task_id": 2164}'
1120
- \`\`\`
1114
+ ## 默认 workflow-run 模式
1115
+
1116
+ 1. \`workflow_get(name)\`,确认 input schema、节点描述和 DAG 依赖。
1117
+ 2. 从 original_prompt 提取合法 input。
1118
+ 3. 没有 existing_sub_session_id 时调用 fresh \`workflow_run\`;有该 ID 时先调
1119
+ \`workflow_run_status(run_id)\`,再以同一 ID 作为 session 恢复。runId == sessionId。
1120
+
1121
+ Copy-paste CLI 示例:
1122
+ \`roy-agent workflow run roy-rd-with-trace -s workflow_run_1783407282099_1_ah8pho\`
1123
+ 4. 对 \`completed\` / \`paused\` 返回真实 output;对 \`running\` / \`stopped\` 按真实状态报告。
1124
+ 5. 对每次 \`failed\` / \`timeout\`,扫描你自己最近的 workflow_run tool results,推理连续失败次数。
1125
+
1126
+ ## 连续 2 次失败阈值(由 LLM 自行推理)
1127
+
1128
+ 接管不依赖 runtime Map、counter 或 execution hook。你必须检查自己最近两次
1129
+ \`workflow_run\` tool result:只有两次连续为 \`status: "failed"\` 或 \`status: "timeout"\`
1130
+ 时才接管。未达到连续 2 次时,可以针对同一 run_id 恢复一次;成功结果会中断连续失败序列。
1121
1131
 
1122
- 或编程方式:
1123
- \`\`\`ts
1124
- workflow_run({ workflow_name: "strict-task-agent", session: "workflow_run_1783..._1_abc" })
1132
+ ## 接管流程(严格顺序)
1133
+
1134
+ 达到阈值后,**接管后不再调 workflow_run**,并依次执行:
1135
+
1136
+ 1. 调 \`workflow_run_status(original_run_id)\`,读取真实 run 状态、失败节点和已完成节点。
1137
+ 2. 调 \`workflow_get(name)\`,读取真实 workflow 定义、节点 description 与 DAG 依赖。
1138
+ 3. 将每个**节点描述视为 skill spec**:严格遵守其目标、输入输出契约、依赖和验证要求。
1139
+ 4. 已成功 phase 不重复;失败节点必须从该节点自身要求重新执行,而不是从首节点重跑。
1140
+ 5. 后续节点必须按 DAG/phase 依赖顺序推进,不得在失败节点修复及验证前执行后继节点。
1141
+ 6. 使用通用 ReAct 工具完成节点,并收集命令、文件、测试、构建、trace 等验证证据。
1142
+ 7. 无法完成的事项不得隐藏,必须列入 unfinished_items。
1143
+
1144
+ ## 禁止伪造 workflow engine 成功
1145
+
1146
+ - 禁止把人工 ReAct 接管描述成 workflow engine 的 \`completed\` 或正常 workflow_run success。
1147
+ - 禁止改写、伪造或猜测 engine 状态;状态只能来自 \`workflow_run_status\`。
1148
+ - fallback 证据块不是 workflow output,必须与 engine 原始状态明确区分。
1149
+
1150
+ ## 最终 fallback 证据输出契约
1151
+
1152
+ 接管后的最终回答必须包含完整证据块:
1153
+
1154
+ \`\`\`
1155
+ ===FALLBACK_TAKEOVER===
1156
+ takeover: true
1157
+ original_run_id: <原始 workflow run_id>
1158
+ workflow_name: <workflow 名>
1159
+ failed_node: <失败节点 id 或 phase>
1160
+ react_completed_nodes: [<人工 ReAct 完成的节点>]
1161
+ verification_evidence: |
1162
+ <逐项测试、构建、CLI、trace 或文件证据>
1163
+ unfinished_items: [<仍未完成的事项;无则 []>]
1164
+ ===END_FALLBACK_TAKEOVER===
1125
1165
  \`\`\`
1126
1166
 
1127
- > **关键**: runId == sessionId. 同一个 ID 既用于 \`workflow_run_status\` 查询,
1128
- > 也用于 \`-s\` resume. 不要混淆.
1167
+ ## 终止与防递归规则
1129
1168
 
1130
- ## 严格约束
1169
+ 接管不可再触发接管。进入接管模式后保持该模式,输出证据块后立即退出;
1170
+ 不得再次调用 workflow_run,也不得再次以“连续失败 2 次”为由嵌套接管。
1171
+
1172
+ ## 最终检查
1131
1173
 
1132
- - 只用 5 个 workflow_* 工具
1133
- - ✅ 先 schema 后 input 后 run
1134
- - 不要直接读 workflow YAML 文件自己解释
1135
- - 不要 delegate_task 再委托 (deniedTools 已禁)
1136
- - 不要 bash / 其他工具
1137
- `,
1174
+ - workflow_run_status workflow_get 均已调用,并以真实返回为依据。
1175
+ - 节点目标、输入输出、依赖和验证要求均已遵守。
1176
+ - 已成功 phase 未重复,失败节点和后续 DAG 顺序正确。
1177
+ - 未伪造 workflow engine 成功,证据块字段完整。
1178
+ - deniedTools 中的 delegate_task / stop_task 从未调用。`,
1138
1179
  "json-extract": `# JSON Extract Agent
1139
1180
 
1140
1181
  你是一个 JSON 提取子智能体。**唯一职责**:从父 session 的对话历史中提取最终答案,通过 \`workflow_submit_output\` 工具调用提交结构化 JSON(最多 5 次)。
@@ -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-3bdpnmtg.js";
13
+ } from "./roy-agent-core-v5nknfh0.js";
14
14
  import {
15
15
  ContextError
16
16
  } from "./roy-agent-core-ctdhjv68.js";
@@ -8,7 +8,7 @@ import {
8
8
  BackgroundTaskManager,
9
9
  createDelegateTool,
10
10
  createStopTool
11
- } from "./roy-agent-core-7a3gf3tw.js";
11
+ } from "./roy-agent-core-wpw37qqf.js";
12
12
  import {
13
13
  SQLiteTaskStore,
14
14
  getDefaultTaskDbPath
@@ -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({
@@ -68,7 +68,7 @@ function parseWorkflowFileSync(content, filename) {
68
68
  definition
69
69
  };
70
70
  }
71
- var DependsOnSchema, RetryConfigSchema, NodeDefinitionSchema, WorkflowConfigSchema, OutputDefinitionSchema, InputParameterSchema, WorkflowInputsSchema, WorkflowMetadataSchema, WorkflowDefinitionSchema, yamlParser = null;
71
+ var DependsOnSchema, RetryConfigSchema, LoopGuardConfigSchema, NodeDefinitionSchema, WorkflowConfigSchema, OutputDefinitionSchema, InputParameterSchema, WorkflowInputsSchema, WorkflowMetadataSchema, WorkflowDefinitionSchema, yamlParser = null;
72
72
  var init_workflow = __esm(() => {
73
73
  init_edge();
74
74
  DependsOnSchema = z2.array(z2.string());
@@ -77,6 +77,14 @@ var init_workflow = __esm(() => {
77
77
  backoff: z2.enum(["fixed", "exponential"]).default("exponential"),
78
78
  initial_delay: z2.number().min(0).default(1000)
79
79
  });
80
+ LoopGuardConfigSchema = z2.object({
81
+ type: z2.literal("value_unchanged"),
82
+ previous_signal: z2.string().min(1, "previous_signal must be a non-empty template path"),
83
+ current_signal_command: z2.string().min(1, "current_signal_command must be a non-empty shell command"),
84
+ cwd: z2.string().optional(),
85
+ max_consecutive_no_progress: z2.number().int().min(1).default(1),
86
+ fail_message: z2.string().optional()
87
+ });
80
88
  NodeDefinitionSchema = z2.object({
81
89
  id: z2.string().min(1, "Node ID is required"),
82
90
  type: z2.string().min(1, "Node type is required"),
@@ -86,6 +94,29 @@ var init_workflow = __esm(() => {
86
94
  condition: z2.string().optional(),
87
95
  retry: RetryConfigSchema.optional(),
88
96
  timeout: z2.number().optional()
97
+ }).superRefine((value, ctx) => {
98
+ const config = value.config ?? {};
99
+ if (Object.prototype.hasOwnProperty.call(config, "loop_guard")) {
100
+ const parsed = LoopGuardConfigSchema.safeParse(config.loop_guard);
101
+ if (!parsed.success) {
102
+ for (const issue of parsed.error.issues) {
103
+ ctx.addIssue({
104
+ code: z2.ZodIssueCode.custom,
105
+ path: ["config", "loop_guard", ...issue.path ?? []],
106
+ message: issue.message
107
+ });
108
+ }
109
+ }
110
+ }
111
+ }).transform((value) => {
112
+ const config = value.config ?? {};
113
+ if (Object.prototype.hasOwnProperty.call(config, "loop_guard")) {
114
+ const parsed = LoopGuardConfigSchema.safeParse(config.loop_guard);
115
+ if (parsed.success) {
116
+ value.config = { ...config, loop_guard: parsed.data };
117
+ }
118
+ }
119
+ return value;
89
120
  });
90
121
  WorkflowConfigSchema = z2.object({
91
122
  parallel_limit: z2.number().nullable().optional(),
@@ -438,4 +469,4 @@ var init_types = __esm(() => {
438
469
  init_run();
439
470
  });
440
471
 
441
- export { BaseEventSchema, WorkflowStartedEventSchema, WorkflowPausedEventSchema, WorkflowResumedEventSchema, WorkflowStoppedEventSchema, WorkflowCompletedEventSchema, WorkflowFailedEventSchema, WorkflowOutputEventSchema, NodeScheduledEventSchema, NodeStartedEventSchema, NodeProgressEventSchema, NodeCompletedEventSchema, NodeFailedEventSchema, NodeSkippedEventSchema, NodeDataEventSchema, NodeAddedEventSchema, NodeRemovedEventSchema, ControlPauseEventSchema, ControlResumeEventSchema, ControlStopEventSchema, NodeInterruptEventSchema, WorkflowAskUserEventSchema, WorkflowEventSchema, createWorkflowEvent, init_event, EdgeDefinitionSchema, DependsOnSchema, RetryConfigSchema, NodeDefinitionSchema, WorkflowConfigSchema, OutputDefinitionSchema, InputParameterSchema, WorkflowInputsSchema, WorkflowMetadataSchema, WorkflowDefinitionSchema, parseWorkflowFile, parseWorkflowFileSync, WorkflowMessageRoleSchema, isWorkflowSessionMetadata, getWorkflowSessionStatus, RunStatusSchema, NodeStatusSchema, createNodeExecutionContext, WorkflowError, TemplateUnresolvedError, WorkflowValidationError, nodeNotFound, pathNotFound, unresolvedVariable, init_workflow_error, init_types };
472
+ export { EdgeDefinitionSchema, DependsOnSchema, RetryConfigSchema, LoopGuardConfigSchema, NodeDefinitionSchema, WorkflowConfigSchema, OutputDefinitionSchema, InputParameterSchema, WorkflowInputsSchema, WorkflowMetadataSchema, WorkflowDefinitionSchema, parseWorkflowFile, parseWorkflowFileSync, WorkflowMessageRoleSchema, isWorkflowSessionMetadata, getWorkflowSessionStatus, BaseEventSchema, WorkflowStartedEventSchema, WorkflowPausedEventSchema, WorkflowResumedEventSchema, WorkflowStoppedEventSchema, WorkflowCompletedEventSchema, WorkflowFailedEventSchema, WorkflowOutputEventSchema, NodeScheduledEventSchema, NodeStartedEventSchema, NodeProgressEventSchema, NodeCompletedEventSchema, NodeFailedEventSchema, NodeSkippedEventSchema, NodeDataEventSchema, NodeAddedEventSchema, NodeRemovedEventSchema, ControlPauseEventSchema, ControlResumeEventSchema, ControlStopEventSchema, NodeInterruptEventSchema, WorkflowAskUserEventSchema, WorkflowEventSchema, createWorkflowEvent, init_event, RunStatusSchema, NodeStatusSchema, createNodeExecutionContext, WorkflowError, TemplateUnresolvedError, WorkflowValidationError, nodeNotFound, pathNotFound, unresolvedVariable, init_workflow_error, init_types };
@@ -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-80e4a3g5.js";
7
7
  import {
8
8
  WORKFLOW_EXTRACT_PROMPT
9
- } from "./roy-agent-core-ms5dp89r.js";
9
+ } from "./roy-agent-core-apz6v22z.js";
10
10
  import {
11
11
  TaskHookPoints
12
12
  } from "./roy-agent-core-1pg0fepg.js";