@ynhcj/xiaoyi-channel 0.0.9-next → 0.0.9-test20260606

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 (264) hide show
  1. package/dist/index.d.ts +2 -15
  2. package/dist/index.js +372 -10
  3. package/dist/provider-discovery.d.ts +2 -0
  4. package/dist/provider-discovery.js +4 -0
  5. package/dist/src/acp-session-binding.d.ts +37 -0
  6. package/dist/src/acp-session-binding.js +237 -0
  7. package/dist/src/approval-bridge.d.ts +48 -0
  8. package/dist/src/approval-bridge.js +382 -0
  9. package/dist/src/bot.d.ts +14 -0
  10. package/dist/src/bot.js +559 -158
  11. package/dist/src/channel.js +101 -23
  12. package/dist/src/client.d.ts +4 -3
  13. package/dist/src/client.js +32 -46
  14. package/dist/src/compaction-provider.d.ts +50 -0
  15. package/dist/src/compaction-provider.js +202 -0
  16. package/dist/src/cron-command.d.ts +17 -0
  17. package/dist/src/cron-command.js +55 -0
  18. package/dist/src/cron-query-handler.d.ts +27 -0
  19. package/dist/src/cron-query-handler.js +615 -0
  20. package/dist/src/cron-recovery.d.ts +25 -0
  21. package/dist/src/cron-recovery.js +587 -0
  22. package/dist/src/cspl/call-api.d.ts +9 -0
  23. package/dist/src/cspl/call-api.js +110 -0
  24. package/dist/src/cspl/call_api.d.ts +7 -0
  25. package/dist/src/cspl/call_api.js +103 -0
  26. package/dist/src/cspl/config.d.ts +15 -0
  27. package/dist/src/cspl/config.js +119 -0
  28. package/dist/src/cspl/configs.json +10 -0
  29. package/dist/src/cspl/constants.d.ts +105 -0
  30. package/dist/src/cspl/constants.js +73 -0
  31. package/dist/src/cspl/middleware.d.ts +8 -0
  32. package/dist/src/cspl/middleware.js +90 -0
  33. package/dist/src/cspl/sentinel_hook.d.ts +2 -0
  34. package/dist/src/cspl/sentinel_hook.js +108 -0
  35. package/dist/src/cspl/steer-context.d.ts +21 -0
  36. package/dist/src/cspl/steer-context.js +78 -0
  37. package/dist/src/cspl/upload_file.d.ts +1 -0
  38. package/dist/src/cspl/upload_file.js +210 -0
  39. package/dist/src/cspl/utils.d.ts +37 -0
  40. package/dist/src/cspl/utils.js +361 -0
  41. package/dist/src/file-download.d.ts +1 -0
  42. package/dist/src/file-download.js +3 -4
  43. package/dist/src/file-upload.d.ts +10 -0
  44. package/dist/src/file-upload.js +249 -17
  45. package/dist/src/formatter.d.ts +81 -1
  46. package/dist/src/formatter.js +305 -94
  47. package/dist/src/heartbeat.js +4 -7
  48. package/dist/src/log-reporter/config-loader.d.ts +11 -0
  49. package/dist/src/log-reporter/config-loader.js +68 -0
  50. package/dist/src/log-reporter/cursor-store.d.ts +5 -0
  51. package/dist/src/log-reporter/cursor-store.js +26 -0
  52. package/dist/src/log-reporter/index.d.ts +10 -0
  53. package/dist/src/log-reporter/index.js +210 -0
  54. package/dist/src/log-reporter/openclaw-parser.d.ts +18 -0
  55. package/dist/src/log-reporter/openclaw-parser.js +94 -0
  56. package/dist/src/log-reporter/path-resolver.d.ts +5 -0
  57. package/dist/src/log-reporter/path-resolver.js +50 -0
  58. package/dist/src/log-reporter/reporter.d.ts +6 -0
  59. package/dist/src/log-reporter/reporter.js +56 -0
  60. package/dist/src/log-reporter/scanner.d.ts +10 -0
  61. package/dist/src/log-reporter/scanner.js +78 -0
  62. package/dist/src/log-reporter/types.d.ts +58 -0
  63. package/dist/src/log-reporter/types.js +2 -0
  64. package/dist/src/log-reporter/uploader.d.ts +7 -0
  65. package/dist/src/log-reporter/uploader.js +55 -0
  66. package/dist/src/login-token-handler.d.ts +8 -0
  67. package/dist/src/login-token-handler.js +63 -0
  68. package/dist/src/memory-query-handler.d.ts +1 -0
  69. package/dist/src/memory-query-handler.js +283 -0
  70. package/dist/src/message-queue.d.ts +17 -0
  71. package/dist/src/message-queue.js +52 -0
  72. package/dist/src/monitor.js +178 -61
  73. package/dist/src/onboarding.d.ts +3 -4
  74. package/dist/src/onboarding.js +2 -2
  75. package/dist/src/outbound.d.ts +9 -1
  76. package/dist/src/outbound.js +91 -50
  77. package/dist/src/parser.d.ts +33 -1
  78. package/dist/src/parser.js +135 -0
  79. package/dist/src/provider.d.ts +3 -0
  80. package/dist/src/provider.js +786 -0
  81. package/dist/src/push.d.ts +13 -2
  82. package/dist/src/push.js +107 -50
  83. package/dist/src/reply-dispatcher.d.ts +10 -1
  84. package/dist/src/reply-dispatcher.js +353 -160
  85. package/dist/src/runtime.d.ts +3 -11
  86. package/dist/src/runtime.js +6 -18
  87. package/dist/src/self-evolution-handler.d.ts +7 -0
  88. package/dist/src/self-evolution-handler.js +149 -0
  89. package/dist/src/self-evolution-keyword.d.ts +9 -0
  90. package/dist/src/self-evolution-keyword.js +147 -0
  91. package/dist/src/self-evolution-tool-result-nudge.d.ts +3 -0
  92. package/dist/src/self-evolution-tool-result-nudge.js +96 -0
  93. package/dist/src/sensitive-redactor.d.ts +4 -0
  94. package/dist/src/sensitive-redactor.js +364 -0
  95. package/dist/src/skill-retriever/config.d.ts +4 -0
  96. package/dist/src/skill-retriever/config.js +25 -0
  97. package/dist/src/skill-retriever/hooks.d.ts +39 -0
  98. package/dist/src/skill-retriever/hooks.js +203 -0
  99. package/dist/src/skill-retriever/tool-search.d.ts +19 -0
  100. package/dist/src/skill-retriever/tool-search.js +186 -0
  101. package/dist/src/skill-retriever/types.d.ts +37 -0
  102. package/dist/src/skill-retriever/types.js +1 -0
  103. package/dist/src/steer-injector.d.ts +16 -0
  104. package/dist/src/steer-injector.js +74 -0
  105. package/dist/src/steer-queue.d.ts +1 -0
  106. package/dist/src/steer-queue.js +9 -0
  107. package/dist/src/subagent-wait-state.d.ts +73 -0
  108. package/dist/src/subagent-wait-state.js +240 -0
  109. package/dist/src/task-manager.d.ts +20 -32
  110. package/dist/src/task-manager.js +69 -88
  111. package/dist/src/thread-bindings.d.ts +54 -0
  112. package/dist/src/thread-bindings.js +214 -0
  113. package/dist/src/tools/agent-as-skill-tool.d.ts +46 -0
  114. package/dist/src/tools/agent-as-skill-tool.js +183 -0
  115. package/dist/src/tools/calendar-tool.d.ts +24 -1
  116. package/dist/src/tools/calendar-tool.js +10 -46
  117. package/dist/src/tools/call-device-tool.d.ts +20 -0
  118. package/dist/src/tools/call-device-tool.js +131 -0
  119. package/dist/src/tools/call-phone-tool.d.ts +20 -1
  120. package/dist/src/tools/call-phone-tool.js +14 -75
  121. package/dist/src/tools/check-plugin-privilege-tool.d.ts +20 -0
  122. package/dist/src/tools/check-plugin-privilege-tool.js +180 -0
  123. package/dist/src/tools/create-alarm-tool.d.ts +39 -1
  124. package/dist/src/tools/create-alarm-tool.js +18 -131
  125. package/dist/src/tools/create-all-tools.d.ts +16 -0
  126. package/dist/src/tools/create-all-tools.js +62 -0
  127. package/dist/src/tools/delete-alarm-tool.d.ts +15 -1
  128. package/dist/src/tools/delete-alarm-tool.js +14 -82
  129. package/dist/src/tools/device-tool-map.d.ts +4 -0
  130. package/dist/src/tools/device-tool-map.js +45 -0
  131. package/dist/src/tools/discover-cross-devices-tool.d.ts +16 -0
  132. package/dist/src/tools/discover-cross-devices-tool.js +232 -0
  133. package/dist/src/tools/display-a2ui-card-bypath-tool.d.ts +21 -0
  134. package/dist/src/tools/display-a2ui-card-bypath-tool.js +65 -0
  135. package/dist/src/tools/display-a2ui-card-tool.d.ts +2 -0
  136. package/dist/src/tools/display-a2ui-card-tool.js +85 -0
  137. package/dist/src/tools/find-pc-devices-tool.d.ts +6 -0
  138. package/dist/src/tools/find-pc-devices-tool.js +95 -0
  139. package/dist/src/tools/get-alarm-tool-schema.d.ts +16 -0
  140. package/dist/src/tools/get-alarm-tool-schema.js +11 -0
  141. package/dist/src/tools/get-calendar-tool-schema.d.ts +16 -0
  142. package/dist/src/tools/get-calendar-tool-schema.js +9 -0
  143. package/dist/src/tools/get-collection-tool-schema.d.ts +16 -0
  144. package/dist/src/tools/get-collection-tool-schema.js +10 -0
  145. package/dist/src/tools/get-contact-tool-schema.d.ts +16 -0
  146. package/dist/src/tools/get-contact-tool-schema.js +11 -0
  147. package/dist/src/tools/get-device-file-tool-schema.d.ts +16 -0
  148. package/dist/src/tools/get-device-file-tool-schema.js +10 -0
  149. package/dist/src/tools/get-email-tool-schema.d.ts +16 -0
  150. package/dist/src/tools/get-email-tool-schema.js +9 -0
  151. package/dist/src/tools/get-note-tool-schema.d.ts +16 -0
  152. package/dist/src/tools/get-note-tool-schema.js +10 -0
  153. package/dist/src/tools/get-photo-tool-schema.d.ts +16 -0
  154. package/dist/src/tools/get-photo-tool-schema.js +10 -0
  155. package/dist/src/tools/hmos-cli.d.ts +109 -0
  156. package/dist/src/tools/hmos-cli.js +558 -0
  157. package/dist/src/tools/image-reading-tool.d.ts +32 -0
  158. package/dist/src/tools/image-reading-tool.js +246 -0
  159. package/dist/src/tools/invoke.d.ts +88 -0
  160. package/dist/src/tools/invoke.js +1209 -0
  161. package/dist/src/tools/location-tool.d.ts +11 -1
  162. package/dist/src/tools/location-tool.js +17 -49
  163. package/dist/src/tools/login-token-tool.d.ts +24 -0
  164. package/dist/src/tools/login-token-tool.js +142 -0
  165. package/dist/src/tools/modify-alarm-tool.d.ts +47 -1
  166. package/dist/src/tools/modify-alarm-tool.js +41 -144
  167. package/dist/src/tools/modify-note-tool.d.ts +20 -1
  168. package/dist/src/tools/modify-note-tool.js +11 -50
  169. package/dist/src/tools/note-tool.d.ts +20 -1
  170. package/dist/src/tools/note-tool.js +12 -25
  171. package/dist/src/tools/query-app-message-tool.d.ts +31 -0
  172. package/dist/src/tools/query-app-message-tool.js +138 -0
  173. package/dist/src/tools/query-memory-data-tool.d.ts +31 -0
  174. package/dist/src/tools/query-memory-data-tool.js +154 -0
  175. package/dist/src/tools/query-todo-task-tool.d.ts +27 -0
  176. package/dist/src/tools/query-todo-task-tool.js +133 -0
  177. package/dist/src/tools/save-file-to-phone-tool.d.ts +28 -0
  178. package/dist/src/tools/save-file-to-phone-tool.js +165 -0
  179. package/dist/src/tools/save-media-to-gallery-tool.d.ts +28 -0
  180. package/dist/src/tools/save-media-to-gallery-tool.js +173 -0
  181. package/dist/src/tools/save-self-evolution-skill-tool.d.ts +54 -0
  182. package/dist/src/tools/save-self-evolution-skill-tool.js +410 -0
  183. package/dist/src/tools/schema-tool-factory.d.ts +27 -0
  184. package/dist/src/tools/schema-tool-factory.js +32 -0
  185. package/dist/src/tools/search-alarm-tool.d.ts +34 -1
  186. package/dist/src/tools/search-alarm-tool.js +26 -140
  187. package/dist/src/tools/search-calendar-tool.d.ts +24 -1
  188. package/dist/src/tools/search-calendar-tool.js +14 -90
  189. package/dist/src/tools/search-contact-tool.d.ts +16 -1
  190. package/dist/src/tools/search-contact-tool.js +10 -64
  191. package/dist/src/tools/search-email-tool.d.ts +25 -0
  192. package/dist/src/tools/search-email-tool.js +136 -0
  193. package/dist/src/tools/search-file-tool.d.ts +16 -1
  194. package/dist/src/tools/search-file-tool.js +17 -77
  195. package/dist/src/tools/search-message-tool.d.ts +16 -1
  196. package/dist/src/tools/search-message-tool.js +10 -67
  197. package/dist/src/tools/search-note-tool.d.ts +16 -1
  198. package/dist/src/tools/search-note-tool.js +12 -31
  199. package/dist/src/tools/search-photo-gallery-tool.d.ts +21 -1
  200. package/dist/src/tools/search-photo-gallery-tool.js +18 -68
  201. package/dist/src/tools/send-command-to-car-tool.d.ts +5 -0
  202. package/dist/src/tools/send-command-to-car-tool.js +85 -0
  203. package/dist/src/tools/send-cross-device-task-tool.d.ts +35 -0
  204. package/dist/src/tools/send-cross-device-task-tool.js +365 -0
  205. package/dist/src/tools/send-email-tool.d.ts +27 -0
  206. package/dist/src/tools/send-email-tool.js +135 -0
  207. package/dist/src/tools/send-file-to-user-tool.d.ts +20 -1
  208. package/dist/src/tools/send-file-to-user-tool.js +47 -60
  209. package/dist/src/tools/send-html-card-tool.d.ts +25 -0
  210. package/dist/src/tools/send-html-card-tool.js +111 -0
  211. package/dist/src/tools/send-message-tool.d.ts +20 -1
  212. package/dist/src/tools/send-message-tool.js +12 -64
  213. package/dist/src/tools/session-helper.d.ts +24 -0
  214. package/dist/src/tools/session-helper.js +45 -0
  215. package/dist/src/tools/session-manager.d.ts +35 -28
  216. package/dist/src/tools/session-manager.js +138 -132
  217. package/dist/src/tools/timestamp-to-utc8-tool.d.ts +12 -0
  218. package/dist/src/tools/timestamp-to-utc8-tool.js +104 -0
  219. package/dist/src/tools/upload-file-tool.d.ts +20 -1
  220. package/dist/src/tools/upload-file-tool.js +16 -65
  221. package/dist/src/tools/upload-photo-tool.d.ts +20 -1
  222. package/dist/src/tools/upload-photo-tool.js +14 -57
  223. package/dist/src/tools/view-push-result-tool.js +0 -11
  224. package/dist/src/tools/xiaoyi-add-collection-tool.d.ts +35 -0
  225. package/dist/src/tools/xiaoyi-add-collection-tool.js +192 -0
  226. package/dist/src/tools/xiaoyi-append-reference.d.ts +47 -0
  227. package/dist/src/tools/xiaoyi-append-reference.js +107 -0
  228. package/dist/src/tools/xiaoyi-collection-tool.d.ts +20 -1
  229. package/dist/src/tools/xiaoyi-collection-tool.js +54 -97
  230. package/dist/src/tools/xiaoyi-delete-collection-tool.d.ts +18 -0
  231. package/dist/src/tools/xiaoyi-delete-collection-tool.js +162 -0
  232. package/dist/src/tools/xiaoyi-gui-tool.d.ts +16 -1
  233. package/dist/src/tools/xiaoyi-gui-tool.js +23 -44
  234. package/dist/src/trigger-handler.d.ts +3 -0
  235. package/dist/src/trigger-handler.js +38 -53
  236. package/dist/src/types.d.ts +25 -1
  237. package/dist/src/utils/config-manager.d.ts +3 -2
  238. package/dist/src/utils/config-manager.js +25 -8
  239. package/dist/src/utils/cron-push-map.d.ts +26 -0
  240. package/dist/src/utils/cron-push-map.js +131 -0
  241. package/dist/src/utils/logger.d.ts +8 -0
  242. package/dist/src/utils/logger.js +128 -18
  243. package/dist/src/utils/pushdata-manager.js +1 -5
  244. package/dist/src/utils/pushid-manager.js +1 -2
  245. package/dist/src/utils/runtime-manager.d.ts +7 -0
  246. package/dist/src/utils/runtime-manager.js +61 -0
  247. package/dist/src/utils/self-evolution-manager.d.ts +10 -0
  248. package/dist/src/utils/self-evolution-manager.js +69 -0
  249. package/dist/src/utils/skills-logger.d.ts +5 -0
  250. package/dist/src/utils/skills-logger.js +76 -0
  251. package/dist/src/utils/throw.d.ts +5 -0
  252. package/dist/src/utils/throw.js +10 -0
  253. package/dist/src/utils/tool-call-nudge-manager.d.ts +16 -0
  254. package/dist/src/utils/tool-call-nudge-manager.js +47 -0
  255. package/dist/src/websocket.d.ts +7 -1
  256. package/dist/src/websocket.js +384 -52
  257. package/dist/src/xy-session-store.d.ts +79 -0
  258. package/dist/src/xy-session-store.js +153 -0
  259. package/openclaw.plugin.json +26 -0
  260. package/package.json +9 -8
  261. package/dist/src/tools/search-photo-tool.d.ts +0 -9
  262. package/dist/src/tools/search-photo-tool.js +0 -270
  263. package/dist/src/utils/session.d.ts +0 -34
  264. package/dist/src/utils/session.js +0 -50
