codexapi 0.7.3__tar.gz → 0.10.0__tar.gz

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 (32) hide show
  1. {codexapi-0.7.3/src/codexapi.egg-info → codexapi-0.10.0}/PKG-INFO +134 -33
  2. {codexapi-0.7.3 → codexapi-0.10.0}/README.md +133 -32
  3. {codexapi-0.7.3 → codexapi-0.10.0}/pyproject.toml +1 -1
  4. {codexapi-0.7.3 → codexapi-0.10.0}/src/codexapi/__init__.py +2 -2
  5. codexapi-0.10.0/src/codexapi/agent.py +389 -0
  6. codexapi-0.10.0/src/codexapi/agents.py +1409 -0
  7. {codexapi-0.7.3 → codexapi-0.10.0}/src/codexapi/cli.py +600 -27
  8. {codexapi-0.7.3 → codexapi-0.10.0}/src/codexapi/foreach.py +4 -0
  9. {codexapi-0.7.3 → codexapi-0.10.0}/src/codexapi/gh_integration.py +4 -1
  10. {codexapi-0.7.3 → codexapi-0.10.0}/src/codexapi/lead.py +16 -7
  11. {codexapi-0.7.3 → codexapi-0.10.0}/src/codexapi/ralph.py +5 -1
  12. {codexapi-0.7.3 → codexapi-0.10.0}/src/codexapi/science.py +5 -2
  13. {codexapi-0.7.3 → codexapi-0.10.0}/src/codexapi/task.py +44 -10
  14. {codexapi-0.7.3 → codexapi-0.10.0}/src/codexapi/taskfile.py +3 -0
  15. {codexapi-0.7.3 → codexapi-0.10.0/src/codexapi.egg-info}/PKG-INFO +134 -33
  16. {codexapi-0.7.3 → codexapi-0.10.0}/src/codexapi.egg-info/SOURCES.txt +3 -0
  17. codexapi-0.10.0/tests/test_agent_backend.py +83 -0
  18. codexapi-0.10.0/tests/test_agents.py +890 -0
  19. {codexapi-0.7.3 → codexapi-0.10.0}/tests/test_science.py +1 -0
  20. {codexapi-0.7.3 → codexapi-0.10.0}/tests/test_task_progress.py +10 -5
  21. codexapi-0.7.3/src/codexapi/agent.py +0 -173
  22. {codexapi-0.7.3 → codexapi-0.10.0}/LICENSE +0 -0
  23. {codexapi-0.7.3 → codexapi-0.10.0}/setup.cfg +0 -0
  24. {codexapi-0.7.3 → codexapi-0.10.0}/src/codexapi/__main__.py +0 -0
  25. {codexapi-0.7.3 → codexapi-0.10.0}/src/codexapi/pushover.py +0 -0
  26. {codexapi-0.7.3 → codexapi-0.10.0}/src/codexapi/rate_limits.py +0 -0
  27. {codexapi-0.7.3 → codexapi-0.10.0}/src/codexapi/welfare.py +0 -0
  28. {codexapi-0.7.3 → codexapi-0.10.0}/src/codexapi.egg-info/dependency_links.txt +0 -0
  29. {codexapi-0.7.3 → codexapi-0.10.0}/src/codexapi.egg-info/entry_points.txt +0 -0
  30. {codexapi-0.7.3 → codexapi-0.10.0}/src/codexapi.egg-info/requires.txt +0 -0
  31. {codexapi-0.7.3 → codexapi-0.10.0}/src/codexapi.egg-info/top_level.txt +0 -0
  32. {codexapi-0.7.3 → codexapi-0.10.0}/tests/test_rate_limits.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: codexapi
3
- Version: 0.7.3
3
+ Version: 0.10.0
4
4
  Summary: Minimal Python API for running the Codex CLI.
5
5
  License: MIT
6
6
  Keywords: codex,agent,cli,openai
@@ -15,13 +15,14 @@ Requires-Dist: tqdm>=4.64
15
15
 
16
16
  # CodexAPI
17
17
 
18
- Use OpenAI's codex from python as easily as calling a function with your codex credits instead of the API.
18
+ Use Codex or Cursor agents from python as easily as calling a function, using your CLI auth instead of the API.
19
19
 
20
20
  *Note: this project is not affiliated with OpenAI in any way. Thanks for the awesome tools and models though!*
21
21
 
22
22
  ## Requirements
23
23
 
24
- - Codex CLI installed and authenticated (`codex` must be on your PATH).
24
+ - Codex CLI installed and authenticated (`codex` must be on your PATH), or
25
+ - Cursor Agent CLI installed and authenticated (`cursor` must be on your PATH).
25
26
  - Python 3.8+.
26
27
 
27
28
  ## Install
