codexapi 0.1.3__tar.gz → 0.1.7__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: codexapi
3
- Version: 0.1.3
3
+ Version: 0.1.7
4
4
  Summary: Minimal Python API for running the Codex CLI.
5
5
  License: MIT
6
6
  Keywords: codex,agent,cli,openai
@@ -56,9 +56,34 @@ result = task()
56
56
  print(result.success, result.summary)
57
57
  ```
58
58
 
59
+ ## CLI
60
+
61
+ After installing, use the `codexapi` command:
62
+
63
+ ```bash
64
+ codexapi "Summarize this repo."
65
+ codexapi --cwd /path/to/project "Fix the failing tests."
66
+ echo "Say hello." | codexapi
67
+ ```
68
+
69
+ Task mode exits with code 0 on success and 1 on failure, printing the summary.
70
+
71
+ Show running sessions and their latest activity:
72
+
73
+ ```bash
74
+ codexapi top
75
+ ```
76
+ Press `h` for keys.
77
+
78
+ Resume a session and print the thread id to stderr:
79
+
80
+ ```bash
81
+ codexapi --thread-id THREAD_ID --print-thread-id "Continue where we left off."
82
+ ```
83
+
59
84
  ## API
60
85
 
61
- ### `agent(prompt, cwd=None, yolo=False, flags=None, full_auto=False) -> str`
86
+ ### `agent(prompt, cwd=None, yolo=False, flags=None) -> str`
62
87
 
63
88
  Runs a single Codex turn and returns only the agent's message. Any reasoning
64
89
  items are filtered out.
@@ -67,9 +92,8 @@ items are filtered out.
67
92
  - `cwd` (str | PathLike | None): working directory for the Codex session.
68
93
  - `yolo` (bool): pass `--yolo` to Codex when true.
69
94
  - `flags` (str | None): extra CLI flags to pass to Codex.
70
- - `full_auto` (bool): enable `--full-auto` for workspace-write and on-request approvals.
71
95
 
72
- ### `Agent(cwd=None, yolo=False, thread_id=None, flags=None, full_auto=False)`
96
+ ### `Agent(cwd=None, yolo=False, thread_id=None, flags=None)`
73
97
 
74
98
  Creates a stateful session wrapper. Calling the instance sends the prompt into
75
99
  the same conversation and returns only the agent's message.
@@ -78,9 +102,21 @@ the same conversation and returns only the agent's message.
78
102
  - `thread_id -> str | None`: expose the underlying session id once created.
79
103
  - `yolo` (bool): pass `--yolo` to Codex when true.
80
104
  - `flags` (str | None): extra CLI flags to pass to Codex.
81
- - `full_auto` (bool): enable `--full-auto` for workspace-write and on-request approvals.
82
105
 
83
- ### `Task(prompt, max_attempts=10, cwd=None, yolo=False, thread_id=None, flags=None, full_auto=True)`
106
+ ### `task(prompt, check=None, n=10, cwd=None, yolo=False, flags=None) -> str`
107
+
108
+ Runs a task with checker-driven retries and returns the success summary.
109
+ Raises `TaskFailed` when the maximum attempts are reached.
110
+
111
+ - `check` (str | None | False): custom check prompt, default checker, or `False` to skip.
112
+ - `n` (int): maximum number of retries after a failed check.
113
+
114
+ ### `task_result(prompt, check=None, n=10, cwd=None, yolo=False, flags=None) -> TaskResult`
115
+
116
+ Runs a task with checker-driven retries and returns a `TaskResult` without
117
+ raising `TaskFailed`.
118
+
119
+ ### `Task(prompt, max_attempts=10, cwd=None, yolo=False, thread_id=None, flags=None)`
84
120
 
85
121
  Runs a Codex task with checker-driven retries. Subclass it and implement
86
122
  `check()` to return an error string when the task is incomplete, or return
@@ -92,7 +128,6 @@ Runs a Codex task with checker-driven retries. Subclass it and implement
92
128
  - `check() -> str | None`: return an error description or `None`/`""`.
93
129
  - `on_success(result)`: optional success hook.
94
130
  - `on_failure(result)`: optional failure hook.
95
- - `full_auto` (bool): enable `--full-auto` for workspace-write and on-request approvals.
96
131
 
97
132
  ### `TaskResult(success, summary, attempts, errors, thread_id)`
98
133
 
@@ -104,10 +139,19 @@ Simple result object returned by `Task.__call__`.
104
139
  - `errors` (str | None): last checker error, if any.
105
140
  - `thread_id` (str | None): Codex thread id for the session.
106
141
 
142
+ ### `TaskFailed`
143
+
144
+ Exception raised by `task()` when retries are exhausted.
145
+
146
+ - `summary` (str): failure summary text.
147
+ - `attempts` (int | None): attempts made when the task failed.
148
+ - `errors` (str | None): last checker error, if any.
149
+
107
150
  ## Behavior notes
108
151
 
109
152
  - Uses `codex exec --json` and parses JSONL events for `agent_message` items.
110
153
  - Automatically passes `--skip-git-repo-check` so it can run outside a git repo.
154
+ - Passes `--full-auto` unless `--yolo` is enabled.
111
155
  - Passes `--yolo` when enabled (use with care).
112
156
  - Raises `RuntimeError` if Codex exits non-zero or returns no agent message.
113
157
 
@@ -44,9 +44,34 @@ result = task()
44
44
  print(result.success, result.summary)
45
45
  ```