package/dist/index.d.ts CHANGED
@@ -1,16 +1,3 @@
1
- import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
2
- import { xyPlugin } from "./src/channel.js";
3
- /**
4
- * Xiaoyi Channel Plugin Entry Point.
5
- * Exports the plugin for OpenClaw to load.
6
- * Located at root level following feishu pattern for proper plugin registration.
7
- */
8
- declare const plugin: {
9
- id: string;
10
- name: string;
11
- description: string;
12
- configSchema: import("openclaw/plugin-sdk").OpenClawPluginConfigSchema;
13
- register(api: OpenClawPluginApi): void;
14
- };
1
+ import { type OpenClawPluginDefinition } from "openclaw/plugin-sdk/core";
2
+ declare const plugin: OpenClawPluginDefinition;
15
3
  export default plugin;
16
- export { xyPlugin };
package/dist/index.js CHANGED
@@ -1,21 +1,383 @@
1
- import { emptyPluginConfigSchema } from "openclaw/plugin-sdk";
1
+ import { definePluginEntry } from "openclaw/plugin-sdk/core";
2
+ import { xiaoyiProvider } from "./src/provider.js";
3
+ import { xiaoyiCompactionProvider } from "./src/compaction-provider.js";
2
4
  import { xyPlugin } from "./src/channel.js";
