yitongl commited on
Commit
9a2b78c
·
1 Parent(s): 1d42c66

Refresh migration docs for broad auto approval

Browse files
Files changed (2) hide show
  1. LOCAL_SETUP.txt +36 -44
  2. README.md +145 -69
LOCAL_SETUP.txt CHANGED
@@ -1,20 +1,34 @@
1
  # codex_exec local shell setup
2
  # ============================
3
  #
4
- # This file records the local runx/rund setup used on this machine. It is
5
- # also valid Bash and can be copied directly to $HOME/.bash_aliases.
6
  #
7
- # Required files:
8
- # runx: $HOME/codex_auto_run.py
9
- # rund: $HOME/claude_auto_run.py (not included in this repository)
10
- #
11
- # Install and reload:
12
- # cp LOCAL_SETUP.txt $HOME/.bash_aliases
13
  # source $HOME/.bashrc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
- unalias runx rund 2>/dev/null || true
16
 
17
- _autorun_dir_name() {
18
  local rel
19
 
20
  if [[ "$PWD" == "$HOME" ]]; then
@@ -35,7 +49,8 @@ _autorun_dir_name() {
35
  done
36
  [[ -n "$rel" ]] || rel="home"
37
 
38
- # codex_auto_run.py limits a session prefix to 48 characters.
 
39
  if (( ${#rel} > 45 )); then
40
  rel="${rel:0:28}-${rel: -16}"
41
  fi
@@ -44,49 +59,26 @@ _autorun_dir_name() {
44
 
45
  runx() {
46
  local base
47
- base="$(_autorun_dir_name)"
48
- python3 "$HOME/codex_auto_run.py" --session-prefix "${base}-x" "$@"
49
  }
50
 
51
- rund() {
52
- local base
53
- base="$(_autorun_dir_name)"
54
- python3 "$HOME/claude_auto_run.py" --session-prefix "${base}-d" "$@"
55
- }
56
-
57
- # Usage:
58
- # cd $HOME/code/my_project
59
- # runx
60
- # rund
61
  #
62
- # Start with an initial prompt:
63
  # runx -p "Inspect the project, make the requested changes, and run tests."
64
- # rund -p "Inspect the project, make the requested changes, and run tests."
65
  #
66
  # Enable Codex web search:
 
67
  # runx -p "Research and complete the task." -- --search
68
  #
69
- # Because the launchers default to the current directory, -C is unnecessary
70
- # after cd. Additional arguments are passed through unchanged.
71
  #
72
- # Tmux naming for $HOME/code/my_project:
73
- # code-my_project-x Codex / runx
74
- # code-my_project-d Claude / rund
75
  #
76
- # The launcher appends a timestamp/PID uniqueness suffix to the actual tmux
77
- # session name. The -x and -d suffixes deliberately keep the Codex and Claude
78
- # approval watchers from scanning each other's sessions.
79
  #
80
- # Run status or stop commands from the same project directory so the dynamic
81
- # prefix matches:
82
  # runx --status
83
- # rund --status
84
  # runx --stop-daemon
85
- # rund --stop-daemon
86
- #
87
- # Optional global Codex skill on this machine:
88
- # Path: $HOME/.codex/skills/codex-autorun
89
- # Invoke: $codex-autorun
90
- #
91
- # The filesystem skill name uses a hyphen because Codex skill identifiers do
92
- # not allow underscores; its UI display name is codex_autorun.
 
1
  # codex_exec local shell setup
2
  # ============================
3
  #
4
+ # This file is valid Bash. Copy it to $HOME/.bash_aliases, then reload your
5
+ # shell with:
6
  #
 
 
 
 
 
 
7
  # source $HOME/.bashrc
8
+ #
9
+ # It defines one command:
10
+ #
11
+ # runx
12
+ #
13
+ # runx launches $HOME/codex_auto_run.py with a tmux session prefix derived from
14
+ # the current directory. That keeps watcher state and logs separate per project.
15
+ #
16
+ # Install from a fresh clone:
17
+ #
18
+ # git clone https://huggingface.co/yitongl/codex_exec ~/codex_exec
19
+ # cp ~/codex_exec/codex_auto_run.py ~/codex_auto_run.py
20
+ # chmod +x ~/codex_auto_run.py
21
+ # cp ~/codex_exec/LOCAL_SETUP.txt ~/.bash_aliases
22
+ # source ~/.bashrc
23
+ #
24
+ # If you keep codex_auto_run.py somewhere other than $HOME/codex_auto_run.py,
25
+ # edit CODEX_AUTORUN_SCRIPT below before copying this file.
26
+
27
+ unalias runx 2>/dev/null || true
28
 
29
+ CODEX_AUTORUN_SCRIPT="${CODEX_AUTORUN_SCRIPT:-$HOME/codex_auto_run.py}"
30
 
31
+ _codex_autorun_dir_name() {
32
  local rel
33
 
34
  if [[ "$PWD" == "$HOME" ]]; then
 
49
  done
50
  [[ -n "$rel" ]] || rel="home"
51
 
52
+ # codex_auto_run.py limits a session prefix to 48 characters. Leave room
53
+ # for the "-x" suffix.
54
  if (( ${#rel} > 45 )); then
55
  rel="${rel:0:28}-${rel: -16}"
56
  fi
 
59
 
60
  runx() {
61
  local base
62
+ base="$(_codex_autorun_dir_name)"
63
+ python3 "$CODEX_AUTORUN_SCRIPT" --session-prefix "${base}-x" "$@"
64
  }
65
 
66
+ # Examples:
 
 
 
 
 
 
 
 
 
67
  #
68
+ # cd $HOME/code/my_project
69
  # runx -p "Inspect the project, make the requested changes, and run tests."
 
70
  #
71
  # Enable Codex web search:
72
+ #
73
  # runx -p "Research and complete the task." -- --search
74
  #
75
+ # Disable broad MCP/app or directory-trust auto approval when needed:
 
76
  #
77
+ # runx --no-approve-mcp -p "Work without app/tool auto approval."
78
+ # runx --no-auto-trust-directory -p "Work without automatic directory trust."
 
79
  #
80
+ # Status, logs, and daemon control from the same project directory:
 
 
81
  #
 
 
82
  # runx --status
83
+ # tail -f ~/.runtime/$(_codex_autorun_dir_name)-x/approve-debug.log
84
  # runx --stop-daemon
 
 
 
 
 
 
 
 
README.md CHANGED
@@ -8,66 +8,122 @@ tags:
8
 
9
  # codex_exec
10
 
11
- `codex_exec` is an **unofficial** launcher for the interactive OpenAI Codex TUI. It starts a real interactive `codex` session inside `tmux` and runs a small watcher that can confirm recognized approval and selection overlays automatically.
 
 
12
 
13
- Despite the repository name, this is **not** `codex exec` and it does not turn Codex into a non-interactive subprocess. You can attach to the TUI, type follow-up messages, detach, reattach, and resume persisted Codex conversations normally.
 
 
14
 
15
- The runtime is one self-contained Python script with no third-party Python dependencies.
 
 
 
 
 
 
16
 
17
  ## Requirements
18
 
19
- - Linux. The watcher uses `fcntl` and `/proc` for locking and process identity checks.
20
  - Python 3.10 or newer.
21
  - `tmux` available on `PATH`.
22
- - The Codex CLI installed, authenticated, and available as `codex` on `PATH` (or supplied with `--codex-binary`).
 
 
 
 
 
 
23
 
24
- The current implementation and tests were validated with Codex CLI 0.142.3. The watcher recognizes text rendered by the Codex TUI, so a future Codex release that changes approval wording or layout may require detector updates.
 
 
25
 
26
- ## Important safety warning
 
27
 
28
- By default, Codex still starts with `on-request` approvals and the `workspace-write` sandbox. However, the watcher automatically confirms recognized approval and selection overlays for:
29
 
30
- - shell commands;
31
- - file edits;
32
- - permission requests; and
33
- - network access requests;
34
- - MCP/app/tool calls;
35
  - directory trust prompts;
36
- - full-access, hook, plugin, and ordinary multi-choice prompts.
 
 
 
 
37
 
38
- This removes the human review normally provided by an approval prompt. A mistaken or prompt-injected Codex action may delete files, run untrusted commands, disclose accessible data over the network, request broader permissions, choose an unintended default answer, or act through connected apps. The watcher is a convenience mechanism, **not a security boundary**. Use it only in a workspace whose contents and consequences you understand, keep important work under version control, and prefer a disposable or externally isolated environment for risky tasks.
 
 
39
 
40
- The watcher confirms the currently selected option if it is not an obvious negative or cancel choice. This includes persistent choices such as "don't ask again", session-wide approvals, or future host approvals if that row is selected.
 
 
 
 
41
 
42
- `--no-approve-mcp` disables automatic app or MCP approval. `--no-auto-trust-directory` disables automatic directory trust. `--bypass` is substantially more dangerous: it passes Codex's `--dangerously-bypass-approvals-and-sandbox` option and should only be used inside an environment that is already isolated outside Codex.
 
 
 
 
 
43
 
44
- ## Installation
 
 
 
 
 
 
45
 
46
  ```bash
47
  git clone https://huggingface.co/yitongl/codex_exec
48
  cd codex_exec
49
  chmod +x codex_auto_run.py
 
 
 
 
 
 
 
50
  ```
51
 
52
- ## Migrate to another machine
 
 
 
 
53
 
54
- Copy or clone the repository on the target machine, then install the optional
55
- `runx` shell function:
56
 
57
  ```bash
58
- git clone https://huggingface.co/yitongl/codex_exec
59
- cd codex_exec
60
- chmod +x codex_auto_run.py
61
- cp LOCAL_SETUP.txt ~/.bash_aliases
62
  source ~/.bashrc
63
- PYTHONDONTWRITEBYTECODE=1 python3 -m unittest -v test_codex_auto_run.py
64
  ```
65
 
66
- `runx` expects `codex_auto_run.py` to live at `$HOME/codex_auto_run.py`. If you
67
- keep the clone in another directory, either copy/symlink the script there or
68
- adjust the path in `LOCAL_SETUP.txt`.
 
 
 
 
 
 
69
 
70
- ## Start a new session
71
 
72
  ```bash
73
  ./codex_auto_run.py \
@@ -75,51 +131,47 @@ adjust the path in `LOCAL_SETUP.txt`.
75
  -p "Implement the requested change, run the tests, and summarize the result."
76
  ```
77
 
78
- The launcher creates a uniquely named `tmux` session and normally attaches to it immediately. The printed startup information includes the exact command needed to reattach.
 
79
 
80
- Use a UTF-8 prompt file when the task is long:
 
 
 
 
 
 
81
 
82
  ```bash
83
  ./codex_auto_run.py -C ~/code/my_project --prompt-file task.md
84
  ```
85
 
86
- ## Detach and reattach
87
-
88
  Start without attaching:
89
 
90
  ```bash
91
- ./codex_auto_run.py \
92
- --detach \
93
- -C ~/code/my_project \
94
- -p "Run the full task and verify the result."
95
  ```
96
 
97
- Then attach with the session name printed by the launcher:
98
 
99
  ```bash
100
  tmux attach -t codex-auto-YYYYMMDD-HHMMSS-PID-RANDOM
101
  ```
102
 
103
- Inside `tmux`, press `Ctrl-b d` to detach without stopping Codex. Exiting Codex normally ends the `tmux` session unless `--keep-dead-session` was used. When no managed panes remain, the watcher exits after its idle timeout (120 seconds by default).
104
 
105
- ## Resume a Codex conversation
106
 
107
  Resume the most recent interactive conversation for a working directory:
108
 
109
  ```bash
110
- ./codex_auto_run.py \
111
- --resume-last \
112
- -C ~/code/my_project \
113
- -p "Continue the task and rerun the verification."
114
  ```
115
 
116
  Resume a specific Codex session ID or name:
117
 
118
  ```bash
119
- ./codex_auto_run.py \
120
- --resume SESSION_ID \
121
- -C ~/code/my_project \
122
- -p "Continue from the previous result."
123
  ```
124
 
125
  Open Codex's interactive session picker:
@@ -128,11 +180,12 @@ Open Codex's interactive session picker:
128
  ./codex_auto_run.py --resume -C ~/code/my_project
129
  ```
130
 
131
- The picker form cannot be combined with `-p` or `--prompt-file`; select the conversation first and then type in Codex. Resuming starts a new `tmux` wrapper around a persisted Codex conversation. If the original `tmux` session is still running, simply reattach to that session instead.
 
132
 
133
- ## Pass options to Codex
134
 
135
- Place Codex-specific global options after `--`:
136
 
137
  ```bash
138
  ./codex_auto_run.py \
@@ -143,15 +196,17 @@ Place Codex-specific global options after `--`:
143
  --model MODEL_NAME
144
  ```
145
 
146
- The wrapper reserves `-p` for the initial or resumed-session follow-up prompt. Use `--codex-profile PROFILE_NAME` for a Codex profile.
147
-
148
- No model is hardcoded by this repository. Without `--model`, Codex inherits the model selected by the user's Codex configuration and CLI defaults.
149
 
150
- Some Codex options that conflict with wrapper-managed behavior, including Codex's own approval, sandbox, working-directory, full-auto, and bypass flags, are rejected. Use the wrapper's `--sandbox`, `-C`, and `--bypass` options instead.
 
 
 
151
 
152
- ## Watcher controls
153
 
154
- Show the watcher and managed-session status:
155
 
156
  ```bash
157
  ./codex_auto_run.py --status
@@ -169,27 +224,48 @@ Start only the watcher:
169
  ./codex_auto_run.py --start-daemon
170
  ```
171
 
172
- By default, private watcher state and logs are stored under `~/.runtime/codex-auto/`. Only sessions created and registered by this wrapper are watched.
 
 
 
 
 
 
 
 
 
 
173
 
174
- Run `./codex_auto_run.py --help` for all tuning and safety options.
175
 
176
- ## Optional shell aliases
 
 
 
 
 
 
 
 
 
177
 
178
- [`LOCAL_SETUP.txt`](LOCAL_SETUP.txt) contains the current `runx`/`rund` Bash
179
- functions, project-relative tmux naming rules, usage examples, and the local
180
- `codex-autorun` skill location. The `rund` function expects a separate
181
- `~/claude_auto_run.py`, which is not included in this repository.
182
 
183
  ## Tests
184
 
185
- The unit tests exercise approval-screen detection, argument validation, resume command construction, binary probing, `tmux` command construction, and daemon lifecycle safeguards without starting a real Codex session:
186
 
187
  ```bash
188
  PYTHONDONTWRITEBYTECODE=1 python3 -m unittest -v test_codex_auto_run.py
189
  ```
190
 
191
- A passing unit-test suite cannot guarantee compatibility with a future Codex TUI. Before relying on unattended operation after a Codex upgrade, observe a real low-risk session and verify that approvals are detected as intended.
 
 
 
192
 
193
- ## Project status
194
 
195
- This project is independent and unofficial. It is not an OpenAI product and is not endorsed or supported by OpenAI.
 
 
8
 
9
  # codex_exec
10
 
11
+ `codex_exec` is an unofficial launcher for the interactive OpenAI Codex TUI.
12
+ It starts a real interactive `codex` session inside `tmux` and runs a watcher
13
+ that automatically confirms recognized Codex approval and selection overlays.
14
 
15
+ Despite the repository name, this is not `codex exec` and it does not turn
16
+ Codex into a non-interactive subprocess. You can attach to the TUI, type
17
+ follow-up messages, detach, reattach, and resume persisted Codex conversations.
18
 
19
+ The project is intentionally small and self-contained:
20
+
21
+ - `codex_auto_run.py`: the launcher and approval watcher.
22
+ - `test_codex_auto_run.py`: unit tests for detection, argument handling, and
23
+ daemon lifecycle behavior.
24
+ - `LOCAL_SETUP.txt`: optional `runx` Bash setup.
25
+ - `README.md`: this document.
26
 
27
  ## Requirements
28
 
29
+ - Linux. The watcher uses `fcntl`, `/proc`, and `tmux`.
30
  - Python 3.10 or newer.
31
  - `tmux` available on `PATH`.
32
+ - Codex CLI installed, authenticated, and available as `codex` on `PATH`, or
33
+ supplied with `--codex-binary`.
34
+
35
+ The watcher recognizes text rendered by the Codex TUI. If a future Codex
36
+ release changes approval wording or layout, detector updates may be required.
37
+
38
+ ## Current Approval Policy
39
 
40
+ By default, Codex still starts with `on-request` approvals and the
41
+ `workspace-write` sandbox. The watcher then confirms recognized overlays after
42
+ the screen is stable for multiple polls.
43
 
44
+ The current default is broad auto-approval. It confirms the currently selected
45
+ option when that option is not an obvious negative or cancel choice.
46
 
47
+ Automatically confirmed by default:
48
 
49
+ - shell command approvals;
50
+ - file edit approvals;
51
+ - permission approvals;
52
+ - network access approvals;
53
+ - MCP/app/tool approvals;
54
  - directory trust prompts;
55
+ - full-access prompts;
56
+ - hook/plugin prompts;
57
+ - ordinary multi-choice prompts such as `Questions 1/1`;
58
+ - persistent approval rows such as "don't ask again", session-wide approvals,
59
+ or future host approvals, if that row is currently selected.
60
 
61
+ The watcher will not confirm an option whose label starts with an obvious
62
+ negative/cancel prefix such as `No`, `Cancel`, `Deny`, `Reject`, `Quit`,
63
+ `Do not`, or `Don't`.
64
 
65
+ This removes the human review normally provided by an approval prompt. A
66
+ mistaken or prompt-injected Codex action may delete files, run untrusted
67
+ commands, disclose accessible data over the network, request broader
68
+ permissions, choose an unintended default answer, or act through connected apps.
69
+ Use this only in an environment where those side effects are acceptable.
70
 
71
+ Useful opt-out switches:
72
+
73
+ ```bash
74
+ ./codex_auto_run.py --no-approve-mcp ...
75
+ ./codex_auto_run.py --no-auto-trust-directory ...
76
+ ```
77
 
78
+ `--bypass` is more dangerous: it passes Codex's
79
+ `--dangerously-bypass-approvals-and-sandbox` option and should only be used
80
+ inside an externally isolated container or VM.
81
+
82
+ ## Install Or Migrate
83
+
84
+ Clone the repository on the target machine:
85
 
86
  ```bash
87
  git clone https://huggingface.co/yitongl/codex_exec
88
  cd codex_exec
89
  chmod +x codex_auto_run.py
90
+ PYTHONDONTWRITEBYTECODE=1 python3 -m unittest -v test_codex_auto_run.py
91
+ ```
92
+
93
+ Run directly from the clone:
94
+
95
+ ```bash
96
+ ./codex_auto_run.py -C ~/code/my_project -p "Inspect the project and run tests."
97
  ```
98
 
99
+ ## Optional `runx` Command
100
+
101
+ `LOCAL_SETUP.txt` provides a Bash function named `runx`. It derives a tmux
102
+ session prefix from the current directory, so different projects get separate
103
+ watcher state and logs.
104
 
105
+ The default `runx` setup expects the launcher at `$HOME/codex_auto_run.py`.
106
+ Install it like this:
107
 
108
  ```bash
109
+ git clone https://huggingface.co/yitongl/codex_exec ~/codex_exec
110
+ cp ~/codex_exec/codex_auto_run.py ~/codex_auto_run.py
111
+ chmod +x ~/codex_auto_run.py
112
+ cp ~/codex_exec/LOCAL_SETUP.txt ~/.bash_aliases
113
  source ~/.bashrc
 
114
  ```
115
 
116
+ Then use it from any project directory:
117
+
118
+ ```bash
119
+ cd ~/code/my_project
120
+ runx -p "Implement the requested change and verify it."
121
+ ```
122
+
123
+ If you want to keep the script somewhere else, edit the path in
124
+ `LOCAL_SETUP.txt` before copying it to `~/.bash_aliases`.
125
 
126
+ ## Start A Session
127
 
128
  ```bash
129
  ./codex_auto_run.py \
 
131
  -p "Implement the requested change, run the tests, and summarize the result."
132
  ```
133
 
134
+ The launcher creates a uniquely named `tmux` session and normally attaches to
135
+ it immediately. Startup output includes:
136
 
137
+ - the tmux session name;
138
+ - the Codex binary path;
139
+ - the working directory;
140
+ - the approval log path;
141
+ - the reattach command.
142
+
143
+ Use a UTF-8 prompt file for long tasks:
144
 
145
  ```bash
146
  ./codex_auto_run.py -C ~/code/my_project --prompt-file task.md
147
  ```
148
 
 
 
149
  Start without attaching:
150
 
151
  ```bash
152
+ ./codex_auto_run.py --detach -C ~/code/my_project -p "Run the full task."
 
 
 
153
  ```
154
 
155
+ Reattach later:
156
 
157
  ```bash
158
  tmux attach -t codex-auto-YYYYMMDD-HHMMSS-PID-RANDOM
159
  ```
160
 
161
+ Inside `tmux`, press `Ctrl-b d` to detach without stopping Codex.
162
 
163
+ ## Resume
164
 
165
  Resume the most recent interactive conversation for a working directory:
166
 
167
  ```bash
168
+ ./codex_auto_run.py --resume-last -C ~/code/my_project -p "Continue and verify."
 
 
 
169
  ```
170
 
171
  Resume a specific Codex session ID or name:
172
 
173
  ```bash
174
+ ./codex_auto_run.py --resume SESSION_ID -C ~/code/my_project -p "Continue."
 
 
 
175
  ```
176
 
177
  Open Codex's interactive session picker:
 
180
  ./codex_auto_run.py --resume -C ~/code/my_project
181
  ```
182
 
183
+ The picker form cannot be combined with `-p` or `--prompt-file`; select the
184
+ conversation first, then type in Codex.
185
 
186
+ ## Pass Codex Options
187
 
188
+ Put Codex-specific global options after `--`:
189
 
190
  ```bash
191
  ./codex_auto_run.py \
 
196
  --model MODEL_NAME
197
  ```
198
 
199
+ The wrapper reserves `-p` for the initial or resumed-session follow-up prompt.
200
+ Use `--codex-profile PROFILE_NAME` for Codex's own profile option.
 
201
 
202
+ Some Codex options conflict with wrapper-managed behavior and are rejected,
203
+ including Codex's own approval, sandbox, working-directory, full-auto, and
204
+ bypass flags. Use the wrapper's `--sandbox`, `-C`, and `--bypass` options
205
+ instead.
206
 
207
+ ## Watcher Status, Logs, And Control
208
 
209
+ Show status:
210
 
211
  ```bash
212
  ./codex_auto_run.py --status
 
224
  ./codex_auto_run.py --start-daemon
225
  ```
226
 
227
+ Default runtime state and logs are stored under:
228
+
229
+ ```bash
230
+ ~/.runtime/<session-prefix>/
231
+ ```
232
+
233
+ The approval log is:
234
+
235
+ ```bash
236
+ ~/.runtime/<session-prefix>/approve-debug.log
237
+ ```
238
 
239
+ For the default direct launcher prefix this is:
240
 
241
+ ```bash
242
+ ~/.runtime/codex-auto/approve-debug.log
243
+ ```
244
+
245
+ For `runx`, the prefix is based on the current directory and ends in `-x`.
246
+ For example, running from `$HOME` uses:
247
+
248
+ ```bash
249
+ ~/.runtime/home-x/approve-debug.log
250
+ ```
251
 
252
+ Log events include `daemon_start`, `launcher_ready`, `pending`, `approve`,
253
+ `approve_failed`, `clear_active`, `daemon_exit`, and `daemon_stop`.
 
 
254
 
255
  ## Tests
256
 
257
+ Run the unit tests:
258
 
259
  ```bash
260
  PYTHONDONTWRITEBYTECODE=1 python3 -m unittest -v test_codex_auto_run.py
261
  ```
262
 
263
+ The tests do not start a real Codex session. They cover approval-screen
264
+ detection, broad default approval behavior, opt-out switches, argument
265
+ validation, resume command construction, binary probing, tmux command
266
+ construction, and daemon lifecycle safeguards.
267
 
268
+ ## Project Status
269
 
270
+ This project is independent and unofficial. It is not an OpenAI product and is
271
+ not endorsed or supported by OpenAI.