@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.
Files changed (102) hide show
  1. package/README.md +13 -13
  2. package/commands/cursorflow-init.md +113 -32
  3. package/commands/cursorflow-prepare.md +146 -339
  4. package/commands/cursorflow-run.md +148 -131
  5. package/dist/cli/add.js +8 -4
  6. package/dist/cli/add.js.map +1 -1
  7. package/dist/cli/index.js +2 -0
  8. package/dist/cli/index.js.map +1 -1
  9. package/dist/cli/new.js +3 -5
  10. package/dist/cli/new.js.map +1 -1
  11. package/dist/cli/prepare.js +0 -1
  12. package/dist/cli/prepare.js.map +1 -1
  13. package/dist/cli/resume.js +24 -15
  14. package/dist/cli/resume.js.map +1 -1
  15. package/dist/cli/run.js +1 -6
  16. package/dist/cli/run.js.map +1 -1
  17. package/dist/cli/setup-commands.d.ts +1 -0
  18. package/dist/cli/setup-commands.js +1 -0
  19. package/dist/cli/setup-commands.js.map +1 -1
  20. package/dist/core/orchestrator.js +13 -5
  21. package/dist/core/orchestrator.js.map +1 -1
  22. package/dist/core/runner/agent.d.ts +5 -1
  23. package/dist/core/runner/agent.js +31 -1
  24. package/dist/core/runner/agent.js.map +1 -1
  25. package/dist/core/runner/pipeline.d.ts +0 -1
  26. package/dist/core/runner/pipeline.js +136 -173
  27. package/dist/core/runner/pipeline.js.map +1 -1
  28. package/dist/core/runner/prompt.d.ts +0 -1
  29. package/dist/core/runner/prompt.js +11 -16
  30. package/dist/core/runner/prompt.js.map +1 -1
  31. package/dist/core/runner/task.d.ts +1 -2
  32. package/dist/core/runner/task.js +31 -40
  33. package/dist/core/runner/task.js.map +1 -1
  34. package/dist/core/runner.js +15 -2
  35. package/dist/core/runner.js.map +1 -1
  36. package/dist/core/stall-detection.d.ts +32 -4
  37. package/dist/core/stall-detection.js +151 -149
  38. package/dist/core/stall-detection.js.map +1 -1
  39. package/dist/services/logging/console.d.ts +7 -1
  40. package/dist/services/logging/console.js +13 -3
  41. package/dist/services/logging/console.js.map +1 -1
  42. package/dist/services/logging/formatter.d.ts +1 -0
  43. package/dist/services/logging/formatter.js +6 -3
  44. package/dist/services/logging/formatter.js.map +1 -1
  45. package/dist/types/config.d.ts +3 -1
  46. package/dist/types/logging.d.ts +1 -1
  47. package/dist/types/task.d.ts +3 -8
  48. package/dist/utils/config.js +5 -0
  49. package/dist/utils/config.js.map +1 -1
  50. package/dist/utils/doctor.js +4 -4
  51. package/dist/utils/doctor.js.map +1 -1
  52. package/dist/utils/enhanced-logger.d.ts +1 -1
  53. package/dist/utils/enhanced-logger.js +3 -3
  54. package/dist/utils/enhanced-logger.js.map +1 -1
  55. package/dist/utils/git.d.ts +12 -1
  56. package/dist/utils/git.js +56 -1
  57. package/dist/utils/git.js.map +1 -1
  58. package/dist/utils/health.js +13 -13
  59. package/dist/utils/health.js.map +1 -1
  60. package/dist/utils/log-formatter.d.ts +1 -1
  61. package/dist/utils/log-formatter.js +45 -8
  62. package/dist/utils/log-formatter.js.map +1 -1
  63. package/dist/utils/logger.js +2 -2
  64. package/dist/utils/logger.js.map +1 -1
  65. package/package.json +1 -1
  66. package/src/cli/add.ts +9 -4
  67. package/src/cli/index.ts +3 -0
  68. package/src/cli/new.ts +3 -5
  69. package/src/cli/prepare.ts +0 -1
  70. package/src/cli/resume.ts +28 -19
  71. package/src/cli/run.ts +1 -6
  72. package/src/cli/setup-commands.ts +1 -1
  73. package/src/core/orchestrator.ts +14 -5
  74. package/src/core/runner/agent.ts +36 -4
  75. package/src/core/runner/pipeline.ts +149 -182
  76. package/src/core/runner/prompt.ts +11 -18
  77. package/src/core/runner/task.ts +32 -41
  78. package/src/core/runner.ts +17 -2
  79. package/src/core/stall-detection.ts +263 -147
  80. package/src/services/logging/console.ts +13 -3
  81. package/src/services/logging/formatter.ts +6 -3
  82. package/src/types/config.ts +3 -1
  83. package/src/types/logging.ts +4 -2
  84. package/src/types/task.ts +3 -8
  85. package/src/utils/config.ts +6 -0
  86. package/src/utils/doctor.ts +5 -5
  87. package/src/utils/enhanced-logger.ts +3 -3
  88. package/src/utils/flow.ts +1 -0
  89. package/src/utils/git.ts +61 -1
  90. package/src/utils/health.ts +15 -15
  91. package/src/utils/log-formatter.ts +51 -8
  92. package/src/utils/logger.ts +2 -2
  93. package/commands/cursorflow-add.md +0 -159
  94. package/commands/cursorflow-clean.md +0 -84
  95. package/commands/cursorflow-doctor.md +0 -102
  96. package/commands/cursorflow-models.md +0 -51
  97. package/commands/cursorflow-monitor.md +0 -90
  98. package/commands/cursorflow-new.md +0 -87
  99. package/commands/cursorflow-resume.md +0 -205
  100. package/commands/cursorflow-signal.md +0 -52
  101. package/commands/cursorflow-stop.md +0 -55
  102. 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.