Skip to content

Commit d1d2fa8

Browse files
authored
feat: Sequential numbering for forked session titles (Issue #10105) (#10321)
1 parent a030e4e commit d1d2fa8

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

‎packages/opencode/src/session/index.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ export namespace Session {
3939
).test(title)
4040
}
4141

42+
function getForkedTitle(title: string): string {
43+
const match = title.match(/^(.+) \(fork #(\d+)\)$/)
44+
if (match) {
45+
const base = match[1]
46+
const num = parseInt(match[2], 10)
47+
return `${base} (fork #${num + 1})`
48+
}
49+
return `${title} (fork #1)`
50+
}
51+
4252
export const Info = z
4353
.object({
4454
id: Identifier.schema("session"),
@@ -151,8 +161,12 @@ export namespace Session {
151161
messageID: Identifier.schema("message").optional(),
152162
}),
153163
async (input) => {
164+
const original = await get(input.sessionID)
165+
if (!original) throw new Error("session not found")
166+
const title = getForkedTitle(original.title)
154167
const session = await createNext({
155168
directory: Instance.directory,
169+
title,
156170
})
157171
const msgs = await messages({ sessionID: input.sessionID })
158172
const idMap = new Map<string, string>()

0 commit comments

Comments
 (0)