@nxuss/lemma 1.33.0 → 1.35.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 (88) hide show
  1. package/README.md +39 -0
  2. package/bin/brain-ingest.js +28 -0
  3. package/bin/checkpoint.js +6 -0
  4. package/dashboard/README.md +28 -332
  5. package/dashboard/dist/assets/{index-Dh-whqJ7.js → index-euG1IvQ7.js} +82 -82
  6. package/dashboard/dist/index.html +1 -1
  7. package/dist/cjs/cli/hostHooks.d.ts +3 -1
  8. package/dist/cjs/cli/hostHooks.d.ts.map +1 -1
  9. package/dist/cjs/cli/hostHooks.js +31 -13
  10. package/dist/cjs/cli/hostHooks.js.map +1 -1
  11. package/dist/cjs/cli/lemma-proxy.d.ts.map +1 -1
  12. package/dist/cjs/cli/lemma-proxy.js +20 -1
  13. package/dist/cjs/cli/lemma-proxy.js.map +1 -1
  14. package/dist/cjs/mcp/index.js +2 -0
  15. package/dist/cjs/mcp/index.js.map +1 -1
  16. package/dist/cjs/mcp/staleBuild.d.ts +19 -0
  17. package/dist/cjs/mcp/staleBuild.d.ts.map +1 -1
  18. package/dist/cjs/mcp/staleBuild.js +73 -0
  19. package/dist/cjs/mcp/staleBuild.js.map +1 -1
  20. package/dist/cjs/mcp/tools/memory.d.ts.map +1 -1
  21. package/dist/cjs/mcp/tools/memory.js +84 -13
  22. package/dist/cjs/mcp/tools/memory.js.map +1 -1
  23. package/dist/cjs/proxy/DebuggerState.d.ts +3 -0
  24. package/dist/cjs/proxy/DebuggerState.d.ts.map +1 -0
  25. package/dist/cjs/proxy/DebuggerState.js +18 -0
  26. package/dist/cjs/proxy/DebuggerState.js.map +1 -0
  27. package/dist/cjs/subconscious/ExternalRefs.d.ts +47 -0
  28. package/dist/cjs/subconscious/ExternalRefs.d.ts.map +1 -0
  29. package/dist/cjs/subconscious/ExternalRefs.js +131 -0
  30. package/dist/cjs/subconscious/ExternalRefs.js.map +1 -0
  31. package/dist/cjs/subconscious/HostRecall.d.ts +22 -0
  32. package/dist/cjs/subconscious/HostRecall.d.ts.map +1 -1
  33. package/dist/cjs/subconscious/HostRecall.js +96 -0
  34. package/dist/cjs/subconscious/HostRecall.js.map +1 -1
  35. package/dist/cjs/subconscious/TheBrainV2.d.ts +16 -0
  36. package/dist/cjs/subconscious/TheBrainV2.d.ts.map +1 -1
  37. package/dist/cjs/subconscious/TheBrainV2.js +17 -0
  38. package/dist/cjs/subconscious/TheBrainV2.js.map +1 -1
  39. package/dist/cjs/utils/StoreDraft.d.ts +26 -0
  40. package/dist/cjs/utils/StoreDraft.d.ts.map +1 -0
  41. package/dist/cjs/utils/StoreDraft.js +81 -0
  42. package/dist/cjs/utils/StoreDraft.js.map +1 -0
  43. package/dist/cjs/utils/ageLabel.d.ts +3 -0
  44. package/dist/cjs/utils/ageLabel.d.ts.map +1 -0
  45. package/dist/cjs/utils/ageLabel.js +17 -0
  46. package/dist/cjs/utils/ageLabel.js.map +1 -0
  47. package/dist/esm/cli/hostHooks.d.ts +3 -1
  48. package/dist/esm/cli/hostHooks.d.ts.map +1 -1
  49. package/dist/esm/cli/hostHooks.js +30 -12
  50. package/dist/esm/cli/hostHooks.js.map +1 -1
  51. package/dist/esm/cli/lemma-proxy.d.ts.map +1 -1
  52. package/dist/esm/cli/lemma-proxy.js +20 -1
  53. package/dist/esm/cli/lemma-proxy.js.map +1 -1
  54. package/dist/esm/mcp/index.js +2 -0
  55. package/dist/esm/mcp/index.js.map +1 -1
  56. package/dist/esm/mcp/staleBuild.d.ts +19 -0
  57. package/dist/esm/mcp/staleBuild.d.ts.map +1 -1
  58. package/dist/esm/mcp/staleBuild.js +70 -0
  59. package/dist/esm/mcp/staleBuild.js.map +1 -1
  60. package/dist/esm/mcp/tools/memory.d.ts.map +1 -1
  61. package/dist/esm/mcp/tools/memory.js +84 -13
  62. package/dist/esm/mcp/tools/memory.js.map +1 -1
  63. package/dist/esm/proxy/DebuggerState.d.ts +3 -0
  64. package/dist/esm/proxy/DebuggerState.d.ts.map +1 -0
  65. package/dist/esm/proxy/DebuggerState.js +14 -0
  66. package/dist/esm/proxy/DebuggerState.js.map +1 -0
  67. package/dist/esm/subconscious/ExternalRefs.d.ts +47 -0
  68. package/dist/esm/subconscious/ExternalRefs.d.ts.map +1 -0
  69. package/dist/esm/subconscious/ExternalRefs.js +124 -0
  70. package/dist/esm/subconscious/ExternalRefs.js.map +1 -0
  71. package/dist/esm/subconscious/HostRecall.d.ts +22 -0
  72. package/dist/esm/subconscious/HostRecall.d.ts.map +1 -1
  73. package/dist/esm/subconscious/HostRecall.js +93 -0
  74. package/dist/esm/subconscious/HostRecall.js.map +1 -1
  75. package/dist/esm/subconscious/TheBrainV2.d.ts +16 -0
  76. package/dist/esm/subconscious/TheBrainV2.d.ts.map +1 -1
  77. package/dist/esm/subconscious/TheBrainV2.js +17 -0
  78. package/dist/esm/subconscious/TheBrainV2.js.map +1 -1
  79. package/dist/esm/utils/StoreDraft.d.ts +26 -0
  80. package/dist/esm/utils/StoreDraft.d.ts.map +1 -0
  81. package/dist/esm/utils/StoreDraft.js +74 -0
  82. package/dist/esm/utils/StoreDraft.js.map +1 -0
  83. package/dist/esm/utils/ageLabel.d.ts +3 -0
  84. package/dist/esm/utils/ageLabel.d.ts.map +1 -0
  85. package/dist/esm/utils/ageLabel.js +14 -0
  86. package/dist/esm/utils/ageLabel.js.map +1 -0
  87. package/package.json +4 -2
  88. package/dashboard/dist/assets/index-Dh-whqJ7.js.map +0 -1
