Skip to content

Add session_takeover tool for taking over recalled sessions in place#30

Merged
luckeyfaraday merged 2 commits into
mainfrom
feat/session-takeover
Jun 16, 2026
Merged

Add session_takeover tool for taking over recalled sessions in place#30
luckeyfaraday merged 2 commits into
mainfrom
feat/session-takeover

Conversation

@luckeyfaraday

Copy link
Copy Markdown
Owner

Problem

agent_takeover can only hand over sessions this Athena Code process spawned — it's gated on an in-memory handle in the agents map. A session found via session_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 / the athena.agent.takeover event 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.tsx already handles the event for any resumable session.

  • session/agent/session-takeover.ts (new) — pure, side-effect-free planSessionTakeover(): 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.tsindexedSessionWorkspace(): 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).
  • Supports all five agents including athena (resumed through process.execPath, which localAgentResumeCommand omits because athena isn't a spawnable subprocess agent).
  • The tool() wrapper in tool/agent-local.ts only emits / launches; registered as session_takeover in the overlay plugin tool map (plugin/athena.ts).

Design notes

  • No patch edit needed. Tool registration lives in the overlay's plugin/athena.ts (a full overlay file), not in a patch hunk — the patch only wires AthenaPlugin in as a builtin. patch-apply/patch-drift are unaffected.
  • Testability: the repo's tests target dependency-free lib files (the tool() wrappers import @opencode-ai/plugin/GlobalBus, absent standalone). The logic is therefore in the pure planner, whose in_app plan fields are the event payload verbatim; the wrapper is structurally identical to the proven AgentTakeoverTool for the emit/terminal mechanics.
  • No-TUI failure mode: kept the cheap "if nothing happens, run /find-sessions" guidance, matching 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).

bun test test  →  98 pass, 0 fail

🤖 Generated with Claude Code

luckeyfaraday and others added 2 commits June 16, 2026 18:38
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>
@luckeyfaraday luckeyfaraday merged commit c90cb2e into main Jun 16, 2026
2 checks passed
@luckeyfaraday luckeyfaraday deleted the feat/session-takeover branch June 16, 2026 22:36
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