46
46
 
47
+ ## CLI
48
+
49
+ After installing, use the `codexapi` command:
50
+
51
+ ```bash
52
+ codexapi "Summarize this repo."
53
+ codexapi --cwd /path/to/project "Fix the failing tests."
54
+ echo "Say hello." | codexapi
55
+ ```
56
+
57
+ Task mode exits with code 0 on success and 1 on failure, printing the summary.
58
+
59
+ Show running sessions and their latest activity:
60
+
61
+ ```bash
62
+ codexapi top
63
+ ```
64
+ Press `h` for keys.
65
+
66
+ Resume a session and print the thread id to stderr:
67
+
68
+ ```bash
69
+ codexapi --thread-id THREAD_ID --print-thread-id "Continue where we left off."
70
+ ```
71
+
47
72
  ## API
48
73
 
49
- ### `agent(prompt, cwd=None, yolo=False, flags=None, full_auto=False) -> str`
74
+ ### `agent(prompt, cwd=None, yolo=False, flags=None) -> str`
50
75
 
51
76
  Runs a single Codex turn and returns only the agent's message. Any reasoning
52
77
  items are filtered out.
@@ -55,9 +80,8 @@ items are filtered out.
55
80
  - `cwd` (str | PathLike | None): working directory for the Codex session.
56
81
  - `yolo` (bool): pass `--yolo` to Codex when true.
57
82
  - `flags` (str | None): extra CLI flags to pass to Codex.
58
- - `full_auto` (bool): enable `--full-auto` for workspace-write and on-request approvals.
59
83
 
60
- ### `Agent(cwd=None, yolo=False, thread_id=None, flags=None, full_auto=False)`
84
+ ### `Agent(cwd=None, yolo=False, thread_id=None, flags=None)`
61
85
 
62
86
  Creates a stateful session wrapper. Calling the instance sends the prompt into
63
87
  the same conversation and returns only the agent's message.
@@ -66,9 +90,21 @@ the same conversation and returns only the agent's message.
66
90
  - `thread_id -> str | None`: expose the underlying session id once created.
67
91
  - `yolo` (bool): pass `--yolo` to Codex when true.
68
92
  - `flags` (str | None): extra CLI flags to pass to Codex.
69
- - `full_auto` (bool): enable `--full-auto` for workspace-write and on-request approvals.
70
93
 
71
- ### `Task(prompt, max_attempts=10, cwd=None, yolo=False, thread_id=None, flags=None, full_auto=True)`
94
+ ### `task(prompt, check=None, n=10, cwd=None, yolo=False, flags=None) -> str`
95
+
96
+ Runs a task with checker-driven retries and returns the success summary.
97
+ Raises `TaskFailed` when the maximum attempts are reached.
98
+
99
+ - `check` (str | None | False): custom check prompt, default checker, or `False` to skip.
100
+ - `n` (int): maximum number of retries after a failed check.
101
+
102
+ ### `task_result(prompt, check=None, n=10, cwd=None, yolo=False, flags=None) -> TaskResult`
103
+
104
+ Runs a task with checker-driven retries and returns a `TaskResult` without
105
+ raising `TaskFailed`.
106
+
107
+ ### `Task(prompt, max_attempts=10, cwd=None, yolo=False, thread_id=None, flags=None)`
72
108
 
73
109
  Runs a Codex task with checker-driven retries. Subclass it and implement
74
110
  `check()` to return an error string when the task is incomplete, or return
@@ -80,7 +116,6 @@ Runs a Codex task with checker-driven retries. Subclass it and implement
80
116
  - `check() -> str | None`: return an error description or `None`/`""`.
81
117
  - `on_success(result)`: optional success hook.
82
118
  - `on_failure(result)`: optional failure hook.
83
- - `full_auto` (bool): enable `--full-auto` for workspace-write and on-request approvals.
84
119
 
85
120
  ### `TaskResult(success, summary, attempts, errors, thread_id)`
