Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/opencode/src/session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ export namespace Session {
).test(title)
}

function getForkedTitle(title: string): string {
const match = title.match(/^(.+) #(\d+)$/)
if (match) {
const base = match[1]
const num = parseInt(match[2], 10)
return `${base} #${num + 1}`
}
return `${title} #2`
}

export const Info = z
.object({
id: Identifier.schema("session"),
Expand Down Expand Up @@ -151,8 +161,12 @@ export namespace Session {
messageID: Identifier.schema("message").optional(),
}),
async (input) => {
const original = await get(input.sessionID)
if (!original) throw new Error("session not found")
const title = getForkedTitle(original.title)
const session = await createNext({
directory: Instance.directory,
title,
})
const msgs = await messages({ sessionID: input.sessionID })
const idMap = new Map<string, string>()
Expand Down