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

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 (108) hide show
  1. package/builtin-skills/app-skill/SKILL.md +5 -6
  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 +33 -34
  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/dashboard-page.d.ts.map +1 -1
  74. package/dist/cli/templates/dashboard-page.js +10 -3
  75. package/dist/cli/templates/dashboard-page.js.map +1 -1
  76. package/dist/cli/templates/event-management-page.d.ts +8 -0
  77. package/dist/cli/templates/event-management-page.d.ts.map +1 -0
  78. package/dist/cli/templates/event-management-page.js +598 -0
  79. package/dist/cli/templates/event-management-page.js.map +1 -0
  80. package/dist/cli/templates/login-page.d.ts +1 -1
  81. package/dist/cli/templates/login-page.js +1 -1
  82. package/dist/cli/templates/model-management-page.d.ts +1 -1
  83. package/dist/cli/templates/model-management-page.js +1 -1
  84. package/dist/cli/templates/notification-center-page.d.ts +1 -1
  85. package/dist/cli/templates/notification-center-page.js +1 -1
  86. package/dist/cli/templates/notification-detail-page.d.ts +1 -1
  87. package/dist/cli/templates/notification-detail-page.js +1 -1
  88. package/dist/cli/templates/process-management-page.d.ts +1 -1
  89. package/dist/cli/templates/process-management-page.js +1 -1
  90. package/dist/cli/templates/skill-management-page.d.ts +1 -1
  91. package/dist/cli/templates/skill-management-page.js +1 -1
  92. package/dist/cli/templates/user-management-page.d.ts +1 -1
  93. package/dist/cli/templates/user-management-page.js +1 -1
  94. package/dist/config.d.ts +327 -11
  95. package/dist/config.d.ts.map +1 -1
  96. package/dist/config.js +26 -7
  97. package/dist/config.js.map +1 -1
  98. package/dist/index.d.ts +1 -0
  99. package/dist/index.d.ts.map +1 -1
  100. package/dist/index.js.map +1 -1
  101. package/dist/types/event.d.ts +6 -0
  102. package/dist/types/event.d.ts.map +1 -1
  103. package/dist/types/index.d.ts +1 -1
  104. package/dist/types/index.d.ts.map +1 -1
  105. package/dist/types/process.d.ts +45 -7
  106. package/dist/types/process.d.ts.map +1 -1
  107. package/package.json +1 -1
  108. package/builtin-skills/app-skill/references/process-metrics.md +0 -93
@@ -1,47 +1,47 @@
1
- # Process Builder Guide
1
+ # Process 构建指南
2
2
 
3
- ## Purpose
3
+ ## 目的
4
4
 
5
- This guide helps AI assistants create Processes for users. When a user says "I want to automate X" or "run Y every day", use this guide to build a process definition.
5
+ 本指南帮助 AI 助手为用户创建 Process。当用户说"我想自动化 X""每天运行 Y"时,使用本指南构建流程定义。
6
6
 
7
- ## Lightweight vs Full Decision
7
+ ## 轻量模式 vs 完整模式选择
8
8
 
9
- ### Use Lightweight (`--prompt`) when:
10
- - Single, simple task
11
- - No reference files needed
12
- - Prompt fits in a few sentences
13
- - No metrics dashboard needed
9
+ ### 使用轻量模式(`--prompt`)的场景:
10
+ - 单一、简单的任务
11
+ - 不需要引用文件
12
+ - 提示词几句话就能描述清楚
13
+ - 不需要指标仪表盘
14
14
 
15
- ### Use Full (`--process`) when:
16
- - Multi-step workflow with decision points
17
- - Reference documentation needed (API docs, data schemas, style guides)
18
- - Metrics dashboard desired
19
- - Process may evolve over time (Evolution section)
15
+ ### 使用完整模式(`--process`)的场景:
16
+ - 多步骤工作流,包含判断节点
17
+ - 需要参考文档(API 文档、数据模型、样式指南)
18
+ - 需要指标仪表盘
19
+ - 流程可能随时间演进(Evolution 章节)
20
20
 
