@loom-framework/core 0.1.0-alpha.180 → 0.1.0-alpha.181

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 (105) hide show
  1. package/builtin-skills/app-skill/SKILL.md +4 -5
  2. package/builtin-skills/app-skill/references/auth.md +79 -79
  3. package/builtin-skills/app-skill/references/events.md +237 -19
  4. package/builtin-skills/app-skill/references/evolution.md +59 -59
  5. package/builtin-skills/app-skill/references/model.md +48 -48
  6. package/builtin-skills/app-skill/references/notification.md +47 -47
  7. package/builtin-skills/app-skill/references/process-builder.md +173 -197
  8. package/builtin-skills/app-skill/references/process.md +274 -163
  9. package/builtin-skills/loom/SKILL.md +17 -10
  10. package/builtin-skills/loom/references/data-model.md +19 -3
  11. package/dist/backend/auth/rbac.js +1 -1
  12. package/dist/backend/auth/rbac.js.map +1 -1
  13. package/dist/backend/events/subscription-service.d.ts +46 -0
  14. package/dist/backend/events/subscription-service.d.ts.map +1 -0
  15. package/dist/backend/events/subscription-service.js +209 -0
  16. package/dist/backend/events/subscription-service.js.map +1 -0
  17. package/dist/backend/index.d.ts +1 -0
  18. package/dist/backend/index.d.ts.map +1 -1
  19. package/dist/backend/index.js +27 -13
  20. package/dist/backend/index.js.map +1 -1
  21. package/dist/backend/lifecycle/manager.d.ts +4 -2
  22. package/dist/backend/lifecycle/manager.d.ts.map +1 -1
  23. package/dist/backend/lifecycle/manager.js +9 -3
  24. package/dist/backend/lifecycle/manager.js.map +1 -1
  25. package/dist/backend/loom-paths.d.ts +3 -1
  26. package/dist/backend/loom-paths.d.ts.map +1 -1
  27. package/dist/backend/loom-paths.js +5 -1
  28. package/dist/backend/loom-paths.js.map +1 -1
  29. package/dist/backend/process/engine.d.ts +15 -1
  30. package/dist/backend/process/engine.d.ts.map +1 -1
  31. package/dist/backend/process/engine.js +79 -23
  32. package/dist/backend/process/engine.js.map +1 -1
  33. package/dist/backend/process/registry.d.ts +44 -9
  34. package/dist/backend/process/registry.d.ts.map +1 -1
  35. package/dist/backend/process/registry.js +208 -40
  36. package/dist/backend/process/registry.js.map +1 -1
  37. package/dist/backend/process/trigger.d.ts +18 -8
  38. package/dist/backend/process/trigger.d.ts.map +1 -1
  39. package/dist/backend/process/trigger.js +86 -32
  40. package/dist/backend/process/trigger.js.map +1 -1
  41. package/dist/backend/routes/ai-config.d.ts.map +1 -1
  42. package/dist/backend/routes/ai-config.js +1 -69
  43. package/dist/backend/routes/ai-config.js.map +1 -1
  44. package/dist/backend/routes/config-writer.d.ts +94 -0
  45. package/dist/backend/routes/config-writer.d.ts.map +1 -0
  46. package/dist/backend/routes/config-writer.js +522 -0
  47. package/dist/backend/routes/config-writer.js.map +1 -0
  48. package/dist/backend/routes/event-routes.d.ts +9 -2
  49. package/dist/backend/routes/event-routes.d.ts.map +1 -1
  50. package/dist/backend/routes/event-routes.js +101 -7
  51. package/dist/backend/routes/event-routes.js.map +1 -1
  52. package/dist/backend/routes/process-routes.d.ts +3 -0
  53. package/dist/backend/routes/process-routes.d.ts.map +1 -1
  54. package/dist/backend/routes/process-routes.js +120 -49
  55. package/dist/backend/routes/process-routes.js.map +1 -1
  56. package/dist/cli/commands/event.d.ts +12 -0
  57. package/dist/cli/commands/event.d.ts.map +1 -0
  58. package/dist/cli/commands/event.js +332 -0
  59. package/dist/cli/commands/event.js.map +1 -0
  60. package/dist/cli/commands/process.d.ts.map +1 -1
  61. package/dist/cli/commands/process.js +82 -44
  62. package/dist/cli/commands/process.js.map +1 -1
  63. package/dist/cli/generators/capability-generator.d.ts.map +1 -1
  64. package/dist/cli/generators/capability-generator.js +28 -32
  65. package/dist/cli/generators/capability-generator.js.map +1 -1
  66. package/dist/cli/helpers/system-page-config.d.ts +1 -1
  67. package/dist/cli/helpers/system-page-config.d.ts.map +1 -1
  68. package/dist/cli/helpers/system-page-config.js +9 -0
  69. package/dist/cli/helpers/system-page-config.js.map +1 -1
  70. package/dist/cli/index.d.ts.map +1 -1
  71. package/dist/cli/index.js +2 -0
  72. package/dist/cli/index.js.map +1 -1
  73. package/dist/cli/templates/event-management-page.d.ts +8 -0
  74. package/dist/cli/templates/event-management-page.d.ts.map +1 -0
  75. package/dist/cli/templates/event-management-page.js +598 -0
  76. package/dist/cli/templates/event-management-page.js.map +1 -0
  77. package/dist/cli/templates/login-page.d.ts +1 -1
  78. package/dist/cli/templates/login-page.js +1 -1
  79. package/dist/cli/templates/model-management-page.d.ts +1 -1
  80. package/dist/cli/templates/model-management-page.js +1 -1
  81. package/dist/cli/templates/notification-center-page.d.ts +1 -1
  82. package/dist/cli/templates/notification-center-page.js +1 -1
  83. package/dist/cli/templates/notification-detail-page.d.ts +1 -1
  84. package/dist/cli/templates/notification-detail-page.js +1 -1
  85. package/dist/cli/templates/process-management-page.d.ts +1 -1
  86. package/dist/cli/templates/process-management-page.js +1 -1
  87. package/dist/cli/templates/skill-management-page.d.ts +1 -1
  88. package/dist/cli/templates/skill-management-page.js +1 -1
  89. package/dist/cli/templates/user-management-page.d.ts +1 -1
  90. package/dist/cli/templates/user-management-page.js +1 -1
  91. package/dist/config.d.ts +327 -11
  92. package/dist/config.d.ts.map +1 -1
  93. package/dist/config.js +26 -7
  94. package/dist/config.js.map +1 -1
  95. package/dist/index.d.ts +1 -0
  96. package/dist/index.d.ts.map +1 -1
  97. package/dist/index.js.map +1 -1
  98. package/dist/types/event.d.ts +6 -0
  99. package/dist/types/event.d.ts.map +1 -1
  100. package/dist/types/index.d.ts +1 -1
  101. package/dist/types/index.d.ts.map +1 -1
  102. package/dist/types/process.d.ts +45 -7
  103. package/dist/types/process.d.ts.map +1 -1
  104. package/package.json +1 -1
  105. package/builtin-skills/app-skill/references/process-metrics.md +0 -93