package/README.md CHANGED
@@ -35,6 +35,19 @@ lemma start # gateway + dashboard on http://localhost:8081
35
35
  >
36
36
  > **🆕 v1.22.0 — Lemma auto-activates in every LLM client.** `npm i -g @nxuss/lemma` registers the skill in your **user** catalog (auto-loads in every `muse` session, any project) and `lemma init` wires each project for Muse, Claude Code, Cursor, Codex, Windsurf, Kiro and OpenCode. Health check: `lemma doctor`.
37
37
  >
38
+ > **🆕 v1.35.0 — recall *before* the answer, and memories that notice when the world moved.** A
39
+ > status question ("what's still pending?") touches no file, so no post-tool hook ever fired for it
40
+ > and an agent answered from stale notes. `lemma init` now also installs a `UserPromptSubmit` hook
41
+ > that names the memories bearing on the prompt (with age and freshness) and reminds the agent to
42
+ > verify live git/CI state for status questions. `store_memory` takes `refs` — a commit, or an MR /
43
+ > issue with the state it asserts — and `verify_memory` checks them (`git`, `gh`, `glab`; anything it
44
+ > cannot read is `unverified`, never `fresh`). Also: `search_memory` shows each hit's age and lists
45
+ > below-floor near-misses as orientation only, `get_memory` stops saying "tracks nothing" for
46
+ > claim-tracked entries, `lemma-checkpoint` leaves a store draft the next prompt surfaces once, and a
47
+ > stale MCP build is reported by the prompt hook. Re-run `lemma init` after updating.
48
+ >
49
+ > **🆕 v1.34.0 — Dashboard fixes.** The header shows the real running version (from `/health`), the debugger's pause/resume now works against the proxy, the Vite dev proxy points at the right port, and `npm run build` rebuilds the dashboard so the published UI is never stale.
50
+ >
38
51
  > **🆕 v1.33.0 — C# (.NET) support, honestly labeled.** New per-project language detection
