Skip to content

Add codex adapter - #16

Merged
codejunkie99 merged 3 commits into
codejunkie99:masterfrom
hovhannest:codex-adapter
Apr 23, 2026
Merged

codejunkie99 merged 3 commits into
codejunkie99:masterfrom
hovhannest:codex-adapter

Conversation

@hovhannest

Copy link
Copy Markdown
Contributor

Summary

Add a Codex adapter for agentic-stack so the portable .agent/ brain can be used from Codex with the same lightweight
integration style as the existing harness adapters.

What changed

  • added adapters/codex/AGENTS.md
  • added adapters/codex/README.md
  • added docs/per-harness/codex.md
  • wired codex into install.sh and install.ps1
  • updated README.md, docs/getting-started.md, and docs/architecture.md to list Codex as a supported harness

Adapter behavior

  • installs a root AGENTS.md for Codex if one does not already exist
  • mirrors .agent/skills/ into .agents/skills/ so Codex can see the portable skill tree
  • reuses the existing .agent/ memory, tools, and permissions model
  • keeps hooks out by default and relies on manual recall.py / memory_reflect.py, matching the lighter integration
    style used for non-hook harnesses

Notes

  • if AGENTS.md already exists, the installer leaves it in place so Codex can coexist with pi/hermes/opencode-style
    setups
  • on filesystems without symlink support, the installer falls back to copying or merging the skills directory
  • Codex hooks are intentionally not installed here because the stable cross-platform path is instruction + skills +
    manual memory tooling

Validation

  • verified installer wiring for both install.sh and install.ps1
  • validated the Windows install path in a temp project
  • confirmed the adapter creates:
    • AGENTS.md
    • .agent/
    • .agents/skills/
    • onboarded PREFERENCES.md and feature config

Shorter version if you want a tighter PR body:

Summary

Add a Codex adapter for agentic-stack.

What changed

  • add adapters/codex/AGENTS.md
  • add adapters/codex/README.md
  • add docs/per-harness/codex.md
  • wire codex into install.sh and install.ps1
  • update README/docs to list Codex as a supported harness

Notes

The adapter uses root AGENTS.md plus .agents/skills/ to expose the portable .agent/ brain to Codex. It
intentionally does not install hooks and instead follows the existing manual recall.py / memory_reflect.py pattern
used by lighter integrations.

hovhannest and others added 2 commits April 22, 2026 23:28
Cross-model review (Claude + Codex adversarial) flagged real gaps in
the codex adapter. Fixes here:

1. AGENTS.md collision was "skip if exists" — silent-success when the
   user already has an Aider/Amp/Cline/old-codex AGENTS.md. Mirror the
   openclaw pattern: if existing AGENTS.md references .agent/, leave
   alone; if not, print a mergeable snippet and don't overwrite. Same
   change in install.sh and install.ps1.

2. .agents/skills/ sync was destructive (cp -R overlay) and non-healing
   (deleted skills lingered forever). Switch to rsync --delete when
   available, fall back to rm+cp, so the .agents/skills mirror stays in
   sync with the .agent/skills source of truth.

3. install.ps1 used `Test-Path` then `Copy-Item ... -Force`, which on
   PowerShell 5.1 (Windows default) writes through a symlink into the
   target — silently mutating .agent/skills via the link. Detect
   ReparsePoint via Get-Item.Attributes BEFORE Remove-Item; use
   .NET Directory.Delete($path, false) on links so only the link is
   removed, never the target.

4. adapters/codex/AGENTS.md: add a Windows note about python vs python3
   (stock Windows only ships `python` on PATH).

5. Citation: link OpenAI's https://developers.openai.com/codex/skills
   in the adapter docs to make the .agents/skills/ contract explicit.

Smoke tested: fresh install, re-run with real-dir mirror + orphan
skill (orphan deleted via rsync), AGENTS.md collision branches both
covered.
@codejunkie99

Copy link
Copy Markdown
Owner

Hey @hovhannest — ran a cross-model review (Claude + Codex adversarial) on this and found a few things worth addressing. Rather than bounce a review back at you, I pushed a follow-up commit (2e0a707) onto this branch via maintainer-edit so the PR stays in one thread. Feel free to rework, amend, or push back on any of it.

