FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat(tui): add session delete command with confirmation dialog by frouo · Pull Request #11684 · anomalyco/opencode · GitHub

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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" })
}}
/>
)
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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) => {
void sdk.client.session.update({
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,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 { SubagentFooter } from "./subagent-footer.tsx"
import { Flag } from "@opencode-ai/core/flag/flag"
Expand Down Expand Up @@ -443,6 +444,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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function DialogAlert(props: DialogAlertProps) {
dialog.clear()
}
})

return (
<box paddingLeft={2} paddingRight={2} gap={1}>
<box flexDirection="row" justifyContent="space-between">
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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 @@ -200,6 +212,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

Back | FazBrowse Home | New Git URL