39
52
  > (`.csproj/.sln`, target frameworks, mixed repos) and a read-only `capability_matrix` tool so clients
40
53
  > stop guessing what works outside TypeScript. `get_ast_hologram` and `get_symbol_surgical_context` now
@@ -170,6 +183,14 @@ lemma start # gateway + dashboard on http://localhost:8081
170
183
  are recovered from the command; OpenCode gets a plugin, since it has no hook protocol.
171
184
  Windsurf/Devin post-hooks can't inject context, and Kiro's hooks spend tokens by design, so
172
185
  neither is wired.
186
+ - **Recall before the agent answers, and memories that know when the world moved** — a
187
+ `UserPromptSubmit` hook (`lemma-brain-ingest --prompt-submit`, Claude Code) points at the
188
+ memories a prompt substantially covers and, for status-style questions, says to verify live state
189
+ first: file-hash freshness can't see an MR merge. `store_memory` / `update_memory` accept
190
+ `refs` (`{kind:'commit',sha}`, or `{kind:'mr'|'issue',provider,id,state}`), and `verify_memory`
191
+ checks them with `git` / `gh` / `glab` — stale when they moved, `unverified` (never `fresh`) when
192
+ they can't be read. The session-end checkpoint leaves a one-shot reminder to store what was
193
+ verified.
173
194
  - **A team Brain, shared through git** — `brain_team push` writes this project's fresh, tracked
174
195
  memories to `.lemma-brain/memories/<id>.json`: one sorted-key JSON file per memory, so two people
175
196
  sharing at once never conflict, every shared memory goes through code review, and deleting one is
@@ -292,6 +313,7 @@ lemma_toolbox { "action": "call", "tool": "terraform_drift", "args": {} }
292
313
  | `lemma activate <key>` | Activate a Pro license. |
293
314
  | `lemma-checkpoint [projectRoot]` | Derive a session checkpoint from repo state (branch, changed files, commits) with no assistant call. |
294
315
  | `lemma-brain-ingest [projectRoot] [--changelog] [--team-pull]` | Feed The Brain from git commits and `CHANGELOG.md`, incrementally; `--team-pull` imports the repo's `.lemma-brain/`. |
316
+ | `lemma-brain-ingest --prompt-submit` | Read a Claude Code `UserPromptSubmit` payload on stdin and reply with the memories that bear on the prompt (id, age, freshness) plus, for a "what is pending" question, a reminder to verify live git/CI state — or nothing. Also surfaces the last session's store draft and a stale MCP build, once each. |
295
317
  | `lemma-brain-ingest --hook-result [--host=claude\|codex\|cursor\|opencode]` | Read a host post-tool payload on stdin: capture red → green fixes from the agent's own shell, and reply with a Brain note (memory ids, failed attempts, known fixes) in that host's format — or nothing. |
296
318
 
297
319
  Wire the standalone bins into hooks so memory doesn't depend on the assistant remembering to call a tool:
@@ -309,6 +331,23 @@ Wire the standalone bins into hooks so memory doesn't depend on the assistant re
309
331
  "hooks": [{ "type": "command", "command": "lemma-brain-ingest --hook-result" }] }] } }