@@ -1,44 +1,45 @@
1
- # Process CLI Reference
1
+ # Process CLI 参考
2
2
 
3
- ## Overview
3
+ > **配置 Schema 参考**:过程定义的声明式配置 (`processes.definitions`) 见 Loom Skill (`references/data-model.md` → ProcessesConfig)。
4
4
 
5
- Process is Loom's automation engine for scheduling and event-driven AI tasks. Each process has triggers (cron, event, or manual) and executes AI prompts via the Claude Code engine.
5
+ ## 概述
6
6
 
7
- ## Commands
7
+ Process 是 Loom 的自动化引擎,用于调度和事件驱动的 AI 任务。每个 Process 拥有触发器(cron、event 或手动),并通过 Claude Code 引擎执行 AI 提示词。
8
+
9
+ ## 命令
8
10
 
9
11
  ### `loom process add`
10
12
 
11
- Create a new process definition.
13
+ 创建新的 Process 定义。
12
14
 
13
15
  ```bash
14
- # Lightweight process (inline prompt)
16
+ # 轻量模式(内联提示词)
15
17
  loom process add --name "daily-summary" \
16
18
  --cron "0 9 * * 1-5" \
17
19
  --prompt "Summarize yesterday's data and email the team" \
18
20
  --owner admin
19
21
 
20
- # Full process (with PROCESS.md)
22
+ # 完整模式(使用 PROCESS.md
21
23
  loom process add --name "weekly-report" \
22
24
  --cron "0 9 * * 1" \
23
25
  --process "weekly-report" \
24
26
  --owner admin \
25
27
  --description "Weekly analytics report"
26
28
 
27
- # Event-triggered process
29
+ # 事件触发模式(带订阅)
28
30
  loom process add --name "on-task-create" \
29
- --on-event "data:create:tasks" \
31
+ --subscribe "data:create:tasks" \
30
32
  --prompt "Analyze the new task and suggest priorities" \
31
- --owner admin \
32
- --event-debounce 2000
33
+ --owner admin
33
34
 
34
- # With metrics config
35
+ # 带指标配置
35
36
  loom process add --name "health-check" \
36
37
  --cron "*/30 * * * *" \
37
38
  --prompt "Check system health" \
38
39
  --metrics-config ./metrics-config.json \
39
40
  --owner bot
40
41
 
41
- # With a specific model
42
+ # 指定模型
42
43
  loom process add --name "complex-analysis" \
43
44
  --cron "0 2 * * *" \
44
45
  --prompt "Analyze daily data and generate insights" \
@@ -46,29 +47,29 @@ loom process add --name "complex-analysis" \
46
47
  --model "claude-opus-4-7"
47
48
  ```