@@ -59,14 +60,19 @@ result = task()
59
60
  print(result.success, result.summary)
60
61
  ```
61
62
 
63
+ Use `backend="cursor"` (or set `CODEXAPI_BACKEND=cursor`) to switch to the
64
+ Cursor agent backend.
65
+
62
66
  ## CLI
63
67
 
64
68
  After installing, use the `codexapi` command:
65
69
 
66
70
  ```bash
71
+ codexapi --version
67
72
  codexapi run "Summarize this repo."
68
73
  codexapi run --cwd /path/to/project "Fix the failing tests."
69
74
  echo "Say hello." | codexapi run
75
+ codexapi run --backend cursor "Summarize this repo."
70
76
  ```
71
77
 
72
78
  `codexapi task` exits with code 0 on success and 1 on failure.
@@ -122,15 +128,16 @@ Show running sessions and their latest activity:
122
128
  codexapi top
123
129
  ```
124
130
  Press `h` for keys.
131
+ `codexapi top` and `codexapi limit` are Codex-only.
125
132
 
126
- Resume a session and print the thread id to stderr:
133
+ Resume a session and print the thread/session id to stderr:
127
134
 
128
135
  ```bash
129
136
  codexapi run --thread-id THREAD_ID --print-thread-id "Continue where we left off."
130
137
  ```
131
138
 
132
- Use `--no-yolo` to run Codex with `--full-auto` instead.
133
- Use `--include-thinking` to return all agent messages joined together for `codexapi run`.
139
+ Use `--no-yolo` to disable `--yolo` (Codex uses `--full-auto`).
140
+ Use `--include-thinking` to return all agent messages joined together for `codexapi run` (Codex only).
134
141
 
135
142
  Lead mode periodically checks in on a long-running agent session with the
136
143
  current time and prints JSON status updates. The agent controls the loop by
@@ -150,14 +157,89 @@ If the leadbook does not exist, lead creates it with a template.
150
157
 
151
158
  ```bash
152
159
  codexapi lead 5 "Run the benchmark and wait for results."
160
+ codexapi lead 0 "Do a rapid triage pass and report."
161
+ ```
162
+
163
+ ### Durable agents
164
+
165
+ `codexapi agent` is the durable long-running control plane. It stores state
166
+ under `CODEXAPI_HOME` (default `~/.codexapi`), wakes agents on cron, and lets
167
+ you inspect or message them from any shell that points at the same home.
153
168
 
154
- Run without waiting between check-ins:
169
+ Start by checking the effective host/home pair and installing the scheduler:
155
170
 
156
171
  ```bash
157
- codexapi lead 0 "Do a rapid triage pass and report."
172
+ codexapi agent whoami
173
+ codexapi agent install-cron
174
+ ```
175
+
176
+ If you skip `install-cron`, `codexapi agent start` warns on stderr because
177
+ background wakes will not run until the scheduler hook is installed.
178
+ When `gh` is installed and authenticated, `agent start` also captures a
179
+ background-safe `GH_TOKEN` automatically if your shell did not already export
180
+ `GH_TOKEN` or `GITHUB_TOKEN`.
181
+
182
+ Start a goal-directed agent that decides for itself when it is done:
183
+
184
+ ```bash
185
+ codexapi agent start --name ci-fixer \
186
+ "Watch CI, fix failing tests, open or update a PR, and stop when the work is done."
187
+ ```
188
+
189
+ Add `--wait` if you want `start` to block for the first local wake instead of
190
+ just scheduling it.
191
+
192
+ Start a persistent watcher that keeps running until you stop it:
193
+
194
+ ```bash
195
+ codexapi agent start --name issue-watcher \
196
+ --stop-policy until_stopped \
197
+ --heartbeat-minutes 30 \
198
+ "Every wake, scan for newly assigned issues that look actionable and report or start follow-up work."
199
+ ```
200
+
201
+ Inspect and talk to agents:
202
+
203
+ ```bash
204
+ codexapi agent list
205
+ codexapi agent show ci-fixer
206
+ codexapi agent read ci-fixer
207
+ codexapi agent book ci-fixer
208
+ codexapi agent send ci-fixer "Prefer the smallest safe fix."
209
+ codexapi agent send --wait ci-fixer "Reply now if you can handle this immediately."
210
+ codexapi agent wake ci-fixer
211
+ codexapi agent wake --wait ci-fixer
212
+ codexapi agent pause ci-fixer
213
+ codexapi agent resume ci-fixer
214
+ codexapi agent resume --wait ci-fixer
215
+ codexapi agent cancel ci-fixer
216
+ codexapi agent delete ci-fixer
217
+ ```
218
+
219
+ Create a child agent explicitly:
220
+
221
+ ```bash
222
+ codexapi agent start --name child-fix --parent ci-fixer \
223
+ "Investigate the flaky integration test and report back."
158
224
  ```
