Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { DialogConfirm } from "@tui/ui/dialog-confirm"
import { useDialog } from "@tui/ui/dialog"
import { useSync } from "@tui/context/sync"
import { useRoute } from "@tui/context/route"
import { createMemo } from "solid-js"
import { useSDK } from "../context/sdk"
import { Locale } from "@/util/locale"

interface DialogSessionDeleteProps {
session: string
}

export function DialogSessionDelete(props: DialogSessionDeleteProps) {
const dialog = useDialog()
const sync = useSync()
const route = useRoute()
const sdk = useSDK()

const session = createMemo(() => sync.session.get(props.session))

const messageCount = createMemo(() => {
return sync.data.message[props.session]?.length ?? 0
})

const childCount = createMemo(() => {
return sync.data.session.filter((x) => x.parentID === props.session).length
})

const createdDate = createMemo(() => {
const created = session()?.time.created
if (!created) return "Unknown"
return Locale.datetime(created)
})

const message = createMemo(() => {
const title = session()?.title ?? "Untitled session"
const messages = messageCount()
const children = childCount()
const created = createdDate()

let text = `# ${title}\n\nAre you sure you want to delete this session?`

text += `\n\nCreated: ${created}`
text += `\nMessages: ${messages}`

if (children > 0) {
text += `\nChild sessions: ${children}`
}

text += "\n\nThis action cannot be undone."

return text
})

return (
<DialogConfirm
title="Delete session"
message={message()}
onConfirm={() => {
sdk.client.session.delete({
sessionID: props.session,
})
route.navigate({ type: "home" })
}}
/>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function DialogSessionRename(props: DialogSessionRenameProps) {

return (
<DialogPrompt
title="Rename Session"
title="Rename session"
value={session()?.title}
onConfirm={(value) => {
sdk.client.session.update({
Expand Down
13 changes: 13 additions & 0 deletions packages/opencode/src/cli/cmd/tui/routes/session/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import { DialogConfirm } from "@tui/ui/dialog-confirm"
import { DialogTimeline } from "./dialog-timeline"
import { DialogForkFromTimeline } from "./dialog-fork-from-timeline"
import { DialogSessionRename } from "../../component/dialog-session-rename"
import { DialogSessionDelete } from "../../component/dialog-session-delete"
import { Sidebar } from "./sidebar"
import { Flag } from "@/flag/flag"
import { LANGUAGE_EXTENSIONS } from "@/lsp/language"
Expand Down Expand Up @@ -356,6 +357,18 @@ export function Session() {
dialog.replace(() => <DialogSessionRename session={route.sessionID} />)
},
},
{
title: "Delete session",
value: "session.delete",
keybind: "session_delete",
category: "Session",
slash: {
name: "delete",
},
onSelect: (dialog) => {
dialog.replace(() => <DialogSessionDelete session={route.sessionID} />)
},
},
{
title: "Jump to message",
value: "session.timeline",
Expand Down
3 changes: 3 additions & 0 deletions packages/opencode/src/cli/cmd/tui/ui/dialog-alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ export function DialogAlert(props: DialogAlertProps) {

useKeyboard((evt) => {
if (evt.name === "return") {
evt.preventDefault()
evt.stopPropagation()
props.onConfirm?.()
dialog.clear()
}
})

return (
<box paddingLeft={2} paddingRight={2} gap={1}>
<box flexDirection="row" justifyContent="space-between">
Expand Down
3 changes: 3 additions & 0 deletions packages/opencode/src/cli/cmd/tui/ui/dialog-confirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export function DialogConfirm(props: DialogConfirmProps) {

useKeyboard((evt) => {
if (evt.name === "return") {
evt.preventDefault()
evt.stopPropagation()
if (store.active === "confirm") props.onConfirm?.()
if (store.active === "cancel") props.onCancel?.()
dialog.clear()
Expand All @@ -31,6 +33,7 @@ export function DialogConfirm(props: DialogConfirmProps) {
setStore("active", store.active === "confirm" ? "cancel" : "confirm")
}
})

return (
<box paddingLeft={2} paddingRight={2} gap={1}>
<box flexDirection="row" justifyContent="space-between">
Expand Down
24 changes: 24 additions & 0 deletions packages/web/src/content/docs/tui.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ Compact the current session. _Alias_: `/summarize`

---

### delete

Delete the current session after confirmation.

```bash frame="none"
/delete
```

**Keybind:** `ctrl+d`

---

### details

Toggle tool execution details.
Expand Down Expand Up @@ -206,6 +218,18 @@ be a Git repository**.

---

### rename

Rename the current session.

```bash frame="none"
/rename
```

**Keybind:** `ctrl+r`

---

### sessions

List and switch between sessions. _Aliases_: `/resume`, `/continue`
Expand Down
Loading