@loom-framework/core 0.1.0-alpha.150 → 0.1.0-alpha.152

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 (165) hide show
  1. package/builtin-skills/app-skill/SKILL.md +16 -5
  2. package/builtin-skills/app-skill/references/auth.md +23 -19
  3. package/builtin-skills/app-skill/references/events.md +119 -0
  4. package/builtin-skills/app-skill/references/evolution.md +90 -0
  5. package/builtin-skills/app-skill/references/process-builder.md +140 -0
  6. package/builtin-skills/app-skill/references/process-metrics.md +93 -0
  7. package/builtin-skills/app-skill/references/process.md +222 -0
  8. package/builtin-skills/loom/SKILL.md +9 -7
  9. package/dist/backend/auth/request-context.d.ts +15 -0
  10. package/dist/backend/auth/request-context.d.ts.map +1 -0
  11. package/dist/backend/auth/request-context.js +17 -0
  12. package/dist/backend/auth/request-context.js.map +1 -0
  13. package/dist/backend/events/event-bus.d.ts +39 -0
  14. package/dist/backend/events/event-bus.d.ts.map +1 -0
  15. package/dist/backend/events/event-bus.js +182 -0
  16. package/dist/backend/events/event-bus.js.map +1 -0
  17. package/dist/backend/events/event-emitting-adapter.d.ts +31 -0
  18. package/dist/backend/events/event-emitting-adapter.d.ts.map +1 -0
  19. package/dist/backend/events/event-emitting-adapter.js +70 -0
  20. package/dist/backend/events/event-emitting-adapter.js.map +1 -0
  21. package/dist/backend/events/event-registry.d.ts +24 -0
  22. package/dist/backend/events/event-registry.d.ts.map +1 -0
  23. package/dist/backend/events/event-registry.js +22 -0
  24. package/dist/backend/events/event-registry.js.map +1 -0
  25. package/dist/backend/events/index.d.ts +7 -0
  26. package/dist/backend/events/index.d.ts.map +1 -0
  27. package/dist/backend/events/index.js +7 -0
  28. package/dist/backend/events/index.js.map +1 -0
  29. package/dist/backend/index.d.ts +12 -0
  30. package/dist/backend/index.d.ts.map +1 -1
  31. package/dist/backend/index.js +143 -3
  32. package/dist/backend/index.js.map +1 -1
  33. package/dist/backend/process/engine.d.ts +84 -0
  34. package/dist/backend/process/engine.d.ts.map +1 -0
  35. package/dist/backend/process/engine.js +511 -0
  36. package/dist/backend/process/engine.js.map +1 -0
  37. package/dist/backend/process/index.d.ts +7 -0
  38. package/dist/backend/process/index.d.ts.map +1 -0
  39. package/dist/backend/process/index.js +6 -0
  40. package/dist/backend/process/index.js.map +1 -0
  41. package/dist/backend/process/logger.d.ts +30 -0
  42. package/dist/backend/process/logger.d.ts.map +1 -0
  43. package/dist/backend/process/logger.js +132 -0
  44. package/dist/backend/process/logger.js.map +1 -0
  45. package/dist/backend/process/queue.d.ts +31 -0
  46. package/dist/backend/process/queue.d.ts.map +1 -0
  47. package/dist/backend/process/queue.js +80 -0
  48. package/dist/backend/process/queue.js.map +1 -0
  49. package/dist/backend/process/registry.d.ts +25 -0
  50. package/dist/backend/process/registry.d.ts.map +1 -0
  51. package/dist/backend/process/registry.js +98 -0
  52. package/dist/backend/process/registry.js.map +1 -0
  53. package/dist/backend/process/trigger.d.ts +29 -0
  54. package/dist/backend/process/trigger.d.ts.map +1 -0
  55. package/dist/backend/process/trigger.js +108 -0
  56. package/dist/backend/process/trigger.js.map +1 -0
  57. package/dist/backend/routes/ai-config.d.ts +2 -0
  58. package/dist/backend/routes/ai-config.d.ts.map +1 -1
  59. package/dist/backend/routes/ai-config.js +2 -1
  60. package/dist/backend/routes/ai-config.js.map +1 -1
  61. package/dist/backend/routes/auth-routes.d.ts +7 -0
  62. package/dist/backend/routes/auth-routes.d.ts.map +1 -1
  63. package/dist/backend/routes/auth-routes.js +228 -1
  64. package/dist/backend/routes/auth-routes.js.map +1 -1
  65. package/dist/backend/routes/chat.d.ts +2 -0
  66. package/dist/backend/routes/chat.d.ts.map +1 -1
  67. package/dist/backend/routes/chat.js +3 -2
  68. package/dist/backend/routes/chat.js.map +1 -1
  69. package/dist/backend/routes/data.d.ts +2 -1
  70. package/dist/backend/routes/data.d.ts.map +1 -1
  71. package/dist/backend/routes/data.js +7 -1
  72. package/dist/backend/routes/data.js.map +1 -1
  73. package/dist/backend/routes/event-routes.d.ts +15 -0
  74. package/dist/backend/routes/event-routes.d.ts.map +1 -0
  75. package/dist/backend/routes/event-routes.js +35 -0
  76. package/dist/backend/routes/event-routes.js.map +1 -0
  77. package/dist/backend/routes/index.d.ts +4 -0
  78. package/dist/backend/routes/index.d.ts.map +1 -1
  79. package/dist/backend/routes/index.js +2 -0
  80. package/dist/backend/routes/index.js.map +1 -1
  81. package/dist/backend/routes/process-routes.d.ts +15 -0
  82. package/dist/backend/routes/process-routes.d.ts.map +1 -0
  83. package/dist/backend/routes/process-routes.js +237 -0
  84. package/dist/backend/routes/process-routes.js.map +1 -0
  85. package/dist/backend/routes/session-routes.d.ts +2 -0
  86. package/dist/backend/routes/session-routes.d.ts.map +1 -1
  87. package/dist/backend/routes/session-routes.js +4 -1
  88. package/dist/backend/routes/session-routes.js.map +1 -1
  89. package/dist/backend/routes/skills.d.ts +2 -0
  90. package/dist/backend/routes/skills.d.ts.map +1 -1
  91. package/dist/backend/routes/skills.js +4 -0
  92. package/dist/backend/routes/skills.js.map +1 -1
  93. package/dist/cli/commands/auth.d.ts.map +1 -1
  94. package/dist/cli/commands/auth.js +30 -22
  95. package/dist/cli/commands/auth.js.map +1 -1
  96. package/dist/cli/commands/data.d.ts.map +1 -1
  97. package/dist/cli/commands/data.js +47 -44
  98. package/dist/cli/commands/data.js.map +1 -1
  99. package/dist/cli/commands/generate-system-settings.d.ts +3 -2
  100. package/dist/cli/commands/generate-system-settings.d.ts.map +1 -1
  101. package/dist/cli/commands/generate-system-settings.js +50 -7
  102. package/dist/cli/commands/generate-system-settings.js.map +1 -1
  103. package/dist/cli/commands/init.js +1 -1
  104. package/dist/cli/commands/init.js.map +1 -1
  105. package/dist/cli/commands/process.d.ts +8 -0
  106. package/dist/cli/commands/process.d.ts.map +1 -0
  107. package/dist/cli/commands/process.js +444 -0
  108. package/dist/cli/commands/process.js.map +1 -0
  109. package/dist/cli/commands/role.d.ts +5 -2
  110. package/dist/cli/commands/role.d.ts.map +1 -1
  111. package/dist/cli/commands/role.js +145 -18
  112. package/dist/cli/commands/role.js.map +1 -1
  113. package/dist/cli/commands/user-cmd.d.ts.map +1 -1
  114. package/dist/cli/commands/user-cmd.js +41 -50
  115. package/dist/cli/commands/user-cmd.js.map +1 -1
  116. package/dist/cli/generators/capability-generator.d.ts.map +1 -1
  117. package/dist/cli/generators/capability-generator.js +131 -5
  118. package/dist/cli/generators/capability-generator.js.map +1 -1
  119. package/dist/cli/helpers/app-tsx-wiring.d.ts.map +1 -1
  120. package/dist/cli/helpers/app-tsx-wiring.js +21 -14
  121. package/dist/cli/helpers/app-tsx-wiring.js.map +1 -1
  122. package/dist/cli/helpers/auth-client.d.ts +19 -0
  123. package/dist/cli/helpers/auth-client.d.ts.map +1 -0
  124. package/dist/cli/helpers/auth-client.js +42 -0
  125. package/dist/cli/helpers/auth-client.js.map +1 -0
  126. package/dist/cli/index.d.ts.map +1 -1
  127. package/dist/cli/index.js +2 -0
  128. package/dist/cli/index.js.map +1 -1
  129. package/dist/cli/templates/index.d.ts +1 -0
  130. package/dist/cli/templates/index.d.ts.map +1 -1
  131. package/dist/cli/templates/index.js +1 -0
  132. package/dist/cli/templates/index.js.map +1 -1
  133. package/dist/cli/templates/process-management-page.d.ts +8 -0
  134. package/dist/cli/templates/process-management-page.d.ts.map +1 -0
  135. package/dist/cli/templates/process-management-page.js +824 -0
  136. package/dist/cli/templates/process-management-page.js.map +1 -0
  137. package/dist/cli/templates/user-management-page.d.ts +2 -1
  138. package/dist/cli/templates/user-management-page.d.ts.map +1 -1
  139. package/dist/cli/templates/user-management-page.js +321 -62
  140. package/dist/cli/templates/user-management-page.js.map +1 -1
  141. package/dist/config.d.ts +371 -35
  142. package/dist/config.d.ts.map +1 -1
  143. package/dist/config.js +31 -2
  144. package/dist/config.js.map +1 -1
  145. package/dist/index.d.ts +5 -0
  146. package/dist/index.d.ts.map +1 -1
  147. package/dist/index.js +5 -0
  148. package/dist/index.js.map +1 -1
  149. package/dist/types/auth.d.ts +0 -2
  150. package/dist/types/auth.d.ts.map +1 -1
  151. package/dist/types/config.d.ts +4 -0
  152. package/dist/types/config.d.ts.map +1 -1
  153. package/dist/types/event.d.ts +87 -0
  154. package/dist/types/event.d.ts.map +1 -0
  155. package/dist/types/event.js +38 -0
  156. package/dist/types/event.js.map +1 -0
  157. package/dist/types/index.d.ts +3 -0
  158. package/dist/types/index.d.ts.map +1 -1
  159. package/dist/types/index.js +1 -0
  160. package/dist/types/index.js.map +1 -1
  161. package/dist/types/process.d.ts +106 -0
  162. package/dist/types/process.d.ts.map +1 -0
  163. package/dist/types/process.js +5 -0
  164. package/dist/types/process.js.map +1 -0
  165. package/package.json +3 -1