48
49
 
49
- **Options:**
50
- | Flag | Required | Description |
51
- |------|----------|-------------|
52
- | `--name` | Yes | Process name (^[a-zA-Z][a-zA-Z0-9_-]*$) |
53
- | `--prompt` | One of | Inline prompt for lightweight process |
54
- | `--process` | One of | Full process name (expects .loom/processes/{name}/PROCESS.md) |
55
- | `--cron` | No | Cron schedule expression |
56
- | `--cron-timezone` | No | Timezone for cron (e.g., "America/New_York") |
57
- | `--on-event` | No | EventBus pattern (e.g., "data:create:tasks") |
58
- | `--event-filter` | No | JSON filter on event payload fields |
59
- | `--event-debounce` | No | Debounce window in ms (default: 1000) |
60
- | `--description` | No | Process description |
61
- | `--owner` | No | Owner username (default: from processes config) |
62
- | `--owner-token` | No | Direct JWT token (bypasses runtime resolution) |
63
- | `--metrics-config` | No | Path to metrics DashboardWidget config JSON |
64
- | `--source` | No | Feeder script command (auto-registers lifecycle script + event subscription) |
65
- | `--model` | No | AI model name for this process (must exist in model management; use `loom model list` to see available models) |
66
- | `--token` | No | Auth token (or set LOOM_TOKEN) |
67
- | `--server` | No | Server URL (or set LOOM_SERVER, default: http://localhost:3000) |
50
+ **选项:**
51
+ | Flag | 必填 | 说明 |
52
+ |------|------|------|
53
+ | `--name` | | Process 名称(^[a-zA-Z][a-zA-Z0-9_-]*$) |
54
+ | `--prompt` | 二选一 | 轻量模式的内联提示词 |
55
+ | `--process` | 二选一 | 完整模式名称(需存在 .loom/processes/{name}/PROCESS.md |
56
+ | `--cron` | | Cron 调度表达式 |
57
+ | `--cron-timezone` | | Cron 时区(如 "America/New_York" |
58
+ | `--subscribe` | | 订阅的 EventBus 模式(如 "data:create:tasks" |
59
+ | `--event-filter` | | 事件载荷字段的 JSON 过滤条件(仅与 --subscribe 配合使用) |
60
+ | `--event-debounce` | | 防抖窗口,单位毫秒(默认:1000,仅与 --subscribe 配合使用) |
61
+ | `--description` | | Process 描述 |
62
+ | `--owner` | | 所有者用户名(默认:取自 processes 配置) |
63
+ | `--owner-token` | | 直接传入 JWT 令牌(绕过运行时解析) |
64
+ | `--metrics-config` | | DashboardWidget 指标配置 JSON 文件路径 |
65
+ | `--source` | | Feeder 脚本命令(自动注册生命周期脚本 + 事件订阅) |
66
+ | `--model` | | Process 使用的 AI 模型名称(须在模型管理中存在;使用 `loom model list` 查看可用模型) |
67
+ | `--token` | | 认证令牌(或设置 LOOM_TOKEN |
68
+ | `--server` | | 服务器 URL(或设置 LOOM_SERVER,默认:http://localhost:3000 |
68
69
 
69
70
  ### `loom process list`
70
71
 
71
- List all processes.
72
+ 列出所有 Process。
72
73
 
73
74
  ```bash
74
75
  loom process list
@@ -78,7 +79,7 @@ loom process list --status paused
78
79
 
79
80
  ### `loom process status <name>`
80
81
 
81
- Show detailed process status.
82
+ 显示 Process 详细状态。
82
83
 
83
84
  ```bash
84
85
  loom process status daily-summary
@@ -86,7 +87,7 @@ loom process status daily-summary
86
87
 
87
88
  ### `loom process run <name>`
88
89
 
89
- Manually trigger a process execution.
90
+ 手动触发一次 Process 执行。
90
91
 
91
92
  ```bash
92
93
  loom process run daily-summary
@@ -95,7 +96,7 @@ loom process run on-task-create --payload '{"model":"tasks","id":"task_123"}'
95
96
 
96
97
  ### `loom process pause <name>`
97
98
 
98
- Pause a process (stops triggers, manual run still works).
99
+ 暂停 Process(停止触发器,手动执行仍可用)。
99
100
 
100
101
  ```bash
101
102
  loom process pause daily-summary
@@ -103,7 +104,7 @@ loom process pause daily-summary
103
104
 
104
105
  ### `loom process resume <name>`
105
106
 
106
- Resume a paused process.
107
+ 恢复已暂停的 Process。
107
108
 
108
109
  ```bash
109
110
  loom process resume daily-summary
@@ -111,31 +112,39 @@ loom process resume daily-summary
111
112
 
112
113
  ### `loom process update <name>`
113
114
 
114
- Update an existing process definition.
115
+ 更新已有的 Process 定义。
115
116
 
116
117
  ```bash
117
118
  loom process update daily-summary --cron "0 10 * * 1-5"
118
119
  loom process update on-task-create --prompt "Updated prompt text"
119
120
  loom process update daily-summary --description "Updated description" --cron "0 8 * * 1-5"
121
+
122
+ # 添加事件订阅
123
+ loom process update on-task-create --subscribe-add "data:update:tasks"
124
+ loom process update on-task-create --subscribe-add "data:update:tasks" --subscribe-filter '{"status":"critical"}' --subscribe-debounce 2000
125
+
126
+ # 按 ID 移除事件订阅
127
+ loom process update on-task-create --subscribe-remove sub_1747301234_ab
120
128
  ```
121
129
 
122
- **Options:**
123
- | Flag | Required | Description |
124
- |------|----------|-------------|
125
- | `--cron` | No | Update cron schedule expression |
126
- | `--cron-timezone` | No | Update cron timezone |
127
- | `--on-event` | No | Update event trigger pattern |
128
- | `--event-filter` | No | Update event payload filter as JSON |
129
- | `--event-debounce` | No | Update debounce window in ms |
130
- | `--prompt` | No | Update inline prompt |
131
- | `--description` | No | Update description |
132
- | `--model` | No | Update AI model name (pass empty string to remove model binding) |
133
- | `--token` | No | Auth token (or set LOOM_TOKEN) |
134
- | `--server` | No | Server URL (or set LOOM_SERVER, default: http://localhost:3000) |
130
+ **选项:**
131
+ | Flag | 必填 | 说明 |
132
+ |------|------|------|
133
+ | `--cron` | | 更新 Cron 调度表达式 |
134
+ | `--cron-timezone` | | 更新 Cron 时区 |
135
+ | `--prompt` | | 更新内联提示词 |
136
+ | `--description` | | 更新描述 |
137
+ | `--model` | | 更新 AI 模型名称(传入空字符串移除模型绑定) |
138
+ | `--subscribe-add` | | 要订阅的事件模式(创建 `handler: process` 订阅) |
139
+ | `--subscribe-filter` | | 事件载荷的 JSON 过滤条件(仅与 --subscribe-add 配合使用) |
140
+ | `--subscribe-debounce` | | 防抖窗口,单位毫秒(默认:1000,仅与 --subscribe-add 配合使用) |
141
+ | `--subscribe-remove` | | 要移除的订阅 ID(使用 `loom event list` 查找 ID) |
142
+ | `--token` | | 认证令牌(或设置 LOOM_TOKEN) |
143
+ | `--server` | 否 | 服务器 URL(或设置 LOOM_SERVER,默认:http://localhost:3000) |
135
144
 
136
145
  ### `loom process remove <name>`
137
146
 
138
- Remove a process definition. Logs are preserved.
147
+ 移除 Process 定义。执行日志会保留。
139
148
 
140
149
  ```bash
141
150
  loom process remove daily-summary
@@ -143,21 +152,21 @@ loom process remove daily-summary
143
152
 
144
153
  ### `loom process logs <name> [runId]`
145
154
 
146
- View execution logs. When `runId` is provided, shows details for a single run.
155
+ 查看执行日志。提供 `runId` 时显示单次运行的详情。
147
156
 
148
157
  ```bash
149
- # List recent logs
158
+ # 列出最近的日志
150
159
  loom process logs daily-summary
151
160
  loom process logs daily-summary --limit 50
152
161
  loom process logs daily-summary --offset 10
153
162
 
154
- # View a specific run
163
+ # 查看特定运行
155
164
  loom process logs daily-summary run_abc123
156
165
  ```
157
166
 
158
167
  ### `loom process generate <name>`
159
168
 
160
- Create PROCESS.md scaffold directory (for full process mode). Called by AI, not directly by users.
169
+ 创建 PROCESS.md 脚手架目录(用于完整模式)。由 AI 调用,用户一般不直接使用。
161
170
 
162
171
  ```bash
163
172
  loom process generate daily-report --description "Daily report generator"
@@ -165,13 +174,13 @@ loom process generate daily-report --description "Daily report generator"
165
174
 
166
175
  ### `loom process metrics-report <name>`
167
176
 
168
- Report a business metric snapshot. Used by AI agent during process execution.
177
+ 上报业务指标快照。由 AI Agent Process 执行期间调用。
169
178
 
170
179
  ```bash
171
- # Basic report
180
+ # 基础上报
172
181
  loom process metrics-report my-process --metric-name "成功率" --value 0.95 --unit "%"
173
182
 
174
- # With target and dimensions
183
+ # 带目标和维度
175
184
  loom process metrics-report my-process \
176
185
  --metric-name "错题重复率" \
177
186
  --value 3 \
@@ -181,156 +190,258 @@ loom process metrics-report my-process \
181
190
  --run-id $LOOM_RUN_ID
182
191
  ```
183
192
 
184
- **Options:**
185
- | Flag | Required | Description |
186
- |------|----------|-------------|
187
- | `--metric-name` | Yes | Human-readable metric name |
188
- | `--value` | Yes | Numeric metric value |
189
- | `--run-id` | No | Run ID (defaults to LOOM_RUN_ID env var) |
190
- | `--timestamp` | No | ISO timestamp (defaults to now) |
191
- | `--dimensions` | No | Dimension labels as JSON |
192
- | `--target` | No | Target value for goal-line |
193
- | `--unit` | No | Unit label (e.g., "%", "条") |
194
- | `--token` | No | Auth token (or set LOOM_TOKEN) |
195
- | `--server` | No | Server URL (or set LOOM_SERVER) |
193
+ **选项:**
194
+ | Flag | 必填 | 说明 |
195
+ |------|------|------|
196
+ | `--metric-name` | | 指标的可读名称 |
197
+ | `--value` | | 数值型指标值 |
198
+ | `--run-id` | | 运行 ID(默认取 LOOM_RUN_ID 环境变量) |
199
+ | `--timestamp` | | ISO 时间戳(默认为当前时间) |
200
+ | `--dimensions` | | 维度标签,JSON 格式 |
201
+ | `--target` | | 目标值,用于显示目标线 |
202
+ | `--unit` | | 单位标签(如 "%""条" |
203
+ | `--token` | | 认证令牌(或设置 LOOM_TOKEN |
204
+ | `--server` | | 服务器 URL(或设置 LOOM_SERVER |
196
205
 
197
206
  ### `loom process metrics-set-view-config <name>`
198
207
 
199
- Set or update the business metrics view configuration. This defines how process metrics are visualized in the Process Management page — each metric gets its own card and optional chart.
208
+ 设置或更新业务指标视图配置。定义 Process 指标在 Process 管理页面的可视化方式——每个指标拥有独立卡片和可选图表。
200
209
 
201
- **When to use:** After creating a full process with `## Metrics` section, design the view config and write it using this command. See the Process Builder reference for the `ProcessMetricsViewConfig` schema and chart design guidelines.
210
+ **何时使用:** 创建含 `## Metrics` 章节的完整 Process 后,设计视图配置并通过此命令写入。
202
211
 
203
212
  ```bash
204
- # From JSON string
213
+ # JSON 字符串
205
214
  loom process metrics-set-view-config my-process --config '{"version":1,"metrics":[{"metricName":"成功率","title":"成功率","chartType":"gauge","direction":"target","target":1,"unit":"%"}],"charts":[]}'
206
215
 
207
- # From file (recommended for complex configs)
216
+ # 从文件(推荐用于复杂配置)
208
217
  loom process metrics-set-view-config my-process --config @./view-config.json
209
218
  ```
210
219
 
211
- **ProcessMetricsViewConfig structure:**
212
- - `version`: Always `1`
213
- - `metrics[]`: Metric card definitions. Each card shows latest value, trend arrow, and target.
214
- - `metricName`: Exact name used in `metrics-report` calls
215
- - `title`: Display title
216
- - `chartType`: `"gauge"` | `"number"` | `"line"` | `"bar"` | `"area"` gauge/number only render as cards; line/bar/area also render as independent charts
217
- - `direction`: `"increasing"` | `"decreasing"` | `"target"` controls trend arrow color
218
- - `target`: Goal value (shown on card)
219
- - `unit`: Unit label (e.g., "%", "条", "次")
220
- - `charts[]`: G2 v5 chart specs. Each chart MUST include `metricName` for data filtering.
221
- - `metricName`: Which metric's snapshots this chart displays
222
- - `title`: Chart title
223
- - `type`: G2 mark type (`"line"`, `"interval"`, `"area"`, etc.)
224
- - `encode`: Field mapping (use `timestamp` for X axis, `value` for Y axis)
225
- - Other G2 spec properties: `scale`, `axis`, `transform`, etc.
226
-
227
- **Key design rule:** Each chart shows ONE metric only. Never combine different metrics in one chart — they have different units and scales. Use `metricName` to filter data.
228
-
229
- **Options:**
230
- | Flag | Required | Description |
231
- |------|----------|-------------|
232
- | `--config` | Yes | View config JSON (use `@file` to read from file) |
233
- | `--token` | No | Auth token (or set LOOM_TOKEN) |
234
- | `--server` | No | Server URL (or set LOOM_SERVER) |
220
+ **ProcessMetricsViewConfig** 完整 Schema、chart 设计规则和示例见 **`process-builder.md` → Initializing Metrics Visualization**。
221
+
222
+ **选项:**
223
+ | Flag | 必填 | 说明 |
224
+ |------|------|------|
225
+ | `--config` | | 视图配置 JSON(使用 `@file` 从文件读取) |
226
+ | `--token` | | 认证令牌(或设置 LOOM_TOKEN) |
227
+ | `--server` | | 服务器 URL(或设置 LOOM_SERVER) |
235
228
 
236
229
  ### `loom process export <name>`
237
230
 
238
- Export process definition as JSON.
231
+ 导出 Process 定义为 JSON
239
232
 
240
233
  ```bash
241
234
  loom process export daily-summary
242
235
  ```
243
236
 
244
- ## Process Modes
237
+ ## Process 模式
245
238
 
246
- ### Lightweight Mode (`--prompt`)
239
+ ### 轻量模式(`--prompt`)
247
240
 
248
- - Inline prompt, no PROCESS.md file
249
- - Best for simple, single-task automations
250
- - Quick to set up and modify
241
+ - 内联提示词,无需 PROCESS.md 文件
242
+ - 适合简单的单步自动化
243
+ - 快速创建和修改
251
244
 
252
- ### Full Mode (`--process`)
245
+ ### 完整模式(`--process`)
253
246
 
254
- - Has PROCESS.md at `.loom/processes/{name}/PROCESS.md`
255
- - Can include reference files in `.loom/processes/{name}/references/`
256
- - Best for complex, multi-step workflows
257
- - Supports Metrics and Evolution sections
247
+ - `.loom/processes/{name}/PROCESS.md` 拥有 PROCESS.md
248
+ - 可在 `.loom/processes/{name}/references/` 中添加参考文件
249
+ - 适合复杂的多步骤工作流
250
+ - 支持 Metrics Evolution 章节
258
251
 
259
- ## Trigger Types
252
+ ## 触发器类型
260
253
 
261
254
  ### Cron
262
- Standard 5-field cron expression: `minute hour day month weekday`
263
- ```
264
- */5 * * * * — Every 5 minutes
265
- 0 9 * * 1-5 — Weekdays at 9 AM
266
- 0 0 1 * * First of every month
267
- ```
255
+ 标准 5 字段 Cron 表达式:`分钟 小时 星期`
256
+
257
+ | 模式 | 调度 |
258
+ |------|------|
259
+ | `*/5 * * * *` | 5 分钟 |
260
+ | `*/15 * * * *` | 每 15 分钟 |
261
+ | `0 * * * *` | 每小时 |
262
+ | `0 9 * * *` | 每天 9 点 |
263
+ | `0 9 * * 1-5` | 工作日 9 点 |
264
+ | `0 9 * * 1` | 每周一 9 点 |
265
+ | `0 0 1 * *` | 每月 1 号 |
268
266
 
269
267
  ### Event
270
- EventBus pattern matching: `{category}:{action}:{target}`
271
- ```
272
- data:create:tasks — When a task is created
273
- data:update:* — Any data update
274
- user:created — When a user is created
275
- process:completed:xxx — When process xxx completes
276
- ```
268
+ EventBus 模式匹配:`{category}:{action}:{target}`
277
269
 
278
- ### Source (Feeder)
279
- When a process needs a persistent external data source, use `--source` to declare a Feeder script. The script starts when the Loom instance becomes ready and stops when the instance shuts down.
270
+ | 模式 | 触发时机 |
271
+ |------|----------|
272
+ | `data:create:<model>` | 新记录创建时 |
273
+ | `data:update:<model>` | 记录更新时 |
274
+ | `data:delete:<model>` | 记录删除时 |
275
+ | `user:created` | 新用户注册时 |
276
+ | `process:completed:<name>` | 另一个 Process 完成时 |
277
+
278
+ 完整的事件模式文档见 **`events.md`**。
279
+
280
+ ### Source(Feeder)
281
+ 当 Process 需要持久化的外部数据源时,使用 `--source` 声明 Feeder 脚本。脚本在 Loom 实例就绪时启动,实例关闭时停止。
280
282
 
281
283
  ```bash
282
284
  loom process add --name ingest \
283
- --on-event "dingtalk:mention" \
285
+ --subscribe "dingtalk:mention" \
284
286
  --source "bash examples/feeders/dingtalk-mention.sh" \
285
287
  --process "ingest" \
286
288
  --owner admin
287
289
  ```
288
290
 
289
- This single command:
290
- 1. Registers the Process definition with a `source` field
291
- 2. Auto-starts the Feeder via LifecycleManager
292
- 3. Auto-registers the event subscription if not already present
291
+ 此命令一步完成:
292
+ 1. 注册带 `source` 字段的 Process 定义
293
+ 2. 通过 LifecycleManager 自动启动 Feeder
294
+ 3. 若事件订阅尚不存在则自动注册
295
+
296
+ 使用 `loom process remove` 移除 Process 时,如果没有其他 Process 订阅同一事件模式,Feeder 会被自动清理。
297
+
298
+ **Feeder 脚本约定:**
299
+ - 捕获 SIGTERM/SIGINT 并以退出码 0 退出,实现优雅关闭
300
+ - 使用 `$LOOM_SERVER_URL` 而非硬编码 URL
301
+ - 退出码 0 = 正常退出(不重启);非零 = 崩溃(自动重启,带退避策略)
302
+ - 每个名称仅允许一个脚本实例
303
+
304
+ **生命周期事件模式:**
305
+ | 模式 | 触发时机 |
306
+ |------|----------|
307
+ | `lifecycle:started:{name}` | Feeder 脚本启动时 |
308
+ | `lifecycle:failed:{name}` | Feeder 脚本异常退出时 |
309
+ | `lifecycle:circuit_open:{name}` | Feeder 达到最大重启次数时 |
310
+ | `lifecycle:restart:{name}` | Feeder 带退避策略重启时 |
311
+
312
+ ### 手动触发
313
+ `loom process run <name>` —— 立即执行,即使 Process 已暂停也有效。
314
+
315
+ ## 服务令牌认证
316
+
317
+ 启用认证后,Process 需要服务令牌才能运行:
318
+ - `--owner <username>`:通过 UserStore 运行时解析(推荐)
319
+ - `--owner-token <jwt>`:直接传入 JWT 令牌(安全性较低,存储在 loom.config.ts 中)
320
+
321
+ ## 执行模型
293
322
 
294
- Removing the process with `loom process remove` automatically cleans up the Feeder if no other process subscribes to the same event pattern.
323
+ 1. 触发器触发 任务入队
324
+ 2. 队列有空闲槽位 → Process 开始执行
325
+ 3. 构建 AI 提示词(PROCESS.md + 参考文件 + 事件上下文 + 指标协议)
326
+ 4. Claude Code 引擎带超时执行,注入环境变量:LOOM_SERVER、LOOM_PROCESS_NAME、LOOM_RUN_ID
327
+ 5. Agent 可在执行期间调用 `loom process metrics-report` 上报业务指标
328
+ 6. 执行结果记录到 `.loom/processes/{name}/logs/{runId}.json`
329
+ 7. 指标快照存储到 `.loom/processes/{name}/metrics.jsonl`
330
+ 8. 发出事件:`process:started`、`process:completed` 或 `process:failed`
295
331
 
296
- **Feeder script contract:**
297
- - Trap SIGTERM/SIGINT and exit with code 0 for graceful shutdown
298
- - Use `$LOOM_SERVER_URL` instead of hardcoded URLs
299
- - Exit code 0 = normal (no restart); non-zero = crash (auto-restart with backoff)
300
- - One script instance per name
332
+ ## 并发控制
301
333
 
302
- **Lifecycle event patterns:**
303
- | Pattern | When |
304
- |---------|------|
305
- | `lifecycle:started:{name}` | Feeder script started |
306
- | `lifecycle:failed:{name}` | Feeder script exited abnormally |
307
- | `lifecycle:circuit_open:{name}` | Feeder reached max restarts |
308
- | `lifecycle:restart:{name}` | Feeder restarting with backoff |
334
+ loom.config.ts 中的 `processes.maxConcurrent` 控制(默认:5)。达到上限时,新触发器排队等待空闲槽位。
309
335
 
310
- ### Manual
311
- `loom process run <name>` — immediate execution, works even when paused.
336
+ ## 防抖
312
337
 
313
- ## Service Token Authentication
338
+ 事件触发器带有 `eventDebounceMs`(默认:1000ms)。防抖窗口内的快速事件会被合并——仅触发一次执行,使用最后一条事件的载荷。
314
339
 
315
- When auth is enabled, processes need a service token to operate:
316
- - `--owner <username>`: Runtime resolution via UserStore (recommended)
317
- - `--owner-token <jwt>`: Direct JWT token (less secure, stored in processes/_registry.json)
340
+ ## 事件订阅
318
341
 
319
- ## Execution Model
342
+ Process 通过事件订阅响应事件。两种绑定方式:
320
343
 
321
- 1. Trigger fires entry enqueued
322
- 2. Queue slot available process starts
323
- 3. AI prompt built (PROCESS.md + references + event context + metrics protocol)
324
- 4. Claude Code engine executes with timeout, env vars injected: LOOM_SERVER, LOOM_PROCESS_NAME, LOOM_RUN_ID
325
- 5. Agent may call `loom process metrics-report` to report business metrics during execution
326
- 6. Result logged to `.loom/processes/{name}/logs/{runId}.json`
327
- 7. Metric snapshots stored in `.loom/processes/{name}/metrics.jsonl`
328
- 8. Event emitted: `process:started`, `process:completed`, or `process:failed`
344
+ 1. **创建时绑定**:`loom process add --subscribe "pattern"` — 自动创建 `handler: 'process'` 订阅,适合一步到位
345
+ 2. **独立管理**:`loom event subscribe/unsubscribe/update/test` 灵活管理 M:N 关系,支持所有 handler 类型
329
346
 
330
- ## Concurrency
347
+ ```bash
348
+ # 创建 Process 时同时绑定事件
349
+ loom process add --name "on-task-create" \
350
+ --subscribe "data:create:tasks" \
351
+ --prompt "Analyze the new task" \
352
+ --owner admin
353
+
354
+ # 给已有 Process 追加/移除订阅
355
+ loom process update on-task-create --subscribe-add "data:update:tasks"
356
+ loom process update on-task-create --subscribe-remove sub_1747301234_ab
357
+ ```
358
+
359
+ 完整的事件订阅命令、API 端点、handler 类型(process/webhook/log/notify)及声明式配置,见 **`events.md`**。
360
+
361
+ ## 系统指标配置
362
+
363
+ Process 内置执行统计指标(totalRuns、completedRuns、avgDurationMs 等),可通过 `--metrics-config` 配置 Dashboard 展示。这与 `metrics-report` 上报的**业务指标**是两套独立系统:
364
+
365
+ | 系统 | 数据来源 | 配置方式 | 用途 |
366
+ |------|----------|----------|------|
367
+ | **系统指标**(本节) | 自动采集执行统计 | `--metrics-config` + DashboardWidget | 监控执行健康度 |
368
+ | **业务指标** | AI 调用 `metrics-report` 上报 | `## Metrics` + `metrics-set-view-config` | 跟踪业务 KPI |
369
+
370
+ 业务指标的完整设计指南见 **`process-builder.md`**。
331
371
 
332
- Controlled by `processes.maxConcurrent` in loom.config.ts (default: 5). When max is reached, new triggers queue until a slot opens.
372
+ ### 指标配置
333
373
 
334
- ## Debounce
374
+ 创建 Process 时通过 `--metrics-config <path>` 指定 JSON 配置文件:
375
+
376
+ ```bash
377
+ loom process add --name "health-check" \
378
+ --cron "*/30 * * * *" \
379
+ --prompt "Check system health" \
380
+ --metrics-config ./health-metrics.json \
381
+ --owner admin
382
+ ```
383
+
384
+ ### 示例:metrics-config.json
385
+
386
+ ```json
387
+ [
388
+ {
389
+ "type": "stat",
390
+ "title": { "zh-CN": "成功率", "en-US": "Success Rate" },
391
+ "model": "__process_metrics",
392
+ "aggregate": "sum",
393
+ "field": "completedRuns",
394
+ "color": "#52c41a"
395
+ },
396
+ {
397
+ "type": "stat",
398
+ "title": { "zh-CN": "失败次数", "en-US": "Failures" },
399
+ "model": "__process_metrics",
400
+ "aggregate": "sum",
401
+ "field": "failedRuns",
402
+ "color": "#ff4d4f"
403
+ },
404
+ {
405
+ "type": "line",
406
+ "title": { "zh-CN": "执行趋势", "en-US": "Execution Trend" },
407
+ "model": "__process_metrics",
408
+ "aggregate": "sum",
409
+ "field": "totalRuns",
410
+ "groupBy": "date",
411
+ "dateInterval": "day"
412
+ }
413
+ ]
414
+ ```
335
415
 
336
- Event triggers have `eventDebounceMs` (default: 1000ms). Rapid events within the window are collapsed — only one execution fires with the last event's payload.
416
+ ### 可用组件类型
417
+
418
+ | Type | 说明 | 必填字段 |
419
+ |------|------|----------|
420
+ | `stat` | 单数值展示 | `title`、`model`、`aggregate`、`field` |
421
+ | `line` | 折线图 | `title`、`model`、`aggregate`、`field`、`groupBy`、`dateInterval` |
422
+ | `bar` | 柱状图 | `title`、`model`、`aggregate`、`field`、`groupBy` |
423
+ | `pie` | 饼图 | `title`、`model`、`field`、`groupBy` |
424
+ | `gauge` | 仪表盘 | `title`、`model`、`field`、`min`、`max` |
425
+ | `table` | 表格视图 | `title`、`model`、`columns` |
426
+
427
+ ### 可用指标字段
428
+
429
+ 来自 `ProcessMetricsAggregate`:
430
+
431
+ | 字段 | 类型 | 说明 |
432
+ |------|------|------|
433
+ | `date` | string | 日期(YYYY-MM-DD) |
434
+ | `totalRuns` | number | 总执行次数 |
435
+ | `completedRuns` | number | 成功执行次数 |
436
+ | `failedRuns` | number | 失败执行次数 |
437
+ | `timeoutRuns` | number | 超时执行次数 |
438
+ | `avgDurationMs` | number | 平均执行时长(毫秒) |
439
+ | `lastRunAt` | string\|null | 最近执行时间戳 |
440
+ | `lastStatus` | string\|null | 最近执行状态 |
441
+
442
+ ### API 端点
443
+
444
+ | 端点 | 方法 | 说明 |
445
+ |------|------|------|
446
+ | `/api/v1/processes/:name/metrics` | GET | 获取聚合指标数据 |
447
+ | `/api/v1/processes/:name/metrics-config` | GET | 获取组件配置 |