310
332
  ```
311
333
 
334
+ ```jsonc
335
+ // …and the same file gets the recall-before-answer hook (no matcher: it fires on every prompt)
336
+ { "hooks": { "UserPromptSubmit": [{ "hooks": [{ "type": "command",
337
+ "command": "lemma-brain-ingest --prompt-submit" }] }] } }
338
+ ```
339
+
340
+ Attach external state when you store something whose truth depends on it, so `verify_memory` can
341
+ tell when it goes stale:
342
+
343
+ ```jsonc
344
+ // store_memory arguments (excerpt)
345
+ { "refs": [
346
+ { "kind": "commit", "sha": "2c8a8cb" }, // holds while an ancestor of HEAD
347
+ { "kind": "mr", "provider": "gitlab", "id": "1061", "state": "merged" } // stale once its state differs
348
+ ] }
349
+ ```
350
+
312
351
  Codex (`~/.codex/hooks.json`, `--host=codex`), Cursor (`~/.cursor/hooks.json`, `postToolUse` +
313
352
  `postToolUseFailure`, `--host=cursor`) and OpenCode (a plugin in `~/.config/opencode/plugins/`) are
314
353
  wired the same way by `lemma init` when their config directory exists. Existing hooks are kept;
@@ -15,6 +15,7 @@
15
15
  *
16
16
  * Usage: lemma-brain-ingest [projectRoot] [--max N] [--changelog] [--no-commits] [--team-pull]
17
17
  * lemma-brain-ingest --hook-result [--host=claude|codex|cursor|opencode] < payload.json
18
+ * lemma-brain-ingest --prompt-submit < payload.json
18
19
  *
19
20
  * --team-pull Import the repo's shared memories from .lemma-brain/ (post-merge/post-checkout).
20
21
  * --hook-result Read a host PostToolUse hook payload on stdin (Claude Code shape) and:
@@ -29,6 +30,13 @@
29
30
  * `lemma init` wires it for each host it finds, e.g. .claude/settings.local.json:
30
31
  * "hooks": { "PostToolUse": [{ "matcher": "Bash|Read|Edit|MultiEdit|Write|NotebookEdit",
31
32
  * "hooks": [{ "type": "command", "command": "lemma-brain-ingest --hook-result" }] }] }
33
+ * --prompt-submit Read a Claude Code UserPromptSubmit payload on stdin and answer with the
34
+ * Brain's memories that bear on the prompt (ids, age, freshness) plus, for a
35
+ * "what is pending" style question, a reminder to verify live state with
36
+ * git/gh/glab. This is the recall point that exists before the agent answers: a
37
+ * status question touches no file, so no PostToolUse hook ever fires for it.
38
+ * Silent when nothing matches. Wired by `lemma init` in
39
+ * .claude/settings.local.json under hooks.UserPromptSubmit.
32
40
  */
33
41
 
34
42
  const path = require('path');
@@ -72,8 +80,28 @@ function hookResult(args) {
72
80
  if (out) process.stdout.write(out);
73
81
  }
74
82
 
83
+ function promptSubmit() {
84
+ const dist = path.join(__dirname, '..', 'dist', 'cjs');
85
+ let recallForPrompt, formatHostOutput;
86
+ try {
87
+ ({ recallForPrompt } = require(path.join(dist, 'subconscious', 'HostRecall.js')));
88
+ ({ formatHostOutput } = require(path.join(dist, 'subconscious', 'HostAdapters.js')));
89
+ } catch {
90
+ return; // no build — a hook must stay silent and harmless
91
+ }
92
+ let payload;
93
+ try {
94
+ payload = JSON.parse(readStdin());
95
+ } catch {
96
+ return;
97
+ }
98
+ const out = formatHostOutput('claude', recallForPrompt(payload, payload && payload.cwd, undefined, { mcpEntry: path.join(dist, 'mcp', 'index.js') }), 'UserPromptSubmit');
99
+ if (out) process.stdout.write(out);
100
+ }
101
+
75
102
  function main() {
76
103
  const args = process.argv.slice(2);
104
+ if (args.includes('--prompt-submit')) return promptSubmit();
77
105
  if (args.includes('--hook-result')) return hookResult(args);
78
106
  const maxIndex = args.indexOf('--max');
79
107
  const maxCommits = maxIndex >= 0 ? parseInt(args[maxIndex + 1], 10) : undefined;
package/bin/checkpoint.js CHANGED
@@ -35,6 +35,12 @@ function main() {
35
35
  console.error('[lemma-checkpoint] Not a git repository — nothing to capture.');
36
36
  return;
37
37
  }
38
+ // Leave a draft for the next session's first prompt: a SessionEnd hook can't speak to the
39
+ // model, and what was verified this session is exactly what a later status question needs.
40
+ try {
41
+ const { writeStoreDraft } = require(path.join(__dirname, '..', 'dist', 'cjs', 'utils', 'StoreDraft.js'));
42
+ writeStoreDraft(projectRoot);
43
+ } catch { /* the draft is a courtesy */ }
38
44
  console.error(
39
45
  `[lemma-checkpoint] Saved: ${result.filesModified.length} file(s) changed → ${path.join(projectRoot, '.lemma/session')}`
40
46
  );
@@ -1,351 +1,47 @@
1
1
  # Lemma Dashboard
2
2
 
3
- Real-time visualization and monitoring dashboard for the Lemma agent orchestration hub.
3
+ Live view of a running Lemma proxy: token savings, cache behaviour, connected agents, MCP
4
+ activity and the Brain's knowledge base.
4
5
 
5
- ## Features
6
+ The proxy serves the production build itself at `http://localhost:8081/dashboard/`
7
+ (`lemma start`). The version shown in the header comes from the proxy's `/health`.
6
8
 
