Skip to content

Implement self-improvement flow: Codex sessions, worktree lifecycle, agent-branch enforcement - #584

Merged
tombedor merged 1 commit into
mainfrom
self-improvement
May 20, 2026
Merged

Implement self-improvement flow: Codex sessions, worktree lifecycle, agent-branch enforcement#584
tombedor merged 1 commit into
mainfrom
self-improvement

Conversation

@tombedor

Copy link
Copy Markdown
Collaborator

Summary

  • Adds elroy/utils/git.py with source-tree detection helpers and the AGENT_BRANCH = "agent" constant
  • Enforces that Elroy must run on the agent branch when running from source or an editable install (checked at session init and at Codex-session dispatch)
  • Implements dispatch_codex_session, resume_codex_session, and list_codex_sessions tools — each Codex run gets an isolated git worktree on its own branch, Codex output is parsed from JSONL, and the session is persisted to SQLite
  • After a background Codex session completes, the session branch is merged (no-ff) into the agent branch, then the session worktree directory and branch are cleaned up (shutil.rmtree + git worktree prune + git branch -D)
  • resume_codex_session recreates the session branch from the agent HEAD when the original branch was already cleaned up, so Codex thread resumption still works
  • Adds app-restart plumbing (AppRestartRequest / os.execvpe) so Elroy can pull the latest agent branch and restart itself after a session

Test plan

  • just test tests/tools/test_codex_sessions.py — all 5 tests pass
  • just lint — clean
  • Manual: run elroy on the agent branch and dispatch a Codex session; verify the session worktree is removed and the agent branch contains the changes after the session completes

🤖 Generated with Claude Code

…ent-branch enforcement

- Add elroy/utils/git.py with source tree detection and AGENT_BRANCH constant
- Enforce agent-branch-only constraint in session init and codex session dispatch
- Implement dispatch/resume/list Codex session tools with isolated git worktrees
- Merge session branch into agent branch after each session completes
- Clean up session worktree and branch after successful merge (shutil.rmtree + git worktree prune)
- Recreate session branch from agent head when resuming a cleaned-up session
- Add app restart flow (AppRestartRequest / os.execvpe) for pull-and-restart after sessions
- Add docs/self_improvement diagram

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@tombedor
tombedor merged commit 0de770d into main May 20, 2026
1 check passed
@tombedor
tombedor deleted the self-improvement branch May 20, 2026 16:38
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.

1 participant