5
+ import registerSentinelHook from "./src/cspl/sentinel_hook.js";
3
6
  import { setXYRuntime } from "./src/runtime.js";
7
+ import { markCronToolCall, clearCronToolCall, getCurrentSessionContext } from "./src/tools/session-manager.js";
8
+ import { configManager } from "./src/utils/config-manager.js";
9
+ import { setJobPushId } from "./src/utils/cron-push-map.js";
10
+ import { getAllPushIds } from "./src/utils/pushid-manager.js";
11
+ import { registerSelfEvolutionToolResultNudge } from "./src/self-evolution-tool-result-nudge.js";
12
+ import { createBeforePromptBuildHandler } from "./src/skill-retriever/hooks.js";
13
+ import { normalizeToolRetrieverConfig } from "./src/skill-retriever/config.js";
14
+ import { registerCLIHook } from "./src/tools/hmos-cli.js";
15
+ import { recoverCronState } from "./src/cron-recovery.js";
16
+ import { writeSkillUsage } from "./src/utils/skills-logger.js";
17
+ import { markSubagentSpawned, markSubagentEnded, getCachedXYConfig, } from "./src/subagent-wait-state.js";
18
+ import { logger } from "./src/utils/logger.js";
4
19
  /**
5
- * Xiaoyi Channel Plugin Entry Point.
6
- * Exports the plugin for OpenClaw to load.
7
- * Located at root level following feishu pattern for proper plugin registration.
20
+ * Parse a file path string to detect if it refers to a SKILL.md file within
21
+ * a skills directory. Returns the skill name (parent directory) if so.
22
+ *
23
+ * Matches paths like:
24
+ * ~/.openclaw/workspace/skills/my-skill/SKILL.md
25
+ * /home/user/core_skills/my-skill/SKILL.md
26
+ * skills/my-skill/SKILL.md
8
27
  */