225
+
226
+ Useful environment overrides:
227
+
228
+ ```bash
229
+ CODEXAPI_HOME=/tmp/codexapi-test-home codexapi agent list
230
+ CODEXAPI_HOSTNAME=stable-host codexapi agent whoami
159
231
  ```
160
232
 
233
+ `CODEXAPI_HOME` isolates independent agent installations and is the right seam
234
+ for tests. `CODEXAPI_HOSTNAME` is useful when cron, shells, sandboxes, or test
235
+ wrappers report inconsistent hostnames for the same machine.
236
+
237
+ `codexapi agent show` also prints the resolved `AGENTBOOK.md` path so you can
238
+ jump directly to the durable working memory file.
239
+
240
+ See [docs/agent-v1.md](docs/agent-v1.md) for the filesystem model and scheduling
241
+ details.
242
+
161
243
  Ralph loop mode repeats the same prompt until a completion promise or a max
162
244
  iteration cap is hit (0 means unlimited). Cancel by deleting
163
245
  `.codexapi/ralph-loop.local.md` or running `codexapi ralph --cancel`.
@@ -206,31 +288,34 @@ codexapi foreach list.txt task.yaml --retry-all
206
288
 
207
289
  ## API
208
290
 
209
- ### `agent(prompt, cwd=None, yolo=True, flags=None, include_thinking=False) -> str`
291
+ ### `agent(prompt, cwd=None, yolo=True, flags=None, include_thinking=False, backend=None) -> str`
210
292
 
211
- Runs a single Codex turn and returns only the agent's message. Any reasoning
293
+ Runs a single agent turn and returns only the agent's message. Any reasoning
212
294
  items are filtered out.
213
295
 
214
- - `prompt` (str): prompt to send to Codex.
215
- - `cwd` (str | PathLike | None): working directory for the Codex session.
216
- - `yolo` (bool): pass `--yolo` to Codex when true (defaults to true).
217
- - `flags` (str | None): extra CLI flags to pass to Codex.
296
+ - `prompt` (str): prompt to send to the agent backend.
297
+ - `cwd` (str | PathLike | None): working directory for the agent session.
298
+ - `yolo` (bool): pass `--yolo` when true (defaults to true).
299
+ - `flags` (str | None): extra CLI flags to pass to the agent backend.
218
300
  - `include_thinking` (bool): when true, return all agent messages joined.
301
+ - `backend` (str | None): `codex` or `cursor` (defaults to `CODEXAPI_BACKEND` or `codex`).
219
302
 
220
- ### `Agent(cwd=None, yolo=True, thread_id=None, flags=None, welfare=False, include_thinking=False)`
303
+ ### `Agent(cwd=None, yolo=True, thread_id=None, flags=None, welfare=False, include_thinking=False, backend=None)`
221
304
 
222
305
  Creates a stateful session wrapper. Calling the instance sends the prompt into
223
306
  the same conversation and returns only the agent's message.
224
307
 
225
- - `__call__(prompt) -> str`: send a prompt to Codex and return the message.
308
+ - `__call__(prompt) -> str`: send a prompt to the agent backend and return the message.
226
309
  - `thread_id -> str | None`: expose the underlying session id once created.
227
- - `yolo` (bool): pass `--yolo` to Codex when true (defaults to true).
228
- - `flags` (str | None): extra CLI flags to pass to Codex.
310
+ - `yolo` (bool): pass `--yolo` when true (defaults to true).
311
+ - `flags` (str | None): extra CLI flags to pass to the agent backend.
229
312
  - `welfare` (bool): when true, append welfare stop instructions to each prompt
230
313
  and raise `WelfareStop` if the agent outputs `MAKE IT STOP`.
231
314
  - `include_thinking` (bool): when true, return all agent messages joined.
315
+ - `backend` (str | None): `codex` or `cursor` (defaults to `CODEXAPI_BACKEND` or `codex`).
316
+ For Cursor, `thread_id` corresponds to the `session_id` returned by the agent.
232
317
 
233
- ### `lead(minutes, prompt, cwd=None, yolo=True, flags=None, leadbook=None) -> dict`
318
+ ### `lead(minutes, prompt, cwd=None, yolo=True, flags=None, leadbook=None, backend=None) -> dict`
234
319
 
235
320
  Runs a long-lived agent session and periodically checks in with the current
236
321
  local time and a reminder of `prompt`. Each check-in expects JSON with keys:
@@ -241,8 +326,9 @@ JSON is invalid, lead asks the agent once to retry. The loop stops when
241
326
  Lead also injects the leadbook content into each prompt. By default it uses
