Skip to content

Commit 66d409d

Browse files
authored
fix(opencode): Update directory and path fields of imported session (anomalyco#27516)
1 parent 4ad261d commit 66d409d

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

packages/opencode/src/cli/cmd/import.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import { SessionTable, MessageTable, PartTable } from "../../session/session.sql
77
import { InstanceRef } from "@/effect/instance-ref"
88
import { ShareNext } from "@/share/share-next"
99
import { EOL } from "os"
10+
import path from "path"
1011
import { AppFileSystem } from "@opencode-ai/core/filesystem"
1112
import { Effect, Schema } from "effect"
13+
import type { InstanceContext } from "@/project/instance-context"
1214

1315
const decodeMessageInfo = Schema.decodeUnknownSync(MessageV2.Info)
1416
const decodePart = Schema.decodeUnknownSync(MessageV2.Part)
@@ -89,11 +91,11 @@ export const ImportCommand = effectCmd({
8991
handler: Effect.fn("Cli.import")(function* (args) {
9092
const ctx = yield* InstanceRef
9193
if (!ctx) return yield* Effect.die("InstanceRef not provided")
92-
return yield* runImport(args.file, ctx.project.id)
94+
return yield* runImport(args.file, ctx)
9395
}),
9496
})
9597

96-
const runImport = Effect.fn("Cli.import.body")(function* (file: string, projectID: string) {
98+
const runImport = Effect.fn("Cli.import.body")(function* (file: string, ctx: InstanceContext) {
9799
const share = yield* ShareNext.Service
98100
const fs = yield* AppFileSystem.Service
99101

@@ -168,14 +170,19 @@ const runImport = Effect.fn("Cli.import.body")(function* (file: string, projectI
168170

169171
const info = Schema.decodeUnknownSync(Session.Info)({
170172
...exportData.info,
171-
projectID,
173+
projectID: ctx.project.id,
174+
directory: ctx.directory,
175+
path: path.relative(path.resolve(ctx.worktree), ctx.directory).replaceAll("\\", "/"),
172176
}) as Session.Info
173177
const row = Session.toRow(info)
174178
Database.use((db) =>
175179
db
176180
.insert(SessionTable)
177181
.values(row)
178-
.onConflictDoUpdate({ target: SessionTable.id, set: { project_id: row.project_id } })
182+
.onConflictDoUpdate({
183+
target: SessionTable.id,
184+
set: { project_id: row.project_id, directory: row.directory, path: row.path },
185+
})
179186
.run(),
180187
)
181188

0 commit comments

Comments
 (0)