opencode-session-bar 1.1.1 → 1.1.3
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/index.tsx +20 -68
- package/package.json +15 -3
package/index.tsx
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
/** @jsxImportSource @opentui/solid */
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import type { KeyEvent } from "@opentui/core"
|
|
2
|
+
import type { TuiPlugin, TuiPluginApi, TuiPluginModule } from "@opencode-ai/plugin/tui";
|
|
3
|
+
import { createResource, createSignal, For, onCleanup, onMount, Show } from "solid-js";
|
|
5
4
|
|
|
6
5
|
function View(props: { api: TuiPluginApi; sessionID: string }) {
|
|
7
6
|
const theme = () => props.api.theme.current
|
|
8
7
|
const [deleting, setDeleting] = createSignal<Set<string>>(new Set())
|
|
9
|
-
const [selectedIndex, setSelectedIndex] = createSignal(0)
|
|
10
|
-
const [listFocused, setListFocused] = createSignal(false)
|
|
11
|
-
const [boxRef, setBoxRef] = createSignal<any>()
|
|
12
8
|
|
|
13
9
|
const [sessions, { refetch }] = createResource(async () => {
|
|
14
10
|
const res = await props.api.client.session.list()
|
|
@@ -19,10 +15,6 @@ function View(props: { api: TuiPluginApi; sessionID: string }) {
|
|
|
19
15
|
.slice()
|
|
20
16
|
.sort((a, b) => b.time.updated - a.time.updated)
|
|
21
17
|
|
|
22
|
-
function trunc(s: string, n: number): string {
|
|
23
|
-
return s.length > n ? s.slice(0, n) + "…" : s
|
|
24
|
-
}
|
|
25
|
-
|
|
26
18
|
async function handleSwitch(id: string) {
|
|
27
19
|
props.api.route.navigate("session", { sessionID: id })
|
|
28
20
|
}
|
|
@@ -30,7 +22,7 @@ function View(props: { api: TuiPluginApi; sessionID: string }) {
|
|
|
30
22
|
async function handleDelete(id: string) {
|
|
31
23
|
setDeleting(prev => new Set(prev).add(id))
|
|
32
24
|
try {
|
|
33
|
-
await props.api.client.session.delete({
|
|
25
|
+
await props.api.client.session.delete({ sessionID: id })
|
|
34
26
|
refetch()
|
|
35
27
|
} catch {
|
|
36
28
|
props.api.ui.toast({ variant: "error", message: "Failed to delete session" })
|
|
@@ -39,72 +31,32 @@ function View(props: { api: TuiPluginApi; sessionID: string }) {
|
|
|
39
31
|
}
|
|
40
32
|
}
|
|
41
33
|
|
|
42
|
-
function handleKeyDown(e: KeyEvent) {
|
|
43
|
-
const list = sorted()
|
|
44
|
-
if (!list.length) return
|
|
45
|
-
|
|
46
|
-
if (e.name === "down" || e.name === "j") {
|
|
47
|
-
e.preventDefault()
|
|
48
|
-
setSelectedIndex(i => Math.min(i + 1, list.length - 1))
|
|
49
|
-
} else if (e.name === "up" || e.name === "k") {
|
|
50
|
-
e.preventDefault()
|
|
51
|
-
setSelectedIndex(i => Math.max(i - 1, 0))
|
|
52
|
-
} else if (e.name === "enter" || e.name === "space") {
|
|
53
|
-
e.preventDefault()
|
|
54
|
-
const s = list[selectedIndex()]
|
|
55
|
-
if (s && s.id !== props.sessionID) handleSwitch(s.id)
|
|
56
|
-
} else if (e.name === "escape") {
|
|
57
|
-
e.preventDefault()
|
|
58
|
-
setListFocused(false)
|
|
59
|
-
boxRef()?.blur()
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function focusList() {
|
|
64
|
-
setListFocused(true)
|
|
65
|
-
boxRef()?.focus()
|
|
66
|
-
const list = sorted()
|
|
67
|
-
const idx = list.findIndex(s => s.id === props.sessionID)
|
|
68
|
-
if (idx >= 0) setSelectedIndex(idx)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
onMount(() => {
|
|
72
|
-
const dispose = props.api.command?.register(() => [{
|
|
73
|
-
title: "Session Bar: Focus List",
|
|
74
|
-
value: "session-bar:focus",
|
|
75
|
-
category: "Session Bar",
|
|
76
|
-
keybind: "ctrl+s",
|
|
77
|
-
onSelect: focusList,
|
|
78
|
-
}])
|
|
79
|
-
onCleanup(() => dispose?.())
|
|
80
|
-
})
|
|
81
|
-
|
|
82
34
|
return (
|
|
83
35
|
<box>
|
|
84
|
-
<text fg={theme().text}>
|
|
36
|
+
<text fg={theme().text}>
|
|
37
|
+
<strong>Latest sessions</strong>
|
|
38
|
+
</text>
|
|
85
39
|
<Show when={sessions.loading}>
|
|
86
40
|
<text fg={theme().textMuted}>loading...</text>
|
|
87
41
|
</Show>
|
|
88
|
-
<box
|
|
89
|
-
ref={setBoxRef}
|
|
90
|
-
focusable
|
|
91
|
-
focused={listFocused()}
|
|
92
|
-
onKeyDown={handleKeyDown}
|
|
93
|
-
>
|
|
42
|
+
<box>
|
|
94
43
|
<For each={sorted()}>
|
|
95
|
-
{(session
|
|
96
|
-
const active = session.id === props.sessionID
|
|
44
|
+
{(session) => {
|
|
97
45
|
const isDeleting = deleting().has(session.id)
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
46
|
+
onMount(() => {
|
|
47
|
+
const unsub1 = props.api.event.on("session.updated", () => refetch())
|
|
48
|
+
const unsub2 = props.api.event.on("session.deleted", () => refetch())
|
|
49
|
+
const unsub3 = props.api.event.on("session.created", () => refetch())
|
|
50
|
+
onCleanup(() => { unsub1(); unsub2(); unsub3() })
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<box flexDirection="row" justifyContent="space-between" overflow="hidden">
|
|
101
55
|
<text
|
|
102
|
-
fg={
|
|
103
|
-
|
|
104
|
-
wrapMode="none"
|
|
105
|
-
onMouseDown={() => !active && handleSwitch(session.id)}
|
|
56
|
+
fg={theme().textMuted}
|
|
57
|
+
flexGrow={1}
|
|
106
58
|
>
|
|
107
|
-
{
|
|
59
|
+
{session.title.slice(0, 30)}
|
|
108
60
|
</text>
|
|
109
61
|
<Show when={!isDeleting}>
|
|
110
62
|
<text
|
package/package.json
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-session-bar",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "OpenCode TUI sidebar plugin — list all sessions with quick switch and delete",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./tui": "./index.tsx"
|
|
8
8
|
},
|
|
9
|
-
"files": [
|
|
10
|
-
|
|
9
|
+
"files": [
|
|
10
|
+
"index.tsx",
|
|
11
|
+
"package.json",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"keywords": [
|
|
15
|
+
"opencode",
|
|
16
|
+
"opencode-plugin",
|
|
17
|
+
"sidebar",
|
|
18
|
+
"sessions"
|
|
19
|
+
],
|
|
11
20
|
"license": "MIT",
|
|
12
21
|
"repository": {
|
|
13
22
|
"type": "git",
|
|
@@ -21,5 +30,8 @@
|
|
|
21
30
|
"@opentui/core": "^0.2.2",
|
|
22
31
|
"@opentui/solid": "^0.2.2",
|
|
23
32
|
"solid-js": "^1.9.12"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/node": "^25.9.1"
|
|
24
36
|
}
|
|
25
37
|
}
|