242
327
  `LEADBOOK.md` in the working directory. Pass `leadbook=False` to disable or a
243
328
  path string to override the location.
329
+ Set `backend="cursor"` (or `CODEXAPI_BACKEND=cursor`) to use Cursor.
244
330
 
245
- ### `task(prompt, check=None, max_iterations=10, cwd=None, yolo=True, flags=None, progress=False, set_up=None, tear_down=None, on_success=None, on_failure=None) -> str`
331
+ ### `task(prompt, check=None, max_iterations=10, cwd=None, yolo=True, flags=None, progress=False, set_up=None, tear_down=None, on_success=None, on_failure=None, backend=None) -> str`
246
332
 
247
333
  Runs a task with checker-driven retries and returns the success summary.
248
334
  Raises `TaskFailed` when the maximum iterations are reached.
@@ -251,16 +337,17 @@ Raises `TaskFailed` when the maximum iterations are reached.
251
337
  - `max_iterations` (int): maximum number of task iterations (0 means unlimited).
252
338
  - `progress` (bool): show a tqdm progress bar with a one-line status after each round.
253
339
  - `set_up`/`tear_down`/`on_success`/`on_failure` (str | None): optional hook prompts.
340
+ - `backend` (str | None): `codex` or `cursor` (defaults to `CODEXAPI_BACKEND` or `codex`).
254
341
 
255
- ### `task_result(prompt, check=None, max_iterations=10, cwd=None, yolo=True, flags=None, progress=False, set_up=None, tear_down=None, on_success=None, on_failure=None) -> TaskResult`
342
+ ### `task_result(prompt, check=None, max_iterations=10, cwd=None, yolo=True, flags=None, progress=False, set_up=None, tear_down=None, on_success=None, on_failure=None, backend=None) -> TaskResult`
256
343
 
257
344
  Runs a task with checker-driven retries and returns a `TaskResult` without
258
345
  raising `TaskFailed`.
259
346
  Arguments mirror `task()` (including hooks).
260
347
 
261
- ### `Task(prompt, max_iterations=10, cwd=None, yolo=True, thread_id=None, flags=None)`
348
+ ### `Task(prompt, max_iterations=10, cwd=None, yolo=True, thread_id=None, flags=None, backend=None)`
262
349
 
263
- Runs a Codex task with checker-driven retries. Subclass it and implement
350
+ Runs an agent task with checker-driven retries. Subclass it and implement
264
351
  `check()` to return an error string when the task is incomplete, or return
265
352
  `None`/`""` when the task passes.
266
353
  If you do not override `check()`, the default verifier wrapper runs with the
@@ -281,7 +368,7 @@ Simple result object returned by `Task.__call__`.
281
368
  - `summary` (str): agent summary of what happened.
282
369
  - `iterations` (int): how many iterations were used.
283
370
  - `errors` (str | None): last checker error, if any.
284
- - `thread_id` (str | None): Codex thread id for the session.
371
+ - `thread_id` (str | None): thread/session id for the session.
285
372
 
286
373
  ### `TaskFailed`
287
374
 
@@ -291,16 +378,17 @@ Exception raised by `task()` when iterations are exhausted.
291
378
  - `iterations` (int | None): iterations made when the task failed.
292
379
  - `errors` (str | None): last checker error, if any.
293
380
 
294
- ### `foreach(list_file, task_file, n=None, cwd=None, yolo=True, flags=None) -> ForeachResult`
381
+ ### `foreach(list_file, task_file, n=None, cwd=None, yolo=True, flags=None, backend=None) -> ForeachResult`
295
382
 
296
383
  Runs a task file over a list of items, updating the list file in place.
297
384
 
298
385
  - `list_file` (str | PathLike): path to the list file to process.
299
386
  - `task_file` (str | PathLike): YAML task file (must include `prompt`).
300
387
  - `n` (int | None): limit parallelism to N (default: run all items in parallel).
301
- - `cwd` (str | PathLike | None): working directory for the Codex session.
302
- - `yolo` (bool): pass `--yolo` to Codex when true (defaults to true).
303
- - `flags` (str | None): extra CLI flags to pass to Codex.
388
+ - `cwd` (str | PathLike | None): working directory for the agent session.
389
+ - `yolo` (bool): pass `--yolo` when true (defaults to true).
390
+ - `flags` (str | None): extra CLI flags to pass to the agent backend.
391
+ - `backend` (str | None): `codex` or `cursor` (defaults to `CODEXAPI_BACKEND` or `codex`).
304
392
 
305
393
  ### `ForeachResult(succeeded, failed, skipped, results)`
306
394
 
@@ -313,16 +401,29 @@ Simple result object returned by `foreach()`.
313
401
 