What changed in the follow-up:

  1. AGENTS.md collision was "skip if exists" — silent-success when the user already has an Aider/Amp/Cline/old-codex AGENTS.md. Switched to the openclaw pattern (install.sh master): if existing AGENTS.md references .agent/, leave alone; if not, print a mergeable snippet without overwriting. Mirrored in install.ps1.
  2. .agents/skills/ sync was destructive (cp -R overlay) and non-healing (deleted skills lingered forever). Switched to rsync --delete when available, rm+cp fallback.
  3. install.ps1 symlink detection: Test-Path + Copy-Item -Force can write through a symlink on PS 5.1, mutating .agent/skills/ via the link. Added ReparsePoint detection via Get-Item.Attributes before any Remove-Item; use [System.IO.Directory]::Delete($path, $false) on links.
  4. adapters/codex/AGENTS.md: added a Windows note about python vs python3 (stock Windows only ships python on PATH), and linked the OpenAI Codex skills doc to make the .agents/skills/ contract explicit.

One clarification: the initial Claude review flagged .agents/skills/ as potentially unsupported — that was wrong. Web-searched OpenAI's docs and confirmed it's a real feature. Codex's framing was right (destructive sync, not wrong directory), fix is scoped to that.

Tested: fresh install, re-run with real-dir mirror + orphan skill (orphan deleted via rsync), AGENTS.md collision branches both covered.

Full review notes on request.

# Conflicts:
#	README.md
#	install.ps1
codejunkie99 pushed a commit to hovhannest/agentic-stack that referenced this pull request Apr 23, 2026
Two pre-existing infrastructure bugs flagged during the PR codejunkie99#17 cross-model
review, fixed here against master because they predate that PR and
affect every harness.

## 1. Concurrent writes to AGENT_LEARNINGS.jsonl

post_execution.py and on_failure.py both did plain `open(EPISODIC, "a")`
→ `f.write(json.dumps(entry) + "\n")`. POSIX O_APPEND makes single
`write(2)` calls atomic only up to PIPE_BUF (4 KB on Linux/macOS).

In practice most entries stay under that ceiling and the unlocked code
never corrupts, but the `reflection` field is uncapped in log_execution
and can easily exceed 4 KB on high-importance failure logs. Every
downstream reader (auto_dream.py, cluster.py, context_budget.py,
show.py) skips `json.JSONDecodeError` lines silently — so one
over-PIPE_BUF interleave = one episodic entry gone with no signal.

Fix: new `_episodic_io.append_jsonl()` helper that opens in append-
binary mode (no Python text-mode buffering quirks) and wraps the
write in `fcntl.flock(LOCK_EX)`. Shared by both writers. On platforms
without fcntl (native Windows Python) behavior falls back to the
pre-fix unlocked append; WSL, git-bash/Cygwin, macOS, Linux all have
fcntl.

Verified: 40 concurrent writers × 500 entries × 2 KB reflection each
→ 20,000 parseable lines, zero corruption.

## 2. pi install.sh silently leaves stale skills on re-install

`ln -sfn src dest` where `dest` is a REAL directory (e.g. from an
earlier copy-fallback install) silently creates `dest/<basename-of-src>`
INSIDE the dir and exits 0. The existing `if ln -sfn; then` branch
took the success path, the `rm -rf + cp` fallback never ran, and
orphans stuck around forever. Verified on macOS, confirmed the
symlink-inside-dir behavior.

Fix: check `-L` (symlink) and `-d` (real dir) explicitly before
calling `ln -sfn`, mirror the pattern used by the codex adapter
(PR codejunkie99#16 follow-up). Existing symlink → cheap repoint. Real directory
→ rsync --delete when available, rm+cp otherwise. Non-existent →
symlink or copy fallback. Same three-branch shape, no more silent
wrong behavior.

Verified: re-install after orphan-skill was added to a real-dir
`.pi/skills` → rsync --delete removes the orphan.
@codejunkie99
codejunkie99 merged commit 5113298 into codejunkie99:master Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants