codexapi 0.1.1__tar.gz → 0.1.2__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.1
3
+ Version: 0.1.2
4
4
  Summary: Minimal Python API for running the Codex CLI.
5
5
  License: MIT
6
6
  Keywords: codex,agent,cli,openai
@@ -37,11 +37,16 @@ print(agent("Say hello"))
37
37
  session = Agent(cwd="/path/to/project")
38
38
  print(session("Summarize this repo."))
39
39
  print(session("Now list any risks."))
40
+
41
+ # Save and resume a session later
42
+ thread_id = session.thread_id
43
+ session2 = Agent(cwd="/path/to/project", trace_id=thread_id)
44
+ print(session2("Continue from where we left off."))
40
45
  ```
41
46
 
42
47
  ## API
43
48
 
44
- ### `agent(prompt, cwd=None, *, yolo=False, agent="codex") -> str`
49
+ ### `agent(prompt, cwd=None, *, yolo=False, agent="codex", flags=None) -> str`
45
50
 
46
51
  Runs a single Codex turn and returns only the agent's message. Any reasoning
47
52
  items are filtered out.
@@ -50,8 +55,9 @@ items are filtered out.
50
55
  - `cwd` (str | PathLike | None): working directory for the Codex session.
51
56
  - `yolo` (bool): pass `--yolo` to Codex when true.
52
57
  - `agent` (str): agent backend to use (only `"codex"` is supported).
58
+ - `flags` (str | None): extra CLI flags to pass to Codex.
53
59
 
54
- ### `Agent(cwd=None, *, yolo=False, agent="codex", trace_id=None)`
60
+ ### `Agent(cwd=None, *, yolo=False, agent="codex", trace_id=None, flags=None)`
55
61
 
56
62
  Creates a stateful session wrapper. Calling the instance sends the prompt into
57
63
  the same conversation and returns only the agent's message.
@@ -61,6 +67,7 @@ the same conversation and returns only the agent's message.
61
67
  - `trace_id` (str | None): Codex thread id to resume from the first call.
62
68
  - `yolo` (bool): pass `--yolo` to Codex when true.
63
69
  - `agent` (str): agent backend to use (only `"codex"` is supported).
70
+ - `flags` (str | None): extra CLI flags to pass to Codex.
64
71
 
65
72
  ## Behavior notes
66
73
 
@@ -25,11 +25,16 @@ print(agent("Say hello"))
25
25
  session = Agent(cwd="/path/to/project")
26
26
  print(session("Summarize this repo."))
27
27
  print(session("Now list any risks."))
28
+
29
+ # Save and resume a session later
30
+ thread_id = session.thread_id
31
+ session2 = Agent(cwd="/path/to/project", trace_id=thread_id)
32
+ print(session2("Continue from where we left off."))
28
33
  ```
29
34
 
30
35
  ## API
31
36
 
32
- ### `agent(prompt, cwd=None, *, yolo=False, agent="codex") -> str`
37
+ ### `agent(prompt, cwd=None, *, yolo=False, agent="codex", flags=None) -> str`
33
38
 
34
39
  Runs a single Codex turn and returns only the agent's message. Any reasoning
35
40
  items are filtered out.
@@ -38,8 +43,9 @@ items are filtered out.
38
43
  - `cwd` (str | PathLike | None): working directory for the Codex session.
39
44
  - `yolo` (bool): pass `--yolo` to Codex when true.
40
45
  - `agent` (str): agent backend to use (only `"codex"` is supported).
46
+ - `flags` (str | None): extra CLI flags to pass to Codex.
41
47
 
42
- ### `Agent(cwd=None, *, yolo=False, agent="codex", trace_id=None)`
48
+ ### `Agent(cwd=None, *, yolo=False, agent="codex", trace_id=None, flags=None)`
43
49
 
44
50
  Creates a stateful session wrapper. Calling the instance sends the prompt into
45
51
  the same conversation and returns only the agent's message.
@@ -49,6 +55,7 @@ the same conversation and returns only the agent's message.
49
55
  - `trace_id` (str | None): Codex thread id to resume from the first call.
50
56
  - `yolo` (bool): pass `--yolo` to Codex when true.
51
57
  - `agent` (str): agent backend to use (only `"codex"` is supported).
58
+ - `flags` (str | None): extra CLI flags to pass to Codex.
52
59
 
53
60
  ## Behavior notes
54
61
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "codexapi"
7
- version = "0.1.1"
7
+ version = "0.1.2"
8
8
  description = "Minimal Python API for running the Codex CLI."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -3,4 +3,4 @@
3
3
  from .client import Agent, agent
4
4
 
5
5
  __all__ = ["Agent", "agent"]
6
- __version__ = "0.1.1"
6
+ __version__ = "0.1.2"
@@ -4,6 +4,7 @@ from __future__ import annotations
4
4
 
5
5
  import json
6
6
  import os
7
+ import shlex
7
8
  import subprocess
8
9
  from typing import Optional, Tuple, Union
9
10
 