314
402
  ## Behavior notes
315
403
 
316
- - Uses `codex exec --json` and parses JSONL events for `agent_message` items.
317
- - Returns the last `agent_message` by default; set `include_thinking=True` to join all messages.
318
- - Automatically passes `--skip-git-repo-check` so it can run outside a git repo.
319
- - Passes `--yolo` by default (use `--no-yolo` or `yolo=False` for `--full-auto`).
320
- - Raises `RuntimeError` if Codex exits non-zero or returns no agent message.
404
+ - Codex backend uses `codex exec --json` and parses JSONL `agent_message` items.
405
+ - Codex backend passes `--skip-git-repo-check` so it can run outside a git repo.
406
+ - Cursor backend uses `cursor agent --print --output-format json --trust` and parses the JSON result.
407
+ - `include_thinking=True` only affects Codex; Cursor returns a single result string.
408
+ - Passes `--yolo` by default (Codex uses `--full-auto` when disabled).
409
+ - Raises `RuntimeError` if the backend exits non-zero or returns no agent message.
321
410
 
322
411
  ## Configuration
323
412
 
413
+ Set the default backend:
414
+
415
+ ```bash
416
+ export CODEXAPI_BACKEND=cursor
417
+ ```
418
+
324
419
  Set `CODEX_BIN` to point at a non-default Codex binary:
325
420
 
326
421
  ```bash
327
422
  export CODEX_BIN=/path/to/codex
328
423
  ```
424
+
425
+ Set `CURSOR_BIN` to point at a non-default Cursor binary:
426
+
427
+ ```bash
428
+ export CURSOR_BIN=/path/to/cursor
429
+ ```
@@ -1,12 +1,13 @@
1
1
  # CodexAPI
2
2
 
3
- Use OpenAI's codex from python as easily as calling a function with your codex credits instead of the API.
3
+ Use Codex or Cursor agents from python as easily as calling a function, using your CLI auth instead of the API.
4
4
 
5
5
  *Note: this project is not affiliated with OpenAI in any way. Thanks for the awesome tools and models though!*
6
6
 
7
7
  ## Requirements
8
8
 
9
- - Codex CLI installed and authenticated (`codex` must be on your PATH).
9
+ - Codex CLI installed and authenticated (`codex` must be on your PATH), or
10
+ - Cursor Agent CLI installed and authenticated (`cursor` must be on your PATH).
10
11
  - Python 3.8+.
11
12
 
12
13
  ## Install
@@ -44,14 +45,19 @@ result = task()
44
45
  print(result.success, result.summary)
45
46
  ```
46
47
 
48
+ Use `backend="cursor"` (or set `CODEXAPI_BACKEND=cursor`) to switch to the
49
+ Cursor agent backend.
50
+
47
51
  ## CLI
48
52
 
49
53
  After installing, use the `codexapi` command:
50
54
 
51
55
  ```bash
56
+ codexapi --version
52
57
  codexapi run "Summarize this repo."
53
58
  codexapi run --cwd /path/to/project "Fix the failing tests."
54
59
  echo "Say hello." | codexapi run
60
+ codexapi run --backend cursor "Summarize this repo."
55
61
  ```
56
62
 
57
63
  `codexapi task` exits with code 0 on success and 1 on failure.
@@ -107,15 +113,16 @@ Show running sessions and their latest activity:
107
113
  codexapi top
108
114
  ```
109
115
  Press `h` for keys.
116
+ `codexapi top` and `codexapi limit` are Codex-only.
110
117
 
111
- Resume a session and print the thread id to stderr:
118
+ Resume a session and print the thread/session id to stderr:
112
119
 
113
120
  ```bash
114
121
  codexapi run --thread-id THREAD_ID --print-thread-id "Continue where we left off."
115
122
  ```
116
123
 
117
- Use `--no-yolo` to run Codex with `--full-auto` instead.
118
- Use `--include-thinking` to return all agent messages joined together for `codexapi run`.
124
+ Use `--no-yolo` to disable `--yolo` (Codex uses `--full-auto`).
125
+ Use `--include-thinking` to return all agent messages joined together for `codexapi run` (Codex only).
119
126
 
120
127
  Lead mode periodically checks in on a long-running agent session with the
121
128
  current time and prints JSON status updates. The agent controls the loop by
@@ -135,14 +142,89 @@ If the leadbook does not exist, lead creates it with a template.
135
142
 
136
143
  ```bash
137
144
  codexapi lead 5 "Run the benchmark and wait for results."
145
+ codexapi lead 0 "Do a rapid triage pass and report."
146
+ ```
147
+
148
+ ### Durable agents
149
+
150
+ `codexapi agent` is the durable long-running control plane. It stores state
151
+ under `CODEXAPI_HOME` (default `~/.codexapi`), wakes agents on cron, and lets
152
+ you inspect or message them from any shell that points at the same home.
138
153
 