7
- ### 1. Agent Graph
8
- - Live visualization of connected agents
9
- - Node graph showing agent relationships
10
- - Real-time status updates (active, idle, busy)
11
- - Agent capabilities display
12
- - Connection lines to central hub
9
+ ## Panels
13
10
 
14
- ### 2. Token Economics
15
- - Real-time cost savings tracking
16
- - Token usage metrics
17
- - Cache hit rate visualization
18
- - Performance charts:
19
- - Cache performance over time
20
- - Latency trends
21
- - Cumulative cost savings
22
- - ROI calculator with projections
11
+ - **Metrics bar / charts** — requests, hit rate, latency, tokens and cost saved
12
+ (`/api/metrics`, `/api/cache-stats`, `/api/savings-breakdown`).
13
+ - **The Hub** — connected agents (`/api/agents`), charts, savings breakdown, Brain knowledge
14
+ stats (`/api/brain/stats`), cache stats and the event timeline (`/api/events`).
15
+ - **The Tools** — live feed of MCP tool calls; the header badge shows MCP status
16
+ (`/api/mcp-status`) and toggles it (`/api/mcp/toggle`).
17
+ - **The Brain** — semantic search over the cache (`/api/search`).
18
+ - **Debugger** (bottom panel) — pause/resume. While paused the proxy refuses new completions
19
+ with `503` + `Retry-After` (`/api/debugger/pause|resume|state`).
20
+ - **Flush Cache** — `/api/cache/clear`.
23
21
 
24
- ### 3. Time-Travel Debugger
25
- - Event timeline with all agent interactions
26
- - State inspector for any point in time
27
- - Playback controls (pause, step back/forward)
28
- - State editing capabilities
29
- - Event filtering by type
22
+ `TimeTravel.tsx` and the rewind call (`/api/debugger/rewind`) exist in the code but are not
23
+ wired into the proxy: rewind is only implemented by the standalone API server
24
+ (`src/api/dashboardRoutes.ts`).
30
25
 
31
- ## Quick Start
32
-
33
- ### Installation
26
+ ## Develop
34
27
 
35
28
  ```bash
36
- cd dashboard
37
29
  npm install
30
+ npm run dev # Vite on http://localhost:8082/dashboard/
38
31
  ```
39
32
 
40
- ### Development
41
-
42
- ```bash
43
- npm run dev
44
- ```
45
-
46
- Dashboard will be available at `http://localhost:3000`
33
+ The dev server talks to the proxy on `http://localhost:8081` (start it with `lemma start`).
34
+ Override with `VITE_API_URL` / `VITE_WS_URL` in `.env`.
47
35
 
48
- ### Production Build
36
+ ## Build
49
37
 
