Skip to content

Commit 961b226

Browse files
committed
Fix /fork command to directly fork without intermediate modal
- Replace DialogTimeline with DialogForkTimeline in session.fork command - DialogForkTimeline directly calls sdk.client.session.fork() on message selection - Fixes issue anomalyco#5599: /fork now immediately forks after message selection - Eliminates extra 'fork/copy/revert' modal step that was breaking UX
1 parent 297d37b commit 961b226

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { createMemo, onMount } from "solid-js"
2+
import { useSync } from "@tui/context/sync"
3+
import { DialogSelect, type DialogSelectOption } from "@tui/ui/dialog-select"
4+
import type { TextPart } from "@opencode-ai/sdk/v2"
5+
import { Locale } from "@/util/locale"
6+
import { useSDK } from "@tui/context/sdk"
7+
import { useRoute } from "@tui/context/route"
8+
import { useDialog } from "../../ui/dialog"
9+
10+
export function DialogForkTimeline(props: {
11+
sessionID: string
12+
onMove: (messageID: string) => void
13+
}) {
14+
const sync = useSync()
15+
const dialog = useDialog()
16+
const sdk = useSDK()
17+
const route = useRoute()
18+
19+
onMount(() => {
20+
dialog.setSize("large")
21+
})
22+
23+
const options = createMemo((): DialogSelectOption<string>[] => {
24+
const messages = sync.data.message[props.sessionID] ?? []
25+
const result = [] as DialogSelectOption<string>[]
26+
for (const message of messages) {
27+
if (message.role !== "user") continue
28+
const part = (sync.data.part[message.id] ?? []).find((x) => x.type === "text" && !x.synthetic) as TextPart
29+
if (!part) continue
30+
result.push({
31+
title: part.text.replace(/\n/g, " "),
32+
value: message.id,
33+
footer: Locale.time(message.time.created),
34+
onSelect: async (dialog) => {
35+
// Directly fork the session at this message
36+
const result = await sdk.client.session.fork({
37+
sessionID: props.sessionID,
38+
messageID: message.id,
39+
})
40+
route.navigate({
41+
sessionID: result.data!.id,
42+
type: "session",
43+
})
44+
dialog.clear()
45+
},
46+
})
47+
}
48+
result.reverse()
49+
return result
50+
})
51+
52+
return <DialogSelect onMove={(option) => props.onMove(option.value)} title="Fork Timeline" options={options()} />
53+
}

‎packages/opencode/src/cli/cmd/tui/routes/session/index.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import { iife } from "@/util/iife"
5353
import { DialogConfirm } from "@tui/ui/dialog-confirm"
5454
import { DialogPrompt } from "@tui/ui/dialog-prompt"
5555
import { DialogTimeline } from "./dialog-timeline"
56+
import { DialogForkTimeline } from "./dialog-fork-timeline"
5657

5758
import { DialogSessionRename } from "../../component/dialog-session-rename"
5859
import { Sidebar } from "./sidebar"
@@ -303,7 +304,7 @@ export function Session() {
303304
category: "Session",
304305
onSelect: (dialog) => {
305306
dialog.replace(() => (
306-
<DialogTimeline
307+
<DialogForkTimeline
307308
onMove={(messageID) => {
308309
const child = scroll.getChildren().find((child) => {
309310
return child.id === messageID

0 commit comments

Comments
 (0)