21
- ## Step-by-Step Creation
21
+ ## 逐步创建
22
22
 
23
- ### 1. Analyze the Request
23
+ ### 1. 分析需求
24
24
 
25
- Identify:
26
- - **What** the process should do
27
- - **When** it should run (schedule or event trigger)
28
- - **Who** owns it (username for service token)
29
- - **Which model** should run it (use `loom model list` to see available models; fast for simple tasks, max for complex reasoning; omit to use global default)
30
- - **Complexity** (lightweight vs full)
25
+ 明确:
26
+ - **做什么** 流程应该执行什么操作
27
+ - **何时运行** 定时调度还是事件触发
28
+ - **谁负责** 服务令牌对应的用户名(owner)
29
+ - **用哪个模型** 使用 `loom model list` 查看可用模型;简单任务用快速模型,复杂推理用最大模型;省略则使用全局默认
30
+ - **复杂度** 轻量还是完整
31
31
 
32
- ### 2. Choose Trigger
32
+ ### 2. 选择触发方式
33
33
 
34
- | Need | Use | Example |
35
- |------|-----|---------|
36
- | Periodic schedule | `--cron` | `0 9 * * 1-5` (weekdays 9am) |
37
- | On data change | `--on-event` | `data:create:tasks` |
38
- | On user action | `--on-event` | `user:created` |
39
- | External data source | `--source` | `--source "bash feeders/my-feeder.sh"` |
40
- | Manual only | Neither | Just `loom process run` |
34
+ | 需求 | 使用 | 示例 |
35
+ |------|-----|------|
36
+ | 定时调度 | `--cron` | `0 9 * * 1-5`(工作日每天9点) |
37
+ | 数据变更时 | `--subscribe` | `data:create:tasks` |
38
+ | 用户操作时 | `--subscribe` | `user:created` |
39
+ | 外部数据源 | `--source` | `--source "bash feeders/my-feeder.sh"` |
40
+ | 仅手动触发 | 都不用 | 直接 `loom process run` |
41
41
 
42
- ### 3. Create the Process
42
+ ### 3. 创建流程
43
43
 
44
- For lightweight:
44
+ 轻量模式:
45
45
  ```bash
46
46
  loom process add --name "task-summary" \
47
47
  --cron "0 9 * * *" \
@@ -50,148 +50,142 @@ loom process add --name "task-summary" \
50
50
  --model "claude-sonnet-4-6"
51
51
  ```
52
52
 
53
- For full:
53
+ 完整模式:
54
54
  ```bash
55
- # Step 1: Generate scaffold
55
+ # 步骤 1:生成脚手架
56
56
  loom process generate weekly-report --description "Weekly analytics report"
57
57
 
58
- # Step 2: Edit PROCESS.md with detailed flow
59
- # (AI should write the PROCESS.md content)
58
+ # 步骤 2:编辑 PROCESS.md,填写详细流程
59
+ # AI 应编写 PROCESS.md 内容)
60
60
 
61
- # Step 3: Add reference files if needed
62
- # If this process requires additional context, create the references directory
63
- # and add files that the AI agent will need during execution:
61
+ # 步骤 3:按需添加引用文件
62
+ # 如果流程需要额外上下文,创建 references 目录
63
+ # 并添加 AI 代理执行时需要的文件:
64
64
  mkdir -p .loom/processes/weekly-report/references
65
- # Then add reference files such as:
66
- # - Skill references (CLI command usage, API docs)
67
- # - Domain knowledge (data schemas, business rules)
68
- # - Scripts or tools (data transforms, query templates)
69
- # Only create the directory when reference files are actually needed.
70
- # Skip this step if no additional context is required.
71
-
72
- # Step 4: Register the process
65
+ # 然后添加引用文件,例如:
66
+ # - Skill 引用(CLI 命令用法、API 文档)
67
+ # - 领域知识(数据模型、业务规则)
68
+ # - 脚本或工具(数据转换、查询模板)
69
+ # 仅在确实需要引用文件时才创建该目录。
70
+ # 无需额外上下文时跳过此步骤。
71
+
72
+ # 步骤 4:注册流程
73
73
  loom process add --name "weekly-report" \
74
74
  --cron "0 9 * * 1" \
75
75
  --process "weekly-report" \
76
76
  --owner admin
77
77
 
78
- # Step 5: Initialize metrics view config (if PROCESS.md has ## Metrics section)
79
- # Design the view config based on ## Metrics section (see "Initializing Metrics Visualization" below)
80
- # Then write it using metrics-set-view-config:
78
+ # 步骤 5:初始化指标视图配置(如果 PROCESS.md 中有 ## Metrics 章节才需要)
79
+ # 根据 ## Metrics 章节设计视图配置(见下方"初始化指标可视化"
80
+ # 然后使用 metrics-set-view-config 写入:
81
81
  loom process metrics-set-view-config weekly-report --config @./view-config.json
82
82
  ```
