@hoox-sh/hoox-tui 0.2.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.
Files changed (104) hide show
  1. package/README.md +247 -0
  2. package/bin/hoox-tui.js +35 -0
  3. package/dist/main.js +17594 -0
  4. package/package.json +72 -0
  5. package/src/app.tsx +696 -0
  6. package/src/cli-bridge-test-double.ts +212 -0
  7. package/src/components/layout/layout.test.tsx +205 -0
  8. package/src/components/layout/sidebar.tsx +69 -0
  9. package/src/components/layout/statusbar.test.tsx +423 -0
  10. package/src/components/layout/statusbar.tsx +348 -0
  11. package/src/components/shared/animated-border.tsx +58 -0
  12. package/src/components/shared/chrome.test.tsx +29 -0
  13. package/src/components/shared/command-palette.tsx +361 -0
  14. package/src/components/shared/cool-brackets.tsx +75 -0
  15. package/src/components/shared/crash-screen.tsx +167 -0
  16. package/src/components/shared/error-boundary.tsx +99 -0
  17. package/src/components/shared/keybinding-hint.tsx +37 -0
  18. package/src/components/shared/panel.tsx +61 -0
  19. package/src/components/shared/quit-modal.tsx +65 -0
  20. package/src/components/shared/shared.test.tsx +538 -0
  21. package/src/components/shared/spinner.tsx +85 -0
  22. package/src/components/shared/status-dot.tsx +54 -0
  23. package/src/components/shared/view-header.tsx +53 -0
  24. package/src/components/ui/connection-toasts.test.ts +50 -0
  25. package/src/components/ui/connection-toasts.ts +215 -0
  26. package/src/components/ui/dialog.tsx +281 -0
  27. package/src/components/ui/select.tsx +197 -0
  28. package/src/components/ui/toast.tsx +185 -0
  29. package/src/components/views/ai-chat.test.tsx +81 -0
  30. package/src/components/views/ai-chat.tsx +576 -0
  31. package/src/components/views/config-editor/action-bar.tsx +102 -0
  32. package/src/components/views/config-editor/code-editor.tsx +597 -0
  33. package/src/components/views/config-editor/file-tree.tsx +113 -0
  34. package/src/components/views/config-editor/types.ts +37 -0
  35. package/src/components/views/config-editor.test.tsx +465 -0
  36. package/src/components/views/config-editor.tsx +709 -0
  37. package/src/components/views/dashboard/alerts-panel.tsx +154 -0
  38. package/src/components/views/dashboard/auto-repair-panel.tsx +229 -0
  39. package/src/components/views/dashboard/model-health-section.tsx +276 -0
  40. package/src/components/views/dashboard/pyne-health-section.tsx +112 -0
  41. package/src/components/views/dashboard.test.tsx +347 -0
  42. package/src/components/views/dashboard.tsx +647 -0
  43. package/src/components/views/db-query.test.tsx +115 -0
  44. package/src/components/views/db-query.tsx +849 -0
  45. package/src/components/views/edge-topology.test.tsx +198 -0
  46. package/src/components/views/edge-topology.tsx +572 -0
  47. package/src/components/views/kv-viewer.test.tsx +241 -0
  48. package/src/components/views/kv-viewer.tsx +717 -0
  49. package/src/components/views/logs-viewer.test.tsx +273 -0
  50. package/src/components/views/logs-viewer.tsx +616 -0
  51. package/src/components/views/queue-depth.test.tsx +221 -0
  52. package/src/components/views/queue-depth.tsx +376 -0
  53. package/src/components/views/secrets-viewer.test.tsx +65 -0
  54. package/src/components/views/secrets-viewer.tsx +548 -0
  55. package/src/components/views/service-manager.test.tsx +358 -0
  56. package/src/components/views/service-manager.tsx +946 -0
  57. package/src/components/views/settings.test.tsx +648 -0
  58. package/src/components/views/settings.tsx +1497 -0
  59. package/src/components/views/setup-wizard.test.tsx +297 -0
  60. package/src/components/views/setup-wizard.tsx +1321 -0
  61. package/src/components/views/trade-monitor.test.tsx +592 -0
  62. package/src/components/views/trade-monitor.tsx +745 -0
  63. package/src/components/views/worker-detail.test.tsx +289 -0
  64. package/src/components/views/worker-detail.tsx +676 -0
  65. package/src/components/views/worker-settings.test.tsx +43 -0
  66. package/src/components/views/worker-settings.tsx +563 -0
  67. package/src/components/views/workers-overview.test.tsx +260 -0
  68. package/src/components/views/workers-overview.tsx +631 -0
  69. package/src/hooks/hooks.test.ts +72 -0
  70. package/src/hooks/index.ts +11 -0
  71. package/src/hooks/renderer-ref.ts +22 -0
  72. package/src/hooks/use-keyboard.ts +130 -0
  73. package/src/hooks/use-polling.ts +73 -0
  74. package/src/hooks/use-service-data.ts +18 -0
  75. package/src/main.tsx +117 -0
  76. package/src/network-test-double.ts +133 -0
  77. package/src/opentui-augment.d.ts +45 -0
  78. package/src/opentui-jsx.d.ts +70 -0
  79. package/src/services/cli-bridge/index.ts +1662 -0
  80. package/src/services/cli-bridge/standalone.ts +315 -0
  81. package/src/services/cli-bridge/types.ts +307 -0
  82. package/src/services/cli-bridge.test.ts +406 -0
  83. package/src/services/clipboard.test.ts +57 -0
  84. package/src/services/clipboard.ts +180 -0
  85. package/src/services/dashboard-settings-loader.ts +31 -0
  86. package/src/services/dev-log.test.ts +168 -0
  87. package/src/services/dev-log.ts +194 -0
  88. package/src/services/hoox-path-service.test.ts +183 -0
  89. package/src/services/hoox-path-service.ts +185 -0
  90. package/src/services/tui-connection.test.ts +212 -0
  91. package/src/services/tui-connection.ts +236 -0
  92. package/src/services/tui-storage.test.ts +92 -0
  93. package/src/services/tui-storage.ts +86 -0
  94. package/src/stores/config-store.test.ts +360 -0
  95. package/src/stores/service-store.test.ts +1026 -0
  96. package/src/stores/session-restore.test.ts +134 -0
  97. package/src/stores/ui-store.test.ts +276 -0
  98. package/src/test-setup.ts +265 -0
  99. package/src/test-utils.ts +179 -0
  100. package/src/types.ts +153 -0
  101. package/src/utils/colors.test.ts +326 -0
  102. package/src/utils/formatters.test.ts +236 -0
  103. package/src/view-registry.test.ts +132 -0
  104. package/src/view-registry.tsx +368 -0
