opencode-session-bar 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -0
- package/index.tsx +88 -0
- package/package.json +25 -0
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# opencode-session-bar
|
|
2
|
+
|
|
3
|
+
OpenCode TUI sidebar plugin — list all sessions with quick switch and delete.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
opencode plugin add opencode-session-bar
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or add to `tui.json`:
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
{
|
|
15
|
+
"plugin": ["opencode-session-bar"]
|
|
16
|
+
}
|
|
17
|
+
```
|
package/index.tsx
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/** @jsxImportSource @opentui/solid */
|
|
2
|
+
import { createResource, createSignal, For, Show } from "solid-js"
|
|
3
|
+
import type { TuiPlugin, TuiPluginApi, TuiPluginModule } from "@opencode-ai/plugin/tui"
|
|
4
|
+
|
|
5
|
+
function View(props: { api: TuiPluginApi; sessionID: string }) {
|
|
6
|
+
const theme = () => props.api.theme.current
|
|
7
|
+
const [deleting, setDeleting] = createSignal<Set<string>>(new Set())
|
|
8
|
+
|
|
9
|
+
const [sessions, { refetch }] = createResource(async () => {
|
|
10
|
+
const res = await props.api.client.session.list()
|
|
11
|
+
return (res.data ?? []) as Array<{ id: string; title: string; time: { created: number; updated: number } }>
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
async function handleSwitch(id: string) {
|
|
15
|
+
props.api.route.navigate("session", { sessionID: id })
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function handleDelete(id: string) {
|
|
19
|
+
setDeleting(prev => new Set(prev).add(id))
|
|
20
|
+
try {
|
|
21
|
+
await props.api.client.session.delete({ path: { id } })
|
|
22
|
+
refetch()
|
|
23
|
+
} catch {
|
|
24
|
+
props.api.ui.toast({ variant: "error", message: "Failed to delete session" })
|
|
25
|
+
} finally {
|
|
26
|
+
setDeleting(prev => { const next = new Set(prev); next.delete(id); return next })
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const sorted = () => (sessions() ?? [])
|
|
31
|
+
.slice()
|
|
32
|
+
.sort((a, b) => b.time.updated - a.time.updated)
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<box>
|
|
36
|
+
<text fg={theme().text}>Sessions</text>
|
|
37
|
+
<Show when={sessions.loading}>
|
|
38
|
+
<text fg={theme().textMuted}>loading...</text>
|
|
39
|
+
</Show>
|
|
40
|
+
<For each={sorted()}>
|
|
41
|
+
{(session) => {
|
|
42
|
+
const active = session.id === props.sessionID
|
|
43
|
+
const isDeleting = deleting().has(session.id)
|
|
44
|
+
return (
|
|
45
|
+
<box flexDirection="row" gap={1}>
|
|
46
|
+
<text
|
|
47
|
+
fg={active ? theme().accent : theme().text}
|
|
48
|
+
attributes={{ bold: active }}
|
|
49
|
+
onMouseDown={() => !active && handleSwitch(session.id)}
|
|
50
|
+
>
|
|
51
|
+
{active ? ">" : " "} {session.title}
|
|
52
|
+
</text>
|
|
53
|
+
<Show when={!isDeleting}>
|
|
54
|
+
<text
|
|
55
|
+
fg={theme().textMuted}
|
|
56
|
+
onMouseDown={() => handleDelete(session.id)}
|
|
57
|
+
>
|
|
58
|
+
[x]
|
|
59
|
+
</text>
|
|
60
|
+
</Show>
|
|
61
|
+
<Show when={isDeleting}>
|
|
62
|
+
<text fg={theme().textMuted}>...</text>
|
|
63
|
+
</Show>
|
|
64
|
+
</box>
|
|
65
|
+
)
|
|
66
|
+
}}
|
|
67
|
+
</For>
|
|
68
|
+
</box>
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const tui: TuiPlugin = async (api) => {
|
|
73
|
+
api.slots.register({
|
|
74
|
+
order: 40,
|
|
75
|
+
slots: {
|
|
76
|
+
sidebar_content(_ctx, props) {
|
|
77
|
+
return <View api={api} sessionID={props.session_id} />
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const plugin: TuiPluginModule & { id: string } = {
|
|
84
|
+
id: "opencode-session-bar",
|
|
85
|
+
tui,
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export default plugin
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "opencode-session-bar",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "OpenCode TUI sidebar plugin — list all sessions with quick switch and delete",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
"./tui": "./index.tsx"
|
|
8
|
+
},
|
|
9
|
+
"files": ["index.tsx", "package.json", "README.md"],
|
|
10
|
+
"keywords": ["opencode", "opencode-plugin", "sidebar", "sessions"],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/yuritoledo/opencode-session-bar"
|
|
15
|
+
},
|
|
16
|
+
"engines": {
|
|
17
|
+
"opencode": ">=1.4.3"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@opencode-ai/plugin": "^1.4.3",
|
|
21
|
+
"@opentui/core": "^0.2.2",
|
|
22
|
+
"@opentui/solid": "^0.2.2",
|
|
23
|
+
"solid-js": "^1.9.12"
|
|
24
|
+
}
|
|
25
|
+
}
|