mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
fix: protect existing workspace state during host import
This commit is contained in:
1 parent
0a37fd14a3
commit
9669570e97
6 files changed
+185
-48
No files matched your search
@@ -25,7 +25,7 @@ import { DEFAULT_AGENTS_MD } from '../constants'
|
||||
import { validateSSHPrivateKey } from '../utils/ssh-validation'
|
||||
import { encryptSecret } from '../utils/crypto'
|
||||
import { compareVersions, isValidVersion } from '../utils/version-utils'
|
||||
import { getImportedSessionDirectories, getOpenCodeImportStatus, syncOpenCodeImport } from '../services/opencode-import'
|
||||
import { getImportedSessionDirectories, getOpenCodeImportStatus, OpenCodeImportProtectionError, syncOpenCodeImport } from '../services/opencode-import'
|
||||
import { relinkReposFromSessionDirectories } from '../services/repo'
|
||||
import {
|
||||
listManagedSkills,
|
||||
@@ -459,7 +459,8 @@ export function createSettingsRoutes(db: Database, gitAuthService: GitAuthServic
|
||||
const result = await syncOpenCodeImport({
|
||||
db,
|
||||
userId,
|
||||
overwriteState: body.overwriteState ?? true,
|
||||
overwriteState: body.overwriteState ?? false,
|
||||
protectExistingState: true,
|
||||
})
|
||||
|
||||
if (!result.configImported && !result.stateImported) {
|
||||
@@ -499,6 +500,13 @@ export function createSettingsRoutes(db: Database, gitAuthService: GitAuthServic
|
||||
if (error instanceof z.ZodError) {
|
||||
return c.json({ error: 'Invalid OpenCode import request', details: error.issues }, 400)
|
||||
}
|
||||
if (error instanceof OpenCodeImportProtectionError) {
|
||||
return c.json({
|
||||
error: error.message,
|
||||
code: error.code,
|
||||
detail: error.detail,
|
||||
}, 409)
|
||||
}
|
||||
return c.json({
|
||||
error: 'Failed to import existing OpenCode host data',
|
||||
details: error instanceof Error ? error.message : 'Unknown error'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import os from 'os'
|
||||
import path from 'path'
|
||||
import { cp, readdir, rm } from 'fs/promises'
|
||||
import { cp, mkdtemp, readdir, rename, rm } from 'fs/promises'
|
||||
import { Database as SQLiteDatabase, type Database } from 'bun:sqlite'
|
||||
import { OpenCodeConfigSchema } from '@opencode-manager/shared/schemas'
|
||||
import { getOpenCodeConfigFilePath, getWorkspacePath } from '@opencode-manager/shared/config/env'
|
||||
@@ -22,6 +22,7 @@ export interface SyncOpenCodeImportOptions {
|
||||
db: Database
|
||||
userId?: string
|
||||
overwriteState?: boolean
|
||||
protectExistingState?: boolean
|
||||
}
|
||||
|
||||
export interface SyncOpenCodeImportResult extends OpenCodeImportStatus {
|
||||
@@ -29,6 +30,17 @@ export interface SyncOpenCodeImportResult extends OpenCodeImportStatus {
|
||||
stateImported: boolean
|
||||
}
|
||||
|
||||
export class OpenCodeImportProtectionError extends Error {
|
||||
code = 'OPENCODE_IMPORT_PROTECTED'
|
||||
detail: string
|
||||
|
||||
constructor(detail: string) {
|
||||
super('OpenCode host import was blocked to protect existing workspace state')
|
||||
this.name = 'OpenCodeImportProtectionError'
|
||||
this.detail = detail
|
||||
}
|
||||
}
|
||||
|
||||
export interface ImportedSessionDirectorySummary {
|
||||
directories: string[]
|
||||
}
|
||||
@@ -95,6 +107,8 @@ export async function importOpenCodeStateDirectory(sourcePath: string, targetPat
|
||||
const resolvedSourcePath = path.resolve(sourcePath)
|
||||
const resolvedTargetPath = path.resolve(targetPath)
|
||||
const sourceDbPath = path.join(resolvedSourcePath, 'opencode.db')
|
||||
const targetParentPath = path.dirname(resolvedTargetPath)
|
||||
const targetDirectoryName = path.basename(resolvedTargetPath)
|
||||
|
||||
if (resolvedSourcePath === resolvedTargetPath) {
|
||||
return false
|
||||
@@ -104,22 +118,21 @@ export async function importOpenCodeStateDirectory(sourcePath: string, targetPat
|
||||
return false
|
||||
}
|
||||
|
||||
await ensureDirectoryExists(resolvedTargetPath)
|
||||
await ensureDirectoryExists(targetParentPath)
|
||||
|
||||
const existingEntries = await readdir(resolvedTargetPath, { withFileTypes: true })
|
||||
for (const entry of existingEntries) {
|
||||
if (!OPENCODE_STATE_DB_FILENAMES.has(entry.name)) {
|
||||
await rm(path.join(resolvedTargetPath, entry.name), { recursive: true, force: true })
|
||||
}
|
||||
const stagedTargetPath = await mkdtemp(path.join(targetParentPath, `${targetDirectoryName}-import-`))
|
||||
|
||||
try {
|
||||
await copyOpenCodeStateFiles(resolvedSourcePath, stagedTargetPath)
|
||||
snapshotOpenCodeDatabase(sourceDbPath, path.join(stagedTargetPath, 'opencode.db'))
|
||||
|
||||
await rm(resolvedTargetPath, { recursive: true, force: true })
|
||||
await rename(stagedTargetPath, resolvedTargetPath)
|
||||
return true
|
||||
} catch (error) {
|
||||
await rm(stagedTargetPath, { recursive: true, force: true })
|
||||
throw error
|
||||
}
|
||||
|
||||
await rm(path.join(resolvedTargetPath, 'opencode.db'), { force: true })
|
||||
await rm(path.join(resolvedTargetPath, 'opencode.db-shm'), { force: true })
|
||||
await rm(path.join(resolvedTargetPath, 'opencode.db-wal'), { force: true })
|
||||
|
||||
await copyOpenCodeStateFiles(resolvedSourcePath, resolvedTargetPath)
|
||||
snapshotOpenCodeDatabase(sourceDbPath, path.join(resolvedTargetPath, 'opencode.db'))
|
||||
return true
|
||||
}
|
||||
|
||||
export async function getOpenCodeImportStatus(): Promise<OpenCodeImportStatus> {
|
||||
@@ -175,14 +188,21 @@ async function importOpenCodeConfigFromSource(db: Database, userId: string, sour
|
||||
export async function syncOpenCodeImport(options: SyncOpenCodeImportOptions): Promise<SyncOpenCodeImportResult> {
|
||||
const initialStatus = await getOpenCodeImportStatus()
|
||||
const userId = options.userId || 'default'
|
||||
const overwriteState = options.overwriteState === true
|
||||
let configImported = false
|
||||
let stateImported = false
|
||||
|
||||
if (options.protectExistingState && initialStatus.stateSourcePath && initialStatus.workspaceStateExists && !overwriteState) {
|
||||
throw new OpenCodeImportProtectionError(
|
||||
`Import was blocked because workspace state already exists at ${initialStatus.workspaceStatePath}. Clear the workspace state first if you want to replace it with host state.`
|
||||
)
|
||||
}
|
||||
|
||||
if (initialStatus.configSourcePath) {
|
||||
configImported = await importOpenCodeConfigFromSource(options.db, userId, initialStatus.configSourcePath, initialStatus.workspaceConfigPath)
|
||||
}
|
||||
|
||||
if (initialStatus.stateSourcePath && ((options.overwriteState ?? true) || !initialStatus.workspaceStateExists)) {
|
||||
if (initialStatus.stateSourcePath && (overwriteState || !initialStatus.workspaceStateExists)) {
|
||||
stateImported = await importOpenCodeStateDirectory(initialStatus.stateSourcePath, initialStatus.workspaceStatePath)
|
||||
}
|
||||
|
||||
|
||||
@@ -66,6 +66,15 @@ vi.mock('../../src/services/opencode-single-server', () => ({
|
||||
}))
|
||||
|
||||
vi.mock('../../src/services/opencode-import', () => ({
|
||||
OpenCodeImportProtectionError: class OpenCodeImportProtectionError extends Error {
|
||||
code = 'OPENCODE_IMPORT_PROTECTED'
|
||||
detail: string
|
||||
|
||||
constructor(detail: string) {
|
||||
super('OpenCode host import was blocked to protect existing workspace state')
|
||||
this.detail = detail
|
||||
}
|
||||
},
|
||||
getOpenCodeImportStatus: vi.fn(),
|
||||
syncOpenCodeImport: vi.fn(),
|
||||
getImportedSessionDirectories: vi.fn(),
|
||||
@@ -100,7 +109,7 @@ vi.mock('@opencode-manager/shared/config/env', () => ({
|
||||
}))
|
||||
|
||||
import { createSettingsRoutes } from '../../src/routes/settings'
|
||||
import { getImportedSessionDirectories, getOpenCodeImportStatus, syncOpenCodeImport } from '../../src/services/opencode-import'
|
||||
import { getImportedSessionDirectories, getOpenCodeImportStatus, OpenCodeImportProtectionError, syncOpenCodeImport } from '../../src/services/opencode-import'
|
||||
import { relinkReposFromSessionDirectories } from '../../src/services/repo'
|
||||
import { opencodeServerManager } from '../../src/services/opencode-single-server'
|
||||
|
||||
@@ -205,6 +214,7 @@ describe('Settings Routes - OpenCode Upgrade', () => {
|
||||
db: testDb,
|
||||
userId: 'default',
|
||||
overwriteState: true,
|
||||
protectExistingState: true,
|
||||
})
|
||||
expect(mockGetImportedSessionDirectories).toHaveBeenCalledWith('/tmp/test-workspace/.opencode/state/opencode')
|
||||
expect(mockRelinkReposFromSessionDirectories).toHaveBeenCalled()
|
||||
@@ -236,6 +246,26 @@ describe('Settings Routes - OpenCode Upgrade', () => {
|
||||
expect(mockRestart).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should return 409 when import is blocked to protect workspace state', async () => {
|
||||
mockSyncOpenCodeImport.mockRejectedValueOnce(
|
||||
new OpenCodeImportProtectionError('Workspace state already exists and must be cleared before import')
|
||||
)
|
||||
|
||||
const req = new Request('http://localhost/opencode-import', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({}),
|
||||
})
|
||||
const res = await settingsApp.fetch(req)
|
||||
const json = await res.json() as Record<string, unknown>
|
||||
|
||||
expect(res.status).toBe(409)
|
||||
expect(json.error).toBe('OpenCode host import was blocked to protect existing workspace state')
|
||||
expect(json.code).toBe('OPENCODE_IMPORT_PROTECTED')
|
||||
expect(json.detail).toBe('Workspace state already exists and must be cleared before import')
|
||||
expect(mockRestart).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should not call relink functions when only config is imported (stateImported: false)', async () => {
|
||||
mockSyncOpenCodeImport.mockResolvedValueOnce({
|
||||
configSourcePath: '/import/opencode-config/opencode.json',
|
||||
|
||||
@@ -3,7 +3,9 @@ import type { Database } from 'bun:sqlite'
|
||||
|
||||
vi.mock('fs/promises', () => ({
|
||||
cp: vi.fn(),
|
||||
mkdtemp: vi.fn(),
|
||||
readdir: vi.fn(),
|
||||
rename: vi.fn(),
|
||||
rm: vi.fn(),
|
||||
}))
|
||||
|
||||
@@ -31,7 +33,7 @@ vi.mock('@opencode-manager/shared/config/env', () => ({
|
||||
}))
|
||||
|
||||
import path from 'path'
|
||||
import { readdir, rm, cp } from 'fs/promises'
|
||||
import { readdir, rm, cp, mkdtemp, rename } from 'fs/promises'
|
||||
import { Database as SQLiteDatabase } from 'bun:sqlite'
|
||||
import { ensureDirectoryExists, fileExists, readFileContent, writeFileContent } from '../../src/services/file-operations'
|
||||
import { SettingsService } from '../../src/services/settings'
|
||||
@@ -44,6 +46,8 @@ const mockWriteFileContent = writeFileContent as ReturnType<typeof vi.fn>
|
||||
const mockEnsureDirectoryExists = ensureDirectoryExists as ReturnType<typeof vi.fn>
|
||||
const MockSettingsService = SettingsService as unknown as ReturnType<typeof vi.fn>
|
||||
const MockSQLiteDatabase = SQLiteDatabase as unknown as ReturnType<typeof vi.fn>
|
||||
const mockMkdtemp = mkdtemp as unknown as ReturnType<typeof vi.fn>
|
||||
const mockRename = rename as unknown as ReturnType<typeof vi.fn>
|
||||
|
||||
describe('opencode-import service', () => {
|
||||
const mockDb = {} as unknown as Database
|
||||
@@ -58,6 +62,8 @@ describe('opencode-import service', () => {
|
||||
MockSettingsService.mockImplementation(() => settingsService)
|
||||
mockReadFileContent.mockResolvedValue('{"$schema":"https://opencode.ai/config.json"}')
|
||||
mockReaddir.mockResolvedValue([])
|
||||
mockMkdtemp.mockResolvedValue('/tmp/workspace/.opencode/state/opencode-import-123')
|
||||
mockRename.mockResolvedValue(undefined)
|
||||
})
|
||||
|
||||
it('detects importable host config and state paths with opencode.db', async () => {
|
||||
@@ -121,8 +127,12 @@ describe('opencode-import service', () => {
|
||||
'/tmp/workspace/.config/opencode/opencode.json',
|
||||
'{"$schema":"https://opencode.ai/config.json"}'
|
||||
)
|
||||
expect(mockEnsureDirectoryExists).toHaveBeenCalledWith('/tmp/workspace/.opencode/state/opencode')
|
||||
expect(mockEnsureDirectoryExists).toHaveBeenCalledWith('/tmp/workspace/.opencode/state')
|
||||
expect(MockSQLiteDatabase).toHaveBeenCalledWith('/import/opencode-state/opencode.db')
|
||||
expect(mockRename).toHaveBeenCalledWith(
|
||||
'/tmp/workspace/.opencode/state/opencode-import-123',
|
||||
'/tmp/workspace/.opencode/state/opencode'
|
||||
)
|
||||
})
|
||||
|
||||
it('does not report state imported when source db is missing', async () => {
|
||||
@@ -215,33 +225,50 @@ describe('opencode-import service', () => {
|
||||
expect(MockSQLiteDatabase).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('removes stale non-DB artifacts before copying new state during overwrite import', async () => {
|
||||
it('blocks import when workspace state exists and overwriteState is not enabled', async () => {
|
||||
process.env.OPENCODE_IMPORT_CONFIG_PATH = '/import/opencode-config/opencode.json'
|
||||
process.env.OPENCODE_IMPORT_STATE_PATH = '/import/opencode-state'
|
||||
|
||||
mockFileExists.mockImplementation(async (candidate: string) => {
|
||||
return candidate === '/import/opencode-config/opencode.json'
|
||||
|| candidate === '/import/opencode-state'
|
||||
|| candidate === '/import/opencode-state/opencode.db'
|
||||
|| candidate === '/tmp/workspace/.opencode/state/opencode/opencode.db'
|
||||
})
|
||||
|
||||
await expect(syncOpenCodeImport({
|
||||
db: mockDb,
|
||||
userId: 'default',
|
||||
overwriteState: false,
|
||||
protectExistingState: true,
|
||||
})).rejects.toThrow('OpenCode host import was blocked to protect existing workspace state')
|
||||
|
||||
expect(settingsService.updateOpenCodeConfig).not.toHaveBeenCalled()
|
||||
expect(mockEnsureDirectoryExists).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('stages imported state before replacing the target directory', async () => {
|
||||
const { importOpenCodeStateDirectory } = await import('../../src/services/opencode-import')
|
||||
|
||||
const sourcePath = '/import/opencode-state'
|
||||
const targetPath = '/workspace/.opencode/state/opencode'
|
||||
const stagedPath = '/workspace/.opencode/state/opencode-import-123'
|
||||
|
||||
mockFileExists.mockImplementation(async (candidate: string) => {
|
||||
if (candidate === path.join(sourcePath, 'opencode.db')) {
|
||||
return true
|
||||
}
|
||||
if (candidate === path.join(targetPath, 'opencode.db')) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
mockEnsureDirectoryExists.mockResolvedValue(undefined)
|
||||
mockReaddir.mockResolvedValue([
|
||||
{ name: 'stale-file.txt', isDirectory: () => false },
|
||||
{ name: 'stale-folder', isDirectory: () => true },
|
||||
{ name: 'opencode.db', isDirectory: () => false },
|
||||
{ name: 'opencode.db-shm', isDirectory: () => false },
|
||||
{ name: 'opencode.db-wal', isDirectory: () => false },
|
||||
] as any)
|
||||
|
||||
mockEnsureDirectoryExists.mockResolvedValue(undefined)
|
||||
const mockRm = vi.mocked(rm)
|
||||
mockRm.mockResolvedValue(undefined)
|
||||
mockMkdtemp.mockResolvedValue(stagedPath)
|
||||
|
||||
const mockCp = vi.mocked(cp)
|
||||
mockCp.mockResolvedValue(undefined)
|
||||
@@ -256,15 +283,43 @@ describe('opencode-import service', () => {
|
||||
const result = await importOpenCodeStateDirectory(sourcePath, targetPath)
|
||||
|
||||
expect(result).toBe(true)
|
||||
expect(mockRm).toHaveBeenCalledWith(
|
||||
path.join(targetPath, 'stale-file.txt'),
|
||||
{ recursive: true, force: true }
|
||||
expect(mockCp).toHaveBeenCalledWith(
|
||||
path.join(sourcePath, 'stale-file.txt'),
|
||||
path.join(stagedPath, 'stale-file.txt'),
|
||||
expect.any(Object)
|
||||
)
|
||||
expect(mockRm).toHaveBeenCalledWith(
|
||||
path.join(targetPath, 'stale-folder'),
|
||||
{ recursive: true, force: true }
|
||||
)
|
||||
expect(mockCp).toHaveBeenCalled()
|
||||
expect(mockExec).toHaveBeenCalled()
|
||||
expect(mockRm).toHaveBeenCalledWith(targetPath, { recursive: true, force: true })
|
||||
expect(mockRename).toHaveBeenCalledWith(stagedPath, targetPath)
|
||||
})
|
||||
|
||||
it('cleans up the staged import directory when snapshotting fails', async () => {
|
||||
const { importOpenCodeStateDirectory } = await import('../../src/services/opencode-import')
|
||||
|
||||
const sourcePath = '/import/opencode-state'
|
||||
const targetPath = '/workspace/.opencode/state/opencode'
|
||||
const stagedPath = '/workspace/.opencode/state/opencode-import-456'
|
||||
|
||||
mockFileExists.mockImplementation(async (candidate: string) => candidate === path.join(sourcePath, 'opencode.db'))
|
||||
mockEnsureDirectoryExists.mockResolvedValue(undefined)
|
||||
mockMkdtemp.mockResolvedValue(stagedPath)
|
||||
|
||||
const mockExec = vi.fn(() => {
|
||||
throw new Error('snapshot failed')
|
||||
})
|
||||
const mockClose = vi.fn()
|
||||
MockSQLiteDatabase.mockImplementationOnce(() => ({
|
||||
exec: mockExec,
|
||||
close: mockClose,
|
||||
}))
|
||||
|
||||
const mockRm = vi.mocked(rm)
|
||||
mockRm.mockResolvedValue(undefined)
|
||||
|
||||
await expect(importOpenCodeStateDirectory(sourcePath, targetPath)).rejects.toThrow('snapshot failed')
|
||||
|
||||
expect(mockRm).toHaveBeenCalledWith(stagedPath, { recursive: true, force: true })
|
||||
expect(mockRm).not.toHaveBeenCalledWith(targetPath, { recursive: true, force: true })
|
||||
expect(mockRename).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
@@ -151,7 +151,7 @@ export const settingsApi = {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/settings/opencode-import/status`)
|
||||
},
|
||||
|
||||
syncOpenCodeImport: async (overwriteState = true): Promise<SyncOpenCodeImportResponse> => {
|
||||
syncOpenCodeImport: async (overwriteState = false): Promise<SyncOpenCodeImportResponse> => {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/settings/opencode-import`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
|
||||
@@ -23,6 +23,7 @@ import { useServerHealth } from '@/hooks/useServerHealth'
|
||||
import { parseJsonc, hasJsoncComments } from '@/lib/jsonc'
|
||||
import { showToast } from '@/lib/toast'
|
||||
import { invalidateConfigCaches } from '@/lib/queryInvalidation'
|
||||
import { FetchError } from '@/api/fetchWrapper'
|
||||
import type { OpenCodeConfig, OpenCodeImportStatus } from '@/api/types/settings'
|
||||
|
||||
interface Command {
|
||||
@@ -162,7 +163,7 @@ export function OpenCodeConfigManager() {
|
||||
})
|
||||
|
||||
const syncOpenCodeImportMutation = useMutation({
|
||||
mutationFn: async () => settingsApi.syncOpenCodeImport(true),
|
||||
mutationFn: async () => settingsApi.syncOpenCodeImport(),
|
||||
onSuccess: async () => {
|
||||
await fetchConfigs()
|
||||
invalidateConfigCaches(queryClient)
|
||||
@@ -171,6 +172,10 @@ export function OpenCodeConfigManager() {
|
||||
})
|
||||
|
||||
const getApiErrorMessage = (error: unknown, fallback: string): string => {
|
||||
if (error instanceof FetchError) {
|
||||
return error.detail || error.message || fallback
|
||||
}
|
||||
|
||||
if (error && typeof error === 'object' && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { details?: string; error?: string } } }).response
|
||||
return response?.data?.details || response?.data?.error || fallback
|
||||
@@ -182,6 +187,14 @@ export function OpenCodeConfigManager() {
|
||||
return getApiErrorMessage(error, 'Failed to restart OpenCode server')
|
||||
}
|
||||
|
||||
const getOpenCodeImportErrorMessage = (error: unknown): string => {
|
||||
if (error instanceof FetchError && error.code === 'OPENCODE_IMPORT_PROTECTED') {
|
||||
return error.detail || error.message
|
||||
}
|
||||
|
||||
return getApiErrorMessage(error, 'Failed to import existing OpenCode host data')
|
||||
}
|
||||
|
||||
const fetchConfigs = async () => {
|
||||
try {
|
||||
setIsLoading(true)
|
||||
@@ -455,12 +468,12 @@ export function OpenCodeConfigManager() {
|
||||
<Card>
|
||||
<CardHeader className="pb-3">
|
||||
<div className="flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div>
|
||||
<CardTitle className="text-sm sm:text-base">Existing OpenCode Host Import</CardTitle>
|
||||
<p className="text-sm text-muted-foreground mt-1">
|
||||
Re-import your standalone OpenCode config and session state into this workspace, then restart the server so existing chats can reconnect.
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<CardTitle className="text-sm sm:text-base">Existing OpenCode Host Import</CardTitle>
|
||||
<p className="text-sm text-muted-foreground mt-1">
|
||||
Import your standalone OpenCode config and session state into this workspace, then restart the server so existing chats can reconnect.
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
@@ -477,7 +490,7 @@ export function OpenCodeConfigManager() {
|
||||
: ''
|
||||
showToast.success(`Imported existing OpenCode ${importedParts || 'data'} and restarted the server.${relinkSummary}`, { id: 'opencode-import' })
|
||||
} catch (error) {
|
||||
showToast.error(getApiErrorMessage(error, 'Failed to import existing OpenCode host data'), { id: 'opencode-import' })
|
||||
showToast.error(getOpenCodeImportErrorMessage(error), { id: 'opencode-import' })
|
||||
}
|
||||
}}
|
||||
>
|
||||
@@ -512,10 +525,21 @@ export function OpenCodeConfigManager() {
|
||||
</p>
|
||||
<p className="mt-2 text-xs text-muted-foreground">
|
||||
{importStatus?.workspaceStateExists
|
||||
? 'A workspace session database already exists. Import will replace it with the detected host state.'
|
||||
? 'A workspace session database already exists. Import is blocked to protect it from being replaced by detected host state.'
|
||||
: 'No workspace session database exists yet. Import will seed it from the detected host state.'}
|
||||
</p>
|
||||
</div>
|
||||
{syncOpenCodeImportMutation.error && (
|
||||
<div className="rounded-lg border border-destructive/40 bg-destructive/5 p-3">
|
||||
<p className="font-medium text-destructive">Import blocked</p>
|
||||
<p className="mt-1 text-sm text-destructive/90">
|
||||
{getOpenCodeImportErrorMessage(syncOpenCodeImportMutation.error)}
|
||||
</p>
|
||||
<p className="mt-2 text-xs text-destructive/80">
|
||||
This workspace already has OpenCode session state, so host state import was stopped to prevent accidental replacement of existing chats and history. If you want to use host state instead, clear the workspace state first and then run the import again.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
{syncOpenCodeImportMutation.data?.relinkedRepos && (
|
||||
<div className="rounded-lg border border-border p-3">
|
||||
<p className="font-medium">Last Relink Result</p>
|
||||
|
||||
Reference in new issue
Block a user