claw-dashboard 2.1.1 → 2.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 (89) hide show
  1. package/CHANGELOG.md +29 -1
  2. package/docs/API.md +1 -2
  3. package/index.js +31 -41
  4. package/package.json +22 -12
  5. package/src/auto-save.js +11 -5
  6. package/src/cli/export-snapshot.js +3 -1
  7. package/src/cli/import-snapshot.js +3 -1
  8. package/src/config.js +9 -15
  9. package/src/errors.js +0 -9
  10. package/src/security.js +6 -2
  11. package/src/snapshot.js +73 -26
  12. package/src/web-server.js +7 -10
  13. package/.c8rc.json +0 -38
  14. package/.dockerignore +0 -68
  15. package/.github/dependabot.yml +0 -45
  16. package/.github/pull_request_template.md +0 -39
  17. package/.github/workflows/ci.yml +0 -147
  18. package/.github/workflows/release.yml +0 -40
  19. package/.github/workflows/security.yml +0 -84
  20. package/.husky/pre-commit +0 -1
  21. package/.planning/codebase/ARCHITECTURE.md +0 -206
  22. package/.planning/codebase/INTEGRATIONS.md +0 -150
  23. package/.planning/codebase/STACK.md +0 -122
  24. package/.planning/codebase/STRUCTURE.md +0 -201
  25. package/CONTRIBUTING.md +0 -378
  26. package/Dockerfile +0 -54
  27. package/FEATURES.md +0 -307
  28. package/TODO.md +0 -28
  29. package/ai.openclaw.dashboard.plist +0 -35
  30. package/build-cjs.js +0 -127
  31. package/cjs-shim.js +0 -13
  32. package/dist/clawdash +0 -1729
  33. package/dist/clawdash.meta.json +0 -2236
  34. package/dist/widgets.cjs +0 -6511
  35. package/docker-compose.yml +0 -67
  36. package/esbuild.config.js +0 -158
  37. package/eslint.config.js +0 -56
  38. package/examples/plugins/README.md +0 -122
  39. package/examples/plugins/api-status/index.js +0 -294
  40. package/examples/plugins/api-status/plugin.json +0 -19
  41. package/examples/plugins/hello-world/index.js +0 -104
  42. package/examples/plugins/hello-world/plugin.json +0 -15
  43. package/examples/plugins/system-metrics-chart/index.js +0 -339
  44. package/examples/plugins/system-metrics-chart/plugin.json +0 -18
  45. package/examples/plugins/weather-widget/index.js +0 -136
  46. package/examples/plugins/weather-widget/plugin.json +0 -19
  47. package/index.cjs +0 -23005
  48. package/jest.config.js +0 -11
  49. package/scripts/release.js +0 -595
  50. package/src/database.js +0 -734
  51. package/tests/alerts.test.js +0 -437
  52. package/tests/auto-save.test.js +0 -529
  53. package/tests/cache.test.js +0 -317
  54. package/tests/cli.test.js +0 -351
  55. package/tests/command-palette.test.js +0 -320
  56. package/tests/config-processor.test.js +0 -452
  57. package/tests/config-validator.test.js +0 -710
  58. package/tests/config-watcher.test.js +0 -594
  59. package/tests/config.test.js +0 -755
  60. package/tests/database.test.js +0 -438
  61. package/tests/errors.test.js +0 -189
  62. package/tests/example-plugins.test.js +0 -624
  63. package/tests/integration.test.js +0 -1321
  64. package/tests/loading-states.test.js +0 -300
  65. package/tests/manifest-validation-on-load.test.js +0 -671
  66. package/tests/performance-monitor.test.js +0 -190
  67. package/tests/plugin-api-rate-limit.test.js +0 -302
  68. package/tests/plugin-errors.test.js +0 -311
  69. package/tests/plugin-lifecycle-e2e.test.js +0 -1036
  70. package/tests/plugin-reload.test.js +0 -764
  71. package/tests/rate-limiter.test.js +0 -539
  72. package/tests/removed-dependencies.test.js +0 -74
  73. package/tests/retry.test.js +0 -308
  74. package/tests/security.test.js +0 -411
  75. package/tests/settings-modal.test.js +0 -226
  76. package/tests/theme-selector.test.js +0 -57
  77. package/tests/utils.js +0 -242
  78. package/tests/utils.test.js +0 -317
  79. package/tests/validate-plugin-cli.test.js +0 -359
  80. package/tests/validation.test.js +0 -837
  81. package/tests/web-server.test.js +0 -646
  82. package/tests/widget-arrange-mode.test.js +0 -183
  83. package/tests/widget-config-hot-reload.test.js +0 -465
  84. package/tests/widget-dependency.test.js +0 -591
  85. package/tests/widget-error-boundary.test.js +0 -749
  86. package/tests/widget-error-isolation.test.js +0 -469
  87. package/tests/widget-integration.test.js +0 -1147
  88. package/tests/widget-refresh-intervals.test.js +0 -284
  89. package/tests/worker-pool.test.js +0 -522
