claw-dashboard 1.9.0 → 2.1.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 (135) hide show
  1. package/.c8rc.json +38 -0
  2. package/.dockerignore +68 -0
  3. package/.github/dependabot.yml +45 -0
  4. package/.github/pull_request_template.md +39 -0
  5. package/.github/workflows/ci.yml +147 -0
  6. package/.github/workflows/release.yml +40 -0
  7. package/.github/workflows/security.yml +84 -0
  8. package/.husky/pre-commit +1 -0
  9. package/.planning/codebase/ARCHITECTURE.md +206 -0
  10. package/.planning/codebase/INTEGRATIONS.md +150 -0
  11. package/.planning/codebase/STACK.md +122 -0
  12. package/.planning/codebase/STRUCTURE.md +201 -0
  13. package/CHANGELOG.md +293 -0
  14. package/CONTRIBUTING.md +378 -0
  15. package/Dockerfile +54 -0
  16. package/FEATURES.md +195 -21
  17. package/README.md +83 -6
  18. package/TODO.md +28 -0
  19. package/build-cjs.js +127 -0
  20. package/cjs-shim.js +13 -0
  21. package/dist/clawdash +1729 -0
  22. package/dist/clawdash.meta.json +2236 -0
  23. package/dist/widgets.cjs +6511 -0
  24. package/docker-compose.yml +67 -0
  25. package/docs/API.md +1050 -0
  26. package/docs/PLUGINS.md +1504 -0
  27. package/esbuild.config.js +158 -0
  28. package/eslint.config.js +56 -0
  29. package/examples/plugins/README.md +122 -0
  30. package/examples/plugins/api-status/index.js +294 -0
  31. package/examples/plugins/api-status/plugin.json +19 -0
  32. package/examples/plugins/hello-world/index.js +104 -0
  33. package/examples/plugins/hello-world/plugin.json +15 -0
  34. package/examples/plugins/system-metrics-chart/index.js +339 -0
  35. package/examples/plugins/system-metrics-chart/plugin.json +18 -0
  36. package/examples/plugins/weather-widget/index.js +136 -0
  37. package/examples/plugins/weather-widget/plugin.json +19 -0
  38. package/index.cjs +23005 -0
  39. package/index.js +5285 -566
  40. package/jest.config.js +11 -0
  41. package/man/clawdash.1 +276 -0
  42. package/package.json +54 -6
  43. package/schemas/plugin-manifest.json +128 -0
  44. package/scripts/release.js +595 -0
  45. package/src/alerts.js +693 -0
  46. package/src/auto-save.js +584 -0
  47. package/src/cache.js +390 -0
  48. package/src/checksum.js +146 -0
  49. package/src/cli/args.js +110 -0
  50. package/src/cli/export-schedule.js +423 -0
  51. package/src/cli/export-snapshot.js +138 -0
  52. package/src/cli/help.js +69 -0
  53. package/src/cli/import-snapshot.js +230 -0
  54. package/src/cli/index.js +14 -0
  55. package/src/cli/list-templates.js +69 -0
  56. package/src/cli/validate-config.js +76 -0
  57. package/src/cli/validate-plugin.js +187 -0
  58. package/src/cli/version.js +15 -0
  59. package/src/config-validator.js +586 -0
  60. package/src/config-watcher.js +401 -0
  61. package/src/config.js +684 -0
  62. package/src/container-detector.js +499 -0
  63. package/src/database.js +734 -0
  64. package/src/differential-render.js +327 -0
  65. package/src/errors.js +169 -0
  66. package/src/export-scheduler.js +581 -0
  67. package/src/gateway-manager.js +685 -0
  68. package/src/hints.js +371 -0
  69. package/src/loading-states.js +509 -0
  70. package/src/logger.js +185 -0
  71. package/src/memory-pressure.js +467 -0
  72. package/src/performance-monitor.js +374 -0
  73. package/src/plugin-errors.js +586 -0
  74. package/src/plugin-manifest-validator.js +219 -0
  75. package/src/plugin-reload.js +481 -0
  76. package/src/plugin-scaffold.js +1934 -0
  77. package/src/plugin-validator.js +284 -0
  78. package/src/retry.js +218 -0
  79. package/src/security.js +860 -0
  80. package/src/snapshot.js +372 -0
  81. package/src/splash.js +115 -0
  82. package/src/theme-selector.js +411 -0
  83. package/src/themes.js +874 -0
  84. package/src/transitions.js +534 -0
  85. package/src/types.d.ts +174 -0
  86. package/src/validation.js +926 -0
  87. package/src/web-server.js +885 -0
  88. package/src/widgets/builtin-widgets.js +1056 -0
  89. package/src/widgets/config-processor.js +401 -0
  90. package/src/widgets/dependency-resolver.js +596 -0
  91. package/src/widgets/index.js +79 -0
  92. package/src/widgets/plugin-api.js +845 -0
  93. package/src/widgets/widget-error-boundary.js +773 -0
  94. package/src/widgets/widget-error-isolation.js +551 -0
  95. package/src/widgets/widget-loader.js +1437 -0
  96. package/src/workers/system-worker.js +130 -0
  97. package/src/workers/worker-pool.js +633 -0
  98. package/tests/alerts.test.js +437 -0
  99. package/tests/auto-save.test.js +529 -0
  100. package/tests/cache.test.js +317 -0
  101. package/tests/cli.test.js +351 -0
  102. package/tests/command-palette.test.js +320 -0
  103. package/tests/config-processor.test.js +452 -0
  104. package/tests/config-validator.test.js +710 -0
  105. package/tests/config-watcher.test.js +594 -0
  106. package/tests/config.test.js +755 -0
  107. package/tests/database.test.js +438 -0
  108. package/tests/errors.test.js +189 -0
  109. package/tests/example-plugins.test.js +624 -0
  110. package/tests/integration.test.js +1321 -0
  111. package/tests/loading-states.test.js +300 -0
  112. package/tests/manifest-validation-on-load.test.js +671 -0
  113. package/tests/performance-monitor.test.js +190 -0
  114. package/tests/plugin-api-rate-limit.test.js +302 -0
  115. package/tests/plugin-errors.test.js +311 -0
  116. package/tests/plugin-lifecycle-e2e.test.js +1036 -0
  117. package/tests/plugin-reload.test.js +764 -0
  118. package/tests/rate-limiter.test.js +539 -0
  119. package/tests/retry.test.js +308 -0
  120. package/tests/security.test.js +411 -0
  121. package/tests/settings-modal.test.js +226 -0
  122. package/tests/theme-selector.test.js +57 -0
  123. package/tests/utils.js +242 -0
  124. package/tests/utils.test.js +317 -0
  125. package/tests/validate-plugin-cli.test.js +359 -0
  126. package/tests/validation.test.js +837 -0
  127. package/tests/web-server.test.js +646 -0
  128. package/tests/widget-arrange-mode.test.js +183 -0
  129. package/tests/widget-config-hot-reload.test.js +465 -0
  130. package/tests/widget-dependency.test.js +591 -0
  131. package/tests/widget-error-boundary.test.js +749 -0
  132. package/tests/widget-error-isolation.test.js +469 -0
  133. package/tests/widget-integration.test.js +1147 -0
  134. package/tests/widget-refresh-intervals.test.js +284 -0
  135. package/tests/worker-pool.test.js +522 -0