@@ -1,8 +1,8 @@
1
1
  ---
2
- name: {{projectName}}-data
2
+ name: {{projectName}}
3
3
  description: |
4
4
  ⚠️ TODO: 根据下方 [TODO] 标记补全触发短语。阅读 references/models.md 中的数据模型和 AI 按钮定义,
5
- 编写触发短语,包含:用户语言中的常见增删改查动词、各数据模型相关的操作、AI 按钮的标签。
5
+ 编写触发短语,包含:用户语言中的常见增删改查动词、各数据模型相关的操作、AI 按钮的标签<!-- AUTH_DESC --><!-- EVENTS_DESC --><!-- PROCESS_DESC -->
6
6
  格式:"This skill should be used when the user asks to '短语1', '短语2',
7
7
  or any request about <此项目管理的内容> in the {{projectName}} project."
8
8
  version: 1.0.0
@@ -10,23 +10,34 @@ version: 1.0.0
10
10
 
11
11
  # {{projectName}} — App Skill
12
12
 
13
- > **此文件由 `loom generate capabilities` 生成。标记为 [TODO] 的部分需要手动编辑补全。**
13
+ > **此文件由 `loom generate capabilities` 生成。标记为 [TODO] 的部分需要手动编辑补全。**
14
14
  > references/models.md 和 references/data-semantics.md 会每次重新生成,无需手动编辑。
