@litmers/cursorflow-orchestrator 0.1.37 → 0.1.40
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.
- package/README.md +13 -13
- package/commands/cursorflow-init.md +113 -32
- package/commands/cursorflow-prepare.md +146 -339
- package/commands/cursorflow-run.md +148 -131
- package/dist/cli/add.js +8 -4
- package/dist/cli/add.js.map +1 -1
- package/dist/cli/index.js +2 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/new.js +3 -5
- package/dist/cli/new.js.map +1 -1
- package/dist/cli/prepare.js +0 -1
- package/dist/cli/prepare.js.map +1 -1
- package/dist/cli/resume.js +24 -15
- package/dist/cli/resume.js.map +1 -1
- package/dist/cli/run.js +1 -6
- package/dist/cli/run.js.map +1 -1
- package/dist/cli/setup-commands.d.ts +1 -0
- package/dist/cli/setup-commands.js +1 -0
- package/dist/cli/setup-commands.js.map +1 -1
- package/dist/core/orchestrator.js +13 -5
- package/dist/core/orchestrator.js.map +1 -1
- package/dist/core/runner/agent.d.ts +5 -1
- package/dist/core/runner/agent.js +31 -1
- package/dist/core/runner/agent.js.map +1 -1
- package/dist/core/runner/pipeline.d.ts +0 -1
- package/dist/core/runner/pipeline.js +136 -173
- package/dist/core/runner/pipeline.js.map +1 -1
- package/dist/core/runner/prompt.d.ts +0 -1
- package/dist/core/runner/prompt.js +11 -16
- package/dist/core/runner/prompt.js.map +1 -1
- package/dist/core/runner/task.d.ts +1 -2
- package/dist/core/runner/task.js +31 -40
- package/dist/core/runner/task.js.map +1 -1
- package/dist/core/runner.js +15 -2
- package/dist/core/runner.js.map +1 -1
- package/dist/core/stall-detection.d.ts +32 -4
- package/dist/core/stall-detection.js +151 -149
- package/dist/core/stall-detection.js.map +1 -1
- package/dist/services/logging/console.d.ts +7 -1
- package/dist/services/logging/console.js +13 -3
- package/dist/services/logging/console.js.map +1 -1
- package/dist/services/logging/formatter.d.ts +1 -0
- package/dist/services/logging/formatter.js +6 -3
- package/dist/services/logging/formatter.js.map +1 -1
- package/dist/types/config.d.ts +3 -1
- package/dist/types/logging.d.ts +1 -1
- package/dist/types/task.d.ts +3 -8
- package/dist/utils/config.js +5 -0
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/doctor.js +4 -4
- package/dist/utils/doctor.js.map +1 -1
- package/dist/utils/enhanced-logger.d.ts +1 -1
- package/dist/utils/enhanced-logger.js +3 -3
- package/dist/utils/enhanced-logger.js.map +1 -1
- package/dist/utils/git.d.ts +12 -1
- package/dist/utils/git.js +56 -1
- package/dist/utils/git.js.map +1 -1
- package/dist/utils/health.js +13 -13
- package/dist/utils/health.js.map +1 -1
- package/dist/utils/log-formatter.d.ts +1 -1
- package/dist/utils/log-formatter.js +45 -8
- package/dist/utils/log-formatter.js.map +1 -1
- package/dist/utils/logger.js +2 -2
- package/dist/utils/logger.js.map +1 -1
- package/package.json +1 -1
- package/src/cli/add.ts +9 -4
- package/src/cli/index.ts +3 -0
- package/src/cli/new.ts +3 -5
- package/src/cli/prepare.ts +0 -1
- package/src/cli/resume.ts +28 -19
- package/src/cli/run.ts +1 -6
- package/src/cli/setup-commands.ts +1 -1
- package/src/core/orchestrator.ts +14 -5
- package/src/core/runner/agent.ts +36 -4
- package/src/core/runner/pipeline.ts +149 -182
- package/src/core/runner/prompt.ts +11 -18
- package/src/core/runner/task.ts +32 -41
- package/src/core/runner.ts +17 -2
- package/src/core/stall-detection.ts +263 -147
- package/src/services/logging/console.ts +13 -3
- package/src/services/logging/formatter.ts +6 -3
- package/src/types/config.ts +3 -1
- package/src/types/logging.ts +4 -2
- package/src/types/task.ts +3 -8
- package/src/utils/config.ts +6 -0
- package/src/utils/doctor.ts +5 -5
- package/src/utils/enhanced-logger.ts +3 -3
- package/src/utils/flow.ts +1 -0
- package/src/utils/git.ts +61 -1
- package/src/utils/health.ts +15 -15
- package/src/utils/log-formatter.ts +51 -8
- package/src/utils/logger.ts +2 -2
- package/commands/cursorflow-add.md +0 -159
- package/commands/cursorflow-clean.md +0 -84
- package/commands/cursorflow-doctor.md +0 -102
- package/commands/cursorflow-models.md +0 -51
- package/commands/cursorflow-monitor.md +0 -90
- package/commands/cursorflow-new.md +0 -87
- package/commands/cursorflow-resume.md +0 -205
- package/commands/cursorflow-signal.md +0 -52
- package/commands/cursorflow-stop.md +0 -55
- package/commands/cursorflow-triggers.md +0 -250
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
# CursorFlow Event Triggers & Webhooks
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
CursorFlow emits various status changes during the orchestration process as **Events**. Through this event system, you can send notifications to external services (Webhooks) or execute custom logic to automate complex workflows.
|
|
6
|
-
|
|
7
|
-
## Key Concepts
|
|
8
|
-
|
|
9
|
-
### 1. Events
|
|
10
|
-
Occurrences during the lifecycle of the orchestrator, lanes, tasks, agents, and reviewers. Each event has a unique type and payload.
|
|
11
|
-
|
|
12
|
-
### 2. Webhooks
|
|
13
|
-
A mechanism to send emitted events to external HTTP endpoints. Configured via `cursorflow.config.js`, allowing you to filter for specific events.
|
|
14
|
-
|
|
15
|
-
### 3. Dependency Triggers
|
|
16
|
-
Internally, when a lane completes, any subsequent lanes that depend on it are automatically executed (triggered). This is managed by the DAG (Directed Acyclic Graph) scheduler.
|
|
17
|
-
|
|
18
|
-
## Supported Events
|
|
19
|
-
|
|
20
|
-
| Category | Event Type | Occurrence |
|
|
21
|
-
| :--- | :--- | :--- |
|
|
22
|
-
| **Orchestration** | `orchestration.started` | When the entire workflow begins |
|
|
23
|
-
| | `orchestration.completed` | When all lanes complete successfully |
|
|
24
|
-
| | `orchestration.failed` | When an error occurs during the workflow |
|
|
25
|
-
| **Lane** | `lane.started` | When an individual lane starts execution |
|
|
26
|
-
| | `lane.completed` | When all tasks in a lane are finished |
|
|
27
|
-
| | `lane.failed` | When an error occurs during lane execution |
|
|
28
|
-
| | `lane.dependency_requested` | When an agent requests to modify external dependencies |
|
|
29
|
-
| **Task** | `task.started` | When an individual task within a lane begins |
|
|
30
|
-
| | `task.completed` | When a task succeeds |
|
|
31
|
-
| | `task.failed` | When a task fails |
|
|
32
|
-
| **Agent** | `agent.prompt_sent` | When a prompt is sent to the AI agent |
|
|
33
|
-
| | `agent.response_received` | When a response is received from the AI agent |
|
|
34
|
-
| **Review** | `review.started` | When the AI review process begins |
|
|
35
|
-
| | `review.completed` | When the AI review completes (includes results) |
|
|
36
|
-
| | `review.approved` | When a review is approved |
|
|
37
|
-
| | `review.rejected` | When a review is rejected and a retry is determined |
|
|
38
|
-
|
|
39
|
-
## Common Event Structure
|
|
40
|
-
|
|
41
|
-
All events passed to listeners have the following common wrapper structure:
|
|
42
|
-
|
|
43
|
-
```typescript
|
|
44
|
-
{
|
|
45
|
-
"id": "evt_1734842400000_abc123", // Unique event ID
|
|
46
|
-
"type": "task.completed", // Event type
|
|
47
|
-
"timestamp": "2024-12-22T10:00:00.000Z", // Timestamp (ISO 8601)
|
|
48
|
-
"runId": "run-1734842400000", // Current orchestration run ID
|
|
49
|
-
"payload": { ... } // Event-specific data (see below)
|
|
50
|
-
}
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
## Event Payload Details
|
|
54
|
-
|
|
55
|
-
### 1. Orchestration
|
|
56
|
-
|
|
57
|
-
#### `orchestration.started`
|
|
58
|
-
- `runId`: Unique run ID
|
|
59
|
-
- `tasksDir`: Path to the directory containing task configuration files
|
|
60
|
-
- `laneCount`: Total number of lanes to be executed
|
|
61
|
-
- `runRoot`: Root directory where logs and status files are stored
|
|
62
|
-
|
|
63
|
-
#### `orchestration.completed`
|
|
64
|
-
- `runId`: Unique run ID
|
|
65
|
-
- `laneCount`: Total number of lanes
|
|
66
|
-
- `completedCount`: Number of successfully completed lanes
|
|
67
|
-
- `failedCount`: Number of failed lanes
|
|
68
|
-
|
|
69
|
-
#### `orchestration.failed`
|
|
70
|
-
- `error`: Error message
|
|
71
|
-
- `blockedLanes`: (Optional) List of lane names that could not start due to dependency issues
|
|
72
|
-
|
|
73
|
-
### 2. Lane
|
|
74
|
-
|
|
75
|
-
#### `lane.started`
|
|
76
|
-
- `laneName`: Name of the lane (filename)
|
|
77
|
-
- `pid`: (Optional) Process ID of the child process running the lane
|
|
78
|
-
- `logPath`: Path to the log file for this lane
|
|
79
|
-
|
|
80
|
-
#### `lane.completed`
|
|
81
|
-
- `laneName`: Name of the lane
|
|
82
|
-
- `exitCode`: Exit code (0 for success)
|
|
83
|
-
|
|
84
|
-
#### `lane.failed`
|
|
85
|
-
- `laneName`: Name of the lane
|
|
86
|
-
- `exitCode`: Exit code
|
|
87
|
-
- `error`: Description of the failure cause
|
|
88
|
-
|
|
89
|
-
#### `lane.dependency_requested`
|
|
90
|
-
- `laneName`: Name of the lane that sent the request
|
|
91
|
-
- `dependencyRequest`: Dependency modification plan (includes `reason`, `changes`, `commands`)
|
|
92
|
-
|
|
93
|
-
### 3. Task
|
|
94
|
-
|
|
95
|
-
#### `task.started`
|
|
96
|
-
- `taskName`: Name of the task
|
|
97
|
-
- `taskBranch`: Name of the Git branch being worked on
|
|
98
|
-
- `index`: Task sequence index within the lane (starting from 0)
|
|
99
|
-
- `timeout`: (Optional) Task-specific timeout in milliseconds
|
|
100
|
-
|
|
101
|
-
#### `task.completed`
|
|
102
|
-
- `taskName`: Name of the task
|
|
103
|
-
- `taskBranch`: Name of the Git branch
|
|
104
|
-
- `status`: Completion status (e.g., 'FINISHED')
|
|
105
|
-
|
|
106
|
-
#### `task.failed`
|
|
107
|
-
- `taskName`: Name of the task
|
|
108
|
-
- `taskBranch`: Branch name
|
|
109
|
-
- `error`: Error message from task execution
|
|
110
|
-
|
|
111
|
-
### 4. Agent
|
|
112
|
-
|
|
113
|
-
#### `agent.prompt_sent`
|
|
114
|
-
- `taskName`: Current task name
|
|
115
|
-
- `model`: AI model used
|
|
116
|
-
- `promptLength`: Length of the sent prompt string
|
|
117
|
-
|
|
118
|
-
#### `agent.response_received`
|
|
119
|
-
- `taskName`: Task name
|
|
120
|
-
- `ok`: Success flag (boolean)
|
|
121
|
-
- `duration`: Time taken for AI response (milliseconds)
|
|
122
|
-
- `responseLength`: Length of the received response string
|
|
123
|
-
- `error`: (On failure) Error message
|
|
124
|
-
|
|
125
|
-
### 5. Review
|
|
126
|
-
|
|
127
|
-
#### `review.started`
|
|
128
|
-
- `taskName`: Name of the task under review
|
|
129
|
-
- `taskBranch`: Name of the branch under review
|
|
130
|
-
|
|
131
|
-
#### `review.completed`
|
|
132
|
-
- `taskName`: Task name
|
|
133
|
-
- `status`: Review result (`'approved'` or `'needs_changes'`)
|
|
134
|
-
- `issueCount`: Number of issues found
|
|
135
|
-
- `summary`: Review summary content
|
|
136
|
-
|
|
137
|
-
#### `review.approved`
|
|
138
|
-
- `taskName`: Task name
|
|
139
|
-
- `iterations`: Number of review iterations until final approval
|
|
140
|
-
|
|
141
|
-
#### `review.rejected`
|
|
142
|
-
- `taskName`: Task name
|
|
143
|
-
- `reason`: Reason for rejection (summary of requested changes)
|
|
144
|
-
- `iterations`: Current number of review iterations
|
|
145
|
-
|
|
146
|
-
## Webhook Configuration
|
|
147
|
-
|
|
148
|
-
Set up the `webhooks` array in your `cursorflow.config.js` file.
|
|
149
|
-
|
|
150
|
-
```javascript
|
|
151
|
-
module.exports = {
|
|
152
|
-
// ... other settings
|
|
153
|
-
webhooks: [
|
|
154
|
-
{
|
|
155
|
-
enabled: true,
|
|
156
|
-
url: 'https://your-api.com/webhooks/cursorflow',
|
|
157
|
-
secret: 'your-hmac-secret', // Secret for HMAC signature
|
|
158
|
-
events: ['lane.completed', 'orchestration.*'], // Event patterns to receive
|
|
159
|
-
headers: {
|
|
160
|
-
'X-Custom-Header': 'CursorFlow-Bot'
|
|
161
|
-
},
|
|
162
|
-
retries: 3, // Number of retries on failure
|
|
163
|
-
timeoutMs: 5000 // Timeout setting
|
|
164
|
-
}
|
|
165
|
-
]
|
|
166
|
-
};
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
### Event Filtering Patterns
|
|
170
|
-
- `*`: Receive all events
|
|
171
|
-
- `lane.*`: Receive all lane-related events
|
|
172
|
-
- `task.failed`: Receive only task failure events
|
|
173
|
-
|
|
174
|
-
## Programmatic Event Listeners (Function Triggers)
|
|
175
|
-
|
|
176
|
-
In addition to webhooks, you can register event listeners directly via Node.js code to execute custom logic. This is useful for running local scripts or complex conditional logic.
|
|
177
|
-
|
|
178
|
-
### 1. Registering in `cursorflow.config.js`
|
|
179
|
-
|
|
180
|
-
Since the `cursorflow run` command loads the configuration file, you can subscribe to events at this point.
|
|
181
|
-
|
|
182
|
-
```javascript
|
|
183
|
-
// cursorflow.config.js
|
|
184
|
-
const { events } = require('@litmers/cursorflow-orchestrator');
|
|
185
|
-
|
|
186
|
-
// Execute custom logic on task completion
|
|
187
|
-
events.on('task.completed', (event) => {
|
|
188
|
-
const { taskName, taskBranch } = event.payload;
|
|
189
|
-
console.log(`[HOOK] Task completed: ${taskName} (Branch: ${taskBranch})`);
|
|
190
|
-
|
|
191
|
-
// Example: Check if a specific file was created or update a local database
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
// Notify on entire orchestration failure
|
|
195
|
-
events.on('orchestration.failed', (event) => {
|
|
196
|
-
console.error(`!!! Orchestration failed: ${event.payload.error}`);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
module.exports = {
|
|
200
|
-
tasksDir: '_cursorflow/tasks',
|
|
201
|
-
// ... other configurations
|
|
202
|
-
};
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
### 2. Usage in Custom Scripts
|
|
206
|
-
|
|
207
|
-
If you are using CursorFlow as a library, you can call the `orchestrate` function directly and monitor events.
|
|
208
|
-
|
|
209
|
-
```javascript
|
|
210
|
-
const { orchestrate, events } = require('@litmers/cursorflow-orchestrator');
|
|
211
|
-
|
|
212
|
-
async function runMyPipeline() {
|
|
213
|
-
// Register event listener
|
|
214
|
-
events.on('lane.started', (event) => {
|
|
215
|
-
console.log(`Lane started: ${event.payload.laneName}`);
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
// Execute orchestration
|
|
219
|
-
try {
|
|
220
|
-
await orchestrate('./my-tasks');
|
|
221
|
-
console.log('All tasks completed');
|
|
222
|
-
} catch (err) {
|
|
223
|
-
console.error('Error during orchestration', err);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
runMyPipeline();
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
## Security & Verification
|
|
231
|
-
|
|
232
|
-
When sending webhooks, you can verify the integrity of the payload using the `X-CursorFlow-Signature` header.
|
|
233
|
-
|
|
234
|
-
- **Algorithm**: HMAC-SHA256
|
|
235
|
-
- **Format**: `sha256=<hex_signature>`
|
|
236
|
-
|
|
237
|
-
The receiver should hash the request body using the configured `secret` and verify it matches the signature in the header.
|
|
238
|
-
|
|
239
|
-
## Use Cases
|
|
240
|
-
|
|
241
|
-
1. **Slack/Discord Notifications**: Notify the team messenger on `orchestration.completed` or `lane.failed`.
|
|
242
|
-
2. **Deployment Automation**: Execute an external script to deploy code to a staging environment once a specific lane completes.
|
|
243
|
-
3. **Statistics Collection**: Record token usage or response times in a database via the `agent.response_received` event.
|
|
244
|
-
4. **Dashboard Updates**: Reflect real-time status on an external monitoring dashboard.
|
|
245
|
-
|
|
246
|
-
## Precautions
|
|
247
|
-
|
|
248
|
-
- Webhook endpoints must support the `POST` method.
|
|
249
|
-
- Payloads are sent in `application/json` format.
|
|
250
|
-
- Consider network latency and set timeout and retry policies appropriately.
|