139
- Run without waiting between check-ins:
154
+ Start by checking the effective host/home pair and installing the scheduler:
140
155
 
141
156
  ```bash
142
- codexapi lead 0 "Do a rapid triage pass and report."
157
+ codexapi agent whoami
158
+ codexapi agent install-cron
159
+ ```
160
+
161
+ If you skip `install-cron`, `codexapi agent start` warns on stderr because
162
+ background wakes will not run until the scheduler hook is installed.
163
+ When `gh` is installed and authenticated, `agent start` also captures a
164
+ background-safe `GH_TOKEN` automatically if your shell did not already export
165
+ `GH_TOKEN` or `GITHUB_TOKEN`.
166
+
167
+ Start a goal-directed agent that decides for itself when it is done:
168
+
169
+ ```bash
170
+ codexapi agent start --name ci-fixer \
171
+ "Watch CI, fix failing tests, open or update a PR, and stop when the work is done."
172
+ ```
173
+
174
+ Add `--wait` if you want `start` to block for the first local wake instead of
175
+ just scheduling it.
176
+
177
+ Start a persistent watcher that keeps running until you stop it:
178
+
179
+ ```bash
180
+ codexapi agent start --name issue-watcher \
181
+ --stop-policy until_stopped \
182
+ --heartbeat-minutes 30 \
183
+ "Every wake, scan for newly assigned issues that look actionable and report or start follow-up work."
184
+ ```
185
+
186
+ Inspect and talk to agents:
187
+
188
+ ```bash
189
+ codexapi agent list
190
+ codexapi agent show ci-fixer
191
+ codexapi agent read ci-fixer
192
+ codexapi agent book ci-fixer
193
+ codexapi agent send ci-fixer "Prefer the smallest safe fix."
194
+ codexapi agent send --wait ci-fixer "Reply now if you can handle this immediately."
195
+ codexapi agent wake ci-fixer
196
+ codexapi agent wake --wait ci-fixer
197
+ codexapi agent pause ci-fixer
198
+ codexapi agent resume ci-fixer
199
+ codexapi agent resume --wait ci-fixer
200
+ codexapi agent cancel ci-fixer
201
+ codexapi agent delete ci-fixer
202
+ ```
203
+
204
+ Create a child agent explicitly:
205
+
206
+ ```bash
207
+ codexapi agent start --name child-fix --parent ci-fixer \
208
+ "Investigate the flaky integration test and report back."
143
209
  ```
210
+
211
+ Useful environment overrides:
212
+
213
+ ```bash
214
+ CODEXAPI_HOME=/tmp/codexapi-test-home codexapi agent list
215
+ CODEXAPI_HOSTNAME=stable-host codexapi agent whoami
144
216
  ```
145
217
 
218
+ `CODEXAPI_HOME` isolates independent agent installations and is the right seam
219
+ for tests. `CODEXAPI_HOSTNAME` is useful when cron, shells, sandboxes, or test
220
+ wrappers report inconsistent hostnames for the same machine.
221
+
222
+ `codexapi agent show` also prints the resolved `AGENTBOOK.md` path so you can
223
+ jump directly to the durable working memory file.
224
+
225
+ See [docs/agent-v1.md](docs/agent-v1.md) for the filesystem model and scheduling
226
+ details.
227
+
146
228
  Ralph loop mode repeats the same prompt until a completion promise or a max
147
229
  iteration cap is hit (0 means unlimited). Cancel by deleting
148
230
  `.codexapi/ralph-loop.local.md` or running `codexapi ralph --cancel`.
@@ -191,31 +273,34 @@ codexapi foreach list.txt task.yaml --retry-all
191
273
 
192
274
  ## API
193
275
 
194
- ### `agent(prompt, cwd=None, yolo=True, flags=None, include_thinking=False) -> str`
276
+ ### `agent(prompt, cwd=None, yolo=True, flags=None, include_thinking=False, backend=None) -> str`
195
277
 
196
- Runs a single Codex turn and returns only the agent's message. Any reasoning
278
+ Runs a single agent turn and returns only the agent's message. Any reasoning
197
279
  items are filtered out.
198
280
 
199
- - `prompt` (str): prompt to send to Codex.
200
- - `cwd` (str | PathLike | None): working directory for the Codex session.
201
- - `yolo` (bool): pass `--yolo` to Codex when true (defaults to true).
202
- - `flags` (str | None): extra CLI flags to pass to Codex.
281
+ - `prompt` (str): prompt to send to the agent backend.
282
+ - `cwd` (str | PathLike | None): working directory for the agent session.
283
+ - `yolo` (bool): pass `--yolo` when true (defaults to true).
284
+ - `flags` (str | None): extra CLI flags to pass to the agent backend.
203
285
  - `include_thinking` (bool): when true, return all agent messages joined.
