evolcore 0.0.25 → 0.0.26

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 (231) hide show
  1. package/CHANGELOG.md +607 -565
  2. package/LICENSE +21 -21
  3. package/README.md +455 -455
  4. package/bin/codex-managed-acl.ps1 +160 -160
  5. package/bin/codex-managed-hook.mjs +208 -208
  6. package/bin/ec-safe-output.js +327 -327
  7. package/bin/ec.js +40 -29
  8. package/bin/install-codex-managed-hooks.mjs +582 -555
  9. package/dist/agents/baseagent.js +96 -46
  10. package/dist/agents/claude-runner.js +50 -12
  11. package/dist/agents/codex/app-server-client.js +13 -5
  12. package/dist/agents/codex/catalog.js +1 -1
  13. package/dist/agents/codex/diagnostics.js +34 -1
  14. package/dist/agents/codex-runner.js +121 -38
  15. package/dist/agents/ecagent-runner.js +4 -9
  16. package/dist/agents/gemini-runner.js +2 -7
  17. package/dist/agents/runner-types.js +25 -17
  18. package/dist/aun/aid/agentmd.js +81 -8
  19. package/dist/aun/aid/client.js +1 -1
  20. package/dist/aun/aid/identity.js +1 -1
  21. package/dist/aun/aid/index.js +1 -1
  22. package/dist/aun/aid/store.js +17 -13
  23. package/dist/aun/menu-client.js +74 -0
  24. package/dist/aun/msg/group.js +1 -1
  25. package/dist/aun/msg/managed-operation.js +1 -1
  26. package/dist/aun/msg/p2p.js +6 -1
  27. package/dist/aun/msg/upload.js +30 -22
  28. package/dist/channels/aun.js +329 -94
  29. package/dist/cli/agent-command.js +105 -84
  30. package/dist/cli/agent-create.js +112 -10
  31. package/dist/cli/agent.js +16 -5
  32. package/dist/cli/aun-commands.js +297 -296
  33. package/dist/cli/bench.js +20 -20
  34. package/dist/cli/config.js +47 -28
  35. package/dist/cli/contact.js +70 -13
  36. package/dist/cli/ctl-command.js +22 -22
  37. package/dist/cli/daemon-commands.js +105 -40
  38. package/dist/cli/diag.js +31 -0
  39. package/dist/cli/fs-command.js +67 -67
  40. package/dist/cli/handoff-command.js +41 -9
  41. package/dist/cli/index.js +83 -77
  42. package/dist/cli/link-rules.js +21 -21
  43. package/dist/cli/managed-command-guard.js +3 -0
  44. package/dist/cli/menu-client.js +46 -31
  45. package/dist/cli/net-check.js +22 -22
  46. package/dist/cli/queue-command.js +29 -29
  47. package/dist/cli/response.js +30 -30
  48. package/dist/cli/restart-monitor.js +87 -40
  49. package/dist/cli/stats.js +51 -51
  50. package/dist/cli/trigger-command.js +56 -56
  51. package/dist/config/builtin-roles.js +1 -0
  52. package/dist/config/config-operation-service.js +145 -0
  53. package/dist/config/contact-operation-service.js +96 -7
  54. package/dist/config/resolved-config-op.js +27 -7
  55. package/dist/core/agent-application-service.js +2 -1
  56. package/dist/core/auth/authorization-audit.js +20 -12
  57. package/dist/core/auth/operation-authorizer.js +25 -4
  58. package/dist/core/auth/operation-catalog.js +35 -4
  59. package/dist/core/auth/remote-access-store.js +40 -1
  60. package/dist/core/bootstrap-service.js +1 -1
  61. package/dist/core/command/command-handler.js +83 -26
  62. package/dist/core/command/diag-service.js +118 -0
  63. package/dist/core/command/menu-catalog.js +12 -3
  64. package/dist/core/command/menu-handler.js +47 -26
  65. package/dist/core/command/menu-protocol.js +5 -0
  66. package/dist/core/command/menu-token-store.js +41 -8
  67. package/dist/core/command/slash-gate.js +34 -4
  68. package/dist/core/command/slash-handler.js +86 -21
  69. package/dist/core/handoff/runtime.js +205 -27
  70. package/dist/core/handoff/store.js +193 -4
  71. package/dist/core/message/im-renderer.js +72 -21
  72. package/dist/core/message/message-bridge.js +69 -9
  73. package/dist/core/message/message-queue.js +26 -0
  74. package/dist/core/message/message-utils.js +1 -0
  75. package/dist/core/message/response-engine.js +47 -28
  76. package/dist/core/model/catalog-service.js +79 -49
  77. package/dist/core/model/context-window-suffix.js +33 -0
  78. package/dist/core/model/model-catalog.js +1 -1
  79. package/dist/core/model/model-permission.js +12 -3
  80. package/dist/core/permission/ec-command-parser.js +51 -12
  81. package/dist/core/permission/sandbox-runtime.js +36 -14
  82. package/dist/core/permission/tool-policy.js +2 -1
  83. package/dist/index.js +280 -163
  84. package/dist/ipc.js +54 -2
  85. package/dist/response-system/engines/v1/proactive-flow.js +59 -2
  86. package/dist/stats/billing.js +41 -15
  87. package/dist/stats/db.js +159 -159
  88. package/dist/stats/eck-vars.js +9 -9
  89. package/dist/stats/price-resolver.js +28 -10
  90. package/dist/stats/query.js +139 -139
  91. package/dist/stats/role-budget.js +6 -6
  92. package/dist/stats/writer.js +51 -51
  93. package/dist/utils/cross-platform.js +30 -1
  94. package/dist/utils/error-dict.json +160 -160
  95. package/dist/utils/error-utils.js +21 -0
  96. package/dist/utils/evolcore-version.js +129 -0
  97. package/dist/utils/logger.js +3 -1
  98. package/dist/utils/macos-autostart.js +22 -22
  99. package/dist/utils/model-prices.jsonl +23 -23
  100. package/dist/utils/npm-ops.js +176 -35
  101. package/dist/utils/welcome.js +22 -22
  102. package/ecagent/LICENSE +21 -21
  103. package/ecagent/NOTICE +11 -11
  104. package/ecagent/README.md +61 -61
  105. package/ecagent/dist/harness/compaction/branch-summarization.js +30 -30
  106. package/ecagent/dist/harness/compaction/compaction.js +83 -83
  107. package/ecagent/dist/harness/messages.js +7 -7
  108. package/kits/docs/GUIDE.md +20 -20
  109. package/kits/docs/INDEX.md +66 -66
  110. package/kits/docs/aun/CHEATSHEET.md +19 -19
  111. package/kits/docs/aun/SYNC_PROTOCOL.md +15 -15
  112. package/kits/docs/channels/aun.md +56 -56
  113. package/kits/docs/channels/feishu.md +56 -56
  114. package/kits/docs/context-assembly.md +364 -364
  115. package/kits/docs/eck_templates/GUIDE.template.md +22 -22
  116. package/kits/docs/eck_templates/INDEX.template.md +28 -28
  117. package/kits/docs/eck_templates/path-registry.template.md +33 -33
  118. package/kits/docs/eck_templates/runtime.template.md +19 -19
  119. package/kits/docs/evolcore/INDEX.md +71 -71
  120. package/kits/docs/evolcore/agent-create.md +170 -165
  121. package/kits/docs/evolcore/agent.md +66 -66
  122. package/kits/docs/evolcore/aid.md +60 -60
  123. package/kits/docs/evolcore/codex-windows-sandbox.md +146 -146
  124. package/kits/docs/evolcore/config.md +202 -195
  125. package/kits/docs/evolcore/contact.md +75 -68
  126. package/kits/docs/evolcore/ctl.md +46 -46
  127. package/kits/docs/evolcore/event.md +216 -216
  128. package/kits/docs/evolcore/fs-architecture.md +1215 -1215
  129. package/kits/docs/evolcore/fs.md +110 -110
  130. package/kits/docs/evolcore/group-collaboration.md +243 -243
  131. package/kits/docs/evolcore/group-fs.md +17 -17
  132. package/kits/docs/evolcore/group-rules.md +251 -251
  133. package/kits/docs/evolcore/group.md +152 -152
  134. package/kits/docs/evolcore/menu-client.md +42 -34
  135. package/kits/docs/evolcore/model.md +50 -50
  136. package/kits/docs/evolcore/msg.md +166 -165
  137. package/kits/docs/evolcore/response.md +75 -75
  138. package/kits/docs/evolcore/rpc.md +37 -37
  139. package/kits/docs/evolcore/self-summary.md +29 -29
  140. package/kits/docs/evolcore/stats.md +83 -83
  141. package/kits/docs/evolcore/storage.md +50 -50
  142. package/kits/docs/evolcore/trigger.md +575 -575
  143. package/kits/docs/identity/AID_PROFILE_SPEC.md +26 -26
  144. package/kits/docs/identity/PATH_OPS.md +16 -16
  145. package/kits/docs/identity/ROLE_DETAIL.md +25 -25
  146. package/kits/docs/identity/identity-tools.md +26 -26
  147. package/kits/docs/path-registry.md +62 -62
  148. package/kits/docs/prompt-loading-architecture.md +269 -269
  149. package/kits/docs/venues/aun-group.md +45 -45
  150. package/kits/docs/venues/aun-private.md +10 -10
  151. package/kits/docs/venues/client-desktop.md +10 -10
  152. package/kits/docs/venues/client-mobile.md +10 -10
  153. package/kits/docs/venues/feishu-group.md +13 -13
  154. package/kits/docs/venues/feishu-private.md +9 -9
  155. package/kits/docs/venues/group.md +37 -25
  156. package/kits/docs/venues/private.md +10 -10
  157. package/kits/eck_manifest.auxiliary.json +43 -43
  158. package/kits/eck_manifest.json +190 -190
  159. package/kits/eck_message_manifest.json +74 -74
  160. package/kits/migrations/README-role-config-v4.md +32 -32
  161. package/kits/migrations/migrate-contact-book-v2.mjs +748 -748
  162. package/kits/migrations/migrate-role-config-v4.mjs +614 -614
  163. package/kits/migrations/migrate-role-config-v5.mjs +365 -365
  164. package/kits/migrations/rename-config-file.mjs +99 -99
  165. package/kits/rules/01-overview.md +162 -162
  166. package/kits/rules/02-navigation.md +96 -96
  167. package/kits/rules/03-identity.md +36 -36
  168. package/kits/rules/04-relation.md +75 -75
  169. package/kits/rules/05-venue.md +60 -60
  170. package/kits/rules/06-channel.md +63 -63
  171. package/kits/schemas/_meta.json +53 -53
  172. package/kits/schemas/agent-config.schema.1.json +177 -177
  173. package/kits/schemas/agent-config.schema.10.json +395 -395
  174. package/kits/schemas/agent-config.schema.11.json +421 -421
  175. package/kits/schemas/agent-config.schema.12.json +427 -427
  176. package/kits/schemas/agent-config.schema.2.json +239 -239
  177. package/kits/schemas/agent-config.schema.3.json +119 -119
  178. package/kits/schemas/agent-config.schema.4.json +208 -208
  179. package/kits/schemas/agent-config.schema.5.json +326 -326
  180. package/kits/schemas/agent-config.schema.6.json +322 -322
  181. package/kits/schemas/agent-config.schema.7.json +303 -303
  182. package/kits/schemas/agent-config.schema.8.json +304 -304
  183. package/kits/schemas/agent-config.schema.9.json +364 -364
  184. package/kits/schemas/contact-book.schema.1.json +36 -36
  185. package/kits/schemas/contact-book.schema.2.json +43 -43
  186. package/kits/schemas/contact-book.schema.3.json +67 -67
  187. package/kits/schemas/daemon.schema.1.json +91 -91
  188. package/kits/schemas/daemon.schema.2.json +101 -101
  189. package/kits/schemas/daemon.schema.3.json +123 -123
  190. package/kits/schemas/daemon.schema.4.json +136 -136
  191. package/kits/schemas/daemon.schema.5.json +135 -135
  192. package/kits/schemas/daemon.schema.6.json +131 -131
  193. package/kits/schemas/defaults.schema.1.json +81 -81
  194. package/kits/schemas/defaults.schema.2.json +85 -85
  195. package/kits/schemas/defaults.schema.3.json +73 -73
  196. package/kits/schemas/defaults.schema.4.json +107 -107
  197. package/kits/schemas/defaults.schema.5.json +119 -119
  198. package/kits/schemas/menu-exec-schema-commands.md +208 -208
  199. package/kits/schemas/migrations/README.md +30 -30
  200. package/kits/schemas/relation-config.schema.1.json +158 -158
  201. package/kits/schemas/relation-config.schema.2.json +73 -73
  202. package/kits/schemas/relation-config.schema.3.json +50 -50
  203. package/kits/schemas/relation-config.schema.4.json +47 -47
  204. package/kits/schemas/relation-config.schema.5.json +47 -47
  205. package/kits/schemas/relation-config.schema.6.json +46 -46
  206. package/kits/schemas/relation-config.schema.7.json +59 -59
  207. package/kits/schemas/relation-config.schema.8.json +103 -103
  208. package/kits/schemas/role-config.schema.1.json +201 -201
  209. package/kits/schemas/role-registry.schema.1.json +35 -35
  210. package/kits/schemas/single-session.schema.1.json +31 -31
  211. package/kits/schemas/single-session.schema.2.json +57 -57
  212. package/kits/schemas/single-session.schema.3.json +32 -32
  213. package/kits/templates/bootstrap-welcome.md +17 -17
  214. package/kits/templates/message-fragments/handoff-context-to-target.md +9 -9
  215. package/kits/templates/message-fragments/handoff-request-to-target.md +19 -19
  216. package/kits/templates/message-fragments/handoff-response-to-origin.md +9 -9
  217. package/kits/templates/message-fragments/inject-default.md +2 -2
  218. package/kits/templates/message-fragments/item.md +2 -2
  219. package/kits/templates/roles/admin.json +92 -92
  220. package/kits/templates/roles/member.json +96 -96
  221. package/kits/templates/roles/owner.json +9 -9
  222. package/kits/templates/roles/visitor.json +85 -85
  223. package/kits/templates/system-fragments/baseagent.md +14 -14
  224. package/kits/templates/system-fragments/bootstrap.md +31 -29
  225. package/kits/templates/system-fragments/channel.md +64 -64
  226. package/kits/templates/system-fragments/commands.md +28 -28
  227. package/kits/templates/system-fragments/identity.md +13 -13
  228. package/kits/templates/system-fragments/relation.md +19 -19
  229. package/kits/templates/system-fragments/session.md +59 -59
  230. package/kits/templates/system-fragments/venue.md +31 -31
  231. package/package.json +100 -98
