Default to broad Codex auto approval
Browse files- README.md +27 -6
- codex_auto_run.py +121 -30
- test_codex_auto_run.py +49 -20
README.md
CHANGED
|
@@ -8,7 +8,7 @@ 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
|
| 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 |
|
|
@@ -25,18 +25,21 @@ The current implementation and tests were validated with Codex CLI 0.142.3. The
|
|
| 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
|
| 29 |
|
| 30 |
- shell commands;
|
| 31 |
- file edits;
|
| 32 |
- permission requests; and
|
| 33 |
-
- network access requests
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
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,
|
| 36 |
|
| 37 |
-
The watcher
|
| 38 |
|
| 39 |
-
`--approve-mcp`
|
| 40 |
|
| 41 |
## Installation
|
| 42 |
|
|
@@ -46,6 +49,24 @@ cd codex_exec
|
|
| 46 |
chmod +x codex_auto_run.py
|
| 47 |
```
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
## Start a new session
|
| 50 |
|
| 51 |
```bash
|
|
|
|
| 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 |
|
|
|
|
| 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 |
|
|
|
|
| 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
|
codex_auto_run.py
CHANGED
|
@@ -3,8 +3,8 @@
|
|
| 3 |
|
| 4 |
This is deliberately an interactive Codex session, not ``codex exec``. A
|
| 5 |
small daemon watches only tmux sessions created with the configured prefix and
|
| 6 |
-
presses the
|
| 7 |
-
has been stable for multiple polls.
|
| 8 |
|
| 9 |
Typical use::
|
| 10 |
|
|
@@ -21,12 +21,13 @@ use ``--codex-profile NAME`` or place Codex options after ``--``.
|
|
| 21 |
|
| 22 |
Security model
|
| 23 |
--------------
|
| 24 |
-
By default the watcher approves Codex command, edit, permission,
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
| 30 |
"""
|
| 31 |
|
| 32 |
from __future__ import annotations
|
|
@@ -50,7 +51,7 @@ from pathlib import Path
|
|
| 50 |
from typing import TextIO
|
| 51 |
|
| 52 |
|
| 53 |
-
SCRIPT_VERSION =
|
| 54 |
DEFAULT_SESSION_PREFIX = "codex-auto"
|
| 55 |
DEFAULT_POLL_INTERVAL = 0.35
|
| 56 |
DEFAULT_COOLDOWN = 0.8
|
|
@@ -62,7 +63,10 @@ LOG_BACKUPS = 3
|
|
| 62 |
MAX_OVERLAY_ROWS = 80
|
| 63 |
|
| 64 |
ANSI_ESCAPE_RE = re.compile(r"\x1b(?:\[[0-?]*[ -/]*[@-~]|\][^\x07]*(?:\x07|\x1b\\))")
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
| 66 |
STANDARD_FOOTER_RE = re.compile(
|
| 67 |
r"^press\s+enter\s+to\s+confirm\s+or\s+.+\s+to\s+cancel(?:\s+or\s+.+)?$",
|
| 68 |
re.IGNORECASE,
|
|
@@ -82,13 +86,23 @@ STANDARD_TITLES: dict[str, str] = {
|
|
| 82 |
}
|
| 83 |
|
| 84 |
POSITIVE_LABELS: dict[str, tuple[str, ...]] = {
|
| 85 |
-
"command": ("yes, proceed",),
|
| 86 |
-
"edit": ("yes, proceed",),
|
| 87 |
-
"permissions": ("yes, grant
|
| 88 |
-
"network": ("yes, just this once",),
|
| 89 |
"mcp": ("yes, provide the requested info",),
|
| 90 |
}
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
NEGATIVE_SIGNALS: dict[str, tuple[str, ...]] = {
|
| 93 |
"command": (
|
| 94 |
"no, continue without running it",
|
|
@@ -397,9 +411,9 @@ class TmuxClient:
|
|
| 397 |
return output.splitlines() if rc == 0 else []
|
| 398 |
|
| 399 |
def confirm_selected_choice(self, pane_id: str) -> bool:
|
| 400 |
-
# Detection requires Codex's own
|
| 401 |
-
#
|
| 402 |
-
#
|
| 403 |
rc, _, _ = self.run("send-keys", "-t", pane_id, "Enter")
|
| 404 |
return rc == 0
|
| 405 |
|
|
@@ -522,14 +536,27 @@ def _find_standard_title_span(
|
|
| 522 |
return None
|
| 523 |
|
| 524 |
|
| 525 |
-
def
|
| 526 |
for idx in range(before - 1, -1, -1):
|
| 527 |
-
match =
|
| 528 |
if match:
|
| 529 |
return idx, match.group("label")
|
| 530 |
return None
|
| 531 |
|
| 532 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 533 |
def _contains_any(lines: list[str], values: tuple[str, ...]) -> bool:
|
| 534 |
# Joining with spaces lets fixed phrases survive terminal soft wrapping.
|
| 535 |
joined = " ".join(lines).casefold()
|
|
@@ -548,7 +575,7 @@ def detect_standard_approval(lines: list[str], approve_mcp: bool) -> PromptCandi
|
|
| 548 |
return None
|
| 549 |
footer_start, footer_end = footer
|
| 550 |
|
| 551 |
-
selected =
|
| 552 |
if selected is None:
|
| 553 |
return None
|
| 554 |
selected_row, selected_label = selected
|
|
@@ -588,10 +615,12 @@ def detect_mcp_tool_approval(lines: list[str]) -> PromptCandidate | None:
|
|
| 588 |
return None
|
| 589 |
footer_start, footer_end = footer
|
| 590 |
|
| 591 |
-
selected =
|
| 592 |
if selected is None:
|
| 593 |
return None
|
| 594 |
selected_row, selected_label = selected
|
|
|
|
|
|
|
| 595 |
if not selected_label.casefold().startswith("allow"):
|
| 596 |
return None
|
| 597 |
|
|
@@ -618,10 +647,12 @@ def detect_trust_directory(lines: list[str]) -> PromptCandidate | None:
|
|
| 618 |
return None
|
| 619 |
footer_start, footer_end = footer
|
| 620 |
|
| 621 |
-
selected =
|
| 622 |
if selected is None:
|
| 623 |
return None
|
| 624 |
selected_row, label = selected
|
|
|
|
|
|
|
| 625 |
if not label.casefold().startswith("yes, continue"):
|
| 626 |
return None
|
| 627 |
|
|
@@ -633,6 +664,46 @@ def detect_trust_directory(lines: list[str]) -> PromptCandidate | None:
|
|
| 633 |
return PromptCandidate(kind="trust_directory", signature=_candidate_signature("trust", overlay))
|
| 634 |
|
| 635 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 636 |
def detect_candidate(raw_lines: list[str], config: Config) -> PromptCandidate | None:
|
| 637 |
lines = [normalize_line(line) for line in raw_lines]
|
| 638 |
candidate = detect_standard_approval(lines, config.approve_mcp)
|
|
@@ -643,8 +714,10 @@ def detect_candidate(raw_lines: list[str], config: Config) -> PromptCandidate |
|
|
| 643 |
if candidate is not None:
|
| 644 |
return candidate
|
| 645 |
if config.auto_trust_directory:
|
| 646 |
-
|
| 647 |
-
|
|
|
|
|
|
|
| 648 |
|
| 649 |
|
| 650 |
def _write_daemon_record(config: Config, record: DaemonRecord) -> None:
|
|
@@ -862,10 +935,12 @@ def start_daemon(config: Config) -> tuple[bool, str | None]:
|
|
| 862 |
"--idle-exit-seconds",
|
| 863 |
str(config.idle_exit_seconds),
|
| 864 |
]
|
| 865 |
-
if config.approve_mcp
|
| 866 |
-
|
| 867 |
-
|
| 868 |
-
|
|
|
|
|
|
|
| 869 |
|
| 870 |
with open(os.devnull, "rb") as devnull_in, open(os.devnull, "ab") as devnull_out:
|
| 871 |
subprocess.Popen(
|
|
@@ -1215,13 +1290,29 @@ def parse_args(argv: list[str] | None = None) -> tuple[argparse.ArgumentParser,
|
|
| 1215 |
)
|
| 1216 |
parser.add_argument(
|
| 1217 |
"--approve-mcp",
|
|
|
|
| 1218 |
action="store_true",
|
| 1219 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1220 |
)
|
| 1221 |
parser.add_argument(
|
| 1222 |
"--auto-trust-directory",
|
|
|
|
| 1223 |
action="store_true",
|
| 1224 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1225 |
)
|
| 1226 |
parser.add_argument(
|
| 1227 |
"--detach",
|
|
|
|
| 3 |
|
| 4 |
This is deliberately an interactive Codex session, not ``codex exec``. A
|
| 5 |
small daemon watches only tmux sessions created with the configured prefix and
|
| 6 |
+
presses the currently selected non-negative choice when a Codex confirmation or
|
| 7 |
+
selection overlay has been stable for multiple polls.
|
| 8 |
|
| 9 |
Typical use::
|
| 10 |
|
|
|
|
| 21 |
|
| 22 |
Security model
|
| 23 |
--------------
|
| 24 |
+
By default the watcher approves Codex command, edit, permission, network,
|
| 25 |
+
MCP/app/tool, directory-trust, full-access, plugin, hook, and ordinary
|
| 26 |
+
multi-choice overlays whenever the current selection is not an obvious
|
| 27 |
+
negative/cancel choice. This is intentionally broad automation and should only
|
| 28 |
+
be used in an environment where these side effects are acceptable.
|
| 29 |
+
``--bypass`` maps to Codex's dangerous no-sandbox mode and should only be used
|
| 30 |
+
inside an externally isolated container or VM.
|
| 31 |
"""
|
| 32 |
|
| 33 |
from __future__ import annotations
|
|
|
|
| 51 |
from typing import TextIO
|
| 52 |
|
| 53 |
|
| 54 |
+
SCRIPT_VERSION = 2
|
| 55 |
DEFAULT_SESSION_PREFIX = "codex-auto"
|
| 56 |
DEFAULT_POLL_INTERVAL = 0.35
|
| 57 |
DEFAULT_COOLDOWN = 0.8
|
|
|
|
| 63 |
MAX_OVERLAY_ROWS = 80
|
| 64 |
|
| 65 |
ANSI_ESCAPE_RE = re.compile(r"\x1b(?:\[[0-?]*[ -/]*[@-~]|\][^\x07]*(?:\x07|\x1b\\))")
|
| 66 |
+
SELECTED_OPTION_RE = re.compile(
|
| 67 |
+
r"^[›>]\s*(?P<number>\d+)\.\s+(?P<label>.+)$",
|
| 68 |
+
re.IGNORECASE,
|
| 69 |
+
)
|
| 70 |
STANDARD_FOOTER_RE = re.compile(
|
| 71 |
r"^press\s+enter\s+to\s+confirm\s+or\s+.+\s+to\s+cancel(?:\s+or\s+.+)?$",
|
| 72 |
re.IGNORECASE,
|
|
|
|
| 86 |
}
|
| 87 |
|
| 88 |
POSITIVE_LABELS: dict[str, tuple[str, ...]] = {
|
| 89 |
+
"command": ("yes, proceed", "yes, and"),
|
| 90 |
+
"edit": ("yes, proceed", "yes, and"),
|
| 91 |
+
"permissions": ("yes, grant",),
|
| 92 |
+
"network": ("yes, just this once", "yes, and allow"),
|
| 93 |
"mcp": ("yes, provide the requested info",),
|
| 94 |
}
|
| 95 |
|
| 96 |
+
NEGATIVE_LABEL_PREFIXES = (
|
| 97 |
+
"no",
|
| 98 |
+
"cancel",
|
| 99 |
+
"deny",
|
| 100 |
+
"reject",
|
| 101 |
+
"quit",
|
| 102 |
+
"do not",
|
| 103 |
+
"don't",
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
NEGATIVE_SIGNALS: dict[str, tuple[str, ...]] = {
|
| 107 |
"command": (
|
| 108 |
"no, continue without running it",
|
|
|
|
| 411 |
return output.splitlines() if rc == 0 else []
|
| 412 |
|
| 413 |
def confirm_selected_choice(self, pane_id: str) -> bool:
|
| 414 |
+
# Detection requires Codex's own confirmation/submission footer and a
|
| 415 |
+
# currently selected row that is not an obvious negative/cancel choice.
|
| 416 |
+
# Enter follows the rendered keymap, including persistent approval rows.
|
| 417 |
rc, _, _ = self.run("send-keys", "-t", pane_id, "Enter")
|
| 418 |
return rc == 0
|
| 419 |
|
|
|
|
| 536 |
return None
|
| 537 |
|
| 538 |
|
| 539 |
+
def _selected_option_row(lines: list[str], before: int) -> tuple[int, str] | None:
|
| 540 |
for idx in range(before - 1, -1, -1):
|
| 541 |
+
match = SELECTED_OPTION_RE.match(lines[idx])
|
| 542 |
if match:
|
| 543 |
return idx, match.group("label")
|
| 544 |
return None
|
| 545 |
|
| 546 |
|
| 547 |
+
def _selected_label_is_negative(label: str) -> bool:
|
| 548 |
+
folded = label.casefold().strip()
|
| 549 |
+
return any(folded.startswith(prefix) for prefix in NEGATIVE_LABEL_PREFIXES)
|
| 550 |
+
|
| 551 |
+
|
| 552 |
+
def _matching_confirmation_footer(lines: list[str]) -> tuple[int, int] | None:
|
| 553 |
+
for regex in (STANDARD_FOOTER_RE, MCP_FORM_FOOTER_RE, TRUST_FOOTER_RE):
|
| 554 |
+
footer = _matching_tail_span(lines, regex)
|
| 555 |
+
if footer is not None:
|
| 556 |
+
return footer
|
| 557 |
+
return None
|
| 558 |
+
|
| 559 |
+
|
| 560 |
def _contains_any(lines: list[str], values: tuple[str, ...]) -> bool:
|
| 561 |
# Joining with spaces lets fixed phrases survive terminal soft wrapping.
|
| 562 |
joined = " ".join(lines).casefold()
|
|
|
|
| 575 |
return None
|
| 576 |
footer_start, footer_end = footer
|
| 577 |
|
| 578 |
+
selected = _selected_option_row(lines, footer_start)
|
| 579 |
if selected is None:
|
| 580 |
return None
|
| 581 |
selected_row, selected_label = selected
|
|
|
|
| 615 |
return None
|
| 616 |
footer_start, footer_end = footer
|
| 617 |
|
| 618 |
+
selected = _selected_option_row(lines, footer_start)
|
| 619 |
if selected is None:
|
| 620 |
return None
|
| 621 |
selected_row, selected_label = selected
|
| 622 |
+
if _selected_label_is_negative(selected_label):
|
| 623 |
+
return None
|
| 624 |
if not selected_label.casefold().startswith("allow"):
|
| 625 |
return None
|
| 626 |
|
|
|
|
| 647 |
return None
|
| 648 |
footer_start, footer_end = footer
|
| 649 |
|
| 650 |
+
selected = _selected_option_row(lines, footer_start)
|
| 651 |
if selected is None:
|
| 652 |
return None
|
| 653 |
selected_row, label = selected
|
| 654 |
+
if _selected_label_is_negative(label):
|
| 655 |
+
return None
|
| 656 |
if not label.casefold().startswith("yes, continue"):
|
| 657 |
return None
|
| 658 |
|
|
|
|
| 664 |
return PromptCandidate(kind="trust_directory", signature=_candidate_signature("trust", overlay))
|
| 665 |
|
| 666 |
|
| 667 |
+
def _classify_generic_overlay(overlay: list[str]) -> str:
|
| 668 |
+
joined = " ".join(overlay).casefold()
|
| 669 |
+
if "enable full access?" in joined:
|
| 670 |
+
return "full_access"
|
| 671 |
+
if "do you trust the contents of this directory?" in joined:
|
| 672 |
+
return "trust_directory"
|
| 673 |
+
if "field 1/1" in joined and "run the tool and continue" in joined:
|
| 674 |
+
return "mcp_tool"
|
| 675 |
+
if "needs your approval" in joined:
|
| 676 |
+
return "mcp"
|
| 677 |
+
if re.search(r"\bquestions?\s+\d+/\d+\b", joined):
|
| 678 |
+
return "user_input"
|
| 679 |
+
return "generic_choice"
|
| 680 |
+
|
| 681 |
+
|
| 682 |
+
def detect_generic_confirmation(
|
| 683 |
+
lines: list[str],
|
| 684 |
+
config: Config,
|
| 685 |
+
) -> PromptCandidate | None:
|
| 686 |
+
footer = _matching_confirmation_footer(lines)
|
| 687 |
+
if footer is None:
|
| 688 |
+
return None
|
| 689 |
+
footer_start, footer_end = footer
|
| 690 |
+
|
| 691 |
+
selected = _selected_option_row(lines, footer_start)
|
| 692 |
+
if selected is None:
|
| 693 |
+
return None
|
| 694 |
+
selected_row, selected_label = selected
|
| 695 |
+
if _selected_label_is_negative(selected_label):
|
| 696 |
+
return None
|
| 697 |
+
|
| 698 |
+
overlay = lines[max(0, selected_row - MAX_OVERLAY_ROWS) : footer_end + 1]
|
| 699 |
+
kind = _classify_generic_overlay(overlay)
|
| 700 |
+
if kind in {"mcp", "mcp_tool"} and not config.approve_mcp:
|
| 701 |
+
return None
|
| 702 |
+
if kind == "trust_directory" and not config.auto_trust_directory:
|
| 703 |
+
return None
|
| 704 |
+
return PromptCandidate(kind=kind, signature=_candidate_signature(kind, overlay))
|
| 705 |
+
|
| 706 |
+
|
| 707 |
def detect_candidate(raw_lines: list[str], config: Config) -> PromptCandidate | None:
|
| 708 |
lines = [normalize_line(line) for line in raw_lines]
|
| 709 |
candidate = detect_standard_approval(lines, config.approve_mcp)
|
|
|
|
| 714 |
if candidate is not None:
|
| 715 |
return candidate
|
| 716 |
if config.auto_trust_directory:
|
| 717 |
+
candidate = detect_trust_directory(lines)
|
| 718 |
+
if candidate is not None:
|
| 719 |
+
return candidate
|
| 720 |
+
return detect_generic_confirmation(lines, config)
|
| 721 |
|
| 722 |
|
| 723 |
def _write_daemon_record(config: Config, record: DaemonRecord) -> None:
|
|
|
|
| 935 |
"--idle-exit-seconds",
|
| 936 |
str(config.idle_exit_seconds),
|
| 937 |
]
|
| 938 |
+
command.append("--approve-mcp" if config.approve_mcp else "--no-approve-mcp")
|
| 939 |
+
command.append(
|
| 940 |
+
"--auto-trust-directory"
|
| 941 |
+
if config.auto_trust_directory
|
| 942 |
+
else "--no-auto-trust-directory"
|
| 943 |
+
)
|
| 944 |
|
| 945 |
with open(os.devnull, "rb") as devnull_in, open(os.devnull, "ab") as devnull_out:
|
| 946 |
subprocess.Popen(
|
|
|
|
| 1290 |
)
|
| 1291 |
parser.add_argument(
|
| 1292 |
"--approve-mcp",
|
| 1293 |
+
dest="approve_mcp",
|
| 1294 |
action="store_true",
|
| 1295 |
+
default=True,
|
| 1296 |
+
help="auto-approve MCP/app tool calls that may have external side effects (default)",
|
| 1297 |
+
)
|
| 1298 |
+
parser.add_argument(
|
| 1299 |
+
"--no-approve-mcp",
|
| 1300 |
+
dest="approve_mcp",
|
| 1301 |
+
action="store_false",
|
| 1302 |
+
help="disable automatic approval of MCP/app tool calls",
|
| 1303 |
)
|
| 1304 |
parser.add_argument(
|
| 1305 |
"--auto-trust-directory",
|
| 1306 |
+
dest="auto_trust_directory",
|
| 1307 |
action="store_true",
|
| 1308 |
+
default=True,
|
| 1309 |
+
help="automatically trust a directory on Codex's first-run screen (default)",
|
| 1310 |
+
)
|
| 1311 |
+
parser.add_argument(
|
| 1312 |
+
"--no-auto-trust-directory",
|
| 1313 |
+
dest="auto_trust_directory",
|
| 1314 |
+
action="store_false",
|
| 1315 |
+
help="disable automatic directory trust",
|
| 1316 |
)
|
| 1317 |
parser.add_argument(
|
| 1318 |
"--detach",
|
test_codex_auto_run.py
CHANGED
|
@@ -135,8 +135,8 @@ def rows(value: str) -> list[str]:
|
|
| 135 |
def config(
|
| 136 |
runtime_dir: Path,
|
| 137 |
*,
|
| 138 |
-
approve_mcp: bool =
|
| 139 |
-
auto_trust_directory: bool =
|
| 140 |
stability_polls: int = 2,
|
| 141 |
) -> app.Config:
|
| 142 |
return app.Config(
|
|
@@ -175,44 +175,64 @@ class DetectorTests(unittest.TestCase):
|
|
| 175 |
self.assertIsNotNone(candidate)
|
| 176 |
self.assertEqual(kind, candidate.kind)
|
| 177 |
|
| 178 |
-
def
|
| 179 |
-
|
| 180 |
-
|
| 181 |
for fixture in (MCP_APPROVAL, MCP_TOOL_APPROVAL):
|
| 182 |
with self.subTest(fixture=fixture[:30]):
|
| 183 |
-
self.assertIsNone(app.detect_candidate(rows(fixture), safe))
|
| 184 |
candidate = app.detect_candidate(rows(fixture), enabled)
|
| 185 |
self.assertIsNotNone(candidate)
|
| 186 |
self.assertIn(candidate.kind, {"mcp", "mcp_tool"})
|
|
|
|
| 187 |
|
| 188 |
-
def
|
| 189 |
-
|
| 190 |
-
candidate = app.detect_candidate(
|
| 191 |
-
rows(TRUST_DIRECTORY),
|
| 192 |
-
config(self.runtime, auto_trust_directory=True),
|
| 193 |
-
)
|
| 194 |
self.assertIsNotNone(candidate)
|
| 195 |
self.assertEqual("trust_directory", candidate.kind)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
|
| 197 |
-
def
|
| 198 |
-
cfg = config(self.runtime
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
|
| 203 |
def test_historical_approval_text_above_composer_is_not_approved(self) -> None:
|
| 204 |
transcript = COMMAND_APPROVAL + "\n\n• Command completed\n\n› write a follow-up"
|
| 205 |
self.assertIsNone(app.detect_candidate(rows(transcript), config(self.runtime)))
|
| 206 |
|
| 207 |
-
def
|
| 208 |
-
|
| 209 |
"› 1. Yes, proceed (y)",
|
| 210 |
" 1. Yes, proceed (y)",
|
| 211 |
).replace(
|
| 212 |
" 2. Yes, and don't ask again",
|
| 213 |
"› 2. Yes, and don't ask again",
|
| 214 |
)
|
| 215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
|
| 217 |
def test_soft_wrapped_mcp_description_still_matches(self) -> None:
|
| 218 |
wrapped = MCP_TOOL_APPROVAL.replace(
|
|
@@ -284,6 +304,15 @@ class ArgumentTests(unittest.TestCase):
|
|
| 284 |
self.assertEqual("hello world", args.prompt)
|
| 285 |
self.assertEqual(["--model", "gpt-5.4"], args.codex_args)
|
| 286 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
def test_resume_modes_parse_without_changing_passthrough(self) -> None:
|
| 288 |
_, exact = app.parse_args(
|
| 289 |
["--resume", "019f-test", "-p", "continue", "--", "--search"]
|
|
|
|
| 135 |
def config(
|
| 136 |
runtime_dir: Path,
|
| 137 |
*,
|
| 138 |
+
approve_mcp: bool = True,
|
| 139 |
+
auto_trust_directory: bool = True,
|
| 140 |
stability_polls: int = 2,
|
| 141 |
) -> app.Config:
|
| 142 |
return app.Config(
|
|
|
|
| 175 |
self.assertIsNotNone(candidate)
|
| 176 |
self.assertEqual(kind, candidate.kind)
|
| 177 |
|
| 178 |
+
def test_mcp_defaults_to_enabled_but_can_be_disabled(self) -> None:
|
| 179 |
+
enabled = config(self.runtime)
|
| 180 |
+
disabled = config(self.runtime, approve_mcp=False)
|
| 181 |
for fixture in (MCP_APPROVAL, MCP_TOOL_APPROVAL):
|
| 182 |
with self.subTest(fixture=fixture[:30]):
|
|
|
|
| 183 |
candidate = app.detect_candidate(rows(fixture), enabled)
|
| 184 |
self.assertIsNotNone(candidate)
|
| 185 |
self.assertIn(candidate.kind, {"mcp", "mcp_tool"})
|
| 186 |
+
self.assertIsNone(app.detect_candidate(rows(fixture), disabled))
|
| 187 |
|
| 188 |
+
def test_directory_trust_defaults_to_enabled_but_can_be_disabled(self) -> None:
|
| 189 |
+
candidate = app.detect_candidate(rows(TRUST_DIRECTORY), config(self.runtime))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
self.assertIsNotNone(candidate)
|
| 191 |
self.assertEqual("trust_directory", candidate.kind)
|
| 192 |
+
self.assertIsNone(
|
| 193 |
+
app.detect_candidate(
|
| 194 |
+
rows(TRUST_DIRECTORY),
|
| 195 |
+
config(self.runtime, auto_trust_directory=False),
|
| 196 |
+
)
|
| 197 |
+
)
|
| 198 |
|
| 199 |
+
def test_generic_interactive_surfaces_are_approved(self) -> None:
|
| 200 |
+
cfg = config(self.runtime)
|
| 201 |
+
expected = {
|
| 202 |
+
FULL_ACCESS: "full_access",
|
| 203 |
+
REQUEST_USER_INPUT: "user_input",
|
| 204 |
+
}
|
| 205 |
+
for fixture, kind in expected.items():
|
| 206 |
+
with self.subTest(kind=kind):
|
| 207 |
+
candidate = app.detect_candidate(rows(fixture), cfg)
|
| 208 |
+
self.assertIsNotNone(candidate)
|
| 209 |
+
self.assertEqual(kind, candidate.kind)
|
| 210 |
|
| 211 |
def test_historical_approval_text_above_composer_is_not_approved(self) -> None:
|
| 212 |
transcript = COMMAND_APPROVAL + "\n\n• Command completed\n\n› write a follow-up"
|
| 213 |
self.assertIsNone(app.detect_candidate(rows(transcript), config(self.runtime)))
|
| 214 |
|
| 215 |
+
def test_persistent_positive_selection_is_approved(self) -> None:
|
| 216 |
+
persistent_selection = COMMAND_APPROVAL.replace(
|
| 217 |
"› 1. Yes, proceed (y)",
|
| 218 |
" 1. Yes, proceed (y)",
|
| 219 |
).replace(
|
| 220 |
" 2. Yes, and don't ask again",
|
| 221 |
"› 2. Yes, and don't ask again",
|
| 222 |
)
|
| 223 |
+
candidate = app.detect_candidate(rows(persistent_selection), config(self.runtime))
|
| 224 |
+
self.assertIsNotNone(candidate)
|
| 225 |
+
self.assertEqual("command", candidate.kind)
|
| 226 |
+
|
| 227 |
+
def test_negative_selection_is_not_approved(self) -> None:
|
| 228 |
+
negative_selection = COMMAND_APPROVAL.replace(
|
| 229 |
+
"› 1. Yes, proceed (y)",
|
| 230 |
+
" 1. Yes, proceed (y)",
|
| 231 |
+
).replace(
|
| 232 |
+
" 3. No, and tell Codex what to do differently",
|
| 233 |
+
"› 3. No, and tell Codex what to do differently",
|
| 234 |
+
)
|
| 235 |
+
self.assertIsNone(app.detect_candidate(rows(negative_selection), config(self.runtime)))
|
| 236 |
|
| 237 |
def test_soft_wrapped_mcp_description_still_matches(self) -> None:
|
| 238 |
wrapped = MCP_TOOL_APPROVAL.replace(
|
|
|
|
| 304 |
self.assertEqual("hello world", args.prompt)
|
| 305 |
self.assertEqual(["--model", "gpt-5.4"], args.codex_args)
|
| 306 |
|
| 307 |
+
def test_broad_auto_approval_defaults_can_be_disabled(self) -> None:
|
| 308 |
+
_, defaults = app.parse_args([])
|
| 309 |
+
self.assertTrue(defaults.approve_mcp)
|
| 310 |
+
self.assertTrue(defaults.auto_trust_directory)
|
| 311 |
+
|
| 312 |
+
_, disabled = app.parse_args(["--no-approve-mcp", "--no-auto-trust-directory"])
|
| 313 |
+
self.assertFalse(disabled.approve_mcp)
|
| 314 |
+
self.assertFalse(disabled.auto_trust_directory)
|
| 315 |
+
|
| 316 |
def test_resume_modes_parse_without_changing_passthrough(self) -> None:
|
| 317 |
_, exact = app.parse_args(
|
| 318 |
["--resume", "019f-test", "-p", "continue", "--", "--search"]
|