Add session_takeover tool for taking over recalled sessions in place#30
Merged
Conversation
agent_takeover can only hand over sessions this process spawned: it is
gated on an in-memory handle in the agents map. A session found via
session_recall has no handle, so the model had no in-place takeover tool
for historical sessions and fell back to spawning a new terminal window.
The in-place machinery (execResume / resumeCommand / the
athena.agent.takeover event the TUI listens for) was already fully
general, taking a plain { agent, sessionId, workspace }. session_takeover
bridges recall to that same event for any indexed session, no live handle
required.
- session/agent/session-takeover.ts: pure planSessionTakeover() validates
the recalled { agent, session_id } against the cross-agent index, then
builds an in-app handover or a visible-terminal resume. Keeping it
side-effect-free lets it be unit-tested without the plugin/bus glue.
- sessionindex.ts: indexedSessionWorkspace() — a stale id yields a clean
not-found error instead of a silently dropped handover, and the
session's own indexed workspace is used so it resumes in its own repo.
- Supports all five agents including athena (resumed through
process.execPath, which localAgentResumeCommand omits).
- The tool() wrapper in tool/agent-local.ts only emits / launches;
registered as session_takeover in the overlay plugin tool map.
Co-Authored-By: Claude Opus 4.8 <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.
Problem
agent_takeovercan only hand over sessions this Athena Code process spawned — it's gated on an in-memory handle in the agents map. A session found viasession_recall(or/find-sessions) has no handle, so the model had no in-place takeover tool for historical sessions and fell back to spawning a new terminal window. The in-place machinery (execResume/resumeCommand/ theathena.agent.takeoverevent the TUI already listens for) was the whole time one event-emit away — it takes a plain{ agent, sessionId, workspace }, not a live handle.What this adds
A sibling tool,
session_takeover, that bridges recall → the existing takeover event for any indexed session, no live handle required. No TUI changes —athena-takeover.tsxalready handles the event for any resumable session.session/agent/session-takeover.ts(new) — pure, side-effect-freeplanSessionTakeover(): validates the recalled{ agent, session_id }against the cross-agent index, resolves the workspace, and builds either an in-app handover or a visible-terminal resume.sessionindex.ts—indexedSessionWorkspace(): a stale id from recall now produces a clean not-found error instead of a silently dropped handover, and the session's own indexed workspace is used so it resumes in its own repo (better than defaulting to the current worktree for cross-workspace sessions).process.execPath, whichlocalAgentResumeCommandomits because athena isn't a spawnable subprocess agent).tool()wrapper intool/agent-local.tsonly emits / launches; registered assession_takeoverin the overlay plugin tool map (plugin/athena.ts).Design notes
plugin/athena.ts(a full overlay file), not in a patch hunk — the patch only wiresAthenaPluginin as a builtin.patch-apply/patch-driftare unaffected.tool()wrappers import@opencode-ai/plugin/GlobalBus, absent standalone). The logic is therefore in the pure planner, whosein_appplan fields are the event payload verbatim; the wrapper is structurally identical to the provenAgentTakeoverToolfor the emit/terminal mechanics.agent_takeover(no ack handshake).Tests
Added 4 cases to
test/agent-local.test.ts(in-app payload, terminal mode for athena + claude, explicit workspace override, rejection of unknown agents / stale ids).🤖 Generated with Claude Code