83
83
 
84
- ### Event-triggered process with Feeder source
84
+ ### 事件触发 + Feeder 数据源
85
85
 
86
- When the process needs a persistent data source (e.g., DingTalk messages, webhooks), use `--source` to declare a Feeder script:
86
+ 当流程需要持久数据源(如钉钉消息、Webhook)时,使用 `--source` 声明 Feeder 脚本:
87
87
 
88
88
  ```bash
89
- # Step 1: Generate scaffold (if full mode)
89
+ # 步骤 1:生成脚手架(如果是完整模式)
90
90
  loom process generate ingest --description "AI semantic router for incoming messages"
91
91
 
92
- # Step 2: Edit PROCESS.md with routing logic
92
+ # 步骤 2:编辑 PROCESS.md,编写路由逻辑
93
93
  # ...
94
94
 
95
- # Step 3: Register with Feeder source
95
+ # 步骤 3:注册时指定 Feeder 数据源
96
96
  loom process add --name "ingest" \
97
- --on-event "dingtalk:mention" \
97
+ --subscribe "dingtalk:mention" \
98
98
  --source "bash examples/feeders/dingtalk-mention.sh" \
99
99
  --process "ingest" \
100
100
  --owner admin
101
101
  ```
102
102
 
103
- **When to use `--source`:**
104
- - Process needs a persistent external data source (DingTalk, Git webhook, scanner, etc.)
105
- - The Feeder should run as long as the Loom instance is running
106
- - You want auto-restart and backoff for the Feeder
103
+ **何时使用 `--source`:**
104
+ - 流程需要持久的外部数据源(钉钉、Git Webhook、扫描器等)
105
+ - Feeder 应随 Loom 实例的运行持续运行
106
+ - 需要 Feeder 的自动重启和退避机制
107
107
 
108
- **Feeder script requirements:**
109
- - Trap SIGTERM/SIGINT and exit 0 for graceful shutdown
110
- - Use `$LOOM_SERVER_URL` instead of hardcoded URLs
111
- - Exit code 0 = normal stop (no restart); non-zero = crash (auto-restart)
112
- - Write data to `POST $LOOM_SERVER_URL/api/v1/events/notify`
108
+ Feeder 脚本要求、生命周期事件、清理机制详见 **`process.md` → Source (Feeder)**。
113
109
 
114
- **Cleanup:** Removing the process with `loom process remove` automatically stops the Feeder if no other process subscribes to the same event pattern.
115
-
116
- ### 4. Verify
110
+ ### 4. 验证
117
111
 
118
112
  ```bash
119
113
  loom process status <name>
120
- loom process run <name> # manual test
121
- loom process logs <name> # check result
114
+ loom process run <name> # 手动测试
115
+ loom process logs <name> # 查看结果
122
116
  ```
123
117
 
124
- ## PROCESS.md Best Practices
118
+ ## PROCESS.md 最佳实践
125
119
 
126
- ### Structure
120
+ ### 结构
127
121
 
