@clwnd/opencode 0.18.4 → 0.18.6

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.
Files changed (2) hide show
  1. package/package.json +10 -3
  2. package/tui.tsx +99 -0
package/package.json CHANGED
@@ -1,16 +1,20 @@
1
1
  {
2
2
  "name": "@clwnd/opencode",
3
- "version": "0.18.4",
3
+ "version": "0.18.6",
4
4
  "description": "clwnd for opencode",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "exports": {
8
8
  ".": {
9
9
  "import": "./dist/index.js"
10
+ },
11
+ "./tui": {
12
+ "import": "./tui.tsx"
10
13
  }
11
14
  },
12
15
  "files": [
13
- "dist/"
16
+ "dist/",
17
+ "tui.tsx"
14
18
  ],
15
19
  "scripts": {
16
20
  "build": "tsup",
@@ -37,7 +41,10 @@
37
41
  "@ai-sdk/provider-utils": "^4.0.21"
38
42
  },
39
43
  "peerDependencies": {
40
- "@opencode-ai/plugin": ">=1.3.5"
44
+ "@opencode-ai/plugin": ">=1.3.5",
45
+ "@opentui/core": "^0.1.97",
46
+ "@opentui/solid": "^0.1.97",
47
+ "solid-js": "^1.9.12"
41
48
  },
42
49
  "devDependencies": {
43
50
  "@opencode-ai/plugin": "^1.3.5",
package/tui.tsx ADDED
@@ -0,0 +1,99 @@
1
+ /** @jsxImportSource @opentui/solid */
2
+ import type { TuiPlugin, TuiPluginModule } from "@opencode-ai/plugin/tui"
3
+ import { createSignal, onCleanup, createMemo, Show } from "solid-js"
4
+
5
+ interface DaemonData {
6
+ status: "connected" | "disconnected"
7
+ procs: number
8
+ sessions: number
9
+ uptimeMin: number
10
+ readDedup: number
11
+ bashCapped: number
12
+ contextWarnings: number
13
+ }
14
+
15
+ const SOCK_PATH = (() => {
16
+ const runtime = process.env.XDG_RUNTIME_DIR
17
+ const sock = process.env.CLWND_SOCKET ?? (runtime ? `${runtime}/clwnd/clwnd.sock` : "/tmp/clwnd/clwnd.sock")
18
+ return sock + ".http"
19
+ })()
20
+
21
+ async function fetchDaemon(): Promise<DaemonData> {
22
+ try {
23
+ const [statusResp, savingsResp] = await Promise.all([
24
+ fetch("http://localhost/status", { unix: SOCK_PATH } as RequestInit),
25
+ fetch("http://localhost/savings", { unix: SOCK_PATH } as RequestInit),
26
+ ])
27
+ const status = (await statusResp.json()) as any
28
+ const savings = (await savingsResp.json()) as any
29
+ const c = savings.counters ?? {}
30
+ return {
31
+ status: "connected",
32
+ procs: (status.procs ?? []).length,
33
+ sessions: status.sessions ?? 0,
34
+ uptimeMin: Math.round((savings.uptimeMs ?? 0) / 60_000),
35
+ readDedup: c.readDedupHits ?? 0,
36
+ bashCapped: c.bashTruncated ?? 0,
37
+ contextWarnings: c.contextOverThreshold ?? 0,
38
+ }
39
+ } catch {
40
+ return {
41
+ status: "disconnected", procs: 0, sessions: 0, uptimeMin: 0,
42
+ readDedup: 0, bashCapped: 0, contextWarnings: 0,
43
+ }
44
+ }
45
+ }
46
+
47
+ function SidebarView(props: { api: any; session_id: string }) {
48
+ const theme = () => props.api.theme.current
49
+ const [data, setData] = createSignal<DaemonData>({
50
+ status: "disconnected", procs: 0, sessions: 0, uptimeMin: 0,
51
+ readDedup: 0, bashCapped: 0, contextWarnings: 0,
52
+ })
53
+
54
+ const poll = () => fetchDaemon().then(setData).catch(() => {})
55
+ poll()
56
+ const timer = setInterval(poll, 10_000)
57
+ onCleanup(() => clearInterval(timer))
58
+
59
+ const statusLine = createMemo(() => {
60
+ const d = data()
61
+ const dot = d.status === "connected" ? "●" : "○"
62
+ return `${dot} ${d.status} · ${String(d.uptimeMin)}m`
63
+ })
64
+
65
+ const procsLine = createMemo(() => {
66
+ const d = data()
67
+ return `${String(d.procs)} proc${d.procs !== 1 ? "s" : ""} · ${String(d.sessions)} session${d.sessions !== 1 ? "s" : ""}`
68
+ })
69
+
70
+ const savingsLine = createMemo(() => {
71
+ const d = data()
72
+ if (d.readDedup === 0 && d.bashCapped === 0) return ""
73
+ return `saved: ${String(d.readDedup)} dedup · ${String(d.bashCapped)} capped`
74
+ })
75
+
76
+ return (
77
+ <box>
78
+ <text fg={theme().text}><b>clwnd</b></text>
79
+ <text fg={data().status === "connected" ? theme().success : theme().error}>{statusLine()}</text>
80
+ <text fg={theme().textMuted}>{procsLine()}</text>
81
+ <Show when={savingsLine() !== ""}>
82
+ <text fg={theme().textMuted}>{savingsLine()}</text>
83
+ </Show>
84
+ </box>
85
+ )
86
+ }
87
+
88
+ const tui: TuiPlugin = async (api) => {
89
+ api.slots.register({
90
+ order: 150,
91
+ slots: {
92
+ sidebar_content(_ctx, props) {
93
+ return <SidebarView api={api} session_id={props.session_id} />
94
+ },
95
+ },
96
+ })
97
+ }
98
+
99
+ export default { id: "@clwnd/opencode", tui } satisfies TuiPluginModule & { id: string }