9
- const plugin = {
28
+ function extractSkillNameFromPath(filePath) {
29
+ if (typeof filePath !== "string" || !filePath)
30
+ return null;
31
+ // Normalize common path prefixes
32
+ const normalized = filePath.replace(/^~\//, "/home/").replace(/\\/g, "/");
33
+ // Match: .../skills/<skillName>/SKILL.md or .../skills/<skillName>/...
34
+ // Also match: .../core_skills/<skillName>/SKILL.md
35
+ const match = normalized.match(/\/(?:core_)?skills\/([^/]+)\/SKILL\.md$/i);
36
+ return match ? match[1] : null;
37
+ }
38
+ /**
39
+ * Register the skills diagnostic event listener via after_tool_call hook.
40
+ *
41
+ * When openclaw fires a `skill.used` diagnostic event, the skill's SKILL.md
42
+ * is typically read by the model first. We detect SKILL.md reads through
43
+ * the `after_tool_call` hook and write the skill name to the skills log.
44
+ */
45
+ function registerSkillsDiagnosticHook(api) {
46
+ api.on("after_tool_call", async (event, _ctx) => {
47
+ if (event.toolName !== "read")
48
+ return;
49
+ const skillName = extractSkillNameFromPath(event.params?.path);
50
+ if (skillName) {
51
+ writeSkillUsage(skillName);
52
+ }
53
+ });
54
+ }
55
+ /**
56
+ * Register the cron detection hook.
57
+ *
58
+ * When openclaw's cron runner triggers a tool call, the sessionKey has the
59
+ * format "cron:<jobId>". We use this to mark the toolCallId in a global Map
60
+ * so that sendCommand() can route the command through the push channel
61
+ * instead of the (non-existent) WebSocket session.
62
+ */
63
+ function registerCronDetectionHook(api) {
64
+ api.on("before_tool_call", async (event, ctx) => {
65
+ if (ctx.sessionKey?.startsWith("cron:") && event.toolCallId) {
66
+ markCronToolCall(event.toolCallId);
67
+ }
68
+ });
69
+ api.on("after_tool_call", async (event, ctx) => {
70
+ if (event.toolCallId) {
71
+ clearCronToolCall(event.toolCallId);
72
+ }
73
+ // 捕获对话创建的 cron job:agent 调 cron(add) 后,从 result 拿 jobId,
74
+ // 配合当前会话的 pushId,写入 jobId↔pushId 映射,供 fire 时反查设备。
75
+ await captureCronAddMapping(event, ctx).catch((err) => {
76
+ // 捕获失败不影响工具结果
77
+ console.error("[xy] captureCronAddMapping failed:", err);
78
+ });
79
+ });
80
+ }
81
+ /** 从 cron add 工具结果中提取 jobId 并写入 pushId 映射。 */
82
+ async function captureCronAddMapping(event, ctx) {
83
+ // 两条创建路径都要捕获:
84
+ // 1) cron agent 工具:toolName==="cron", params.action==="add"
85
+ // 2) exec 跑 CLI:toolName==="exec", params.command 含 "cron add"
86
+ // (agent 实际用的是这条:openclaw cron add --name ... --cron ... --message ...)
87
+ const isCronAddTool = event.toolName === "cron" &&
88
+ (event.params?.action === "add" || event.params?.action === "create");
89
+ const isExecCronAdd = event.toolName === "exec" && isExecCronAddCommand(event.params?.command);
90
+ if (!isCronAddTool && !isExecCronAdd)
91
+ return;
92
+ console.log(`[CRONMAP] after_tool_call path=${event.toolName}, resultType=${typeof event.result}`);
93
+ const jobId = readJobIdFromResult(event.result);
94
+ if (!jobId) {
95
+ console.log(`[CRONMAP] skip: could not extract jobId. preview=${preview(event.result)}`);
96
+ return;
97
+ }
98
+ console.log(`[CRONMAP] extracted jobId=${jobId}`);
99
+ const sessionCtx = getCurrentSessionContext();
100
+ const sessionId = sessionCtx?.sessionId;
101
+ if (!sessionId) {
102
+ console.log(`[CRONMAP] skip: no sessionId in ALS scope (ctxFound=${!!sessionCtx})`);
103
+ return;
104
+ }
105
+ const pushId = await resolvePushId(sessionId);
106
+ if (!pushId) {
107
+ console.log(`[CRONMAP] skip: no pushId available for sessionId=${sessionId} (no session match, no global, no file)`);
108
+ return;
109
+ }
110
+ console.log(`[CRONMAP] writing map: jobId=${jobId}, sessionId=${sessionId}, pushId=${pushId.substring(0, 16)}...`);
111
+ await setJobPushId(jobId, {
112
+ pushId,
113
+ sessionId,
114
+ deviceType: sessionCtx?.deviceType,
115
+ source: event.toolName === "exec" ? "exec-cli" : "conversation",
116
+ });
117
+ console.log(`[CRONMAP] map written OK`);
118
+ }
119
+ /** 回退链取 pushId:当前会话 → 全局兜底 → 本地文件首个(保底)。 */
120
+ async function resolvePushId(sessionId) {
121
+ // 1. 同会话
122
+ const session = configManager.getPushId(sessionId);
123
+ if (session)
124
+ return session;
125
+ // 2. 全局(任何会话注册过的)
126
+ const global = configManager.getPushId();
127
+ if (global)
128
+ return global;
129
+ // 3. 文件兜底
130
+ try {
131
+ const all = await getAllPushIds();
132
+ if (all.length > 0)
133
+ return all[0];
134
+ }
135
+ catch {
136
+ // ignore
137
+ }
138
+ return null;
139
+ }
140
+ /** 判断 exec 命令是否为 cron add(匹配 "openclaw cron add" 或裸 "cron add",排除 list/remove 等)。 */
141
+ function isExecCronAddCommand(command) {
142
+ if (typeof command !== "string")
143
+ return false;
144
+ return /\bcron\s+add\b/.test(command);
145
+ }
146
+ /** 取结果的短预览,用于诊断。 */
147
+ function preview(value) {
148
+ if (value == null)
149
+ return String(value);
150
+ const s = typeof value === "string" ? value : JSON.stringify(value);
151
+ return s.length > 200 ? s.slice(0, 200) + "…" : s;
152
+ }
153
+ /** 防御性地从 cron add 结果中取 job id。
154
+ * 覆盖:裸 job 对象、JSON 字符串、exec 输出文本、
155
+ * {content:[{text}]} / {stdout} / data/result/job 嵌套。 */
156
+ function readJobIdFromResult(result) {
157
+ if (!result)
158
+ return undefined;
159
+ // {content: [{type:"text", text: "..."}]} — exec 工具的输出信封
160
+ if (result && typeof result === "object") {
161
+ const contentArr = result.content;
162
+ if (Array.isArray(contentArr)) {
163
+ for (const item of contentArr) {
164
+ if (item && typeof item === "object") {
165
+ const text = item.text;
166
+ if (typeof text === "string" && text.trim()) {
167
+ const fromContent = readJobIdFromResult(text);
168
+ if (fromContent)
169
+ return fromContent;
170
+ }
171
+ }
172
+ }
173
+ }
174
+ }
175
+ // {stdout} — 备选 exec 输出信封
176
+ if (result && typeof result === "object") {
177
+ const stdout = result.stdout;
178
+ if (typeof stdout === "string" && stdout.trim()) {
179
+ const fromStdout = readJobIdFromResult(stdout);
180
+ if (fromStdout)
181
+ return fromStdout;
182
+ }
183
+ }
184
+ let obj = result;
185
+ if (typeof result === "string") {
186
+ try {
187
+ obj = JSON.parse(result);
188
+ }
189
+ catch {
190
+ // 纯文本:可能含 stderr 前缀行 + JSON。用正则抓 "id":"..."。
191
+ const m = result.match(/"id"\s*:\s*"([^"]+)"/);
192
+ if (m)
193
+ return m[1];
194
+ return undefined;
195
+ }
196
+ }
197
+ if (obj && typeof obj === "object") {
198
+ const id = obj.id;
199
+ if (typeof id === "string" && id.trim())
200
+ return id.trim();
201
+ for (const k of ["data", "result", "job"]) {
202
+ const inner = obj[k];
203
+ if (inner && typeof inner === "object") {
204
+ const innerId = inner.id;
205
+ if (typeof innerId === "string" && innerId.trim())
206
+ return innerId.trim();
207
+ }
208
+ }
209
+ }
210
+ return undefined;
211
+ }
212
+ // ── Gateway startup: cron state recovery ────────────────────────────────────
213
+ /**
214
+ * Register the gateway_start hook for cron state recovery.
215
+ *
216
+ * On gateway startup, checks .openclaw/cron/ for legacy JSON/JSONL files
217
+ * and migrates them into the SQLite state database:
218
+ * - Reads legacy jobs.json + jobs-state.json → imports into cron_jobs table
219
+ * - Reads legacy runs/*.jsonl → imports into cron_run_logs table
220
+ * - Archives migrated files with .migrated suffix
221
+ *
222
+ * Pattern follows legacy-store-migration.ts and legacy-run-log-migration.ts:
223
+ * check → load → import into SQLite → archive old files.
224
+ */
225
+ function registerCronRecoveryHook(api) {
226
+ api.on("gateway_start", async (_event, _ctx) => {
227
+ const logTag = "[CRON-RECOVERY-HOOK]";
228
+ const startTime = Date.now();
229
+ logger.log(`${logTag} ═══════════════════════════════════════════`);
230
+ logger.log(`${logTag} gateway_start fired — checking for legacy cron files`);
231
+ logger.log(`${logTag} Timestamp: ${new Date().toISOString()}`);
232
+ logger.log(`${logTag} Plugin registration mode: ${api.registrationMode ?? "unknown"}`);
233
+ let result;
234
+ try {
235
+ result = await recoverCronState();
236
+ }
237
+ catch (err) {
238
+ const errMsg = err instanceof Error ? err.message : String(err);
239
+ const errStack = err instanceof Error ? err.stack : undefined;
240
+ logger.error(`${logTag} cron state recovery threw: ${errMsg}`);
241
+ if (errStack)
242
+ logger.error(`${logTag} Stack: ${errStack}`);
243
+ // Don't let a recovery failure block gateway startup.
244
+ logger.log(`${logTag} Recovery failed after ${Date.now() - startTime}ms — gateway startup continues`);
245
+ return;
246
+ }
247
+ const elapsed = Date.now() - startTime;
248
+ if (result.recovered) {
249
+ logger.log(`${logTag} ✅ Migration performed successfully in ${elapsed}ms:` +
250
+ ` storeMigrated=${result.storeMigrated}, ` +
251
+ ` runLogFilesImported=${result.runLogFilesImported}`);
252
+ }
253
+ else {
254
+ logger.log(`${logTag} ℹ️ No legacy cron files migrated in ${elapsed}ms ` +
255
+ `(nothing to migrate or database unavailable)`);
256
+ }
257
+ // Log diagnostics summary
258
+ const warnings = result.diagnostics.filter((d) => d.includes("skipping") || d.includes("locked") || d.includes("unavailable"));
259
+ const errors = result.diagnostics.filter((d) => d.includes("error") || d.includes("failed") || d.includes("Failed"));
260
+ if (warnings.length > 0) {
261
+ logger.warn(`${logTag} ${warnings.length} warning(s) from migration:`);
262
+ for (const w of warnings) {
263
+ logger.warn(`${logTag} ⚠ ${w}`);
264
+ }
265
+ }
266
+ if (errors.length > 0) {
267
+ logger.error(`${logTag} ${errors.length} error(s) from migration:`);
268
+ for (const e of errors) {
269
+ logger.error(`${logTag} ✗ ${e}`);
270
+ }
271
+ }
272
+ if (warnings.length === 0 && errors.length === 0) {
273
+ logger.log(`${logTag} All diagnostics clean, no warnings or errors`);
274
+ }
275
+ logger.log(`${logTag} ═══════════════════════════════════════════`);
276
+ });
277
+ }
278
+ function registerSubagentHooks(api) {
279
+ // subagent_spawned: fires after a subagent run is successfully registered.
280
+ // We increment the expected completion count so that onIdle knows to wait.
281
+ api.on("subagent_spawned", async (_event, ctx) => {
282
+ const requesterSessionKey = ctx?.requesterSessionKey;
283
+ if (!requesterSessionKey)
284
+ return;
285
+ const count = markSubagentSpawned(requesterSessionKey);
286
+ if (count > 0) {
287
+ logger.log(`[XY-SUBAGENT] spawned, requesterSessionKey=${requesterSessionKey.slice(0, 30)}, expected=${count}`);
288
+ }
289
+ });
290
+ // subagent_ended: fires when a subagent run terminates (complete/error/killed).
291
+ // This is the PRIMARY delivery tracking mechanism. When all expected
292
+ // subagents have ended and parent has settled, we finalize the A2A session.
293
+ api.on("subagent_ended", async (event, ctx) => {
294
+ try {
295
+ const requesterSessionKey = ctx?.requesterSessionKey;
296
+ if (!requesterSessionKey) {
297
+ logger.log(`[XY-SUBAGENT-END] no requesterSessionKey in ctx`);
298
+ return;
299
+ }
300
+ const transition = markSubagentEnded(requesterSessionKey);
301
+ logger.log(`[XY-SUBAGENT-END] ended, targetSessionKey=${event?.targetSessionKey?.slice(0, 30)}, outcome=${event?.outcome}, complete=${transition?.isComplete ?? false}, shouldFinalize=${transition?.shouldFinalize ?? false}, transition=${!!transition}`);
302
+ if (transition?.shouldFinalize) {
303
+ logger.log(`[XY-SUBAGENT-END] Starting finalization...`);
304
+ const config = getCachedXYConfig();
305
+ if (!config) {
306
+ logger.error(`[XY-SUBAGENT-END] No cached XY config, cannot deliver final result`);
307
+ return;
308
+ }
309
+ const { deliverSubagentFinalResult } = await import("./src/outbound.js");
310
+ logger.log(`[XY-SUBAGENT-END] Using cached XY config`);
311
+ await deliverSubagentFinalResult({
312
+ config: config,
313
+ state: transition.state,
314
+ reason: "all-subagents-ended-after-parent-settled",
315
+ });
316
+ logger.log(`[XY-SUBAGENT-END] Finalized A2A session after all subagents ended`);
317
+ }
318
+ }
319
+ catch (err) {
320
+ logger.error(`[XY-SUBAGENT-END] Error in subagent_ended hook:`, err);
321
+ }
322
+ });
323
+ }
324
+ function registerFullHooks(api) {
325
+ // SUBAGENT HOOKS: track subagent spawn/end lifecycle for session keep-alive
326
+ registerSubagentHooks(api);
327
+ // SKILL RETRIEVER HOOK: before_prompt_build hook
328
+ const pluginConfig = api.pluginConfig || {};
329
+ const skillRetrieverConfig = normalizeToolRetrieverConfig({
330
+ enabled: pluginConfig.skillRetrieverEnabled ?? true,
331
+ maxTools: pluginConfig.skillRetrieverMaxTools ?? 2,
332
+ includeUninstalledOnly: true,
333
+ envFilePath: "~/.openclaw/.xiaoyienv",
334
+ timeoutMs: pluginConfig.skillRetrieverTimeoutMs ?? 1000,
335
+ });
336
+ const beforePromptBuildHandler = createBeforePromptBuildHandler(skillRetrieverConfig);
337
+ api.on("before_prompt_build", async (event, ctx) => {
338
+ logger.log(`[BEFORE_PROMPT_BUILD] hook fired, sessionKey=${ctx.sessionKey || "undefined"}, sessionId=${ctx.sessionId || "undefined"}`);
339
+ return beforePromptBuildHandler(event, ctx);
340
+ });
341
+ registerSelfEvolutionToolResultNudge(api);
342
+ }
343
+ const plugin = definePluginEntry({
10
344
  id: "xiaoyi-channel",
11
345
  name: "Xiaoyi Channel",
12
346
  description: "Xiaoyi channel plugin - Xiaoyi A2A protocol integration",
13
- configSchema: emptyPluginConfigSchema(),
14
347
  register(api) {
15
- setXYRuntime(api.runtime);
348
+ // Always register the provider so wrapStreamFn/prepareExtraParams work
349
+ // in ALL registration modes (not just "full").
350
+ api.registerProvider(xiaoyiProvider);
351
+ // Register the compaction provider so openclaw's safeguard hook uses
352
+ // our summarization path (which injects x-hag-trace-id) instead of the
353
+ // built-in LLM path that bypasses wrapStreamFn.
354
+ api.registerCompactionProvider(xiaoyiCompactionProvider);
355
+ if (api.registrationMode === "cli-metadata") {
356
+ return;
357
+ }
358
+ if (api.registrationMode === "tool-discovery") {
359
+ registerFullHooks(api);
360
+ return;
361
+ }
362
+ // Register channel plugin and set runtime
16
363
  api.registerChannel({ plugin: xyPlugin });
364
+ setXYRuntime(api.runtime);
365
+ if (api.registrationMode === "discovery") {
366
+ return;
367
+ }
368
+ if (api.registrationMode === "full") {
369
+ registerFullHooks(api);
370
+ // CSPL sentinel hook: before_tool_call + after_tool_call security scanning
371
+ registerSentinelHook(api);
372
+ // Cron detection hook: marks toolCallIds from cron sessions
373
+ registerCronDetectionHook(api);
374
+ // CLI exec hook: intercepts built-in exec for HarmonyOS CLI skill tools
375
+ registerCLIHook(api);
376
+ // Cron recovery hook: prunes stale cron-push-map and pushData on gateway startup
377
+ registerCronRecoveryHook(api);
378
+ // Skills diagnostic hook: log skill usage (detected via SKILL.md reads)
379
+ registerSkillsDiagnosticHook(api);
380
+ }
17
381
  },
18
- };
382
+ });
19
383
  export default plugin;