15
15
 
16
16
  ## Overview
17
17
 
18
18
  [TODO: 阅读 references/models.md,用2-3句话描述项目做什么、管理哪些数据模型、用户如何通过 AI 对话与数据交互。]
19
+ <!-- AUTH_OVERVIEW -->
20
+ <!-- EVENTS_OVERVIEW -->
21
+ <!-- PROCESS_OVERVIEW -->
19
22
 
20
23
  ## Usage Scenarios
21
24
 
22
25
  **必须加载 references/models.md 和 references/data-semantics.md**,这两个文件包含从 loom.config.ts 动态注入的项目特定信息,不加载则无法生成正确内容:
23
26
  - models.md — 当前项目的数据模型字段表(字段名、类型、enum 取值、默认值)、AI 按钮定义(id、label、prompt、placement)、CLI 命令语法(read/write/update/delete,不要使用 create/list 等不存在的命令)。
24
27
  - data-semantics.md — 当前项目的数据模型名称列表、write 的 --data JSON 构造规则(字段类型格式、enum 取值约束、贴合业务的真实示例值)、read 的 --filter JSON 构造规则(优先用 enum/boolean 字段筛选、跨模型关联查询)。
28
+ <!-- AUTH_SCENARIOS_LOAD -->
29
+ <!-- PROCESS_SCENARIOS_LOAD -->
25
30
 
