Handoff: support large sessions and fix menu input focus#1
Draft
pirate wants to merge 2 commits into
Draft
Conversation
Pass --max-context-tokens / --max-tool-output to casr so oversized source sessions (which the source agent has already compacted many times) are trimmed to the target's size/context limits instead of failing the handoff. Env-overridable via CASR_MAX_CONTEXT_TOKENS / CASR_MAX_TOOL_OUTPUT; older casr builds without these flags exit non-zero and fall through to the existing prompt-handoff path.
async_split_pane created the new pane but left keyboard focus on the original session, so the "Choose target agent" prompt (which blocks on read) never saw the user's keystrokes and appeared frozen. Activate the child session after splitting, for both fork and handoff.
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.
What
Two fixes to the
handoff_agent_here(⌘⇧G) flow:Why
1. Large sessions
A long-running source session (e.g. Codex) can be hundreds of MB on disk while its live context is only a few MB — it compacts repeatedly as it runs. The handoff shells out to
casrto convert the source session into the target agent's native format; replaying the entire on-disk archive blows the target's resume size / context-window limits and the handoff fails.This passes
--max-context-tokensand--max-tool-outputtocasr(which honors the source's compaction and trims to those caps), so the new agent ends up with roughly the same context the source agent actually had — not the full archive. Both are env-overridable (CASR_MAX_CONTEXT_TOKENS,CASR_MAX_TOOL_OUTPUT), and oldercasrbuilds that don't understand the flags simply exit non-zero and fall through to the existing prompt-handoff fallback.2. Menu input focus
async_split_pane()creates the new pane but leaves keyboard focus on the original session. The handoff launcher prints a "Choose target agent" menu and blocks onread, so with focus still on the original pane the menu looked frozen — keystrokes went to the wrong pane. Callingasync_activate()on the child after the split fixes it. (The ⌘⇧F fork path auto-runs its command and needs no input, which is why only the handoff menu was affected; activation is added to both for consistency.)Testing locally
fork_agent_here.pyinto your iTerm AutoLaunch dir (~/.config/iterm2/AppSupport/Scripts/AutoLaunch/), then restart iTerm (or relaunch the script) so the daemon reloads.casrand resumes, even for a multi-hundred-MB source session that previously failed the handoff.export CASR_MAX_CONTEXT_TOKENS=120000before launching.The budgeting needs a
casrbuild that understands--max-context-tokens/--max-tool-output(companion change); without it the handoff still works via the prompt-handoff fallback.Summary by cubic
Make the ⌘⇧G handoff robust for large sessions and fix input focus so the target-agent menu accepts keystrokes. Context is trimmed during
casrresume, and the new split pane is activated.casr--max-context-tokens/--max-tool-output(env:CASR_MAX_CONTEXT_TOKENS,CASR_MAX_TOOL_OUTPUT); oldercasrfalls back to prompt path.Written for commit e5a3149. Summary will update on new commits.