Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .codex/hooks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"description": "Generated by PyAutoMind/scripts/repos_sync.py. Review and trust the current hook definition with Codex /hooks before relying on it.",
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "python3 \"$(git rev-parse --show-toplevel)/bin/mind_commit_guard.py\"",
"statusMessage": "Checking shared PyAutoMind commit safety"
}
]
},
{
"matcher": "^(send_later|subscribe_pr_activity|ScheduleWakeup|CronCreate|RemoteTrigger|mcp__.*(send_later|subscribe_pr_activity).*)$",
"hooks": [
{
"type": "command",
"command": "bash \"$(git rev-parse --show-toplevel)/.claude/hooks/end-at-deliverable.sh\"",
"statusMessage": "Enforcing the end-at-deliverable policy"
}
]
}
]
}
}
7 changes: 7 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,10 @@ outlives the turn to wait for CI, a review or a merge: no `send_later`, no
armed hourly check-ins on 2026-08-31, and a mobile `/prm` re-armed a 60-minute
`send_later` hourly all night on 2026-09-03 with no task active, draining usage.
<!-- repos_sync:deliverable:end -->

Codex loads this repo's generated safety registrations from `.codex/hooks.json`
only after the project layer and exact current hook hash are reviewed and trusted
with `/hooks`; changed or untrusted hooks are skipped. The adapter registers the
shared-Mind commit guard and end-at-deliverable guard. It intentionally does not
copy the Claude remote-session Python `SessionStart` bootstrap; local Codex work
continues to source the workspace `activate.sh` normally.
4 changes: 2 additions & 2 deletions agents/conductors/clone/_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@
".github/*", # wiki-currency / citation workflows
"wiki/README.md", "wiki/project/*", # project wiki rules + profile template
"scripts/AGENTS.md", "scripts/CLAUDE.md", "scripts/README.md",
# Harness mirrors of the generic machinery (.claude/, .gemini/):
".claude/hooks/*", ".claude/settings.json", ".gemini/*",
# Harness mirrors of the generic machinery (.claude/, .codex/, .gemini/):
".claude/hooks/*", ".claude/settings.json", ".codex/hooks.json", ".gemini/*",
".claude/skills/_*", ".claude/skills/start-new-project*",
".claude/skills/contribute-upstream*",
]
Expand Down
7 changes: 6 additions & 1 deletion bin/mind_commit_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,14 @@ def main() -> None:
payload = json.loads(raw)
except (json.JSONDecodeError, ValueError):
_allow()
if not isinstance(payload, dict):
_allow()
if payload.get("tool_name") != "Bash":
_allow()
command = (payload.get("tool_input") or {}).get("command") or ""
tool_input = payload.get("tool_input") or {}
if not isinstance(tool_input, dict):
_allow()
command = tool_input.get("command") or ""
cwd = payload.get("cwd") or ""
try:
reason = check_command(command, cwd)
Expand Down
66 changes: 66 additions & 0 deletions tests/test_mind_commit_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,25 @@

from __future__ import annotations

import json
import subprocess
import sys
from pathlib import Path

import pytest

sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "bin"))
from mind_commit_guard import check_command # noqa: E402

MIND = "/home/jammy/Code/PyAutoLabs/PyAutoMind"
HOOK = Path(__file__).resolve().parents[1] / "bin" / "mind_commit_guard.py"


def run_codex_hook(payload):
body = payload if isinstance(payload, str) else json.dumps(payload)
return subprocess.run(
[sys.executable, str(HOOK)], input=body, capture_output=True, text=True
)


def test_bare_commit_in_mind_denied():
Expand Down Expand Up @@ -194,3 +206,57 @@ def test_simple_shapes_still_denied_after_v13(tmp_path):
(mind / "active").mkdir(parents=True)
assert check_command(f'cd {mind} && git commit -m "m"') is not None
assert check_command(f'git -C {mind} commit -m "m" -- active/') is not None


def test_codex_pre_tool_use_payload_denies_unsafe_mind_commit(tmp_path):
mind = tmp_path / "PyAutoMind"
mind.mkdir()
result = run_codex_hook({
"session_id": "codex-session",
"turn_id": "turn-1",
"tool_name": "Bash",
"tool_use_id": "call-1",
"cwd": str(mind),
"hook_event_name": "PreToolUse",
"tool_input": {"command": 'git commit -m "unsafe"'},
})
assert result.returncode == 0
decision = json.loads(result.stdout)["hookSpecificOutput"]
assert decision["hookEventName"] == "PreToolUse"
assert decision["permissionDecision"] == "deny"


def test_codex_pre_tool_use_payload_allows_safe_mind_commit(tmp_path):
mind = tmp_path / "PyAutoMind"
mind.mkdir()
(mind / "active.md").write_text("task\n")
result = run_codex_hook({
"turn_id": "turn-2",
"tool_name": "Bash",
"cwd": str(mind),
"hook_event_name": "PreToolUse",
"tool_input": {
"command": 'git commit -m "safe" -- active.md'
},
})
assert result.returncode == 0
assert result.stdout == ""


@pytest.mark.parametrize("payload", ["not-json", "[]", '{"tool_name":"Bash","tool_input":7}'])
def test_codex_malformed_payload_fails_open_without_crashing(payload):
result = run_codex_hook(payload)
assert result.returncode == 0
assert result.stdout == ""
assert result.stderr == ""


def test_codex_project_config_registers_mind_and_deliverable_guards():
root = Path(__file__).resolve().parents[1]
config = json.loads((root / ".codex" / "hooks.json").read_text())
groups = config["hooks"]["PreToolUse"]
commands = [group["hooks"][0]["command"] for group in groups]
assert [group["matcher"] for group in groups][0] == "Bash"
assert all("git rev-parse --show-toplevel" in command for command in commands)
assert any("bin/mind_commit_guard.py" in command for command in commands)
assert any("end-at-deliverable.sh" in command for command in commands)
Loading