@ai-setting/roy-agent-core 1.7.52 → 1.7.53

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 (334) hide show
  1. package/dist/config/config-component.d.ts +346 -0
  2. package/dist/config/config-parser.d.ts +45 -0
  3. package/dist/config/env-key.d.ts +97 -0
  4. package/dist/config/env-source.d.ts +113 -0
  5. package/dist/config/file-source.d.ts +90 -0
  6. package/dist/config/index.d.ts +4 -0
  7. package/dist/config/protocol-resolver.d.ts +94 -0
  8. package/dist/env/agent/agent-component.d.ts +646 -0
  9. package/dist/env/agent/agent-config-registration.d.ts +18 -0
  10. package/dist/env/agent/agent-registry.d.ts +500 -0
  11. package/dist/env/agent/index.d.ts +9 -0
  12. package/dist/env/agent/summary-agent.d.ts +44 -0
  13. package/dist/env/agent/types.d.ts +503 -0
  14. package/dist/env/commands/commands-component.d.ts +97 -0
  15. package/dist/env/commands/commands-config-registration.d.ts +19 -0
  16. package/dist/env/commands/index.d.ts +7 -0
  17. package/dist/env/commands/parser.d.ts +18 -0
  18. package/dist/env/commands/types.d.ts +133 -0
  19. package/dist/env/component.d.ts +186 -0
  20. package/dist/env/constants.d.ts +112 -0
  21. package/dist/env/context/env-context.d.ts +420 -0
  22. package/dist/env/context/env-event.d.ts +144 -0
  23. package/dist/env/context/index.d.ts +13 -0
  24. package/dist/env/debug/debug-component.d.ts +160 -0
  25. package/dist/env/debug/formatters/index.d.ts +8 -0
  26. package/dist/env/debug/formatters/repl-formatter.d.ts +80 -0
  27. package/dist/env/debug/formatters/trace-formatter.d.ts +43 -0
  28. package/dist/env/debug/formatters/tree-formatter.d.ts +72 -0
  29. package/dist/env/debug/index.d.ts +15 -0
  30. package/dist/env/debug/index.js +1 -1
  31. package/dist/env/debug/parser/regex-parser.d.ts +49 -0
  32. package/dist/env/debug/parser/span-builder.d.ts +79 -0
  33. package/dist/env/debug/reader/log-reader.d.ts +55 -0
  34. package/dist/env/debug/reader/span-db-reader.d.ts +70 -0
  35. package/dist/env/debug/types.d.ts +145 -0
  36. package/dist/env/environment.d.ts +185 -0
  37. package/dist/env/errors.d.ts +120 -0
  38. package/dist/env/event-source/bounty-cli-handler.d.ts +42 -0
  39. package/dist/env/event-source/bounty-im-handler.d.ts +232 -0
  40. package/dist/env/event-source/event-source-component.d.ts +177 -0
  41. package/dist/env/event-source/event-source-config-registration.d.ts +18 -0
  42. package/dist/env/event-source/event-source-handlers.d.ts +486 -0
  43. package/dist/env/event-source/event-store.d.ts +110 -0
  44. package/dist/env/event-source/idempotency-key.d.ts +19 -0
  45. package/dist/env/event-source/index.d.ts +15 -0
  46. package/dist/env/event-source/index.js +2 -2
  47. package/dist/env/event-source/timer-handler.d.ts +74 -0
  48. package/dist/env/event-source/types.d.ts +803 -0
  49. package/dist/env/hook/global-hook-manager.d.ts +73 -0
  50. package/dist/env/hook/hook-manager.d.ts +139 -0
  51. package/dist/env/hook/index.d.ts +9 -0
  52. package/dist/env/hook/types.d.ts +107 -0
  53. package/dist/env/index.d.ts +24 -0
  54. package/dist/env/index.js +4 -4
  55. package/dist/env/interface.d.ts +156 -0
  56. package/dist/env/lark-mention-utils.d.ts +59 -0
  57. package/dist/env/llm/adapter-ai-sdk.d.ts +10 -0
  58. package/dist/env/llm/adapter-pi-ai.d.ts +39 -0
  59. package/dist/env/llm/adapter.d.ts +80 -0
  60. package/dist/env/llm/factory.d.ts +13 -0
  61. package/dist/env/llm/hooks.d.ts +150 -0
  62. package/dist/env/llm/index.d.ts +16 -0
  63. package/dist/env/llm/invoke.d.ts +264 -0
  64. package/dist/env/llm/llm-cache.d.ts +38 -0
  65. package/dist/env/llm/llm.d.ts +238 -0
  66. package/dist/env/llm/opencode-session.d.ts +79 -0
  67. package/dist/env/llm/provider.d.ts +40 -0
  68. package/dist/env/llm/tool-args-parser.d.ts +77 -0
  69. package/dist/env/llm/tool-schema.d.ts +54 -0
  70. package/dist/env/llm/transform.d.ts +57 -0
  71. package/dist/env/llm/types.d.ts +818 -0
  72. package/dist/env/log-trace/decorator.d.ts +88 -0
  73. package/dist/env/log-trace/index.d.ts +14 -0
  74. package/dist/env/log-trace/log-trace-component.d.ts +268 -0
  75. package/dist/env/log-trace/log-trace-config-registration.d.ts +25 -0
  76. package/dist/env/log-trace/logger.d.ts +83 -0
  77. package/dist/env/log-trace/opentelemetry/cli-propagation.d.ts +105 -0
  78. package/dist/env/log-trace/opentelemetry/mod.d.ts +24 -0
  79. package/dist/env/log-trace/opentelemetry/propagation-env.d.ts +81 -0
  80. package/dist/env/log-trace/opentelemetry/propagation.d.ts +79 -0
  81. package/dist/env/log-trace/opentelemetry/tracer-provider.d.ts +157 -0
  82. package/dist/env/log-trace/span-storage.d.ts +37 -0
  83. package/dist/env/log-trace/trace-context.d.ts +28 -0
  84. package/dist/env/log-trace/types.d.ts +127 -0
  85. package/dist/env/mcp/command-resolver.d.ts +12 -0
  86. package/dist/env/mcp/config.d.ts +103 -0
  87. package/dist/env/mcp/index.d.ts +13 -0
  88. package/dist/env/mcp/loader.d.ts +78 -0
  89. package/dist/env/mcp/mcp-component.d.ts +54 -0
  90. package/dist/env/mcp/mcp-config-registration.d.ts +19 -0
  91. package/dist/env/mcp/npm-prefix/index.d.ts +17 -0
  92. package/dist/env/mcp/scanner.d.ts +38 -0
  93. package/dist/env/mcp/tool/adapter.d.ts +32 -0
  94. package/dist/env/mcp/tool/index.d.ts +4 -0
  95. package/dist/env/mcp/types.d.ts +131 -0
  96. package/dist/env/memory/built-in/index.d.ts +41 -0
  97. package/dist/env/memory/built-in/recall-memory.d.ts +29 -0
  98. package/dist/env/memory/built-in/record-memory.d.ts +44 -0
  99. package/dist/env/memory/index.d.ts +10 -0
  100. package/dist/env/memory/memory-component.d.ts +114 -0
  101. package/dist/env/memory/memory-config-registration.d.ts +18 -0
  102. package/dist/env/memory/memory-config.d.ts +18 -0
  103. package/dist/env/memory/plugin/index.d.ts +16 -0
  104. package/dist/env/memory/plugin/memory-agent.d.ts +126 -0
  105. package/dist/env/memory/plugin/memory-manager.d.ts +71 -0
  106. package/dist/env/memory/plugin/memory-plugin.d.ts +103 -0
  107. package/dist/env/memory/plugin/recall-memory.d.ts +16 -0
  108. package/dist/env/memory/plugin/types.d.ts +75 -0
  109. package/dist/env/memory/tools/memory-agent-tools.d.ts +109 -0
  110. package/dist/env/memory/types.d.ts +80 -0
  111. package/dist/env/paths.d.ts +46 -0
  112. package/dist/env/plugin/bounty-cli-notification-channel.d.ts +60 -0
  113. package/dist/env/plugin/event-bus-notification-channel.d.ts +50 -0
  114. package/dist/env/plugin/index.d.ts +13 -0
  115. package/dist/env/plugin/lark-cli-notification-channel.d.ts +61 -0
  116. package/dist/env/plugin/notification-channel.d.ts +143 -0
  117. package/dist/env/plugin/plugin-component.d.ts +232 -0
  118. package/dist/env/plugin/types.d.ts +146 -0
  119. package/dist/env/prompt/index.d.ts +7 -0
  120. package/dist/env/prompt/prompt-component.d.ts +194 -0
  121. package/dist/env/prompt/prompt-config-registration.d.ts +18 -0
  122. package/dist/env/prompt/prompt-store.d.ts +26 -0
  123. package/dist/env/prompt/prompts-index.d.ts +146 -0
  124. package/dist/env/prompt/renderer.d.ts +21 -0
  125. package/dist/env/prompt/types.d.ts +176 -0
  126. package/dist/env/session/hooks.d.ts +14 -0
  127. package/dist/env/session/index.d.ts +19 -0
  128. package/dist/env/session/search-query-parser.d.ts +41 -0
  129. package/dist/env/session/session-component.d.ts +464 -0
  130. package/dist/env/session/session-config-registration.d.ts +18 -0
  131. package/dist/env/session/session-id.d.ts +26 -0
  132. package/dist/env/session/session-message-converter.d.ts +142 -0
  133. package/dist/env/session/session-store.d.ts +188 -0
  134. package/dist/env/session/storage/index.d.ts +5 -0
  135. package/dist/env/session/storage/memory.d.ts +119 -0
  136. package/dist/env/session/storage/sqlite.d.ts +108 -0
  137. package/dist/env/session/types.d.ts +705 -0
  138. package/dist/env/session-tree-stopper.d.ts +79 -0
  139. package/dist/env/skill/config.d.ts +13 -0
  140. package/dist/env/skill/index.d.ts +6 -0
  141. package/dist/env/skill/parser.d.ts +9 -0
  142. package/dist/env/skill/scanner.d.ts +25 -0
  143. package/dist/env/skill/skill-component.d.ts +89 -0
  144. package/dist/env/skill/skill-config-registration.d.ts +18 -0
  145. package/dist/env/skill/tool/index.d.ts +1 -0
  146. package/dist/env/skill/tool/skill-tool.d.ts +15 -0
  147. package/dist/env/skill/types.d.ts +61 -0
  148. package/dist/env/task/backend/index.d.ts +24 -0
  149. package/dist/env/task/backend/index.js +704 -0
  150. package/dist/env/task/backend/roy-sidecar-task-port.d.ts +148 -0
  151. package/dist/env/task/backend/sqlite-task-port.d.ts +28 -0
  152. package/dist/env/task/backend/task-store-backend.d.ts +107 -0
  153. package/dist/env/task/backend/types.d.ts +293 -0
  154. package/dist/env/task/delegate/bg-task-id-storage.d.ts +9 -0
  155. package/dist/env/task/delegate/delegate-tool.d.ts +681 -0
  156. package/dist/env/task/delegate/index.d.ts +8 -0
  157. package/dist/env/task/delegate/process-registry.d.ts +58 -0
  158. package/dist/env/task/delegate/stop-tool.d.ts +12 -0
  159. package/dist/env/task/delegate/subagent-resolver.d.ts +25 -0
  160. package/dist/env/task/events/index.d.ts +7 -0
  161. package/dist/env/task/events/task-event-payloads.d.ts +101 -0
  162. package/dist/env/task/events/task-event-types.d.ts +23 -0
  163. package/dist/env/task/hooks/contexts.d.ts +191 -0
  164. package/dist/env/task/hooks/index.d.ts +7 -0
  165. package/dist/env/task/hooks/task-hook-points.d.ts +42 -0
  166. package/dist/env/task/index.d.ts +7 -0
  167. package/dist/env/task/plugins/auto-task-plugin.d.ts +38 -0
  168. package/dist/env/task/plugins/card-chat-routing.d.ts +135 -0
  169. package/dist/env/task/plugins/fake-user-message-helper.d.ts +90 -0
  170. package/dist/env/task/plugins/index.d.ts +8 -0
  171. package/dist/env/task/plugins/index.js +1 -1
  172. package/dist/env/task/plugins/lark-card-action-handler.d.ts +166 -0
  173. package/dist/env/task/plugins/lark-card-patch-notifier.d.ts +651 -0
  174. package/dist/env/task/plugins/lark-cli-task-notify-plugin.d.ts +248 -0
  175. package/dist/env/task/plugins/max-iteration-reminder-plugin.d.ts +112 -0
  176. package/dist/env/task/plugins/per-task-group-chat-plugin.d.ts +561 -0
  177. package/dist/env/task/plugins/task-tag-plugin.d.ts +70 -0
  178. package/dist/env/task/plugins/workflow-extractor-agent.d.ts +43 -0
  179. package/dist/env/task/registry-hook-installer.d.ts +43 -0
  180. package/dist/env/task/storage/index.d.ts +5 -0
  181. package/dist/env/task/storage/migrations/001_add_project_path_context.d.ts +14 -0
  182. package/dist/env/task/storage/migrations/002_add_task_type.d.ts +14 -0
  183. package/dist/env/task/storage/migrations/003_add_process_description.d.ts +20 -0
  184. package/dist/env/task/storage/migrations/004_rename_action_to_milestone.d.ts +37 -0
  185. package/dist/env/task/storage/migrations/005_convert_blob_description_to_text.d.ts +51 -0
  186. package/dist/env/task/storage/sqlite-task-store.d.ts +241 -0
  187. package/dist/env/task/tag-service.d.ts +138 -0
  188. package/dist/env/task/task-child-context.d.ts +70 -0
  189. package/dist/env/task/task-component.d.ts +270 -0
  190. package/dist/env/task/task-config-registration.d.ts +19 -0
  191. package/dist/env/task/task-creation-registry.d.ts +181 -0
  192. package/dist/env/task/task-reuse-context.d.ts +52 -0
  193. package/dist/env/task/task-reuse-registry.d.ts +31 -0
  194. package/dist/env/task/tools/batch-archive-tool.d.ts +9 -0
  195. package/dist/env/task/tools/batch-delete-tool.d.ts +9 -0
  196. package/dist/env/task/tools/complete-tool.d.ts +12 -0
  197. package/dist/env/task/tools/create-tool.d.ts +6 -0
  198. package/dist/env/task/tools/delete-tool.d.ts +6 -0
  199. package/dist/env/task/tools/get-tool.d.ts +6 -0
  200. package/dist/env/task/tools/index.d.ts +13 -0
  201. package/dist/env/task/tools/list-tool.d.ts +6 -0
  202. package/dist/env/task/tools/operation/create-tool.d.ts +12 -0
  203. package/dist/env/task/tools/operation/delete-tool.d.ts +6 -0
  204. package/dist/env/task/tools/operation/get-tool.d.ts +6 -0
  205. package/dist/env/task/tools/operation/index.d.ts +8 -0
  206. package/dist/env/task/tools/operation/list-tool.d.ts +6 -0
  207. package/dist/env/task/tools/operation/operation-types.d.ts +225 -0
  208. package/dist/env/task/tools/operation/update-tool.d.ts +6 -0
  209. package/dist/env/task/tools/search-tool.d.ts +9 -0
  210. package/dist/env/task/tools/task-tree-tool.d.ts +65 -0
  211. package/dist/env/task/tools/task-types.d.ts +255 -0
  212. package/dist/env/task/tools/update-tool.d.ts +6 -0
  213. package/dist/env/task/types.d.ts +290 -0
  214. package/dist/env/tool/built-in/bash-effect.d.ts +36 -0
  215. package/dist/env/tool/built-in/bash.d.ts +16 -0
  216. package/dist/env/tool/built-in/echo.d.ts +7 -0
  217. package/dist/env/tool/built-in/edit-file.d.ts +6 -0
  218. package/dist/env/tool/built-in/glob.d.ts +6 -0
  219. package/dist/env/tool/built-in/grep.d.ts +6 -0
  220. package/dist/env/tool/built-in/index.d.ts +39 -0
  221. package/dist/env/tool/built-in/query-background-process-tool.d.ts +113 -0
  222. package/dist/env/tool/built-in/read-file.d.ts +5 -0
  223. package/dist/env/tool/built-in/understand-image.d.ts +59 -0
  224. package/dist/env/tool/built-in/write-file.d.ts +5 -0
  225. package/dist/env/tool/index.d.ts +16 -0
  226. package/dist/env/tool/registry.d.ts +61 -0
  227. package/dist/env/tool/tool-component.d.ts +242 -0
  228. package/dist/env/tool/tool-config-registration.d.ts +18 -0
  229. package/dist/env/tool/types.d.ts +274 -0
  230. package/dist/env/tool/validator.d.ts +14 -0
  231. package/dist/env/types.d.ts +184 -0
  232. package/dist/env/workflow/decorators/decorator-node.d.ts +76 -0
  233. package/dist/env/workflow/decorators/edge.d.ts +42 -0
  234. package/dist/env/workflow/decorators/index.d.ts +13 -0
  235. package/dist/env/workflow/decorators/node-as.d.ts +40 -0
  236. package/dist/env/workflow/decorators/workflow.d.ts +30 -0
  237. package/dist/env/workflow/engine/dag-manager.d.ts +176 -0
  238. package/dist/env/workflow/engine/engine.d.ts +375 -0
  239. package/dist/env/workflow/engine/event-bus.d.ts +54 -0
  240. package/dist/env/workflow/engine/executor.d.ts +122 -0
  241. package/dist/env/workflow/engine/index.d.ts +15 -0
  242. package/dist/env/workflow/engine/node-registry.d.ts +159 -0
  243. package/dist/env/workflow/engine/scheduler.d.ts +164 -0
  244. package/dist/env/workflow/extractor/workflow-converter.d.ts +55 -0
  245. package/dist/env/workflow/fixtures.d.ts +401 -0
  246. package/dist/env/workflow/hooks/index.d.ts +4 -0
  247. package/dist/env/workflow/hooks/workflow-hook-points.d.ts +161 -0
  248. package/dist/env/workflow/index.d.ts +30 -0
  249. package/dist/env/workflow/index.js +1 -1
  250. package/dist/env/workflow/metadata/keys.d.ts +6 -0
  251. package/dist/env/workflow/nodes/agent-component-adapter.d.ts +175 -0
  252. package/dist/env/workflow/nodes/agent-node.d.ts +206 -0
  253. package/dist/env/workflow/nodes/ask-user-node.d.ts +66 -0
  254. package/dist/env/workflow/nodes/condition-node.d.ts +39 -0
  255. package/dist/env/workflow/nodes/index.d.ts +8 -0
  256. package/dist/env/workflow/nodes/merge-node.d.ts +40 -0
  257. package/dist/env/workflow/nodes/python-call-node.d.ts +95 -0
  258. package/dist/env/workflow/nodes/skill-node.d.ts +29 -0
  259. package/dist/env/workflow/nodes/tool-node.d.ts +58 -0
  260. package/dist/env/workflow/nodes/workflow-node.d.ts +118 -0
  261. package/dist/env/workflow/plugins/index.d.ts +6 -0
  262. package/dist/env/workflow/plugins/lark-cli-workflow-notify-plugin.d.ts +107 -0
  263. package/dist/env/workflow/plugins/workflow-json-output-plugin.d.ts +166 -0
  264. package/dist/env/workflow/runtime/runtime-cancellation-scope.d.ts +121 -0
  265. package/dist/env/workflow/service/index.d.ts +9 -0
  266. package/dist/env/workflow/service/registry.d.ts +37 -0
  267. package/dist/env/workflow/service/workflow-service.d.ts +422 -0
  268. package/dist/env/workflow/storage/index.d.ts +11 -0
  269. package/dist/env/workflow/storage/mock-repositories.d.ts +106 -0
  270. package/dist/env/workflow/storage/safe-json.d.ts +62 -0
  271. package/dist/env/workflow/storage/sqlite.d.ts +57 -0
  272. package/dist/env/workflow/storage/tag-repo.d.ts +65 -0
  273. package/dist/env/workflow/storage/workflow-repo.d.ts +161 -0
  274. package/dist/env/workflow/tools/ask-user-tool.d.ts +35 -0
  275. package/dist/env/workflow/tools/index.d.ts +16 -0
  276. package/dist/env/workflow/tools/run-workflow.d.ts +130 -0
  277. package/dist/env/workflow/tools/submit-json-output-tool.d.ts +38 -0
  278. package/dist/env/workflow/tools/workflow-add-tool.d.ts +47 -0
  279. package/dist/env/workflow/tools/workflow-get-tool.d.ts +29 -0
  280. package/dist/env/workflow/tools/workflow-list-tool.d.ts +55 -0
  281. package/dist/env/workflow/tools/workflow-run-status-tool.d.ts +26 -0
  282. package/dist/env/workflow/tools/workflow-run-stop-tool.d.ts +29 -0
  283. package/dist/env/workflow/tools/workflow-search-tool.d.ts +33 -0
  284. package/dist/env/workflow/tools/workflow-tag-list-tool.d.ts +59 -0
  285. package/dist/env/workflow/tools/workflow-validate-tool.d.ts +60 -0
  286. package/dist/env/workflow/types/context.d.ts +17 -0
  287. package/dist/env/workflow/types/decorators-types.d.ts +182 -0
  288. package/dist/env/workflow/types/edge.d.ts +33 -0
  289. package/dist/env/workflow/types/event.d.ts +869 -0
  290. package/dist/env/workflow/types/index.d.ts +16 -0
  291. package/dist/env/workflow/types/run.d.ts +235 -0
  292. package/dist/env/workflow/types/workflow-error.d.ts +79 -0
  293. package/dist/env/workflow/types/workflow-hil.d.ts +57 -0
  294. package/dist/env/workflow/types/workflow-message.d.ts +193 -0
  295. package/dist/env/workflow/types/workflow-session.d.ts +17 -0
  296. package/dist/env/workflow/types/workflow.d.ts +654 -0
  297. package/dist/env/workflow/types_compat.d.ts +10 -0
  298. package/dist/env/workflow/utils/agent-session-metadata.d.ts +35 -0
  299. package/dist/env/workflow/utils/build-agent-node-output.d.ts +11 -0
  300. package/dist/env/workflow/utils/create-workflow.d.ts +35 -0
  301. package/dist/env/workflow/utils/dependency-prescan.d.ts +67 -0
  302. package/dist/env/workflow/utils/execution-state.d.ts +46 -0
  303. package/dist/env/workflow/utils/extract-agent-json-output.d.ts +6 -0
  304. package/dist/env/workflow/utils/index.d.ts +14 -0
  305. package/dist/env/workflow/utils/json-schema-to-zod.d.ts +23 -0
  306. package/dist/env/workflow/utils/node-id-utils.d.ts +20 -0
  307. package/dist/env/workflow/utils/node-output-contracts.d.ts +137 -0
  308. package/dist/env/workflow/utils/node-registry-helper.d.ts +36 -0
  309. package/dist/env/workflow/utils/output-schema-hint.d.ts +7 -0
  310. package/dist/env/workflow/utils/parse-agent-output-config.d.ts +9 -0
  311. package/dist/env/workflow/utils/recovery-validator.d.ts +30 -0
  312. package/dist/env/workflow/utils/sensitive-redact.d.ts +37 -0
  313. package/dist/env/workflow/utils/session-parser.d.ts +23 -0
  314. package/dist/env/workflow/utils/session-recovery.d.ts +122 -0
  315. package/dist/env/workflow/utils/template-contract-validator.d.ts +87 -0
  316. package/dist/env/workflow/utils/template-resolver.d.ts +285 -0
  317. package/dist/env/workflow/utils/validate-workflow-definition.d.ts +57 -0
  318. package/dist/env/workflow/utils/validation-rules.d.ts +103 -0
  319. package/dist/env/workflow/utils/workflow-message-metadata.d.ts +20 -0
  320. package/dist/env/workflow/utils/workflow-sanitize.d.ts +51 -0
  321. package/dist/env/workflow/workflow-component.d.ts +138 -0
  322. package/dist/index.d.ts +59 -0
  323. package/dist/index.js +5 -5
  324. package/dist/shared/@ai-setting/{roy-agent-core-rcfewbzr.js → roy-agent-core-4sx6sdb2.js} +1 -1
  325. package/dist/shared/@ai-setting/{roy-agent-core-ezgsem94.js → roy-agent-core-ph5qbqcx.js} +1 -1
  326. package/dist/util/process/process-tree-killer.d.ts +67 -0
  327. package/dist/utils/id.d.ts +11 -0
  328. package/dist/utils/loose-json.d.ts +30 -0
  329. package/dist/utils/media.d.ts +70 -0
  330. package/dist/utils/temp-file-manager/index.d.ts +99 -0
  331. package/package.json +4 -2
  332. /package/dist/shared/@ai-setting/{roy-agent-core-s214vmmd.js → roy-agent-core-4vpk40ss.js} +0 -0
  333. /package/dist/shared/@ai-setting/{roy-agent-core-pkpkctvf.js → roy-agent-core-hch2geta.js} +0 -0
  334. /package/dist/shared/@ai-setting/{roy-agent-core-0cfaqnz9.js → roy-agent-core-k25gv86p.js} +0 -0