286
+ - `backend` (str | None): `codex` or `cursor` (defaults to `CODEXAPI_BACKEND` or `codex`).
204
287
 
205
- ### `Agent(cwd=None, yolo=True, thread_id=None, flags=None, welfare=False, include_thinking=False)`
288
+ ### `Agent(cwd=None, yolo=True, thread_id=None, flags=None, welfare=False, include_thinking=False, backend=None)`
206
289
 
207
290
  Creates a stateful session wrapper. Calling the instance sends the prompt into
208
291
  the same conversation and returns only the agent's message.
209
292
 
210
- - `__call__(prompt) -> str`: send a prompt to Codex and return the message.
293
+ - `__call__(prompt) -> str`: send a prompt to the agent backend and return the message.
211
294
  - `thread_id -> str | None`: expose the underlying session id once created.
212
- - `yolo` (bool): pass `--yolo` to Codex when true (defaults to true).
213
- - `flags` (str | None): extra CLI flags to pass to Codex.
295
+ - `yolo` (bool): pass `--yolo` when true (defaults to true).
296
+ - `flags` (str | None): extra CLI flags to pass to the agent backend.
214
297
  - `welfare` (bool): when true, append welfare stop instructions to each prompt
215
298
  and raise `WelfareStop` if the agent outputs `MAKE IT STOP`.
216
299
  - `include_thinking` (bool): when true, return all agent messages joined.
300
+ - `backend` (str | None): `codex` or `cursor` (defaults to `CODEXAPI_BACKEND` or `codex`).
301
+ For Cursor, `thread_id` corresponds to the `session_id` returned by the agent.
217
302
 
218
- ### `lead(minutes, prompt, cwd=None, yolo=True, flags=None, leadbook=None) -> dict`
303
+ ### `lead(minutes, prompt, cwd=None, yolo=True, flags=None, leadbook=None, backend=None) -> dict`
219
304
 
220
305
  Runs a long-lived agent session and periodically checks in with the current
221
306
  local time and a reminder of `prompt`. Each check-in expects JSON with keys:
@@ -226,8 +311,9 @@ JSON is invalid, lead asks the agent once to retry. The loop stops when
226
311
  Lead also injects the leadbook content into each prompt. By default it uses
227
312
  `LEADBOOK.md` in the working directory. Pass `leadbook=False` to disable or a
228
313
  path string to override the location.
314
+ Set `backend="cursor"` (or `CODEXAPI_BACKEND=cursor`) to use Cursor.
229
315
 
230
- ### `task(prompt, check=None, max_iterations=10, cwd=None, yolo=True, flags=None, progress=False, set_up=None, tear_down=None, on_success=None, on_failure=None) -> str`
316
+ ### `task(prompt, check=None, max_iterations=10, cwd=None, yolo=True, flags=None, progress=False, set_up=None, tear_down=None, on_success=None, on_failure=None, backend=None) -> str`
231
317
 
232
318
  Runs a task with checker-driven retries and returns the success summary.
233
319
  Raises `TaskFailed` when the maximum iterations are reached.
@@ -236,16 +322,17 @@ Raises `TaskFailed` when the maximum iterations are reached.
236
322
  - `max_iterations` (int): maximum number of task iterations (0 means unlimited).
237
323
  - `progress` (bool): show a tqdm progress bar with a one-line status after each round.
238
324
  - `set_up`/`tear_down`/`on_success`/`on_failure` (str | None): optional hook prompts.
325
+ - `backend` (str | None): `codex` or `cursor` (defaults to `CODEXAPI_BACKEND` or `codex`).
239
326
 
240
- ### `task_result(prompt, check=None, max_iterations=10, cwd=None, yolo=True, flags=None, progress=False, set_up=None, tear_down=None, on_success=None, on_failure=None) -> TaskResult`
327
+ ### `task_result(prompt, check=None, max_iterations=10, cwd=None, yolo=True, flags=None, progress=False, set_up=None, tear_down=None, on_success=None, on_failure=None, backend=None) -> TaskResult`
241
328
 
242
329
  Runs a task with checker-driven retries and returns a `TaskResult` without
243
330
  raising `TaskFailed`.
244
331
  Arguments mirror `task()` (including hooks).
245
332
 
246
- ### `Task(prompt, max_iterations=10, cwd=None, yolo=True, thread_id=None, flags=None)`
333
+ ### `Task(prompt, max_iterations=10, cwd=None, yolo=True, thread_id=None, flags=None, backend=None)`
247
334
 