26
- [TODO: 生成8-10个典型用户请求,每个格式:用户说的话 → 对应的 `loom data` CLI 命令。每个数据模型至少包含一个场景。]
31
+ [TODO: 生成5-10个典型用户请求,每个格式:用户说的话 → 对应的 `loom data` CLI 命令。每个数据模型至少包含一个场景。]
32
+ <!-- AUTH_SCENARIOS -->
33
+ <!-- EVENTS_SCENARIOS -->
34
+ <!-- PROCESS_SCENARIOS -->
27
35
 
28
36
  ## Technical Reference
29
37
 
38
+ <!-- CLI_AUTH -->
30
39
  - 数据模型结构、CLI 语法和操作规范:**references/models.md**
31
40
  - 语义引导(示例数据生成、筛选选择、关系推断):**references/data-semantics.md**
32
- <!-- AUTH_REF -->
41
+ <!-- AUTH_REF -->
42
+ <!-- EVENTS_REF -->
43
+ <!-- PROCESS_REF -->
@@ -1,19 +1,5 @@
1
1
  # Auth Commands Reference
2
2
 
3
- ## CLI Authentication
4
-
5
- CLI commands require authentication when auth is enabled. Provide token via:
6
-
7
- 1. **`--token` flag**: `loom data read <model> --token <jwt>`
8
- 2. **`LOOM_TOKEN` env**: `LOOM_TOKEN=<jwt> loom data read <model>`
9
-
10
- When auth is not enabled, CLI commands use local DataAdapter without token.
11
-
12
- ### AI Chat Sessions
13
-
14
- When using AI chat (web UI), `LOOM_TOKEN` is automatically set in the AI's environment.
15
- AI can run `loom data read`, `loom user list`, etc. directly — the token matches the logged-in user's identity and permissions.
16
-
17
3
  ## Authentication Commands
18
4
 
19
5
  ### Login
@@ -65,12 +51,30 @@ loom user delete <id> --token <admin-jwt>
65
51
  loom user role <id> <role> --token <admin-jwt>
66
52
  ```
67
53
 
68
- ## Role Info
54
+ ## Role Management
69
55
 
70
56
  ### List Roles
71
57
  ```bash
72
58
  loom role list [--token <jwt>]
73
59
  ```
60
+ Note: `role list` does not require authentication (the endpoint is public).
61
+
62
+ ### Create Role (admin required)
63
+ ```bash
64
+ loom role create <name> -p '[{"model":"*","level":"read"}]' --token <admin-jwt>
65
+ ```
66
+
67
+ ### Update Role (admin required)
68
+ ```bash
69
+ loom role update <name> -n <new-name> --token <admin-jwt>
70
+ loom role update <name> -p '[{"model":"items","level":"write"}]' --token <admin-jwt>
71
+ ```
72
+
73
+ ### Delete Role (admin required)
74
+ ```bash
75
+ loom role delete <name> --token <admin-jwt>
76
+ ```
77
+ Cannot delete a role that still has assigned users.
74
78
 
75
79
  ### Permission Levels
76
80
  ```bash
@@ -89,8 +93,6 @@ loom data delete <model> --id <id> --token <jwt>
89
93
  loom data schema <model> --token <jwt>
