@loom-framework/core 0.1.0-alpha.151 → 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 (110) hide show
  1. package/builtin-skills/app-skill/SKILL.md +15 -5
  2. package/builtin-skills/app-skill/references/auth.md +23 -19
  3. package/builtin-skills/app-skill/references/evolution.md +90 -0
  4. package/builtin-skills/app-skill/references/process-builder.md +140 -0
  5. package/builtin-skills/app-skill/references/process-metrics.md +93 -0
  6. package/builtin-skills/app-skill/references/process.md +222 -0
  7. package/builtin-skills/loom/SKILL.md +9 -7
  8. package/dist/backend/index.d.ts +4 -0
  9. package/dist/backend/index.d.ts.map +1 -1
  10. package/dist/backend/index.js +52 -2
  11. package/dist/backend/index.js.map +1 -1
  12. package/dist/backend/process/engine.d.ts +84 -0
  13. package/dist/backend/process/engine.d.ts.map +1 -0
  14. package/dist/backend/process/engine.js +511 -0
  15. package/dist/backend/process/engine.js.map +1 -0
  16. package/dist/backend/process/index.d.ts +7 -0
  17. package/dist/backend/process/index.d.ts.map +1 -0
  18. package/dist/backend/process/index.js +6 -0
  19. package/dist/backend/process/index.js.map +1 -0
  20. package/dist/backend/process/logger.d.ts +30 -0
  21. package/dist/backend/process/logger.d.ts.map +1 -0
  22. package/dist/backend/process/logger.js +132 -0
  23. package/dist/backend/process/logger.js.map +1 -0
  24. package/dist/backend/process/queue.d.ts +31 -0
  25. package/dist/backend/process/queue.d.ts.map +1 -0
  26. package/dist/backend/process/queue.js +80 -0
  27. package/dist/backend/process/queue.js.map +1 -0
  28. package/dist/backend/process/registry.d.ts +25 -0
  29. package/dist/backend/process/registry.d.ts.map +1 -0
  30. package/dist/backend/process/registry.js +98 -0
  31. package/dist/backend/process/registry.js.map +1 -0
  32. package/dist/backend/process/trigger.d.ts +29 -0
  33. package/dist/backend/process/trigger.d.ts.map +1 -0
  34. package/dist/backend/process/trigger.js +108 -0
  35. package/dist/backend/process/trigger.js.map +1 -0
  36. package/dist/backend/routes/auth-routes.d.ts +5 -0
  37. package/dist/backend/routes/auth-routes.d.ts.map +1 -1
  38. package/dist/backend/routes/auth-routes.js +221 -1
  39. package/dist/backend/routes/auth-routes.js.map +1 -1
  40. package/dist/backend/routes/index.d.ts +2 -0
  41. package/dist/backend/routes/index.d.ts.map +1 -1
  42. package/dist/backend/routes/index.js +1 -0
  43. package/dist/backend/routes/index.js.map +1 -1
  44. package/dist/backend/routes/process-routes.d.ts +15 -0
  45. package/dist/backend/routes/process-routes.d.ts.map +1 -0
  46. package/dist/backend/routes/process-routes.js +237 -0
  47. package/dist/backend/routes/process-routes.js.map +1 -0
  48. package/dist/cli/commands/auth.d.ts.map +1 -1
  49. package/dist/cli/commands/auth.js +30 -22
  50. package/dist/cli/commands/auth.js.map +1 -1
  51. package/dist/cli/commands/data.d.ts.map +1 -1
  52. package/dist/cli/commands/data.js +36 -47
  53. package/dist/cli/commands/data.js.map +1 -1
  54. package/dist/cli/commands/generate-system-settings.d.ts +3 -2
  55. package/dist/cli/commands/generate-system-settings.d.ts.map +1 -1
  56. package/dist/cli/commands/generate-system-settings.js +50 -7
  57. package/dist/cli/commands/generate-system-settings.js.map +1 -1
  58. package/dist/cli/commands/init.js +1 -1
  59. package/dist/cli/commands/init.js.map +1 -1
  60. package/dist/cli/commands/process.d.ts +8 -0
  61. package/dist/cli/commands/process.d.ts.map +1 -0
  62. package/dist/cli/commands/process.js +444 -0
  63. package/dist/cli/commands/process.js.map +1 -0
  64. package/dist/cli/commands/role.d.ts +5 -2
  65. package/dist/cli/commands/role.d.ts.map +1 -1
  66. package/dist/cli/commands/role.js +145 -18
  67. package/dist/cli/commands/role.js.map +1 -1
  68. package/dist/cli/commands/user-cmd.d.ts.map +1 -1
  69. package/dist/cli/commands/user-cmd.js +41 -50
  70. package/dist/cli/commands/user-cmd.js.map +1 -1
  71. package/dist/cli/generators/capability-generator.d.ts.map +1 -1
  72. package/dist/cli/generators/capability-generator.js +121 -6
  73. package/dist/cli/generators/capability-generator.js.map +1 -1
  74. package/dist/cli/helpers/app-tsx-wiring.d.ts.map +1 -1
  75. package/dist/cli/helpers/app-tsx-wiring.js +21 -14
  76. package/dist/cli/helpers/app-tsx-wiring.js.map +1 -1
  77. package/dist/cli/helpers/auth-client.d.ts +19 -0
  78. package/dist/cli/helpers/auth-client.d.ts.map +1 -0
  79. package/dist/cli/helpers/auth-client.js +42 -0
  80. package/dist/cli/helpers/auth-client.js.map +1 -0
  81. package/dist/cli/index.d.ts.map +1 -1
  82. package/dist/cli/index.js +2 -0
  83. package/dist/cli/index.js.map +1 -1
  84. package/dist/cli/templates/index.d.ts +1 -0
  85. package/dist/cli/templates/index.d.ts.map +1 -1
  86. package/dist/cli/templates/index.js +1 -0
  87. package/dist/cli/templates/index.js.map +1 -1
  88. package/dist/cli/templates/process-management-page.d.ts +8 -0
  89. package/dist/cli/templates/process-management-page.d.ts.map +1 -0
  90. package/dist/cli/templates/process-management-page.js +824 -0
  91. package/dist/cli/templates/process-management-page.js.map +1 -0
  92. package/dist/cli/templates/user-management-page.d.ts +2 -1
  93. package/dist/cli/templates/user-management-page.d.ts.map +1 -1
  94. package/dist/cli/templates/user-management-page.js +321 -62
  95. package/dist/cli/templates/user-management-page.js.map +1 -1
  96. package/dist/config.d.ts +43 -23
  97. package/dist/config.d.ts.map +1 -1
  98. package/dist/config.js +8 -2
  99. package/dist/config.js.map +1 -1
  100. package/dist/types/auth.d.ts +0 -2
  101. package/dist/types/auth.d.ts.map +1 -1
  102. package/dist/types/config.d.ts +2 -0
  103. package/dist/types/config.d.ts.map +1 -1
  104. package/dist/types/index.d.ts +1 -0
  105. package/dist/types/index.d.ts.map +1 -1
  106. package/dist/types/process.d.ts +106 -0
  107. package/dist/types/process.d.ts.map +1 -0
  108. package/dist/types/process.js +5 -0
  109. package/dist/types/process.js.map +1 -0
  110. 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,24 +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
