Implement self-improvement flow: Codex sessions, worktree lifecycle, agent-branch enforcement - #584
Merged
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
elroy/utils/git.pywith source-tree detection helpers and theAGENT_BRANCH = "agent"constantagentbranch when running from source or an editable install (checked at session init and at Codex-session dispatch)dispatch_codex_session,resume_codex_session, andlist_codex_sessionstools — each Codex run gets an isolated git worktree on its own branch, Codex output is parsed from JSONL, and the session is persisted to SQLiteagentbranch, then the session worktree directory and branch are cleaned up (shutil.rmtree+git worktree prune+git branch -D)resume_codex_sessionrecreates the session branch from the agent HEAD when the original branch was already cleaned up, so Codex thread resumption still worksAppRestartRequest/os.execvpe) so Elroy can pull the latest agent branch and restart itself after a sessionTest plan
just test tests/tools/test_codex_sessions.py— all 5 tests passjust lint— cleanagentbranch 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