Skip to content

Add /merge command for session context import - #1

Draft
RandyHaddad wants to merge 12 commits into
mainfrom
codex/merge-command
Draft

RandyHaddad wants to merge 12 commits into
mainfrom
codex/merge-command

Conversation

@RandyHaddad

@RandyHaddad RandyHaddad commented Jun 7, 2026 •

Copy link
Copy Markdown
Owner

For Humans

This PR adds /merge: a way to bring the working state from another Codex session back into the current session.

Codex already lets a user branch work through forked, resumed, and parallel sessions. The missing piece is the return path. When a side session has done real work, the main session has no structured way to absorb what happened there without a manual handoff.

/merge user flow

/merge implementation

Generated by Codex using GPT Image.

The command keeps the user in the current session, imports another session as background context, leaves the source session untouched, and records the import as a visible merge history item. It does not merge Git branches, files, or worktrees.

For Agents

Summary:

  • Adds a first-class /merge slash command for importing source-session context into the current target session.
  • Reuses the remote compact runtime with merge-specific instructions.
  • Stores the imported state as a distinct MergedItem checkpoint with provenance and visible history markers.
  • Leaves the source session untouched.
  • Keeps Git/file/worktree merging out of scope.

What changed:

  • Adds merge protocol types and rollout reconstruction support.
  • Adds merge import-state helpers and merge task wiring.
  • Adds app-server route and TUI slash command / resume-style picker.
  • Adds pre/post merge hooks and generated hook schemas.
  • Adds visible merge history markers in resumed/debugged transcripts.

Verification:

  • CARGO_NET_GIT_FETCH_WITH_CLI=true cargo check -p codex-protocol -p codex-config -p codex-hooks -p codex-core -p codex-app-server-protocol -p codex-app-server -p codex-tui -p codex-analytics
  • CARGO_NET_GIT_FETCH_WITH_CLI=true cargo test -p codex-core merge::tests
  • CARGO_NET_GIT_FETCH_WITH_CLI=true cargo test -p codex-hooks generated_hook_schemas_match_fixtures
  • CARGO_NET_GIT_FETCH_WITH_CLI=true cargo test -p codex-hooks loads_generated_hook_schemas
  • CARGO_NET_GIT_FETCH_WITH_CLI=true cargo test -p codex-tui slash_merge
  • CARGO_NET_GIT_FETCH_WITH_CLI=true cargo test -p codex-app-server-protocol builds_visible_marker_from_merged_item

Review note:

This is an internal fork PR for Randy/Elie review before opening anything against openai/codex.

@RandyHaddad
RandyHaddad force-pushed the codex/merge-command branch from 2c5320e to 170bbe4 Compare June 7, 2026 17:47
fabianVagnoni and others added 4 commits June 18, 2026 18:22
Catches the branch up to openai/codex (was 387 commits behind).
Resolved 5 conflicts:
- core/src/lib.rs: keep both `mod merge;` and the BackgroundTerminalInfo re-export
- rollout/src/recorder.rs: adopt upstream's generic `items.push(item)` (handles Merged)
- state/src/extract.rs + thread-store/.../thread_metadata_sync.rs: handle both
  RolloutItem::Merged (this PR) and RolloutItem::InterAgentCommunication (upstream)
- tui slash_commands test: keep both /merge and /import test cases

Cross-variant exhaustiveness compile fixes to follow in a separate commit.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Compile fixes after merging 387 commits of openai/codex into the branch.
All mirror how the current compact code does it:
- ResponseItem::Message and ::Compaction gained id/metadata fields
- TurnContext.features -> turn_context.config.features
- ResponseItem::CompactionTrigger is now a struct variant {id, metadata}
- Prompt.personality field removed
- run_remote_compaction_request_v2 now takes &CodexResponsesMetadata
- build_v2_compacted_history now returns (Vec<ResponseItem>, usize)
- dropped deleted calls (start_next_auto_compact_window, advance_window_generation)
- added Merged / MergedContext match arms in upstream memories + tui code

Verified: cargo check --workspace --all-targets --keep-going passes (exit 0).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
- ISSUE-1: box RawPluginManifestHooks::Inline(Box<HooksFile>) to clear
  clippy large_enum_variant (warnings are -D in CI)
- ISSUE-2/3: regenerate config + app-server schema/TS fixtures for the merge
  types (ThreadMergeStart, MergedContext, PreMerge/PostMerge, Merge turn kind)
- ISSUE-4: update TUI hooks-browser + hooks-popup snapshots (PreMerge/PostMerge)
- command_popup test: /merge now matches the "/m" prefix; add it to the
  expected presentation order (model, memories, merge, mention, mcp)

Co-Authored-By: Claude Opus 4.8 <[email protected]>
fabianVagnoni pushed a commit that referenced this pull request Jun 18, 2026
## Stack

1. [1 of 3] Support long raw TUI goal objectives - openai#27508
2. [2 of 3] Support long pasted text in TUI goals - openai#27509
3. **[3 of 3] Support images in TUI goals** - this PR

## Why

The first two PRs make goal definitions resilient to long text, but
`/goal` still dropped image inputs from the composer. That meant a user
could attach images while defining a goal and the resulting goal
continuation would not have any useful reference to those images.

Goal state still persists only objective text, so image inputs need to
become paths or URLs that the agent can read later.

## What Changed

- Extends TUI `GoalDraft` with local image attachments and remote image
URLs.
- Copies local goal images through the app-server filesystem layer into
the managed goal attachment directory, then rewrites active image
placeholders to file references.
- Appends unplaced local images and remote image URLs to the objective
as referenced image files or URLs.
- Preserves goal image metadata through live `/goal` submission and
queued `/goal` dispatch.

## Verification

- Added goal materialization coverage for local image files and remote
image URLs.
- Added/updated TUI slash-command coverage showing `/goal` drafts
include attached images instead of dropping them.

## Manual Testing

- Attached an image by bracketed-pasting its local path into a live
`/goal` composer. The `[Image #1]` placeholder became a server-host
`image-1.png` reference, copied bytes matched exactly, and no attachment
was written under the TUI's local home.
- Deleted an image placeholder before submitting a small goal and
verified no image was copied.
- Attached PNG and JPEG files to the same goal. Placeholder order was
preserved as `image-1.png` and `image-2.jpg`, and both remote copies
matched their source bytes.
- Tried extensionless, malformed-extension, and
extension/content-mismatched paths; the composer rejected them as image
attachments before goal dispatch rather than creating misleading managed
image files.
- Combined a local image, a large pasted block, and enough raw text to
exceed 4,000 characters. The remote attachment directory contained the
image, paste sidecar, and `goal-objective.md`; all embedded references
used server-host paths and both payloads matched their sources.
- Submitted an image replacement while a goal was active, verified no
image was copied before confirmation, then canceled and confirmed the
attachment count was unchanged.
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