@@ -0,0 +1,300 @@
1
+ /**
2
+ * Tests for loading-states.js
3
+ */
4
+
5
+ import loadingStates, {
6
+ LoadingStateManager,
7
+ createWidgetSpinner,
8
+ createProgressBar,
9
+ loadSequentially,
10
+ loadStaggered,
11
+ getSpinnerFrame,
12
+ getSpinnerStyles,
13
+ SPINNER_FRAMES,
14
+ PROGRESS_STYLES
15
+ } from '../src/loading-states.js';
16
+
17
+ describe('Loading States', () => {
18
+ beforeEach(() => {
19
+ loadingStates.clearAll();
20
+ });
21
+
22
+ afterEach(() => {
23
+ loadingStates.clearAll();
24
+ });
25
+
26
+ describe('LoadingStateManager', () => {
27
+ test('should create a loading state', () => {
28
+ const state = loadingStates.create('test', {
29
+ type: 'spinner',
30
+ message: 'Testing...'
31
+ });
32
+
33
+ expect(state).toBeDefined();
34
+ expect(state.id).toBe('test');
35
+ expect(typeof state.update).toBe('function');
36
+ expect(typeof state.complete).toBe('function');
37
+ });
38
+
39
+ test('should track multiple loading states', () => {
40
+ loadingStates.create('test1', { type: 'spinner' });
41
+ loadingStates.create('test2', { type: 'progress', total: 100 });
42
+
43
+ const active = loadingStates.getActive();
44
+ expect(active).toHaveLength(2);
45
+ expect(active).toContain('test1');
46
+ expect(active).toContain('test2');
47
+ });
48
+
49
+ test('should update loading message', () => {
50
+ const state = loadingStates.create('test', {
51
+ type: 'spinner',
52
+ message: 'Initial message'
53
+ });
54
+
55
+ state.update('New message');
56
+ const frame = state.getFrame();
57
+ expect(frame.message).toBe('New message');
58
+ });
59
+
60
+ test('should update progress', () => {
61
+ const state = loadingStates.create('test', {
62
+ type: 'progress',
63
+ message: 'Loading...',
64
+ total: 100
65
+ });
66
+
67
+ state.progress(50);
68
+ const frame = state.getFrame();
69
+ expect(frame.percentage).toBe('50.0');
70
+ expect(frame.current).toBe(50);
71
+ });
72
+
73
+ test('should complete loading state', () => {
74
+ const state = loadingStates.create('test', { type: 'spinner' });
75
+ state.complete('Done!');
76
+
77
+ expect(state.getFrame().message).toBe('Done!');
78
+ });
79
+
80
+ test('should remove loading state', () => {
81
+ loadingStates.create('test', { type: 'spinner' });
82
+ loadingStates.remove('test');
83
+
84
+ expect(loadingStates.getActive()).toHaveLength(0);
85
+ });
86
+
87
+ test('should clear all loading states', () => {
88
+ loadingStates.create('test1', { type: 'spinner' });
89
+ loadingStates.create('test2', { type: 'spinner' });
90
+ loadingStates.create('test3', { type: 'spinner' });
91
+
92
+ loadingStates.clearAll();
93
+ expect(loadingStates.getActive()).toHaveLength(0);
94
+ });
95
+ });
96
+
97
+ describe('Spinner Styles', () => {
98
+ test('should have multiple spinner styles', () => {
99
+ const styles = getSpinnerStyles();
100
+ expect(styles).toContain('dots');
101
+ expect(styles).toContain('line');
102
+ expect(styles).toContain('pulse');
103
+ expect(styles).toContain('blocks');
104
+ expect(styles).toContain('arrows');
105
+ expect(styles).toContain('bouncing');
106
+ });
107
+
108
+ test('should return frames for each style', () => {
109
+ Object.keys(SPINNER_FRAMES).forEach(style => {
110
+ const frame = getSpinnerFrame(style, 0);
111
+ expect(frame).toBeDefined();
112
+ expect(typeof frame).toBe('string');
113
+ });
114
+ });
115
+
116
+ test('should default to dots style', () => {
117
+ const frame = getSpinnerFrame('invalid-style', 0);
118
+ expect(frame).toBe(SPINNER_FRAMES.dots.frames[0]);
119
+ });
120
+
121
+ test('should auto-increment frame', () => {
122
+ const frame1 = getSpinnerFrame('dots');
123
+ // Small delay to get different frame
124
+ const start = Date.now();
125
+ while (Date.now() - start < 10) {} // Tiny busy wait
126
+ const frame2 = getSpinnerFrame('dots');
127
+ // Frames could be same or different depending on timing
128
+ expect(typeof frame1).toBe('string');
129
+ expect(typeof frame2).toBe('string');
130
+ });
131
+ });
132
+
133
+ describe('Progress Bar', () => {
134
+ test('should create progress bar', () => {
135
+ const controller = createProgressBar('test-operation', 50);
136
+
137
+ expect(controller).toBeDefined();
138
+ expect(typeof controller.progress).toBe('function');
139
+ expect(typeof controller.complete).toBe('function');
140
+ });
141
+
142
+ test('should have progress bar styles', () => {
143
+ expect(PROGRESS_STYLES.blocks).toBeDefined();
144
+ expect(PROGRESS_STYLES.bars).toBeDefined();
145
+ expect(PROGRESS_STYLES.ascii).toBeDefined();
146
+ expect(PROGRESS_STYLES.dots).toBeDefined();
147
+ });
148
+ });
149
+
150
+ describe('Sequential Loading', () => {
151
+ test('should load items sequentially', async () => {
152
+ const items = ['a', 'b', 'c'];
153
+ let callCount = 0;
154
+ const loader = async (item) => {
155
+ callCount++;
156
+ return 'loaded';
157
+ };
158
+
159
+ const results = await loadSequentially(items, loader);
160
+
161
+ expect(results).toHaveLength(3);
162
+ expect(callCount).toBe(3);
163
+ expect(results[0].success).toBe(true);
164
+ });
165
+
166
+ test('should handle loader failures gracefully', async () => {
167
+ const items = ['a', 'b'];
168
+ const loader = async (item) => {
169
+ if (item === 'b') throw new Error('failed');
170
+ return 'loaded';
171
+ };
172
+
173
+ const results = await loadSequentially(items, loader);
174
+
175
+ expect(results).toHaveLength(2);
176
+ expect(results[0].success).toBe(true);
177
+ expect(results[1].success).toBe(false);
178
+ });
179
+
180
+ test('should call progress callback', async () => {
181
+ const items = ['a', 'b'];
182
+ const loader = async () => 'loaded';
183
+ const progressCalls = [];
184
+ const onProgress = (current, total, item) => {
185
+ progressCalls.push({ current, total, item });
186
+ };
187
+
188
+ await loadSequentially(items, loader, { onProgress });
189
+
190
+ expect(progressCalls).toHaveLength(2);
191
+ expect(progressCalls[0]).toEqual({ current: 1, total: 2, item: 'a' });
192
+ expect(progressCalls[1]).toEqual({ current: 2, total: 2, item: 'b' });
193
+ });
194
+
195
+ test('should call item complete callback', async () => {
196
+ const items = [{ name: 'test' }];
197
+ const loader = async () => 'result';
198
+ const completedItems = [];
199
+ const onItemComplete = (item, result, index) => {
200
+ completedItems.push({ item, result, index });
201
+ };
202
+
203
+ await loadSequentially(items, loader, { onItemComplete });
204
+
205
+ expect(completedItems).toHaveLength(1);
206
+ expect(completedItems[0].item).toBe(items[0]);
207
+ expect(completedItems[0].result).toBe('result');
208
+ expect(completedItems[0].index).toBe(0);
209
+ });
210
+ });
211
+
212
+ describe('Staggered Loading', () => {
213
+ test('should load widgets with stagger delay', async () => {
214
+ const widgets = [{ id: 1 }, { id: 2 }];
215
+ let callCount = 0;
216
+ const factory = async () => {
217
+ callCount++;
218
+ return { created: true };
219
+ };
220
+
221
+ const results = await loadStaggered(widgets, factory, {
222
+ staggerDelay: 1 // Very small delay for fast test
223
+ });
224
+
225
+ expect(results).toHaveLength(2);
226
+ expect(callCount).toBe(2);
227
+ });
228
+
229
+ test('should call widget loaded callback', async () => {
230
+ const widgets = [{ id: 1 }];
231
+ const factory = async () => ({ created: true });
232
+ const loadedWidgets = [];
233
+ const onWidgetLoaded = (widget, config, index) => {
234
+ loadedWidgets.push({ widget, config, index });
235
+ };
236
+
237
+ await loadStaggered(widgets, factory, { onWidgetLoaded });
238
+
239
+ expect(loadedWidgets).toHaveLength(1);
240
+ expect(loadedWidgets[0].widget).toEqual({ created: true });
241
+ expect(loadedWidgets[0].config).toBe(widgets[0]);
242
+ expect(loadedWidgets[0].index).toBe(0);
243
+ });
244
+ });
245
+
246
+ describe('Widget Spinner', () => {
247
+ test('should return spinner controller', () => {
248
+ const mockBlessed = {};
249
+ const mockParent = {
250
+ screen: { render: () => {} }
251
+ };
252
+
253
+ const controller = createWidgetSpinner('test-widget', mockBlessed, mockParent);
254
+
255
+ expect(controller).toBeDefined();
256
+ expect(typeof controller.attach).toBe('function');
257
+ expect(typeof controller.update).toBe('function');
258
+ expect(typeof controller.complete).toBe('function');
259
+ expect(typeof controller.detach).toBe('function');
260
+ });
261
+ });
262
+
263
+ describe('Elapsed Time Formatting', () => {
264
+ test('should format milliseconds', () => {
265
+ const state = loadingStates.create('test', { type: 'spinner' });
266
+ // Wait a tiny bit
267
+ const elapsed = state.elapsed();
268
+ expect(elapsed).toBeGreaterThanOrEqual(0);
269
+ expect(typeof elapsed).toBe('number');
270
+ });
271
+ });
272
+
273
+ describe('Listener Management', () => {
274
+ test('should notify listeners on update', (done) => {
275
+ const state = loadingStates.create('test', { type: 'spinner' });
276
+
277
+ state.onUpdate((frame) => {
278
+ if (frame.message === 'Updated!') {
279
+ done();
280
+ }
281
+ });
282
+
283
+ state.update('Updated!');
284
+ });
285
+
286
+ test('should allow unsubscribing listeners', () => {
287
+ const state = loadingStates.create('test', { type: 'spinner' });
288
+ let callCount = 0;
289
+ const callback = () => {
290
+ callCount++;
291
+ };
292
+
293
+ const unsubscribe = state.onUpdate(callback);
294
+ unsubscribe(); // Remove listener
295
+
296
+ state.update('Test');
297
+ expect(callCount).toBe(0);
298
+ });
299
+ });
300
+ });