package/README.md ADDED
@@ -0,0 +1,247 @@
1
+ # Hoox TUI
2
+
3
+ **Terminal Operations Center** for the Hoox algorithmic trading framework.
4
+ A full-screen terminal dashboard built with [OpenTUI](https://github.com/anomalyco/opentui), [Bun](https://bun.sh), and [Zustand](https://zustand.docs.pmnd.rs/).
5
+
6
+ ---
7
+
8
+ ## Quick Start
9
+
10
+ ### Outside a monorepo (recommended for operators)
11
+
12
+ ```bash
13
+ # CLI + TUI as global packages
14
+ bun add -g @hoox-sh/hoox-cli @hoox-sh/hoox-tui
15
+ # or after CLI is already installed:
16
+ bun add -g @hoox-sh/hoox-tui
17
+
18
+ hx tui
19
+ ```
20
+
21
+ If the TUI package is missing, `hx tui` prints install instructions.
22
+ Full monorepo under `~/.hoox/repo` is optional (`hx doctor --fix-runtime`).
23
+
24
+ ### From this monorepo
25
+
26
+ ```bash
27
+ # Install dependencies (from repo root)
28
+ bun install
29
+
30
+ # Launch via CLI (recommended) — LOCAL → http://localhost:8787
31
+ hoox tui
32
+
33
+ # Connect to remote management plane (REMOTE) — fail-closed auth
34
+ # Server secret: wrangler secret put OPERATOR_API_KEY (must match token)
35
+ export HOOX_API_TOKEN=… # required (or Access service-token env)
36
+ # Optional Access: CF_ACCESS_CLIENT_ID + CF_ACCESS_CLIENT_SECRET
37
+ # Optional: HOOX_TRANSPORT=access
38
+ hoox tui --remote
39
+ # or: hoox tui --api-url https://mgmt.example.com --token "$HOOX_API_TOKEN"
40
+ # Escape hatch only: hoox tui --remote --allow-insecure
41
+ # Management API: GET /v1/health, /v1/workers, SSE /v1/trades|logs/stream
42
+
43
+ # Dev logging → $HOME/.hoox/.tui-state/debug.log (secrets redacted)
44
+ hoox tui --debug
45
+ # or: HOOX_DEBUG=1 / TUI_DEBUG=1
46
+
47
+ # Or launch from package
48
+ cd packages/tui
49
+ bun run dev
50
+
51
+ # Build bundle
52
+ bun run build
53
+
54
+ # Run the built bundle
55
+ bun run start
56
+ ```
57
+
58
+ **Prerequisites:**
59
+
60
+ - [Bun](https://bun.sh) >= 1.2
61
+ - Terminal with 256-color support (xterm-256color, kitty, iTerm2, Windows Terminal)
62
+ - Minimum terminal size: 80 columns × 24 rows
63
+ - OpenTUI packages (`@opentui/core`, `@opentui/react`) — installed via `bun install`
64
+
65
+ Persistent UI state lives under `$HOME/.hoox/.tui-state/` (session, crash log, chat history, DB query history).
66
+
67
+ ---
68
+
69
+ ## Keyboard Shortcuts
70
+
71
+ | Key | Action |
72
+ | ------------------- | ---------------------------------------- |
73
+ | `Ctrl+1` | Dashboard view |
74
+ | `Ctrl+2` | Workers Overview |
75
+ | `Ctrl+3` | Worker Detail |
76
+ | `Ctrl+4` | Trade Monitor |
77
+ | `Ctrl+5` | Logs Viewer |
78
+ | `Ctrl+6` | Service Manager |
79
+ | `Ctrl+7` | Config Editor |
80
+ | `Ctrl+8` | Setup Wizard |
81
+ | `Ctrl+9` | Settings |
82
+ | `Ctrl+0` | Queue Depth |
83
+ | `Ctrl+Alt+K` | KV Viewer |
84
+ | `Ctrl+Alt+S` | Secrets Viewer |
85
+ | `Ctrl+Alt+C` | AI Chat |
86
+ | `Ctrl+Alt+Q` | DB Query |
87
+ | `Ctrl+Alt+E` | Edge Topology |
88
+ | `Ctrl+Alt+W` | Worker Settings (dashboard.jsonc) |
89
+ | `Ctrl+P` | Open Command Palette |
90
+ | `Ctrl+B` | Toggle Sidebar |
91
+ | `Ctrl+R` | Refresh all data |
92
+ | `Ctrl+Q` | Quit (with confirmation) |
93
+ | `Esc` | Close palette / dismiss modal / go back |
94
+ | `↑` `↓` | Navigate within active view |
95
+ | `Tab` / `Shift+Tab` | Cycle focus between interactive elements |
96
+ | `Enter` | Select / confirm |
97
+ | `Space` | Toggle |
98
+ | `/` | Focus search (in searchable views) |
99
+
100
+ ---
101
+
102
+ ## Views
103
+
104
+ | View | Description |
105
+ | -------------------- | -------------------------------------------------------------------------------------------------- |
106
+ | **Dashboard** | System health overview: service grid, alerts, quick stats, agent health, and **PYNE** edge health. |
107
+ | **Workers Overview** | List of all Cloudflare Workers with status, uptime, CPU, memory, and request metrics. |
108
+ | **Worker Detail** | Detailed view of a single worker — logs, metrics, Durable Objects, and deployment info. |
109
+ | **Trade Monitor** | Live trade stream with symbol, side, price, quantity, and P&L per trade. |
110
+ | **Logs Viewer** | Scrollable log stream with level filtering, worker selection, and full-text search. |
111
+ | **Service Manager** | Start, stop, restart, and deploy workers. View deployment history and rollback. |
112
+ | **Config Editor** | Edit Hoox configuration — exchange credentials, strategy parameters, risk limits. |
113
+ | **Setup Wizard** | Step-by-step guided setup for new Hoox installations (API keys, exchanges, wallet). |
114
+ | **Settings** | Display preferences, theme, notification toggles, and keyboard shortcut customization. |
115
+ | **Queue Depth** | Queue backlog visualization across workers. |
116
+ | **KV Viewer** | Read-only Cloudflare KV key browser. |
117
+ | **Secrets Viewer** | Read-only secret names/metadata (values never shown). |
118
+ | **AI Chat** | Streaming chat with the agent worker. |
119
+ | **DB Query** | Read-only D1 SQL panel (`SELECT` / `WITH` / `EXPLAIN` only). |
120
+ | **Edge Topology** | Worker mesh / service-binding graph. |
121
+ | **Worker Settings** | Same settings as the web dashboard — fields from `workers/*/dashboard.jsonc` backed by CONFIG_KV. |
122
+
123
+ ---
124
+
125
+ ## Tech Stack
126
+
127
+ | Component | Technology |
128
+ | -------------------- | ---------------------------------------------------------------------------- |
129
+ | **TUI Framework** | OpenTUI — `@opentui/core` + `@opentui/react` (JSX-based terminal rendering) |
130
+ | **Runtime** | [Bun](https://bun.sh) — fast all-in-one JS runtime |
131
+ | **State Management** | [Zustand](https://zustand.docs.pmnd.rs/) with Immer middleware |
132
+ | **Language** | TypeScript (strict mode) |
133
+ | **Testing** | Bun test runner (`bun test`) |
134
+ | **Build** | `bun build` — bundles entry to `dist/main.js` (OpenTUI packages external) |
135
+ | **Shared Module** | `@hoox-sh/hoox-shared` — API client, SSE streaming, color tokens, formatters |
136
+
137
+ ---
138
+
139
+ ## Running Tests
140
+
141
+ ```bash
142
+ # From package
143
+ cd packages/tui
144
+ bun test
145
+
146
+ # From monorepo root (recommended — includes preload)
147
+ bun run test:tui
148
+
149
+ # Scoped foundation suite (stores / utils / integration / registry)
150
+ bun test --preload ./packages/tui/src/test-setup.ts \
151
+ packages/tui/src/stores packages/tui/src/utils \
152
+ packages/tui/test packages/tui/src/view-registry.test.ts
153
+
154
+ # Typecheck
155
+ bun run typecheck
156
+
157
+ # E2E smoke (requires interactive TTY + OpenTUI)
158
+ bun test test/e2e/
159
+ ```
160
+
161
+ ---
162
+
163
+ ## Troubleshooting
164
+
165
+ ### "Cannot find module @opentui/core"
166
+
167
+ OpenTUI packages must be installed. Ensure `bun install` completed successfully.
168
+ If the packages are in a local path, verify the workspace configuration in the root `package.json`.
169
+
170
+ ### API unreachable (OFFLINE in status bar)
171
+
172
+ **Local:** HTTP first, then CLI `monitorStatus` fallback.
173
+ **Remote:** fail-closed HTTP only (no CLI fallback). Auth requires `HOOX_API_TOKEN`, Access env, or `--allow-insecure`.
174
+
175
+ 1. Is a local dev mesh / API reachable? (`HOOX_API_URL`, default `http://localhost:8787`)
176
+ 2. Remote: is `HOOX_API_TOKEN` set and matching server `OPERATOR_API_KEY`?
177
+ 3. Is the `hoox` CLI on `PATH` for local fallback? (`bun add -g @hoox-sh/hoox-cli`)
178
+ 4. Are you on the correct network / VPN?
179
+
180
+ ### Terminal too small
181
+
182
+ The TUI requires at least **80 columns × 24 rows**. Resize your terminal window.
183
+ If you see garbled output, try: `export TERM=xterm-256color`
184
+
185
+ ### Garbled screen after exit
186
+
187
+ If the alternate screen buffer isn't cleaned up, run: `reset` or `tput reset`
188
+
189
+ ### Ctrl+Q not working
190
+
191
+ Some terminal emulators intercept Ctrl+Q for flow control (XON/XOFF).
192
+ Disable flow control in your terminal settings, or use `stty -ixon` before launching.
193
+ You can also open the command palette (`Ctrl+P`) and run **QUIT HOOX**.
194
+
195
+ ### Build fails with missing dependencies
196
+
197
+ The `bun build` command bundles TypeScript sources with OpenTUI marked external. If dependencies aren't resolved:
198
+
199
+ ```bash
200
+ bun install
201
+ bun run build
202
+ ```
203
+
204
+ Ensure `@hoox-sh/hoox-shared` is linked as a workspace dependency.
205
+
206
+ ### Colors look wrong
207
+
208
+ The TUI uses 256-color ANSI escape sequences. Ensure:
209
+
210
+ - `TERM=xterm-256color` (or `kitty`, `screen-256color`)
211
+ - Your terminal supports 256 colors
212
+ - No conflicting terminal color schemes
213
+
214
+ ---
215
+
216
+ ## Project Structure
217
+
218
+ ```
219
+ packages/tui/
220
+ ├── src/
221
+ │ ├── main.tsx # Entry point — OpenTUI renderer setup
222
+ │ ├── app.tsx # Root component — layout, keyboard, crash recovery
223
+ │ ├── components/
224
+ │ │ ├── views/ # Dashboard, workers, trades, logs, queues, …
225
+ │ │ ├── layout/ # Sidebar + status bar
226
+ │ │ ├── shared/ # Palette, crash screen, error boundary, …
227
+ │ │ └── ui/ # Dialog / toast wrappers
228
+ │ ├── services/
229
+ │ │ ├── cli-bridge/ # Spawns `hoox` CLI with typed results
230
+ │ │ ├── hoox-path-service.ts # $HOME/.hoox path helpers
231
+ │ │ └── tui-storage.ts # File-backed JSON state (no localStorage)
232
+ │ ├── hooks/ # Keyboard, polling, renderer ref
233
+ │ └── stores/ # Store unit tests (stores live in hoox-shared)
234
+ ├── test/
235
+ │ ├── e2e/smoke.test.ts
236
+ │ └── integration/navigation.test.tsx
237
+ ├── package.json
238
+ └── README.md
239
+ ```
240
+
241
+ ---
242
+
243
+ ## Design
244
+
245
+ Near-black canvas (`#050508`), cool indigo accent (`#818CF8`) + cyan highlight,
246
+ static accent brackets on chrome (no rainbow animation), squared edges.
247
+ Follows the Hoox landing page design DNA. No CSS, no DOM — pure terminal rendering via OpenTUI's JSX intrinsics (`<box>`, `<text>`, `<input>`, `<scrollbox>`). UI persistence uses the filesystem under `$HOME/.hoox/.tui-state/` (Bun has no `localStorage`).
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * Copyright (c) 2026 HOOX · HOOX · jango-blockchained (hoox-sh)
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * Hoox TUI binary entry point.
8
+ *
9
+ * Resolution order (first match wins):
10
+ * 1. `../dist/main.js` — bundled output from `bun run build`
11
+ * 2. `../src/main.tsx` — monorepo / bun link dev path
12
+ * 3. Clear error with install/build instructions
13
+ */
14
+ import { existsSync } from "node:fs";
15
+ import { fileURLToPath } from "node:url";
16
+ import { dirname, resolve } from "node:path";
17
+
18
+ const here = dirname(fileURLToPath(import.meta.url));
19
+ const distEntry = resolve(here, "..", "dist", "main.js");
20
+ const srcEntry = resolve(here, "..", "src", "main.tsx");
21
+
22
+ if (existsSync(distEntry)) {
23
+ await import(distEntry);
24
+ } else if (existsSync(srcEntry)) {
25
+ await import(srcEntry);
26
+ } else {
27
+ console.error(
28
+ `hoox-tui: could not find an entry point. Looked for:\n` +
29
+ ` - ${distEntry}\n` +
30
+ ` - ${srcEntry}\n\n` +
31
+ `Install the package: bun add -g @hoox-sh/hoox-tui\n` +
32
+ `Or from the monorepo: cd packages/tui && bun run build`
33
+ );
34
+ process.exit(1);
35
+ }