echoes-vault-opencode 1.0.13 → 1.0.15

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 +1 -1
  2. package/tui.ts +89 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "echoes-vault-opencode",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "description": "EchoesVault — persistent memory plugin for OpenCode. Obsidian-style knowledge base with daily logs, encyclopedia pages, and session resumption.",
5
5
  "type": "module",
6
6
  "main": "index.ts",
package/tui.ts CHANGED
@@ -1,18 +1,95 @@
1
+ import { createElement, spread } from "@opentui/solid"
1
2
  import type { TuiPlugin } from "@opencode-ai/plugin/tui"
2
3
 
4
+ function h(tag: string, props: Record<string, any> = {}, children: any[] = []) {
5
+ const el = createElement(tag)
6
+ spread(el, props)
7
+ for (const child of children) {
8
+ if (child != null && child !== false) el.add(child)
9
+ }
10
+ return el
11
+ }
12
+
13
+ function t(content: string, props: Record<string, any> = {}) {
14
+ const el = createElement("text")
15
+ el.content = content
16
+ spread(el, props)
17
+ return el
18
+ }
19
+
20
+ function box(props: Record<string, any> = {}, ...children: any[]) {
21
+ return h("box", props, children.flat())
22
+ }
23
+
24
+ function text(content: string, props: Record<string, any> = {}) {
25
+ return t(content, props)
26
+ }
27
+
3
28
  const tui: TuiPlugin = async (api) => {
4
- api.slots.register({
5
- sidebar_content: () => (
6
- <Box flexDirection="column">
7
- <Box border="all" borderStyle="single" paddingX={1} paddingY={0}>
8
- <Text bold>EchoesVault</Text>
9
- </Box>
10
- <Box paddingX={1}>
11
- <Text dim>Status here</Text>
12
- </Box>
13
- </Box>
14
- ),
15
- })
29
+ const KV = "echoes_vault"
30
+
31
+ type VaultState = {
32
+ initialized: boolean
33
+ sessionActive: boolean
34
+ pagesCount: number
35
+ lastSession: string | null
36
+ }
37
+
38
+ let vault: VaultState = {
39
+ initialized: false,
40
+ sessionActive: false,
41
+ pagesCount: 0,
42
+ lastSession: null,
43
+ }
44
+
45
+ try {
46
+ const saved = api.kv.get<VaultState>(KV)
47
+ if (saved) vault = saved
48
+
49
+ api.event.on("session.created", () => {
50
+ vault.sessionActive = true
51
+ vault.lastSession = new Date().toISOString().slice(0, 10)
52
+ try { api.kv.set(KV, vault) } catch {}
53
+ })
54
+
55
+ api.event.on("session.deleted", () => {
56
+ vault.sessionActive = false
57
+ try { api.kv.set(KV, vault) } catch {}
58
+ })
59
+
60
+ api.event.on("session.idle", () => {
61
+ vault.sessionActive = false
62
+ try { api.kv.set(KV, vault) } catch {}
63
+ })
64
+
65
+ api.slots.register({
66
+ sidebar_content: ({ session_id }: { session_id: string }) => {
67
+ const sessionInfo = session_id ? api.state.session.get(session_id) : undefined
68
+ const title = sessionInfo?.title ?? "—"
69
+ const count = vault.pagesCount
70
+ const statusLine = vault.sessionActive ? `Session: ${title}` : "Idle"
71
+ const pagesLine = count > 0 ? ` · ${count} pages` : ""
72
+
73
+ return box(
74
+ { flexDirection: "column" },
75
+ box(
76
+ { border: "all" as any, borderStyle: "single" as any, paddingX: 1, paddingY: 0 },
77
+ text("EchoesVault"),
78
+ ),
79
+ box(
80
+ { paddingX: 1 },
81
+ text(`${statusLine}${pagesLine}`, { dim: true }),
82
+ ),
83
+ box(
84
+ { paddingX: 1, paddingY: 0 },
85
+ text("/echoes-init /echoes-start /echoes-end /echoes-status", { dim: true }),
86
+ ),
87
+ )
88
+ },
89
+ })
90
+ } catch (error) {
91
+ console.error("[echoes-vault] TUI init failed:", error)
92
+ }
16
93
  }
17
94
 
18
95
  export default { tui }