50
38
  ```bash
51
- npm run build
52
- npm run preview
53
- ```
54
-
55
- ## Configuration
56
-
57
- Create a `.env` file:
58
-
59
- ```env
60
- VITE_ROUTER_URL=ws://localhost:8080
61
- VITE_API_URL=http://localhost:8080
62
- ```
63
-
64
- ## Architecture
65
-
66
- ### Tech Stack
67
-
68
- - **React 18**: UI framework
69
- - **TypeScript**: Type safety
70
- - **Vite**: Build tool and dev server
71
- - **TailwindCSS**: Styling
72
- - **Recharts**: Data visualization
73
- - **Zustand**: State management
74
- - **WebSocket**: Real-time communication
75
-
76
- ### Project Structure
77
-
78
- ```
79
- dashboard/
80
- ├── src/
81
- │ ├── components/
82
- │ │ ├── AgentGraph.tsx # Agent visualization
83
- │ │ ├── MetricsPanel.tsx # Token economics
84
- │ │ ├── TimeTravel.tsx # State debugger
85
- │ │ ├── ConnectionStatus.tsx # WebSocket status
86
- │ │ └── Layout.tsx # App layout
87
- │ ├── hooks/
88
- │ │ └── useWebSocket.ts # WebSocket connection
89
- │ ├── App.tsx # Main app component
90
- │ ├── main.tsx # Entry point
91
- │ └── index.css # Global styles
92
- ├── index.html
93
- ├── package.json
94
- ├── tsconfig.json
95
- ├── vite.config.ts
96
- └── tailwind.config.js
97
- ```
98
-
99
- ## WebSocket Protocol
100
-
101
- The dashboard connects to the Lemma router via WebSocket and exchanges IAP (Inter-Agent Protocol) messages.
102
-
103
- ### Connection
104
-
105
- ```typescript
106
- const ws = new WebSocket('ws://localhost:8080');
107
-
108
- // Send handshake
109
- ws.send(JSON.stringify({
110
- type: 'HANDSHAKE',
111
- messageId: crypto.randomUUID(),
112
- timestamp: Date.now(),
113
- payload: {
114
- agentId: 'dashboard-client',
115
- agentName: 'Dashboard',
116
- version: '1.0.0',
117
- capabilities: [{ name: 'monitoring', version: '1.0.0' }],
118
- },
119
- }));
39
+ npm run build # tsc + vite build -> dist/
120
40
  ```
121
41
 