@@ -18,6 +19,7 @@ def agent(
18
19
  *,
19
20
  yolo: bool = False,
20
21
  agent: str = "codex",
22
+ flags: Optional[str] = None,
21
23
  ) -> str:
22
24
  """Run a single Codex turn and return only the agent's message.
23
25
 
@@ -26,6 +28,7 @@ def agent(
26
28
  cwd: Optional working directory for the Codex session.
27
29
  yolo: Whether to pass --yolo to Codex.
28
30
  agent: Agent backend to use (only "codex" is supported).
31
+ flags: Additional raw CLI flags to pass to Codex.
29
32
 
30
33
  Returns:
31
34
  The agent's visible response text with reasoning traces removed.
@@ -36,6 +39,7 @@ def agent(
36
39
  cwd=cwd,
37
40
  thread_id=None,
38
41
  yolo=yolo,
42
+ flags=flags,
39
43
  )
40
44
  return message
41
45
 
@@ -56,6 +60,7 @@ class Agent:
56
60
  yolo: bool = False,
57
61
  agent: str = "codex",
58
62
  trace_id: Optional[str] = None,
63
+ flags: Optional[str] = None,
59
64
  ) -> None:
60
65
  """Create a new session wrapper.
61
66
 
@@ -64,10 +69,12 @@ class Agent:
64
69
  yolo: Whether to pass --yolo to Codex.
65
70
  agent: Agent backend to use (only "codex" is supported).
66
71
  trace_id: Optional Codex thread id to resume from the first call.
72
+ flags: Additional raw CLI flags to pass to Codex.
67
73
  """
68
74
  _require_codex_agent(agent)
69
75
  self._cwd = cwd
70
76
  self._yolo = yolo
77
+ self._flags = flags
71
78
  self._thread_id: Optional[str] = trace_id
72
79
 
73
80
  def __call__(self, prompt: str) -> str:
@@ -77,6 +84,7 @@ class Agent:
77
84
  cwd=self._cwd,
78
85
  thread_id=self._thread_id,
79
86
  yolo=self._yolo,
87
+ flags=self._flags,
80
88
  )
81
89
  if thread_id:
82
90
  self._thread_id = thread_id
@@ -94,6 +102,7 @@ def _run_codex(
94
102
  cwd: Optional[Pathish],
95
103
  thread_id: Optional[str],
96
104
  yolo: bool,
105
+ flags: Optional[str],
97
106
  ) -> Tuple[str, Optional[str]]:
98
107
  """Invoke the Codex CLI and return the message plus thread id (if any)."""
99
108
  cmd = [
@@ -106,6 +115,8 @@ def _run_codex(
106
115
  ]
107
116
  if yolo:
108
117
  cmd.append("--yolo")
118
+ if flags:
119
+ cmd.extend(shlex.split(flags))
109
120
  if cwd is not None:
110
121
  cmd.extend(["--cd", os.fspath(cwd)])
111
122
  if thread_id:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: codexapi
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: Minimal Python API for running the Codex CLI.
5
5
  License: MIT
6
6
  Keywords: codex,agent,cli,openai
@@ -37,11 +37,16 @@ print(agent("Say hello"))
37
37
  session = Agent(cwd="/path/to/project")
38
38
  print(session("Summarize this repo."))
39
39
  print(session("Now list any risks."))
40
+
41
+ # Save and resume a session later
42
+ thread_id = session.thread_id
43
+ session2 = Agent(cwd="/path/to/project", trace_id=thread_id)
44
+ print(session2("Continue from where we left off."))
40
45
  ```
41
46
 
42
47
  ## API
43
48
 
44
- ### `agent(prompt, cwd=None, *, yolo=False, agent="codex") -> str`
49
+ ### `agent(prompt, cwd=None, *, yolo=False, agent="codex", flags=None) -> str`
45
50
 
46
51
  Runs a single Codex turn and returns only the agent's message. Any reasoning
47
52
  items are filtered out.
@@ -50,8 +55,9 @@ items are filtered out.
50
55
  - `cwd` (str | PathLike | None): working directory for the Codex session.
51
56
  - `yolo` (bool): pass `--yolo` to Codex when true.
52
57
  - `agent` (str): agent backend to use (only `"codex"` is supported).
58
+ - `flags` (str | None): extra CLI flags to pass to Codex.
53
59
 
54
- ### `Agent(cwd=None, *, yolo=False, agent="codex", trace_id=None)`
60
+ ### `Agent(cwd=None, *, yolo=False, agent="codex", trace_id=None, flags=None)`
55
61
 
56
62
  Creates a stateful session wrapper. Calling the instance sends the prompt into
57
63
  the same conversation and returns only the agent's message.
@@ -61,6 +67,7 @@ the same conversation and returns only the agent's message.
61
67
  - `trace_id` (str | None): Codex thread id to resume from the first call.
62
68
  - `yolo` (bool): pass `--yolo` to Codex when true.
63
69
  - `agent` (str): agent backend to use (only `"codex"` is supported).
70
+ - `flags` (str | None): extra CLI flags to pass to Codex.
64
71
 
65
72
  ## Behavior notes
66
73
 
File without changes
File without changes