41
  <!-- AUTH_REF -->
33
- <!-- EVENTS_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,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.
@@ -0,0 +1,222 @@
1
+ # Process CLI Reference
2
+
3
+ ## Overview
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.
6
+
7
+ ## Commands
8
+
9
+ ### `loom process add`
10
+
11
+ Create a new process definition.
12
+
13
+ ```bash
14
+ # Lightweight process (inline prompt)
15
+ loom process add --name "daily-summary" \
16
+ --cron "0 9 * * 1-5" \
17
+ --prompt "Summarize yesterday's data and email the team" \
18
+ --owner admin
19
+
20
+ # Full process (with PROCESS.md)
21
+ loom process add --name "weekly-report" \
22
+ --cron "0 9 * * 1" \
23
+ --process "weekly-report" \
24
+ --owner admin \
25
+ --description "Weekly analytics report"
26
+
27
+ # Event-triggered process
28
+ loom process add --name "on-task-create" \
29
+ --on-event "data:create:tasks" \
30
+ --prompt "Analyze the new task and suggest priorities" \
31
+ --owner admin \
32
+ --event-debounce 2000
33
+
34
+ # With metrics config
35
+ loom process add --name "health-check" \
36
+ --cron "*/30 * * * *" \
37
+ --prompt "Check system health" \
38
+ --metrics-config ./metrics-config.json \
39
+ --owner bot
40
+ ```
41
+
42
+ **Options:**
43
+ | Flag | Required | Description |
44
+ |------|----------|-------------|
45
+ | `--name` | Yes | Process name (^[a-zA-Z][a-zA-Z0-9_-]*$) |
46
+ | `--prompt` | One of | Inline prompt for lightweight process |
47
+ | `--process` | One of | Full process name (expects .claude/processes/{name}/PROCESS.md) |
48
+ | `--cron` | No | Cron schedule expression |
49
+ | `--cron-timezone` | No | Timezone for cron (e.g., "America/New_York") |
50
+ | `--on-event` | No | EventBus pattern (e.g., "data:create:tasks") |
51
+ | `--event-filter` | No | JSON filter on event payload fields |
52
+ | `--event-debounce` | No | Debounce window in ms (default: 1000) |
53
+ | `--description` | No | Process description |
54
+ | `--owner` | No | Owner username (default: from processes config) |
55
+ | `--owner-token` | No | Direct JWT token (bypasses runtime resolution) |
56
+ | `--metrics-config` | No | Path to metrics DashboardWidget config JSON |
57
+ | `--token` | No | Auth token (or set LOOM_TOKEN) |
58
+ | `--server` | No | Server URL (or set LOOM_SERVER, default: http://localhost:3000) |
59
+
60
+ ### `loom process list`
61
+
62
+ List all processes.
63
+
64
+ ```bash
65
+ loom process list
66
+ loom process list --status active
67
+ loom process list --status paused
68
+ ```
69
+
70
+ ### `loom process status <name>`
71
+
72
+ Show detailed process status.
73
+
74
+ ```bash
75
+ loom process status daily-summary
76
+ ```
77
+
78
+ ### `loom process run <name>`
79
+
80
+ Manually trigger a process execution.
81
+
82
+ ```bash
83
+ loom process run daily-summary
84
+ loom process run on-task-create --payload '{"model":"tasks","id":"task_123"}'
85
+ ```
86
+
87
+ ### `loom process pause <name>`
88
+
89
+ Pause a process (stops triggers, manual run still works).
90
+
91
+ ```bash
92
+ loom process pause daily-summary
93
+ ```
94
+
95
+ ### `loom process resume <name>`
96
+
97
+ Resume a paused process.
98
+
99
+ ```bash
100
+ loom process resume daily-summary
101
+ ```
102
+
103
+ ### `loom process update <name>`
104
+
105
+ Update an existing process definition.
106
+
107
+ ```bash
108
+ loom process update daily-summary --cron "0 10 * * 1-5"
109
+ loom process update on-task-create --prompt "Updated prompt text"
110
+ loom process update daily-summary --description "Updated description" --cron "0 8 * * 1-5"
111
+ ```
112
+
113
+ **Options:**
114
+ | Flag | Required | Description |
115
+ |------|----------|-------------|
116
+ | `--cron` | No | Update cron schedule expression |
117
+ | `--cron-timezone` | No | Update cron timezone |
118
+ | `--on-event` | No | Update event trigger pattern |
119
+ | `--event-filter` | No | Update event payload filter as JSON |
120
+ | `--event-debounce` | No | Update debounce window in ms |
121
+ | `--prompt` | No | Update inline prompt |
122
+ | `--description` | No | Update description |
123
+ | `--token` | No | Auth token (or set LOOM_TOKEN) |
124
+ | `--server` | No | Server URL (or set LOOM_SERVER, default: http://localhost:3000) |
125
+
126
+ ### `loom process remove <name>`
127
+
128
+ Remove a process definition. Logs are preserved.
129
+
130
+ ```bash
131
+ loom process remove daily-summary
132
+ ```
133
+
134
+ ### `loom process logs <name> [runId]`
135
+
136
+ View execution logs. When `runId` is provided, shows details for a single run.
137
+
138
+ ```bash
139
+ # List recent logs
140
+ loom process logs daily-summary
141
+ loom process logs daily-summary --limit 50
142
+ loom process logs daily-summary --offset 10
143
+
144
+ # View a specific run
145
+ loom process logs daily-summary run_abc123
146
+ ```
147
+
148
+ ### `loom process generate <name>`
149
+
150
+ Create PROCESS.md scaffold directory (for full process mode). Called by AI, not directly by users.
151
+
152
+ ```bash
153
+ loom process generate daily-report --description "Daily report generator"
154
+ ```
155
+
156
+ ### `loom process export <name>`
157
+
158
+ Export process definition as JSON.
159
+
160
+ ```bash
161
+ loom process export daily-summary
162
+ ```
163
+
164
+ ## Process Modes
165
+
166
+ ### Lightweight Mode (`--prompt`)
167
+
168
+ - Inline prompt, no PROCESS.md file
169
+ - Best for simple, single-task automations
170
+ - Quick to set up and modify
171
+
172
+ ### Full Mode (`--process`)
173
+
174
+ - Has PROCESS.md at `.claude/processes/{name}/PROCESS.md`
175
+ - Can include reference files in `.claude/processes/{name}/references/`
176
+ - Best for complex, multi-step workflows
177
+ - Supports Metrics and Evolution sections
178
+
179
+ ## Trigger Types
180
+
181
+ ### Cron
182
+ Standard 5-field cron expression: `minute hour day month weekday`
183
+ ```
184
+ */5 * * * * — Every 5 minutes
185
+ 0 9 * * 1-5 — Weekdays at 9 AM
186
+ 0 0 1 * * — First of every month
187
+ ```
188
+
189
+ ### Event
190
+ EventBus pattern matching: `{category}:{action}:{target}`
191
+ ```
192
+ data:create:tasks — When a task is created
193
+ data:update:* — Any data update
194
+ user:created — When a user is created
195
+ process:completed:xxx — When process xxx completes
196
+ ```
197
+
198
+ ### Manual
199
+ `loom process run <name>` — immediate execution, works even when paused.
200
+
201
+ ## Service Token Authentication
202
+
203
+ When auth is enabled, processes need a service token to operate:
204
+ - `--owner <username>`: Runtime resolution via UserStore (recommended)
205
+ - `--owner-token <jwt>`: Direct JWT token (less secure, stored in processes.json)
206
+
207
+ ## Execution Model
208
+
209
+ 1. Trigger fires → entry enqueued
210
+ 2. Queue slot available → process starts
211
+ 3. AI prompt built (PROCESS.md + references + event context)
212
+ 4. Claude Code engine executes with timeout
213
+ 5. Result logged to `.loom/process-logs/{name}/{runId}.json`
214
+ 6. Event emitted: `process:started`, `process:completed`, or `process:failed`
215
+
216
+ ## Concurrency
217
+
218
+ Controlled by `processes.maxConcurrent` in loom.config.ts (default: 5). When max is reached, new triggers queue until a slot opens.
219
+
220
+ ## Debounce
221
+
222
+ Event triggers have `eventDebounceMs` (default: 1000ms). Rapid events within the window are collapsed — only one execution fires with the last event's payload.