122
- ### Message Types
123
-
124
- #### Metrics Update
125
- ```json
126
- {
127
- "type": "METRICS_UPDATE",
128
- "payload": {
129
- "totalRequests": 1000,
130
- "cacheHits": 800,
131
- "cacheMisses": 200,
132
- "averageLatency": 45.2,
133
- "tokensSaved": 150000,
134
- "costSaved": 0.3,
135
- "hitRate": "80.0%"
136
- }
137
- }
138
- ```
139
-
140
- #### Agent Connected
141
- ```json
142
- {
143
- "type": "AGENT_CONNECTED",
144
- "payload": {
145
- "id": "agent-123",
146
- "name": "Research Agent",
147
- "capabilities": ["research", "analysis"],
148
- "status": "idle",
149
- "connectedAt": 1234567890
150
- }
151
- }
152
- ```
153
-
154
- #### State Event
155
- ```json
156
- {
157
- "type": "STATE_EVENT",
158
- "payload": {
159
- "id": "event-uuid",
160
- "timestamp": 1234567890,
161
- "type": "TASK_REQUEST",
162
- "agentId": "agent-123",
163
- "data": {},
164
- "snapshot": {}
165
- }
166
- }
167
- ```
168
-
169
- ## Components
170
-
171
- ### AgentGraph
172
-
173
- Visualizes the agent swarm as a node graph.
174
-
175
- **Props:**
176
- - `agents: Agent[]` - Array of connected agents
177
-
178
- **Features:**
179
- - Circular layout around central hub
180
- - Color-coded status indicators
181
- - Capability badges
182
- - Connection lines with animation
183
-
184
- ### MetricsPanel
185
-
186
- Displays token economics and performance metrics.
187
-
188
- **Props:**
189
- - `metrics: Metrics` - Current metrics object
190
-
191
- **Features:**
192
- - 6 key metric cards
193
- - 3 interactive charts
194
- - ROI calculator
195
- - Historical data tracking
196
-
197
- ### TimeTravel
198
-
199
- State debugger with time-travel capabilities.
200
-
201
- **Props:**
202
- - `events: StateEvent[]` - Array of captured events
203
-
204
- **Features:**
205
- - Event timeline
206
- - State inspector
207
- - Playback controls
208
- - State editing
209
-
210
- ### ConnectionStatus
211
-
212
- Shows WebSocket connection status.
213
-
214
- **Props:**
215
- - `isConnected: boolean` - Connection state
216
-
217
- ## Customization
218
-
219
- ### Theme
220
-
221
- Edit `tailwind.config.js` to customize colors:
222
-
223
- ```javascript
224
- theme: {
225
- extend: {
226
- colors: {
227
- primary: { /* your colors */ },
228
- success: { /* your colors */ },
229
- // ...
230
- },
231
- },
232
- }
233
- ```
234
-
235
- ### Metrics
236
-
237
- Add custom metrics in `useWebSocket.ts`:
238
-
239
- ```typescript
240
- export interface Metrics {
241
- // ... existing metrics
242
- customMetric: number;
243
- }
244
- ```
245
-
246
- ### Charts
247
-
248
- Add new charts in `MetricsPanel.tsx` using Recharts:
249
-
250
- ```typescript
251
- <LineChart data={historicalData}>
252
- <Line dataKey="customMetric" stroke="#color" />
253
- </LineChart>
254
- ```
255
-
256
- ## Performance
257
-
258
- ### Optimizations
259
-
260
- - **Lazy Loading**: Components loaded on-demand
261
- - **Memoization**: React.memo for expensive components
262
- - **Virtual Scrolling**: For large event lists
263
- - **Data Limiting**: Keep only recent data points
264
-
265
- ### Metrics
266
-
267
- - **Bundle Size**: ~200KB gzipped
268
- - **Initial Load**: <1s on fast connection
269
- - **Memory Usage**: ~50MB typical
270
- - **CPU Usage**: <5% idle, <15% active
271
-
272
- ## Deployment
273
-
274
- ### Static Hosting
275
-
276
- Build and deploy to any static host:
277
-
278
- ```bash
279
- npm run build
280
- # Upload dist/ folder to:
281
- # - Vercel
282
- # - Netlify
283
- # - AWS S3 + CloudFront
284
- # - GitHub Pages
285
- ```
286
-
287
- ### Docker
288
-
289
- ```dockerfile
290
- FROM node:20-alpine AS builder
291
- WORKDIR /app
292
- COPY package*.json ./
293
- RUN npm ci
294
- COPY . .
295
- RUN npm run build
296
-
297
- FROM nginx:alpine
298
- COPY --from=builder /app/dist /usr/share/nginx/html
299
- EXPOSE 80
300
- CMD ["nginx", "-g", "daemon off;"]
301
- ```
302
-
303
- ### Environment Variables
304
-
305
- Set in deployment platform:
306
-
307
- - `VITE_ROUTER_URL`: WebSocket URL of Lemma router
308
- - `VITE_API_URL`: HTTP API URL (if different)
309
-
310
- ## Troubleshooting
311
-
312
- ### WebSocket Connection Failed
313
-
314
- 1. Check router is running
315
- 2. Verify URL in `.env`
316
- 3. Check CORS settings
317
- 4. Verify firewall rules
318
-
319
- ### Metrics Not Updating
320
-
321
- 1. Check WebSocket connection status
322
- 2. Verify router is broadcasting metrics
323
- 3. Check browser console for errors
324
- 4. Verify message format
325
-
326
- ### Charts Not Rendering
327
-
328
- 1. Check data format matches Recharts requirements
329
- 2. Verify ResponsiveContainer has height
330
- 3. Check for console errors
331
- 4. Verify data is not empty
332
-
333
- ## Development
334
-
335
- ### Adding a New Tab
336
-
337
- 1. Create component in `src/components/`
338
- 2. Add tab button in `App.tsx`
339
- 3. Add route in tab navigation
340
- 4. Update state management
341
-
342
- ### Adding a New Metric
343
-
344
- 1. Update `Metrics` interface in `useWebSocket.ts`
345
- 2. Add metric card in `MetricsPanel.tsx`
346
- 3. Update backend to send metric
347
- 4. Add to historical data tracking
42
+ From the repo root, `npm run build` also builds the dashboard. `dashboard/dist` is
43
+ git-ignored but published to npm, so rebuild before releasing.
348
44
 
349
- ## License
45
+ ## Stack
350
46
 
351
- MIT
47
+ React 18, TypeScript, Vite, Tailwind, Zustand, Recharts, Socket.IO client.