86
121
 
@@ -92,10 +127,19 @@ Simple result object returned by `Task.__call__`.
92
127
  - `errors` (str | None): last checker error, if any.
93
128
  - `thread_id` (str | None): Codex thread id for the session.
94
129
 
130
+ ### `TaskFailed`
131
+
132
+ Exception raised by `task()` when retries are exhausted.
133
+
134
+ - `summary` (str): failure summary text.
135
+ - `attempts` (int | None): attempts made when the task failed.
136
+ - `errors` (str | None): last checker error, if any.
137
+
95
138
  ## Behavior notes
96
139
 
97
140
  - Uses `codex exec --json` and parses JSONL events for `agent_message` items.
98
141
  - Automatically passes `--skip-git-repo-check` so it can run outside a git repo.
142
+ - Passes `--full-auto` unless `--yolo` is enabled.
99
143
  - Passes `--yolo` when enabled (use with care).
100
144
  - Raises `RuntimeError` if Codex exits non-zero or returns no agent message.
101
145
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "codexapi"
7
- version = "0.1.3"
7
+ version = "0.1.7"
8
8
  description = "Minimal Python API for running the Codex CLI."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -17,6 +17,9 @@ classifiers = [
17
17
 
18
18
  dependencies = []
19
19
 
20
+ [project.scripts]
21
+ codexapi = "codexapi.cli:main"
22
+
20
23
  [tool.setuptools]
21
24
  package-dir = {"" = "src"}
22
25
 
@@ -0,0 +1,15 @@
1
+ """Minimal Python API for running the Codex CLI."""
2
+
3
+ from .agent import Agent, agent
4
+ from .task import Task, TaskFailed, TaskResult, task, task_result
5
+
6
+ __all__ = [
7
+ "Agent",
8
+ "Task",
9
+ "TaskFailed",
10
+ "TaskResult",
11
+ "agent",
12
+ "task",
13
+ "task_result",
14
+ ]
15
+ __version__ = "0.1.7"
@@ -0,0 +1,5 @@
1
+ from .cli import main
2
+
3
+
4
+ if __name__ == "__main__":
5
+ main()
@@ -8,7 +8,7 @@ import subprocess
8
8
  _CODEX_BIN = os.environ.get("CODEX_BIN", "codex")
9
9
 
10
10
 
11
- def agent(prompt, cwd=None, yolo=False, flags=None, full_auto=False):
11
+ def agent(prompt, cwd=None, yolo=False, flags=None):
12
12
  """Run a single Codex turn and return only the agent's message.
13
13
 
14
14
  Args:
@@ -20,14 +20,7 @@ def agent(prompt, cwd=None, yolo=False, flags=None, full_auto=False):
20
20
  Returns:
21
21
  The agent's visible response text with reasoning traces removed.
22
22
  """
23
- message, _thread_id = _run_codex(
24
- prompt,
25
- cwd,
26
- thread_id=None,
27
- yolo=yolo,
28
- flags=flags,
29
- full_auto=full_auto,
30
- )
23
+ message, _thread_id = _run_codex(prompt, cwd, None, yolo, flags)
31
24
  return message
32
25
 
33
26
 
@@ -46,7 +39,6 @@ class Agent:
46
39
  yolo=False,
47
40
  thread_id=None,
48
41
  flags=None,
49
- full_auto=False,
50
42
  ):
51
43
  """Create a new session wrapper.
52
44
 
@@ -60,7 +52,6 @@ class Agent:
60
52
  self.cwd = cwd
61
53
  self._yolo = yolo
62
54
  self._flags = flags
63
- self._full_auto = full_auto
64
55
  self.thread_id = thread_id
65
56
 
66
57
  def __call__(self, prompt):
@@ -71,14 +62,13 @@ class Agent:
71
62
  self.thread_id,
72
63
  self._yolo,
73
64
  self._flags,
74
- self._full_auto,
75
65
  )
76
66
  if thread_id:
77
67
  self.thread_id = thread_id
78
68
  return message
79
69
 
80
70
 
81
- def _run_codex(prompt, cwd, thread_id, yolo, flags, full_auto):
71
+ def _run_codex(prompt, cwd, thread_id, yolo, flags):
82
72
  """Invoke the Codex CLI and return the message plus thread id (if any)."""
83
73
  command = [
84
74
  _CODEX_BIN,
@@ -90,7 +80,7 @@ def _run_codex(prompt, cwd, thread_id, yolo, flags, full_auto):
90
80
  ]
91
81
  if yolo:
92
82
  command.append("--yolo")
93
- if full_auto:
83
+ else:
94
84
  command.append("--full-auto")
95
85
  if flags:
96
86
  command.extend(shlex.split(flags))