@buildify-cli/cursor-agent 0.1.1 → 0.2.1

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 CHANGED
@@ -1,27 +1,35 @@
1
- # @buildify/cursor-agent
1
+ # Buildify Cursor Agent
2
2
 
3
- Node.js client runner for the Buildify **Cursor Broker** bundle. It connects to `CursorBrokerTriggerNode`, receives submitted tasks over SSE/HTTP, and executes them locally with [`@cursor/sdk`](https://cursor.com/docs/sdk/typescript).
3
+ `buildify-cursor-agent` connects Buildify Agent Broker to the local Cursor CLI. It pulls `cursor.task` jobs from Broker, runs them through Cursor `agent acp`, then reports task results, token usage, and errors back to Broker.
4
4
 
5
- ## Architecture
5
+ ## Requirements
6
6
 
7
- ```
8
- Buildify Workflow
9
- └── CursorBrokerTriggerNode (Java Netty HTTP server)
10
- └── CursorSubmitTaskNode (submit task)
11
- └── CursorCancelTaskNode (cancel task)
12
- HTTP + SSE
13
- @buildify/cursor-agent (this package)
14
- └── @cursor/sdk Agent.create() + agent.send()
7
+ - Node.js 18 or newer
8
+ - Cursor CLI installed on the agent machine
9
+ - A Cursor API key for the task model
10
+ - Network access from the agent machine to Buildify Agent Broker
11
+
12
+ Check Cursor CLI:
13
+
14
+ ```bash
15
+ agent --version
16
+ agent --help
15
17
  ```
16
18
 
17
- ## Requirements
19
+ If `agent` is not available, install the Cursor CLI:
18
20
 
19
- - Node.js 18+
20
- - macOS (for `install-service`; foreground/daemon mode works on any OS)
21
- - Buildify workflow with `CursorBrokerTriggerNode` running and reachable
21
+ ```bash
22
+ buildify-cursor-agent install-cursor
23
+ ```
22
24
 
23
25
  ## Install
24
26
 
27
+ From npm:
28
+
29
+ ```bash
30
+ npm install -g @buildify-cli/cursor-agent
31
+ ```
32
+
25
33
  From this repository:
26
34
 
27
35
  ```bash
@@ -31,158 +39,270 @@ npm run build
31
39
  npm link
32
40
  ```
33
41
 
34
- Or after publishing:
42
+ Verify:
35
43
 
36
44
  ```bash
37
- npm install -g @buildify/cursor-agent
45
+ buildify-cursor-agent --version
46
+ buildify-cursor-agent --help
38
47
  ```
39
48
 
40
- ## Configuration
49
+ ## Quick Start
41
50
 
42
- Initialize defaults:
51
+ Create the default config file:
43
52
 
44
53
  ```bash
45
54
  buildify-cursor-agent config init
46
55
  ```
47
56
 
48
- Edit `~/.buildify/cursor-agent.json`:
57
+ Set Broker connection values:
49
58
 
50
- ```json
51
- {
52
- "server": "http://localhost:8080",
53
- "clientId": "my-macbook",
54
- "defaultCwd": "/Users/you/projects",
55
- "maxConcurrent": 2,
56
- "token": "",
57
- "logLevel": "info",
58
- "streamLogs": false,
59
- "requestTimeoutMs": 30000,
60
- "reconnectMinDelayMs": 1000,
61
- "reconnectMaxDelayMs": 30000
62
- }
59
+ ```bash
60
+ buildify-cursor-agent config set \
61
+ server=http://localhost:8080 \
62
+ token=<broker-token> \
63
+ clientId=<agent-client-id>
63
64
  ```
64
65
 
65
- Or set values via CLI:
66
+ Optionally set a default Cursor API key for model discovery:
66
67
 
67
68
  ```bash
68
- buildify-cursor-agent config set \
69
- server=http://192.168.1.10:9001 \
70
- clientId=my-macbook \
71
- defaultCwd=/Users/you/projects \
72
- token=broker_server_key
69
+ buildify-cursor-agent config set cursorApiKey=<cursor-api-key>
73
70
  ```
74
71
 
75
- | Key | Description |
76
- |-----|-------------|
77
- | `server` | Base URL of the Java Cursor Broker (from `CursorBrokerTriggerNode` status) |
78
- | `clientId` | Unique agent identifier; must match `CursorSubmitTaskNode.clientId` |
79
- | `defaultCwd` | Default working directory when a task has no `cwd` |
80
- | `maxConcurrent` | Max parallel Cursor SDK runs (reported at connect) |
81
- | `token` | Bearer token when Buildify auth is enabled (`Authorization: Bearer <serverKey>`) |
82
- | `logLevel` | `error`, `warn`, `info`, or `debug` |
83
- | `streamLogs` | Print Cursor SDK stream messages to stdout for debugging |
84
- | `requestTimeoutMs` | HTTP timeout for broker calls |
85
- | `reconnectMinDelayMs` | Minimum reconnect backoff |
86
- | `reconnectMaxDelayMs` | Maximum reconnect backoff |
87
-
88
- Show current config (secrets masked):
72
+ Start in the foreground:
89
73
 
90
74
  ```bash
91
- buildify-cursor-agent config show
75
+ buildify-cursor-agent start --logs
92
76
  ```
93
77
 
94
- ## Usage
78
+ Start as a background daemon:
79
+
80
+ ```bash
81
+ buildify-cursor-agent start --daemon
82
+ buildify-cursor-agent status
83
+ buildify-cursor-agent stop
84
+ ```
95
85
 
96
- ### Foreground
86
+ Install as a macOS launchd service:
97
87
 
98
88
  ```bash
99
- buildify-cursor-agent start
89
+ buildify-cursor-agent install-service
90
+ buildify-cursor-agent status
91
+ buildify-cursor-agent uninstall-service
100
92
  ```
101
93
 
102
- Press `Ctrl+C` to disconnect cleanly (`DELETE /disconnect`).
94
+ ## Configuration
95
+
96
+ Config file:
103
97
 
104
- ### Debug logs
98
+ ```text
99
+ ~/.buildify/cursor-agent.json
100
+ ```
101
+
102
+ Show current config:
105
103
 
106
104
  ```bash
107
- buildify-cursor-agent start --log-level debug --stream-logs
105
+ buildify-cursor-agent config show
108
106
  ```
109
107
 
110
- `--stream-logs` prints Cursor SDK stream events such as status, assistant text, thinking, and tool calls. The runner also reports task progress events back to `CursorBrokerTriggerNode`.
108
+ Set config values:
111
109
 
112
- When a task provides `cwd`, the runner resolves it on the agent machine and creates the directory recursively if it does not already exist. If the path exists but is not a directory, the task fails.
110
+ ```bash
111
+ buildify-cursor-agent config set key=value [key=value ...]
112
+ ```
113
113
 
114
- ### Background daemon
114
+ Common keys:
115
+
116
+ | Key | Default | Description |
117
+ | --- | --- | --- |
118
+ | `server` | `http://localhost:8080` | Buildify Agent Broker URL |
119
+ | `clientId` | host name | Agent client ID registered with Broker |
120
+ | `token` | empty | Broker auth token |
121
+ | `defaultCwd` | `~/projects` | Default working directory on the agent machine |
122
+ | `maxConcurrent` | `2` | Max parallel Cursor tasks |
123
+ | `cursorApiKey` | empty | Cursor API key used for model discovery |
124
+ | `cursorBin` | `agent` | Cursor CLI executable path |
125
+ | `defaultModel` | `composer-2.5` | Fallback model when discovery fails |
126
+ | `usageProbe` | `true` | Probe Cursor print mode for usage if ACP omits it |
127
+ | `logs` | `false` | Print local agent logs |
128
+
129
+ Configuration priority:
130
+
131
+ 1. CLI flags
132
+ 2. Environment variables
133
+ 3. `~/.buildify/cursor-agent.json`
134
+ 4. Built-in defaults
135
+
136
+ ## Environment Variables
137
+
138
+ | Variable | Description |
139
+ | --- | --- |
140
+ | `BUILDIFY_SERVER` | Broker server URL |
141
+ | `BUILDIFY_TOKEN` | Broker auth token |
142
+ | `BUILDIFY_CLIENT_ID` | Agent client ID |
143
+ | `BUILDIFY_LOGS` | Enable local logs |
144
+ | `CURSOR_API_KEY` | Cursor API key |
145
+ | `BUILDIFY_CURSOR_API_KEY` | Cursor API key alias |
146
+ | `BUILDIFY_CURSOR_BIN` | Cursor `agent` executable path |
147
+ | `BUILDIFY_CURSOR_USAGE_PROBE` | Enable or disable usage probing |
148
+
149
+ Example:
115
150
 
116
151
  ```bash
117
- buildify-cursor-agent start --daemon
118
- buildify-cursor-agent status
152
+ BUILDIFY_SERVER=http://localhost:8080 \
153
+ BUILDIFY_TOKEN=<broker-token> \
154
+ BUILDIFY_CLIENT_ID=cursor-local \
155
+ CURSOR_API_KEY=<cursor-api-key> \
156
+ buildify-cursor-agent start --logs
157
+ ```
158
+
159
+ ## CLI Commands
160
+
161
+ ```bash
162
+ buildify-cursor-agent start [options]
119
163
  buildify-cursor-agent stop
164
+ buildify-cursor-agent status
165
+ buildify-cursor-agent install-service
166
+ buildify-cursor-agent uninstall-service
167
+ buildify-cursor-agent install-cursor
168
+ buildify-cursor-agent config init
169
+ buildify-cursor-agent config show
170
+ buildify-cursor-agent config set key=value [key=value ...]
120
171
  ```
121
172
 
122
- PID file: `~/.buildify/cursor-agent.pid`
173
+ `start` options:
174
+
175
+ | Option | Description |
176
+ | --- | --- |
177
+ | `--daemon` | Run in background |
178
+ | `--foreground` | Run in foreground |
179
+ | `--server <url>` | Override Broker URL |
180
+ | `--token <token>` | Override Broker token |
181
+ | `--client-id <id>` | Override client ID |
182
+ | `--logs` | Enable local logs |
183
+ | `--request-timeout-ms <ms>` | HTTP request timeout |
184
+
185
+ ## Use In Buildify
186
+
187
+ Use `AgentCursorSubmitTaskNode` to submit Cursor tasks.
188
+
189
+ Required fields:
190
+
191
+ - Broker instance
192
+ - Client ID matching the running `buildify-cursor-agent`
193
+ - Cursor model
194
+ - Cursor API key
195
+ - Prompt
196
+ - Working directory (`cwd`)
197
+
198
+ Important: `cwd` is a path on the machine where this agent runs. It is not the Buildify server path. If the directory may not exist, enable “create working directory if missing”.
199
+
200
+ ## Cursor Task Fields
201
+
202
+ The runner supports these task values from Buildify:
123
203
 
124
- ### macOS launchd service (like Docker Desktop auto-start)
204
+ - `prompt`: user instruction sent to Cursor
205
+ - `cwd`: local working directory on the agent machine
206
+ - `model`: Cursor model, for example `composer-2.5`
207
+ - `cursorApiKey`: Cursor API key used by the task
208
+ - `conversationId`: optional ACP session ID to resume
209
+ - `mcpServers`: optional MCP server definitions passed to Cursor ACP
210
+ - `createCwdIfMissing`: whether the agent may create `cwd`
125
211
 
126
- Install a user LaunchAgent that starts on login and restarts on failure:
212
+ Each task starts a fresh Cursor ACP subprocess:
213
+
214
+ ```bash
215
+ agent --api-key <cursor-api-key> --model <model> acp
216
+ ```
217
+
218
+ ## Usage Reporting
219
+
220
+ Cursor ACP may not always report token usage directly. When `usageProbe=true`, this agent performs a best-effort usage probe after the task finishes.
221
+
222
+ Reported usage can include:
223
+
224
+ - input tokens
225
+ - output tokens
226
+ - reasoning tokens
227
+ - cache read/write tokens
228
+ - source metadata such as `acp`, `print-probe`, or `estimated`
229
+
230
+ If usage cannot be read from Cursor, the runner falls back to an estimate so Broker still receives a useful usage payload.
231
+
232
+ ## Debugging
233
+
234
+ Enable normal logs:
235
+
236
+ ```bash
237
+ buildify-cursor-agent start --logs
238
+ ```
239
+
240
+ Check daemon/service status:
127
241
 
128
242
  ```bash
129
- buildify-cursor-agent install-service
130
243
  buildify-cursor-agent status
131
244
  ```
132
245
 
133
- Logs:
246
+ Install or verify the Cursor CLI:
134
247
 
135
- - `~/.buildify/cursor-agent.log`
136
- - `~/.buildify/cursor-agent.log.err`
248
+ ```bash
249
+ buildify-cursor-agent install-cursor
250
+ ```
137
251
 
138
- Uninstall:
252
+ For local ACP investigation, use the debug script:
139
253
 
140
254
  ```bash
141
- buildify-cursor-agent uninstall-service
255
+ node debug-acp.mjs \
256
+ --model composer-2.5 \
257
+ --api-key <cursor-api-key> \
258
+ --prompt "say hello"
142
259
  ```
143
260
 
144
- ## Protocol
261
+ ## Common Errors
262
+
263
+ ### `Task is missing cursorApiKey`
264
+
265
+ The task did not include a Cursor API key. Set the key in Buildify `ModelSelect` or pass `cursorApiKey` in the task payload.
145
266
 
146
- Implements the client side of the Cursor Broker HTTP API:
267
+ ### `Cursor API key is invalid`
147
268
 
148
- | Method | Path | Purpose |
149
- |--------|------|---------|
150
- | `POST` | `/connect` | Register client, get `sessionId` |
151
- | `GET` | `/events` | SSE stream (`newTask` and `cancelled` events) |
152
- | `GET` | `/tasks/next` | Pull next queued task |
153
- | `POST` | `/tasks/{taskId}/events` | Report received / progress / completed / failed / cancelled |
154
- | `POST` | `/heartbeat` | Keep-alive with `runningCount` |
155
- | `DELETE` | `/disconnect` | Clean shutdown |
269
+ Check whether the API key is valid and not redacted. The task must pass the real key value, not a masked placeholder.
156
270
 
157
- Headers:
271
+ ### `Cursor usage limit reached`
158
272
 
159
- - `Agent-Client-Id` agent identifier
160
- - `Agent-Session-Id` — session from `/connect`
273
+ The selected Cursor account or model has reached its usage limit. Try another model or wait for quota reset.
161
274
 
162
- Model discovery:
275
+ ### `Working directory does not exist`
163
276
 
164
- - The runner sends its cached model list in `/connect` and `/heartbeat`.
165
- - The model cache is refreshed from Cursor with the task-scoped `cursorApiKey` when a task starts.
166
- - `CursorSubmitTaskNode.model` loads options from the selected `clientId`; if the agent has not reported models yet, it falls back to `composer-2.5`.
277
+ The `cwd` path does not exist on the agent machine and `createCwdIfMissing` is disabled. Use a local path on the agent machine or enable directory creation.
167
278
 
168
- ## Buildify workflow setup
279
+ ### `Cursor CLI not found`
169
280
 
170
- 1. Add **Cursor Broker Trigger** node; note the listening port in node status.
171
- 2. Enable auth if needed and configure **Cursor Broker Credential** (`serverKey`).
172
- 3. Set `token` in client config to the same `serverKey`.
173
- 4. Add **Submit Cursor Task** node with matching `clientId` and task-scoped `cursorApiKey`.
174
- 5. Optionally add **Cancel Cursor Task** node and pass `taskId` to cancel queued or running tasks.
175
- 6. Start this runner on the target machine.
281
+ The `agent` binary is missing or not on `PATH`. Run:
282
+
283
+ ```bash
284
+ buildify-cursor-agent install-cursor
285
+ ```
286
+
287
+ Or configure:
288
+
289
+ ```bash
290
+ buildify-cursor-agent config set cursorBin=/path/to/agent
291
+ ```
176
292
 
177
293
  ## Development
178
294
 
179
295
  ```bash
180
296
  npm install
181
- npm run dev -- config show
182
- npm run dev -- start
297
+ npm run typecheck
183
298
  npm run build
299
+ npm run build:dev
184
300
  ```
185
301
 
186
- ## License
302
+ Before publishing:
187
303
 
188
- MIT
304
+ ```bash
305
+ npm run typecheck
306
+ npm run build
307
+ npm pack --dry-run
308
+ ```