248
- Runs a Codex task with checker-driven retries. Subclass it and implement
335
+ Runs an agent task with checker-driven retries. Subclass it and implement
249
336
  `check()` to return an error string when the task is incomplete, or return
250
337
  `None`/`""` when the task passes.
251
338
  If you do not override `check()`, the default verifier wrapper runs with the
@@ -266,7 +353,7 @@ Simple result object returned by `Task.__call__`.
266
353
  - `summary` (str): agent summary of what happened.
267
354
  - `iterations` (int): how many iterations were used.
268
355
  - `errors` (str | None): last checker error, if any.
269
- - `thread_id` (str | None): Codex thread id for the session.
356
+ - `thread_id` (str | None): thread/session id for the session.
270
357
 
271
358
  ### `TaskFailed`
272
359
 
@@ -276,16 +363,17 @@ Exception raised by `task()` when iterations are exhausted.
276
363
  - `iterations` (int | None): iterations made when the task failed.
277
364
  - `errors` (str | None): last checker error, if any.
278
365
 
279
- ### `foreach(list_file, task_file, n=None, cwd=None, yolo=True, flags=None) -> ForeachResult`
366
+ ### `foreach(list_file, task_file, n=None, cwd=None, yolo=True, flags=None, backend=None) -> ForeachResult`
280
367
 
281
368
  Runs a task file over a list of items, updating the list file in place.
282
369
 
283
370
  - `list_file` (str | PathLike): path to the list file to process.
284
371
  - `task_file` (str | PathLike): YAML task file (must include `prompt`).
285
372
  - `n` (int | None): limit parallelism to N (default: run all items in parallel).
286
- - `cwd` (str | PathLike | None): working directory for the Codex session.
287
- - `yolo` (bool): pass `--yolo` to Codex when true (defaults to true).
288
- - `flags` (str | None): extra CLI flags to pass to Codex.
373
+ - `cwd` (str | PathLike | None): working directory for the agent session.
374
+ - `yolo` (bool): pass `--yolo` when true (defaults to true).
375
+ - `flags` (str | None): extra CLI flags to pass to the agent backend.
376
+ - `backend` (str | None): `codex` or `cursor` (defaults to `CODEXAPI_BACKEND` or `codex`).
289
377
 
290
378
  ### `ForeachResult(succeeded, failed, skipped, results)`
291
379
 
@@ -298,16 +386,29 @@ Simple result object returned by `foreach()`.
298
386
 
299
387
  ## Behavior notes
300
388
 
301
- - Uses `codex exec --json` and parses JSONL events for `agent_message` items.
302
- - Returns the last `agent_message` by default; set `include_thinking=True` to join all messages.
303
- - Automatically passes `--skip-git-repo-check` so it can run outside a git repo.
304
- - Passes `--yolo` by default (use `--no-yolo` or `yolo=False` for `--full-auto`).
305
- - Raises `RuntimeError` if Codex exits non-zero or returns no agent message.
389
+ - Codex backend uses `codex exec --json` and parses JSONL `agent_message` items.
390
+ - Codex backend passes `--skip-git-repo-check` so it can run outside a git repo.
391
+ - Cursor backend uses `cursor agent --print --output-format json --trust` and parses the JSON result.
392
+ - `include_thinking=True` only affects Codex; Cursor returns a single result string.
393
+ - Passes `--yolo` by default (Codex uses `--full-auto` when disabled).
394
+ - Raises `RuntimeError` if the backend exits non-zero or returns no agent message.
306
395
 
307
396
  ## Configuration
308
397
 
398
+ Set the default backend:
399
+
400
+ ```bash
401
+ export CODEXAPI_BACKEND=cursor
402
+ ```
403
+
309
404
  Set `CODEX_BIN` to point at a non-default Codex binary:
310
405
 
311
406
  ```bash
312
407
  export CODEX_BIN=/path/to/codex
313
408
  ```
409
+
410
+ Set `CURSOR_BIN` to point at a non-default Cursor binary:
411
+
412
+ ```bash
413
+ export CURSOR_BIN=/path/to/cursor
414
+ ```
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "codexapi"
7
- version = "0.7.3"
7
+ version = "0.10.0"
8
8
  description = "Minimal Python API for running the Codex CLI."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -1,4 +1,4 @@
1
- """Minimal Python API for running the Codex CLI."""
1
+ """Minimal Python API for running agent CLIs."""
2
2
 
3
3
  from .agent import Agent, WelfareStop, agent
4
4
  from .foreach import ForeachResult, foreach
@@ -27,4 +27,4 @@ __all__ = [
27
27
  "task_result",
28
28
  "lead",
29
29
  ]
30
- __version__ = "0.7.3"
30
+ __version__ = "0.10.0"