@@ -1,206 +0,0 @@
1
- # Architecture
2
-
3
- **Analysis Date:** 2026-02-28
4
-
5
- ## Pattern Overview
6
-
7
- **Overall:** Modular widget-based terminal dashboard with plugin architecture
8
-
9
- **Key Characteristics:**
10
- - Widget-based UI components using blessed framework
11
- - Plugin system with lazy loading and hot-reload
12
- - Event-driven architecture (EventEmitter pattern)
13
- - Worker thread pool for heavy system operations
14
- - Rate limiting throughout API access
15
- - Comprehensive error boundaries
16
-
17
- ## Layers
18
-
19
- **Application Layer:**
20
- - Purpose: Entry point, CLI parsing, main dashboard orchestration
21
- - Location: `index.js`
22
- - Contains: Main screen setup, keyboard handlers, initialization sequence
23
- - Depends on: All other layers
24
- - Used by: CLI binary
25
-
26
- **Widget Layer:**
27
- - Purpose: UI components and plugin system
28
- - Location: `src/widgets/`
29
- - Contains: BaseWidget class, PluginAPI, WidgetLoader, built-in widgets
30
- - Depends on: blessed, blessed-contrib
31
- - Used by: Application layer
32
-
33
- **Service Layer:**
34
- - Purpose: Business logic, data fetching, caching
35
- - Location: `src/*.js` (non-widget files)
36
- - Contains: gateway-manager, database, cache, themes, alerts, validation
37
- - Depends on: systeminformation, sql.js
38
- - Used by: Widgets and Application
39
-
40
- **Worker Layer:**
41
- - Purpose: Offload heavy system calls to threads
42
- - Location: `src/workers/`
43
- - Contains: WorkerPool, system-worker
44
- - Depends on: Node.js worker_threads
45
- - Used by: Application layer for system metrics
46
-
47
- **Data Layer:**
48
- - Purpose: Persistence and caching
49
- - Location: `src/database.js`, `src/cache.js`
50
- - Contains: SQLite persistence, in-memory caching
51
- - Depends on: sql.js, fs
52
- - Used by: Service layer
53
-
54
- ## Data Flow
55
-
56
- **System Metrics Flow:**
57
-
58
- 1. Widget requests data via PluginAPI
59
- 2. PluginAPI checks rate limiter
60
- 3. Widget calls getData() which may use:
61
- - Worker pool for systeminformation calls
62
- - Cache for recent data
63
- - Direct fetch for real-time data
64
- 4. Data returns to widget
65
- 5. Widget renders to blessed elements
66
-
67
- **Gateway Data Flow:**
68
-
69
- 1. GatewayManager initialized with endpoints
70
- 2. Periodic fetch from `/api/sessions`, `/api/agents`
71
- 3. Checksum verification (optional)
72
- 4. Data aggregated from multiple endpoints
73
- 5. Stored in SQLite database
74
- 6. Widgets query database for display
75
-
76
- **Widget Plugin Flow:**
77
-
78
- 1. WidgetLoader discovers plugins from `~/.openclaw/plugins/`
79
- 2. Manifest validated (`src/plugin-manifest-validator.js`)
80
- 3. Dependencies resolved (`src/widgets/dependency-resolver.js`)
81
- 4. Widget class loaded dynamically
82
- 5. BaseWidget lifecycle: init -> create -> getData -> render -> destroy
83
- 6. Config watcher enables hot-reload
84
-
85
- ## Key Abstractions
86
-
87
- **BaseWidget:**
88
- - Purpose: Base class for all widgets
89
- - Location: `src/widgets/plugin-api.js` (class BaseWidget)
90
- - Pattern: Template method pattern with lifecycle hooks
91
- - Methods: init(), create(screen, theme), getData(), render(data), destroy()
92
-
93
- **PluginAPI:**
94
- - Purpose: Stable API for widget development
95
- - Location: `src/widgets/plugin-api.js`
96
- - Pattern: Facade pattern with rate limiting
97
- - Extension points: registerExtensionPoint(), extend(), registerProvider()
98
-
99
- **WidgetLoader:**
100
- - Purpose: Lazy loading and plugin management
101
- - Location: `src/widgets/widget-loader.js`
102
- - Pattern: Registry + Factory pattern
103
- - Features: Priority-based loading, dependency resolution, hot-reload
104
-
105
- **GatewayManager:**
106
- - Purpose: Multi-endpoint gateway aggregation
107
- - Location: `src/gateway-manager.js`
108
- - Pattern: Manager pattern with aggregation
109
- - Features: Checksum verification, retry logic, endpoint health tracking
110
-
111
- **Error Boundaries:**
112
- - Purpose: Isolate widget failures
113
- - Location: `src/widgets/widget-error-boundary.js`
114
- - Pattern: Decorator pattern
115
- - Features: Per-widget error isolation, automatic retry
116
-
117
- ## Entry Points
118
-
119
- **Main Entry:**
120
- - Location: `index.js`
121
- - Triggers: CLI execution (`clawdash` or `node index.js`)
122
- - Responsibilities:
123
- - Parse CLI args (`src/cli/index.js`)
124
- - Initialize database
125
- - Setup blessed screen
126
- - Load widgets via WidgetLoader
127
- - Setup keyboard handlers
128
- - Start refresh loop
129
-
130
- **CLI Commands:**
131
- - Location: `src/cli/`
132
- - Files: args.js, help.js, version.js, validate-plugin.js, validate-config.js
133
- - Exports centralized in: `src/cli/index.js`
134
-
135
- **Worker Entry:**
136
- - Location: `src/workers/system-worker.js`
137
- - Triggers: WorkerPool initialization
138
- - Responsibilities: Execute systeminformation calls in separate threads
139
-
140
- ## State Management
141
-
142
- **Theme State:**
143
- - File: `src/themes.js`
144
- - Pattern: Singleton with observer pattern
145
- - Detection: Auto-detects system dark/light mode
146
- - Persistence: Settings file
147
-
148
- **Settings State:**
149
- - File: `src/config.js` (constants), `src/validation.js` (validation)
150
- - Pattern: Immutable constants with validation
151
- - Storage: JSON file at `~/.openclaw/dashboard-settings.json`
152
-
153
- **Widget State:**
154
- - File: `src/widgets/widget-loader.js`
155
- - Pattern: Registry with metadata
156
- - Storage: In-memory Map instances
157
-
158
- **Performance State:**
159
- - File: `src/performance-monitor.js`
160
- - Pattern: Observer with periodic sampling
161
- - Metrics: Memory usage, worker pool stats
162
-
163
- ## Error Handling
164
-
165
- **Strategy:** Hierarchical error classes with boundary isolation
166
-
167
- **Patterns:**
168
- - Custom error hierarchy: `DashboardError` -> specific errors
169
- - Widget error boundaries isolate failures
170
- - Plugin error analyzer for debugging
171
- - Rate-limited error reporting
172
-
173
- **Error Classes:**
174
- - `src/errors.js`: DashboardError, ConfigError, SettingsError, GatewayError, etc.
175
- - `src/plugin-errors.js`: PluginError, PluginErrorAnalyzer
176
-
177
- ## Cross-Cutting Concerns
178
-
179
- **Logging:**
180
- - Location: `src/logger.js`
181
- - Pattern: Centralized with level filtering
182
- - Output: Console + file (`~/.openclaw/claw-dashboard.log`)
183
-
184
- **Validation:**
185
- - Location: `src/validation.js`
186
- - Pattern: Schema-based with detailed error messages
187
- - Scope: Settings, file paths, refresh intervals
188
-
189
- **Security:**
190
- - Location: `src/security.js`
191
- - Pattern: Input sanitization + path validation
192
- - Features: Path traversal prevention, file permission management
193
-
194
- **Rate Limiting:**
195
- - Location: `src/alerts.js` (RateLimiter class)
196
- - Pattern: Token bucket per category
197
- - Integration: PluginAPI uses for API calls
198
-
199
- **Caching:**
200
- - Location: `src/cache.js`
201
- - Pattern: TTL-based with category-specific timeouts
202
- - Features: Debounce, throttle, memoization
203
-
204
- ---
205
-
206
- *Architecture analysis: 2026-02-28*
@@ -1,150 +0,0 @@
1
- # External Integrations
2
-
3
- **Analysis Date:** 2026-02-28
4
-
5
- ## APIs & External Services
6
-
7
- **OpenClaw Gateway (Primary Integration):**
8
- - Default endpoint: localhost:18789
9
- - Protocol: HTTPS with optional token authentication
10
- - Endpoints queried:
11
- - `/api/sessions` - Active session list
12
- - `/api/agents` - Available agents
13
- - `/api/logs` - Log entries
14
- - File: `src/gateway-manager.js`
15
-
16
- **System Information (systeminformation library):**
17
- - CPU: load, usage, temperature
18
- - Memory: total, used, free, swap
19
- - GPU: NVIDIA (nvidia-smi), AMD (radeontop), Intel, WSL
20
- - Network: interfaces, speed, stats
21
- - Disk: filesystems, IO, usage
22
- - OS: uptime, hostname, platform
23
- - File: Uses `systeminformation` npm package
24
-
25
- **No External Cloud Services:**
26
- - No telemetry or analytics services
27
- - No external logging services
28
- - No cloud-based configuration
29
-
30
- ## Data Storage
31
-
32
- **Local SQLite Database:**
33
- - Library: sql.js (WebAssembly SQLite)
34
- - Path: `~/.openclaw/dashboard-history.db`
35
- - Tables: session_snapshots, cpu_metrics, memory_metrics, network_metrics
36
- - File: `src/database.js`
37
-
38
- **JSON Configuration:**
39
- - Settings: `~/.openclaw/dashboard-settings.json`
40
- - Persistent state across restarts
41
- - File: `src/config.js`, `src/validation.js`
42
-
43
- **File Storage:**
44
- - Local filesystem only
45
- - Export directory: `~/.openclaw/exports/`
46
- - Plugin directory: `~/.openclaw/plugins/`
47
-
48
- **Caching:**
49
- - In-memory cache with TTL
50
- - Categories: cpu, memory, gpu, network, disk, system, container
51
- - File: `src/cache.js`
52
-
53
- ## Authentication & Identity
54
-
55
- **Gateway Authentication:**
56
- - Token-based (optional per endpoint)
57
- - Header: Authorization Bearer token
58
- - File: `src/gateway-manager.js`
59
-
60
- **Web Interface Auth (Optional):**
61
- - API key authentication (disabled by default)
62
- - Key format: `cd_[a-zA-Z0-9]{32}`
63
- - Max 10 keys, hashed in storage
64
- - File: `src/web-server.js`
65
-
66
- **File Permissions:**
67
- - Settings/database: 0600 (owner read/write only)
68
- - File: `src/security.js`
69
-
70
- ## Monitoring & Observability
71
-
72
- **Error Tracking:**
73
- - Custom error classes (DashboardError hierarchy)
74
- - Centralized error handling in widgets
75
- - Plugin error boundary with isolation
76
- - File: `src/errors.js`, `src/plugin-errors.js`, `src/widgets/widget-error-boundary.js`
77
-
78
- **Logging:**
79
- - Local log file: `~/.openclaw/claw-dashboard.log`
80
- - Logger: `src/logger.js`
81
- - Levels: error, warn, info, debug
82
- - Console output during development
83
-
84
- **Performance Monitoring:**
85
- - Worker pool metrics
86
- - Memory pressure detection
87
- - Widget render timing
88
- - File: `src/performance-monitor.js`, `src/memory-pressure.js`
89
-
90
- ## Web Interface
91
-
92
- **Embedded Web Server:**
93
- - Disabled by default
94
- - Port: 18790 (configurable)
95
- - Rate limiting: 100 requests/minute per IP
96
- - CORS: configurable (wildcard in development)
97
- - Endpoints:
98
- - GET /health
99
- - GET /metrics
100
- - GET /sessions
101
- - GET /agents
102
- - GET /logs
103
- - GET /status
104
- - File: `src/web-server.js`
105
-
106
- ## CI/CD & Deployment
107
-
108
- **CI Pipeline:**
109
- - GitHub Actions configured (`.github/workflows/`)
110
- - Jest tests with coverage
111
- - Docker support (Dockerfile, docker-compose.yml)
112
-
113
- **Installation:**
114
- - npm global install: `npm install -g claw-dashboard`
115
- - Binary: `clawdash`
116
- - Manual install script: `install.sh`
117
-
118
- ## Environment Configuration
119
-
120
- **Required env vars:**
121
- - None (all have defaults)
122
-
123
- **Optional env vars:**
124
- - `HOME` - Used for path expansion
125
- - `DARK_MODE` - Theme override
126
- - `THEME` - Theme override
127
- - `COLORFGBG` - Terminal background detection
128
-
129
- **Secrets location:**
130
- - Settings file (~/.openclaw/dashboard-settings.json)
131
- - Database file (~/.openclaw/dashboard-history.db)
132
- - API keys hashed before storage
133
-
134
- ## Webhooks & Callbacks
135
-
136
- **Incoming:**
137
- - None
138
-
139
- **Outgoing:**
140
- - None
141
-
142
- **Plugin System:**
143
- - Plugins loaded from filesystem
144
- - Hot-reload support via file watcher
145
- - Extension points for custom functionality
146
- - File: `src/widgets/widget-loader.js`, `src/widgets/plugin-api.js`
147
-
148
- ---
149
-
150
- *Integration audit: 2026-02-28*
@@ -1,122 +0,0 @@
1
- # Technology Stack
2
-
3
- **Analysis Date:** 2026-02-28
4
-
5
- ## Languages
6
-
7
- **Primary:**
8
- - JavaScript (ES2022) - All source code
9
- - TypeScript definitions (types.d.ts) - Type definitions for IDE support
10
-
11
- ## Runtime
12
-
13
- **Environment:**
14
- - Node.js >= 18 (required)
15
- - ES Modules (`"type": "module"` in package.json)
16
-
17
- **Package Manager:**
18
- - npm (lockfile present: package-lock.json)
19
-
20
- ## Frameworks & Libraries
21
-
22
- **Core Runtime:**
23
- - `blessed` ^0.1.81 - Terminal UI framework (blessed curses-like library)
24
- - `blessed-contrib` ^4.11.0 - Charts and widgets for blessed
25
- - `chalk` ^5.3.0 - Terminal string styling
26
- - `systeminformation` ^5.21.22 - System information gathering (CPU, memory, network, disk, GPU)
27
- - `sql.js` ^1.14.0 - SQLite compiled to WebAssembly for in-process database
28
- - `timeout-cli` ^0.3.2 - Command timeout utilities
29
-
30
- **Build System:**
31
- - `esbuild` ^0.25.12 - Fast bundler for CJS builds
32
- - Dual-package: ESM (primary) + CJS (built via build-cjs.js)
33
-
34
- **Testing:**
35
- - `jest` ^30.2.0 - Test framework (run with --experimental-vm-modules)
36
- - No additional assertion library (uses Jest built-in)
37
-
38
- **Linting:**
39
- - `eslint` ^10.0.2 - Linting with @eslint/js recommended config
40
- - Uses flat config (eslint.config.js)
41
-
42
- ## Key Dependencies
43
-
44
- **Critical:**
45
- - `blessed` + `blessed-contrib` - Terminal UI framework (core dependency)
46
- - `systeminformation` - All system metrics (CPU, memory, GPU, network, disk)
47
- - `sql.js` - SQLite WASM for historical data persistence
48
-
49
- **Infrastructure:**
50
- - `chalk` - Terminal styling
51
- - `worker_threads` (Node.js built-in) - Worker pool for heavy operations
52
- - `https`/`http` (Node.js built-in) - Gateway API communication
53
-
54
- ## Configuration
55
-
56
- **Environment:**
57
- - Settings stored in: `~/.openclaw/dashboard-settings.json`
58
- - Database stored in: `~/.openclaw/dashboard-history.db`
59
- - Plugins loaded from: `~/.openclaw/plugins/`
60
- - Log file: `~/.openclaw/claw-dashboard.log`
61
-
62
- **Build:**
63
- - esbuild.config.js - ESM build configuration
64
- - build-cjs.js - CJS bundle generation (creates index.cjs, dist/widgets.cjs)
65
- - cjs-shim.js - Provides import.meta.url polyfill for CJS
66
-
67
- **Package Exports:**
68
- ```json
69
- {
70
- ".": {
71
- "import": "./index.js",
72
- "require": "./index.cjs"
73
- },
74
- "./widgets": {
75
- "import": "./src/widgets/index.js",
76
- "require": "./dist/widgets.cjs"
77
- }
78
- }
79
- ```
80
-
81
- ## Platform Requirements
82
-
83
- **Development:**
84
- - Node.js >= 18
85
- - npm for dependency management
86
- - macOS/Linux/Windows (some system features macOS-specific)
87
-
88
- **Production:**
89
- - Node.js runtime
90
- - No external services required (self-contained)
91
- - Optional: OpenClaw gateway endpoint on localhost:18789
92
-
93
- ## Module System
94
-
95
- **Primary:** ES Modules (ESM) with `.js` extension
96
- **Dual Package:** CJS builds for compatibility
97
- **Worker Threads:** Separate worker files in `src/workers/`
98
-
99
- **Import Patterns:**
100
- ```javascript
101
- // ESM imports throughout
102
- import blessed from 'blessed';
103
- import { BaseWidget } from './plugin-api.js';
104
- import config, { DEFAULT_SETTINGS } from './config.js';
105
- ```
106
-
107
- ## Database
108
-
109
- **Type:** SQLite via sql.js (WebAssembly)
110
- **Location:** `~/.openclaw/dashboard-history.db`
111
- **Tables:**
112
- - `session_snapshots` - Agent session data
113
- - `cpu_metrics` - CPU usage history
114
- - `memory_metrics` - Memory usage history
115
- - `network_metrics` - Network usage history
116
-
117
- **Save Interval:** 30 seconds
118
- **Cleanup Interval:** 1 hour (with retention policy)
119
-
120
- ---
121
-
122
- *Stack analysis: 2026-02-28*
@@ -1,201 +0,0 @@
1
- # Codebase Structure
2
-
3
- **Analysis Date:** 2026-02-28
4
-
5
- ## Directory Layout
6
-
7
- ```
8
- /Users/kdsmith/.openclaw/workspace/claw-dashboard/
9
- ├── index.js # Main entry point (blessed TUI)
10
- ├── index.cjs # CJS build output
11
- ├── src/ # Core source code
12
- │ ├── widgets/ # Widget system (plugins + built-in)
13
- │ ├── workers/ # Worker thread pool
14
- │ ├── cli/ # CLI command handlers
15
- │ ├── *.js # Core modules (config, themes, etc.)
16
- ├── tests/ # Jest test suites (375 tests)
17
- ├── examples/ # Example plugins
18
- │ └── plugins/ # Widget plugin examples
19
- ├── docs/ # Documentation
20
- ├── schemas/ # JSON schemas
21
- ├── dist/ # CJS build output
22
- ├── scripts/ # Build/release scripts
23
- ├── man/ # Man pages
24
- ├── build-cjs.js # CJS build script
25
- ├── esbuild.config.js # ESM build config
26
- ├── jest.config.js # Test configuration
27
- ├── eslint.config.js # Lint configuration
28
- ├── package.json # Package manifest (ESM + CJS dual)
29
- └── README.md, CHANGELOG.md # Documentation
30
- ```
31
-
32
- ## Directory Purposes
33
-
34
- **`src/` - Core Source:**
35
- - Purpose: All application logic
36
- - Contains: 35 JavaScript modules, organized by function
37
- - Key files:
38
- - `index.js` - Main entry
39
- - `config.js` - Centralized constants
40
- - `themes.js` - Theme management
41
- - `gateway-manager.js` - Gateway communication
42
- - `database.js` - SQLite persistence
43
-
44
- **`src/widgets/` - Widget System:**
45
- - Purpose: Plugin architecture and built-in widgets
46
- - Contains: 10 files, ~14k total lines
47
- - Key files:
48
- - `plugin-api.js` - BaseWidget and PluginAPI classes
49
- - `widget-loader.js` - Lazy loading, hot-reload, registry
50
- - `builtin-widgets.js` - 10 built-in widget classes
51
- - `dependency-resolver.js` - Widget dependency resolution
52
- - `widget-error-boundary.js` - Error isolation
53
- - `config-processor.js` - Config with env interpolation
54
-
55
- **`src/workers/` - Worker Pool:**
56
- - Purpose: Thread pool for heavy system operations
57
- - Contains: 2 files
58
- - Files:
59
- - `worker-pool.js` - Pool management (874 lines)
60
- - `system-worker.js` - Worker thread code (3k lines)
61
-
62
- **`src/cli/` - CLI Commands:**
63
- - Purpose: Command-line argument parsing and commands
64
- - Contains: 6 files
65
- - Files:
66
- - `index.js` - Centralized exports
67
- - `args.js` - Argument parsing
68
- - `help.js` - Help text
69
- - `validate-plugin.js` - Plugin validation CLI
70
- - `validate-config.js` - Config validation CLI
71
-
72
- **`tests/` - Test Suites:**
73
- - Purpose: Jest test coverage
74
- - Contains: 32 test files, 375 total tests
75
- - Key files:
76
- - `integration.test.js` - Multi-module integration
77
- - `widget-*.test.js` - Widget system tests
78
- - `example-plugins.test.js` - Plugin tests
79
-
80
- **`examples/plugins/` - Example Plugins:**
81
- - Purpose: Reference implementations for plugin developers
82
- - Contains: 4 example widgets
83
- - Plugins:
84
- - `hello-world/` - Minimal widget example
85
- - `api-status/` - API polling widget
86
- - `system-metrics-chart/` - Chart widget example
87
- - `weather-widget/` - External API widget
88
-
89
- **`docs/` - Documentation:**
90
- - Purpose: User and developer documentation
91
- - Contains: PLUGINS.md, API.md
92
-
93
- **`schemas/` - JSON Schemas:**
94
- - Purpose: Validation schemas
95
- - Contains: Plugin manifest schema
96
-
97
- ## Key File Locations
98
-
99
- **Entry Points:**
100
- - `index.js` - Main application entry (blessed TUI)
101
- - `src/workers/system-worker.js` - Worker thread entry
102
- - `src/cli/index.js` - CLI exports
103
-
104
- **Configuration:**
105
- - `src/config.js` - Centralized constants and defaults
106
- - `src/config-validator.js` - Runtime config validation
107
- - `src/validation.js` - Input validation
108
- - `jest.config.js` - Test config
109
- - `eslint.config.js` - Lint config
110
-
111
- **Core Logic:**
112
- - `src/gateway-manager.js` - Gateway communication
113
- - `src/database.js` - SQLite persistence
114
- - `src/cache.js` - In-memory caching
115
- - `src/themes.js` - Theme management
116
- - `src/alerts.js` - Rate limiting and alerts
117
-
118
- **Widget System:**
119
- - `src/widgets/plugin-api.js` - BaseWidget, PluginAPI
120
- - `src/widgets/widget-loader.js` - Lazy loading
121
- - `src/widgets/builtin-widgets.js` - Built-in widgets
122
- - `src/widgets/index.js` - Widget system exports
123
-
124
- **Build System:**
125
- - `build-cjs.js` - CJS bundle generation
126
- - `esbuild.config.js` - ESM build configuration
127
- - `cjs-shim.js` - import.meta.url polyfill
128
-
129
- ## Naming Conventions
130
-
131
- **Files:**
132
- - Kebab-case: `widget-loader.js`, `builtin-widgets.js`
133
- - Extensions: `.js` for source, `.test.js` for tests
134
-
135
- **Directories:**
136
- - Kebab-case: `widget-error-boundary.js` directory would be `widget-error-boundary/`
137
- - Singular nouns except workers/ (plural by convention)
138
-
139
- **Classes:**
140
- - PascalCase: `BaseWidget`, `WidgetLoader`, `PluginAPI`
141
- - Suffix pattern: `*Widget`, `*Manager`, `*Error`
142
-
143
- **Functions/Methods:**
144
- - camelCase: `loadWidget()`, `getData()`, `validateConfig()`
145
- - Async prefix: `async` keyword, not name
146
-
147
- **Constants:**
148
- - UPPER_SNAKE_CASE: `DEFAULT_SETTINGS`, `REFRESH_INTERVALS`
149
- - Grouped in objects: `config.REFRESH_INTERVALS`
150
-
151
- ## Where to Add New Code
152
-
153
- **New Widget:**
154
- - Implementation: `src/widgets/builtin-widgets.js` (for built-in) OR `~/.openclaw/plugins/<name>/` (for plugin)
155
- - Tests: `tests/<widget-name>.test.js`
156
-
157
- **New Plugin:**
158
- - Development: `examples/plugins/<name>/`
159
- - Required files: `index.js`, `plugin.json`
160
- - See `examples/plugins/hello-world/` for template
161
-
162
- **New Service Module:**
163
- - Implementation: `src/<module-name>.js`
164
- - Tests: `tests/<module-name>.test.js`
165
- - Export from: `src/widgets/index.js` if widget-related
166
-
167
- **New CLI Command:**
168
- - Handler: `src/cli/<command-name>.js`
169
- - Export: `src/cli/index.js`
170
- - Integration: `index.js` main CLI parsing
171
-
172
- **New Worker Task:**
173
- - Worker: `src/workers/system-worker.js` (add task handler)
174
- - Pool: `src/workers/worker-pool.js` (add public method)
175
-
176
- ## Special Directories
177
-
178
- **`dist/`:**
179
- - Purpose: CJS build output
180
- - Generated: Yes (by `npm run build:cjs`)
181
- - Committed: Yes (for npm package)
182
- - Contains: `widgets.cjs` for CJS consumers
183
-
184
- **`node_modules/`:**
185
- - Purpose: npm dependencies
186
- - Generated: Yes
187
- - Committed: No
188
-
189
- **`coverage/`:**
190
- - Purpose: Jest coverage reports
191
- - Generated: Yes
192
- - Committed: No
193
-
194
- **`~/.openclaw/` (runtime):**
195
- - Purpose: User data directory
196
- - Created: At runtime if not exists
197
- - Contains: settings, database, logs, plugins
198
-
199
- ---
200
-
201
- *Structure analysis: 2026-02-28*