Repository navigation
RFC: Import, adopt and observe conversations agent-manager did not start #818
Replies: 5 comments 1 reply
|
I would love this. I think it could help a lot of people who are trying to migrate to agent-manager, but have a lot of pre-existing sessions they don't want to recreate/handoff to a new session started from within agent-manager. Or maybe there's times where someone is running into an issue with agent-manager so they start a session outside of it directly, then the issue they were having gets fixed, or whatever and they want to move their session back into agent-manager. Separately, I think it might also make sense to start even simpler, perhaps just offering a way to import an existing session by it's agent type, name/id, rather than requiring a a scan. For example, I could imagine the |
|
@ribeirojose @chancez the import part went out in v0.45.0, in a different shape than the RFC. Adopt live and observe only are parked for now, since I'm not working on them myself. I'm open to a PR for either one if someone wants to pick it up. |
|
Useful RFC. LISA ships an observe-only layer over the same stores, so here is what we learned, keyed to your questions. Q2, process scan or files. Files only. We never enumerate processes. The one exception is the Claude pid registry below, and it serves a single decision. Q3, Claude status without a pane. One fact shaped our state machine: Claude Code does not log permission prompts to the transcript. On disk, a tool waiting for approval is indistinguishable from a tool that is still running. So we never report "waiting for permission" from staleness. The rules we settled on, after a false-alarm phase:
Because the file does not grow while a tool waits, Codex. Rollout tail only: an error flag gives OpenCode. We poll Aider. Q4, a mode column or a separate table. We kept one row type and put the difference in a per-integration visibility tier ( Source, if it helps as a reference: |
|
Refusing a resume while the pid is alive and not inferring permission waits from the transcript are both good points. Adopt live and observe only are still parked on my side, so I'll keep these notes here for whoever picks them up, and a PR is still welcome. |
|
For adopt-live, how would you distinguish the original process from a recycled PID? In the activity-monitoring work we're doing on Sinaps Studio at SinapsData, I'd keep 'a process exists' separate from 'this process owns this run'. A stale registry entry with a reused PID would make a useful negative case before enabling takeover. Could adoption report unknown ownership unless the process instance and conversation binding are verified? |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Why
A conversation opened outside the manager has no row. This holds on this machine and on an SSH host. The only ways in are
nandspawn. After #813, a remote host shows the rows that its own manager made. A user with weeks of Claude Code, Codex or opencode history starts with an empty list.Proposal
The manager gets three modes on one scanner and one command path. They build on #813 as separate PRs. The design is below.
agentsession.Listenumerates a store for a CLI the way thatSnapshotalready does for one cwd.agent-manager conversations --jsonlists the id, the cwd, the time and the title for each tool, and marks the ids that a row already tracks.agent-manager import --tool codex --id <id>creates a row and resumes it in a managed pane throughresume_by_id_command. That is the same path thatrevivetakes. Over SSH, both verbs run on the host, and the host owns the row.ipromotes the row to a pane.An Import screen opens on
i, and once on an empty first run. The screen groups the scan by host and repository, newest first. Selection is multi-select and never automatic. A second scan is idempotent.Coverage
Store adapters exist for codex, opencode, gemini, hermes, muse, antigravity, omp and command-code. Claude gets one over the transcript that the manager already reads. The pid-to-conversation link is certain for claude, hermes, muse, antigravity, omp and grok. For the other tools it is a marked guess.
pi and grok have
resume_by_id_commandbut no store adapter. Their formats are unverified here, and they resume by hand until an adapter lands. Gemini 0.36 writes JSON underchats/. The walker in the repository expects a JSONL header there.Questions
~/.claude/sessions/<pid>.json, an undocumented file, stay within the thin-wrapper rule?modecolumn onsessions, or a table of its own?ialone enough?Design
The design covers import, adoption and observation of agent conversations that were opened outside the manager, on this machine or on an SSH host. It builds on #813 (SSH connections) as separate PRs and changes nothing inside #813.
Studied on branch
feat/ssh-connections(merge basecf9ed0d). File:line references are to that tree. On-disk formats were read on this Mac with Claude Code 2.1.302, Codex 0.163.0, Gemini CLI 0.36.0, opencode 1.14.19 and pi installed. agy, hermes, muse, grok (store), omp and cmd come from the adapters in the repository only, and the text marks them so.The ask
That sentence holds three different things. They share a scanner and one command. They differ in what the manager can promise.
What exists
Every piece below is reused. Nothing here needs a new way to read a CLI.
Per-tool stores
internal/agentsessionalready enumerates a store for a directory.Snapshotwalks every conversation in a cwd with its activity time (capture.go:100). It does so throughcodexCandidates(:787),commandCodeCandidates(:421),queryHermesActivity(:334),opencodeSessionListJSON(:631),geminiCandidates(gemini.go:66),museCandidates(muse.go:37),antigravityCandidates(antigravity.go:34) andompCandidates(omp.go:72). Each one reads an id and a cwd from the header of the store. Dropping the cwd filter gives the whole scanner for eight tools.Claude transcripts
ClaudeTranscriptPathandClaudeTranscriptTail(claude.go:17,:55) read~/.claude/projects/<slug>/<id>.jsonlfor the last prompt and reply without a pane. Claude has nosession_store, because it takes--session-id(builtin.go:27).Resume by id
Every agent tool declares
resume_by_id_commandinbuiltin.go. The line numbers are: claude:28, opencode:94, codex:149, muse:198, grok:230and gemini:273. The rest are: antigravity:330, hermes:367, pi:421, omp:464and command-code:503.launch.ReviveCommand(launch.go:159) turns a storedAgentSessionIDinto that line.Lifecycle.Reviveruns the line throughlaunchExisting(lifecycle.go:257,:342). An import is a revive of a row that did not exist yet.The row
The row carries
sessions.agent_session_id,retired_agent_session_id,relaunch_snapshot,tmux_socketandopened_without_session(store/schema.go:41,:62,:117,:115,:135).TmuxSocketalready lets the poller leave alone a row whose pane it cannot see (poller.go:364-376). A row with no pane at all has the same shape.Live process to conversation
internal/conversationmaps a running agent to its conversation for the CLIs that report nothing. It uses open files for muse and antigravity (reader.go:47), andunified.jsonllines for grok that carrypidandsid(grok.go:27). It uses the per-tty crumb for hermes (hermes.go:19) and the per-tty breadcrumb for omp (omp.go:36). Today a launch keys these by the pid that the launch recorded (agent.go:24). The same readers answer for any pid.Remote
snapshot --jsonis the inventory that a connection reads (sessioncmd/snapshot.go:23,remote/operations.go:16). It is versioned and lives in memory only (ui/connection_state.go:19). New remote verbs follow the same table (docs/ssh-connections.mdProtocol).Coverage: what the store of each CLI allows
The table answers four questions. Which conversations exist on disk, and where? Does the store name the cwd? Does the CLI resume by one id from a shell? Does the store give status or the last exchange without a pane, and does it link a live pid to a conversation?
~/.claude/projects/<slug>/<uuid>.jsonl. The first line is amoderecord. cwd andsessionIdcome on the firstuserorsystementry.ai-titleandlast-promptrecords exist.sessions-index.json(version, entries[sessionId, projectPath, created, modified, firstPrompt, summary, messageCount, gitBranch]) is present in 4 of 407 project dirs here, so it is optionalcwd. The folder slug is lossy)claude --resume {id}(builtin.go:28). Whether it finds a transcript from another cwd is unverifiedClaudeTranscriptTail. Status:~/.claude/sessions/<pid>.jsoncarriesstatus(idle/busy),statusUpdatedAt,cwd,sessionId,kind(interactive/bg) andtmux(<session>:@w.%por null). Hooks cover only launches that we madetmuxnamesam_<id>for our rows~/.codex/sessions/YYYY/MM/DD/rollout-*.jsonl(capture.go:787). 0.163 also keepsstate_5.sqlitethreads(id, rollout_path, cwd, title, created_at, updated_at, source, archived and git_branch. 6375 rows here) andsession_index.jsonl(id, thread_name, updated_at)session_meta.payload.cwd,threads.cwd)codex resume {id}from any cwd (codex resume --help: the picker is cwd-filtered unless--all)thread_history_1.sqlitethread_turns.status/completed_atcan give turn state, but it is undocumentedopencode session list --format json(id, directory, updated) (capture.go:631).opencode.dbsessionhastitle,parent_idandtime_updateddirectory. The list is scoped to the calling dir, so the scanner runs it per project dir or reads the table)opencode --session {id}(builtin.go:94)updatedfrom the list~/.gemini/tmp/**/session-*.jsonlheader (sessionId,projectHash) (gemini.go:40). 0.36.0 on this Mac writes<hash>/chats/session-*.json(JSON: sessionId, projectHash, startTime, lastUpdated, messages).--list-sessionsexists, and it prompted for a login heregemini.go:31). A directory is found. A hash alone is not invertiblegemini --resume {id}(builtin.go:273)lastUpdatedsessionreport.go:wireGemini). None for a foreign processstate.dbsessions(id, cwd, started_at, last_activity_at, source) andmessages(capture.go:334)hermes --cli --resume {id}last_activity_at, newest message timestampterminal-sessions/tty-<name>(hermes.go:19). The tty of a foreign hermes maps to its conversation$XDG_DATA_HOME/muse/sessions/**/session.jsonl,runtime.session.metadatarecord (muse.go:72)workspace_root)muse resume {id}sessions/<id>.jsonor.session.lock(reader.go:70)conversation_summaries.db(conversation_id,workspace_uris,last_modified_time) (antigravity.go:34)--add-diragy --conversation {id}last_modified_timepresence/<id>.lock(reader.go:86)~/.omp/agent/sessions/<dir>/*.jsonl, headertype=sessionwithid,cwdandtimestamp(omp.go:125)omp --resume {id}omp.go:36)~/.commandcode/projects/**/*.jsonl, first linetype=sessionwithid/sessionIdandcwd(capture.go:458)cmd --session {id}--session-dirandPI_CODING_AGENT_SESSION_DIR(pi --help). The default dir and the header are unverified here (no sessions on this Mac). omp is a pi fork, so the omp header is the likely shapepi --session {id}(builtin.go:421)~/.grok/logs/unified.jsonlis read (grok.go:27). Where grok keeps conversations is not in the repo and not on this Macgrok --resume {id}(builtin.go:230)unified.jsonllines (ts,pid,sid) answer for any grok pidshell = true)Import and resume cover 9 of the 11 agent tools with code that exists. pi and grok need one adapter each, and their formats need a check upstream first. Adopt live has a certain answer for claude, hermes, muse, antigravity, omp and grok. For the other tools it is a process-scan guess. Observe-only status is an activity signal wherever a store exists. It is a real state only for claude.
Mode 1: import and resume
Scan
agentsession.List(sessionStore, since) ([]Conversation, error)returns{ID, Cwd, Updated, Title}for every conversation in the store that is newer thansince. The function isSnapshotwithout the cwd filter. The candidate walkers gaincwd == "", which means any directory. The opencode path reads the table that it already parses.Claude gets its first store adapter. The adapter walks
~/.claude/projects/*/and reads the head of each.jsonluntil the first entry that carriescwdandsessionId. The read is bounded to 64 KiB. The adapter skipsisSidechain, the<uuid>/subagent folders and.orphaned-*.jsonl, and it usessessions-index.jsonwhere that file exists.Titleis the title from the store where the store keeps one (claudeai-title, codexthreads.title, opencodetitle). The adapter cuts the title to one line and cleans it like a remote string (remote/sanitize.go). OtherwiseTitleis empty.Command
sessioncmd.Sessions.Conversations(sessionID, opts)runs the scan for every tool inbuiltinToolsthat has a store. The scan runs locally. The command marks each conversation:tracked: the id of a row, archived rows included, whoseagent_session_idorretired_agent_session_idis this conversation. A re-scan never offers a tracked conversation.live: the pid of a process on the conversation, where mode 2 can tell.cwd_exists: whether the directory still exists on this host.agent-manager conversations --json [--tool x] [--since 30d] [--limit n]is the CLI form. The envelope carriesversion, likesnapshot. The scan has a budget of 10 s. That budget is under the remotecallTimeoutof 15 s (remote/client.go:18). The scan returnstruncated: trueafter the budget.Import
sessioncmd.Lifecycle.Import(ImportRequest{Tool, AgentSessionID, Cwd, Name, Group, Pane})creates the row withAgentSessionIDset andStatusdead. Then it takes theRevivepath fromlifecycle.go:295:WithChoice,SnapshotRelaunchandlaunchExisting(ReviveCommand(tool, id)).Import sends no prompt, so it sends no rename directive. The name is the title, or
<tool>-<first 8 of id>. The manager refuses a tracked id and names the row that holds it. The UI offers revive or restore on that row instead. The manager refuses a missing cwd, unless the request asks for observe-only (mode 3).agent-manager import --json --tool codex --id <id> [--name] [--group] [--observe]and the MCP toolimport_sessioncall the same method.Remote
conversations --jsonandimport --jsonrun on the host over SSH, like every other verb (remote/operations.go). The host scans its own disk, creates its own row and resumes the row in its own pane. The nextsnapshotshows the row. The manager writes nothing remote to the local disk. The local side holds the scan result in memory next to the snapshot of the host. An outdated remote answersoutdated(host), the same way as forsnapshot.Mode 2: adopt live
The manager cannot move a process that it did not start into a managed pane. The sections below cover what the manager can detect and what the word adopt can mean.
Detect
conversationsgains a process pass. A process is a candidate when its binary matches a configured tool (execution/panetool.go:12,ToolBinaries). The pid must not be under a pane on the agentmgr socket. Interpreters are unnamed by design. The scan records the pid, the cwd (gopsutilCwd()) and the tty (sysstatsamplespsalready,trees_unix.go:81).The mapping to a conversation uses the readers that exist. They are
~/.claude/sessions/<pid>.jsonfor claude, the per-tty crumbs for hermes and omp, the open files for muse and antigravity, and the unified log for grok. codex, opencode, gemini, command-code and pi appear withconversation: unknown. For those tools the scan suggests the newest conversation in the cwd and marks the value as a suggestion.Adopt
Adopt is one of two explicit choices. It is never automatic.
adopt_on_exitset. The poller watches the pid. When the pid is gone, the manager revives the row in a managed pane withresume_by_id_command. That isReviveon a row that was never launched here, which is whatlaunchExistingdoes.SIGTERMto the process. It sendsSIGINTfirst for CLIs that trap it.killon the remote host does the same through the CLI of the host. The manager waits for the exit, then revives the row. The dialog names the pid, the tty and the terminal, because this step closes a window that the user watches somewhere else.The manager never resumes a conversation while a live process runs on it. Two processes that append to one transcript is the one failure that no tool documents a recovery for. The list tells a
tracked-but-dead row apart from aliveconversation, so the user sees why one offers import and the other does not.Mode 3: observe only, with no tmux
A row for a conversation that the manager cannot type into needs a store mark,
sessions.mode. The value''means managed and'observed'means observed. That mark is one migration entry.Status
Pane rules and hooks need a pane. The manager reads an observed row from the store on each poll.
statusfrom the live registry when a pid holds the conversation (busy→ working,idle→ idle). Otherwise idle.UpdatedinList. The value grew since the last poll → working. Otherwise idle.Waiting, finished and errored are not derived. Nothing on disk says that a dialog is open, and a turn end is known only where a store records one. An observed row raises no finished alert and no notification. The row shows "observed", the last activity ("2m ago") and, for claude, the last prompt and reply from
ClaudeTranscriptTail. Other tools show the id and the time.What degrades, and how the UI says it
Ten actions are refused with one sentence: attach, focus, preview, send, quick prompt, fork, review, restart, kill and the editor. The text is: "observed session: the manager has no pane on it; import it to get one". Archive, rename, move, delete and group placement work.
read/read_sessionreturn the tail of the transcript where one exists. Otherwise they return the refusal.The Rail paints a distinct mark beside the name (Advanced
◌, Compatibleo). The key legend names "import" on the row. Remote observed rows come throughsnapshotwithmodeset. The local side refuses the same actions that it refuses for every remote row, plus the pane actions.Promote
ion an observed row with no live process runsImport.Importflipsmodeto managed and revives the row. With a live process,ioffers the two choices from mode 2.Onboarding scan
ifrom the list opens it later. The screen runsConversationsfor this host. When connections exist, it runsconversations --jsonon each host in parallel on the effect lane. Each host fills in as it answers. An offline host shows the error from the connection. The manager imports nothing until the user confirms.git.Driver.RepoRoot,git/worktree.go:51, and the cwd itself when it is not a repo). Rows are newest first and show the tool, the title or id, the last activity, and a mark for tracked, live and missing-directory.--sincedefaults to 30 days. A key widens the range.spacetoggles a row.atoggles a repo group.enterimports the selection.Oimports as observed.escleaves. A click toggles a row, and the footer buttons import and close. Imported rows land in a group named after the basename of the repository root, when one exists. Otherwise they land in the root group. The group field in the screen overrides that choice and reuses the group picker from thenform.trackedrows are listed but not selectable, and the row says which session holds the conversation. A second scan after an import shows the row as tracked. The store columnagent_session_idis the only state, so a scan on another manager that shares the profile agrees.iafter that.Where it lives
The design builds on #813 as separate PRs. It touches
remoteonly to add two operations. It touchesui/connection_*only to route the scan to a host.internal/agentsession(Listper store,claude_store.gonew)internal/conversation(Foreign(tool) []Process)internal/sessioncmd(conversations.go,import.go)Conversations,Lifecycle.Import, the envelope and its version, the refusalsinternal/execution(pollobserved.go)mode = observedrows. Theadopt_on_exitwatchinternal/store(sessions.go,schema.go)modeandadopt_on_exitcolumns.TrackedConversations()internal/cli,internal/mcpserverconversations,import,list_conversations,import_session, withhostinternal/remote/operations.goConversations(host),Import(host, opts)internal/ui/import_*.go(importadded to the file-name map)The UI feature keeps a narrow host (8 methods,
model_host_test.go). It takes copied scan rows and hands back typed import requests that the root runs throughLifecycle.Import, the way that spawn goes throughLifecycle.Spawn. There is one command path. The screen,agent-manager importandimport_sessionall callLifecycle.Import. A remote import is the CLI of the host running the same.Thin wrapper and coverage
session_storecapturers as tool-specific detection that is "isolated; not a precedent".Listadds one function per store to adapters that already parse these headers. It adds nothing to tools that have no adapter. The claude scanner is new per-tool code, and it reads the same file thatClaudeTranscriptTailalready reads.resume_by_id_command. It adds no flag, chooses no model and writes no configuration. A tool whose resume moves fails the way that revive fails today, with the message from the CLI in the pane. Gemini--resumetakes an index orlatestin the 0.36 help text, and a UUID through the line in the repository.--sinceand the import group are per-scan choices on the screen, not stored preferences.agentsession(hermes_windows.go,antigravity_windows.go). The process pass needsforeign_unix.goandforeign_windows.go(proctreeon Windows). A remote host is POSIX by the rule in feat: manage sessions on other machines over SSH connections #813. WSL2 reads the Linux stores.Partial pieces that need a maintainer decision
resume_by_id_commandbut no store adapter. The evidence needed is the session directory and the header for pi, and the conversation store for grok. Until then the scan lists neither tool. The screen says so per tool, and both still revive by hand.busyvalue from claude on top is the one-tool extra.~/.claude/sessions/<pid>.json) is undocumented. It is the best live signal in the set. The fallback when it changes is the process scan that every tool gets.Risks
agentsession. Message content is read only for the tail of the observed row, on request, on the host that holds it. Over SSH the rule is the same. The remoteconversationsanswer carries no message text, and the manager writes nothing remote to the local store (feat: manage sessions on other machines over SSH connections #813). Titles are untrusted text and passcleanText.YYYY/MM/DD, claude file mtime). It stops at the budget and saystruncated. It runs on the effect lane, never onUpdate. The remote budget sits undercallTimeout.chats/, and the walker in the repository expects a JSONL header. The scan must hold on both, or say which one it skips. Codex now keeps a SQLite index. Rollouts still exist, so the walker stays the source and the index is an optional shortcut.trackedonly in its own store. This case is out of scope and documented.Delivery
Each PR ships on its own and leaves the manager usable without the next.
agentsession.List, the claude store adapter,sessioncmd.Conversations,agent-manager conversations --json,trackedandcwd_exists. No UI. Tests per store on fixtures. The Scope table of the PR covers every tool. pi and grok are the named gap with the issue linked.Lifecycle.Import,agent-manager import,import_session, the Import screen for this host with keyboard and mouse, the first-run offer, and the idempotent re-scan.conversationsandimportover SSH, hosts in the screen, the MCPhostargument. The snapshot version stays the same, because no row field is new yet.modecolumn, observed polling, the row mark and the refusals,snapshotwithmode(bumpSnapshotVersion), and promotion withi.Open questions for the maintainer
~/.claude/sessions/<pid>.jsonstay within the thin-wrapper rule? It is an undocumented file, and the best live status signal here.modecolumn onsessions, or a table of their own? A column keeps every list and snapshot path in one query. A table keeps the session loop of the poller untouched.ifrom the list enough? An empty list on the first run is also the moment when the user has the fewest expectations about what the manager reads.conversationsandimportas verbs,list_conversationsandimport_sessionas tools,ias the key. The list does not useitoday (docs/usage.mdkey table).All reactions