128
122
  ```markdown
129
123
  # Process: <name>
130
124
 
131
125
  ## Description
132
- What this process does and why.
126
+ 此流程的功能及目的。
133
127
 
134
128
  ## Trigger
135
- When it runs and what triggers it.
129
+ 运行时机和触发条件。
136
130
 
137
131
  ## Flow
138
- Step-by-step instructions:
139
- 1. Read data from <model>
140
- 2. Analyze <something>
141
- 3. Write results to <model>
142
- 4. Send notification with execution result via `loom notification send`
132
+ 逐步指令:
133
+ 1. <model> 读取数据
134
+ 2. 分析 <something>
135
+ 3. 将结果写入 <model>
136
+ 4. 通过 `loom notification send` 发送执行结果通知
143
137
 
144
138
  ## Decision Points
145
- Key decisions the AI should make:
146
- - If X, do Y
147
- - If Z, skip to step N
139
+ AI 应做出的关键判断:
140
+ - 如果 X,执行 Y
141
+ - 如果 Z,跳到步骤 N
148
142
 
149
143
  ## Metrics
150
- How success is measured:
151
- - Execution time < N seconds
152
- - Error rate < X%
153
- - Output quality: <criteria>
144
+ 如何衡量成功:
145
+ - 执行时间 < N
146
+ - 错误率 < X%
147
+ - 输出质量:<标准>
154
148
 
155
149
  ## Evolution
156
- How this process should improve:
157
- - After N runs, review and optimize prompt
158
- - Track common errors and add handling
150
+ 此流程应如何改进:
151
+ - 运行 N 次后,回顾并优化提示词
152
+ - 追踪常见错误并添加处理逻辑
159
153
 
160
154
  ## References
161
- _List files in the `references/` directory that support this process:_
162
- - _Skill references (e.g., CLI command usage, API docs)_
163
- - _Domain knowledge (e.g., data schemas, business rules)_
164
- - _Scripts or tools (e.g., data transforms, query templates)_
165
- _Only create the `references/` directory and add files when needed._
155
+ _列出 `references/` 目录中支持此流程的文件:_
156
+ - _Skill 引用(如 CLI 命令用法、API 文档)_
157
+ - _领域知识(如数据模型、业务规则)_
158
+ - _脚本或工具(如数据转换、查询模板)_
159
+ _仅在需要时才创建 `references/` 目录并添加文件。_
166
160
  ```
167
161
 
168
- ### Tips
169
- - Be specific in Flow steps — AI follows them literally
170
- - Include data model names and field names
171
- - Reference CLI commands: `loom data list <model>`, `loom data create <model>`
172
- - Use `loom data` commands for data operations, not direct file I/O
173
- - Include error handling in Decision Points
174
- - Add a notification step at the end of Flow to send execution results to yourself: `loom notification send --userId <owner> --type success --title "Process completed" --description "Summary of results" --token $LOOM_TOKEN`
175
- - If your process needs strong reasoning, specify a max-level model via `--model` when creating it. Fast models are best for simple data aggregations.
162
+ ### 技巧
163
+ - Flow 步骤要具体 — AI 会严格按字面执行
164
+ - 包含数据模型名称和字段名称
165
+ - 引用 CLI 命令:`loom data list <model>`、`loom data create <model>`
166
+ - 数据操作使用 `loom data` 命令,而非直接文件 I/O
167
+ - Decision Points 中包含错误处理
168
+ - Flow 末尾添加通知步骤,将执行结果发送给自己:`loom notification send --userId <owner> --type success --title "Process completed" --description "Summary of results" --token $LOOM_TOKEN`
169
+ - 如果流程需要强推理能力,创建时通过 `--model` 指定最大级别模型。简单数据聚合任务使用快速模型即可。
176
170
 
177
- ## Metrics Definition
171
+ ## 指标定义
178
172
 
179
- When defining `## Metrics` in PROCESS.md, follow these guidelines so the system can properly track and visualize them:
173
+ PROCESS.md 中定义 `## Metrics` 时,遵循以下指南以便系统正确追踪和可视化:
180
174
 
181
- ### Format
175
+ ### 格式
182
176
 
