Resume in New Native Chat for OpenCode (#28072)

* feat(chat): Resume in New Native Chat for OpenCode terminal conversations

An OpenCode conversation started in the terminal now offers "Resume in New Native Chat" in its
Session History row menu and its tab's right-click menu, as Claude, Codex, Grok and OMP do: a new
OpenCode chat takes it over, showing its history and continuing it. OpenCode 2.x rows
(`opencode2`) and 1.x rows both open an OpenCode chat.

Two pieces kept OpenCode off the shared adoption path. Its account is a locator, not a folder, so
the transcript import now works over the account the chat pins, whatever its kind; the folder
agents wrap their lookups in directoryTranscriptImport, unchanged. Its conversations live in a
database, so the journal import reads the found database with the reader the OpenCode transcript
view already uses. OpenCode refuses to reopen a session from another folder, so the workspace rule
covers it too.

* test(chat): Pi is now the agent with no transcript import

* fix(chat): find an OpenCode 2.x terminal tab's Session History row

The pane reports `opencode` while Session History lists the conversation as `opencode2`, so the pane
header's and tab menu's Resume in New Native Chat found no row. Match by the chat agent that takes the
conversation over.

* Fix OpenCode chat adoption environment and pane eligibility

* test(chat): adapt parent adoption fixtures to account identities

* test: keep only the tests that pin user-visible behavior

* refactor(chat): map a Session History row to its chat agent where the chat starts

Both Resume in New Native Chat callers repeated the row-to-chat agent lookup. The launch now
takes the row agent and maps it once, so the Session History actions file stays unchanged.
This commit is contained in:
Brennan Benson
2026-10-14 00:25:08 -07:00
committed by GitHub
parent b5c568e9fb
commit 76d1c68ab5
28 changed files with 510 additions and 207 deletions
@@ -55,7 +55,7 @@ describe('structured OpenCode account binding', () => {
accounts.select(second)
const environment = environmentForStructuredOpenCodeAccountHome(binding, {
managedAccounts: accounts,
baseEnvironment: { PATH: '/bin' }
baseEnvironment: { PATH: '/bin', XDG_DATA_HOME: '/settings/data', OPENCODE_DB: 'work.db' }
})
expect(environment.XDG_DATA_HOME).toBe(`/profiles/${first}/data`)
expect(environment.OPENCODE_DB).toBe('opencode.db')
@@ -55,7 +55,7 @@ export function environmentForStructuredOpenCodeAccountHome(
binding: OpenCodeAgentSessionAccountHome,
input: {
managedAccounts: Pick<AccountReader, 'environmentForAccount' | 'restoreOriginalEnvironment'>
baseEnvironment: Record<string, string>
baseEnvironment: NodeJS.ProcessEnv
}
): Record<string, string> {
const environment = restoredEnvironment(input.baseEnvironment, input.managedAccounts)
@@ -0,0 +1,39 @@
import { existsSync } from 'node:fs'
import { homedir } from 'node:os'
import { isLegacyAgentSessionAccountHome } from '../../shared/agent-session-account-home'
import { getManagedDataAccountService } from '../managed-data-accounts/service'
import type { StructuredAgentTranscriptImport } from '../native-chat/structured-agent-cli-conversations'
import { resolveOpenCodeDatabasePath } from './opencode-data-directory'
import { environmentForStructuredOpenCodeAccountHome } from './opencode-structured-account-home'
export const OPENCODE_TRANSCRIPT_IMPORT: StructuredAgentTranscriptImport = {
// The selected account, then the unmanaged environment this chat would launch with.
accountHomeCandidates: ({ selectedAccountHome }) => [
selectedAccountHome,
{ kind: 'opencode', locator: { kind: 'unmanaged' } }
],
// The database the account's OpenCode opens, which is the only one its chat can load from.
findTranscript: async ({ providerSessionId, accountHome, launchEnv }) => {
if (isLegacyAgentSessionAccountHome(accountHome)) {
return null
}
const env = environmentForStructuredOpenCodeAccountHome(accountHome, {
managedAccounts: getManagedDataAccountService(),
baseEnvironment: launchEnv
})
const dbPath = resolveOpenCodeDatabasePath(
env,
(process.platform === 'win32' ? env.USERPROFILE : env.HOME) || homedir()
)
if (!dbPath || !existsSync(dbPath)) {
return null
}
const { readOpenCodeTranscriptSignalViaWorker } =
await import('../ai-vault/session-scanner-opencode-sqlite-worker-spawn')
const signal = await readOpenCodeTranscriptSignalViaWorker({
dbPath,
sessionId: providerSessionId
})
return signal ? dbPath : null
}
}