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
19 changes: 18 additions & 1 deletion src/agent_learner/adapters/codex.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import shlex
from pathlib import Path

from .common import append_lines_if_missing, ensure_dir, merge_json_file, write_text
from .common import append_lines_if_missing, ensure_dir, merge_json_file, upsert_hook, write_text
from agent_learner.core.storage import migrate_legacy_learning_assets


Expand Down Expand Up @@ -336,3 +336,20 @@ def install_codex_adapter_with_scope(target_root: Path, *, scope: str = "project
if scope == "project":
written.extend(migrate_legacy_learning_assets(target_root))
return written


# ---------------------------------------------------------------------------
# Phase 2: lightweight hook installer (mirrors claude adapter pattern)
# ---------------------------------------------------------------------------

_CODEX_HOOK_COMMAND = "agent-learner process --adapter codex --auto"


def install_codex_hooks(project_root: Path, *, scope: str = "project") -> Path:
"""Install agent-learner Stop hook into .codex/hooks.json.

Idempotent: updates existing agent-learner hook if present.
Preserves other Stop hooks.
"""
settings_path = project_root / ".codex" / "hooks.json"
return upsert_hook(settings_path, "Stop", _CODEX_HOOK_COMMAND, hook_format="codex")
4 changes: 4 additions & 0 deletions src/agent_learner/adapters/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ def _make_hook_entry(command: str, *, hook_format: str) -> dict:
"matcher": ".*",
"hooks": [{"type": "command", "command": command}],
}
if hook_format == "codex":
return {
"hooks": [{"type": "command", "command": command}],
}
return {"command": command}


Expand Down
Loading