90
94
  ```
91
95
 
92
- Optional: `--server <url>` (default: http://localhost:3000)
93
-
94
96
  ## Permission Model
95
97
 
96
98
  ### Levels (hierarchical)
@@ -115,7 +117,6 @@ auth: {
115
117
  defaults: {
116
118
  read: 'read',
117
119
  write: 'write',
118
- readIncludesAiButtons: false, // viewer sees AI buttons?
119
120
  writeExcludesDelete: false, // writer can delete?
120
121
  },
121
122
  },
@@ -146,7 +147,10 @@ Used by Process automation to execute as the user.
146
147
  | POST | /api/v1/auth/logout | Yes | Logout |
147
148
  | POST | /api/v1/auth/refresh | No* | Refresh token |
148
149
  | GET | /api/v1/auth/whoami | Yes | Current user |
149
- | GET | /api/v1/auth/roles | Yes | List roles |
150
+ | GET | /api/v1/auth/roles | No | List roles |
151
+ | POST | /api/v1/auth/roles | Admin | Create role |
152
+ | PUT | /api/v1/auth/roles/:role | Admin | Update role |
153
+ | DELETE | /api/v1/auth/roles/:role | Admin | Delete role |
150
154
  | GET | /api/v1/auth/users | Admin | List users |
151
155
  | POST | /api/v1/auth/users | Admin | Create user |
152
156
  | GET | /api/v1/auth/users/:id | Self/Admin | Get user |
@@ -0,0 +1,119 @@
1
+ # 事件系统参考
2
+
3
+ Loom 事件系统在数据变更和系统操作时自动触发事件,可用于通知、审计和自动化。
4
+
5
+ ## 事件模式格式
6
+
7
+ 事件使用 `category:action:target` 三段式模式:
8
+
9
+ | 段 | 说明 | 示例 |
10
+ |----|------|------|
11
+ | category | 事件类别 | `data`, `user`, `skill`, `ai`, `session`, `file` |
12
+ | action | 操作类型 | `create`, `update`, `delete`, `login`, `logout` |
13
+ | target | 操作对象 | 模型名、`models`、技能名等 |
14
+
15
+ ## 通配符订阅
16
+
17
+ | 通配符 | 匹配规则 | 示例 |
18
+ |--------|----------|------|
19
+ | `*` | 单段匹配 | `data:*:tasks` 匹配 `data:create:tasks`、`data:update:tasks` |
20
+ | `**` | 任意深度匹配 | `data:**` 匹配所有 data 类事件 |
21
+
22
+ ## 数据事件(EventEmittingAdapter 自动触发)
23
+
24
+ 这些事件由 DataAdapter 操作自动触发,无需手动代码:
25
+
26
+ | 事件模式 | 触发时机 | Payload 字段 |
27
+ |----------|----------|-------------|
28
+ | `data:create:<model>` | 创建记录 | model, id, data |
29
+ | `data:update:<model>` | 更新记录 | model, id, data, previousData, changedFields |
30
+ | `data:delete:<model>` | 删除记录 | model, id, previousData |
31
+ | `data:import:<model>` | CSV 导入完成 | model, imported, errors |
32
+ | `data:batch_delete:<model>` | 批量删除完成 | model, count, errors |
33
+
34
+ ## 认证事件
35
+
36
+ | 事件模式 | 触发时机 | Payload 字段 |
37
+ |----------|----------|-------------|
38
+ | `user:login` | 用户登录 | userId, username, role |
39
+ | `user:logout` | 用户登出 | userId |
40
+ | `user:created` | 创建用户 | userId, username, role |
41
+ | `user:updated` | 更新用户 | userId, username, role |
42
+ | `user:deleted` | 删除用户 | userId |
43
+
44
+ ## 技能管理事件
45
+
46
+ | 事件模式 | 触发时机 | Payload 字段 |
47
+ |----------|----------|-------------|
48
+ | `skill:created` | 创建技能 | skillName |
49
+ | `skill:deleted` | 删除技能 | skillName |
50
+ | `skill:file_updated` | 更新技能文件 | skillName, filename, path |
51
+
52
+ ## AI 配置事件
53
+
54
+ | 事件模式 | 触发时机 | Payload 字段 |
55
+ |----------|----------|-------------|
56
+ | `ai:models_updated` | 模型列表更新 | count |
57
+
58
+ ## 会话事件
59
+
60
+ | 事件模式 | 触发时机 | Payload 字段 |
61
+ |----------|----------|-------------|
62
+ | `session:created` | 创建会话 | sessionId |
63
+ | `session:deleted` | 删除会话 | sessionId |
64
+ | `session:truncated` | 截断会话消息 | sessionId, fromIndex |
65
+
66
+ ## 文件上传事件
67
+
68
+ | 事件模式 | 触发时机 | Payload 字段 |
69
+ |----------|----------|-------------|
70
+ | `file:uploaded` | 文件上传成功 | filename, sessionId, path, size |
71
+
72
+ ## 配置声明式订阅
73
+
74
+ 在 `loom.config.ts` 中声明事件处理器:
75
+
76
+ ```typescript
77
+ export default defineConfig({
78
+ // ...
79
+ events: {
80
+ subscriptions: [
81
+ {
82
+ pattern: 'data:create:orders',
83
+ handler: 'webhook',
84
+ config: { url: 'https://example.com/webhook' },
85
+ },
86
+ {
87
+ pattern: 'user:login',
88
+ handler: 'log',
89
+ config: { level: 'info' },
90
+ },
91
+ ],
92
+ },
93
+ });
94
+ ```
95
+
96
+ ## 事件 API
97
+
98
+ | 端点 | 方法 | 说明 |
99
+ |------|------|------|
100
+ | `/api/v1/events/notify` | POST | 外部事件注入(CLI 使用) |
101
+ | `/api/v1/events/patterns` | GET | 查看已注册的事件模式 |
102
+
103
+ ### POST /api/v1/events/notify
104
+
105
+ ```json
106
+ {
107
+ "pattern": "data:create:tasks",
108
+ "payload": { "model": "tasks", "id": "rec_123" },
109
+ "source": "cli"
110
+ }
111
+ ```
112
+
113
+ ## 订阅可用处理器
114
+
115
+ | handler | 说明 | config 字段 |
116
+ |---------|------|------------|
117
+ | `log` | 写入服务器日志 | `level`: info/debug/warn |
118
+ | `webhook` | 发送 HTTP 请求 | `url`, `method`, `headers` |
119
+ | `process` | 启动进程(未来) | `process`, `filter` |
@@ -0,0 +1,90 @@
1
+ # Process Evolution Guide
2
+
3
+ ## Overview
4
+
5
+ Process Evolution is the practice of iteratively improving automated processes based on execution results. Loom provides the tooling (logs, metrics) for AI to analyze and optimize processes over time.
6
+
7
+ ## How Evolution Works
8
+
9
+ 1. **Monitor**: Review execution logs and metrics
10
+ 2. **Analyze**: Identify patterns, failures, and optimization opportunities
11
+ 3. **Decide**: Determine what to change (prompt, trigger, references)
12
+ 4. **Apply**: Update the process definition or PROCESS.md
13
+ 5. **Verify**: Monitor subsequent runs for improvement
14
+
15
+ ## Reading Metrics
16
+
17
+ ```bash
18
+ # Check recent logs
19
+ loom process logs <name> --limit 20
20
+
21
+ # View process status
22
+ loom process status <name>
23
+ ```
24
+
25
+ ### Key Indicators
26
+
27
+ | Metric | Good | Needs Improvement |
28
+ |--------|------|-------------------|
29
+ | Success rate | > 95% | < 80% |
30
+ | Avg duration | Stable or decreasing | Increasing trend |
31
+ | Timeout rate | 0% | > 5% |
32
+ | Error patterns | Unique errors | Repeated same error |
33
+
34
+ ## Evolution Strategies
35
+
36
+ ### Prompt Optimization
37
+
38
+ If a process frequently fails or produces low-quality results:
39
+
40
+ 1. Read the current prompt: `loom process export <name>`
41
+ 2. Analyze failure patterns in logs
42
+ 3. Make the prompt more specific:
43
+ - Add constraints ("Output must be JSON")
44
+ - Add examples ("Here's a good output: ...")
45
+ - Add error handling instructions
46
+ 4. Update: `loom process export <name>` → edit → API update
47
+
48
+ ### Trigger Adjustment
49
+
50
+ If a process runs too often or too rarely:
51
+
52
+ - Adjust cron frequency
53
+ - Add `--event-debounce` for bursty events
54
+ - Add `--event-filter` for selective triggering
55
+
56
+ ```bash
57
+ # Increase debounce for bursty events
58
+ loom process update <name> --event-debounce 5000
59
+
60
+ # Add filter to only trigger on specific conditions
61
+ loom process update <name> --event-filter '{"status":"urgent"}'
62
+ ```
63
+
64
+ ### Reference Updates
65
+
66
+ For full processes, update reference files:
67
+ - Outdated API docs → replace with current
68
+ - Missing context → add new reference files
69
+ - Unnecessary references → remove to reduce prompt size
70
+
71
+ ## Safety Constraints
72
+
73
+ Evolution is limited to these safe operations:
74
+ - **Notify**: Send alerts via events
75
+ - **Data write**: Create/update records via `loom data` CLI
76
+ - **Process update**: Modify process definitions via CLI
77
+
78
+ Evolution MUST NOT:
79
+ - Delete data without explicit user approval
80
+ - Modify other processes without user consent
81
+ - Change authentication or authorization settings
82
+ - Execute shell commands outside the sandbox
83
+
84
+ ## Monitoring Checklist
85
+
86
+ After applying evolution changes:
87
+ 1. Run manually: `loom process run <name>`
88
+ 2. Check result: `loom process logs <name> --limit 1`
89
+ 3. Verify metrics improve over next 5-10 scheduled runs
90
+ 4. Revert if worse: restore previous definition
@@ -0,0 +1,140 @@
1
+ # Process Builder Guide
2
+
3
+ ## Purpose
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.
6
+
7
+ ## Lightweight vs Full Decision
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
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)
20
+
21
+ ## Step-by-Step Creation
22
+
23
+ ### 1. Analyze the Request
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
+ - **Complexity** (lightweight vs full)
30
+
31
+ ### 2. Choose Trigger
32
+
33
+ | Need | Use | Example |
34
+ |------|-----|---------|
35
+ | Periodic schedule | `--cron` | `0 9 * * 1-5` (weekdays 9am) |
36
+ | On data change | `--on-event` | `data:create:tasks` |
37
+ | On user action | `--on-event` | `user:created` |
38
+ | Manual only | Neither | Just `loom process run` |
39
+
40
+ ### 3. Create the Process
41
+
42
+ For lightweight:
43
+ ```bash
44
+ loom process add --name "task-summary" \
45
+ --cron "0 9 * * *" \
46
+ --prompt "Read all tasks created yesterday, summarize key themes, and post a digest" \
47
+ --owner admin
48
+ ```
49
+
50
+ For full:
51
+ ```bash
52
+ # Step 1: Generate scaffold
53
+ loom process generate weekly-report --description "Weekly analytics report"
54
+
55
+ # Step 2: Edit PROCESS.md with detailed flow
56
+ # (AI should write the PROCESS.md content)
57
+
58
+ # Step 3: Add reference files if needed
59
+ # (Copy to .claude/processes/weekly-report/references/)
60
+
61
+ # Step 4: Register the process
62
+ loom process add --name "weekly-report" \
63
+ --cron "0 9 * * 1" \
64
+ --process "weekly-report" \
65
+ --owner admin
66
+ ```
67
+
68
+ ### 4. Verify
69
+
70
+ ```bash
71
+ loom process status <name>
72
+ loom process run <name> # manual test
73
+ loom process logs <name> # check result
74
+ ```
75
+
76
+ ## PROCESS.md Best Practices
77
+
78
+ ### Structure
79
+
80
+ ```markdown
81
+ # Process: <name>
82
+
83
+ ## Description
84
+ What this process does and why.
85
+
86
+ ## Trigger
87
+ When it runs and what triggers it.
88
+
89
+ ## Flow
90
+ Step-by-step instructions:
91
+ 1. Read data from <model>
92
+ 2. Analyze <something>
93
+ 3. Write results to <model>
94
+ 4. Notify <channel>
95
+
96
+ ## Decision Points
97
+ Key decisions the AI should make:
98
+ - If X, do Y
99
+ - If Z, skip to step N
100
+
101
+ ## Metrics
102
+ How success is measured:
103
+ - Execution time < N seconds
104
+ - Error rate < X%
105
+ - Output quality: <criteria>
106
+
107
+ ## Evolution
108
+ How this process should improve:
109
+ - After N runs, review and optimize prompt
110
+ - Track common errors and add handling
111
+ ```
112
+
113
+ ### Tips
114
+ - Be specific in Flow steps — AI follows them literally
115
+ - Include data model names and field names
116
+ - Reference CLI commands: `loom data list <model>`, `loom data create <model>`
117
+ - Use `loom data` commands for data operations, not direct file I/O
118
+ - Include error handling in Decision Points
119
+
120
+ ## Common Cron Patterns
121
+
122
+ | Pattern | Schedule |
123
+ |---------|----------|
124
+ | `*/5 * * * *` | Every 5 minutes |
125
+ | `*/15 * * * *` | Every 15 minutes |
126
+ | `0 * * * *` | Every hour |
127
+ | `0 9 * * *` | Daily at 9 AM |
128
+ | `0 9 * * 1-5` | Weekdays at 9 AM |
129
+ | `0 9 * * 1` | Every Monday at 9 AM |
130
+ | `0 0 1 * *` | First of every month |
131
+
132
+ ## Common Event Patterns
133
+
134
+ | Pattern | When |
135
+ |---------|------|
136
+ | `data:create:<model>` | New record created |
137
+ | `data:update:<model>` | Record updated |
138
+ | `data:delete:<model>` | Record deleted |
139
+ | `user:created` | New user registered |
140
+ | `process:completed:<name>` | Another process finished |
@@ -0,0 +1,93 @@
1
+ # Process Metrics Reference
2
+
3
+ ## Overview
4
+
5
+ Process metrics allow you to define dashboard widgets for monitoring process execution. Metrics are served via the `/api/v1/processes/:name/metrics` endpoint and configured per-process.
6
+
7
+ ## Metrics Config
8
+
9
+ Define metrics using DashboardWidget schema in `--metrics-config <path>` JSON file or via the API.
10
+
11
+ ### Example: metrics-config.json
12
+
13
+ ```json
14
+ [
15
+ {
16
+ "type": "stat",
17
+ "title": "成功率",
18
+ "model": "__process_metrics",
19
+ "aggregate": "sum",
20
+ "field": "completedRuns",
21
+ "color": "#52c41a"
22
+ },
23
+ {
24
+ "type": "stat",
25
+ "title": "失败次数",
26
+ "model": "__process_metrics",
27
+ "aggregate": "sum",
28
+ "field": "failedRuns",
29
+ "color": "#ff4d4f"
30
+ },
31
+ {
32
+ "type": "line",
33
+ "title": "执行趋势",
34
+ "model": "__process_metrics",
35
+ "aggregate": "sum",
36
+ "field": "totalRuns",
37
+ "groupBy": "date",
38
+ "dateInterval": "day"
39
+ }
40
+ ]
41
+ ```
42
+
43
+ ### Available Widget Types
44
+
45
+ | Type | Description | Required Fields |
46
+ |------|-------------|-----------------|
47
+ | `stat` | Single number display | `title`, `model`, `aggregate`, `field` |
48
+ | `line` | Line chart | `title`, `model`, `aggregate`, `field`, `groupBy`, `dateInterval` |
49
+ | `bar` | Bar chart | `title`, `model`, `aggregate`, `field`, `groupBy` |
50
+ | `pie` | Pie chart | `title`, `model`, `field`, `groupBy` |
51
+ | `gauge` | Gauge display | `title`, `model`, `field`, `min`, `max` |
52
+ | `table` | Table view | `title`, `model`, `columns` |
53
+
54
+ ### Available Metrics Fields
55
+
56
+ From `ProcessMetricsAggregate`:
57
+
58
+ | Field | Type | Description |
59
+ |-------|------|-------------|
60
+ | `date` | string | Date (YYYY-MM-DD) |
61
+ | `totalRuns` | number | Total executions |
62
+ | `completedRuns` | number | Successful executions |
63
+ | `failedRuns` | number | Failed executions |
64
+ | `timeoutRuns` | number | Timed out executions |
65
+ | `avgDurationMs` | number | Average duration in ms |
66
+ | `lastRunAt` | string\|null | Last execution timestamp |
67
+ | `lastStatus` | string\|null | Last execution status |
68
+
69
+ ### Setting Metrics Config
70
+
71
+ ```bash
72
+ # During process creation
73
+ loom process add --name "health-check" \
74
+ --cron "*/30 * * * *" \
75
+ --prompt "Check system health" \
76
+ --metrics-config ./health-metrics.json \
77
+ --owner admin
78
+
79
+ # Or create the JSON file first
80
+ echo '[
81
+ {"type":"stat","title":"Success Rate","model":"__process_metrics","aggregate":"sum","field":"completedRuns"},
82
+ {"type":"stat","title":"Avg Duration","model":"__process_metrics","aggregate":"avg","field":"avgDurationMs"}
83
+ ]' > health-metrics.json
84
+ ```
85
+
86
+ ### API Endpoints
87
+
88
+ | Endpoint | Method | Description |
89
+ |----------|--------|-------------|
90
+ | `/api/v1/processes/:name/metrics` | GET | Get aggregated metrics data |
91
+ | `/api/v1/processes/:name/metrics-config` | GET | Get widget configuration |
92
+
93
+ The frontend ProcessManagementPage Metrics tab fetches both endpoints and renders the configured widgets dynamically.