183
- Each metric should include:
184
- - **Name**: A clear, concise identifier (e.g., "错题 review 率")
185
- - **Meaning**: What this metric measures and why it matters
186
- - **Direction**: Whether the metric should increase, decrease, or approach a target
187
- - `increasing` = higher is better (e.g., success rate)
188
- - `decreasing` = lower is better (e.g., error count)
189
- - `target` = should approach a specific value (e.g., 100% coverage)
190
- - **Target** (optional): The goal value
191
- - **Unit** (optional): Measurement unit (e.g., "%", "条", "次")
192
- - **Chart** (optional): Suggested chart type for visualization
177
+ 每个指标应包含:
178
+ - **名称**:清晰简洁的标识符(如"错题 review 率"
179
+ - **含义**:该指标衡量什么以及为什么重要
180
+ - **方向**:指标应增大、减小还是趋近目标值
181
+ - `increasing` = 越高越好(如成功率)
182
+ - `decreasing` = 越低越好(如错误数)
183
+ - `target` = 应趋近特定值(如 100% 覆盖率)
184
+ - **目标值**(可选):目标数值
185
+ - **单位**(可选):度量单位(如"%""条""次"
186
+ - **图表**(可选):建议的可视化图表类型
193
187
 
194
- ### Example
188
+ ### 示例
195
189
 
196
190
  ```markdown
197
191
  ## Metrics
@@ -200,77 +194,77 @@ Each metric should include:
200
194
  - **错题重复出现率**: 统计相同错误模式的错题数量趋势。方向:越低越好。单位:条。图表:line。
201
195
  ```
202
196
 
203
- ### Initializing Metrics Visualization
197
+ ### 初始化指标可视化
204
198
 
205
- After registering a full process with `--process`, you MUST initialize the metrics view configuration so the Process Management page can render charts for each metric. This is a two-step process:
199
+ 使用 `--process` 注册完整流程后,必须初始化指标视图配置,以便流程管理页面能为每个指标渲染图表。这是一个两步过程:
206
200
 
207
- #### Step 1: Design the view config based on ## Metrics
201
+ #### 步骤 1:根据 ## Metrics 设计视图配置
208
202
 
209
- Analyze each metric in the `## Metrics` section and generate a `ProcessMetricsViewConfig` JSON. The config has two parts:
203
+ 分析 `## Metrics` 章节中的每个指标,生成 `ProcessMetricsViewConfig` JSON。配置包含两部分:
210
204
 
211
- - **`metrics[]`**: Metric card definitions (shown as number + trend + target)
212
- - **`charts[]`**: G2 v5 chart specs (one independent chart per metric, filtered by `metricName`)
205
+ - **`metrics[]`**:指标卡片定义(显示数值 + 趋势 + 目标)
206
+ - **`charts[]`**:G2 v5 图表规格(每个指标一个独立图表,通过 `metricName` 过滤)
213
207
 
214
- **ProcessMetricsViewConfig Schema:**
208
+ **ProcessMetricsViewConfig Schema:**
215
209
 
216
210
  ```typescript
217
211
  {
218
212
  version: 1,
219
- metrics: ProcessMetricView[], // Metric card definitions
220
- charts: ProcessMetricChartSpec[] // Chart specs with metric binding
213
+ metrics: ProcessMetricView[], // 指标卡片定义
214
+ charts: ProcessMetricChartSpec[] // 带指标绑定的图表规格
221
215
  }
222
216
 
223
217
  // ProcessMetricView:
224
218
  {
225
- metricName: string; // Must match the exact name used in metrics-report
226
- title: LocaleString; // Display title for the card (i18n)
227
- description?: LocaleString; // Optional tooltip description (i18n)
219
+ metricName: string; // 必须与 metrics-report 中使用的名称完全一致
220
+ title: LocaleString; // 卡片显示标题(i18n
221
+ description?: LocaleString; // 可选的工具提示描述(i18n
228
222
  chartType: string; // 'line' | 'bar' | 'area' | 'gauge' | 'number'
229
223
  direction?: 'increasing' | 'decreasing' | 'target';
230
- target?: number; // Goal value (shown on card)
231
- unit?: string; // Unit label (e.g., "%", "条", "次")
224
+ target?: number; // 目标值(显示在卡片上)
225
+ unit?: string; // 单位标签(如 "%""条""次"
232
226
  }
233
227
 
234
228
  // ProcessMetricChartSpec:
235
229
  {
236
- metricName?: string; // Filter snapshots for this metric
237
- title?: LocaleString; // Chart title (i18n)
238
- type: string; // G2 chart type: 'line' | 'interval' | 'area' | 'cell'
239
- encode?: Record<string, unknown>; // G2 encode config
240
- scale?: Record<string, unknown>; // G2 scale config
241
- coordinate?: Record<string, unknown>; // G2 coordinate config
242
- transform?: Record<string, unknown>[];// G2 transform config
243
- style?: Record<string, unknown>; // G2 style config
230
+ metricName?: string; // 按此指标名称过滤快照数据
231
+ title?: LocaleString; // 图表标题(i18n
232
+ type: string; // G2 图表类型: 'line' | 'interval' | 'area' | 'cell'
233
+ encode?: Record<string, unknown>; // G2 encode 配置
234
+ scale?: Record<string, unknown>; // G2 scale 配置
235
+ coordinate?: Record<string, unknown>; // G2 coordinate 配置
236
+ transform?: Record<string, unknown>[];// G2 transform 配置
237
+ style?: Record<string, unknown>; // G2 style 配置
244
238
  legend?: Record<string, unknown> | boolean;
245
239
  labels?: Record<string, unknown>[];
246
- interval?: 'minute' | 'hour' | 'day' | 'week' | 'month'; // Date truncation for timestamp field
247
- aggregate?: 'count' | 'sum' | 'avg'; // Aggregate function when interval is set (default: 'avg')
240
+ interval?: 'minute' | 'hour' | 'day' | 'week' | 'month'; // 时间戳字段的日期截断
241
+ aggregate?: 'count' | 'sum' | 'avg'; // 设置 interval 时的聚合函数(默认: 'avg'
248
242
  }
249
243
 
250
- // LocaleString is either a plain string or { "zh-CN": "...", "en-US": "..." }
244
+ // LocaleString 可以是纯字符串或 { "zh-CN": "...", "en-US": "..." }
251
245
  type LocaleString = string | { "zh-CN": string; "en-US": string };
252
246
  ```
253
247
 
254
- **Chart type selection guide:**
248
+ **图表类型选择指南:**
255
249
 
256
- | Metric direction + unit | chartType | Has chart? | Reasoning |
257
- |------------------------|-----------|-----------|-----------|
258
- | `target` + `%` unit | `gauge` | No (card only) | Percentage target card shows current vs target |
259
- | `target` + non-`%` unit | `number` | No (card only) | Numeric target card is sufficient |
260
- | `increasing` / `decreasing` + `%` | `line` | Yes | Track trend over time |
261
- | `increasing` / `decreasing` + count unit | `bar` | Yes | Compare across runs |
250
+ | 指标方向 + 单位 | chartType | 是否有图表? | 原因 |
251
+ |----------------|-----------|------------|------|
252
+ | `target` + `%` 单位 | `gauge` | 无(仅卡片) | 百分比目标卡片显示当前值与目标值 |
253
+ | `target` + `%` 单位 | `number` | 无(仅卡片) | 数值目标卡片已足够 |
254
+ | `increasing` / `decreasing` + `%` | `line` | | 追踪时间趋势 |
255
+ | `increasing` / `decreasing` + 计数单位 | `bar` | | 跨运行对比 |
262
256
 
263
- **Chart spec design rules:**
257
+ **图表规格设计规则:**
264
258
 
265
- 1. **Each metric gets its own independent chart** never mix different metrics in one chart. Different metrics have different units and scales, combining them makes the chart unreadable.
266
- 2. **Every chart MUST include `metricName`** — the frontend uses this field to filter `metricSnapshots` for that specific metric. Without it, all data would be mixed.
267
- 3. **Chart data fields** reference `ProcessMetricSnapshot` properties: `timestamp`, `value`, `metricName`, `dimensions`, `target`, `unit`. The frontend injects filtered snapshots as `data`.
268
- 4. **Title each chart** add a `title` field (use LocaleString format for i18n support).
259
+ 1. **每个指标独立一个图表**绝不在一个图表中混合不同指标。不同指标有不同单位和量级,合并会导致图表不可读。
260
+ 2. **每个图表必须包含 `metricName`** — 前端使用此字段为该特定指标过滤 `metricSnapshots`。缺少此字段会导致所有数据混合。
261
+ 3. **图表数据字段**引用 `ProcessMetricSnapshot` 属性:`timestamp`、`value`、`metricName`、`dimensions`、`target`、`unit`。前端将过滤后的快照作为 `data` 注入。
262
+ 4. **为每个图表添加标题**添加 `title` 字段(使用 LocaleString 格式支持 i18n)。
269
263
 
270
- **Chart spec templates by type:**
264
+ **按图表类型的规格模板:**
271
265
 
272
266
  ```jsonc
273
- // line chart time series trend (with date aggregation)
267
+ // 折线图时间序列趋势(带日期聚合)
274
268
  {
275
269
  "metricName": "错题重复出现率",
276
270
  "title": { "zh-CN": "错题重复出现率趋势", "en-US": "Repeat Error Rate Trend" },
@@ -281,7 +275,7 @@ type LocaleString = string | { "zh-CN": string; "en-US": string };
281
275
  "scale": { "y": { "nice": true } }
282
276
  }
283
277
 
284
- // bar chart per-run comparison
278
+ // 柱状图每次运行对比
285
279
  {
286
280
  "metricName": "新增错题数",
287
281
  "title": { "zh-CN": "每次执行新增错题数", "en-US": "New Errors Per Run" },
@@ -290,7 +284,7 @@ type LocaleString = string | { "zh-CN": string; "en-US": string };
290
284
  "scale": { "y": { "nice": true } }
291
285
  }
292
286
 
293
- // area chart cumulative trend (with date aggregation)
287
+ // 面积图累计趋势(带日期聚合)
294
288
  {
295
289
  "metricName": "review 完成数",
296
290
  "title": { "zh-CN": "Review 完成趋势", "en-US": "Review Completion Trend" },
@@ -302,15 +296,15 @@ type LocaleString = string | { "zh-CN": string; "en-US": string };
302
296
  }
303
297
  ```
304
298
 
305
- 5. **gauge and number types do NOT need a chart entry** they only appear as metric cards (showing latest value, trend arrow, and target).
306
- 6. **When `interval` is set**, the frontend automatically aggregates snapshots by truncated date (minute/hour/day/week/month). Use `encode: { "x": "name", "y": "value" }` for interval-mode charts. When `interval` is omitted, raw snapshots are passed through to G2 directly (use `encode: { "x": "timestamp", "y": "value" }` for time series without aggregation).
299
+ 5. **gauge number 类型不需要图表条目**它们仅作为指标卡片显示(展示最新值、趋势箭头和目标值)。
300
+ 6. **设置 `interval` 时**,前端自动按截断日期(分钟/小时/天/周/月)聚合快照。interval 模式图表使用 `encode: { "x": "name", "y": "value" }`。省略 `interval` 时,原始快照直接传递给 G2(无聚合的时间序列使用 `encode: { "x": "timestamp", "y": "value" }`)。
307
301
 
308
- #### Step 2: Write the view config
302
+ #### 步骤 2:写入视图配置
309
303
 
310
- Use `loom process metrics-set-view-config` to write the configuration:
304
+ 使用 `loom process metrics-set-view-config` 写入配置:
311
305
 
312
306
  ```bash
313
- # From JSON string
307
+ # JSON 字符串写入
314
308
  loom process metrics-set-view-config <name> --config '{
315
309
  "version": 1,
316
310
  "metrics": [
@@ -345,15 +339,15 @@ loom process metrics-set-view-config <name> --config '{
345
339
  ]
346
340
  }'
347
341
 
348
- # Or from a file
342
+ # 或从文件读取
349
343
  loom process metrics-set-view-config <name> --config @./view-config.json
350
344
  ```
351
345
 
352
- Note: The server must be running when using this command (it calls the API).
346
+ 注意:使用此命令时服务器必须正在运行(它会调用 API)。
353
347
 
354
- ### Complete example — error-pattern-analysis process
348
+ ### 完整示例 — error-pattern-analysis 流程
355
349
 
356
- PROCESS.md `## Metrics` section:
350
+ PROCESS.md `## Metrics` 章节:
357
351
 
358
352
  ```markdown
359
353
  ## Metrics
@@ -362,7 +356,7 @@ PROCESS.md `## Metrics` section:
362
356
  - **错题重复出现率**: 统计相同错误模式的错题数量趋势。方向:越低越好。单位:条。图表:line。
363
357
  ```
364
358
 
365
- Corresponding view config:
359
+ 对应的视图配置:
366
360
 
367
361
  ```json
368
362
  {
@@ -400,11 +394,11 @@ Corresponding view config:
400
394
  }
401
395
  ```
402
396
 
403
- Note: "错题 review 率" has `chartType: "gauge"` which only renders as a metric card (latest value + target + trend). It does NOT need a chart entry in `charts[]`.
397
+ 注意:"错题 review 率" `chartType: "gauge"` 仅渲染为指标卡片(最新值 + 目标值 + 趋势)。它在 `charts[]` 中不需要图表条目。
404
398
 
405
- ### Reporting metrics during execution
399
+ ### 执行期间上报指标
406
400
 
407
- When a process's PROCESS.md has a `## Metrics` section, the system automatically injects a Metrics Protocol into the AI prompt. The agent MUST call `loom process metrics-report` for each metric after computing its value:
401
+ 当流程的 PROCESS.md 包含 `## Metrics` 章节时,系统会自动在 AI 提示词中注入指标协议(Metrics Protocol)。代理在计算每个指标的值后,必须调用 `loom process metrics-report`:
408
402
 
409
403
  ```bash
410
404
  loom process metrics-report <process-name> \
@@ -415,30 +409,12 @@ loom process metrics-report <process-name> \
415
409
  --run-id $LOOM_RUN_ID
416
410
  ```
417
411
 
418
- Key points:
419
- - `--metric-name` MUST exactly match the name used in the view config (including `metrics[]` entries)
420
- - `--run-id` is automatically available via the `$LOOM_RUN_ID` environment variable
421
- - `--dimensions` is optional for dimensional breakdown (e.g., `--dimensions '{"subject":"数学"}'`)
422
- - Report each metric as soon as it's computed, don't batch at the end
423
-
424
- ## Common Cron Patterns
425
-
426
- | Pattern | Schedule |
427
- |---------|----------|
428
- | `*/5 * * * *` | Every 5 minutes |
429
- | `*/15 * * * *` | Every 15 minutes |
430
- | `0 * * * *` | Every hour |
431
- | `0 9 * * *` | Daily at 9 AM |
432
- | `0 9 * * 1-5` | Weekdays at 9 AM |
433
- | `0 9 * * 1` | Every Monday at 9 AM |
434
- | `0 0 1 * *` | First of every month |
435
-
436
- ## Common Event Patterns
437
-
438
- | Pattern | When |
439
- |---------|------|
440
- | `data:create:<model>` | New record created |
441
- | `data:update:<model>` | Record updated |
442
- | `data:delete:<model>` | Record deleted |
443
- | `user:created` | New user registered |
444
- | `process:completed:<name>` | Another process finished |
412
+ 关键要点:
413
+ - `--metric-name` 必须与视图配置中使用的名称完全一致(包括 `metrics[]` 条目中的名称)
414
+ - `--run-id` 通过 `$LOOM_RUN_ID` 环境变量自动获取
415
+ - `--dimensions` 可选,用于维度拆分(如 `--dimensions '{"subject":"数学"}'`)
416
+ - 每个指标计算完成后立即上报,不要在最后批量上报
417
+
418
+ ## 快速参考
419
+
420
+ 常用 Cron Event 模式表见 **`process.md` → Trigger Types**。