@@ -1,575 +1,575 @@
1
- # ec trigger - 定时与事件触发器
2
-
3
- 创建、查看、启停、删除和手动运行本机 daemon 管理的 trigger。触发词:触发器/定时任务/cron/提醒/定时检查/自动执行/巡检/禁用 trigger/删除 trigger。
4
-
5
- > `ec trigger` 通过 daemon IPC 直接操作 TriggerRuntimeScheduler。agent 会话内省略 `--agent` 时,CLI 使用当前任务上下文里的 agent AID;只有跨身份操作或脱离 agent 会话执行时才需要显式传 `--agent <aid>`。
6
-
7
- ## 什么时候用
8
-
9
- - 用户要求“稍后/每天/每小时/定时/周期性”执行任务
10
- - 需要无人值守巡检、升级检查、日报、仓库同步
11
- - 需要基于系统事件触发时,先读 `evolcore/event.md`
12
- - 需要一次性立即排队执行时,使用 `--once`
13
-
14
- 不要用 trigger 代替当前会话内的即时动作;一次性马上执行直接处理当前请求。
15
-
16
- ## 查询
17
-
18
- ```bash
19
- ec trigger list
20
- ec trigger list --all
21
- ec trigger show <triggerId>
22
- ec trigger show <triggerId> --json
23
- ec trigger history [triggerId]
24
- ec trigger history [triggerId] --limit 500 --json
25
- ```
26
-
27
- `list` 默认只显示 enabled trigger。排查历史、禁用项或已达到 limits 的 trigger 时加 `--all`。
28
-
29
- `list --json` 返回列表摘要,不返回完整 definition。每项只包含 `id/name/enabled/description`、精简后的 `source`、`execution.type`、`feedback.strategy/target`、`nextFireAt`、最近运行状态和 `updatedAt`。event source 只返回 `eventPattern`,不返回 `filter`;不会返回 prompt/script 参数、model、effort、permissionMode、反馈分支模板、reliability、limits 或 origin。
30
-
31
- `show --json` 返回完整 definition、definition `revision` 和精简运行态。active run 只包含标识、阶段、时间和 `eventCount`;schedule 不返回 `sourceSignature`;recent runs 只包含状态与时间摘要;script 只返回路径、runtime、大小和 mtime,不内联脚本文本。完整运行审计使用 `history` 查询。
32
-
33
- `history` 查询 `data/triggers/<aid>/history.jsonl` 中的长期审计事件,包括定义创建、完整更新快照、启停、删除 tombstone 和 run 终态。删除 trigger 目录后,历史仍保留。
34
-
35
- ## 创建
36
-
37
- 创建操作统一使用 `create`:
38
-
39
- | 入口 | 正式命令 | 兼容别名 |
40
- | --- | --- | --- |
41
- | CLI | `ec trigger create ...` | `ec trigger set ...` |
42
- | Slash | `/trigger create ...` | `/trigger set ...` |
43
- | Menu Protocol | `menu.action name=trigger action=create` | `action=set` |
44
-
45
- 新调用只使用 `create`;`set` 仅用于兼容旧脚本和旧客户端。三种入口最终都映射到内部操作 `trigger.create`。
46
-
47
- Flag 模式适合 agent 现场创建常规 trigger:
48
-
49
- ```bash
50
- ec trigger create \
51
- --cron '0 9 * * *' \
52
- --exec target-session \
53
- --prompt '生成昨日摘要并发送给我' \
54
- --target-channel <channelKey> --target-channel-id <channelId> \
55
- --target-session main \
56
- --model <model> --effort high \
57
- --name daily-summary \
58
- --enable
59
- ```
60
-
61
- CLI flag 模式必须显式指定 `--exec`、`--target-channel` 和 `--target-channel-id`,并生成 `feedback.strategy=target`。需要 `origin` 或 `silent` feedback 时,用 `/trigger` 或 `--exec <type> --file <trigger.json|trigger-dir>` 导入 Trigger V3 第二阶段 JSON;CLI 会校验 `--exec` 与 JSON 的 `execution.type` 一致。
62
-
63
- 多行或复杂 prompt 使用 `--prompt-file <path>`,文件内容会原样作为 prompt(UTF-8 BOM 会移除)。内联 `--prompt` 最多 4096 个字符;超限时 CLI 会提示改用 `--prompt-file <path>`:
64
-
65
- ```bash
66
- ec trigger create --cron '0 9 * * *' \
67
- --exec target-session \
68
- --prompt-file ./prompts/daily-summary.md \
69
- --target-channel <channelKey> --target-channel-id <channelId> \
70
- --name daily-summary --enable
71
-
72
- ec trigger update <triggerId> --prompt-file ./prompts/daily-summary-v2.md
73
- ```
74
-
75
- `--file` 始终表示导入完整的 `trigger.json` 或 trigger 目录;`--prompt-file` 只表示 prompt 正文。所有 `create` 形式都必须显式指定 `--exec`;`--prompt-file` 与 `--prompt` 互斥,且不能和 `--file` 同时使用。
76
-
77
- 模型通过 Bash 调用 CLI 且用双引号传递 `--prompt` 时,正文中的双引号、反引号和 Shell 变量形式的 `$` 需要分别写成 `\"`、反斜杠+反引号、`\$`。Shell 会在启动 `ec` 时去掉保护反斜杠,Trigger 中保存的仍是原始正文。
78
-
79
- 支持的触发来源:
80
-
81
- ```bash
82
- --once
83
- --delay 30m
84
- --at 2026-06-28T09:00:00+08:00
85
- --cron '0 9 * * *'
86
- --every 4h
87
- --event 'message:received'
88
- ```
89
-
90
- 这些来源互斥,只能指定一个。`--cron` 表达式必须加引号,避免被 shell 拆成多个参数。`--every` 是固定间隔,`--cron` 是日历调度。`--once` 创建后立即进入一次 run,完成后自动禁用。
91
-
92
- `--event` 基于 EventBus 事件触发,事件模式支持精确事件名、命名空间前缀和全量:`message:received`、`message:*`、`*`。flag 模式只支持设置 `eventPattern`;需要按 payload 字段过滤时,使用 Trigger V3 第二阶段 JSON 的 `source.filter.match`,再通过 `--file` 导入。事件清单、payload 字段和过滤操作见 `$KITS_DOCS/evolcore/event.md`。
93
-
94
- ## 执行类型
95
-
96
- Trigger V3 第二阶段使用 `execution.type` 区分执行位置:
97
-
98
- ```bash
99
- --exec script
100
- --exec trigger-session
101
- --exec target-session
102
- ```
103
-
104
- `target-session` 把 `--prompt` 或 `--prompt-file` 的内容当作一条 trigger 来源消息投递进目标会话队列,并等待该会话处理完成。创建时必须显式指定 `--exec target-session`,不会再隐式选择该类型。
105
-
106
- `trigger-session` 在 daemon 内部 trigger 会话执行 prompt,再把最终结果按 feedback 投递;prompt 可来自 `--prompt` 或 `--prompt-file`:
107
-
108
- ```bash
109
- --exec trigger-session \
110
- --prompt '检查服务状态并总结异常' \
111
- --trigger-thread per-run
112
- ```
113
-
114
- 省略 `--trigger-thread` 时默认使用 `by-trigger`,同一个 trigger 复用同一条 trigger 会话;只有显式指定 `--trigger-thread per-run` 时,每次 run 才使用独立 trigger 会话。
115
-
116
- `script` 执行随 trigger 一起保存的脚本:
117
-
118
- ```bash
119
- --exec script \
120
- --script-path scripts/check.js \
121
- --script-runtime node \
122
- --script-timeout 30s \
123
- --script-args '{"scope":"daily"}'
124
- ```
125
-
126
- `script` 不使用 `--prompt` 或 `--prompt-file`;它必须使用 `--script-path` 和 `--script-runtime`。脚本路径必须在 trigger 目录内;通过 `--file` 导入目录时,脚本文件会随 definition 一起上传。已有 script trigger 的 `update --prompt-file` 会被拒绝,脚本正文使用 `update --script-file` 替换。
127
-
128
- ## 目标与反馈
129
-
130
- 目标会话字段:
131
-
132
- ```bash
133
- --target-channel <channelKey>
134
- --target-channel-id <channelId>
135
- --target-chat-type <private|group>
136
- --target-session main
137
- --target-session thread --target-thread-id <threadId>
138
- ```
139
-
140
- AUN 渠道由 agent AID 隐式创建,不需要写入 agent 配置的 `channels[]`。CLI 和 Trigger V3.1 definition 均可将 `aun` 用作 `channelKey` 简写;保存前会按 `agentAid` 展开为 `aun#<agentAid>#main`。AUN 目标必须明确设置 `chatType`;`channelId` 在私聊时是对端 ID,在群聊时就是群 ID,不再额外保存 `groupId`。读取缺少 `chatType` 的旧 AUN Trigger definition 时,迁移逻辑会仅在该次迁移中按 `private` 补齐并回写;新建和编辑仍要求显式指定。其他渠道仍需指定完整的实例 channel key。
141
-
142
- ```json
143
- {
144
- "strategy": "target",
145
- "target": {
146
- "channelKey": "aun",
147
- "channelId": "peer.agentid.pub",
148
- "chatType": "private",
149
- "session": "main"
150
- }
151
- }
152
- ```
153
-
154
- Trigger V3.1 feedback 是单策略:
155
-
156
- - `origin`:送回创建 trigger 的来源会话
157
- - `target`:送到 `feedback.target`
158
- - `silent`:不投递最终结果
159
-
160
- `target-session` 执行类型只支持 `origin` 或 `target`,因为它本身就是投递到一个会话执行;`script` 和 `trigger-session` 可以使用 `silent`。
161
-
162
- 默认反馈文本:
163
-
164
- - success:`reply.text`
165
- - noop:空文本,不发送
166
- - failure:标准失败文本
167
-
168
- 通常不要显式设置 template。只有 `script` 支持 `feedback.onReply/onNoop/onFailure` 分支模板;`trigger-session` 和 `target-session` 不支持自定义分支模板。
169
-
170
- 可用占位符示例:
171
-
172
- ```text
173
- {{reply.text}}
174
- {{trigger.name}}
175
- {{reply.meta.durationMs}}
176
- {{error.message}}
177
- {{date}} {{time}}
178
- ```
179
-
180
- script trigger 返回 `[[NOOP]]` 或 `outcome: "noop"` 时走 noop 分支;默认 noop 静默。
181
-
182
- ## 模型与权限
183
-
184
- 执行模型可按 trigger 单独覆盖:
185
-
186
- ```bash
187
- --model <模型>
188
- --effort <low|medium|high|xhigh|max>
189
- --baseagent <claude|codex|gemini>
190
- ```
191
-
192
- `--model` / `--effort` 只覆盖本 trigger 执行时传给 base agent 的模型与推理强度。
193
- `--baseagent` 仅支持 `--exec trigger-session`,用于给该 trigger 会话单独选择 base agent;
194
- `script` 和 `target-session` 不接受该参数。未设置时沿用 trigger 所属 agent 当前 active baseagent。
195
-
196
- 无人值守 trigger 不适合 `request`。需要写文件、git、安装升级、重启服务、管理 trigger 时应显式使用:
197
-
198
- ```bash
199
- --permission bypass
200
- ```
201
-
202
- owner/admin 通过 `/trigger create` 创建时默认使用 `bypass`;非 admin 默认 `readonly`,不能提权到 `bypass`,也不能跨渠道或跨会话指定 target。历史 `/trigger set` 仍是兼容别名。
203
-
204
- ## 执行边界
205
-
206
- 周期任务建议设置系统边界,避免无限运行:
207
-
208
- ```bash
209
- --max-runs 10
210
- --max-duration 3d
211
- ```
212
-
213
- 任一边界命中后,scheduler 会禁用后续调度,不中断当前 run。
214
-
215
- ## 管理
216
-
217
- ```bash
218
- ec trigger enable <triggerId>
219
- ec trigger disable <triggerId>
220
- ec trigger cancel <triggerId> # disable 的兼容别名
221
- ec trigger delete <triggerId>
222
- ec trigger remove <triggerId> # delete 的兼容别名
223
- ec trigger rm <triggerId> # delete 的兼容别名
224
- ```
225
-
226
- 语义区别:
227
-
228
- | 命令 | 定义文件 | 后续调度 | 当前 run | 可恢复 |
229
- | --- | --- | --- | --- | --- |
230
- | `disable` / `cancel` | 保留,写 `enabled: false` | 清理 | 不中断 | 可 `enable` |
231
- | `delete` | 删除整个 trigger 运行态目录,保留 history tombstone | 清理 | 不中断 | 定义不可恢复,审计可复查 |
232
-
233
- `delete` 不需要先执行 `disable/cancel`;它内部会先清理 timer/event/schedule,再删除定义。
234
-
235
- ## 局部更新
236
-
237
- `update` 是 patch 语义,只提交需要修改的字段;未指定字段(包括长 prompt)保持不变。`--prompt-file <path>` 只更新非 script trigger 的 prompt,不接受完整 definition。已有 script trigger 使用 `--script-file <path>` 原地替换脚本内容;脚本路径、runtime、args 和调度配置保持不变:
238
-
239
- `--script-file` 只能通过本机受控 CLI 读取文件并提交给 daemon;脚本 trigger 属于 daemon-owner 控制面,managed Agent task 不能直接读取本地脚本文件。
240
-
241
- ```bash
242
- ec trigger update <triggerId> --cron '0 10 * * *'
243
- ec trigger update <triggerId> --prompt '新的任务内容' --name new-name
244
- ec trigger update <triggerId> --prompt-file ./prompts/new-task.md
245
- ec trigger update <triggerId> --script-file ./scripts/check-v2.js
246
- ec trigger update <triggerId> --cron '0 10 * * *' --if-revision 'sha256:...'
247
- ```
248
-
249
- 可更新参数只保留三组常用字段:
250
-
251
- - 调度:`--once`、`--delay`、`--at`、`--cron`、`--every`、`--event`、`--tz`
252
- - 内容:`--prompt` 或 `--prompt-file <path>`、`--name`
253
- - 执行配置:`--model`、`--effort`、`--permission`
254
- - 运行边界:`--max-runs`、`--max-duration`、`--concurrency`、`--missed-policy`
255
-
256
- 脚本的路径、runtime、参数、投递目标、feedback、reliability、limits、event filter 或执行类型需要变化时,删除后重新创建 trigger;仅替换已有脚本正文使用 `--script-file`。
257
-
258
- `--if-revision` 是可选的乐观并发检查;值来自 `show --json` 顶层的 `revision`。revision 不一致时更新失败,不覆盖较新的 definition。
259
-
260
- `--tz` 只对 cron 有效,用 IANA 时区(如 `Asia/Shanghai`、`UTC`)解释 cron;不写时使用运行进程时区。`--concurrency` 控制上一 run 仍在执行时的行为(`forbid`/`replace`/`allow`);`--missed-policy` 控制错过触发时间后的行为(`skip`/`run-once`/`run-all`)。
261
-
262
- `update --json` 返回更新后的列表摘要和新 revision,不回传包含长 prompt 的完整 definition。
263
-
264
- ## 手动运行
265
-
266
- ```bash
267
- ec trigger run <triggerId>
268
- ec trigger run <triggerId> --dry-run
269
- ```
270
-
271
- `--dry-run` 不写 active 状态、不写正式 audit、不执行真实副作用,适合验证 prompt/template。
272
-
273
- ## 审计存储
274
-
275
- ```text
276
- data/triggers/<aid>/<triggerId>/trigger.json
277
- data/triggers/<aid>/<triggerId>/active.json
278
- data/triggers/<aid>/history.jsonl
279
- logs/trigger-runs.log
280
- ```
281
-
282
- - `history.jsonl` 是长期 append-only 审计真相源,默认不自动清理。
283
- - 旧版 done 归档行保持可读,不会在升级时重写。
284
- - `trigger-runs.log` 是短期运维日志,按天轮转并保留 7 天。
285
- - `show` 的 recent run 摘要、运行统计和 `history` 命令读取长期历史。
286
- - 启动时会把仍保留的旧 `trigger-runs*.log` 幂等补导入 `history.jsonl`。
287
-
288
- ## 从文件导入
289
-
290
- 复杂 trigger 使用 Trigger V3 第二阶段 JSON:
291
-
292
- ```bash
293
- ec trigger create --exec target-session --file ./trigger.json --enable
294
- ec trigger create --exec script --file ./trigger-dir --enable
295
- ```
296
-
297
- 当前产品版本是 Trigger V3 第二阶段;其持久化定义版本为 `$schema_version: 3.1`。旧 `$schema_version: 4` 文件加载时会自动规范化为 `3.1`。
298
-
299
- ### target-session 示例
300
-
301
- ```json
302
- {
303
- "$schema_version": 3.1,
304
- "agentAid": "<aid>",
305
- "enabled": true,
306
- "name": "daily-summary",
307
- "source": {
308
- "type": "cron",
309
- "expression": "0 9 * * *",
310
- "timezone": "Asia/Shanghai"
311
- },
312
- "execution": {
313
- "type": "target_session",
314
- "prompt": "生成昨日摘要并发送给我",
315
- "model": "<model>",
316
- "effort": "high",
317
- "permissionMode": "bypass",
318
- "onError": "fail",
319
- "noopSentinel": "[[NOOP]]"
320
- },
321
- "feedback": {
322
- "strategy": "target",
323
- "target": {
324
- "channelKey": "<channelKey>",
325
- "channelId": "<channelId>",
326
- "chatType": "private",
327
- "session": "main"
328
- }
329
- },
330
- "reliability": {
331
- "concurrency": "forbid",
332
- "missedPolicy": "run_once",
333
- "retry": {
334
- "maxAttempts": 0,
335
- "backoffMs": 30000
336
- }
337
- }
338
- }
339
- ```
340
-
341
- ### trigger-session 示例
342
-
343
- ```json
344
- {
345
- "$schema_version": 3.1,
346
- "agentAid": "<aid>",
347
- "enabled": true,
348
- "name": "hourly-health-check",
349
- "origin": {
350
- "channelKey": "<channelKey>",
351
- "channelId": "<channelId>",
352
- "session": "main"
353
- },
354
- "source": {
355
- "type": "interval",
356
- "everyMs": 3600000
357
- },
358
- "execution": {
359
- "type": "trigger_session",
360
- "prompt": "检查服务状态并总结异常;无异常输出 [[NOOP]]",
361
- "thread": "per_run",
362
- "permissionMode": "readonly",
363
- "onError": "retry",
364
- "noopSentinel": "[[NOOP]]"
365
- },
366
- "feedback": {
367
- "strategy": "origin"
368
- },
369
- "reliability": {
370
- "concurrency": "forbid",
371
- "missedPolicy": "run_once",
372
- "retry": {
373
- "maxAttempts": 1,
374
- "backoffMs": 30000
375
- }
376
- }
377
- }
378
- ```
379
-
380
- ### script 示例
381
-
382
- ```json
383
- {
384
- "$schema_version": 3.1,
385
- "agentAid": "<aid>",
386
- "enabled": true,
387
- "name": "script-health",
388
- "source": {
389
- "type": "cron",
390
- "expression": "0 */4 * * *",
391
- "timezone": "Asia/Shanghai"
392
- },
393
- "execution": {
394
- "type": "script",
395
- "script": {
396
- "path": "scripts/health.js",
397
- "runtime": "node",
398
- "timeoutMs": 30000
399
- },
400
- "onError": "retry",
401
- "noopSentinel": "[[NOOP]]"
402
- },
403
- "feedback": {
404
- "strategy": "target",
405
- "target": {
406
- "channelKey": "<channelKey>",
407
- "channelId": "<channelId>",
408
- "chatType": "private",
409
- "session": "main"
410
- },
411
- "onReply": {
412
- "template": "{{reply.text}}"
413
- },
414
- "onNoop": {
415
- "template": ""
416
- },
417
- "onFailure": {
418
- "template": "健康检查失败:{{error.message}}"
419
- }
420
- },
421
- "reliability": {
422
- "concurrency": "forbid",
423
- "missedPolicy": "run_once",
424
- "retry": {
425
- "maxAttempts": 2,
426
- "backoffMs": 30000
427
- }
428
- }
429
- }
430
- ```
431
-
432
- ## 事件触发
433
-
434
- 简单事件触发可直接用 flag 模式:
435
-
436
- ```bash
437
- ec trigger create --event 'message:received' \
438
- --exec target-session \
439
- --prompt '检查收到的消息是否需要自动跟进;无动作输出 [[NOOP]]' \
440
- --target-channel <channelKey> --target-channel-id <channelId> \
441
- --target-session main \
442
- --name on-message-received --enable
443
- ```
444
-
445
- 监听某个命名空间下的所有事件:
446
-
447
- ```bash
448
- ec trigger create --event 'task:*' \
449
- --exec target-session \
450
- --prompt '任务完成或失败后生成简短诊断;无动作输出 [[NOOP]]' \
451
- --target-channel <channelKey> --target-channel-id <channelId> \
452
- --target-session main \
453
- --name on-task-events --enable
454
- ```
455
-
456
- flag 模式不能配置过滤条件。需要根据事件 payload 过滤时,写完整的 Trigger V3 第二阶段 JSON:
457
-
458
- ```json
459
- {
460
- "$schema_version": 3.1,
461
- "agentAid": "<aid>",
462
- "enabled": true,
463
- "name": "on-important-message",
464
- "source": {
465
- "type": "event",
466
- "eventPattern": "message:received",
467
- "filter": {
468
- "match": {
469
- "channel": "<channelKey>",
470
- "channelId": "<channelId>",
471
- "content": { "$regex": "日报|告警|失败" }
472
- }
473
- }
474
- },
475
- "execution": {
476
- "type": "target_session",
477
- "prompt": "根据事件内容判断是否需要处理;无动作输出 [[NOOP]]",
478
- "permissionMode": "readonly",
479
- "onError": "retry",
480
- "noopSentinel": "[[NOOP]]"
481
- },
482
- "feedback": {
483
- "strategy": "target",
484
- "target": {
485
- "channelKey": "<channelKey>",
486
- "channelId": "<channelId>",
487
- "chatType": "private",
488
- "session": "main"
489
- }
490
- },
491
- "reliability": {
492
- "concurrency": "forbid",
493
- "missedPolicy": "run_once",
494
- "retry": {
495
- "maxAttempts": 0,
496
- "backoffMs": 30000
497
- }
498
- }
499
- }
500
- ```
501
-
502
- `source.filter.match` 的 key 是 payload 字段路径,支持等值、`$in`、`$regex`、数值比较和 `$exists`。例如 `message:received` 可过滤 `channel`、`channelId`、`content`、`userId`、`sessionId`;完整字段以事件目录为准。
503
-
504
- ## 常用例子
505
-
506
- 一次性提醒:
507
-
508
- ```bash
509
- ec trigger create --delay 30m \
510
- --exec target-session \
511
- --prompt '提醒用户检查部署状态' \
512
- --target-channel <channelKey> --target-channel-id <channelId> \
513
- --target-session main \
514
- --name deploy-reminder --enable
515
- ```
516
-
517
- 创建后立即执行一次:
518
-
519
- ```bash
520
- ec trigger create --once \
521
- --exec target-session \
522
- --prompt '生成一次当前状态摘要' \
523
- --target-channel <channelKey> --target-channel-id <channelId> \
524
- --target-session main \
525
- --name one-shot-summary --enable
526
- ```
527
-
528
- 每天巡检:
529
-
530
- ```bash
531
- ec trigger create --cron '30 9 * * *' \
532
- --exec target-session \
533
- --prompt '检查服务状态并汇报异常;无异常输出 [[NOOP]]' \
534
- --target-channel <channelKey> --target-channel-id <channelId> \
535
- --target-session main \
536
- --name daily-health-check --enable
537
- ```
538
-
539
- 复用 trigger 会话做周期跟踪:
540
-
541
- ```bash
542
- ec trigger create --every 4h \
543
- --exec trigger-session \
544
- --trigger-thread by-trigger \
545
- --prompt '继续跟踪升级状态并输出最新结论;无变化输出 [[NOOP]]' \
546
- --target-channel <channelKey> --target-channel-id <channelId> \
547
- --target-session main \
548
- --name upgrade-watch --enable
549
- ```
550
-
551
- 定时尝试升级,最多 10 次或 3 天:
552
-
553
- ```bash
554
- ec trigger create --every 4h \
555
- --max-runs 10 --max-duration 3d \
556
- --permission bypass \
557
- --model <model> --effort high \
558
- --exec target-session \
559
- --prompt '尝试执行升级检查;成功后调用 ec trigger disable auto-updater;无变化输出 [[NOOP]]' \
560
- --target-channel <channelKey> --target-channel-id <channelId> \
561
- --target-session main \
562
- --name auto-updater --enable
563
- ```
564
-
565
- 硬删除:
566
-
567
- ```bash
568
- ec trigger delete auto-updater
569
- ```
570
-
571
- ## 相关文档
572
-
573
- - event source 可监听事件:`$KITS_DOCS/evolcore/event.md`
574
- - Trigger V3 第二阶段执行与反馈设计:`$PACKAGE_ROOT/docs/trigger-v3-phase2-execution-feedback-design.md`
575
- - limits / disable / delete 语义:`$PACKAGE_ROOT/docs/trigger-limits-feature-v2.md`
1
+ # ec trigger - 定时与事件触发器
2
+
3
+ 创建、查看、启停、删除和手动运行本机 daemon 管理的 trigger。触发词:触发器/定时任务/cron/提醒/定时检查/自动执行/巡检/禁用 trigger/删除 trigger。
4
+
5
+ > `ec trigger` 通过 daemon IPC 直接操作 TriggerRuntimeScheduler。agent 会话内省略 `--agent` 时,CLI 使用当前任务上下文里的 agent AID;只有跨身份操作或脱离 agent 会话执行时才需要显式传 `--agent <aid>`。
6
+
7
+ ## 什么时候用
8
+
9
+ - 用户要求“稍后/每天/每小时/定时/周期性”执行任务
10
+ - 需要无人值守巡检、升级检查、日报、仓库同步
11
+ - 需要基于系统事件触发时,先读 `evolcore/event.md`
12
+ - 需要一次性立即排队执行时,使用 `--once`
13
+
14
+ 不要用 trigger 代替当前会话内的即时动作;一次性马上执行直接处理当前请求。
15
+
16
+ ## 查询
17
+
18
+ ```bash
19
+ ec trigger list
20
+ ec trigger list --all
21
+ ec trigger show <triggerId>
22
+ ec trigger show <triggerId> --json
23
+ ec trigger history [triggerId]
24
+ ec trigger history [triggerId] --limit 500 --json
25
+ ```
26
+
27
+ `list` 默认只显示 enabled trigger。排查历史、禁用项或已达到 limits 的 trigger 时加 `--all`。
28
+
29
+ `list --json` 返回列表摘要,不返回完整 definition。每项只包含 `id/name/enabled/description`、精简后的 `source`、`execution.type`、`feedback.strategy/target`、`nextFireAt`、最近运行状态和 `updatedAt`。event source 只返回 `eventPattern`,不返回 `filter`;不会返回 prompt/script 参数、model、effort、permissionMode、反馈分支模板、reliability、limits 或 origin。
30
+
31
+ `show --json` 返回完整 definition、definition `revision` 和精简运行态。active run 只包含标识、阶段、时间和 `eventCount`;schedule 不返回 `sourceSignature`;recent runs 只包含状态与时间摘要;script 只返回路径、runtime、大小和 mtime,不内联脚本文本。完整运行审计使用 `history` 查询。
32
+
33
+ `history` 查询 `data/triggers/<aid>/history.jsonl` 中的长期审计事件,包括定义创建、完整更新快照、启停、删除 tombstone 和 run 终态。删除 trigger 目录后,历史仍保留。
34
+
35
+ ## 创建
36
+
37
+ 创建操作统一使用 `create`:
38
+
39
+ | 入口 | 正式命令 | 兼容别名 |
40
+ | --- | --- | --- |
41
+ | CLI | `ec trigger create ...` | `ec trigger set ...` |
42
+ | Slash | `/trigger create ...` | `/trigger set ...` |
43
+ | Menu Protocol | `menu.action name=trigger action=create` | `action=set` |
44
+
45
+ 新调用只使用 `create`;`set` 仅用于兼容旧脚本和旧客户端。三种入口最终都映射到内部操作 `trigger.create`。
46
+
47
+ Flag 模式适合 agent 现场创建常规 trigger:
48
+
49
+ ```bash
50
+ ec trigger create \
51
+ --cron '0 9 * * *' \
52
+ --exec target-session \
53
+ --prompt '生成昨日摘要并发送给我' \
54
+ --target-channel <channelKey> --target-channel-id <channelId> \
55
+ --target-session main \
56
+ --model <model> --effort high \
57
+ --name daily-summary \
58
+ --enable
59
+ ```
60
+
61
+ CLI flag 模式必须显式指定 `--exec`、`--target-channel` 和 `--target-channel-id`,并生成 `feedback.strategy=target`。需要 `origin` 或 `silent` feedback 时,用 `/trigger` 或 `--exec <type> --file <trigger.json|trigger-dir>` 导入 Trigger V3 第二阶段 JSON;CLI 会校验 `--exec` 与 JSON 的 `execution.type` 一致。
62
+
63
+ 多行或复杂 prompt 使用 `--prompt-file <path>`,文件内容会原样作为 prompt(UTF-8 BOM 会移除)。内联 `--prompt` 最多 4096 个字符;超限时 CLI 会提示改用 `--prompt-file <path>`:
64
+
65
+ ```bash
66
+ ec trigger create --cron '0 9 * * *' \
67
+ --exec target-session \
68
+ --prompt-file ./prompts/daily-summary.md \
69
+ --target-channel <channelKey> --target-channel-id <channelId> \
70
+ --name daily-summary --enable
71
+
72
+ ec trigger update <triggerId> --prompt-file ./prompts/daily-summary-v2.md
73
+ ```
74
+
75
+ `--file` 始终表示导入完整的 `trigger.json` 或 trigger 目录;`--prompt-file` 只表示 prompt 正文。所有 `create` 形式都必须显式指定 `--exec`;`--prompt-file` 与 `--prompt` 互斥,且不能和 `--file` 同时使用。
76
+
77
+ 模型通过 Bash 调用 CLI 且用双引号传递 `--prompt` 时,正文中的双引号、反引号和 Shell 变量形式的 `$` 需要分别写成 `\"`、反斜杠+反引号、`\$`。Shell 会在启动 `ec` 时去掉保护反斜杠,Trigger 中保存的仍是原始正文。
78
+
79
+ 支持的触发来源:
80
+
81
+ ```bash
82
+ --once
83
+ --delay 30m
84
+ --at 2026-06-28T09:00:00+08:00
85
+ --cron '0 9 * * *'
86
+ --every 4h
87
+ --event 'message:received'
88
+ ```
89
+
90
+ 这些来源互斥,只能指定一个。`--cron` 表达式必须加引号,避免被 shell 拆成多个参数。`--every` 是固定间隔,`--cron` 是日历调度。`--once` 创建后立即进入一次 run,完成后自动禁用。
91
+
92
+ `--event` 基于 EventBus 事件触发,事件模式支持精确事件名、命名空间前缀和全量:`message:received`、`message:*`、`*`。flag 模式只支持设置 `eventPattern`;需要按 payload 字段过滤时,使用 Trigger V3 第二阶段 JSON 的 `source.filter.match`,再通过 `--file` 导入。事件清单、payload 字段和过滤操作见 `$KITS_DOCS/evolcore/event.md`。
93
+
94
+ ## 执行类型
95
+
96
+ Trigger V3 第二阶段使用 `execution.type` 区分执行位置:
97
+
98
+ ```bash
99
+ --exec script
100
+ --exec trigger-session
101
+ --exec target-session
102
+ ```
103
+
104
+ `target-session` 把 `--prompt` 或 `--prompt-file` 的内容当作一条 trigger 来源消息投递进目标会话队列,并等待该会话处理完成。创建时必须显式指定 `--exec target-session`,不会再隐式选择该类型。
105
+
106
+ `trigger-session` 在 daemon 内部 trigger 会话执行 prompt,再把最终结果按 feedback 投递;prompt 可来自 `--prompt` 或 `--prompt-file`:
107
+
108
+ ```bash
109
+ --exec trigger-session \
110
+ --prompt '检查服务状态并总结异常' \
111
+ --trigger-thread per-run
112
+ ```
113
+
114
+ 省略 `--trigger-thread` 时默认使用 `by-trigger`,同一个 trigger 复用同一条 trigger 会话;只有显式指定 `--trigger-thread per-run` 时,每次 run 才使用独立 trigger 会话。
115
+
116
+ `script` 执行随 trigger 一起保存的脚本:
117
+
118
+ ```bash
119
+ --exec script \
120
+ --script-path scripts/check.js \
121
+ --script-runtime node \
122
+ --script-timeout 30s \
123
+ --script-args '{"scope":"daily"}'
124
+ ```
125
+
126
+ `script` 不使用 `--prompt` 或 `--prompt-file`;它必须使用 `--script-path` 和 `--script-runtime`。脚本路径必须在 trigger 目录内;通过 `--file` 导入目录时,脚本文件会随 definition 一起上传。已有 script trigger 的 `update --prompt-file` 会被拒绝,脚本正文使用 `update --script-file` 替换。
127
+
128
+ ## 目标与反馈
129
+
130
+ 目标会话字段:
131
+
132
+ ```bash
133
+ --target-channel <channelKey>
134
+ --target-channel-id <channelId>
135
+ --target-chat-type <private|group>
136
+ --target-session main
137
+ --target-session thread --target-thread-id <threadId>
138
+ ```
139
+
140
+ AUN 渠道由 agent AID 隐式创建,不需要写入 agent 配置的 `channels[]`。CLI 和 Trigger V3.1 definition 均可将 `aun` 用作 `channelKey` 简写;保存前会按 `agentAid` 展开为 `aun#<agentAid>#main`。AUN 目标必须明确设置 `chatType`;`channelId` 在私聊时是对端 ID,在群聊时就是群 ID,不再额外保存 `groupId`。读取缺少 `chatType` 的旧 AUN Trigger definition 时,迁移逻辑会仅在该次迁移中按 `private` 补齐并回写;新建和编辑仍要求显式指定。其他渠道仍需指定完整的实例 channel key。
141
+
142
+ ```json
143
+ {
144
+ "strategy": "target",
145
+ "target": {
146
+ "channelKey": "aun",
147
+ "channelId": "peer.agentid.pub",
148
+ "chatType": "private",
149
+ "session": "main"
150
+ }
151
+ }
152
+ ```
153
+
154
+ Trigger V3.1 feedback 是单策略:
155
+
156
+ - `origin`:送回创建 trigger 的来源会话
157
+ - `target`:送到 `feedback.target`
158
+ - `silent`:不投递最终结果
159
+
160
+ `target-session` 执行类型只支持 `origin` 或 `target`,因为它本身就是投递到一个会话执行;`script` 和 `trigger-session` 可以使用 `silent`。
161
+
162
+ 默认反馈文本:
163
+
164
+ - success:`reply.text`
165
+ - noop:空文本,不发送
166
+ - failure:标准失败文本
167
+
168
+ 通常不要显式设置 template。只有 `script` 支持 `feedback.onReply/onNoop/onFailure` 分支模板;`trigger-session` 和 `target-session` 不支持自定义分支模板。
169
+
170
+ 可用占位符示例:
171
+
172
+ ```text
173
+ {{reply.text}}
174
+ {{trigger.name}}
175
+ {{reply.meta.durationMs}}
176
+ {{error.message}}
177
+ {{date}} {{time}}
178
+ ```
179
+
180
+ script trigger 返回 `[[NOOP]]` 或 `outcome: "noop"` 时走 noop 分支;默认 noop 静默。
181
+
182
+ ## 模型与权限
183
+
184
+ 执行模型可按 trigger 单独覆盖:
185
+
186
+ ```bash
187
+ --model <模型>
188
+ --effort <low|medium|high|xhigh|max>
189
+ --baseagent <claude|codex|gemini>
190
+ ```
191
+
192
+ `--model` / `--effort` 只覆盖本 trigger 执行时传给 base agent 的模型与推理强度。
193
+ `--baseagent` 仅支持 `--exec trigger-session`,用于给该 trigger 会话单独选择 base agent;
194
+ `script` 和 `target-session` 不接受该参数。未设置时沿用 trigger 所属 agent 当前 active baseagent。
195
+
196
+ 无人值守 trigger 不适合 `request`。需要写文件、git、安装升级、重启服务、管理 trigger 时应显式使用:
197
+
198
+ ```bash
199
+ --permission bypass
200
+ ```
201
+
202
+ owner/admin 通过 `/trigger create` 创建时默认使用 `bypass`;非 admin 默认 `readonly`,不能提权到 `bypass`,也不能跨渠道或跨会话指定 target。历史 `/trigger set` 仍是兼容别名。
203
+
204
+ ## 执行边界
205
+
206
+ 周期任务建议设置系统边界,避免无限运行:
207
+
208
+ ```bash
209
+ --max-runs 10
210
+ --max-duration 3d
211
+ ```
212
+
213
+ 任一边界命中后,scheduler 会禁用后续调度,不中断当前 run。
214
+
215
+ ## 管理
216
+
217
+ ```bash
218
+ ec trigger enable <triggerId>
219
+ ec trigger disable <triggerId>
220
+ ec trigger cancel <triggerId> # disable 的兼容别名
221
+ ec trigger delete <triggerId>
222
+ ec trigger remove <triggerId> # delete 的兼容别名
223
+ ec trigger rm <triggerId> # delete 的兼容别名
224
+ ```
225
+
226
+ 语义区别:
227
+
228
+ | 命令 | 定义文件 | 后续调度 | 当前 run | 可恢复 |
229
+ | --- | --- | --- | --- | --- |
230
+ | `disable` / `cancel` | 保留,写 `enabled: false` | 清理 | 不中断 | 可 `enable` |
231
+ | `delete` | 删除整个 trigger 运行态目录,保留 history tombstone | 清理 | 不中断 | 定义不可恢复,审计可复查 |
232
+
233
+ `delete` 不需要先执行 `disable/cancel`;它内部会先清理 timer/event/schedule,再删除定义。
234
+
235
+ ## 局部更新
236
+
237
+ `update` 是 patch 语义,只提交需要修改的字段;未指定字段(包括长 prompt)保持不变。`--prompt-file <path>` 只更新非 script trigger 的 prompt,不接受完整 definition。已有 script trigger 使用 `--script-file <path>` 原地替换脚本内容;脚本路径、runtime、args 和调度配置保持不变:
238
+
239
+ `--script-file` 只能通过本机受控 CLI 读取文件并提交给 daemon;脚本 trigger 属于 daemon-owner 控制面,managed Agent task 不能直接读取本地脚本文件。
240
+
241
+ ```bash
242
+ ec trigger update <triggerId> --cron '0 10 * * *'
243
+ ec trigger update <triggerId> --prompt '新的任务内容' --name new-name
244
+ ec trigger update <triggerId> --prompt-file ./prompts/new-task.md
245
+ ec trigger update <triggerId> --script-file ./scripts/check-v2.js
246
+ ec trigger update <triggerId> --cron '0 10 * * *' --if-revision 'sha256:...'
247
+ ```
248
+
249
+ 可更新参数只保留三组常用字段:
250
+
251
+ - 调度:`--once`、`--delay`、`--at`、`--cron`、`--every`、`--event`、`--tz`
252
+ - 内容:`--prompt` 或 `--prompt-file <path>`、`--name`
253
+ - 执行配置:`--model`、`--effort`、`--permission`
254
+ - 运行边界:`--max-runs`、`--max-duration`、`--concurrency`、`--missed-policy`
255
+
256
+ 脚本的路径、runtime、参数、投递目标、feedback、reliability、limits、event filter 或执行类型需要变化时,删除后重新创建 trigger;仅替换已有脚本正文使用 `--script-file`。
257
+
258
+ `--if-revision` 是可选的乐观并发检查;值来自 `show --json` 顶层的 `revision`。revision 不一致时更新失败,不覆盖较新的 definition。
259
+
260
+ `--tz` 只对 cron 有效,用 IANA 时区(如 `Asia/Shanghai`、`UTC`)解释 cron;不写时使用运行进程时区。`--concurrency` 控制上一 run 仍在执行时的行为(`forbid`/`replace`/`allow`);`--missed-policy` 控制错过触发时间后的行为(`skip`/`run-once`/`run-all`)。
261
+
262
+ `update --json` 返回更新后的列表摘要和新 revision,不回传包含长 prompt 的完整 definition。
263
+
264
+ ## 手动运行
265
+
266
+ ```bash
267
+ ec trigger run <triggerId>
268
+ ec trigger run <triggerId> --dry-run
269
+ ```
270
+
271
+ `--dry-run` 不写 active 状态、不写正式 audit、不执行真实副作用,适合验证 prompt/template。
272
+
273
+ ## 审计存储
274
+
275
+ ```text
276
+ data/triggers/<aid>/<triggerId>/trigger.json
277
+ data/triggers/<aid>/<triggerId>/active.json
278
+ data/triggers/<aid>/history.jsonl
279
+ logs/trigger-runs.log
280
+ ```
281
+
282
+ - `history.jsonl` 是长期 append-only 审计真相源,默认不自动清理。
283
+ - 旧版 done 归档行保持可读,不会在升级时重写。
284
+ - `trigger-runs.log` 是短期运维日志,按天轮转并保留 7 天。
285
+ - `show` 的 recent run 摘要、运行统计和 `history` 命令读取长期历史。
286
+ - 启动时会把仍保留的旧 `trigger-runs*.log` 幂等补导入 `history.jsonl`。
287
+
288
+ ## 从文件导入
289
+
290
+ 复杂 trigger 使用 Trigger V3 第二阶段 JSON:
291
+
292
+ ```bash
293
+ ec trigger create --exec target-session --file ./trigger.json --enable
294
+ ec trigger create --exec script --file ./trigger-dir --enable
295
+ ```
296
+
297
+ 当前产品版本是 Trigger V3 第二阶段;其持久化定义版本为 `$schema_version: 3.1`。旧 `$schema_version: 4` 文件加载时会自动规范化为 `3.1`。
298
+
299
+ ### target-session 示例
300
+
301
+ ```json
302
+ {
303
+ "$schema_version": 3.1,
304
+ "agentAid": "<aid>",
305
+ "enabled": true,
306
+ "name": "daily-summary",
307
+ "source": {
308
+ "type": "cron",
309
+ "expression": "0 9 * * *",
310
+ "timezone": "Asia/Shanghai"
311
+ },
312
+ "execution": {
313
+ "type": "target_session",
314
+ "prompt": "生成昨日摘要并发送给我",
315
+ "model": "<model>",
316
+ "effort": "high",
317
+ "permissionMode": "bypass",
318
+ "onError": "fail",
319
+ "noopSentinel": "[[NOOP]]"
320
+ },
321
+ "feedback": {
322
+ "strategy": "target",
323
+ "target": {
324
+ "channelKey": "<channelKey>",
325
+ "channelId": "<channelId>",
326
+ "chatType": "private",
327
+ "session": "main"
328
+ }
329
+ },
330
+ "reliability": {
331
+ "concurrency": "forbid",
332
+ "missedPolicy": "run_once",
333
+ "retry": {
334
+ "maxAttempts": 0,
335
+ "backoffMs": 30000
336
+ }
337
+ }
338
+ }
339
+ ```
340
+
341
+ ### trigger-session 示例
342
+
343
+ ```json
344
+ {
345
+ "$schema_version": 3.1,
346
+ "agentAid": "<aid>",
347
+ "enabled": true,
348
+ "name": "hourly-health-check",
349
+ "origin": {
350
+ "channelKey": "<channelKey>",
351
+ "channelId": "<channelId>",
352
+ "session": "main"
353
+ },
354
+ "source": {
355
+ "type": "interval",
356
+ "everyMs": 3600000
357
+ },
358
+ "execution": {
359
+ "type": "trigger_session",
360
+ "prompt": "检查服务状态并总结异常;无异常输出 [[NOOP]]",
361
+ "thread": "per_run",
362
+ "permissionMode": "readonly",
363
+ "onError": "retry",
364
+ "noopSentinel": "[[NOOP]]"
365
+ },
366
+ "feedback": {
367
+ "strategy": "origin"
368
+ },
369
+ "reliability": {
370
+ "concurrency": "forbid",
371
+ "missedPolicy": "run_once",
372
+ "retry": {
373
+ "maxAttempts": 1,
374
+ "backoffMs": 30000
375
+ }
376
+ }
377
+ }
378
+ ```
379
+
380
+ ### script 示例
381
+
382
+ ```json
383
+ {
384
+ "$schema_version": 3.1,
385
+ "agentAid": "<aid>",
386
+ "enabled": true,
387
+ "name": "script-health",
388
+ "source": {
389
+ "type": "cron",
390
+ "expression": "0 */4 * * *",
391
+ "timezone": "Asia/Shanghai"
392
+ },
393
+ "execution": {
394
+ "type": "script",
395
+ "script": {
396
+ "path": "scripts/health.js",
397
+ "runtime": "node",
398
+ "timeoutMs": 30000
399
+ },
400
+ "onError": "retry",
401
+ "noopSentinel": "[[NOOP]]"
402
+ },
403
+ "feedback": {
404
+ "strategy": "target",
405
+ "target": {
406
+ "channelKey": "<channelKey>",
407
+ "channelId": "<channelId>",
408
+ "chatType": "private",
409
+ "session": "main"
410
+ },
411
+ "onReply": {
412
+ "template": "{{reply.text}}"
413
+ },
414
+ "onNoop": {
415
+ "template": ""
416
+ },
417
+ "onFailure": {
418
+ "template": "健康检查失败:{{error.message}}"
419
+ }
420
+ },
421
+ "reliability": {
422
+ "concurrency": "forbid",
423
+ "missedPolicy": "run_once",
424
+ "retry": {
425
+ "maxAttempts": 2,
426
+ "backoffMs": 30000
427
+ }
428
+ }
429
+ }
430
+ ```
431
+
432
+ ## 事件触发
433
+
434
+ 简单事件触发可直接用 flag 模式:
435
+
436
+ ```bash
437
+ ec trigger create --event 'message:received' \
438
+ --exec target-session \
439
+ --prompt '检查收到的消息是否需要自动跟进;无动作输出 [[NOOP]]' \
440
+ --target-channel <channelKey> --target-channel-id <channelId> \
441
+ --target-session main \
442
+ --name on-message-received --enable
443
+ ```
444
+
445
+ 监听某个命名空间下的所有事件:
446
+
447
+ ```bash
448
+ ec trigger create --event 'task:*' \
449
+ --exec target-session \
450
+ --prompt '任务完成或失败后生成简短诊断;无动作输出 [[NOOP]]' \
451
+ --target-channel <channelKey> --target-channel-id <channelId> \
452
+ --target-session main \
453
+ --name on-task-events --enable
454
+ ```
455
+
456
+ flag 模式不能配置过滤条件。需要根据事件 payload 过滤时,写完整的 Trigger V3 第二阶段 JSON:
457
+
458
+ ```json
459
+ {
460
+ "$schema_version": 3.1,
461
+ "agentAid": "<aid>",
462
+ "enabled": true,
463
+ "name": "on-important-message",
464
+ "source": {
465
+ "type": "event",
466
+ "eventPattern": "message:received",
467
+ "filter": {
468
+ "match": {
469
+ "channel": "<channelKey>",
470
+ "channelId": "<channelId>",
471
+ "content": { "$regex": "日报|告警|失败" }
472
+ }
473
+ }
474
+ },
475
+ "execution": {
476
+ "type": "target_session",
477
+ "prompt": "根据事件内容判断是否需要处理;无动作输出 [[NOOP]]",
478
+ "permissionMode": "readonly",
479
+ "onError": "retry",
480
+ "noopSentinel": "[[NOOP]]"
481
+ },
482
+ "feedback": {
483
+ "strategy": "target",
484
+ "target": {
485
+ "channelKey": "<channelKey>",
486
+ "channelId": "<channelId>",
487
+ "chatType": "private",
488
+ "session": "main"
489
+ }
490
+ },
491
+ "reliability": {
492
+ "concurrency": "forbid",
493
+ "missedPolicy": "run_once",
494
+ "retry": {
495
+ "maxAttempts": 0,
496
+ "backoffMs": 30000
497
+ }
498
+ }
499
+ }
500
+ ```
501
+
502
+ `source.filter.match` 的 key 是 payload 字段路径,支持等值、`$in`、`$regex`、数值比较和 `$exists`。例如 `message:received` 可过滤 `channel`、`channelId`、`content`、`userId`、`sessionId`;完整字段以事件目录为准。
503
+
504
+ ## 常用例子
505
+
506
+ 一次性提醒:
507
+
508
+ ```bash
509
+ ec trigger create --delay 30m \
510
+ --exec target-session \
511
+ --prompt '提醒用户检查部署状态' \
512
+ --target-channel <channelKey> --target-channel-id <channelId> \
513
+ --target-session main \
514
+ --name deploy-reminder --enable
515
+ ```
516
+
517
+ 创建后立即执行一次:
518
+
519
+ ```bash
520
+ ec trigger create --once \
521
+ --exec target-session \
522
+ --prompt '生成一次当前状态摘要' \
523
+ --target-channel <channelKey> --target-channel-id <channelId> \
524
+ --target-session main \
525
+ --name one-shot-summary --enable
526
+ ```
527
+
528
+ 每天巡检:
529
+
530
+ ```bash
531
+ ec trigger create --cron '30 9 * * *' \
532
+ --exec target-session \
533
+ --prompt '检查服务状态并汇报异常;无异常输出 [[NOOP]]' \
534
+ --target-channel <channelKey> --target-channel-id <channelId> \
535
+ --target-session main \
536
+ --name daily-health-check --enable
537
+ ```
538
+
539
+ 复用 trigger 会话做周期跟踪:
540
+
541
+ ```bash
542
+ ec trigger create --every 4h \
543
+ --exec trigger-session \
544
+ --trigger-thread by-trigger \
545
+ --prompt '继续跟踪升级状态并输出最新结论;无变化输出 [[NOOP]]' \
546
+ --target-channel <channelKey> --target-channel-id <channelId> \
547
+ --target-session main \
548
+ --name upgrade-watch --enable
549
+ ```
550
+
551
+ 定时尝试升级,最多 10 次或 3 天:
552
+
553
+ ```bash
554
+ ec trigger create --every 4h \
555
+ --max-runs 10 --max-duration 3d \
556
+ --permission bypass \
557
+ --model <model> --effort high \
558
+ --exec target-session \
559
+ --prompt '尝试执行升级检查;成功后调用 ec trigger disable auto-updater;无变化输出 [[NOOP]]' \
560
+ --target-channel <channelKey> --target-channel-id <channelId> \
561
+ --target-session main \
562
+ --name auto-updater --enable
563
+ ```
564
+
565
+ 硬删除:
566
+
567
+ ```bash
568
+ ec trigger delete auto-updater
569
+ ```
570
+
571
+ ## 相关文档
572
+
573
+ - event source 可监听事件:`$KITS_DOCS/evolcore/event.md`
574
+ - Trigger V3 第二阶段执行与反馈设计:`$PACKAGE_ROOT/docs/trigger-v3-phase2-execution-feedback-design.md`
575
+ - limits / disable / delete 语义:`$PACKAGE_ROOT/docs/trigger-limits-feature-v2.md`