20
- // Also export the plugin directly for testing
21
- export { xyPlugin };
@@ -0,0 +1,2 @@
1
+ import { xiaoyiProvider } from "./src/provider.js";
2
+ export default xiaoyiProvider;
@@ -0,0 +1,4 @@
1
+ // Provider discovery entry for fast-path provider resolution.
2
+ // Exported as default so normalizeDiscoveryModule can unwrap it via .default.
3
+ import { xiaoyiProvider } from "./src/provider.js";
4
+ export default xiaoyiProvider;
@@ -0,0 +1,37 @@
1
+ import { type BindingTargetKind } from "openclaw/plugin-sdk/conversation-runtime";
2
+ type XyBindingTargetKind = "subagent" | "acp";
3
+ type XyAcpBindingRecord = {
4
+ accountId: string;
5
+ conversationId: string;
6
+ parentConversationId?: string;
7
+ deliveryTo?: string;
8
+ targetKind: XyBindingTargetKind;
9
+ targetSessionKey: string;
10
+ agentId?: string;
11
+ label?: string;
12
+ boundBy?: string;
13
+ boundAt: number;
14
+ lastActivityAt: number;
15
+ };
16
+ type XyAcpBindingManager = {
17
+ accountId: string;
18
+ getByConversationId: (conversationId: string) => XyAcpBindingRecord | undefined;
19
+ listBySessionKey: (targetSessionKey: string) => XyAcpBindingRecord[];
20
+ bindConversation: (params: {
21
+ conversationId: string;
22
+ parentConversationId?: string;
23
+ targetKind: BindingTargetKind;
24
+ targetSessionKey: string;
25
+ metadata?: Record<string, unknown>;
26
+ }) => XyAcpBindingRecord | null;
27
+ touchConversation: (conversationId: string, at?: number) => XyAcpBindingRecord | null;
28
+ unbindConversation: (conversationId: string) => XyAcpBindingRecord | null;
29
+ unbindBySessionKey: (targetSessionKey: string) => XyAcpBindingRecord[];
30
+ stop: () => void;
31
+ };
32
+ export declare function createXyAcpBindingManager(params: {
33
+ accountId?: string;
34
+ cfg: any;
35
+ }): XyAcpBindingManager;
36
+ export declare function getXyAcpBindingManager(accountId?: string): XyAcpBindingManager | null;
37
+ export {};