@@ -0,0 +1,681 @@
1
+ /**
2
+ * @fileoverview delegate_task Tool
3
+ *
4
+ * 基于 agent-core 的 delegate_task 实现
5
+ * 参考: packages/core/src/core/environment/expend/task/task-tool.ts
6
+ *
7
+ * 功能:
8
+ * - 委派子Agent执行任务(仅后台模式)
9
+ * - 支持多种 subagent 类型
10
+ * - 支持任务关联(task_id)
11
+ * - 发布 task.background.* EnvEvent 事件供外部订阅
12
+ *
13
+ * Note: 自 2026-06 起,delegate_task 仅支持后台模式。
14
+ * 父 agent 通过返回的 task_id 主动查询进度。
15
+ */
16
+ import { z } from "zod";
17
+ import type { Tool, ToolResult } from "../../tool/types";
18
+ import type { TaskComponent } from "../task-component";
19
+ /**
20
+ * Background Task Event Types
21
+ * 这些事件由 BackgroundTaskManager 发布,标识为 task.background.*
22
+ */
23
+ export declare const BackgroundTaskEventTypes: {
24
+ readonly STARTED: "task.background.started";
25
+ readonly PROGRESS: "task.background.progress";
26
+ readonly COMPLETED: "task.background.completed";
27
+ readonly FAILED: "task.background.failed";
28
+ readonly TIMEOUT: "task.background.timeout";
29
+ readonly STOPPED: "task.background.stopped";
30
+ /**
31
+ * Task #3147 (subagent ask_user cascade → 标准 notify event)
32
+ * 当 delegate_task 触发的 sub-agent 内部调用 ask_user tool 并抛出 AskUserError 时,
33
+ * BackgroundTaskManager.executeTask 的 catch 块捕获后,发布此事件供 CLI EventHandler
34
+ * 走**标准** notify 流程(与 task.background.completed 等完全一致):
35
+ * - EventMessageFormatter 渲染 payload(含 question + subSessionId + rule-based hints)
36
+ * - handleEventMessageWithEnv → executeInternal 把消息喂给主 agent LLM
37
+ * - 主 agent 用 ask_user tool 展示问题、等用户答复
38
+ * - 拿到答复后用 delegate_task(subagentType=..., existingSubSessionId=payload.subSessionId, ...)
39
+ * 复用 sub-session 让 sub-agent 继承消息历史继续推进(无需 resume function)。
40
+ *
41
+ * 关键:hints 由 BackgroundTaskManager 在构造事件时 rule-based 填充(事件自带),
42
+ * CLI 端 formatter 只渲染,handler 端零特殊化。
43
+ */
44
+ readonly ASK_USER: "task.background.ask_user";
45
+ };
46
+ export interface BackgroundTaskStartedPayload {
47
+ backgroundTaskId: string;
48
+ subSessionId: string;
49
+ parentSessionId: string;
50
+ description: string;
51
+ subagentType: string;
52
+ }
53
+ export interface BackgroundTaskProgressPayload {
54
+ backgroundTaskId: string;
55
+ subSessionId: string;
56
+ parentSessionId: string;
57
+ status: string;
58
+ progress?: number;
59
+ description?: string;
60
+ associatedTaskId?: number;
61
+ }
62
+ export interface BackgroundTaskCompletedPayload {
63
+ backgroundTaskId: string;
64
+ subSessionId: string;
65
+ parentSessionId: string;
66
+ status: "completed" | "failed" | "timeout" | "stopped";
67
+ result?: string;
68
+ error?: string;
69
+ executionTimeMs: number;
70
+ description?: string;
71
+ associatedTaskId?: number;
72
+ }
73
+ /**
74
+ * Task #3147 — ask_user 事件 payload(标准 notify event 流程)
75
+ *
76
+ * 当 BackgroundTaskManager.executeTask 的 catch 块识别到 AskUserError 时发布。
77
+ * CLI 端 EventHandler 订阅 `task.background.ask_user` 事件后走**标准** notify
78
+ * 流程(跟 task.background.completed 等完全一致,无任何特殊化):
79
+ * - EventMessageFormatter 渲染 payload(question + subSessionId + hints)成消息
80
+ * - handleEventMessageWithEnv → executeInternal 把消息喂给主 agent LLM
81
+ * - 主 agent 用 ask_user tool 把 question 展示给用户
82
+ * - 拿到用户答复后用 delegate_task(subagentType=payload.subagentType,
83
+ * existingSubSessionId=payload.subSessionId, prompt=<用户答复>)
84
+ * 复用 sub-session 让 sub-agent 继承之前消息历史继续推进(无需 resume function)。
85
+ *
86
+ * hints 是 rule-based 提示数组,BackgroundTaskManager 在构造事件时填充。
87
+ */
88
+ export interface BackgroundTaskAskUserPayload {
89
+ backgroundTaskId: string;
90
+ subSessionId: string;
91
+ parentSessionId: string;
92
+ subagentType: string;
93
+ description: string;
94
+ /**
95
+ * 解码后的 AskUserError fields(来自 __ASK_USER_ERROR__:...JSON.parse):
96
+ * - query: 原始 ask_user 调用时传入的问题文本(含可选 "(选项: A, B)" 后缀)
97
+ * - sessionId: AskUserError.sessionId(sub-agent 的 session id,与 subSessionId 一致)
98
+ * - nodeId: AskUserError.nodeId(sub-agent 内部 ask_user 节点的 ID)
99
+ * - nodeType: AskUserError.nodeType(默认 'agent')
100
+ * - agentSessionId: AskUserError.agentSessionId(optional,用于跨工具链 resume)
101
+ */
102
+ query: string;
103
+ sessionId: string;
104
+ nodeId: string;
105
+ nodeType: string;
106
+ agentSessionId?: string;
107
+ /** 原始 __ASK_USER_ERROR__:... 错误字符串(备份,便于诊断) */
108
+ error: string;
109
+ executionTimeMs: number;
110
+ associatedTaskId?: number;
111
+ /**
112
+ * Task #3147 — Rule-based hints(事件载荷自带)
113
+ *
114
+ * 原本 #3142 写在 formatter 的 [🤖 Agent 操作提示] 块,按用户预期重做为
115
+ * **事件 payload 自带** 的 hints 数组:rule-based 由 BackgroundTaskManager
116
+ * 在构造 ASK_USER 事件时填充,formatter 只负责渲染,handler 端零特殊化。
117
+ *
118
+ * 内容:
119
+ * - 「显示给用户」/「等待回复」/「delegate_task 续传」
120
+ *
121
+ * 包含必要 ID(subagentType / subSessionId / backgroundTaskId)便于 LLM
122
+ * 看到消息后直接构造 delegate_task 续传调用。
123
+ */
124
+ hints: string[];
125
+ }
126
+ export interface SubAgentSpec {
127
+ id: string;
128
+ name: string;
129
+ description: string;
130
+ mode: "subagent" | "primary" | "all";
131
+ promptOverride?: string;
132
+ /** 允许的工具列表(白名单) */
133
+ allowedTools?: string[];
134
+ /** 拒绝的工具列表(黑名单) */
135
+ deniedTools?: string[];
136
+ }
137
+ export declare const builtInSubAgents: SubAgentSpec[];
138
+ export declare function getSubAgentSpec(id: string): SubAgentSpec | undefined;
139
+ export declare const DelegateToolParameters: z.ZodObject<{
140
+ description: z.ZodString;
141
+ prompt: z.ZodString;
142
+ subagent_type: z.ZodDefault<z.ZodString>;
143
+ timeout: z.ZodOptional<z.ZodNumber>;
144
+ reason: z.ZodOptional<z.ZodString>;
145
+ similar_task_ids: z.ZodArray<z.ZodNumber, "many">;
146
+ sub_session_id: z.ZodOptional<z.ZodString>;
147
+ triggerEventId: z.ZodOptional<z.ZodString>;
148
+ }, "strip", z.ZodTypeAny, {
149
+ description: string;
150
+ prompt: string;
151
+ subagent_type: string;
152
+ similar_task_ids: number[];
153
+ reason?: string | undefined;
154
+ timeout?: number | undefined;
155
+ sub_session_id?: string | undefined;
156
+ triggerEventId?: string | undefined;
157
+ }, {
158
+ description: string;
159
+ prompt: string;
160
+ similar_task_ids: number[];
161
+ reason?: string | undefined;
162
+ timeout?: number | undefined;
163
+ subagent_type?: string | undefined;
164
+ sub_session_id?: string | undefined;
165
+ triggerEventId?: string | undefined;
166
+ }>;
167
+ export type DelegateToolParams = z.infer<typeof DelegateToolParameters>;
168
+ export interface DelegateToolResult {
169
+ tool: Tool;
170
+ backgroundTaskManager: BackgroundTaskManager;
171
+ }
172
+ export interface BackgroundTask {
173
+ id: string;
174
+ /**
175
+ * Task #2590 follow-up — runId of the sub-agent run launched by this task.
176
+ *
177
+ * Pre-allocated in `executeWithAbort` and passed to `env.handle_query` via
178
+ * `AgentContext.runId` so the record is populated BEFORE the run actually
179
+ * starts. Used for run-scoped abort via `agentComponent.abortRun(runId)`
180
+ * instead of the agent-name-scoped `agentComponent.abort(subagentType)`
181
+ * (which silently killed concurrent same-type sub-agents and is the
182
+ * root cause of silent-fail empty `result`).
183
+ */
184
+ runId?: string;
185
+ subSessionId: string;
186
+ parentSessionId: string;
187
+ description: string;
188
+ subagentType: string;
189
+ status: "pending" | "running" | "completed" | "failed" | "timeout" | "stopped" | "awaiting-user";
190
+ createdAt: number;
191
+ /** Timestamp of the latest lifecycle state change or progress notification. */
192
+ lastUpdatedAt?: number;
193
+ startedAt?: number;
194
+ completedAt?: number;
195
+ result?: string;
196
+ error?: string;
197
+ progress?: number;
198
+ progressMessage?: string;
199
+ abortController?: AbortController;
200
+ associatedTaskId?: number;
201
+ similarTaskIds?: number[];
202
+ /**
203
+ * Task #4042 (ESPlugin v2 Phase 2):trigger event ID
204
+ *
205
+ * 由 ES 触发的 delegate_task 会把 triggerEventId 通过 publishBackgroundEvent
206
+ * 透传到所有 task.background.* event,让事件 trigger CLI 可反查 EventStore
207
+ * 拿原始 chatId。不存在时表示非 ES 触发(向后兼容)。
208
+ */
209
+ triggerEventId?: string;
210
+ /**
211
+ * ★ Task #4042 follow-up — delegate 时刻捕获的回复通道快照。
212
+ *
213
+ * 之前 notify event 不带 replyChannel,CLI EventHandler 处理 task.background.*
214
+ * 时只能 fallback 到 REPL 的全局 `lastReplyChannel`(last-write-wins),
215
+ * 多群并发时"最后来的群消息决定所有任务通知回哪个群"(#4035/#4038/#4039 串群)。
216
+ *
217
+ * 修复:createTask 时把 parent EnvContext 的 replyChannel 快照到 task,
218
+ * publishBackgroundEvent 时写进 event.metadata.replyChannel,让每个通知自带
219
+ * 自己 task 诞生时的回复目标;EventHandler.extractChatId 优先用它做
220
+ * chat-keyed session 隔离与回复路由,不再依赖全局 lastReplyChannel。
221
+ */
222
+ replyChannel?: {
223
+ type?: string;
224
+ appId?: string;
225
+ chatId?: string;
226
+ messageId?: string;
227
+ profile?: string;
228
+ params?: Record<string, unknown>;
229
+ };
230
+ }
231
+ export interface CreateBackgroundTaskOptions {
232
+ parentSessionId: string;
233
+ description: string;
234
+ prompt: string;
235
+ subagentType: string;
236
+ timeout?: number;
237
+ similarTaskIds?: number[];
238
+ /**
239
+ * 如果 subagentType 是 workflow 类型被 entry-agent 中介,
240
+ * 此字段记录原始 workflow 名称(用于日志/审计/追踪)。
241
+ *
242
+ * 背景:.roy/design/2026-06-29-workflow-subagent-entry-agent-design.md
243
+ */
244
+ originalWorkflowName?: string;
245
+ /**
246
+ * ★ 已有 sub-agent session ID(可选)。
247
+ * 传入时跳过 sessionComponent.create(),改为 sessionComponent.get() 校验后复用。
248
+ * 用于超时/失败后的重试场景,sub agent 继承之前会话上下文(消息历史保留),
249
+ * 只需在 metadata 中标记 reused_sub_session=true + reused_at=timestamp。
250
+ *
251
+ * 2026-07-10 新增(Task #1752 subSessionId 复用与超时重试机制)
252
+ */
253
+ existingSubSessionId?: string;
254
+ /**
255
+ * ★ Task #4042 (ESPlugin v2 Phase 2):trigger event ID
256
+ *
257
+ * 当 delegate_task 由 ES 触发时(用户在飞书群里说"调研 X",主 agent 调 delegate_task),
258
+ * ES 先通过 EventStore.insertTriggerEvent 把原始飞书消息落库,拿到 triggerEventId,
259
+ * 然后调用 delegate_task 时把 triggerEventId 传到这里。
260
+ *
261
+ * BackgroundTaskManager 会:
262
+ * 1. 把 triggerEventId 写到 sub-session.metadata.triggerEventId(sub-agent 读 ALS 仍可用)
263
+ * 2. 透传到后续所有 task.background.* event metadata(让 CLI event-handler 反查 EventStore)
264
+ */
265
+ triggerEventId?: string;
266
+ }
267
+ /**
268
+ * 构建 entry-agent 调度的 prompt 包装 (Task #2164 beta-compare divergence #2)
269
+ *
270
+ * 当 delegate_task 检测到 workflow 类型 subagent (或 5 legacy yaml alias) 时,
271
+ * 用此函数包装原始 prompt, 明确告诉 entry-agent 要调度哪个 workflow.
272
+ *
273
+ * 结构化设计 (beta divergence vs reference #2146):
274
+ * - 使用 `<workflow_name>NAME</workflow_name>` XML 标签作为唯一权威的 workflow 名来源
275
+ * - 取代 reference 让 LLM 通过 pattern examples 解析 workflow 名的方案
276
+ * - 工作流名应严格从这个标签解析 (避免 LLM 模式猜测)
277
+ * - 用法: prompt.match(/<workflow_name>([^<]+)<\/workflow_name>/)?.[1]
278
+ */
279
+ export declare function buildEntryAgentPrompt(options: {
280
+ workflowName: string;
281
+ originalPrompt: string;
282
+ description: string;
283
+ }): string;
284
+ /**
285
+ * 5 个 legacy yaml subagent 名称 (Task #2164 兼容性)
286
+ *
287
+ * 用户历史上可能在 ~/.local/share/roy-agent/agents/ 下配置过这些名字的 yaml 文件,
288
+ * 为了不破坏用户配置, Beta 把它们统一改写到 workflow-runner.
289
+ *
290
+ * 设计:Set 查找 O(1),不引入额外 dispatcher 类。
291
+ */
292
+ export declare const WORKFLOW_COMPAT_ALIASES: ReadonlySet<string>;
293
+ export declare const DEFAULT_TIMEOUT = 1800000;
294
+ /**
295
+ * Background Task Manager (简化版)
296
+ *
297
+ * 管理后台任务的创建、执行、状态跟踪
298
+ * 发布 task.background.* 事件供外部订阅
299
+ */
300
+ export declare class BackgroundTaskManager {
301
+ private env;
302
+ /**
303
+ * Task #2539 — processRegistries 上限。超过上限时 createTask 拒绝(拒绝 throw),
304
+ * 防止 spawn 出 bug 时无界累积。默认 1000(足够日常使用,又不至于无限增长)。
305
+ * 实际活跃 task 数受 processRegistries.size 限制;正常 task 完成后 finalizeTask
306
+ * 会清掉 map entry;残留 PID task(BL-4c)保留 map entry 直到 killAll 才清。
307
+ */
308
+ private readonly maxProcessRegistries;
309
+ /**
310
+ * Task #2539 — terminalTasks 上限。终态任务从 tasks Map 移到这里,cap 1000。
311
+ * 超过上限时丢最旧的(保持 LRU 语义:最近完成的任务优先保留,便于 query_background_process 查询)。
312
+ */
313
+ private readonly maxTerminalTasks;
314
+ private tasks;
315
+ /**
316
+ * Task #2539 — 终态任务镜像。
317
+ * finalizeTask 时把 BackgroundTask 从 tasks Map 移到这里;getTask 优先查 tasks,其次 terminalTasks。
318
+ * 上限 maxTerminalTasks,超过时丢最旧。
319
+ */
320
+ private terminalTasks;
321
+ private abortControllers;
322
+ private progressTimers;
323
+ /**
324
+ * Per-task ProcessRegistry(2026-07 新增)。
325
+ * 跟踪该 task 派生的所有子进程 PID;timeout/stop/dispose 时遍历杀进程树。
326
+ * 内部值是 ProcessRegistry 实例;存储而不暴露,便于测试访问。
327
+ *
328
+ * Task #2539 — 终态释放契约:transient registry(tasks / abortControllers /
329
+ * workflowRunRegistries / 本 task 的 processRegistries entry)在 sub session
330
+ * 终态触发后必须释放;processRegistries 仅在 size==0 时 delete map 入口
331
+ * (保留 BL-4c force-stop 重试 contract)。
332
+ */
333
+ private processRegistries;
334
+ /**
335
+ * Per-task workflow run registry (Task #2144).
336
+ * 跟踪该 task 派生的所有 workflow_run runId;stopTask() 时遍历调 workflowService.stopRun。
337
+ * 镜像 processRegistries 的 Map<bgTaskId, Set<workflowRunId>> 模式。
338
+ */
339
+ private workflowRunRegistries;
340
+ /**
341
+ * WorkflowService 引用(Task #2144 — 反向注入,避免 task → workflow 直接 import)。
342
+ * WorkflowComponent 启动时通过 setWorkflowService() 注入。
343
+ */
344
+ private workflowService?;
345
+ constructor(env: any);
346
+ /**
347
+ * Task #2144 — 注入 WorkflowService 引用。
348
+ * 由 WorkflowComponent 在初始化时反向注入(避免 task → workflow 直接 import)。
349
+ * 缺省时 propagateStopToWorkflowRuns 仅记录 warn 日志,不抛错。
350
+ */
351
+ setWorkflowService(svc: {
352
+ stopRun(runId: string, reason?: string): Promise<void>;
353
+ }): void;
354
+ /**
355
+ * Task #2144 — Attach a workflow runId to a bgTask。
356
+ * 当 sub-session 通过 workflow_run 启动 workflow 时调用,把 runId 注册到
357
+ * 对应 bgTaskId 的 workflowRunRegistries,供 stopTask() 级联 stop。
358
+ *
359
+ * 空字符串 / 缺失参数静默忽略(避免脏数据);重复 attach 同一 runId 幂等。
360
+ */
361
+ attachWorkflowRun(bgTaskId: string, workflowRunId: string): void;
362
+ /**
363
+ * Task #2144 — Detach a workflow runId from a bgTask。
364
+ * 当 workflow_run 自然完成(success)时调用,把 runId 从 registry 中移除,
365
+ * 避免 propagateStopToWorkflowRuns 重复 stop 已完成的 workflow。
366
+ * 缺省时 propagateStop 仍会 stopRun,但 stopRun 对已完成 workflow 是幂等的。
367
+ */
368
+ detachWorkflowRun(bgTaskId: string, workflowRunId: string): void;
369
+ /**
370
+ * Task #2190 — Replace a placeholder runId with the real engine runId.
371
+ * 触发时机:sub-session 调 workflow_run 时,wrapper 立即用 reservedRunId
372
+ * 做 PRE-attach;engine 随后通过 onSessionCreated 报回真实 runId;tool 调
373
+ * 此 hook 把 registry 里的占位 id 替换成真实 id,使后续 stop_task 能针对
374
+ * 真实 workflow 调用 stopRun。
375
+ *
376
+ * 语义:若 oldRunId 存在则删除;若 newRunId 非空则加入(覆盖式 swap)。
377
+ * 空字符串 / 缺失参数静默忽略;bgTaskId 不存在则 no-op。
378
+ */
379
+ replaceWorkflowRun(bgTaskId: string, oldRunId: string, newRunId: string): void;
380
+ /**
381
+ * Task #2144 — 级联 stop 所有 attach 到 bgTaskId 的 workflow runs。
382
+ * 在 stopTask() 的 killAll() 之后调;workflowService.stopRun 对已完成 workflow
383
+ * 是幂等的(try/catch + logger.warn 吞掉 "Session not found" 等异常)。
384
+ * 主 session 直接调用(无 bgTaskId)时 workflowRunRegistries 为空,no-op。
385
+ *
386
+ * Task #2190 — returns `{ runIds, stopResults }` so stopTask() can populate
387
+ * `attached_workflow_run_ids` and `workflow_stop_results` in the payload.
388
+ * `stopResults[i]` mirrors `runIds[i]` 1:1; entries carry `{ runId, success, error? }`.
389
+ */
390
+ private propagateStopToWorkflowRuns;
391
+ /**
392
+ * Task #2539 — 终态联动释放 transient registry(success / error / cancel / timeout 共用)。
393
+ *
394
+ * 释放:
395
+ * - tasks Map 中本 task entry(BackgroundTask 对象本身;持有者持有引用时可继续读,但不再可查询)
396
+ * - abortControllers Map 中本 task entry
397
+ * - workflowRunRegistries Map 中本 task entry(per-task Set)
398
+ * - progressTimers Map 中本 task entry(通过 stopProgressReporter)
399
+ *
400
+ * 保留(BL-4c force-stop 重试 contract):
401
+ * - processRegistries Map 中本 task entry — 仅在 size==0 时 delete map 入口,
402
+ * 残留 PID 时保留 map entry 供下一次 forceStopAllAcrossParents 重试。
403
+ *
404
+ * 幂等:重复调用 no-op(map 上 .delete 第二次返回 false)。
405
+ * 不存在的 taskId:no-op,不报错。
406
+ */
407
+ finalizeTask(taskId: string, reason: string): void;
408
+ /**
409
+ * Task #2539 — processRegistries 当前 size(可观测)。
410
+ * 用于 heap stress 测试 / 监控埋点。
411
+ */
412
+ getProcessRegistrySize(): number;
413
+ /**
414
+ * Task #2539 — processRegistries 上限。
415
+ */
416
+ getMaxProcessRegistries(): number;
417
+ /**
418
+ * Task #2539 — 清掉所有 size==0 的 processRegistry map entries(保守兜底)。
419
+ * 不主动调用;正常路径由 finalizeTask 在 size==0 时 delete。
420
+ * 提供这个 API 供测试 / 监控。
421
+ *
422
+ * @returns cleaned count
423
+ */
424
+ cleanupEmptyProcessRegistries(): number;
425
+ /**
426
+ * Workflow entry-agent 默认名称
427
+ *
428
+ * 当 delegate_task 检测到 workflow 类型 subagent 时,委托给该 entry-agent。
429
+ * 详见 .roy/design/2026-06-29-workflow-subagent-entry-agent-design.md
430
+ */
431
+ static readonly DEFAULT_WORKFLOW_ENTRY_AGENT = "workflow-runner";
432
+ /**
433
+ * 检查 subagentType 是否需要走 entry-agent 路由(workflow 类型)
434
+ *
435
+ * 返回 entry-agent 名称(如果有),否则返回 undefined(走原路径)。
436
+ *
437
+ * 注意:这里必须 try/catch,因为 this.env?.getComponent 可能抛错。
438
+ *
439
+ * Task #2164 beta-compare divergence #1: 单一层 canonicalization
440
+ * - 5 个 legacy yaml alias (strict-task-agent/code-review/...) 直接在这里重写,
441
+ * handleBackgroundTask 不再二次检测
442
+ * - 参考 reference 在 createDelegateTool().execute() + handleBackgroundTask()
443
+ * 两层 rewriting, beta 只 1 层
444
+ */
445
+ resolveEntryAgent(subagentType: string): string | undefined;
446
+ /**
447
+ * Internal compat-rewrite detection (Task #2164 trace #3)
448
+ *
449
+ * 用 wrapFunction 包一层让 free-standing 检测逻辑也能进入 OTel span,
450
+ * 参考 reference 把这逻辑标记为 "not-applicable" 因为 @TracedAs 不支持 free function.
451
+ * Beta 用 wrapFunction 让 `delegate.detectWorkflowShortcut` span 被记录。
452
+ */
453
+ private static _detectWorkflowShortcutWrapped;
454
+ /** 公开的 static 入口,wrapFunction 不污染 caller API */
455
+ static detectWorkflowShortcutCompat(subagentType: string): boolean;
456
+ /**
457
+ * Get SessionComponent from env
458
+ */
459
+ private getSessionComponent;
460
+ /**
461
+ * sub-session → task 的确定性反查。
462
+ *
463
+ * sub-agent 的 `task_create` 用 `sessionId = ctx.session_id`(即 sub-session id),
464
+ * 因此可按 session_id 反查它创建的第一个 task。用于在 completion 时稳定地确定
465
+ * `associatedTaskId`,避免依赖易失的 `getCurrentTaskId()`(被 task_complete 清空)
466
+ * 或有歧义的结果文本正则。
467
+ */
468
+ private resolveAssociatedTaskIdBySubSession;
469
+ /**
470
+ * Publish a task.background.* event
471
+ *
472
+ * Task #4042 (ESPlugin v2 Phase 2):可选 triggerEventId 参数。
473
+ * 当 ES 触发 delegate_task 时,主 agent 会通过 EventStore.insertTriggerEvent
474
+ * 先把原始飞书事件落库,拿到 triggerEventId;sub-agent 完成后 emit notify event
475
+ * 携带 triggerEventId,主 agent 处理 notify event 时反查 EventStore 拿原始 chatId。
476
+ *
477
+ * 不传 triggerEventId 时,向后兼容老代码路径(metadata.triggerEventId 缺失)。
478
+ */
479
+ private publishBackgroundEvent;
480
+ /**
481
+ * 带 triggerEventId 的 publishBackgroundEvent 公开版(用于测试和外部调用)
482
+ *
483
+ * @internal 测试 / 集成用,普通调用方走 publishBackgroundEvent 私有方法
484
+ */
485
+ publishBackgroundEventWithTrigger<T>(type: string, payload: T, parentSessionId: string | undefined, triggerEventId: string, replyChannel?: BackgroundTask["replyChannel"]): void;
486
+ /**
487
+ * Task #3xxx — 解析 AskUserError 信息
488
+ *
489
+ * env.handle_query() 路径下,ask_user 抛出的 AskUserError 会被 agent-component 编码成
490
+ * `__ASK_USER_ERROR__:{JSON}` 字符串,然后通过 `throw new Error(result.error)`
491
+ * 抛出(environment.ts:417),所以 catch 块只能拿到 plain Error instance。
492
+ * 直接 throw 的场景(如未来插件扩展)也能命中 instance / name 检查。
493
+ *
494
+ * 复用 interactive.ts:1300 parseAskUserError 的识别规则(避免重复实现):
495
+ * 1. error instanceof AskUserError
496
+ * 2. error.name === 'AskUserError'
497
+ * 3. error.message 包含 __ASK_USER_ERROR__: 前缀 → JSON.parse
498
+ *
499
+ * @returns 解码后的 AskUserErrorInfo;null 表示不是 ask_user 错误(继续走普通 error 分支)
500
+ */
501
+ private static parseAskUserErrorFromMessage;
502
+ createTask(options: CreateBackgroundTaskOptions): Promise<{
503
+ taskId: string;
504
+ subSessionId: string;
505
+ }>;
506
+ /**
507
+ * Task #3146 — sub-agent ask_user cascade(移除 resume function)
508
+ *
509
+ * 历史:原 `resumeFromAskUserAnswer()` 由 Task #3142 引入,用于用户答复后
510
+ * 通过 BackgroundTaskManager 复用 sub-session 续传 sub-agent。
511
+ *
512
+ * 决定(用户指令):**无需实现 resume function**——续传完全由 delegate_task
513
+ * 自然完成。具体流程:
514
+ * 1. BackgroundTaskManager.executeTask 在 catch 块识别 AskUserError 后,
515
+ * 保留 sub-session 并发布 `task.background.ask_user` 事件。
516
+ * 2. CLI 收到事件后直接显示问题给用户(不送 LLM)。
517
+ * 3. 用户答复后,主 agent(或用户命令)通过 `delegate_task` 工具调用
518
+ * `subagentType=original.subagentType, existingSubSessionId=original.subSessionId`
519
+ * 即可复用 sub-session(保留 message history)继续推进 sub-agent。
520
+ *
521
+ * 因此本方法不再提供;续传是 delegate_task + existingSubSessionId 内建能力。
522
+ */
523
+ private executeTask;
524
+ /**
525
+ * Start progress reporter for a task
526
+ */
527
+ private startProgressReporter;
528
+ /**
529
+ * Stop progress reporter for a task
530
+ */
531
+ private stopProgressReporter;
532
+ private executeWithAbort;
533
+ stopTask(taskId: string): Promise<{
534
+ success: boolean;
535
+ task?: BackgroundTask;
536
+ message: string;
537
+ /**
538
+ * Task #2190 — workflow runId list that was attached at stop time.
539
+ * Main session can audit which workflow_runs were stopped as a
540
+ * cascade of this stop_task. Always an array (empty if none).
541
+ */
542
+ attached_workflow_run_ids?: string[];
543
+ /**
544
+ * Task #2190 — per-id stop outcomes from `propagateStopToWorkflowRuns`.
545
+ * 1:1 with `attached_workflow_run_ids` when both arrays have entries.
546
+ * Each entry: `{ runId, success, error? }`.
547
+ */
548
+ workflow_stop_results?: Array<{
549
+ runId: string;
550
+ success: boolean;
551
+ error?: string;
552
+ }>;
553
+ }>;
554
+ getTask(taskId: string): BackgroundTask | undefined;
555
+ listTasks(): BackgroundTask[];
556
+ /**
557
+ * Task #2255 — ESC idle-with-active-descendant fix.
558
+ *
559
+ * Returns true if there is at least one background task whose
560
+ * `parentSessionId` matches the given parent AND whose status is
561
+ * `pending` or `running`. Used by REPL.handleEscKey() to decide
562
+ * whether to cascade-stop the session tree even when the main LLM
563
+ * is idle (isExecuting=false).
564
+ *
565
+ * Cheap: O(N) over the in-memory tasks Map (typically <10 active
566
+ * per session). Not persisted to DB — runs from in-memory state only.
567
+ */
568
+ hasActiveTaskForParent(parentSessionId: string): boolean;
569
+ /**
570
+ * Task #2245 — ESC cascade stop.
571
+ *
572
+ * Stop all BackgroundTask instances whose `parentSessionId` matches the given
573
+ * parent, regardless of which sub-agent type created them. Calls the existing
574
+ * `stopTask(taskId)` per entry, which already propagates to attached workflow
575
+ * runs (Task #2144). Returns `{ stoppedTaskIds }` so callers (e.g. REPL ESC
576
+ * handler / `cascadeStopSessionTree`) can audit cascade coverage.
577
+ *
578
+ * Only acts on `pending` / `running` tasks; `completed` / `failed` / `stopped`
579
+ * / `timeout` are skipped (idempotent).
580
+ *
581
+ * Iron rule: does NOT mutate `parentSessionId` or any background-task identity.
582
+ * No effect on tasks whose parent does not match.
583
+ */
584
+ stopAllForParent(parentSessionId: string): Promise<{
585
+ stoppedTaskIds: string[];
586
+ }>;
587
+ /**
588
+ * Task #2245 — ESC force-stop (second-press within 2s window).
589
+ *
590
+ * Traverse ALL BackgroundTask entries (regardless of parent), kill their
591
+ * process trees via ProcessRegistry, and mark them `stopped`. Used as the
592
+ * force path when `stopAllForParent` (graceful) leaves residual orphans.
593
+ *
594
+ * Task #2245 — BL-4: iterates ALL tasks (not just running/pending) so that
595
+ * tasks already marked `stopped` by graceful `stopTask()` but with leaked
596
+ * PIDs can still be retried. Combined with `ProcessRegistry.killAll()`
597
+ * retaining `stillAlive` PIDs, this enables second-ESC force retry.
598
+ *
599
+ * Task #2245 — P1-#1: also calls `propagateStopToWorkflowRuns` for each task
600
+ * so that attached workflow runs are cascaded into the engine's stop
601
+ * (the original cascade gap — only `dispose()` did this previously).
602
+ *
603
+ * Task #2245 — P1-#2: publishes `task.background.stopped` event for each
604
+ * task that is freshly marked `stopped` by this force pass, so the parent
605
+ * session and CLI UI see the stop signal (previously force path was silent).
606
+ *
607
+ * Task #2245 — P1-#8: renamed to `forceStopAllAcrossParents` to clarify
608
+ * that this iterates ALL tasks (regardless of parent), unlike
609
+ * `stopAllForParent(parentId)` which is parent-scoped. `forceStopAll` is
610
+ * kept as a deprecated alias for backward compatibility.
611
+ */
612
+ forceStopAllAcrossParents(): Promise<void>;
613
+ /**
614
+ * Task #2245 — P1-#8: deprecated alias for `forceStopAllAcrossParents`.
615
+ * Kept for backward compatibility with code that still calls `forceStopAll`.
616
+ * New code should call `forceStopAllAcrossParents` directly.
617
+ * @deprecated use forceStopAllAcrossParents
618
+ */
619
+ forceStopAll(): Promise<void>;
620
+ /**
621
+ * Dispose and cleanup all resources
622
+ * Call this when shutting down to prevent process from hanging
623
+ */
624
+ dispose(): Promise<void>;
625
+ }
626
+ /**
627
+ * Create delegate_task tool
628
+ */
629
+ export declare function createDelegateTool(taskComponent: TaskComponent): Tool;
630
+ /**
631
+ * Task #4042 ESPlugin v2 P0(生产路径修复):从当前 EnvContext 派生 triggerEventId。
632
+ *
633
+ * 完整 v2 链路:
634
+ * lark event → EventStore.insertTriggerEvent → triggerEventId
635
+ * → 主 agent delegate_task(triggerEventId) → task.background.* metadata.triggerEventId
636
+ * → CLI EventHandler 反查 EventStore 拿原始 chatId / messageId。
637
+ *
638
+ * 问题:triggerEventId 只在 LLM 显式传参时才透传,而它对 LLM 是个晦涩 token,
639
+ * 生产上几乎不传 → notify event 缺 metadata.triggerEventId → v2 path 永不命中,
640
+ * 退回老 replyChannel fallback(正是 #4035/#4038/#4039 串群根因)。
641
+ *
642
+ * 兜底来源(优先级从高到低):
643
+ * 1. EnvContext.envEvent.metadata.triggerEventId(LarkCliInstance.handleEvent 注入)
644
+ * 2. EnvContext.envEvent.payload.triggerEventId(同上的 payload 副本)
645
+ *
646
+ * 非 ES 触发场景(普通 CLI / REPL 输入)返回 undefined,向后兼容。
647
+ */
648
+ declare function _deriveTriggerEventIdFromEnvContext(): string | undefined;
649
+ /**
650
+ * traced 版 deriveTriggerEventIdFromEnvContext(供 debug trace 观测派生结果)。
651
+ */
652
+ export declare const deriveTriggerEventIdFromEnvContext: typeof _deriveTriggerEventIdFromEnvContext;
653
+ /**
654
+ * Task #4042 follow-up:把当前 EnvContext.replyChannel 拍成不可变快照。
655
+ *
656
+ * 为什么快照:replyChannel 对象可能被后续事件修改(父子共享/ALS 继承),
657
+ * 而 BackgroundTask 生命周期长(sub-agent 可能跑几十分钟),必须固化 delegate
658
+ * 时刻的回复目标,避免"通知发出时读到的 replyChannel 已经是别的群"。
659
+ *
660
+ * 返回 undefined 当没有 EnvContext / 没有 replyChannel / replyChannel 无 chatId+messageId
661
+ * (无有效回复目标时不要塞空对象,保持向后兼容)。
662
+ */
663
+ declare function _captureReplyChannelSnapshot(): BackgroundTask["replyChannel"] | undefined;
664
+ /**
665
+ * traced 版 captureReplyChannelSnapshot(供 debug trace 观测 task 的回复目标快照)。
666
+ */
667
+ export declare const captureReplyChannelSnapshot: typeof _captureReplyChannelSnapshot;
668
+ declare function handleBackgroundTask(backgroundTaskManager: BackgroundTaskManager, parentSessionId: string, description: string, prompt: string, subagentType: string, timeout?: number, similarTaskIds?: number[],
669
+ /**
670
+ * ★ 2026-07-10 新增(Task #1752 subSessionId 复用机制)
671
+ * 已有 sub session ID。传入时 BackgroundTaskManager.createTask 跳过 create(),
672
+ * 改为 get() 校验后复用 sub session;不传则保持新建模式。
673
+ */
674
+ existingSubSessionId?: string,
675
+ /**
676
+ * ★ Task #4042 ESPlugin v2:EventStore trigger event ID。
677
+ * 传入时透传给 createTask → publishBackgroundEvent,写进 task.background.*
678
+ * 事件 metadata,供主 agent 反查原始 chatId。
679
+ */
680
+ triggerEventId?: string): Promise<ToolResult>;
681
+ export { handleBackgroundTask };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @fileoverview Delegate Tools Index
3
+ */
4
+ export { createDelegateTool, BackgroundTaskManager } from "./delegate-tool";
5
+ export { createStopTool } from "./stop-tool";
6
+ export type { DelegateToolResult, DelegateToolParams, DelegateToolParameters } from "./delegate-tool";
7
+ export type { BackgroundTask, SubAgentSpec } from "./delegate-tool";
8
+ export { BackgroundTaskEventTypes, type BackgroundTaskStartedPayload, type BackgroundTaskProgressPayload, type BackgroundTaskCompletedPayload, } from "./delegate-tool";